26 #include "TGo4MbsEvent.h"
27 #include "TGo4WinCond.h"
28 #include "TGo4PolyCond.h"
29 #include "TGo4CondArray.h"
30 #include "TGo4Picture.h"
31 #include "TGo4StepFactory.h"
32 #include "TGo4Analysis.h"
33 #include "TGo4Version.h"
36 #include "../saftdabc/Definitions.h"
37 #include "../../hadaq/hadaq/defines.h"
40 #define SAFT_PROCID 0xa
53 TSaftProc::TSaftProc() : TGo4EventProcessor(), fLastEventNumber(0), fLastTime(0),fLastTimeDeadline(0), fLastFlipTime(0)
62 TGo4Log::Info(
"TSaftProc: Delete instance");
69 TGo4Log::Info(
"TSaftProc: Create instance %s", name);
70 hDeltaN=MakeTH1(
'I',
"DeltaN",
"MBS Eventnumber difference", 1000, 0,1000);
71 hDeltaT=MakeTH1(
'I',
"DeltaT",
"Timing Events execution difference", 1000000, 0, 1000000,
"us",
"N");
72 hDeltaT_deadline=MakeTH1(
'I',
"DeltaT_deadline",
"Timing Events deadline difference", 1000000, 0, 1000000,
"us",
"N");
74 hDeltaT_coarse=MakeTH1(
'I',
"DeltaT_coarse",
"Coarse Timing Events execution difference",
75 10000, 0, 1.0e12,
"ns",
"N");
78 hDeltaT_deadline_fine=MakeTH1(
'I',
"DeltaT_deadline_fine",
"Timing Events deadline fine difference", 1000000, 0, 1000000,
"ns",
"N");
80 hLostSequence=MakeTH1(
'I',
"LostEdges",
"Lost rising or falling edges",2,0,2);
88 hOverflowCounts=MakeTH1(
'I',
"OverflowCounts",
"Relative Action sink overflows",1000,0,1000);
89 hOverflowScaler=MakeTH1(
'I',
"OverflowScaler",
"Action sink Overflow sum",2,0,2);
97 fPar=
dynamic_cast<TSaftParam*
>(MakeParameter(
"SaftParam",
"TSaftParam",
"set_SaftParam.C"));
109 if ((GetInputEvent()==0) || (GetInputEvent()->IsA() != TGo4MbsEvent::Class())) {
110 TGo4Log::Error(
"TSaftProc: no input MBS event found!");
114 TGo4MbsEvent* evnt = (TGo4MbsEvent*) GetInputEvent();
116 if(evnt->GetTrigger() > 11) {
117 TGo4Log::Info(
"TSaftProc: Skip trigger event");
123 evnt->ResetIterator();
124 TGo4MbsSubEvent *psubevt(0);
125 while((psubevt = evnt->NextSubEvent()) != 0) {
130 Int_t* pdata = psubevt->GetDataField();
131 Int_t* theEnd = psubevt->GetDataField() + psubevt->GetIntLen();
132 Int_t* evtEnd = theEnd;
133 Int_t* evtPaddedEnd = theEnd;
134 Int_t* subEnd = theEnd;
135 Int_t* subPaddedEnd = theEnd;
147 evtEnd= (Int_t*)( ((
char*) hadevt) + hadevt->
GetSize());
148 evtPaddedEnd= (Int_t*)( ((
char*) hadevt) + hadevt->
GetPaddedSize());
149 subEnd=(Int_t*)( ((
char*) hadsub) + hadsub->
GetSize());
150 subPaddedEnd=(Int_t*)( ((
char*) hadsub) + hadsub->
GetPaddedSize());
153 printf(
"TSaftProc::BuildEvent sees first hadaq event in buffer of size %d, padded:%d, subevt size:%d padded:%d\n",
155 std::cout << std::endl;
177 pdata=evtPaddedEnd+1;
178 if(pdata>=theEnd)
break;
183 evtEnd= (Int_t*)( ((
char*) hadevt) + hadevt->
GetSize());
184 evtPaddedEnd= (Int_t*)( ((
char*) hadevt) + hadevt->
GetPaddedSize());
185 subEnd=(Int_t*)( ((
char*) hadsub) + hadsub->
GetSize());
186 subPaddedEnd=(Int_t*)( ((
char*) hadsub) + hadsub->
GetPaddedSize());
189 printf(
"TSaftProc::BuildEvent sees new hadaq event of size %d, padded:%d, subevt size:%d padded:%d\n",
191 std::cout << std::endl;
199 pdata=subPaddedEnd+1;
200 if(pdata>=theEnd)
break;
203 subEnd=(Int_t*)( ((
char*) hadsub) + hadsub->
GetSize());
204 subPaddedEnd=(Int_t*)( ((
char*) hadsub) + hadsub->
GetPaddedSize());
207 printf(
"TSaftProc::BuildEvent sees new hadaq subevent of size:%d padded:%d\n",
209 std::cout << std::endl;
220 lo=(uint64_t)(*pdata++);
221 hi=(uint64_t)(*pdata++);
222 theEvent.
fEvent = (hi<<32) | (lo & 0xFFFFFFFF);
223 lo=(uint64_t)(*pdata++);
224 hi=(uint64_t)(*pdata++);
225 theEvent.
fParam = (hi<<32) | (lo & 0xFFFFFFFF);
226 lo=(uint64_t)(*pdata++);
227 hi=(uint64_t)(*pdata++);
228 theEvent.
fDeadline = (hi<<32) | (lo & 0xFFFFFFFF);
229 lo=(uint64_t)(*pdata++);
230 hi=(uint64_t)(*pdata++);
231 theEvent.
fExecuted = (hi<<32) | (lo & 0xFFFFFFFF);
232 lo=(uint64_t)(*pdata++);
233 hi=(uint64_t)(*pdata++);
234 theEvent.
fFlags = (hi<<32) | (lo & 0xFFFFFFFF);
235 lo=(uint64_t)(*pdata++);
236 hi=(uint64_t)(*pdata++);
237 theEvent.
fOverflows = (hi<<32) | (lo & 0xFFFFFFFF);
243 printf(
"Problem with info message!");
249 printf(
"TSaftProc::BuildEvent of event %d sees %s\n",evnt->GetCount(), buf);
252 std::cout << std::endl;
268 Double_t deltaus=delta/1.0e3;
272 Double_t deltadeadaus=deltaDead/1.0e3;
281 printf(
"******** Found delta= 0x%lx units (%ld ns) (%E us)\n", delta, delta, deltaus);
282 printf(
"** %s\n",buf);
283 printf(
"** Last time:0x%lx\n",
fLastTime);
285 printf(
"** Last Event: %s\n",buf);
287 printf(
"** Delta since last flip=0x%lx units\n",deltaflip);
288 printf(
"*************************************");
289 std::cout << std::endl;
347 uint64_t ns = time % 1000000000;
348 time_t s = time / 1000000000;
349 struct tm *tm = gmtime(&s);
355 strftime(date,
sizeof(date),
"%Y-%m-%d %H:%M:%S", tm);
356 snprintf(full,
sizeof(full),
"%s.%09ld", date, (
long)ns);
359 snprintf(full,
sizeof(full),
"0d%lu.%09ld",s,(
long)ns);
361 snprintf(full,
sizeof(full),
"0x%016llx", (
unsigned long long)time);
#define GO4_PMODE_VERBOSE
TH1 * hDeltaN
sequence number diff of events
TH1 * hDeltaT_deadline_fine
time difference of subsequent events, fine detail of deadline
TH1 * hDeltaT
"executed" time difference of subsequent events
unsigned fLastEventNumber
remember last mbs event number received
static std::string FormatDate(uint64_t time, uint32_t pmode)
stolen from saftlib to check the real time stamp delivered:
TH1 * hOverflowScaler
scaler for total overflow counter versus timing events without loss
uint64_t fLastTime
remember last time stamp (executed) received
TH1 * hLostSequence
counts lost events by checking leading/trailing edge alternation
TH1 * hOverflowCounts
histogram of increase of overflow counter as taken from action sink.
TH1 * hDeltaT_deadline
"deadline" time difference of subsequent events
TH1 * hDeltaT_coarse
time difference of subsequent events, coarse range overview
Bool_t BuildEvent(TGo4EventElement *)
uint64_t fLastFlipTime
remember last time stamp of large deltat
uint64_t fLastTimeDeadline
remember last time stamp (deadling) received
The saftlib input event data structure.
char fDescription[SAFT_DABC_DESCRLEN]
int InfoMessage(char *str, size_t len)
#define SAFT_DABC_DESCRLEN
length of descriptor text field in timing event structure
uint32_t GetPaddedSize() const
Hadaq subevent structure.