KaliVeda
Toolkit for HIC analysis
KVFAZIAReconDataAnalyser.cpp
1 /*
2 $Id: KVFAZIAReconDataAnalyser.cpp,v 1.4 2007/11/15 14:59:45 franklan Exp $
3 $Revision: 1.4 $
4 $Date: 2007/11/15 14:59:45 $
5 */
6 
7 //Created by KVClassFactory on Wed Apr 5 23:50:04 2006
8 //Author: Eric Bonnet
9 
10 #include "KVFAZIAReconDataAnalyser.h"
11 #include "KVDataSet.h"
12 #include "KVMultiDetArray.h"
13 
14 using namespace std;
15 
18 // For analysing reconstructed FAZIA data
19 //
21 
24 
26 {
27  //Default constructor
28  theTree = 0;
29  fLinkRawData = kFALSE;
30 }
31 
32 
33 
36 
37 KVFAZIAReconDataAnalyser::~KVFAZIAReconDataAnalyser()
38 {
39  //Destructor
40 }
41 
42 
43 
44 
47 
49 {
50  //Run the interactive analysis
51  if (gDataSet != GetDataSet()) GetDataSet()->cd();
52 
54  optl.ParseOptions(GetUserClassOptions());
55  fLinkRawData = optl.IsOptGiven("ReadRawData");
56 
57  //loop over runs
58  for (auto& r : GetRunList()) {
59  fRunNumber = r;
60  Info("SubmitTask", "treatment of run# %d", fRunNumber.run());
61  ProcessRun();
62  }
63 }
64 
65 
66 
75 
77 {
78  // Perform treatment of a given run
79  // Before processing each run, after opening the associated file, user's InitRun() method is called.
80  // After each run, user's EndRun() is called.
81  // For each event of each run, user's Analysis() method is called.
82  //
83  // For further customisation, the pre/post-methods are called just before and just after
84  // each of these methods (preInitRun(), postAnalysis(), etc. etc.)
85  TString fullPathToRunfile = gDataSet->GetFullPathToRunfile(GetDataType(), fRunNumber);
86  TFile* f = gDataSet->OpenRunfile<TFile>(GetDataType(), fRunNumber);
87  if (!(f && !f->IsZombie())) {
88  Error("ProcessRun", "file %s does not exist or is made zombie", fullPathToRunfile.Data());
89  return;
90  }
91 
92  theTree = (TTree*)f->Get("ReconstructedEvents");
93 
94  TFile* ffriend = 0;
95  if (fLinkRawData) {
96  fullPathToRunfile = gDataSet->GetFullPathToRunfile("raw", fRunNumber);
97  ffriend = gDataSet->OpenRunfile<TFile>("raw", fRunNumber);
98  if (!(ffriend && !ffriend->IsZombie())) {
99  Warning("ProcessRun", "file %s does not exist or is made zombie\n Reading of raw data is not possible", fullPathToRunfile.Data());
100  }
101  else {
102  theTree->AddFriend("FAZIA", ffriend);
103  }
104  }
105 
106  TString option("");
107  // Add any user-defined options
108  if (GetUserClassOptions() != "") {
109  if (option != "")
110  option += ",";
111  option += GetUserClassOptions();
112  }
113 
114  Info("SubmitTask", "Beginning TTree::Process... Option=%s", option.Data());
115  if (GetNbEventToRead()) {
116  theTree->Process(GetUserClassName(), option.Data(), GetNbEventToRead());
117  }
118  else {
119  theTree->Process(GetUserClassName(), option.Data());
120  }
121 
122  if (ffriend && ffriend->IsOpen())
123  ffriend->Close();
124  f->Close();
125 
126 }
127 
128 
129 // fSelector = 0;
130 //
131 // //if (theChain) delete theChain;
132 // theChain = new TChain("ReconstructedEvents");
133 // theChain->SetDirectory(0); // we handle delete
134 //
135 // //if (theFriendChain) delete theFriendChain;
136 // if (fLinkRawData) {
137 // theFriendChain = new TChain("FAZIA");
138 // theFriendChain->SetDirectory(0); // we handle delete
139 // } else {
140 // theFriendChain = 0;
141 // }
142 //
143 // fRunList.Begin();
144 // Int_t run;
145 //
146 // // open and add to TChain all required files
147 // // we force the opening of the files to avoid problems with xrootd which sometimes
148 // // seems to have a little difficulty
149 // while (!fRunList.End()) {
150 // run = fRunList.Next();
151 //
152 // //Add run file
153 // TString fullPathToRunfile = gDataSet->GetFullPathToRunfile(fDataType.Data(), run);
154 // cout << "Opening file " << fullPathToRunfile << endl;
155 // TFile* f = (TFile*)gDataSet->OpenRunfile(fDataType.Data(), run);
156 // cout << "Adding file " << fullPathToRunfile;
157 // cout << " to the TChain." << endl;
158 // theChain->Add(fullPathToRunfile);
159 // if (f && !f->IsZombie()) {
160 // // update run infos in available runs file if necessary
161 // KVAvailableRunsFile* ARF = gDataSet->GetAvailableRunsFile(fDataType.Data());
162 // if (ARF->InfosNeedUpdate(run, gSystem->BaseName(fullPathToRunfile))) {
163 // if (!((TTree*)f->Get("ReconstructedEvents"))) {
164 // Error("SubmitTask", "No tree named ReconstructedEvents is present in the current file");
165 // delete theChain;
166 // return;
167 // }
168 // TEnv* treeInfos = (TEnv*)((TTree*)f->Get("ReconstructedEvents"))->GetUserInfo()->FindObject("TEnv");
169 // if (treeInfos) {
170 // TString kvversion = treeInfos->GetValue("KVBase::GetKVVersion()", "");
171 // TString username = treeInfos->GetValue("gSystem->GetUserInfo()->fUser", "");
172 // if (kvversion != "") ARF->UpdateInfos(run, gSystem->BaseName(fullPathToRunfile), kvversion, username);
173 // } else {
174 // Info("SubmitTask", "No TEnv object associated to the tree");
175 // }
176 // }
177 // }
178 //
179 // //Add run file
180 // if (theFriendChain) {
181 // fullPathToRunfile = gDataSet->GetFullPathToRunfile("raw", run);
182 // cout << "Opening file " << fullPathToRunfile << endl;
183 // f = (TFile*)gDataSet->OpenRunfile("raw", run);
184 // cout << "Adding file " << fullPathToRunfile;
185 // cout << " to the friend TChain." << endl;
186 // theFriendChain->Add(fullPathToRunfile);
187 // }
188 // }
189 //
190 // if (theFriendChain) theChain->AddFriend("FAZIA");
191 //
192 // TotalEntriesToRead = theChain->GetEntries();
193 // TString option("");
194 // if (fDataSelector.Length()) {
195 // option.Form("DataSelector=%s", fDataSelector.Data());
196 // cout << "Data Selector : " << fDataSelector.Data() << endl;
197 // }
198 //
199 // // Add any user-defined options
200 // if (GetUserClassOptions() != "") {
201 // option += ",";
202 // option += GetUserClassOptions();
203 // }
204 //
205 // fSelector = (TSelector*)GetInstanceOfUserClass();
206 //
207 // if (!fSelector || !fSelector->InheritsFrom("TSelector")) {
208 // cout << "The selector \"" << GetUserClass() << "\" is not valid." << endl;
209 // cout << "Process aborted." << endl;
210 // } else {
211 // SafeDelete(fSelector);
212 // Info("SubmitTask", "Beginning TChain::Process...%s %s", GetUserClass(), option.Data());
213 // if (nbEventToRead) {
214 // theChain->Process(GetUserClass(), option.Data(), nbEventToRead);
215 // } else {
216 // theChain->Process(GetUserClass(), option.Data());
217 // }
218 // }
219 //
220 // if (theFriendChain) {
221 // theChain->RemoveFriend(theFriendChain);
222 // delete theFriendChain;
223 // theFriendChain = 0;
224 // }
225 // delete theChain;
226 // theChain = 0;
227 // fSelector = 0; //deleted by TChain/TTreePlayer
228 
229 
230 
231 
238 
240 {
241  // Called by currently-processed KVFAZIASelector before user's InitAnalysis() method.
242  // We build the multidetector for the current dataset in case informations on
243  // detector are needed e.g. to define histograms in InitAnalysis().
244  // Note that at this stage we are not analysing a given run, so the parameters
245  // of the array are not set (they will be set in preInitRun()).
246 
247  Info("preInitAnalysis", "Appel");
248  if (gDataSet && !gMultiDetArray) {
249  Info("preInitAnalysis", "Building of FAZIA array");
251  }
252 
253 }
254 
255 
256 
257 
262 
264 {
265  // Called by currently-processed KVFAZIASelector when a new file in the TChain is opened.
266  // We call gFazia->SetParameters for the current run.
267 
268  // Infos on currently read file/tree are printed.
269 
270  Info("preInitRun", "Appel");
271  gMultiDetArray->SetParameters(fRunNumber.run());
272 }
273 
274 
275 
276 
ROOT::R::TRInterface & r
#define f(i)
constexpr Bool_t kFALSE
Option_t Option_t option
TString GetFullPathToRunfile(const KVString &type, const run_index_t &run) const
Definition: KVDataSet.cpp:931
FileType * OpenRunfile(const KVString &type, const run_index_t &run)
Definition: KVDataSet.h:164
Pilot analysis of reconstructed FAZIA data.
void SubmitTask() override
Run the interactive analysis.
virtual void SetParameters(UInt_t n, Bool_t physics_parameters_only=kFALSE)
static KVMultiDetArray * MakeMultiDetector(const Char_t *dataset_name, Int_t run=-1, TString classname="KVMultiDetArray")
Handle list of options and input parameters for user analyis .
void ParseOptions(const KVString &optlist)
Bool_t IsOptGiven(const Char_t *opt)
virtual Bool_t IsOpen() const
void Close(Option_t *option="") override
const char * GetName() const override
R__ALWAYS_INLINE Bool_t IsZombie() const
const char * Data() const
BinData::ErrorType GetDataType(const TGraph *gr, DataOptions &fitOpt)
void Error(const char *location, const char *fmt,...)
void Info(const char *location, const char *fmt,...)
void Warning(const char *location, const char *fmt,...)
ClassImp(TPyArg)