GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
adf/Macros/GANIL/OfflineWatchers.C
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (c) IPNL, IN2P3, CNRS *
3  * Contibutor(s) : *
4  * Olivier Stezowski stezow(AT)ipnl.in2p3.fr [2014] *
5  * Jeremie Dudouet j.dudouet(AT)ipnl.in2p3.fr [2014] *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 
23 // ROOT includes
24 #include "TROOT.h"
25 #include "TBrowser.h"
26 #include "TSystem.h"
27 
28 // Gw and Watchers
29 #include "RootAFP.h"
30 #include "ReadMezzAFP.h"
31 
32 #include "FrameDispatcher.h"
33 
34 #include "EmulatorControl.h"
35 #include "Emulator.h"
36 
37 // same include that for Online
38 #include "SetupWatchers.C"
39 
41 namespace {
42  // ADF CRYSTAL CCRYSTAL PSA RANC0 EB MERGER TRACKING
43  TString EntryPointInSetupWatchers = "TRACKING"; // selection in the SetupWatcher.C file
44  TString PathToOut = "./Out"; // path where to store root files. It should exist !
45  TString PatternOfROOTFiles = ""; // basename for ROOT files. If empty, files are not saved
46  TString TTreeName = "TreeMaster"; // name of the Tree
47  TString TTeeTilte = "GANIL Tree" ; // Title
48 
49  TString Run = "" ; // used to add run number by hand or automatically in case OfflineWatcher(run_number, ...) is called
50 
51 // Availables producer : RootAFP ==> Used to read adf input files
52 // ReadMezzAFP ==> Used to read cdat files produced by the mezzanines (only for ADF and CRYSTAL levels)
53 // ReadPSAHitsAFP ==> Used to read Root files containing psa hits of a global event (only for Tracking watcher level)
54 
55  TString ProducerType = "RootAFP";
56 }
57 
58 using namespace Gw;
59 using namespace ADF;
60 
61 void OfflineWatchers(Int_t start = -1, TFile *file = 0x0 );
62 void OfflineWatchers(Int_t start, const Char_t *rootafp, TString EntryPoint,bool ReadCDAT);
63 void OfflineWatchers(Int_t which_run, const char *which_experiment, const char *which_adf_data,const char *run_patt, Option_t *opt_adf_pattern, Int_t start = -1);
65 
67 /*
68  An emulator is composed of producer that reads data from .adf files
69  and send the buffer to an FrameDispatcher.
70 
71  Watchers, in which the analysis is done are attached to the FrameDispatcher.
72 
73  Watchers are added to the FrameDispacher using the SetupWatcher function
74  that is in the SetupWtachers.C (in order to be shared with other macros see OnlineWatchers examples)
75 
76  @author O.Stezowski
77 
78 */
79 void OfflineWatchers(Int_t start, TFile *file)
80 {
81  // MainDir is the top dir to organise histograms in subdirectories
82  // each one being attached to a given task.
83  TDirectory *MainDir = gROOT;
84 
85  // chain a producer and a FrameDispacher to which Watchers are attached
87  FrameDispatcher *FDispatcher;
88 
89  if ( ! emulator->Init() ) {
90  std::cout << "Cannot Init emulator" << std::endl; return;
91  }
92  else {
93  FDispatcher = (FrameDispatcher*) emulator->GetBaseConsumer();
94  if ( file )
95  MainDir = file;
96  if ( MainDir != gROOT )
97  FDispatcher->SetDirectory(MainDir,MainDir);
98  }
99 
100  // to have all watcher in the task folder
101  EmulatorControl *control = new EmulatorControl(emulator);
102  gROOT->GetListOfTasks()->Add( control );
103  gROOT->GetListOfTasks()->Add( FDispatcher );
104 
105  TTreeMaster::SetDefaultPathAndName(PathToOut.Data(),TTreeName.Data());
106  SetupWatchers(EntryPointInSetupWatchers.Data(),FDispatcher);
107 
108  if ( !gROOT->IsBatch() ) {
109  TBrowser *b = (TBrowser*)gROOT->GetListOfBrowsers()->Last();
110 
111  TFolder *GwWatchersFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("GwWatchers");
112  if(GwWatchersFolder) b->Add(GwWatchersFolder);
113 
114  TFolder *RootFilesFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("ROOT Files");
115  if(RootFilesFolder) b->Add(RootFilesFolder);
116  }
117 
118  // run
119  if(start==-1)emulator->Run();
120  else if(start>0)emulator->Run(start);
121 
122  // displays statistics and keeps all histograms
123  // write all the spectra produced by the different watchers in a root file
124  if ( MainDir != gROOT && start>0 ) {
125  control->Save();
126  }
127 }
128 
129 void OfflineWatchers(Int_t start, const Char_t *rootafp, TString EntryPoint, bool ReadCDAT)
130 {
131  // MainDir is the top dir to organise histograms in subdirectories
132  // each one being attached to a given task.
133  TDirectory *MainDir = gROOT;
134 
135  if(EntryPoint!="") EntryPointInSetupWatchers = EntryPoint;
136  if(ReadCDAT) ProducerType = "ReadMezzAFP";
137 
138  // chain a producer and a FrameDispacher to which Watchers are attached
139  BaseEmulatorChain *emulator;
140  FrameDispatcher *FDispatcher;
141 
142  emulator = DefineEmulatorType();
143 
144  if ( ! emulator->Init(rootafp) ) {
145  std::cout << "Cannot Init emulator" << std::endl; return;
146  }
147  else {
148  FDispatcher = (FrameDispatcher*) emulator->GetBaseConsumer();
149  TFile *tmp_rfile = 0x0;
150  if ( PatternOfROOTFiles != "" ) {
151  tmp_rfile = TFile::Open( Form("%s/%s.root",PathToOut.Data(),PatternOfROOTFiles.Data()) , "UPDATE" );
152  }
153  if ( tmp_rfile ) {
154  MainDir = tmp_rfile;
155  }
156  if ( MainDir != gROOT )
157  FDispatcher->SetDirectory(MainDir,MainDir);
158  }
159 
160  // to have all watcher in the task folder
161  EmulatorControl *control = new EmulatorControl(emulator);
162  gROOT->GetListOfTasks()->Add( control );
163  gROOT->GetListOfTasks()->Add( FDispatcher );
164 
165  TTreeMaster::SetDefaultPathAndName(PathToOut.Data(),TTreeName.Data());
166  SetupWatchers(EntryPointInSetupWatchers.Data(),FDispatcher);
167 
168  if ( !gROOT->IsBatch() ) {
169  TBrowser *b = (TBrowser*)gROOT->GetListOfBrowsers()->Last();
170 
171  TFolder *GwWatchersFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("GwWatchers");
172  if(GwWatchersFolder) b->Add(GwWatchersFolder);
173 
174  TFolder *RootFilesFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("ROOT Files");
175  if(RootFilesFolder) b->Add(RootFilesFolder);
176  }
177 
178  // run
179  if(start==-1)emulator->Run();
180  else if(start>0)emulator->Run(start);
181 
182  // displays statistics and keeps all histograms
183  // write all the spectra produced by the different watchers in a root file
184  if ( MainDir != gROOT && start ) {
185  control->Save();
186  }
187 }
188 
189 void OfflineWatchers(Int_t which_run, const char *which_experiment, const char *which_adf_data, const char *run_patt, Option_t *opt_adf_pattern, Int_t start)
190 {
191  TDirectory *MainDir = gROOT;
192 
193  // chain a producer and a FrameDispacher to which Watchers are attached
195  FrameDispatcher *FDispatcher;
196 
197  if ( ! emulator->Init(which_run,which_experiment,which_adf_data,run_patt,opt_adf_pattern) ) {
198  std::cout << "Cannot Init emulator" << std::endl;
199  return;
200  }
201  else {
202  FDispatcher = (FrameDispatcher*) emulator->GetBaseConsumer();
203  TFile *tmp_rfile = 0x0;
204  if ( PatternOfROOTFiles != "" ) {
205  tmp_rfile = TFile::Open( Form("%s/%s.root",PathToOut.Data(),PatternOfROOTFiles.Data()) , "UPDATE" );
206  }
207  if ( tmp_rfile ) {
208  MainDir = tmp_rfile;
209  }
210  if ( MainDir != gROOT )
211  FDispatcher->SetDirectory(MainDir,MainDir);
212  }
213 
214  // to have all watcher in the task folder
215  EmulatorControl *control = new EmulatorControl(emulator);
216  gROOT->GetListOfTasks()->Add( control );
217  gROOT->GetListOfTasks()->Add( FDispatcher );
218 
219  TTreeMaster::SetDefaultPathAndName(PathToOut.Data(),TTreeName.Data());
220  SetupWatchers(EntryPointInSetupWatchers.Data(),FDispatcher);
221 
222  if ( !gROOT->IsBatch() ) {
223  TBrowser *b = (TBrowser*)gROOT->GetListOfBrowsers()->Last();
224 
225  TFolder *GwWatchersFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("GwWatchers");
226  if(GwWatchersFolder) b->Add(GwWatchersFolder);
227 
228  TFolder *RootFilesFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("ROOT Files");
229  if(RootFilesFolder) b->Add(RootFilesFolder);
230  }
231 
232  // run
233  if(start==-1)emulator->Run();
234  else if(start>0)emulator->Run(start);
235 
236  // displays statistics and keeps all histograms
237  // write all the spectra produced by the different watchers in a root file
238  if ( MainDir != gROOT && start ) {
239  control->Save();
240  }
241 }
242 
244 {
245  BaseEmulatorChain *emulator = 0x0;
246 
247  if(ProducerType == "RootAFP")
248  emulator = new EmulatorPC<RootAFP,FrameDispatcher>("./");
249  else if(ProducerType == "ReadMezzAFP")
250  emulator = new EmulatorPC<ReadMezzAFP,FrameDispatcher>("./");
251 
252  return emulator;
253 }
254 
255 
TBrowser * b
Process a buffer, trigg and dispachs the work to sub-watchers.
void Save(Option_t *opt="*")
Save the spectra.
Bool_t SetupWatchers(const char *df_type, FrameDispatcher *fd, const char *ext="")
It shows how to set up the watchers for different kind of data flow.
virtual Bool_t Run(UInt_t=kMaxUInt)
loop
header file for ReadMezzAFP.cpp
virtual ADF::NarvalConsumer * GetBaseConsumer()
virtual Bool_t Init()
It should be overwritten !
void OfflineWatchers(Int_t start=-1, TFile *file=0x0)
This function shows how to do offline analysis using the watchers. if a root file is given...
to have a common base class to be able to control the emulator through a TTask
header file for RootAFP.cpp
ADF::LogMessage & endl(ADF::LogMessage &log)
BaseEmulatorChain * DefineEmulatorType()
static void SetDefaultPathAndName(const char *new_path="./Out", const char *treename="TreeMaster")
to change the default value of path for output. It returns the old one
virtual void SetDirectory(TDirectory *mother_dir_of_watcher, TDirectory *mother_dir_for_tag, Bool_t load_objects=true)
change directories and Load objects if required