35 if ( ! Watcher::SetTrigger(trigger) ){
41 fFrame = GetTrigger()->GetInputSharedFP();
56 { fFrame->GetFrame()->Dump(fFilename.Data(), fIsNew); fIsNew =
false; }
58 { fFrame->GetFrame()->Dump(fFilename.Data(), fIsNew); }
62 fFilename = filename; fIsNew =
true;
71 fSubKeyFilter(
"*",true),
74 fShowGlobalConf(false),
83 fKeyMessageSubFrame(0x0)
86 fLengthFrame = MakeTH1<TH1F>(
"LengthFrame",
"Length of the Frames (bytes)",
aKByte,0,20*
aKByte);
87 fKeyMessage = MakeTH1<TH1F>(
"KeyMessage",
"Message type", 3,0,3) ;
88 fKeyMessage->SetBit(TH1::kCanRebin);
89 fEventNumber = MakeTH1<TH1D>(
"EventNumber",
"Last event numbers", kMaxCycle,0.,kMaxCycle) ;
90 fTimeStamp = MakeTH1<TH1D>(
"TimeStamp",
"Last time stamps", kMaxCycle,0.,kMaxCycle) ;
91 fCEventNumber = MakeTH1<TH1F>(
"CEventNumber",
"Consecutive event numbers", 1000,0, 10000) ;
92 fCTimeStamp = MakeTH1<TH1F>(
"CTimeStamp",
"Consecutive time stamps", 1000,0, 10000000) ;
93 fCoincTimeStamp = MakeTH1<TH1F>(
"CoincTimeStamp",
"Time stamp distribution in composite frames", 500,0,1000 ) ;
94 fLengthSubFrame = MakeTH1<TH1F>(
"LengthSubFrame",
"Length of the SubFrames (bytes)",
aKByte,0,20*
aKByte);
95 fKeyMessageSubFrame = MakeTH1<TH1F>(
"KeyMessageSubFrame",
"Message type for SubFrames in Composite Frame", 1,0,1);
96 fKeyMessageSubFrame->SetBit(TH1::kCanRebin);
106 TString stmp1(keypattern), stmp2(subkeypattern);
108 Bool_t wildcard1 =
false, wildcard2 =
false;
109 if ( stmp1.Contains(
"*") )
111 if ( stmp2.Contains(
"*") )
114 TRegexp tmp1(keypattern,wildcard1), tmp2(subkeypattern,wildcard2);
117 if ( tmp1.Status() == TRegexp::kOK ) {
120 if ( tmp2.Status() == TRegexp::kOK ) {
121 fSubKeyFilter = tmp2;
128 if ( option ==
"" ) {
129 c->Divide(3,2,0.001,0.001);
131 fLengthFrame->Draw();
133 fLengthSubFrame->Draw();
135 fEventNumber->Draw();
139 fKeyMessageSubFrame->Draw();
143 if ( option ==
"q" ) {
144 c->Divide(1,3,0.001,0.001);
146 fCEventNumber->Draw();
150 fCoincTimeStamp->Draw();
157 printf(
"AgataKeyWatcher::Exec is called \n");
159 UInt_t length, current, eventnumber, message; ULong64_t timestamp; TString mess, mess_sec, mess_tmp;
176 if ( ! mess.Contains(fKeyFilter) )
180 fLengthFrame->Fill(fKey->
GetFrameLength()); fKeyMessage->Fill(mess.Data(),1);
181 if ( mess.Contains(
"UnknownKey") ) {
182 std::cout <<
" WARNING, unknown key " <<
std::endl;
193 (*buf) >> eventnumber;
196 else (*buf) >> timestamp;
200 if ( fWhichBin == -1 ) {
201 fLastEventNumber = eventnumber;
202 flastTimestamp = timestamp;
207 fEventNumber->Fill(fWhichBin,eventnumber);
208 fTimeStamp->Fill(fWhichBin,timestamp);
210 fCEventNumber->Fill(eventnumber-fLastEventNumber);
211 fCTimeStamp->Fill(timestamp-flastTimestamp);
228 fLastEventNumber = eventnumber;
229 flastTimestamp = timestamp;
232 if ( mess.Contains(
"conf") && fShowGlobalConf ) {
233 FILE *fp; Short_t which = 0;
234 while ( which < 20 ) {
235 if ( gSystem->AccessPathName(Form(
"./%s%d.conf",mess.Data(),which)) )
239 fp = ::fopen(Form(
"./%s%d.conf",mess.Data(),which),
"w");
fFrame->
GetFrame()->
Dump(fp); ::fclose(fp);
241 if ( mess.Contains(
"event") ) {
243 fKeyMessageSubFrame->Fill(mess.Data(),1);
246 Bool_t is_a_start =
false; Short_t max_loop = 0u;
251 if ( max_loop++ == 10u )
252 {
fLog <<
" Max has been reached in scan of composite frame " <<
nline;
break; }
256 (*buf) >> length >> message >> eventnumber >> timestamp ;
258 mess_tmp = AgataKeyFactory::theFactory()->GetMessage(message);
261 if ( mess_tmp.Contains(
"UnknownKey") ) {
264 else is_a_start =
true;
271 mess_sec += mess_tmp;
274 mess_sec = Form(
"|%s|",mess_tmp.Data());
276 if ( mess_tmp.Contains(fSubKeyFilter ) ) {
278 fLengthSubFrame->Fill(length);
279 fKeyMessageSubFrame->Fill(mess_sec.Data(),1);
281 fCoincTimeStamp->Fill(timestamp-flastTimestamp);
288 if ( fWhichBin == kMaxCycle ) {
290 fEventNumber->Reset(
"ICE"); fTimeStamp->Reset(
"ICE");
297 TSRate::TSRate(
const Char_t *name,
const Char_t *title, TDirectory *sp_dir, TDirectory *tag_dir) :
311 if ( fTSRates.size() > 0 ) {
312 if ( fTSRates.back() < ts )
313 fTSRates.push_back( ts ) ;
317 else fTSRates.push_back( ts ) ;
328 Watcher(name,title,sp_dir,tag_dir),
337 fTSRates.SetOwner(
false); fPacketWidth.SetOwner(
false); fDeadTime.SetOwner(
false);
340 fDefinitionRate.
Add(30*fgkOneSecond,120);
342 fDefinitionRate.Add(600*fgkOneSecond,72);
344 fDefinitionRate.Add(3600*fgkOneSecond,48);
349 ULong64_t val, min = kMaxULong64;
352 TIter next(&fTSRates);
354 while ( (ts_rate = (
TSRate *)next()) ) {
364 for (Int_t i = 0; i < fRates.GetHists()->GetSize(); i++) {
367 fCurrentRate[i].Reset(fDefinitionRate.
fNbScales);
369 if ( fRates.GetHists()->At(i) == 0x0 )
371 TString
tmp = fRates.GetHists()->At(i)->GetName();
373 tmp += dt.AsString();
375 ((TH1 *)fRates.GetHists()->At(i))->Reset();
376 ((TH1 *)fRates.GetHists()->At(i))->SetTitle(tmp.Data());
380 std::cout <<
" New TIMESTAMP in TSRateCollector" << fT0 <<
std::endl;
383 return (fT0 != kMaxULong64);
388 const Short_t wheel_size = 5;
389 Color_t color_wheel[wheel_size] = { kBlue, kGreen+2, kOrange, kRed, kViolet };
390 Style_t style_wheel[wheel_size] = { 3001, 3002, 3003, 3004, 3005 };
392 if ( !ts_rate->InheritsFrom(
"TSRate") )
397 fTSRates.Add ( ts_rate );
398 C_Rate c_rate(fDefinitionRate.
fNbScales); fCurrentRate.push_back( c_rate );
401 TString hname = fd_name;
405 for (Int_t i = 0; i < fDefinitionRate.
fNbScales; i++)
406 hsize += fDefinitionRate.
fNbSamples[i] + gEmptyBins;
409 TH1F *h = MakeTH1<TH1F>(hname.Data(),
"Rate",hsize,0,hsize);
411 h->SetFillColor(color_wheel[(fRates.GetHists()->GetSize()-1)%wheel_size]);
412 h->SetFillStyle(style_wheel[(fRates.GetHists()->GetSize()-1)%wheel_size]);
413 h->SetXTitle(
"[0][30s/bin = 1hour] -- [170][10m/bin = 12hours] -- [292][1h/bin = 2days]");
416 hname = fd_name; hname +=
"_Width";
417 h = MakeTH1<TH1F>(hname.Data(),
"Width distribution of packets (s)",200,0,20);
419 h->SetFillColor(color_wheel[(fRates.GetHists()->GetSize()-1)%wheel_size]);
420 h->SetFillStyle(style_wheel[(fRates.GetHists()->GetSize()-1)%wheel_size]);
422 hname = fd_name; hname +=
"_Deadtime";
423 h = MakeTH1<TH1F>(hname.Data(),
"Dead time distribution between consecutive packets (s)",100,0,100);
425 h->SetFillColor(color_wheel[(fRates.GetHists()->GetSize()-1)%wheel_size]);
426 h->SetFillStyle(style_wheel[(fRates.GetHists()->GetSize()-1)%wheel_size]);
432 Int_t nbcolumn = 3; c->Divide(nbcolumn,fRates.GetHists()->GetSize()/nbcolumn,0.001,0.001);
434 for (Int_t i = 0; i < fRates.GetHists()->GetSize(); i++) {
436 TH1 *h = (TH1F *)fRates.GetHists()->At(i);
441 TString cmd = Form(
"RunLoupeOnPad( (TCanvas *)gROOT->GetListOfCanvases()->FindObject(\"%s\") )", c->GetName());
442 gROOT->ProcessLine(cmd.Data());
451 TSRate *ts_rate; TH1 *h; ULong64_t dt0, dt, slot, cycle;
454 printf(
"TSRateCollector::Exec is called \n");
456 if ( fTSRates.GetSize() == 0 )
461 printf(
" WARNING in TSRateCollector::Exec Cannot get First timestamp \n");
467 for (Int_t i = 0; i < fTSRates.GetSize(); i++) {
470 ts_rate = (
TSRate *)fTSRates.At(i);
480 h = (TH1F *)fPacketWidth.At(i);
485 h = (TH1F *)fDeadTime.At(i);
486 if ( ts_rate->
LastValues().at(0) > fCurrentRate[i].fLastTS ) {
509 h = (TH1F *)fRates.GetHists()->At(i);
511 for (
size_t j = 1; j < ts_rate->
LastValues().size(); j++) {
514 std::cout <<
" ERROR Timestamp in array smaller that T0 " <<
std::endl;
525 for (Int_t k = 0; k < fDefinitionRate.
fNbScales; k++) {
529 if ( cycle == fCurrentRate[i].fCycle[k] ) {
530 fCurrentRate[i].fSum[k] += dt;
531 fCurrentRate[i].fNbCounts[k]++;
536 slot = fCurrentRate[i].fCycle[k] % fDefinitionRate.
fNbSamples[k];
545 if ( fCurrentRate[i].fSum[k] > 0
546 && ((slot+h0+1) < UInt_t(h->GetNbinsX()))
547 && ((slot+h0+1) > 0) ) {
548 h->SetBinContent(slot+h0+1,fCurrentRate[i].fNbCounts[k]*to_rate/fCurrentRate[i].fSum[k]);
551 std::cout <<
" SUM is O !! "
552 << fCurrentRate[i].fSum[k] <<
" j " << j <<
" " << ts_rate->
LastValues().size()
553 <<
" " << fCurrentRate[i].fNbCounts[k] <<
" " << dt <<
std::endl;
561 fCurrentRate[i].fSum[k] = dt;
562 fCurrentRate[i].fNbCounts[k] = 1;
564 fCurrentRate[i].fCycle[k] = cycle;
566 h0 += (fDefinitionRate.
fNbSamples[k] + gEmptyBins);
574 printf(
"TSRateCollector::Exec is done \n");
584 TimeStampHist = MakeTH1<TH1F>(
"TimeStampHist",
"Time stamp distribution",TMax*10., 0, TMax);
std::vector< Int_t > fNbSamples
virtual Bool_t IsValid() const
true if it is a valid pointer
void SetOutputFile(const Char_t *filename)
******************************************************************************************/// ...
virtual void Exec(Option_t *option="")
watch the current frame
virtual Key * GetKey()=0
To get the Key associated to this frame.
SharedFP * fFrame
the frame to be watched
printf("******************************************************************** \n")
virtual void Add(TTask *)
add only Watchers to the list of tasks to avoid problems.
virtual Frame * GetFrame() const
virtual void Exec(Option_t *option="")
watch the current frame
virtual void DoCanvas(TCanvas *c, Option_t *)
To be overwritten by real implementation if a canvas is produced.
Bool_t SetT0()
******************************************************************************************/// ...
Just dump the frame in a file.
void AddHook(Watcher *, const char *)
Add a timestamp rate.
Watcher to keep last TS values.
AgataKeyWatcher(const Char_t *name, const Char_t *title, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
*/
virtual const BufferIO * GetRealBuffer() const =0
give access to the underlying buffer of the data part
static const ULong64_t fgkOneSecond
virtual Bool_t SetTrigger(ADF::DFTrigger *=0x0)
Set the Frame to be watched.
LogMessage & nline(LogMessage &)
virtual void Print(std::ostream &out=std::cout) const
Print the content of the key.
virtual ULong64_t GetTimeStamp() const =0
To set the timestamp.
Base class for a Watcher.
UInt_t Offset() const
it returns the current position in the buffer
virtual void Exec(Option_t *option="")
watch the current frame
TSRateCollector(const Char_t *name, const Char_t *title, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
*/
To check and display the Data Flow structure by the key content of the frame.
virtual void DoCanvas(TCanvas *c, Option_t *)
To be overwritten by real implementation if a canvas is produced.
virtual void Zero(Option_t *opt1, Option_t *opt2)
******************************************************************************************/// ...
virtual ~TimeStampWatcher()
******************************************************************************************/// ...
virtual void DoCanvas(TCanvas *c, Option_t *)
To be overwritten by real implementation if a canvas is produced.
UInt_t FreeSize() const
it returns the number of free bytes to the end
std::vector< ULong64_t > fPrecision
TimeStampWatcher(const char *name, const char *title, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
*/
virtual void Exec(Option_t *option="")
******************************************************************************************/// ...
TSRate(const Char_t *name, const Char_t *title, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
*/
Base class for a trigger on a data flow.
ADF::LogMessage & endl(ADF::LogMessage &log)
void SetKeyFilter(const Char_t *keypattern="*", const Char_t *subkeypattern="*")
change the filters applied on the main key and on subkeys
virtual void Exec(Option_t *option="")
watch the current frame
virtual UInt_t GetFrameLength() const
Base Watcher working for any kind of Frame (Frame interface)
virtual void Dump(const Char_t *filename, Bool_t anew=false) const =0
Dump the content of the frame in a file (for debugging)
std::vector< ULong64_t > & LastValues()
virtual ~AgataKeyWatcher()
******************************************************************************************/// ...
virtual UInt_t GetMessage() const =0
To get the message type encoded.
compute histograms for several TSRate
UInt_t SetOffset(UInt_t off=0u) const
change the current position.