GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ill/OfflineWatchers.C
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2010 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
21 // ROOT includes
22 #include "TROOT.h"
23 #include "TTreeWatchers.h"
24 
25 // Gw and Watchers
26 #include "NOMADFile.h"
27 #include "NOMADFilter.h"
28 #include "NOMADBuilder.h"
29 
30 #include "FrameDispatcher.h"
31 #include "BlackHole.h"
32 
33 #include "DEmulator.h"
34 
35 // watchers
36 #include "ILLWatchers.h"
37 
38 using namespace Gw;
39 using namespace ADF;
40 
42 
52 void CheckRawData(TFile *file = 0x0, TFile *file_tag = 0x0, Bool_t load_only = false)
53 {
54 // to avoid too much warning on output screen
56 
57 // a root file to save specta in case
58  TDirectory *MainDir = file, *MainTagDir = file_tag;
59  if ( file == 0 ) {
60  MainDir = new TFile("RawData.root","UPDATE");
61  }
62  if ( file_tag == 0 ) {
63  MainTagDir = new TFile("RawDataTag.root","UPDATE");
64  }
65 
66 // Emulator is a chain of a NOMADFile, a NOMADFilter and a FrameDispacher to which Watchers are attached
67  DEmulator *emulator = new DEmulator();
68 
69  emulator->SetGlobal ( NamedItem<Short_t>("Generation",0) );
70 
71 // customization of the emulator
72  emulator->Add<NOMADFile>("-","Producer");
73  //
74  emulator->SetGlobal ( NamedItem<UInt_t>("SizeDataBlockC",aMByte) );
75  emulator->Add<NOMADFilter>("Producer","Calib");
76  //
77  emulator->SetGlobal ( NamedItem<UInt_t>("SizeDataBlockC",5*aMByte) );
78  // emulator.Add<BlackHole>("Calib","Watchers");
79  emulator->Add<FrameDispatcher>("Calib","Watchers");
80 
81 // Create all actors in the topology
82  emulator->Init() ;
83 
84 // Customize
85  FrameDispatcher *d =
86  emulator->GetActorByName<FrameDispatcher>("Watchers");
87  d->SetName("RawData");
88  d->SetDirectory(MainDir, MainTagDir);
89 
90  FrameTrigger *trig = new FrameTrigger("T");
91  trig->Add(FactoryItem("Default","UID",Version(1,1)),FactoryItem("Default","data",Version(0,0)));
92  trig->Universal(true);
93  d->SetTrigger(trig);
94 
95  Watcher *w = d->Add<DoEXOILLCalib>("ILLSpecta","Spectra");
96  gROOT->GetListOfTasks()->Add(w);
97 
98 // Run the emulator
99  if ( !load_only ) {
100  emulator->Run();
101  d->Snapshot("* !tag");
102  }
103 }
104 
106 
117 void AnalyseData(TFile *file = 0x0, TFile *file_tag = 0x0, Bool_t load_only = false)
118 {
119 // to avoid too much warning on output screen
121 
122 // a root file to save specta in case
123  TDirectory *MainDir = file, *MainTagDir = file_tag;
124  if ( file == 0 ) {
125  MainDir = new TFile("Analysis.root","UPDATE");
126  }
127  if ( file_tag == 0 ) {
128  MainTagDir = new TFile("AnalysisTag.root","UPDATE");
129  }
130 
131 // Emulator is a chain of a NOMADFile, a NOMADFilter and a FrameDispacher to which Watchers are attached
132  DEmulator *emulator = new DEmulator();
133 
134  emulator->SetGlobal ( NamedItem<Short_t>("Generation",0) );
135 
136  // customization of the emulator
137  emulator->Add<NOMADFile>("-","Producer");
138  // emulator->Add<NOMADGene>("-","Producer");
139  //
140  emulator->SetGlobal ( NamedItem<UInt_t>("SizeDataBlockC",aMByte) );
141  emulator->Add<NOMADBuilder>("Producer","Calib");
142  //
143  emulator->SetGlobal ( NamedItem<UInt_t>("SizeDataBlockC",5*aMByte) );
144  // emulator.Add<BlackHole>("Calib","Watchers");
145  emulator->Add<FrameDispatcher>("Calib","Watchers");
146  // Create all actors in the topology
147  emulator->Init() ;
148 
149 // Customize the final consumer
150  FrameDispatcher *d =
151  emulator->GetActorByName<FrameDispatcher>("Watchers");
152  d->SetName("RawData");
153  d->SetDirectory(MainDir, MainTagDir);
154 
155  FrameTrigger *trig = new FrameTrigger("T");
156  trig->Add(FactoryItem("Default","UID",Version(1,1)),FactoryItem("Default","data",Version(0,1)));
157  trig->Universal(true);
158  d->SetTrigger(trig);
159 
160  // list of watchers added
161  // singles
162  Watcher *w = d->Add<DoEXOILLCalib>("ILLSpecta","Spectra");
163  gROOT->GetListOfTasks()->Add(w);
164  // raw matrices
165  w = d->Add<RawMatrices>("RawMatrices","Coincidences");
166  gROOT->GetListOfTasks()->Add(w);
167  // gated matrix
168  std::ifstream in("GatedGG.conf"); std::string tmp, file_with_gates;
169  if ( in.is_open() == true ) {
170  getline(in,tmp);
171  tmp += " ";
172  while ( in.good() && !in.eof() ) { // read input stream line by line
173 
174  if ( tmp[0] == '#' ) {
175  getline(in,tmp);
176  continue;
177  } // this line is a comment
178 
179  std::istringstream decode(tmp); decode >> file_with_gates ;
180  w = d->Add<GatedGG>(file_with_gates.data(),"Gated Gamma Gamma Matrix");
181  gROOT->GetListOfTasks()->Add(w);
182 
183  getline(in,tmp);
184  tmp += " ";
185  }
186  in.close();
187  }
188 
189 // Run the emulator
190  if ( !load_only )
191  emulator->Run();
192 
193 // save spectra produced
194  d->Snapshot();
195 }
196 
197 void DoMyTree()
198 {
199  // to avoid too much warning on output screen
201 
202  // Emulator is a chain of a NOMADFile, a NOMADFilter and a FrameDispacher to which Watchers are attached
203  DEmulator *emulator =
204  new DEmulator();
205  emulator->SetGlobal ( NamedItem<Short_t>("Generation",0) );
206 
207  // customization of the emulator
208  emulator->Add<NOMADFile>("-","Producer");
209  emulator->SetGlobal ( NamedItem<UInt_t>("SizeDataBlockC",aMByte) );
210  emulator->Add<NOMADBuilder>("Producer","Calib");
211  emulator->SetGlobal ( NamedItem<UInt_t>("SizeDataBlockC",5*aMByte) );
212  emulator->Add<FrameDispatcher>("Calib","Watchers");
213 
214  // Create all actors in the topology
215  emulator->Init() ;
216 
217  // Customize
218  FrameDispatcher *d =
219  emulator->GetActorByName<FrameDispatcher>("Watchers");
220  d->SetName("RawData");
221 
222  FrameTrigger *trig = new FrameTrigger("T");
223  trig->Add(FactoryItem("Default","UID",Version(1,1)),FactoryItem("Default","data",Version(0,1)));
224  trig->Universal(true);
225  d->SetTrigger(trig);
226 
227 
228  TTreeMaster *rootmaster = d->Add<TTreeMaster>("ILLTree","Own the tree");
229  rootmaster->Add<MyILLTree>("EXO","Branch on EXOGAM DATA");
230 
231  // Run the emulator
232  emulator->Run();
233 
234  delete emulator;
235 }
236 
237 
238 void CheckReading(TFile *file = 0x0)
239 {
240  // to avoid too much warning on output screen
242 
243  // a root file to save specta in case
244  TDirectory *MainDir = file;
245  if ( file == 0 )
246  MainDir = new TFile("Offline.root","UPDATE");
247 
248  // Emulator is a chain of a NOMADFile, a NOMADFilter and a FrameDispacher to which Watchers are attached
249  DEmulator *emulator = new DEmulator();
250 
251  emulator->SetGlobal ( NamedItem<Short_t>("Generation",0) );
252 
253  // customization of the emulator
254  emulator->Add<NOMADFile>("-","Producer");
255  emulator->SetGlobal ( NamedItem<UInt_t>("SizeDataBlockC",aMByte) );
256  emulator->Add<NOMADFilter>("Producer","Calib");
257  emulator->SetGlobal ( NamedItem<UInt_t>("SizeDataBlockC",5*aMByte) );
258  // emulator.Add<BlackHole>("Calib","Watchers");
259 // emulator->Add<FrameDispatcher>("Calib","Watchers");
260  emulator->Add<BlackHole>("Calib","Watchers");
261 
262  // Run the emulator
263  emulator->Init() ;
264  emulator->Run();
265 
266 
267 }
268 
269 #if !defined(__CINT__)
270 int main(int /*argc*/, char ** /*argv*/)
271 {
272  // a new root file is created
273  TFile f("Offline.root","RECREATE");
274  // run your analysis on it
275  CheckRawData(&f);
276 
277  return 1;
278 }
279 #endif
280 
281 
282 
void CheckReading(TFile *file=0x0)
virtual void Add(TTask *)
add only Watchers to the list of tasks to avoid problems.
Definition: Watchers.cpp:244
virtual void SetGlobal(const ANamedItem &)
This method allows to modified some options of the emulator.
DLActor * Add(const Char_t *name_left, const Char_t *name_new_actor, const Char_t *name_right="-", const Char_t *conf_dir="./")
Definition: DEmulator.h:138
An general emulator, could run or not in multi-threading environement.
Definition: DEmulator.h:125
virtual void Run(Int_t max_loop=-1)
Run max loop.
Process a buffer, trigg and dispachs the work to sub-watchers.
static void SetDebug(short global_debug_level=0)
void AnalyseData(TFile *file=0x0, TFile *file_tag=0x0, Bool_t load_only=false)
This function shows how to do offline analysis using the watchers.
Watcher_T * Add(const Char_t *name, const Char_t *title, Short_t do_spectra, Short_t do_tree)
Allocate a watcher in charge of filling one part of the tree ==> Should inherits from TreeBuilder...
virtual Bool_t SetTrigger(ADF::DFTrigger *)
This is the default trigger for any added watcher.
void CheckRawData(TFile *file=0x0, TFile *file_tag=0x0, Bool_t load_only=false)
This function shows how to do offline analysis using the watchers.
int main(int, char **)
void DoMyTree()
Base class for a Watcher.
Definition: Watchers.h:60
black hole. It consumes data and just counts the number of bytes consumed
Definition: BlackHole.h:33
Watcher_T * Add(const Char_t *name, const Char_t *title, ADF::DFTrigger *t=0x0)
allocate a new watcher so that it creates corectly its directory under the dispatcher directory ...
const UInt_t aMByte
Definition: BaseBuffer.h:36
Base class for a generic frame trigger.
Definition: Trigger.h:249
Base class for version numbers.
Definition: Version.h:38
virtual SharedFP * Add(const FactoryItem &key_item, const FactoryItem &frame_item, bool iscons=true, const Char_t *option="")
Add a frame to the list of required frames.
Definition: Trigger.cpp:596
virtual void Init(const NamedItem< std::string > &init_sequence=NamedItem< std::string >("InitSequence","config load init"))
Init the emulator. To be called before calling Run.
Base class for building control spectra and calibrate.
Definition: ILLWatchers.h:106
virtual UInt_t Snapshot(Option_t *="*")
change kind of Watcher
Definition: Watchers.cpp:534
Built some correlation matrices.
Definition: ILLWatchers.h:173
header file for BlackHole.cpp
Watcher to build a tree with branches processed in several watchers.
Shows how to save data in a TTree.
Definition: ILLWatchers.h:233
build a gated matrix
Definition: ILLWatchers.h:208
void Universal(Bool_t b=true)
Set this trigger as universal or not.
Definition: Trigger.h:130
header file for DEmulator.cpp
virtual NarvalInterface * GetActorByName(const Char_t *) const
search for an actor in the emulator
Base class that described an item in a Factory.
Definition: FactoryItem.h:52
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