GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StogsWatchers.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 #include "StogsAFP.h"
29 
30 #include "FrameDispatcher.h"
31 #include "EmulatorControl.h"
32 #include "Emulator.h"
33 
34 // same include that for Online
35 #include "SetupWatchers.C"
36 
38 namespace {
39  // ADF CRYSTAL CCRYSTAL PSA RANC0 EB MERGER TRACKING
40  TString EntryPointInSetupWatchers = "EB"; // selection in the SetupWatcher.C file
41  TString PathToOut = "./Out"; // path where to store root files. It should exist !
42  TString PatternOfROOTFiles = ""; // basename for ROOT files. If empty, files are not saved
43  TString TTreeName = "TreeMaster"; // name of the Tree
44  TString TTeeTilte = "GANIL Tree" ; // Title
45 
46  TString Run = "" ; // used to add run number by hand or automatically in case OfflineWatcher(run_number, ...) is called
47 
48  TString ProducerType = "StogsAFP";
49  bool ADHitTreeMode = false;
50 }
51 
52 using namespace Gw;
53 using namespace ADF;
54 
55 void StogsWatchers(Int_t start = -1, const Char_t *rootafp = "");
57 
59 /*
60  An emulator is composed of producer that reads data from .adf files
61  and send the buffer to an FrameDispatcher.
62 
63  Watchers, in which the analysis is done are attached to the FrameDispatcher.
64 
65  Watchers are added to the FrameDispacher using the SetupWatcher function
66  that is in the SetupWtachers.C (in order to be shared with other macros see OnlineWatchers examples)
67 
68  @author O.Stezowski
69 
70 */
71 
72 void StogsWatchers(Int_t start,const Char_t *rootafp)
73 {
74  // MainDir is the top dir to organise histograms in subdirectories
75  // each one being attached to a given task.
76  TDirectory *MainDir = gROOT;
77 
78  // chain a producer and a FrameDispacher to which Watchers are attached
79  BaseEmulatorChain *emulator;
80  FrameDispatcher *FDispatcher;
81 
82  emulator = DefineEmulatorType();
83 
84  if ( ! emulator->Init(rootafp) ) {
85  std::cout << "Cannot Init emulator" << std::endl; return;
86  }
87  else {
88  FDispatcher = (FrameDispatcher*) emulator->GetBaseConsumer();
89  TFile *tmp_rfile = 0x0;
90  if ( PatternOfROOTFiles != "" ) {
91  tmp_rfile = TFile::Open( Form("%s/%s.root",PathToOut.Data(),PatternOfROOTFiles.Data()) , "UPDATE" );
92  }
93  if ( tmp_rfile ) {
94  MainDir = tmp_rfile;
95  }
96  if ( MainDir != gROOT )
97  FDispatcher->SetDirectory(MainDir,MainDir);
98  }
99 
100  if(ProducerType == "StogsAFP")
101  {
102  StogsAFP *prod = (StogsAFP*)emulator->GetBaseProducer();
103  prod->SetADHitTreeMode(ADHitTreeMode);
104  }
105 
106  // to have all watcher in the task folder
107  EmulatorControl *control = new EmulatorControl(emulator);
108  gROOT->GetListOfTasks()->Add( control );
109  gROOT->GetListOfTasks()->Add( FDispatcher );
110 
111  TTreeMaster::SetDefaultPathAndName(PathToOut.Data(),TTreeName.Data());
112  SetupWatchers(EntryPointInSetupWatchers.Data(),FDispatcher);
113 
114  if ( !gROOT->IsBatch() ) {
115  TBrowser *b = (TBrowser*)gROOT->GetListOfBrowsers()->Last();
116 
117  TFolder *GwWatchersFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("GwWatchers");
118  if(GwWatchersFolder) b->Add(GwWatchersFolder);
119 
120  TFolder *RootFilesFolder = (TFolder*)gROOT->GetRootFolder()->FindObject("ROOT Files");
121  if(RootFilesFolder) b->Add(RootFilesFolder);
122  }
123 
124  // run
125  if(start==-1)emulator->Run();
126  else if(start>0)emulator->Run(start);
127 
128  // displays statistics and keeps all histograms
129  // write all the spectra produced by the different watchers in a root file
130  if ( MainDir != gROOT && start ) {
131  control->Save();
132  }
133 }
134 
136 {
137  BaseEmulatorChain *emulator = 0x0;
138 
139  if(ProducerType == "StogsAFP")
140  {
141  emulator = new EmulatorPC<StogsAFP,FrameDispatcher>("./");
142  }
143 
144  return emulator;
145 }
146 
147 
TBrowser * b
virtual ADF::NarvalProducer * GetBaseProducer()
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
virtual ADF::NarvalConsumer * GetBaseConsumer()
void StogsWatchers(Int_t start=-1, const Char_t *rootafp="")
This function shows how to do offline analysis using the watchers. if a root file is given...
Definition: StogsWatchers.C:72
virtual Bool_t Init()
It should be overwritten !
to have a common base class to be able to control the emulator through a TTask
ADF::LogMessage & endl(ADF::LogMessage &log)
BaseEmulatorChain * DefineEmulatorType()
void SetADHitTreeMode(bool active)
Definition: StogsAFP.h:87
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