GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SpecViewer.C
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <fstream>
4 #include <sstream>
5 #include <vector>
6 #include <string>
7 #include <stdint.h>
8 #include <map>
9 
10 #include "TSystem.h"
11 #include "TRegexp.h"
12 #include "TList.h"
13 #include "TSystemDirectory.h"
14 #include "TNamed.h"
15 #include "TCanvas.h"
16 #include "TDirectory.h"
17 #include "TString.h"
18 #include "TSocket.h"
19 #include "TGFileDialog.h"
20 #include "TROOT.h"
21 #include "TFolder.h"
22 #include "TBrowser.h"
23 #include "TTask.h"
24 #include "TObjArray.h"
25 #include "TObjString.h"
26 
27 #include "SpecViewer.h"
28 #include "BaselineWatcher.h"
29 #include "RawAmpWatcher.h"
30 #include "SignalWatcher.h"
31 #include "SpectraViewerWatcher.h"
32 
33 using namespace std;
34 
35 void Import(TString Incl="*", TString Excl="*.samp", TString DefaultPath="");
36 void ImportFile(TString DefaultPath="", Double_t DefGain=1);
37 TList *GetListFromIncExcl(TList *ListOfFiles, TString Incl, TString Excl);
38 TList *BuildHistograms(TString DataPath, TList *ListOfFiles, std::map<TString, double> GainMap);
39 TString GetFileName(TString DefaultDir,TString FileExt);
40 std::map<TString, double> ReadGain(TString gen_conf_Path);
41 TList *ReadFile(TString FilePath, DinoFileInfo info, TString CrystalName, std::map<TString, double> GainMap);
42 void BuildTasks(TList *ListOfHists, TString RunNbr, std::map<TString, double> GainMap);
43 
47 
48 void Import(TString Incl, TString Excl, TString DefaultPath)
49 {
50  TString CurrentDir = gSystem->pwd();
51  if(DefaultPath=="")
52  DefaultPath="/agatadisks/eagata/";
53  // if(DefaultPath=="")DefaultPath=CurrentDir;
54 
55  TString Path = GetFileName(DefaultPath,"gen_conf.py");
56  if(Path=="") return;
57 
58  TString StringToToken = Path;
59  TObjArray *token = StringToToken.Tokenize("/");
60 
61  TString RunNbr = ((TObject*)token->At(token->GetEntries()-2))->GetName();
62 
63  std::map<TString, double> GainMap = ReadGain(Path);
64 
65  Path.ReplaceAll("/gen_conf.py","");
66 
67  gSystem->cd(CurrentDir);
68 
70  TSystemDirectory Dir;
71  Dir.SetDirectory(Path);
72  if(!Dir.GetListOfFiles()->Contains("Data") && !Dir.GetListOfFiles()->Contains("Conf"))
73  {
74  cout<<"The directory don't refer to a run directory, it must contains Conf and Data sub directories"<<endl;
75  return;
76  }
77 
79 
80  TList *ListOfCrystals;
81  ListOfCrystals = new TList();
82  ListOfCrystals->SetOwner();
83 
84  TString DataPath = Path + "/Data/";
85 
86  if(gSystem->AccessPathName(DataPath))
87  {
88  cout<<DataPath<<" no readable, looking in the Out Dir"<<endl;
89  DataPath.ReplaceAll("/Data/","/Out/");
90  if(gSystem->AccessPathName(DataPath))
91  {
92  cout<<DataPath<<" no readable, exit"<<endl;
93  return;
94  }
95  }
96 
97  Dir.SetDirectory(DataPath);
98  TList *ListOfSubFolders = Dir.GetListOfFiles();
99  ListOfSubFolders->Remove(ListOfSubFolders->FindObject(".")); // Pour supprimer /.
100  ListOfSubFolders->Remove(ListOfSubFolders->FindObject(".."));
101 
102  TIter iter(ListOfSubFolders);
103  TObject *entry;
104 
105  while ( (entry = iter()) )
106  {
107  TString SubDirName = entry->GetName();
108  TString SubDirPath = DataPath + SubDirName;
109 
110  if(entry->InheritsFrom("TSystemDirectory"))
111  {
112  TSystemDirectory SubDir;
113  SubDir.SetDirectory(SubDirPath);
114  TList *ListOfFiles = SubDir.GetListOfFiles();
115  ListOfFiles->Remove(ListOfFiles->FindObject(".")); // Pour supprimer /.
116  ListOfFiles->Remove(ListOfFiles->FindObject("..")); // Pour supprimer /..
117 
118  if(ListOfFiles->IsEmpty()) ListOfSubFolders->Remove(entry);
119  else
120  {
121  TList *ListOfSpectra = GetListFromIncExcl(ListOfFiles,Incl,Excl);
122 
123  ListOfSpectra->SetName(SubDirName);
124  ListOfCrystals->Add(ListOfSpectra);
125  }
126 
127  }
128  }
129 
130  TList *ListOfAllHistograms = BuildHistograms(DataPath, ListOfCrystals, GainMap);
131  ListOfAllHistograms->Sort();
132 
133  //ListOfAllHistograms->ls();
134 
135  TFolder *SpectraViewerFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("SpectraViewer");
136  if(!SpectraViewerFolder)
137  {
138  gROOT->GetRootFolder()->AddFolder("SpectraViewer","SpectraViewer");
139  SpectraViewerFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("SpectraViewer");
140  }
141 
142  ((TFolder*)gROOT->GetRootFolder()->FindObject("SpectraViewer"))->AddFolder(RunNbr,"Folder containing the spectra created by the actors",ListOfAllHistograms);
143 
144  TBrowser *b = (TBrowser*)gROOT->GetListOfBrowsers()->Last();
145  b->Add(SpectraViewerFolder);
146 
147  TFolder *RootFilesFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("ROOT Files");
148  b->Add(RootFilesFolder);
149 
150 
151  BuildTasks(ListOfAllHistograms,RunNbr, GainMap);
152 
153  delete ListOfCrystals;
154 }
155 
157 
158 void ImportFile(TString DefaultPath, Double_t DefGain)
159 {
160  TString CurrentDir = gSystem->pwd();
161  if(DefaultPath=="")
162  DefaultPath="/agatadisks/eagata/";
163 
164  TString Path;
165 
166  if(gSystem->IsFileInIncludePath(DefaultPath)) Path = DefaultPath;
167  else Path = GetFileName(DefaultPath,"*.*");
168 
169  if(Path=="") return;
170 
171  gSystem->cd(CurrentDir);
172 
174  DinoFileInfo info(Path.Data());
175 
176  std::map<TString, double> GainMap;
177 
178  TString ActorName = info.basename;
179 
180  GainMap[info.basename] = DefGain;
181 
182  TList *ListOfCrystals;
183  ListOfCrystals = new TList();
184  ListOfCrystals->SetOwner();
185 
186  TString CrystalName = Path;
187 
188  TList *ListOfActors;
189  ListOfActors = new TList();
190  ListOfActors->SetOwner();
191  ListOfActors->SetName(CrystalName);
192  ListOfCrystals->Add(ListOfActors);
193 
194  TList *NewActor;
195  NewActor = new TList();
196  NewActor->SetOwner();
197  NewActor->SetName(ActorName);
198  ListOfActors->Add(NewActor);
199 
201  TList *ListOfObservables = (TList*)ListOfActors->FindObject(ActorName);
202 
204  TList *ListOfLibraries = ReadFile(Path, info,"",GainMap);
205 
206  ListOfObservables->Add(ListOfLibraries);
207 
208  //add a top folder visible from ROOT browser
209  TFolder *TopFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("//root/SpectraViewer");
210  if (TopFolder!=0x0) delete TopFolder;
211  gROOT->GetRootFolder()->AddFolder("SpectraViewer","Folder containing the spectra created by the actors",ListOfCrystals);
212 
213  TBrowser *b = (TBrowser*)gROOT->GetListOfBrowsers()->Last();
214 
215  TFolder *SpectraViewerFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("SpectraViewer");
216  if(SpectraViewerFolder) b->Add(SpectraViewerFolder);
217 
218  TFolder *RootFilesFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("ROOT Files");
219  if(RootFilesFolder) b->Add(RootFilesFolder);
220 
221 
222  BuildTasks(ListOfCrystals,Path, GainMap);
223 }
224 
226 
227 TList *GetListFromIncExcl(TList *ListOfFiles, TString Incl, TString Excl)
228 {
229  TList *ListOfSpectra = new TList();
230  ListOfSpectra->SetOwner();
231 
232  TString tmp_obj = "", tmp_token = "";
233  Bool_t wildcard;
234  TObject *an_obj = 0x0, *a_token = 0x0;
235 
236  ListOfFiles->Remove(ListOfFiles->FindObject("."));
237  ListOfFiles->Remove(ListOfFiles->FindObject(".."));
238 
239  TIter iter(ListOfFiles);
240 
241  while ( (an_obj = iter()) )
242  {
243  tmp_obj = an_obj->GetName();
244 
245  //ajout des .adf aux exclude
246  Excl = Excl + " *.adf";
247  //ajout des .cdat aux exclude
248  Excl = Excl + " *.cdat*";
249 
250  // tokenize include and exclude filter
251  TObjArray *all_token_include = Incl.Tokenize(" "),*all_token_exclude = Excl.Tokenize(" ");
252  Bool_t add_it = false, exclude_it = false;
253 
254  // check include
255  TIter token_include(all_token_include);
256  while ( (a_token = token_include()) )
257  {
258 
259  tmp_token = a_token->GetName();
260 
261  // pattern expression
262  wildcard = false;
263  if ( tmp_token.Contains("*") )
264  wildcard = true;
265  TRegexp kept(tmp_token,wildcard);
266 
267  if ( tmp_obj.Contains(kept) ) {
268  add_it = true;
269  break;
270  }
271  }
272 
273  // check exclude
274  TIter token_exclude(all_token_exclude);
275  while ( (a_token = token_exclude()) )
276  {
277 
278  tmp_token = a_token->GetName();
279 
280  // pattern expression
281  wildcard = false;
282  if ( tmp_token.Contains("*") )
283  wildcard = true;
284  TRegexp nokept(tmp_token,wildcard);
285 
286  if ( tmp_obj.Contains(nokept) ) {
287  exclude_it = true;
288  break;
289  }
290  }
291 
292  // it is the charge of the user to delete Tokenized collection
293  if ( all_token_include ) {
294  delete all_token_include; all_token_include = 0x0;
295  }
296  if ( all_token_exclude ) {
297  delete all_token_exclude; all_token_exclude = 0x0;
298  }
299 
300  //printf("%s with filter %s , %s \n",tmp_obj.Data(),Incl.Data(),Excl.Data());
301  // now if it passes the filters, add it
302  if ( add_it && !exclude_it ) {
303  ListOfSpectra->Add(an_obj);
304  }
305  }
306 
307  return ListOfSpectra;
308 }
309 
311 
312 TList *BuildHistograms(TString DataPath, TList *ListOfFiles, std::map<TString, double> GainMap)
313 {
314  TList *ListOfCrystals;
315  ListOfCrystals = new TList();
316  ListOfCrystals->SetOwner();
317 
318  TIter iter(ListOfFiles);
319  TObject *entry;
320 
322  while ( (entry = iter()) )
323  {
324  TString CrystalName = entry->GetName();
325 
326  cout<<"Reading spectra for "<<entry->GetName()<<" level:"<<endl;
327  TList *ListOfActors;
328  ListOfActors = new TList();
329  ListOfActors->SetOwner();
330  ListOfActors->SetName(entry->GetName());
331  ListOfCrystals->Add(ListOfActors);
332 
333  TIter iter2((TList*)entry);
334  TObject *entry2;
335 
337  while ( (entry2 = iter2()) )
338  {
339  cout<<"\t File: "<<entry2->GetName()<<endl;
340 
341  TString Filename = entry2->GetName();
343  TString FilePath = DataPath + CrystalName + "/" + Filename;
344 
346  DinoFileInfo info(FilePath.Data());
347  // cout<<FilePath<<endl;
348  // cout<<"basename : "<<info.basename<<endl;
349  // cout<<"datatype : "<<info.datatype<<endl;
350  // cout<<"format : "<<info.format<<endl;
351  // cout<<"histtype : "<<info.histtype<<endl;
352  // cout<<"number_stack : "<<info.number_stack.size()<<endl;
353  // for(uint i=0 ; i<info.number_stack.size() ; i++)
354  // {
355  // cout<<info.number_stack[i]<<endl;
356  // }
357  // cout<<"specifier : "<<info.specifier<<endl;
358  // cout<<endl;
359 
360  TString ActorName = info.basename;
361 
362  if(!ListOfActors->Contains(ActorName))
363  {
364  TList *NewActor;
365  NewActor = new TList();
366  NewActor->SetOwner();
367  NewActor->SetName(ActorName);
368  ListOfActors->Add(NewActor);
369  }
370 
372  TList *ListOfObservables = (TList*)ListOfActors->FindObject(ActorName);
373 
375  TList *ListOfLibraries = ReadFile(FilePath, info, CrystalName, GainMap);
376 
377  if(ListOfLibraries->GetSize()!=0) ListOfObservables->Add(ListOfLibraries);
378  else delete ListOfLibraries;
379  }
380  if(ListOfActors->GetSize()==0)
381  {
382  ListOfCrystals->Remove(ListOfActors);
383  delete ListOfActors;
384  }
385 
386  cout<<endl;
387 
388  }
389 
390  return ListOfCrystals;
391 }
392 
394 
395 bool next_pos(std::vector<int> &ptr, std::vector<int> &max)
396 {
397  // go to the next element in the sequence
398  int pos;
399  for (pos = ptr.size()-1; pos >= 0; --pos)
400  {
401  ptr[pos]++;
402  if (ptr[pos] == max[pos])
403  {
404  ptr[pos] = 0;
405  }
406  else
407  break;
408  }
409 
410  if (pos < 0)
411  return false;
412  return true;
413 }
414 
416 
417 TList *ReadFile(TString FilePath, DinoFileInfo info, TString CrystalName, std::map<TString, double> GainMap)
418 {
419  TList *ListOfLibrairies;
420  ListOfLibrairies = new TList();
421  ListOfLibrairies->SetOwner();
422 
423  TObjString *FileName = new TObjString(FilePath);
424  ListOfLibrairies->Add(FileName);
425 
426  std::ifstream in(FilePath);
427  if (!in)
428  {
429  std::cerr << "cannot open file " << FilePath << std::endl;
430  return 0x0;
431  }
432 
433  int incr=0;
434 
435  if(info.histtype == "samp")
436  {
437  TString Name = "Graph_" + info.specifier + "_" + info.basename + "_" + info.histtype;
438  ListOfLibrairies->SetName(Name);
439 
440  if (info.number_stack.size() < 1)
441  {
442  std::cerr << "invalid format";
443  return 0x0;
444  }
445  int channels = info.number_stack.back();
446  info.number_stack.pop_back();
447 
448  if (!info.number_stack.size())
449  info.number_stack.push_back(1);
450 
451  std::vector<int> ptr_stack(info.number_stack.size(), 0);
452 
453  for (;;)
454  {
455  // build.size() the entry name and subdirectory structure
456  std::ostringstream dir_name;
457  dir_name << info.basename << "_" << info.specifier;
458  for (uint n = 0; n < ptr_stack.size()-1; ++n) dir_name << "_" << std::setw(3) << std::setfill('0') << ptr_stack[n];
459 
460  std::ostringstream histname;
461  histname << "Graph_" << CrystalName.Data() << "_" << dir_name.str() << "_" << std::setw(3) << std::setfill('0') << ptr_stack.back();
462 
464  TString LibraryName = dir_name.str();
465 
466  if(!ListOfLibrairies->Contains(LibraryName))
467  {
468  TList *NewLibrary = new TList();
469  NewLibrary->SetOwner();
470  NewLibrary->SetName(LibraryName);
471  ListOfLibrairies->Add(NewLibrary);
472  }
474  TList *ListOfHistograms = (TList*)ListOfLibrairies->FindObject(LibraryName);
475 
476  TString HistName = (histname.str());
477  TGraph *graph = (TGraph*)gROOT->FindObject(HistName);
478  if(graph) delete graph;
479  graph = new TGraph(channels);
480  graph->SetNameTitle(HistName, HistName);
481 
482  if (info.datatype == "UI")
483  read_1d_data_to_graph<uint32_t>(in, graph);
484  else if (info.datatype == "US")
485  read_1d_data_to_graph<uint16_t>(in, graph);
486  else if (info.datatype == "S")
487  read_1d_data_to_graph<int16_t>(in, graph);
488  else if (info.datatype == "F")
489  read_1d_data_to_graph<float>(in, graph);
490 
491  if(graph->GetN() != 0)ListOfHistograms->Add(graph);
492  else
493  {
494  cout<<"WARNING !! "<<graph->GetName()<<" has a null size !"<<endl;
495  delete graph;
496  }
497 
499  incr++;
500  if(incr==info.number_stack[1])
501  {
502  if(ListOfHistograms->GetSize()==0)
503  {
504  ListOfLibrairies->Remove(ListOfHistograms);
505  delete ListOfHistograms;
506  }
507  incr=0;
508  }
509 
510  if (!next_pos(ptr_stack, info.number_stack)) break;
511  }
512  }
513  else if(info.histtype == "spec") // 1d histogram
514  {
515  TString Name = "H1D_" + info.specifier;
516  ListOfLibrairies->SetName(Name);
517 
518  if (info.number_stack.size() < 1)
519  {
520  std::cerr << "invalid format";
521  return 0x0;
522  }
523  int channels = info.number_stack.back();
524  info.number_stack.pop_back();
525 
526  if (!info.number_stack.size())
527  info.number_stack.push_back(1);
528 
529  std::vector<int> ptr_stack(info.number_stack.size(), 0);
530 
531  for (;;)
532  {
533  // build.size() the entry name and subdirectory structure
534  std::ostringstream dir_name;
535  dir_name << info.basename << "_" << info.specifier;
536  for (uint n = 0; n < ptr_stack.size()-1; ++n) dir_name << "_" << std::setw(3) << std::setfill('0') << ptr_stack[n];
537 
538  std::ostringstream histname;
539  histname << "H1D_" << CrystalName.Data() << "_" << dir_name.str() << "_" << std::setw(3) << std::setfill('0') << ptr_stack.back();
540 
542  TString LibraryName = dir_name.str();
543 
544  if(!ListOfLibrairies->Contains(LibraryName))
545  {
546  TList *NewLibrary = new TList();
547  NewLibrary->SetOwner();
548  NewLibrary->SetName(LibraryName);
549  ListOfLibrairies->Add(NewLibrary);
550  }
552  TList *ListOfHistograms = (TList*)ListOfLibrairies->FindObject(LibraryName);
553 
554  TString HistName = (histname.str());
555  TH1 *hist = (TH1*)gROOT->FindObject(HistName);
556  if(hist) hist->Clear();
557 
559 
560  double Gain = 1.;
561 
562  if( (HistName.Contains("Prep") && HistName.Contains("Esum")) ||
563  (HistName.Contains("Prep") && HistName.Contains("Ener") && !HistName.EndsWith("38") && !HistName.EndsWith("39")) ||
564  (HistName.Contains("Post") && HistName.Contains("Ener")) ||
565  (HistName.Contains("Psa") && HistName.Contains("Ener")) ||
566  (HistName.Contains("Track") && ((HistName.Contains("_EC")) || (HistName.Contains("_EE"))))
567  )
568  {
569  Gain = GainMap[info.basename];
570  hist = new TH1F(HistName, HistName, channels, 0, (int)channels/Gain);
571  }
572  else hist = new TH1I(HistName, HistName, channels, 0, channels);
573 
574  if (info.datatype == "UI")
575  read_1d_data<uint32_t>(in, hist);
576  else if (info.datatype == "US")
577  read_1d_data<uint16_t>(in, hist);
578  else if (info.datatype == "S")
579  read_1d_data<int16_t>(in, hist);
580  else if (info.datatype == "F")
581  read_1d_data<float>(in, hist);
582 
583  if(hist->GetEntries() != 0)ListOfHistograms->Add(hist);
584 
585  else delete hist;
586 
588  incr++;
589  if(incr==info.number_stack[1])
590  {
591  if(ListOfHistograms->GetSize()==0)
592  {
593  ListOfLibrairies->Remove(ListOfHistograms);
594  delete ListOfHistograms;
595  }
596  incr=0;
597  }
598 
599  if (!next_pos(ptr_stack, info.number_stack)) break;
600  }
601  }
602  else if (info.histtype == "matr") // 2d histogram
603  {
604  TString Name = "H2D_" + info.specifier;
605  ListOfLibrairies->SetName(Name);
606 
607  if (info.number_stack.size() < 2)
608  {
609  std::cerr << "invalid format";
610  return 0x0;
611  }
612 
613  int x_channels = info.number_stack.back();
614  info.number_stack.pop_back();
615  int y_channels = info.number_stack.back();
616  info.number_stack.pop_back();
617 
618  if (!info.number_stack.size())
619  info.number_stack.push_back(1);
620 
621  std::vector<int> ptr_stack(info.number_stack.size(), 0);
622 
623  for (;;)
624  {
625  // build the entry name and subdirectory structure
626  std::ostringstream dir_name;
627  dir_name << info.basename << "_" << info.specifier;
628  for (uint n = 0; n < ptr_stack.size()-1; ++n)
629  dir_name << "_" << std::setw(3) << std::setfill('0') << ptr_stack[n];
630 
631  std::ostringstream histname;
632  histname << "H2D_" << CrystalName.Data() << "_" << dir_name.str() << "_" << std::setw(3) << std::setfill('0') << ptr_stack.back();
633 
635  TString LibraryName = dir_name.str();
636  if(!ListOfLibrairies->Contains(LibraryName))
637  {
638  TList *NewLibrary = new TList();
639  NewLibrary->SetOwner();
640  NewLibrary->SetName(LibraryName);
641  ListOfLibrairies->Add(NewLibrary);
642  }
644  TList *ListOfHistograms = (TList*)ListOfLibrairies->FindObject(LibraryName);
645 
646  TString HistName = (histname.str());
647  TH2I *hist = (TH2I*)gROOT->FindObject(HistName);
648  if(hist) hist->Clear();
649 
650  hist = new TH2I(HistName, HistName,
651  x_channels, 0, x_channels,
652  y_channels, 0, y_channels
653  );
654 
655  if (info.datatype == "UI")
656  read_2d_data<uint32_t>(in, hist);
657  else if (info.datatype == "US")
658  read_2d_data<uint16_t>(in, hist);
659  else if (info.datatype == "S")
660  read_2d_data<int16_t>(in, hist);
661  else if (info.datatype == "F")
662  read_2d_data<float>(in, hist);
663 
664  if(hist->GetEntries() != 0 && hist->Integral() != 0.)ListOfHistograms->Add(hist);
665  else delete hist;
666 
668  incr++;
669  if(incr==info.number_stack[1])
670  {
671  if(ListOfHistograms->GetSize()==0)
672  {
673  ListOfLibrairies->Remove(ListOfHistograms);
674  delete ListOfHistograms;
675  }
676  incr=0;
677  }
678 
679  if (!next_pos(ptr_stack, info.number_stack))
680  break;
681  }
682  }
683 
684  return ListOfLibrairies;
685 }
686 
688 
689 TString GetFileName(TString DefaultDir,TString FileExt)
690 {
691 
696 
697  TString FileType;
698  if(FileExt=="*.root") FileType = "Root Files";
699  else if(FileExt=="*.dat") FileType = "Data Files";
700  else if(FileExt=="gen_conf.py") FileType = "gen_conf Files";
701  else if(FileExt=="*.*") FileType = "All_Files";
702 
703  const char *filetypes[] = {FileType, FileExt,"All files", "*", 0, 0};
704 
705  TGFileInfo fi;
706  fi.fFileTypes = filetypes;
707  fi.fIniDir = StrDup(DefaultDir);
708 
709  new TGFileDialog(gClient->GetDefaultRoot(), gClient->GetDefaultRoot() , kFDOpen, &fi);
710  if (!fi.fFilename)
711  {
712  cout<<"!!!! **** WARNING **** !!!! No file Selected ==> exit"<<endl;
713  return "";
714  }
715 
716  return (TString)fi.fFilename;
717 }
718 
720 
721 std::map<TString, double> ReadGain(TString gen_conf_Path)
722 {
723  std::map<TString, double> GainMap;
724 
725  std::ifstream f_in(gen_conf_Path);
726  string Line;
727  TString Buffer;
728 
729  while(f_in)
730  {
731  getline(f_in,Line);
732  Buffer = Line;
733 
734  if(Buffer=="CrystalProducer=(")
735  {
736  GainMap["Prod"] = 1.;
737  while(f_in)
738  {
739  getline(f_in,Line);
740  Buffer = Line;
741  if(Buffer.Contains("ProjeM1") && !Buffer.BeginsWith("#"))
742  {
743  TObjArray *loa=Buffer.Tokenize(" ");
744  GainMap["Prod"] = ((TObjString*)loa->At(2))->GetString().Atof();
745  }
746  if(Buffer.BeginsWith("}"))break;
747  }
748  }
749  else if(Buffer=="PreprocessingFilter=(")
750  {
751  GainMap["Prep"] = 1.;
752  while(f_in)
753  {
754  getline(f_in,Line);
755  Buffer = Line;
756  if(Buffer.Contains("EnergyGain") && !Buffer.BeginsWith("#"))
757  {
758  TObjArray *loa=Buffer.Tokenize(" ");
759  GainMap["Prep"] = ((TObjString*)loa->At(1))->GetString().Atof();;
760  }
761  if(Buffer.BeginsWith("}"))break;
762  }
763  }
764  else if(Buffer=="PSAFilter=(")
765  {
766  GainMap["Psa"] = 1.;
767  while(f_in)
768  {
769  getline(f_in,Line);
770  Buffer = Line;
771  if(Buffer.Contains("EnergyGain") && !Buffer.BeginsWith("#"))
772  {
773  TObjArray *loa=Buffer.Tokenize(" ");
774  GainMap["Psa"] = ((TObjString*)loa->At(1))->GetString().Atof();;
775  }
776  if(Buffer.BeginsWith("}"))break;
777  }
778  }
779  else if(Buffer=="PostPSAFilter=(")
780  {
781  GainMap["Post"] = 1.;
782  while(f_in)
783  {
784  getline(f_in,Line);
785  Buffer = Line;
786  if(Buffer.Contains("EnergyGain") && !Buffer.BeginsWith("#"))
787  {
788  TObjArray *loa=Buffer.Tokenize(" ");
789  GainMap["Post"] = ((TObjString*)loa->At(1))->GetString().Atof();;
790  }
791  if(Buffer.BeginsWith("}"))break;
792  }
793  }
794  else if(Buffer=="TrackingFilter=(")
795  {
796  GainMap["Track"] = 1.;
797  while(f_in)
798  {
799  getline(f_in,Line);
800  Buffer = Line;
801  if(Buffer.Contains("EnergyGain") && !Buffer.BeginsWith("#"))
802  {
803  TObjArray *loa=Buffer.Tokenize(" ");
804  GainMap["Track"] = ((TObjString*)loa->At(1))->GetString().Atof();;
805  }
806  if(Buffer.BeginsWith("}"))break;
807  }
808  }
809  }
810 
811  return GainMap;
812 }
813 
815 
816 void BuildTasks(TList *ListOfHists, TString RunNbr, std::map<TString, double> GainMap)
817 {
818  SpectraViewerWatcher *Global = new SpectraViewerWatcher(RunNbr,RunNbr);
819  gROOT->GetListOfTasks()->Add(Global);
820 
821  SpectraViewerWatcher *LLPWatchers = new SpectraViewerWatcher("LLPWatchers","LLPWatchers");
822  Global->Add(LLPWatchers);
823  SpectraViewerWatcher *GLPWatchers = new SpectraViewerWatcher("GLPWatchers","GLPWatchers");
824  Global->Add(GLPWatchers);
825 
826  TIter IterCrystal(ListOfHists);
827  TObject *oCrystal;
828  while ( (oCrystal = IterCrystal()) )
829  {
830  TString LevelName = oCrystal->GetName();
831  bool IsLocal = false;
832  if(LevelName.Atoi()>0) IsLocal = true;
833  else if(!LevelName.Contains("Track") && !LevelName.Contains("Evb__")) IsLocal = true;
834  TTask *TopTask;
835  if(IsLocal)TopTask = (TTask*)((TTask*)gROOT->GetListOfTasks()->FindObject(RunNbr))->GetListOfTasks()->FindObject("LLPWatchers");
836  else TopTask = (TTask*)((TTask*)gROOT->GetListOfTasks()->FindObject(RunNbr))->GetListOfTasks()->FindObject("GLPWatchers");
837 
838  SpectraViewerWatcher *LevelWatcher = new SpectraViewerWatcher(LevelName,LevelName);
839  TopTask->Add(LevelWatcher);
840 
841  TList *ListOfActors = ((TList*)oCrystal);
842  TIter IterActors(ListOfActors);
843  TObject *oActors;
844  while ( (oActors = IterActors()) )
845  {
846  TString ActorName = oActors->GetName();
847 
848  TList *ListOfObservables = ((TList*)oActors);
849  TIter IterObservables(ListOfObservables);
850  TObject *oObservables;
851 
852  SpectraViewerWatcher *ActorWatcher;
853  ActorWatcher = (SpectraViewerWatcher*)LevelWatcher->GetListOfTasks()->FindObject(ActorName);
854  if( ActorWatcher == 0x0 ) ActorWatcher = new SpectraViewerWatcher(ActorName,ActorName);
855 
856  bool IsActorBuild = false;
857 
858  while ( (oObservables = IterObservables()) )
859  {
860  TString ObservableName = oObservables->GetName();
861 
862  TList *ListOfLibraries = (TList*)oObservables;
863 
864  TObjString *FileName = (TObjString*)ListOfLibraries->At(0);
865 
866  SpectraViewerWatcher *ObservableWatcher = 0x0;
867 
868  if(ActorName=="Prod" && ObservableName=="H1D_Baseline")
869  {
870  ObservableWatcher = new BaselineWatcher(ObservableName,ObservableName);
871  }
872  if(ActorName=="Prod" && ObservableName=="H1D_Ampli")
873  {
874  ObservableWatcher = new RawAmpWatcher(ObservableName,ObservableName);
875  ((RawAmpWatcher*)ObservableWatcher)->SetGain(GainMap["Prod"]);
876  }
877  if(ObservableName.Contains("samp"))
878  {
879  if(ObservableName.Contains("Traces") && ( ObservableName.Contains("Prep") || ObservableName.Contains("Prod")))
880  ObservableWatcher = new SignalWatcherTracesPrepProd(ObservableName,ObservableName);
881 
882  if(ObservableName.Contains("Traces") && ObservableName.Contains("Psa"))
883  ObservableWatcher = new SignalWatcherTracesPsa(ObservableName,ObservableName);
884 
885  if(ObservableName.Contains("AverSingles") && ObservableName.Contains("Psa"))
886  ObservableWatcher = new SignalWatcherAverSinglesPsa(ObservableName,ObservableName);
887  }
888 
889  if(ObservableWatcher != 0x0)
890  {
891  ObservableWatcher->SetCrystal(LevelName);
892  ObservableWatcher->SetFileName(FileName->GetString());
893  ListOfLibraries->Remove(FileName);
894  ObservableWatcher->SetListOfLibrairies(ListOfLibraries);
895  ActorWatcher->Add(ObservableWatcher);
896  IsActorBuild = true;
897  }
898  }
899 
900  if(IsActorBuild) LevelWatcher->Add(ActorWatcher);
901  else delete ActorWatcher;
902  }
903  }
904 }
void Import(TString Incl="*", TString Excl="*.samp", TString DefaultPath="")
*/
Definition: SpecViewer.C:48
TBrowser * b
std::string histtype
Definition: SpecViewer.h:41
void BuildTasks(TList *ListOfHists, TString RunNbr, std::map< TString, double > GainMap)
******************************************************************************************/// ...
Definition: SpecViewer.C:816
void SetListOfLibrairies(TList *l)
Definition: CanvasVisu.h:65
std::string basename
Definition: SpecViewer.h:38
TList * BuildHistograms(TString DataPath, TList *ListOfFiles, std::map< TString, double > GainMap)
******************************************************************************************/// ...
Definition: SpecViewer.C:312
std::string datatype
Definition: SpecViewer.h:42
TList * GetListFromIncExcl(TList *ListOfFiles, TString Incl, TString Excl)
******************************************************************************************/// ...
Definition: SpecViewer.C:227
LogMessage & info(LogMessage &)
manipulator to modify the LogMessage
std::string specifier
Definition: SpecViewer.h:39
void SetFileName(TString name)
******************************************************************************************/// ...
bool next_pos(std::vector< int > &ptr, std::vector< int > &max)
******************************************************************************************/// ...
Definition: SpecViewer.C:395
TList * ReadFile(TString FilePath, DinoFileInfo info, TString CrystalName, std::map< TString, double > GainMap)
******************************************************************************************/// ...
Definition: SpecViewer.C:417
TString GetFileName(TString DefaultDir, TString FileExt)
******************************************************************************************/// ...
Definition: SpecViewer.C:689
ADF::LogMessage & endl(ADF::LogMessage &log)
std::map< TString, double > ReadGain(TString gen_conf_Path)
******************************************************************************************/// ...
Definition: SpecViewer.C:721
void ImportFile(TString DefaultPath="", Double_t DefGain=1)
******************************************************************************************/// ...
Definition: SpecViewer.C:158
std::vector< int > number_stack
Definition: SpecViewer.h:43
void SetCrystal(TString name)
Definition: CanvasVisu.h:68