9 #include "TPaveStats.h"
10 #include "TPaveText.h"
18 #include "BashColor.h"
23 Watcher(name,title,sp_dir,tag_dir),
28 fNBackwardInBackwardTS(0),
41 fHistInSec = MakeTH1<TH1F>((TString)name+
"_1hour",(TString)title+
" on 1 hour (1bin=100#mus)",36000,0,3600);
42 fHistInMin = MakeTH1<TH1F>((TString)name+
"_12hour",(TString)title+
" on 12 hour (1bin=6s)",7200,0,720);
43 fHistInH = MakeTH1<TH1F>((TString)name+
"_2days",(TString)title+
" on 2 days (1bin=6min)",480,0,48);
45 fHistInSec0 = MakeTH1<TH1F>((TString)name+
"_1hour_0",(TString)title+
" on 1 hour for 0 values (1bin=100#mus)",36000,0,3600);
46 fHistInMin0 = MakeTH1<TH1F>((TString)name+
"_12hour_0",(TString)title+
" on 12 hour for 0 values (1bin=6s)",7200,0,720);
47 fHistInH0 = MakeTH1<TH1F>((TString)name+
"_2days_0",(TString)title+
" on 2 days for 0 values (1bin=6min)",480,0,48);
49 fHistInSecMetaSync = MakeTH1<TH1F>((TString)name+
"_1hour_MetaSync",(TString)title+
" on 1 hour for meta sync frames (1bin=100#mus)",36000,0,3600);
50 fHistInMinMetaSync = MakeTH1<TH1F>((TString)name+
"_12hour_MetaSync",(TString)title+
" on 12 hour for meta sync frames (1bin=6s)",7200,0,720);
51 fHistInHMetaSync = MakeTH1<TH1F>((TString)name+
"_2days_MetaSync",(TString)title+
" on 2 days for meta sync frames (1bin=6min)",480,0,48);
54 fHistMessageType = MakeTH1<TH1I>(
"MessageType",
"Message type",NMess,0,NMess);
55 TString labels[NMess] = {
"event:data",
"event:data:psa",
"",
"data:tracked",
"data:psa",
"data:ranc0",
"data:ccrystal",
"data:crystal",
"conf:global",
"meta:sync"};
56 for(
int i=0 ; i<NMess ; i++)
fHistMessageType->GetXaxis()->SetBinLabel(i+1,labels[i]);
58 fHistFold = MakeTH1<TH1I>(
"CrystalFold",
"CrystalFold",20,0,20);
60 fHistDTPSA = MakeTH1<TH1I>(
"TimeStampSpreadPSA",
"Time stamp spread in the event:data:psa frame",190,0,1900);
62 fHistDTEvent = MakeTH1<TH1I>(
"TS_vamos-TS_agata",
"Time stamp spread in the event:data frame",600,-3000,3000);
64 fHistDTPerCrystal = MakeTH2<TH2I>(
"TimeStampSpreadPerCrystal",
"Time stamp spread in the event:data:psa frame per crystal ID",50,0,50,190,0,1900);
66 fHistDTEventPerCrystal = MakeTH2<TH2I>(
"Tvamos-TAgata_per_crystal",
"Time VAMOS - Time AGATA per crystal",50,0,50,600,-3000,3000);
81 if ( ! Watcher::SetTrigger(trigger) ){
89 if ( dynamic_cast<AgataFrameTrigger *> (
GetTrigger())) {
99 TString opt = (TString)option;
104 if(opt.Contains(
"same")) c = (TCanvas*)gPad->GetCanvas();
107 TString Name = (TString)GetName() +
"_TSDist";
108 TString Title = (TString)GetTitle() +
" time stamp distribution";
110 c->Divide(1,3,0.001,0.001);
116 for(
int k=0 ; k<c->cd(1)->GetListOfPrimitives()->GetSize() ; k++)
118 if(c->cd(1)->GetListOfPrimitives()->At(k)->InheritsFrom(
"TH1"))col++;
121 double topmarg = 0.00667084;
122 double rightmarg = 0.00200251;
123 double leftmarg = 0.0373055;
124 double bottommarg = 0.155235;
131 opt.ReplaceAll(
" ",
"");
133 if(opt.Contains(
"0"))
136 opt.ReplaceAll(
"0",
"");
138 if(opt.Contains(
"meta",TString::kIgnoreCase))
141 opt.ReplaceAll(
"meta",
"");
145 TString titles[3] = {
"Time [1h] (s)",
"Time [12h] (min)",
"Time [2d] (h)"};
147 for(
int i=0 ; i<3 ; i++)
151 gPad->SetRightMargin(rightmarg);
152 gPad->SetTopMargin(topmarg);
153 gPad->SetLeftMargin(leftmarg);
154 gPad->SetBottomMargin(bottommarg);
161 if(!opt.Contains(
"same"))
163 htemp->GetXaxis()->SetTitle(titles[i]);
164 htemp->GetXaxis()->SetTitleSize(0.08);
165 htemp->GetXaxis()->SetLabelSize(0.08);
166 htemp->GetXaxis()->SetTitleOffset(0.91);
168 htemp->GetYaxis()->SetTitle(
"Rate (Counts/s)");
169 htemp->GetYaxis()->SetTitleSize(0.08);
170 htemp->GetYaxis()->SetLabelSize(0.08);
171 htemp->GetYaxis()->SetTitleOffset(0.25);
189 TString MessageType = AgataKeyFactory::theFactory()->GetMessage(MainKey->
GetMessage());
193 if(MessageType==
"conf:global" || MessageType==
"meta:sync")
217 TTask *FD = ((TTask*)gROOT->GetListOfTasks()->FindObject(
"FD"));
218 TList *ListOfTasks = 0x0;
219 if(FD) ListOfTasks = FD->GetListOfTasks();
221 TIter it(ListOfTasks);
223 while( (o=it.Next()) )
225 if(((TString)o->GetName()).Contains(
"Univ"))
232 if(UnivKey && ! ((TString)GetName()).Contains(
"Keys_Univ"))
247 double TSinMin = fmod((fTimestamp-
FirstTimeStamp)*10*1e-9/60.,720);
248 double TSinH = fmod((fTimestamp-
FirstTimeStamp)*10*1e-9/3600.,48);
281 if(fTimestamp<LastTimeStamp)
283 if(TMath::Abs(((
double)fTimestamp-(
double)
FirstTimeStamp)*10*1e-9 < 1.))
321 LastTimeStamp = fTimestamp;
328 cout<<
"WARNING ! Unknown message type : "<<MessageType<<
endl;
331 UInt_t length, current, eventnumber, message; ULong64_t timestamp; TString SubMess;
346 double DTEventPC[50];
347 ULong64_t TimeAGATA=0;
348 ULong64_t TimeAGATAPC[50];
349 for(
int i=0 ; i<50 ; i++) TimeAGATA = 0;
350 ULong64_t TimeVamos=0;
351 bool IsVamos =
false;
352 bool IsAGATA =
false;
354 if ( MessageType.Contains(
"event") )
357 bool is_a_start =
false;
367 (*fBufferToRead) >> length >> message >> eventnumber >> timestamp ;
368 SubMess = AgataKeyFactory::theFactory()->GetMessage(message);
376 if ( SubMess.Contains(
"UnknownKey") ) {
379 else is_a_start =
true;
384 if(!
fHistMessageType->GetXaxis()->FindBin(SubMess)) cout<<
"WARNING ! Unknown sub-message type : "<<SubMess<<
endl;
388 if(SubMess==
"event:data:psa")
390 UInt_t sublength, subcurrent, subeventnumber, submessage; ULong64_t subtimestamp; TString SubSubMess;
392 UInt_t TotSubLenght = 20;
395 while ( TotSubLenght<length )
399 (*fBufferToRead) >> sublength >> submessage >> subeventnumber >> subtimestamp ;
401 SubSubMess = AgataKeyFactory::theFactory()->GetMessage(submessage);
405 if(SubSubMess ==
"data:psa")
408 double DTPsa = (subtimestamp-timestamp)*10;
415 UInt_t crysal_id = data->
GetUID();
419 TimeAGATAPC[crysal_id] = subtimestamp;
422 TotSubLenght += sublength;
426 subcurrent+=sublength;
428 if(MessageType==
"event:data")
430 TimeAGATA = timestamp;
436 if(SubMess==
"data:ranc0" && MessageType==
"event:data")
438 TimeVamos = timestamp;
443 if(SubMess==
"data:psa")
446 double DTPsa = (timestamp-fTimestamp)*10;
453 UInt_t crysal_id = data->
GetUID();
471 DTEvent = (double)(TimeVamos*1.-TimeAGATA*1.)*10;
473 for(
int i=0 ; i<50 ; i++)
475 if(TimeAGATAPC[i]!=0)
477 DTEventPC[i] = (TimeVamos*1.-TimeAGATAPC[i]*1.)*10;
486 TString opt = option;
488 if(opt.Contains(
"1") || opt.Contains(
"all"))
494 if(opt.Contains(
"2") || opt.Contains(
"all"))
500 if(opt.Contains(
"3") || opt.Contains(
"all"))
507 TCanvas *c = gPad->GetCanvas();
508 for(
int k=0 ; k<c->GetListOfPrimitives()->GetSize() ; k++)
510 TPad *pad = (TPad*)c->cd(k);
524 TString Name = fName +
"_MessType";
525 TString Title = fTitle +
" Message Type";
529 c->Divide(2,2,0.001,0.001);
533 double topmarg = 0.0560089;
534 double rightmarg = 0.01455;
535 double leftmarg = 0.0747608;
536 double bottommarg = 0.0962985;
538 gPad->SetRightMargin(rightmarg);
539 gPad->SetTopMargin(topmarg);
540 gPad->SetLeftMargin(leftmarg);
541 gPad->SetBottomMargin(bottommarg);
559 st->SetX2NDC(1-rightmarg);
560 st->SetY2NDC(1-topmarg);
565 gPad->SetRightMargin(rightmarg);
566 gPad->SetTopMargin(topmarg);
567 gPad->SetLeftMargin(leftmarg);
568 gPad->SetBottomMargin(bottommarg);
571 fHistFold->GetYaxis()->SetTitle(
"Counts");
572 fHistFold->GetYaxis()->SetTitleSize(0.05);
573 fHistFold->GetYaxis()->SetLabelSize(0.05);
574 fHistFold->GetYaxis()->SetTitleOffset(0.8);
577 fHistFold->GetXaxis()->SetTitleSize(0.05);
578 fHistFold->GetXaxis()->SetLabelSize(0.05);
584 st = (TPaveStats*)
fHistFold->FindObject(
"stats");
587 st->SetX2NDC(1-rightmarg);
588 st->SetY2NDC(1-topmarg);
591 c->cd(3)->Divide(1,2,0.001,0.001);
594 rightmarg = 0.00310682;
595 leftmarg = 0.0660825;
596 bottommarg = 0.175578;
600 gPad->SetRightMargin(rightmarg);
601 gPad->SetTopMargin(topmarg);
602 gPad->SetLeftMargin(leftmarg);
603 gPad->SetBottomMargin(bottommarg);
612 fHistDTPSA->GetXaxis()->SetTitle(
"#DeltaT Psa (ns)");
620 st = (TPaveStats*)
fHistDTPSA->FindObject(
"stats");
623 st->SetX2NDC(1-rightmarg);
624 st->SetY2NDC(1-topmarg);
625 st->SetX1NDC(0.743455);
626 st->SetY1NDC(0.672483);
630 gPad->SetRightMargin(rightmarg);
631 gPad->SetTopMargin(topmarg);
632 gPad->SetLeftMargin(leftmarg);
633 gPad->SetBottomMargin(bottommarg);
642 fHistDTEvent->GetXaxis()->SetTitle(
"#DeltaT Event (ns)");
653 st->SetX2NDC(1-rightmarg);
654 st->SetY2NDC(1-topmarg);
655 st->SetX1NDC(0.743455);
656 st->SetY1NDC(0.672483);
659 c->cd(4)->Divide(1,2,0.001,0.001);
662 gPad->SetRightMargin(rightmarg);
663 gPad->SetTopMargin(topmarg);
664 gPad->SetLeftMargin(leftmarg);
665 gPad->SetBottomMargin(bottommarg);
685 st->SetX2NDC(1-rightmarg);
686 st->SetY2NDC(1-topmarg);
691 gPad->SetRightMargin(rightmarg);
692 gPad->SetTopMargin(topmarg);
693 gPad->SetLeftMargin(leftmarg);
694 gPad->SetBottomMargin(bottommarg);
714 st->SetX2NDC(1-rightmarg);
715 st->SetY2NDC(1-topmarg);
724 std::ostringstream filename;
725 int fCurrentFileNumber = 0;
726 filename << (TString)GetName() +
"_" << std::setfill(
'0') << std::setw(4) << fCurrentFileNumber <<
".keys";
728 while(gSystem->IsFileInIncludePath(filename.str().data()))
731 filename << (TString)GetName() +
"_" << std::setfill(
'0') << std::setw(4) << fCurrentFileNumber++ <<
".keys";
738 cout<<
"Keys will be dumped in the file : "<<fFileName<<
endl;
751 cout<<
"Keys dumping already active"<<
endl;
756 cout<<
"Keys dumping is not active"<<
endl;
767 int size = 3 + 3 + ((TString)GetName()).Length() + 5 + ((TString)GetTitle()).Length() + 3 + 3;
768 for(
int i=0; i<
size ; i++) std::cout<<
"*";
770 std::cout<<
"*** "<<GetName()<<
" --- "<<GetTitle()<<
" ***"<<
std::endl;
771 for(
int i=0; i<
size ; i++) std::cout<<
"*";
774 std::cout<<
"Number of treated events : "<<fNevts<<
std::endl;
780 if(N!=0) std::cout<<
" ---> "<<label<<
" : "<<N<<
endl;
785 if(fNBackwardTS>0) std::cout<<
"Number of backward timestamps : "<<fNBackwardTS<<
std::endl;
786 if(fNBackwardInBackwardTS>0) std::cout<<
"Number of backward in backward timestamps : "<<fNBackwardInBackwardTS<<
std::endl;
787 if(fNRepeatedEvts>0) std::cout<<
"Number of repeated timestamps : "<<fNRepeatedEvts<<
std::endl;
788 if(fNBackwardTS>0) std::cout<<
"Mean number of repeated TS per backward : "<<(double)fNRepeatedEvts/(
double)fNBackwardTS<<
std::endl;
798 int TH = (int)(TotalTimeInS/3600.);
799 int TMin = (int)((TotalTimeInS/3600.-TH)*60.);
800 int TSec = (int)(((TotalTimeInS/3600.-TH)*60.-TMin)*60.);
802 std::cout<<
"Elapsed time (s) : "<<TotalTimeInS<<
" ( "<<TH<<
"h"<<TMin<<
"'"<<TSec<<
"'' )"<<
std::endl;
825 fNBackwardInBackwardTS = 0;
virtual const BufferIO * GetRealBuffer() const
virtual Key * GetKey()=0
To get the Key associated to this frame.
virtual Frame * GetFrame() const
Char_t * CurrentAddress()
for classes that needs it to write directly data into it.
virtual UInt_t Read()
It reads the content into dedicated structures from the Frame (data part)
virtual Int_t GetUID() const =0
to get the crystal ID
virtual SharedFP * GetInputSharedFP(UInt_t which=0u)=0
to get back the Shared pointer that define this trigger
void DumpKeys(bool ActiveDump=false)
virtual const BufferIO * GetRealBuffer() const =0
give access to the underlying buffer of the data part
TH2 * fHistDTEventPerCrystal
TCanvas * NewCanvas(TString cname, TString ctitle)
TH1F * fHistInMinMetaSync
header file for AgataCompositeFrame.cpp
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
KeyWatcher(const char *name, const char *title, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
header file for PSAFrame.cpp
virtual UInt_t GetKeyLength() const
Unique number corresponding to a type of Key.
virtual UInt_t GetEventNumber() const =0
To get the event number encoded.
header file for BufferIO.cpp
virtual void Print(const char *option="") const
UInt_t FreeSize() const
it returns the number of free bytes to the end
virtual UInt_t Export(Char_t *, UInt_t) const
Export this buffer to an array.
ULong64_t FirstEventNumber
header file for AgataKeyFactory.cpp
To be used for Agata Data Flow.
ULong64_t lastEventNumber
virtual Bool_t SetTrigger(ADF::DFTrigger *=0x0)
To set the Frames (through a trigger) associated to this watcher.
UInt_t SetEffectiveSize(UInt_t size=kMaxUInt_t)
in case the buffer is partly filled and you would like to read it again
Base class for a trigger on a data flow.
ADF::LogMessage & endl(ADF::LogMessage &log)
virtual Bool_t Copy(const Char_t *, UInt_t, const char= 'b')=0
copy a buffer to this Frame
virtual void Exec(Option_t *option="")
UInt_t Import(const Char_t *from, UInt_t size_ext_buf)
Import the given array in this buffer.
virtual UInt_t GetFrameLength() const
virtual ADF::DFTrigger * GetTrigger() const
To know the trigger in which the frame to be watched is embedded.
TH1F * fHistInSecMetaSync
ULong64_t LastGoodTimeStamp
virtual void ResetTo(const char *option="all")
virtual UInt_t GetMessage() const =0
To get the message type encoded.
virtual void ShowTSDist(const char *option="hist")
UInt_t SetOffset(UInt_t off=0u) const
change the current position.