37 if ( ! Watcher::SetTrigger(trigger) ){
43 fFrame = GetTrigger()->GetInputSharedFP();
61 { fFrame->GetFrame()->Dump(fFilename.Data(), fIsNew); fIsNew =
false; }
63 { fFrame->GetFrame()->Dump(fFilename.Data(), fIsNew); }
70 fFilename = filename; fIsNew =
true;
82 fSubKeyFilter(
"*",true),
85 fShowGlobalConf(false),
94 fKeyMessageSubFrame(0x0)
97 fLengthFrame = MakeTH1<TH1F>(
"LengthFrame",
"Length of the Frames (bytes)",
aKByte,0,20*
aKByte);
98 fKeyMessage = MakeTH1<TH1F>(
"KeyMessage",
"Message type", 3,0,3) ;
99 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
100 fKeyMessage->GetXaxis()->SetCanExtend(
true);
102 fKeyMessage->SetBit(TH1::kCanRebin);
104 fEventNumber = MakeTH1<TH1D>(
"EventNumber",
"Last event numbers", kMaxCycle,0.,kMaxCycle) ;
105 fTimeStamp = MakeTH1<TH1D>(
"TimeStamp",
"Last time stamps", kMaxCycle,0.,kMaxCycle) ;
106 fCEventNumber = MakeTH1<TH1F>(
"CEventNumber",
"Consecutive event numbers", 1000,0, 10000) ;
107 fCTimeStamp = MakeTH1<TH1F>(
"CTimeStamp",
"Consecutive time stamps", 1000,0, 10000000) ;
108 fCoincTimeStamp = MakeTH1<TH1F>(
"CoincTimeStamp",
"Time stamp distribution in composite frames", 500,0,1000 ) ;
109 fLengthSubFrame = MakeTH1<TH1F>(
"LengthSubFrame",
"Length of the SubFrames (bytes)",
aKByte,0,20*
aKByte);
110 fKeyMessageSubFrame = MakeTH1<TH1F>(
"KeyMessageSubFrame",
"Message type for SubFrames in Composite Frame", 1,0,1);
111 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
112 fKeyMessageSubFrame->GetXaxis()->SetCanExtend(
true);
114 fKeyMessageSubFrame->SetBit(TH1::kCanRebin);
129 TString stmp1(keypattern), stmp2(subkeypattern);
131 Bool_t wildcard1 =
false, wildcard2 =
false;
132 if ( stmp1.Contains(
"*") )
134 if ( stmp2.Contains(
"*") )
137 TRegexp tmp1(keypattern,wildcard1), tmp2(subkeypattern,wildcard2);
140 if ( tmp1.Status() == TRegexp::kOK ) {
143 if ( tmp2.Status() == TRegexp::kOK ) {
144 fSubKeyFilter = tmp2;
153 if ( option ==
"" ) {
154 c->Divide(3,2,0.001,0.001);
156 fLengthFrame->Draw();
158 fLengthSubFrame->Draw();
160 fEventNumber->Draw();
164 fKeyMessageSubFrame->Draw();
168 if ( option ==
"q" ) {
169 c->Divide(1,3,0.001,0.001);
171 fCEventNumber->Draw();
175 fCoincTimeStamp->Draw();
184 printf(
"AgataKeyWatcher::Exec is called \n");
186 UInt_t length, current, eventnumber, message; ULong64_t timestamp; TString mess, mess_sec, mess_tmp;
203 if ( ! mess.Contains(fKeyFilter) )
207 fLengthFrame->Fill(fKey->
GetFrameLength()); fKeyMessage->Fill(mess.Data(),1);
208 if ( mess.Contains(
"UnknownKey") ) {
209 std::cout <<
" WARNING, unknown key " <<
std::endl;
220 (*buf) >> eventnumber;
223 else (*buf) >> timestamp;
227 if ( fWhichBin == -1 ) {
228 fLastEventNumber = eventnumber;
229 flastTimestamp = timestamp;
234 fEventNumber->Fill(fWhichBin,eventnumber);
235 fTimeStamp->Fill(fWhichBin,timestamp);
237 fCEventNumber->Fill(eventnumber-fLastEventNumber);
238 fCTimeStamp->Fill(timestamp-flastTimestamp);
255 fLastEventNumber = eventnumber;
256 flastTimestamp = timestamp;
259 if ( mess.Contains(
"conf") && fShowGlobalConf ) {
260 FILE *fp; Short_t which = 0;
261 while ( which < 20 ) {
262 if ( gSystem->AccessPathName(Form(
"./%s%d.conf",mess.Data(),which)) )
266 fp = ::fopen(Form(
"./%s%d.conf",mess.Data(),which),
"w");
fFrame->
GetFrame()->
Dump(fp); ::fclose(fp);
268 if ( mess.Contains(
"event") ) {
270 fKeyMessageSubFrame->Fill(mess.Data(),1);
273 Bool_t is_a_start =
false; Short_t max_loop = 0u;
278 if ( max_loop++ == 10u )
279 {
fLog <<
" Max has been reached in scan of composite frame " <<
nline;
break; }
283 (*buf) >> length >> message >> eventnumber >> timestamp ;
285 mess_tmp = AgataKeyFactory::theFactory()->GetMessage(message);
288 if ( mess_tmp.Contains(
"UnknownKey") ) {
291 else is_a_start =
true;
298 mess_sec += mess_tmp;
301 mess_sec = Form(
"|%s|",mess_tmp.Data());
303 if ( mess_tmp.Contains(fSubKeyFilter ) ) {
305 fLengthSubFrame->Fill(length);
306 fKeyMessageSubFrame->Fill(mess_sec.Data(),1);
308 fCoincTimeStamp->Fill(timestamp-flastTimestamp);
315 if ( fWhichBin == kMaxCycle ) {
317 fEventNumber->Reset(
"ICE"); fTimeStamp->Reset(
"ICE");
326 TSRate::TSRate(
const Char_t *name,
const Char_t *title, TDirectory *sp_dir, TDirectory *tag_dir) :
342 if ( fTSRates.size() > 0 ) {
343 if ( fTSRates.back() < ts )
344 fTSRates.push_back( ts ) ;
348 else fTSRates.push_back( ts ) ;
363 Watcher(name,title,sp_dir,tag_dir),
372 fTSRates.SetOwner(
false); fPacketWidth.SetOwner(
false); fDeadTime.SetOwner(
false);
386 ULong64_t val, min = kMaxULong64;
389 TIter next(&fTSRates);
391 while ( (ts_rate = (
TSRate *)next()) ) {
401 for (Int_t i = 0; i < fRates.GetHists()->GetSize(); i++) {
404 fCurrentRate[i].Reset(fDefinitionRate.
fNbScales);
406 if ( fRates.GetHists()->At(i) == 0x0 )
408 TString
tmp = fRates.GetHists()->At(i)->GetName();
410 tmp += dt.AsString();
412 ((TH1 *)fRates.GetHists()->At(i))->Reset();
413 ((TH1 *)fRates.GetHists()->At(i))->SetTitle(tmp.Data());
417 std::cout <<
" New TIMESTAMP in TSRateCollector" << fT0 <<
std::endl;
420 return (fT0 != kMaxULong64);
427 const Short_t wheel_size = 5;
428 Color_t color_wheel[wheel_size] = { kBlue, kGreen+2, kOrange, kRed, kViolet };
429 Style_t style_wheel[wheel_size] = { 3001, 3002, 3003, 3004, 3005 };
431 if ( !ts_rate->InheritsFrom(
"TSRate") )
436 fTSRates.Add ( ts_rate );
437 C_Rate c_rate(fDefinitionRate.
fNbScales); fCurrentRate.push_back( c_rate );
440 TString hname = fd_name;
444 for (Int_t i = 0; i < fDefinitionRate.
fNbScales; i++)
445 hsize += fDefinitionRate.
fNbSamples[i] + gEmptyBins;
448 TH1F *h = MakeTH1<TH1F>(hname.Data(),
"Rate",hsize,0,hsize);
450 h->SetFillColor(color_wheel[(fRates.GetHists()->GetSize()-1)%wheel_size]);
451 h->SetFillStyle(style_wheel[(fRates.GetHists()->GetSize()-1)%wheel_size]);
452 h->SetXTitle(
"[0][30s/bin = 1hour] -- [170][10m/bin = 12hours] -- [292][1h/bin = 2days]");
455 hname = fd_name; hname +=
"_Width";
456 h = MakeTH1<TH1F>(hname.Data(),
"Width distribution of packets (s)",200,0,20);
458 h->SetFillColor(color_wheel[(fRates.GetHists()->GetSize()-1)%wheel_size]);
459 h->SetFillStyle(style_wheel[(fRates.GetHists()->GetSize()-1)%wheel_size]);
461 hname = fd_name; hname +=
"_Deadtime";
462 h = MakeTH1<TH1F>(hname.Data(),
"Dead time distribution between consecutive packets (s)",100,0,100);
464 h->SetFillColor(color_wheel[(fRates.GetHists()->GetSize()-1)%wheel_size]);
465 h->SetFillStyle(style_wheel[(fRates.GetHists()->GetSize()-1)%wheel_size]);
473 Int_t nbcolumn = 3; c->Divide(nbcolumn,fRates.GetHists()->GetSize()/nbcolumn,0.001,0.001);
475 for (Int_t i = 0; i < fRates.GetHists()->GetSize(); i++) {
477 TH1 *h = (TH1F *)fRates.GetHists()->At(i);
482 TString cmd = Form(
"RunLoupeOnPad( (TCanvas *)gROOT->GetListOfCanvases()->FindObject(\"%s\") )", c->GetName());
483 gROOT->ProcessLine(cmd.Data());
492 TSRate *ts_rate; TH1 *h; ULong64_t dt0, dt, slot, cycle;
495 printf(
"TSRateCollector::Exec is called \n");
497 if ( fTSRates.GetSize() == 0 )
502 printf(
" WARNING in TSRateCollector::Exec Cannot get First timestamp \n");
508 for (Int_t i = 0; i < fTSRates.GetSize(); i++) {
511 ts_rate = (
TSRate *)fTSRates.At(i);
521 h = (TH1F *)fPacketWidth.At(i);
526 h = (TH1F *)fDeadTime.At(i);
527 if ( ts_rate->
LastValues().at(0) > fCurrentRate[i].fLastTS ) {
550 h = (TH1F *)fRates.GetHists()->At(i);
552 for (
size_t j = 1; j < ts_rate->
LastValues().size(); j++) {
555 std::cout <<
" ERROR Timestamp in array smaller that T0 " <<
std::endl;
566 for (Int_t k = 0; k < fDefinitionRate.
fNbScales; k++) {
570 if ( cycle == fCurrentRate[i].fCycle[k] ) {
571 fCurrentRate[i].fSum[k] += dt;
572 fCurrentRate[i].fNbCounts[k]++;
577 slot = fCurrentRate[i].fCycle[k] % fDefinitionRate.
fNbSamples[k];
586 if ( fCurrentRate[i].fSum[k] > 0
587 && ((slot+h0+1) < UInt_t(h->GetNbinsX()))
588 && ((slot+h0+1) > 0) ) {
589 h->SetBinContent(slot+h0+1,fCurrentRate[i].fNbCounts[k]*to_rate/fCurrentRate[i].fSum[k]);
592 std::cout <<
" SUM is O !! "
593 << fCurrentRate[i].fSum[k] <<
" j " << j <<
" " << ts_rate->
LastValues().size()
594 <<
" " << fCurrentRate[i].fNbCounts[k] <<
" " << dt <<
std::endl;
602 fCurrentRate[i].fSum[k] = dt;
603 fCurrentRate[i].fNbCounts[k] = 1;
605 fCurrentRate[i].fCycle[k] = cycle;
607 h0 += (fDefinitionRate.
fNbSamples[k] + gEmptyBins);
615 printf(
"TSRateCollector::Exec is done \n");
626 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 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 &)
keep some values to compute rates
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)
*/
void Add(ULong64_t precision, Int_t nb_samples)
precision is given in TS unit (use fgkOneSecond for conversion)
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.