GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
adf/Macros/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 
24 // Gw and Watchers
25 #include "RootAFP.h"
26 #include "FrameDispatcher.h"
27 
28 #include "EmulatorControl.h"
29 #include "Emulator.h"
30 #include "SetupWatchers.C"
31 
32 using namespace Gw;
33 using namespace ADF;
34 
36 /*
37  An emulator is composed of producer that reads data from .adf files
38  and send the buffer to an FrameDispatcher.
39 
40  Watchers, in which the analysis is done are attached to the FrameDispatcher.
41 
42  Watchers are added to the FrameDispacher using the SetupWatcher function
43  that is in the SetupWtachers.C (in order to be shared with other macros see OnlineWatchers examples)
44 
45  Of course one can define everything in a single macro like it is done in DoMyTree.
46 
47  @author O.Stezowski
48 
49 */
50 void OfflineWatchers(TFile *file = 0x0)
51 {
52  // MainDir is the top dir to organise histograms in subdirectories
53  // each one being attached to a given task.
54  // Warning, a Watcher creates a new root directory (in the constructor) in the current directory
55  // if you want to keep the same tree structures as for directories,
56  // before allocating a new Watcher, think to set correctly its parent directory
57  // see for instance mainADF->GetDirectory()->cd();
58  TDirectory *MainDir = gROOT;
59  if ( file )
60  MainDir = file;
61 
62  // chain a producer and a FrameDispacher to which Watchers are attached
64 
65  if ( ! emulator.Init() ) {
66  std::cout << "Cannot Init emulator" << std::endl;
67  return;
68  }
69  else
70  emulator.GetConsumer()->SetDirectory(MainDir,MainDir);
71 
72  // add watchers to the dispatcher
73  // ADF ----------------------------------------------------------------
74  // watchers on the key part
75  MainDir->cd();
76  SetupWatchers("ADF",emulator.GetConsumer());
77 
78  // RANC1 --------------------------------------------------------------
79  // watchers on the ancillary frame
80  MainDir->cd();
81  //SetupWatchers("RANC1",emulator.GetConsumer());
82  // -------------------------------------------------------------------
83 
84  // EB -----------------------------------------------------------------
85  // output of the EB ... hits only
86  MainDir->cd();
87  // SetupWatchers("EB",emulator.GetConsumer());
88  // -------------------------------------------------------------------
89 
90  // MERGER -------------------------------------------------------------
91  // output of the merger ... hits correlated to ancillary
92  MainDir->cd();
93  // SetupWatchers("MERGER",emulator.GetConsumer());
94  // -------------------------------------------------------------------
95 
96  // After TRACKING -----------------------------------------------------
97  // output of the tracking ... hits, tracked gamma-rays correlated to ancillary
98  MainDir->cd();
99  //SetupWatchers("TRACKING",emulator.GetConsumer());
100  // -------------------------------------------------------------------
101 
102  // run
103  emulator.Run();
104  // displays statistics and keeps all histograms
105  // emulator.GetConsumer()->GetFrameIO().Print();
106 
107  // write all the spectra produced by the different watchers in a root file
108  MainDir->Write();
109 }
110 
111 #if !defined(__CINT__)
112 int main(int argc, char **argv)
113 {
114  // a new root file is created
115  TFile f("Offline.root","RECREATE");
116  // run your analysis on it
117  OfflineWatchers(&f);
118 
119  return 1;
120 }
121 #endif
122 
123 
124 
virtual Bool_t Run(UInt_t max_loop=kMaxUInt_t)
loop
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.
Cons_actor * GetConsumer()
virtual Bool_t Init(const Char_t *rootafp)
Init the emulator using a different root afp file for the producer.
header file for RootAFP.cpp
ADF::LogMessage & endl(ADF::LogMessage &log)
int main(int argc, char **argv)
void OfflineWatchers(TFile *file=0x0)
This function shows how to do offline analysis using the watchers.
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