AliRoot Core  3dc7879 (3dc7879)
AliRun.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 
16 /* $Id$ */
17 
19 // //
20 // Control class for Alice C++ //
21 // Only one single instance of this class exists. //
22 // The object is created in main program aliroot //
23 // and is pointed by the global gAlice. //
24 // //
25 // -Supports the list of all Alice Detectors (fModules). //
26 // -Supports the list of particles (fParticles). //
27 // -Supports the Trees. //
28 // -Supports the geometry. //
29 // -Supports the event display. //
30 //Begin_Html
31 /*
32 <img src="picts/AliRunClass.gif">
33 */
34 //End_Html
35 //Begin_Html
36 /*
37 <img src="picts/alirun.gif">
38 */
39 //End_Html
40 // //
42 
43 #include <TROOT.h>
44 #include <TRandom3.h>
45 #include <TSystem.h>
46 #include <TVirtualMC.h>
47 #include <TGeoManager.h>
48 #include <TTree.h>
49 //
50 #include "AliLog.h"
51 #include "AliDetector.h"
52 #include "AliHeader.h"
53 #include "AliMC.h"
54 #include "AliPDG.h"
55 #include "AliRun.h"
56 #include "AliStack.h"
57 #include "AliCDBManager.h"
58 #include "AliAlignObj.h"
59 #include "AliSimulation.h"
60 #include "AliLego.h"
61 
63 
64 ClassImp(AliRun)
65 
66 //_______________________________________________________________________
68 // fRun(-1),
69  fEventNrInRun(-1),
70  fSgPerBgEmbedded(0),
71  fModules(0),
72  fMCApp(0),
73  fNdets(0),
74  fConfigFunction(""),
75  fBaseFileName(""),
76  fRunLoader(0x0)
77 {
78  //
79  // Default constructor for AliRun
80  //
81  AliConfig::Instance();//skowron 29 Feb 2002
82  //ensures that the folder structure is build
83 
84 }
85 
86 //_____________________________________________________________________________
87 AliRun::AliRun(const char *name, const char *title):
88  TNamed(name,title),
89  fEventNrInRun(-1),
90  fSgPerBgEmbedded(0),
91  fModules(new TObjArray(77)), // Support list for the Detectors
92  fMCApp(new AliMC(GetName(),GetTitle())),
93  fNdets(0),
94  fConfigFunction("Config();"),
95  fBaseFileName(""),
96  fRunLoader(0x0)
97 {
98  //
99  // Constructor for the main processor.
100  // Creates the geometry
101  // Creates the list of Detectors.
102  // Creates the list of particles.
103  //
104 
105  gAlice = this;
106 
107  // Set random number generator
108  gRandom = new TRandom3();
109 
110  if (gSystem->Getenv("CONFIG_SEED")) {
111  gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED"))));
112  }
113 
114  // Add to list of browsable
115  gROOT->GetListOfBrowsables()->Add(this,name);
116 
117 }
118 
119 //_______________________________________________________________________
121 {
122  //
123  // Default AliRun destructor
124  //
125  gROOT->GetListOfBrowsables()->Remove(this);
126 
127  if (fRunLoader)
128  {
129  TFolder* evfold = fRunLoader->GetEventFolder();
130  TFolder* modfold = dynamic_cast<TFolder*>(evfold->FindObjectAny(AliConfig::GetModulesFolderName()));
131  if(!modfold) AliFatal(Form("Folder %s not found\n",AliConfig::GetModulesFolderName().Data()));
132  TIter next(fModules);
133  AliModule *mod;
134  while((mod = (AliModule*)next()))
135  {
136  modfold->Remove(mod);
137  }
138  }
139 
140  delete fMCApp;
141  delete TVirtualMC::GetMC(); //gMC=0;
142  if (fModules) {
143  fModules->Delete();
144  delete fModules;
145  }
146 
147 }
148 
149 //_____________________________________________________________________________
151 {
152  //creates list of getters
153  AliDebug(1, "");
154  TIter next(fModules);
155  AliModule *mod;
156  while((mod = (AliModule*)next()))
157  {
158  mod->SetRunLoader(fRunLoader);
159  AliDetector *det = dynamic_cast<AliDetector*>(mod);
160  if (det)
161  {
162  AliDebug(2, Form("Adding %s", det->GetName()));
163  fRunLoader->AddLoader(det);
164  }
165  }
166  AliDebug(1, "Done");
167 }
168 
169 //_______________________________________________________________________
170 void AliRun::Announce() const
171 {
172  //
173  // Announce the current version of AliRoot
174  //
175  printf("%70s",
176  "****************************************************************\n");
177  printf("%6s","*");printf("%64s","*\n");
178 
179  printf("%6s","*");
180  printf(" You are running AliRoot version NewIO\n");
181 
182  printf("%6s","*");
183  printf(" The SVN version for the current program is $Id$\n");
184 
185  printf("%6s","*");printf("%64s","*\n");
186  printf("%70s",
187  "****************************************************************\n");
188 }
189 
190 //_______________________________________________________________________
191 AliModule *AliRun::GetModule(const char *name) const
192 {
193  //
194  // Return pointer to detector from name
195  //
196  return dynamic_cast<AliModule*>(fModules->FindObject(name));
197 }
198 
199 //_______________________________________________________________________
200 AliDetector *AliRun::GetDetector(const char *name) const
201 {
202  //
203  // Return pointer to detector from name
204  //
205  return dynamic_cast<AliDetector*>(fModules->FindObject(name));
206 }
207 
208 //_______________________________________________________________________
209 Int_t AliRun::GetModuleID(const char *name) const
210 {
211  //
212  // Return galice internal detector identifier from name
213  //
214  Int_t i=-1;
215  TObject *mod=fModules->FindObject(name);
216  if(mod) i=fModules->IndexOf(mod);
217  return i;
218 }
219 
220 //_______________________________________________________________________
221 Int_t AliRun::GetEvent(Int_t event)
222 {
223 //
224 // Reloads data containers in folders # event
225 // Set branch addresses
226 //
227  if (fRunLoader == 0x0)
228  {
229  AliError("RunLoader is not set. Can not load data.");
230  return -1;
231  }
232 /*****************************************/
233 /**** P R E R E L O A D I N G ****/
234 /*****************************************/
235 // Reset existing structures
236  fMCApp->ResetHits();
238  fMCApp->ResetDigits();
239  fMCApp->ResetSDigits();
240 
241 /*****************************************/
242 /**** R E L O A D ****/
243 /*****************************************/
244 
246 
247 /*****************************************/
248 /**** P O S T R E L O A D I N G ****/
249 /*****************************************/
250 
251  // Set Trees branch addresses
252  TIter next(fModules);
253  AliDetector *detector;
254  while((detector = dynamic_cast<AliDetector*>(next())))
255  {
256  detector->SetTreeAddress();
257  }
258 
260 }
261 
262 //_______________________________________________________________________
263 void AliRun::SetBaseFile(const char *filename)
264 {
265  fBaseFileName = filename;
266 }
267 
268 
269 //_______________________________________________________________________
270 void AliRun::Hits2Digits(const char *selected)
271 {
272 
273  // Convert Hits to sumable digits
274  //
275  for (Int_t nevent=0; nevent<AliRunLoader::Instance()->TreeE()->GetEntries(); nevent++) {
276  GetEvent(nevent);
277  Hits2SDigits(selected);
278  SDigits2Digits(selected);
279  }
280 }
281 
282 
283 //_______________________________________________________________________
284 void AliRun::Tree2Tree(Option_t *option, const char *selected)
285 {
286  //
287  // Function to transform the content of
288  //
289  // - TreeH to TreeS (option "S")
290  // - TreeS to TreeD (option "D")
291  // - TreeD to TreeR (option "R")
292  //
293  // If multiple options are specified ("SDR"), transformation will be done in sequence for
294  // selected detector and for all detectors if none is selected (detector string
295  // can contain blank separated list of detector names).
296 
297 
298  const char *oS = strstr(option,"S");
299  const char *oD = strstr(option,"D");
300  const char *oR = strstr(option,"R");
301 
302  TObjArray *detectors = Detectors();
303 
304  TIter next(detectors);
305 
306  AliDetector *detector = 0;
307 
308  while((detector = dynamic_cast<AliDetector*>(next()))) {
309  if (selected)
310  if (strcmp(detector->GetName(),selected)) continue;
311  if (detector->IsActive())
312  {
313 
314  AliLoader* loader = detector->GetLoader();
315  if (loader == 0x0) continue;
316 
317  if (oS)
318  {
319  AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName()));
320  loader->LoadHits("read");
321  if (loader->TreeS() == 0x0) loader->MakeTree("S");
322  detector->MakeBranch(option);
323  detector->SetTreeAddress();
324  detector->Hits2SDigits();
325  loader->UnloadHits();
326  loader->UnloadSDigits();
327  }
328  if (oD)
329  {
330  AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName()));
331  loader->LoadSDigits("read");
332  if (loader->TreeD() == 0x0) loader->MakeTree("D");
333  detector->MakeBranch(option);
334  detector->SetTreeAddress();
335  detector->SDigits2Digits();
336  loader->UnloadSDigits();
337  loader->UnloadDigits();
338  }
339  if (oR)
340  {
341  AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName()));
342  loader->LoadDigits("read");
343  if (loader->TreeR() == 0x0) loader->MakeTree("R");
344  detector->MakeBranch(option);
345  detector->SetTreeAddress();
346  detector->Digits2Reco();
347  loader->UnloadDigits();
348  loader->UnloadRecPoints();
349 
350  }
351  }
352  }
353 }
354 
355 
356 //_______________________________________________________________________
357 void AliRun::Streamer(TBuffer &R__b)
358 {
359  // Stream an object of class AliRun.
360 
361  if (R__b.IsReading()) {
362  if (!gAlice) gAlice = this;
363  AliRun::Class()->ReadBuffer(R__b, this);
364  gROOT->GetListOfBrowsables()->Add(this,"Run");
365  gRandom = new TRandom3();
366  } else {
367  AliRun::Class()->WriteBuffer(R__b, this);
368  }
369 }
370 
371 //_______________________________________________________________________
373 {
375 }
376 
377 
378 //_______________________________________________________________________
379 Int_t AliRun::GetEvNumber() const
380 {
381 //Returns number of current event
382  if (fRunLoader == 0x0)
383  {
384  AliError("RunLoader is not set. Can not load data.");
385  return -1;
386  }
387 
388  return fRunLoader->GetEventNumber();
389 }
390 
391 //_______________________________________________________________________
393 {
394  //
395  // Set the loader of the run
396  //
397  fRunLoader = rloader;
398  if (fRunLoader == 0x0) return;
399 
400  TString evfoldname;
401  TFolder* evfold = fRunLoader->GetEventFolder();
402  if (evfold) evfoldname = evfold->GetName();
403  else AliFatal("Did not get Event Folder from Run Loader");
404 
405  if ( fRunLoader->GetAliRun() )
406  {//if alrun already exists in folder
407  if (fRunLoader->GetAliRun() != this )
408  {//and is different than this - crash
409  AliFatal("AliRun is already in Folder and it is not this object");
410  return;//pro forma
411  }//else do nothing
412  }
413  else
414  {
415  evfold->Add(this);//Post this AliRun to Folder
416  }
417 
418  TIter next(fModules);
419  AliModule *module;
420  while((module = (AliModule*)next()))
421  {
422  if (evfold) AliConfig::Instance()->Add(module,evfoldname);
423  module->SetRunLoader(fRunLoader);
424  AliDetector* detector = dynamic_cast<AliDetector*>(module);
425  if (detector)
426  {
427  AliLoader* loader = fRunLoader->GetLoader(detector);
428  if (loader == 0x0)
429  {
430  AliError(Form("Can not get loader for detector %s", detector->GetName()));
431  }
432  else
433  {
434  AliDebug(1, Form("Setting loader for detector %s", detector->GetName()));
435  detector->SetLoader(loader);
436  }
437  }
438  }
439 }
440 
441 //_______________________________________________________________________
443 {
444  //
445  // Add a module to the module list
446  //
447  if (mod == 0x0) return;
448  if (strlen(mod->GetName()) == 0) return;
449  if (GetModuleID(mod->GetName()) >= 0) return;
450 
451  AliDebug(1, mod->GetName());
452  if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod);
453  else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName());
454 
455  Modules()->Add(mod);
456 
457  fNdets++;
458 }
459 
static AliRunLoader * Instance()
Definition: AliRunLoader.h:176
Int_t GetEventNumber() const
Definition: AliRunLoader.h:59
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
void SetRunLoader(AliRunLoader *rloader)
Definition: AliRun.cxx:392
virtual void SDigits2Digits(const char *detector=0)
Definition: AliRun.h:56
void UnloadRecPoints() const
Definition: AliLoader.h:132
void AddLoader(AliLoader *loader)
virtual void SetTreeAddress()
void SetLoader(AliLoader *loader)
Definition: AliDetector.h:66
Definition: AliRun.h:27
virtual void MakeTree(Option_t *opt)
Definition: AliLoader.cxx:346
#define TObjArray
virtual void ResetTrackReferences()
Definition: AliMC.cxx:2015
TString fBaseFileName
Definition: AliRun.h:79
virtual Int_t GetNtrack() const
Definition: AliHeader.h:45
virtual void Digits2Reco()
Definition: AliModule.h:97
virtual Int_t GetEvent(Int_t event)
Definition: AliRun.cxx:221
static const TString & GetModulesFolderName()
Definition: AliConfig.h:57
virtual void InitLoaders()
Definition: AliRun.cxx:150
TROOT * gROOT
TTree * TreeD() const
Definition: AliLoader.h:87
virtual void Announce() const
Definition: AliRun.cxx:170
Int_t fNdets
Definition: AliRun.h:77
AliLoader * GetLoader(const char *detname) const
virtual void SetBaseFile(const char *filename="galice.root")
Definition: AliRun.cxx:263
TTree * TreeS() const
Definition: AliLoader.h:85
virtual void ResetDigits()
Definition: AliMC.cxx:1445
Int_t GetEvNumber() const
Definition: AliRun.cxx:379
AliRun()
Definition: AliRun.cxx:67
virtual void Hits2Digits(const char *detector=0)
Definition: AliRun.cxx:270
TTree * TreeR() const
Definition: AliLoader.h:89
void Add(TDatabasePDG *pdg)
Definition: AliConfig.cxx:180
Int_t LoadSDigits(Option_t *opt="")
Definition: AliLoader.h:101
virtual void MakeBranch(Option_t *opt=" ")
void UnloadDigits() const
Definition: AliLoader.h:131
virtual void Hits2SDigits(const char *detector=0)
Definition: AliRun.h:55
AliModule * GetModule(const char *name) const
Definition: AliRun.cxx:191
AliHeader * GetHeader() const
virtual ~AliRun()
Definition: AliRun.cxx:120
void SetRunLoader(AliRunLoader *runLoader)
Definition: AliModule.h:140
AliMC * fMCApp
Definition: AliRun.h:76
AliRun * gAlice
Definition: AliRun.cxx:62
virtual void Hits2SDigits()
Definition: AliModule.h:90
#define AliFatal(message)
Definition: AliLog.h:640
TTree * TreeE() const
Int_t LoadHits(Option_t *opt="")
Definition: AliLoader.h:96
TObjArray * fModules
Definition: AliRun.h:75
Definition: AliMC.h:30
Int_t GetEvent(Int_t evno)
TFolder * GetEventFolder() const
Definition: AliRunLoader.h:147
virtual void ResetSDigits()
Definition: AliMC.cxx:1458
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
void UnloadHits() const
Definition: AliLoader.h:129
Int_t GetModuleID(const char *name) const
Definition: AliRun.cxx:209
AliLoader * GetLoader() const
Definition: AliDetector.h:67
AliRunLoader * fRunLoader
Definition: AliRun.h:80
void UnloadSDigits() const
Definition: AliLoader.h:130
AliDetector * GetDetector(const char *name) const
Definition: AliRun.cxx:200
virtual void SDigits2Digits()
Definition: AliModule.h:95
#define AliError(message)
Definition: AliLog.h:591
virtual void ResetHits()
Definition: AliMC.cxx:1432
Int_t LoadDigits(Option_t *opt="")
Definition: AliLoader.h:106
virtual Bool_t IsActive() const
Definition: AliModule.h:53
void AddModule(AliModule *mod)
Definition: AliRun.cxx:442
virtual void SetGenEventHeader(AliGenEventHeader *header)
Definition: AliRun.cxx:372
virtual void SetGenEventHeader(AliGenEventHeader *header)
Definition: AliHeader.cxx:194
static AliConfig * Instance()
Definition: AliConfig.cxx:87
TObjArray * Modules() const
Definition: AliRun.h:36
AliRun * GetAliRun() const
virtual void Tree2Tree(Option_t *option, const char *detector=0)
Definition: AliRun.cxx:284
TObjArray * Detectors() const
Definition: AliRun.h:35