1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
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. //
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. //
32 <img src="picts/AliRunClass.gif">
37 <img src="picts/alirun.gif">
41 ///////////////////////////////////////////////////////////////////////////////
47 #include <TVirtualMC.h>
48 #include <TGeoManager.h>
51 #include "AliDetector.h"
52 #include "AliHeader.h"
57 #include "AliCDBManager.h"
58 #include "AliAlignObj.h"
59 #include "AliSimulation.h"
66 //_______________________________________________________________________
76 fTriggerDescriptor(""),
80 // Default constructor for AliRun
82 AliConfig::Instance();//skowron 29 Feb 2002
83 //ensures that the folder structure is build
87 //_____________________________________________________________________________
88 AliRun::AliRun(const char *name, const char *title):
91 fModules(new TObjArray(77)), // Support list for the Detectors
92 fMCApp(new AliMC(GetName(),GetTitle())),
94 fConfigFunction("Config();"),
95 fRandom(new TRandom3()),
97 fTriggerDescriptor(""),
101 // Constructor for the main processor.
102 // Creates the geometry
103 // Creates the list of Detectors.
104 // Creates the list of particles.
109 // Set random number generator
112 if (gSystem->Getenv("CONFIG_SEED")) {
113 gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED"))));
116 // Add to list of browsable
117 gROOT->GetListOfBrowsables()->Add(this,name);
122 //_______________________________________________________________________
126 // Default AliRun destructor
128 gROOT->GetListOfBrowsables()->Remove(this);
132 TFolder* evfold = fRunLoader->GetEventFolder();
133 TFolder* modfold = dynamic_cast<TFolder*>(evfold->FindObjectAny(AliConfig::GetModulesFolderName()));
134 TIter next(fModules);
136 while((mod = (AliModule*)next()))
138 modfold->Remove(mod);
152 //_____________________________________________________________________________
154 void AliRun::InitLoaders()
156 //creates list of getters
158 TIter next(fModules);
160 while((mod = (AliModule*)next()))
162 mod->SetRunLoader(fRunLoader);
163 AliDetector *det = dynamic_cast<AliDetector*>(mod);
166 AliDebug(2, Form("Adding %s", det->GetName()));
167 fRunLoader->AddLoader(det);
173 //_______________________________________________________________________
174 void AliRun::Announce() const
177 // Announce the current version of AliRoot
180 "****************************************************************\n");
181 printf("%6s","*");printf("%64s","*\n");
184 printf(" You are running AliRoot version NewIO\n");
187 printf(" The SVN version for the current program is $Id$\n");
189 printf("%6s","*");printf("%64s","*\n");
191 "****************************************************************\n");
194 //_______________________________________________________________________
195 AliModule *AliRun::GetModule(const char *name) const
198 // Return pointer to detector from name
200 return dynamic_cast<AliModule*>(fModules->FindObject(name));
203 //_______________________________________________________________________
204 AliDetector *AliRun::GetDetector(const char *name) const
207 // Return pointer to detector from name
209 return dynamic_cast<AliDetector*>(fModules->FindObject(name));
212 //_______________________________________________________________________
213 Int_t AliRun::GetModuleID(const char *name) const
216 // Return galice internal detector identifier from name
219 TObject *mod=fModules->FindObject(name);
220 if(mod) i=fModules->IndexOf(mod);
224 //_______________________________________________________________________
225 Int_t AliRun::GetEvent(Int_t event)
228 // Reloads data containers in folders # event
229 // Set branch addresses
231 if (fRunLoader == 0x0)
233 AliError("RunLoader is not set. Can not load data.");
236 /*****************************************/
237 /**** P R E R E L O A D I N G ****/
238 /*****************************************/
239 // Reset existing structures
241 fMCApp->ResetTrackReferences();
242 fMCApp->ResetDigits();
243 fMCApp->ResetSDigits();
245 /*****************************************/
246 /**** R E L O A D ****/
247 /*****************************************/
249 AliRunLoader::Instance()->GetEvent(event);
251 /*****************************************/
252 /**** P O S T R E L O A D I N G ****/
253 /*****************************************/
255 // Set Trees branch addresses
256 TIter next(fModules);
257 AliDetector *detector;
258 while((detector = dynamic_cast<AliDetector*>(next())))
260 detector->SetTreeAddress();
263 return AliRunLoader::Instance()->GetHeader()->GetNtrack();
266 //_______________________________________________________________________
267 void AliRun::SetBaseFile(const char *filename)
269 fBaseFileName = filename;
273 //_______________________________________________________________________
274 void AliRun::Hits2Digits(const char *selected)
277 // Convert Hits to sumable digits
279 for (Int_t nevent=0; nevent<AliRunLoader::Instance()->TreeE()->GetEntries(); nevent++) {
281 Hits2SDigits(selected);
282 SDigits2Digits(selected);
287 //_______________________________________________________________________
289 void AliRun::Tree2Tree(Option_t *option, const char *selected)
292 // Function to transform the content of
294 // - TreeH to TreeS (option "S")
295 // - TreeS to TreeD (option "D")
296 // - TreeD to TreeR (option "R")
298 // If multiple options are specified ("SDR"), transformation will be done in sequence for
299 // selected detector and for all detectors if none is selected (detector string
300 // can contain blank separated list of detector names).
303 const char *oS = strstr(option,"S");
304 const char *oD = strstr(option,"D");
305 const char *oR = strstr(option,"R");
307 TObjArray *detectors = Detectors();
309 TIter next(detectors);
311 AliDetector *detector = 0;
313 while((detector = dynamic_cast<AliDetector*>(next()))) {
315 if (strcmp(detector->GetName(),selected)) continue;
316 if (detector->IsActive())
319 AliLoader* loader = detector->GetLoader();
320 if (loader == 0x0) continue;
324 AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName()));
325 loader->LoadHits("read");
326 if (loader->TreeS() == 0x0) loader->MakeTree("S");
327 detector->MakeBranch(option);
328 detector->SetTreeAddress();
329 detector->Hits2SDigits();
330 loader->UnloadHits();
331 loader->UnloadSDigits();
335 AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName()));
336 loader->LoadSDigits("read");
337 if (loader->TreeD() == 0x0) loader->MakeTree("D");
338 detector->MakeBranch(option);
339 detector->SetTreeAddress();
340 detector->SDigits2Digits();
341 loader->UnloadSDigits();
342 loader->UnloadDigits();
346 AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName()));
347 loader->LoadDigits("read");
348 if (loader->TreeR() == 0x0) loader->MakeTree("R");
349 detector->MakeBranch(option);
350 detector->SetTreeAddress();
351 detector->Digits2Reco();
352 loader->UnloadDigits();
353 loader->UnloadRecPoints();
361 //_______________________________________________________________________
362 void AliRun::Streamer(TBuffer &R__b)
364 // Stream an object of class AliRun.
366 if (R__b.IsReading()) {
367 if (!gAlice) gAlice = this;
368 AliRun::Class()->ReadBuffer(R__b, this);
369 gROOT->GetListOfBrowsables()->Add(this,"Run");
373 AliRun::Class()->WriteBuffer(R__b, this);
376 //_______________________________________________________________________
378 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
380 AliRunLoader::Instance()->GetHeader()->SetGenEventHeader(header);
384 //_______________________________________________________________________
386 Int_t AliRun::GetEvNumber() const
388 //Returns number of current event
389 if (fRunLoader == 0x0)
391 AliError("RunLoader is not set. Can not load data.");
395 return fRunLoader->GetEventNumber();
397 //_______________________________________________________________________
399 void AliRun::SetRunLoader(AliRunLoader* rloader)
402 // Set the loader of the run
404 fRunLoader = rloader;
405 if (fRunLoader == 0x0) return;
408 TFolder* evfold = fRunLoader->GetEventFolder();
409 if (evfold) evfoldname = evfold->GetName();
410 else AliWarning("Did not get Event Folder from Run Loader");
412 if ( fRunLoader->GetAliRun() )
413 {//if alrun already exists in folder
414 if (fRunLoader->GetAliRun() != this )
415 {//and is different than this - crash
416 AliFatal("AliRun is already in Folder and it is not this object");
422 evfold->Add(this);//Post this AliRun to Folder
425 TIter next(fModules);
427 while((module = (AliModule*)next()))
429 if (evfold) AliConfig::Instance()->Add(module,evfoldname);
430 module->SetRunLoader(fRunLoader);
431 AliDetector* detector = dynamic_cast<AliDetector*>(module);
434 AliLoader* loader = fRunLoader->GetLoader(detector);
437 AliError(Form("Can not get loader for detector %s", detector->GetName()));
441 AliDebug(1, Form("Setting loader for detector %s", detector->GetName()));
442 detector->SetLoader(loader);
448 void AliRun::AddModule(AliModule* mod)
451 // Add a module to the module list
453 if (mod == 0x0) return;
454 if (strlen(mod->GetName()) == 0) return;
455 if (GetModuleID(mod->GetName()) >= 0) return;
457 AliDebug(1, mod->GetName());
458 if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod);
459 else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName());