GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
KeyWatchers.C
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 
4 #include "TH2.h"
5 #include "TH1.h"
6 #include "TCanvas.h"
7 #include "TPad.h"
8 #include "TStyle.h"
9 #include "TPaveStats.h"
10 #include "TPaveText.h"
11 #include "TSystem.h"
12 #include "TDatime.h"
13 #include "BufferIO.h"
14 
15 #include "AgataCompositeFrame.h"
16 #include "AgataKeyFactory.h"
17 #include "PSAFrame.h"
18 #include "BashColor.h"
19 
20 #include "KeyWatchers.h"
21 
22 KeyWatcher::KeyWatcher( const char * name, const char * title, TDirectory *sp_dir, TDirectory *tag_dir):
23  Watcher(name,title,sp_dir,tag_dir),
24  CanvasVisu(name,title),
25  fBashColor(new BashColor()),
26  fNevts(0),
27  fNBackwardTS(0),
28  fNBackwardInBackwardTS(0),
29  fNRepeatedEvts(0),
30  fFrame(0x0),
31  fNNullTS(0),
32  FirstTimeStamp(0),
33  FirstEventNumber(0),
34  LastTimeStamp(0),
35  LastGoodTimeStamp(0),
36  lastEventNumber(0),
37  fLastFillSec(0),
38  fLastFillMin(0),
39  fLastFillH(0)
40 {
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);
44 
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);
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);
52 
53  const int NMess = 10;
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]);
57 
58  fHistFold = MakeTH1<TH1I>("CrystalFold","CrystalFold",20,0,20);
59 
60  fHistDTPSA = MakeTH1<TH1I>("TimeStampSpreadPSA","Time stamp spread in the event:data:psa frame",190,0,1900);
61 
62  fHistDTEvent = MakeTH1<TH1I>("TS_vamos-TS_agata","Time stamp spread in the event:data frame",600,-3000,3000);
63 
64  fHistDTPerCrystal = MakeTH2<TH2I>("TimeStampSpreadPerCrystal","Time stamp spread in the event:data:psa frame per crystal ID",50,0,50,190,0,1900);
65 
66  fHistDTEventPerCrystal = MakeTH2<TH2I>("Tvamos-TAgata_per_crystal","Time VAMOS - Time AGATA per crystal",50,0,50,600,-3000,3000);
67 
68 
69  fBufferToRead = new BufferIO();
70 
71  NextCycleSec = 3600.;
72  NextCycleMin = 720.;
73  NextCycleH = 48.;
74 
75  IsDumpKeysActive = false;
76  fDumpKeyFile = 0x0;
77 }
78 
80 {
81  if ( ! Watcher::SetTrigger(trigger) ){
82  fFrame = 0x0;
83  return false;
84  }
85 
86  // set the unique frame to be watched
88 
89  if ( dynamic_cast<AgataFrameTrigger *> (GetTrigger())) {
90  fPSAFrame = (dynamic_cast<AgataFrameTrigger *> (GetTrigger()))->AddUtility("data:psa",ConfAgent::theGlobalAgent());
91  }
92 
93  return true;
94 }
95 
96 
97 void KeyWatcher::ShowTSDist(const char *option)
98 {
99  TString opt = (TString)option;
100  TCanvas *c = 0x0;
101 
102  opt.ToLower();
103 
104  if(opt.Contains("same")) c = (TCanvas*)gPad->GetCanvas();
105  else
106  {
107  TString Name = (TString)GetName() + "_TSDist";
108  TString Title = (TString)GetTitle() + " time stamp distribution";
109  c = CanvasVisu::NewCanvas(Name,Title);
110  c->Divide(1,3,0.001,0.001);
111  }
112 
113  if(c == 0x0) return;
114 
115  int col = 0;
116  for(int k=0 ; k<c->cd(1)->GetListOfPrimitives()->GetSize() ; k++)
117  {
118  if(c->cd(1)->GetListOfPrimitives()->At(k)->InheritsFrom("TH1"))col++;
119  }
120 
121  double topmarg = 0.00667084;
122  double rightmarg = 0.00200251;
123  double leftmarg = 0.0373055;
124  double bottommarg = 0.155235;
125 
126  TH1F *hnormal[3] = {fHistInSec,fHistInMin,fHistInH};
127  TH1F *h0[3] = {fHistInSec0,fHistInMin0,fHistInH0};
129 
130  TH1F **h;
131  opt.ReplaceAll(" ","");
132  opt.ToLower();
133  if(opt.Contains("0"))
134  {
135  h = h0;
136  opt.ReplaceAll("0","");
137  }
138  if(opt.Contains("meta",TString::kIgnoreCase))
139  {
140  h = hMeta;
141  opt.ReplaceAll("meta","");
142  }
143  else h = hnormal;
144 
145  TString titles[3] = {"Time [1h] (s)","Time [12h] (min)","Time [2d] (h)"};
146 
147  for(int i=0 ; i<3 ; i++)
148  {
149  c->cd(i+1);
150 
151  gPad->SetRightMargin(rightmarg);
152  gPad->SetTopMargin(topmarg);
153  gPad->SetLeftMargin(leftmarg);
154  gPad->SetBottomMargin(bottommarg);
155 
156  TH1F *htemp = h[i];
157 
158  htemp->SetLineColor(GetColor(col));
159  htemp->Draw(opt);
160 
161  if(!opt.Contains("same"))
162  {
163  htemp->GetXaxis()->SetTitle(titles[i]);
164  htemp->GetXaxis()->SetTitleSize(0.08);
165  htemp->GetXaxis()->SetLabelSize(0.08);
166  htemp->GetXaxis()->SetTitleOffset(0.91);
167 
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);
172 
173 
174  htemp->SetStats(0);
175  }
176  gPad->Modified();
177  gPad->Update();
178  }
179 }
180 
181 void KeyWatcher::Exec(Option_t * /*option*/)
182 {
183  AgataKey *MainKey = (AgataKey*)fFrame->GetFrame()->GetKey();
184 
186  ULong64_t fTimestamp = MainKey->GetTimeStamp();
187 
189  TString MessageType = AgataKeyFactory::theFactory()->GetMessage(MainKey->GetMessage());
190 
191  fNevts++;
192 
193  if(MessageType=="conf:global" || MessageType=="meta:sync")
194  {
195  fHistMessageType->Fill(MessageType,1);
196 
197 
199  fHistInMinMetaSync->Fill(fLastFillMin,10./60.);
200  fHistInHMetaSync->Fill(fLastFillH,10./3600.);
201 
202  return;
203  }
204 
205  if(fTimestamp==0)
206  {
207  fHistInSec0->Fill(fLastFillSec,10);
208  fHistInMin0->Fill(fLastFillMin,10./60.);
209  fHistInH0->Fill(fLastFillH,10./3600.);
210 
211  fNNullTS++;
212  return;
213  }
214 
215  if(FirstTimeStamp==0)
216  {
217  TTask *FD = ((TTask*)gROOT->GetListOfTasks()->FindObject("FD"));
218  TList *ListOfTasks = 0x0;
219  if(FD) ListOfTasks = FD->GetListOfTasks();
220  KeyWatcher *UnivKey = 0x0;
221  TIter it(ListOfTasks);
222  TObject *o = 0x0;
223  while( (o=it.Next()) )
224  {
225  if(((TString)o->GetName()).Contains("Univ"))
226  {
227  UnivKey = (KeyWatcher*)o;
228  break;
229  }
230  }
231 
232  if(UnivKey && ! ((TString)GetName()).Contains("Keys_Univ"))
233  {
234  FirstTimeStamp = UnivKey->GetFirstTS();
235  FirstEventNumber = UnivKey->GetFirstEN();
236  }
237  else
238  {
239  FirstTimeStamp = fTimestamp;
240  FirstEventNumber = MainKey->GetEventNumber();
241  }
242 
244  }
245 
246  double TSinSec = fmod((fTimestamp-FirstTimeStamp)*10*1e-9,3600);
247  double TSinMin = fmod((fTimestamp-FirstTimeStamp)*10*1e-9/60.,720);
248  double TSinH = fmod((fTimestamp-FirstTimeStamp)*10*1e-9/3600.,48);
249 
250 
251  if(LastTimeStamp!=0 && TMath::Abs(((double)fTimestamp-(double)LastTimeStamp)*10*1e-9 > 3600.))
252  return;
253 
254  if((fTimestamp-FirstTimeStamp)*10*1e-9 > NextCycleSec)
255  {
256  fHistInSec->Reset();
257  fHistInSec0->Reset();
258  fHistInSecMetaSync->Reset();
259  NextCycleSec += 3600.;
260  }
261  if((fTimestamp-FirstTimeStamp)*10*1e-9/60. > NextCycleMin)
262  {
263  fHistInMin->Reset();
264  fHistInMin0->Reset();
265  fHistInMinMetaSync->Reset();
266  NextCycleMin += 720.;
267  }
268  if((fTimestamp-FirstTimeStamp)*10*1e-9/3600. > NextCycleH)
269  {
270  fHistInH->Reset();
271  fHistInH0->Reset();
272  fHistInHMetaSync->Reset();
273  NextCycleH += 48.;
274  }
275 
276  if(fTimestamp>LastTimeStamp && fTimestamp > LastGoodTimeStamp)
277  {
278  LastGoodTimeStamp = fTimestamp;
279  }
280 
281  if(fTimestamp<LastTimeStamp)
282  {
283  if(TMath::Abs(((double)fTimestamp-(double)FirstTimeStamp)*10*1e-9 < 1.))
284  {
285 // Print();
286 // ResetStats();
287  }
288  else
289  {
290 // fBashColor->SetWarningOut();
291 // cout<<GetName()<<endl;
292 // cout<<"Warning, this time stamp has been already seen !!!"<<endl;
293 // fBashColor->ResetColor();
294 
295 // cout<<"Last time stamp seen : "<<LastTimeStamp<<" ==> "<<fLastFillSec<<" s"<<endl;
296 // cout<<"Current time stamp : "<<fTimestamp<<" ==> "<<TSinSec<<" s"<<endl;
297 // cout<<"shift of "<<((double)fTimestamp-(double)LastTimeStamp)*10*1e-9<<" s"<<endl;
298 // cout<<"LastGoodTimeStamp = "<<LastGoodTimeStamp<<endl<<endl;
299 
300  fNBackwardTS++;
301 
302  if(LastTimeStamp<LastGoodTimeStamp) fNBackwardInBackwardTS++;
303  }
304  }
305  else
306  {
307  fHistInSec->Fill(TSinSec,10);
308  fHistInMin->Fill(TSinMin,10./60.);
309  fHistInH->Fill(TSinH,10./3600.);
310  }
311 
312  if(fTimestamp < LastGoodTimeStamp)
313  {
314  fNRepeatedEvts++;
315  }
316 
317  fLastFillSec = TSinSec;
318  fLastFillMin = TSinMin;
319  fLastFillH = TSinH;
320 
321  LastTimeStamp = fTimestamp;
322 
323  lastEventNumber = MainKey->GetEventNumber();
324 
325  if(IsDumpKeysActive) MainKey->GetRealBuffer()->Export(fDumpKeyFile,MainKey->GetKeyLength());
326 
327  if(!fHistMessageType->GetXaxis()->FindBin(MessageType))
328  cout<<"WARNING ! Unknown message type : "<<MessageType<<endl;
329  else fHistMessageType->Fill(MessageType,1);
330 
331  UInt_t length, current, eventnumber, message; ULong64_t timestamp; TString SubMess;
332 
333  ADF::Frame *AgataFrame = fFrame->GetFrame();
334 
335  const BufferIO *buf_temp = AgataFrame->GetRealBuffer();
336 
338 
339  fBufferToRead->Import((*buf_temp),MainKey->GetFrameLength());
340 
342 
344 
345  double DTEvent = 0.;
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;
353 
354  if ( MessageType.Contains("event") )
355  {
356  int Fold = 0;
357  bool is_a_start = false;
358 
360 
361  while ( fBufferToRead->FreeSize() > 20u )
362  {
363  current = fBufferToRead->Offset();
364 
365  const char *adress = fBufferToRead->CurrentAddress();
366 
367  (*fBufferToRead) >> length >> message >> eventnumber >> timestamp ;
368  SubMess = AgataKeyFactory::theFactory()->GetMessage(message);
369 
370  // cout<<"\E[30;1m";
371  // cout<<MainKey->GetTimeStamp()<<endl;
372  // cout<<((AgataKey*)fFrame->GetFrame()->GetKey())->GetTimeStamp()<<endl;
373  // cout<<SubMess<<" "<<timestamp<<" "<<eventnumber<<endl;
374  // cout<<"\E[m";
375 
376  if ( SubMess.Contains("UnknownKey") ) { // an unknown key
377  is_a_start = false;
378  }
379  else is_a_start = true;
380 
381  if ( is_a_start )
382  { // a known key has been found
383 
384  if(!fHistMessageType->GetXaxis()->FindBin(SubMess)) cout<<"WARNING ! Unknown sub-message type : "<<SubMess<<endl;
385  else
386  {
387  fHistMessageType->Fill(SubMess,1);
388  if(SubMess=="event:data:psa")
389  {
390  UInt_t sublength, subcurrent, subeventnumber, submessage; ULong64_t subtimestamp; TString SubSubMess;
391 
392  UInt_t TotSubLenght = 20;
393  subcurrent = fBufferToRead->SetOffset(current + 20u);
394 
395  while ( TotSubLenght<length )
396  {
397  const char *subadress = fBufferToRead->CurrentAddress();
398 
399  (*fBufferToRead) >> sublength >> submessage >> subeventnumber >> subtimestamp ;
400 
401  SubSubMess = AgataKeyFactory::theFactory()->GetMessage(submessage);
402 
403  fHistMessageType->Fill(SubSubMess,1);
404 
405  if(SubSubMess == "data:psa")
406  {
407  Fold++;
408  double DTPsa = (subtimestamp-timestamp)*10;
409  fHistDTPSA->Fill(DTPsa);
410 
411  fPSAFrame->GetFrame()->Copy(subadress,sublength);
412  fPSAFrame->GetFrame()->Read();
413 
414  PSAInterface *data = GetDataPointer<PSAInterface>(fPSAFrame);
415  UInt_t crysal_id = data->GetUID();
416 
417  fHistDTPerCrystal->Fill(crysal_id,DTPsa);
418 
419  TimeAGATAPC[crysal_id] = subtimestamp;
420  }
421 
422  TotSubLenght += sublength;
423 
424  fBufferToRead->SetOffset( subcurrent + sublength );
425 
426  subcurrent+=sublength;
427  }
428  if(MessageType=="event:data")
429  {
430  TimeAGATA = timestamp;
431  IsAGATA = true;
432  // double DTEvent = (timestamp-fTimestamp)*10;
433  // fHistDTEvent->Fill(-DTEvent);
434  }
435  }
436  if(SubMess=="data:ranc0" && MessageType=="event:data")
437  {
438  TimeVamos = timestamp;
439  IsVamos = true;
440  // double DTEvent = (timestamp-fTimestamp)*10;
441  // fHistDTEvent->Fill(DTEvent);
442  }
443  if(SubMess=="data:psa")
444  {
445  Fold++;
446  double DTPsa = (timestamp-fTimestamp)*10;
447  fHistDTPSA->Fill(DTPsa);
448 
449  fPSAFrame->GetFrame()->Copy(adress,length);
450  fPSAFrame->GetFrame()->Read();
451 
452  PSAInterface *data = GetDataPointer<PSAInterface>(fPSAFrame);
453  UInt_t crysal_id = data->GetUID();
454 
455  fHistDTPerCrystal->Fill(crysal_id,DTPsa);
456  }
457  }
458  fBufferToRead->SetOffset( current + length );
459  }
460  else
461  {
462  fBufferToRead->SetOffset( current + 4u );
463  }
464  }
465 
466  fHistFold->Fill(Fold);
467  }
468 
469  if(IsVamos&&IsAGATA)
470  {
471  DTEvent = (double)(TimeVamos*1.-TimeAGATA*1.)*10;
472  fHistDTEvent->Fill(DTEvent);
473  for(int i=0 ; i<50 ; i++)
474  {
475  if(TimeAGATAPC[i]!=0)
476  {
477  DTEventPC[i] = (TimeVamos*1.-TimeAGATAPC[i]*1.)*10;
478  fHistDTEventPerCrystal->Fill(i,DTEventPC[i]);
479  }
480  }
481  }
482 }
483 
484 void KeyWatcher::ResetTo(const char *option)
485 {
486  TString opt = option;
487 
488  if(opt.Contains("1") || opt.Contains("all"))
489  {
490  fHistInSec->Reset();
491  fHistInSec0->Reset();
492  fHistInSecMetaSync->Reset();
493  }
494  if(opt.Contains("2") || opt.Contains("all"))
495  {
496  fHistInMin->Reset();
497  fHistInMin0->Reset();
498  fHistInMinMetaSync->Reset();
499  }
500  if(opt.Contains("3") || opt.Contains("all"))
501  {
502  fHistInH->Reset();
503  fHistInH0->Reset();
504  fHistInHMetaSync->Reset();
505  }
506 
507  TCanvas *c = gPad->GetCanvas();
508  for(int k=0 ; k<c->GetListOfPrimitives()->GetSize() ; k++)
509  {
510  TPad *pad = (TPad*)c->cd(k);
511  if(pad)
512  {
513  pad->Modified();
514  pad->Update();
515  }
516  }
517 
519 }
520 
522 {
523 
524  TString Name = fName + "_MessType";
525  TString Title = fTitle + " Message Type";
526 
527  TCanvas *c = CanvasVisu::NewCanvas(Name,Title);
528 
529  c->Divide(2,2,0.001,0.001);
530 
531  c->cd(1);
532 
533  double topmarg = 0.0560089;
534  double rightmarg = 0.01455;
535  double leftmarg = 0.0747608;
536  double bottommarg = 0.0962985;
537 
538  gPad->SetRightMargin(rightmarg);
539  gPad->SetTopMargin(topmarg);
540  gPad->SetLeftMargin(leftmarg);
541  gPad->SetBottomMargin(bottommarg);
542 
543  fHistMessageType->SetBit(TH1::kNoTitle);
544  fHistMessageType->GetYaxis()->SetTitle("Counts");
545  fHistMessageType->GetYaxis()->SetTitleSize(0.05);
546  fHistMessageType->GetYaxis()->SetLabelSize(0.05);
547  fHistMessageType->GetYaxis()->SetTitleOffset(0.8);
548 
549  fHistMessageType->GetXaxis()->SetTitleSize(0.05);
550  fHistMessageType->GetXaxis()->SetLabelSize(0.05);
551 
552  fHistMessageType->Draw();
553  gPad->Modified();
554  gPad->Update();
555 
556  TPaveStats *st = (TPaveStats*)fHistMessageType->FindObject("stats");
557  if(st)
558  {
559  st->SetX2NDC(1-rightmarg);
560  st->SetY2NDC(1-topmarg);
561  }
562 
563  c->cd(2);
564 
565  gPad->SetRightMargin(rightmarg);
566  gPad->SetTopMargin(topmarg);
567  gPad->SetLeftMargin(leftmarg);
568  gPad->SetBottomMargin(bottommarg);
569 
570  fHistFold->SetBit(TH1::kNoTitle);
571  fHistFold->GetYaxis()->SetTitle("Counts");
572  fHistFold->GetYaxis()->SetTitleSize(0.05);
573  fHistFold->GetYaxis()->SetLabelSize(0.05);
574  fHistFold->GetYaxis()->SetTitleOffset(0.8);
575 
576  fHistFold->GetXaxis()->SetTitle("Fold");
577  fHistFold->GetXaxis()->SetTitleSize(0.05);
578  fHistFold->GetXaxis()->SetLabelSize(0.05);
579 
580  fHistFold->Draw();
581  gPad->Modified();
582  gPad->Update();
583 
584  st = (TPaveStats*)fHistFold->FindObject("stats");
585  if(st)
586  {
587  st->SetX2NDC(1-rightmarg);
588  st->SetY2NDC(1-topmarg);
589  }
590 
591  c->cd(3)->Divide(1,2,0.001,0.001);
592 
593  topmarg = 0.0119154;
594  rightmarg = 0.00310682;
595  leftmarg = 0.0660825;
596  bottommarg = 0.175578;
597 
598  c->cd(3)->cd(1);
599 
600  gPad->SetRightMargin(rightmarg);
601  gPad->SetTopMargin(topmarg);
602  gPad->SetLeftMargin(leftmarg);
603  gPad->SetBottomMargin(bottommarg);
604  gPad->SetLogy();
605 
606  fHistDTPSA->SetBit(TH1::kNoTitle);
607  fHistDTPSA->GetYaxis()->SetTitle("Counts");
608  fHistDTPSA->GetYaxis()->SetTitleSize(0.09);
609  fHistDTPSA->GetYaxis()->SetLabelSize(0.08);
610  fHistDTPSA->GetYaxis()->SetTitleOffset(0.4);
611 
612  fHistDTPSA->GetXaxis()->SetTitle("#DeltaT Psa (ns)");
613  fHistDTPSA->GetXaxis()->SetTitleSize(0.09);
614  fHistDTPSA->GetXaxis()->SetLabelSize(0.08);
615 
616  fHistDTPSA->Draw();
617  gPad->Modified();
618  gPad->Update();
619 
620  st = (TPaveStats*)fHistDTPSA->FindObject("stats");
621  if(st)
622  {
623  st->SetX2NDC(1-rightmarg);
624  st->SetY2NDC(1-topmarg);
625  st->SetX1NDC(0.743455);
626  st->SetY1NDC(0.672483);
627  }
628  c->cd(3)->cd(2);
629 
630  gPad->SetRightMargin(rightmarg);
631  gPad->SetTopMargin(topmarg);
632  gPad->SetLeftMargin(leftmarg);
633  gPad->SetBottomMargin(bottommarg);
634  gPad->SetLogy();
635 
636  fHistDTEvent->SetBit(TH1::kNoTitle);
637  fHistDTEvent->GetYaxis()->SetTitle("Counts");
638  fHistDTEvent->GetYaxis()->SetTitleSize(0.09);
639  fHistDTEvent->GetYaxis()->SetLabelSize(0.08);
640  fHistDTEvent->GetYaxis()->SetTitleOffset(0.4);
641 
642  fHistDTEvent->GetXaxis()->SetTitle("#DeltaT Event (ns)");
643  fHistDTEvent->GetXaxis()->SetTitleSize(0.09);
644  fHistDTEvent->GetXaxis()->SetLabelSize(0.08);
645 
646  fHistDTEvent->Draw();
647  gPad->Modified();
648  gPad->Update();
649 
650  st = (TPaveStats*)fHistDTEvent->FindObject("stats");
651  if(st)
652  {
653  st->SetX2NDC(1-rightmarg);
654  st->SetY2NDC(1-topmarg);
655  st->SetX1NDC(0.743455);
656  st->SetY1NDC(0.672483);
657  }
658 
659  c->cd(4)->Divide(1,2,0.001,0.001);
660  c->cd(4)->cd(1);
661 
662  gPad->SetRightMargin(rightmarg);
663  gPad->SetTopMargin(topmarg);
664  gPad->SetLeftMargin(leftmarg);
665  gPad->SetBottomMargin(bottommarg);
666  gPad->SetLogz();
667 
668  fHistDTPerCrystal->SetBit(TH1::kNoTitle);
669  fHistDTPerCrystal->GetYaxis()->SetTitle("#DeltaT Psa (ns)");
670  fHistDTPerCrystal->GetYaxis()->SetTitleSize(0.09);
671  fHistDTPerCrystal->GetYaxis()->SetLabelSize(0.08);
672  fHistDTPerCrystal->GetYaxis()->SetTitleOffset(0.4);
673 
674  fHistDTPerCrystal->GetXaxis()->SetTitle("Crystal ID");
675  fHistDTPerCrystal->GetXaxis()->SetTitleSize(0.09);
676  fHistDTPerCrystal->GetXaxis()->SetLabelSize(0.08);
677 
678  fHistDTPerCrystal->Draw("col");
679  gPad->Modified();
680  gPad->Update();
681 
682  st = (TPaveStats*)fHistDTPerCrystal->FindObject("stats");
683  if(st)
684  {
685  st->SetX2NDC(1-rightmarg);
686  st->SetY2NDC(1-topmarg);
687  }
688 
689  c->cd(4)->cd(2);
690 
691  gPad->SetRightMargin(rightmarg);
692  gPad->SetTopMargin(topmarg);
693  gPad->SetLeftMargin(leftmarg);
694  gPad->SetBottomMargin(bottommarg);
695  gPad->SetLogz();
696 
697  fHistDTEventPerCrystal->SetBit(TH1::kNoTitle);
698  fHistDTEventPerCrystal->GetYaxis()->SetTitle("#DeltaT VAMOS - AGATA (ns)");
699  fHistDTEventPerCrystal->GetYaxis()->SetTitleSize(0.09);
700  fHistDTEventPerCrystal->GetYaxis()->SetLabelSize(0.08);
701  fHistDTEventPerCrystal->GetYaxis()->SetTitleOffset(0.4);
702 
703  fHistDTEventPerCrystal->GetXaxis()->SetTitle("Crystal ID");
704  fHistDTEventPerCrystal->GetXaxis()->SetTitleSize(0.09);
705  fHistDTEventPerCrystal->GetXaxis()->SetLabelSize(0.08);
706 
707  fHistDTEventPerCrystal->Draw("col");
708  gPad->Modified();
709  gPad->Update();
710 
711  st = (TPaveStats*)fHistDTEventPerCrystal->FindObject("stats");
712  if(st)
713  {
714  st->SetX2NDC(1-rightmarg);
715  st->SetY2NDC(1-topmarg);
716  }
717 
718 }
719 
720 void KeyWatcher::DumpKeys(bool ActiveDump)
721 {
722  if( !IsDumpKeysActive && ActiveDump)
723  {
724  std::ostringstream filename;
725  int fCurrentFileNumber = 0;
726  filename << (TString)GetName() + "_" << std::setfill('0') << std::setw(4) << fCurrentFileNumber << ".keys";
727 
728  while(gSystem->IsFileInIncludePath(filename.str().data()))
729  {
730  filename.str("");
731  filename << (TString)GetName() + "_" << std::setfill('0') << std::setw(4) << fCurrentFileNumber++ << ".keys";
732  }
733 
734  fDumpKeyFile = ::fopen(filename.str().data(),"wb");
735  fFileName = filename.str();
736 
737  fBashColor->SetInfoOut();
738  cout<<"Keys will be dumped in the file : "<<fFileName<<endl;
739  }
740  else if( IsDumpKeysActive && !ActiveDump )
741  {
742  if ( fDumpKeyFile ) ::fclose(fDumpKeyFile);
743  fDumpKeyFile = 0x0;
744 
745  fBashColor->SetInfoOut();
746  cout<<"Dumped-keys file : "<<fFileName<<" is close !"<<endl;
747  }
748  else if( IsDumpKeysActive && ActiveDump )
749  {
750  fBashColor->SetWarningOut();
751  cout<<"Keys dumping already active"<<endl;
752  }
753  else if( !IsDumpKeysActive && !ActiveDump )
754  {
755  fBashColor->SetWarningOut();
756  cout<<"Keys dumping is not active"<<endl;
757  }
758 
759  IsDumpKeysActive = ActiveDump;
760 
761  fBashColor->ResetColor();
762 }
763 
764 void KeyWatcher::Print(const char * /* option */ ) const
765 {
766  std::cout<<std::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<<"*";
769  std::cout<<std::endl;
770  std::cout<<"*** "<<GetName()<<" --- "<<GetTitle()<<" ***"<<std::endl;
771  for(int i=0; i<size ; i++) std::cout<<"*";
772  std::cout<<std::endl;
773 
774  std::cout<<"Number of treated events : "<<fNevts<<std::endl;
775 
776  for(int i=fHistMessageType->GetXaxis()->GetNbins() ; i>0 ; i--)
777  {
778  Int_t N = (Int_t)fHistMessageType->GetBinContent(i);
779  TString label = fHistMessageType->GetXaxis()->GetBinLabel(i);
780  if(N!=0) std::cout<<" ---> "<<label<<" : "<<N<<endl;
781  }
782 
783  fBashColor->SetErrorOut();
784  if(fNNullTS>0) std::cout<<"Number of empty Timestamps : "<<fNNullTS<<std::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;
789  fBashColor->SetInfoOut();
790 
791  std::cout<<std::endl;
792  std::cout<<"First Timestamp : "<<FirstTimeStamp<<std::endl;
793  std::cout<<"Last Timestamp : "<<LastTimeStamp<<std::endl;
794  std::cout<<"First Event number : "<<FirstEventNumber<<std::endl;
795  std::cout<<"Last Event number : "<<lastEventNumber<<std::endl;
796 
797  double TotalTimeInS = (LastTimeStamp-FirstTimeStamp)*10.*1e-9;
798  int TH = (int)(TotalTimeInS/3600.);
799  int TMin = (int)((TotalTimeInS/3600.-TH)*60.);
800  int TSec = (int)(((TotalTimeInS/3600.-TH)*60.-TMin)*60.);
801 
802  std::cout<<"Elapsed time (s) : "<<TotalTimeInS<<" ( "<<TH<<"h"<<TMin<<"'"<<TSec<<"'' )"<<std::endl;
803 
804  fBashColor->ResetColor();
805 }
806 
808 {
809  NextCycleSec = 3600.;
810  NextCycleMin = 720.;
811  NextCycleH = 48.;
812 
813  fHistInSec->Reset();
814  fHistInSec0->Reset();
815  fHistInSecMetaSync->Reset();
816  fHistInMin->Reset();
817  fHistInMin0->Reset();
818  fHistInMinMetaSync->Reset();
819  fHistInH->Reset();
820  fHistInH0->Reset();
821  fHistInHMetaSync->Reset();
822 
823  fNNullTS = 0;
824  fNBackwardTS = 0;
825  fNBackwardInBackwardTS = 0;
826  fNRepeatedEvts = 0;
827  fNBackwardTS = 0;
828 
829  FirstTimeStamp = 0;
830  LastTimeStamp = 0;
831  FirstEventNumber = 0;
832  lastEventNumber = 0;
833  LastGoodTimeStamp = 0;
834 
835  fNevts = 0;
836 
837  fHistMessageType->Reset();
838 }
839 
840 
841 
843 
virtual const BufferIO * GetRealBuffer() const
Definition: Key.h:118
double NextCycleMin
Definition: KeyWatchers.h:48
TString fFileName
Definition: KeyWatchers.h:71
virtual Key * GetKey()=0
To get the Key associated to this frame.
virtual Frame * GetFrame() const
Definition: Frame.h:625
double NextCycleSec
Definition: KeyWatchers.h:47
ULong64_t LastTimeStamp
Definition: KeyWatchers.h:60
double NextCycleH
Definition: KeyWatchers.h:49
TH1F * fHistInSec
Definition: KeyWatchers.h:34
Base class for a Frame.
Definition: Frame.h:73
Char_t * CurrentAddress()
for classes that needs it to write directly data into it.
Definition: BufferIO.h:101
virtual UInt_t Read()
It reads the content into dedicated structures from the Frame (data part)
Definition: Frame.h:199
virtual Int_t GetUID() const =0
to get the crystal ID
Interface to AgataKey.
virtual SharedFP * GetInputSharedFP(UInt_t which=0u)=0
to get back the Shared pointer that define this trigger
TH1F * fHistInMin0
Definition: KeyWatchers.h:40
void DumpKeys(bool ActiveDump=false)
Definition: KeyWatchers.C:720
virtual const BufferIO * GetRealBuffer() const =0
give access to the underlying buffer of the data part
bool IsDumpKeysActive
Definition: KeyWatchers.h:70
TH2 * fHistDTEventPerCrystal
Definition: KeyWatchers.h:56
TCanvas * NewCanvas(TString cname, TString ctitle)
Definition: CanvasVisu.C:102
TH1F * fHistInMinMetaSync
Definition: KeyWatchers.h:44
header file for AgataCompositeFrame.cpp
void ResetStats()
Definition: KeyWatchers.C:807
virtual ULong64_t GetTimeStamp() const =0
To set the timestamp.
Base class for a Watcher.
Definition: Watchers.h:60
UInt_t Offset() const
it returns the current position in the buffer
Definition: BufferIO.h:240
ULong64_t GetFirstTS()
Definition: KeyWatchers.h:89
KeyWatcher(const char *name, const char *title, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
Definition: KeyWatchers.C:22
TH2 * fHistDTPerCrystal
Definition: KeyWatchers.h:55
SharedFP * fPSAFrame
Definition: KeyWatchers.h:30
ClassImp(KeyWatcher)
header file for PSAFrame.cpp
virtual UInt_t GetKeyLength() const
Unique number corresponding to a type of Key.
Definition: Key.h:210
virtual UInt_t GetEventNumber() const =0
To get the event number encoded.
header file for BufferIO.cpp
virtual void Print(const char *option="") const
Definition: KeyWatchers.C:764
UInt_t FreeSize() const
it returns the number of free bytes to the end
Definition: BufferIO.h:236
virtual UInt_t Export(Char_t *, UInt_t) const
Export this buffer to an array.
Definition: BufferIO.h:694
ULong64_t FirstEventNumber
Definition: KeyWatchers.h:59
void ShowMessageType()
Definition: KeyWatchers.C:521
header file for AgataKeyFactory.cpp
BufferIO * fBufferToRead
Definition: KeyWatchers.h:32
To be used for Agata Data Flow.
Definition: Trigger.h:462
TH1F * fHistInH0
Definition: KeyWatchers.h:41
Color_t GetColor(int i)
Definition: CanvasVisu.h:49
ULong64_t FirstTimeStamp
Definition: KeyWatchers.h:58
ULong64_t lastEventNumber
Definition: KeyWatchers.h:62
TH1F * fHistInHMetaSync
Definition: KeyWatchers.h:45
TH1F * fHistInH
Definition: KeyWatchers.h:36
double fLastFillSec
Definition: KeyWatchers.h:64
virtual Bool_t SetTrigger(ADF::DFTrigger *=0x0)
To set the Frames (through a trigger) associated to this watcher.
Definition: KeyWatchers.C:79
UInt_t SetEffectiveSize(UInt_t size=kMaxUInt_t)
in case the buffer is partly filled and you would like to read it again
Definition: BufferIO.cpp:152
TH1 * fHistMessageType
Definition: KeyWatchers.h:51
Base class for a trigger on a data flow.
Definition: Trigger.h:155
ADF::LogMessage & endl(ADF::LogMessage &log)
double fLastFillMin
Definition: KeyWatchers.h:65
virtual Bool_t Copy(const Char_t *, UInt_t, const char= 'b')=0
copy a buffer to this Frame
double fLastFillH
Definition: KeyWatchers.h:66
virtual void Exec(Option_t *option="")
Definition: KeyWatchers.C:181
UInt_t Import(const Char_t *from, UInt_t size_ext_buf)
Import the given array in this buffer.
Definition: BufferIO.cpp:298
ULong64_t GetFirstEN()
Definition: KeyWatchers.h:90
virtual UInt_t GetFrameLength() const
TH1F * fHistInSec0
Definition: KeyWatchers.h:39
TH1 * fHistFold
Definition: KeyWatchers.h:52
virtual ADF::DFTrigger * GetTrigger() const
To know the trigger in which the frame to be watched is embedded.
Definition: Watchers.h:360
const Int_t size
Definition: BenchIO.C:24
TH1F * fHistInMin
Definition: KeyWatchers.h:35
TH1F * fHistInSecMetaSync
Definition: KeyWatchers.h:43
TH1 * fHistDTEvent
Definition: KeyWatchers.h:54
ULong64_t LastGoodTimeStamp
Definition: KeyWatchers.h:61
SharedFP * fFrame
Definition: KeyWatchers.h:29
FILE * fDumpKeyFile
Definition: KeyWatchers.h:69
virtual void ResetTo(const char *option="all")
Definition: KeyWatchers.C:484
TH1 * fHistDTPSA
Definition: KeyWatchers.h:53
virtual UInt_t GetMessage() const =0
To get the message type encoded.
UInt_t fNNullTS
Definition: KeyWatchers.h:38
virtual void ShowTSDist(const char *option="hist")
Definition: KeyWatchers.C:97
UInt_t SetOffset(UInt_t off=0u) const
change the current position.
Definition: BufferIO.cpp:122