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 //_______________________________________________________________________
77 fIsRootGeometry(kFALSE),
78 fGeometryFromCDB(kFALSE),
79 fGeometryFileName(""),
80 fTriggerDescriptor(""),
84 // Default constructor for AliRun
86 AliConfig::Instance();//skowron 29 Feb 2002
87 //ensures that the folder structure is build
91 //_____________________________________________________________________________
92 AliRun::AliRun(const char *name, const char *title):
97 fModules(new TObjArray(77)), // Support list for the Detectors
98 fMCApp(new AliMC(GetName(),GetTitle())),
100 fConfigFunction("Config();"),
101 fRandom(new TRandom3()),
103 fIsRootGeometry(kFALSE),
104 fGeometryFromCDB(kFALSE),
105 fGeometryFileName(""),
106 fTriggerDescriptor(""),
110 // Constructor for the main processor.
111 // Creates the geometry
112 // Creates the list of Detectors.
113 // Creates the list of particles.
118 // Set random number generator
121 if (gSystem->Getenv("CONFIG_SEED")) {
122 gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED"))));
125 // Add to list of browsable
126 gROOT->GetListOfBrowsables()->Add(this,name);
131 //_______________________________________________________________________
135 // Default AliRun destructor
137 gROOT->GetListOfBrowsables()->Remove(this);
141 TFolder* evfold = fRunLoader->GetEventFolder();
142 TFolder* modfold = dynamic_cast<TFolder*>(evfold->FindObjectAny(AliConfig::GetModulesFolderName()));
143 TIter next(fModules);
145 while((mod = (AliModule*)next()))
147 modfold->Remove(mod);
161 //_______________________________________________________________________
162 void AliRun::SetRootGeometry(Bool_t flag)
164 // Instruct application that the geometry is to be retreived from a root file.
165 fIsRootGeometry = flag;
166 if (flag && gMC) gMC->SetRootGeometry();
169 //_______________________________________________________________________
170 void AliRun::SetGeometryFromCDB()
172 // Set the loading of geometry from cdb instead of creating it
173 // A default CDB storage needs to be set before this method is called
174 if(AliCDBManager::Instance()->IsDefaultStorageSet() &&
175 AliCDBManager::Instance()->GetRun() >= 0){
177 fGeometryFromCDB = kTRUE;
179 AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
180 AliError("Loading of geometry from CDB ignored. First set a default CDB storage!");
181 AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
185 //_____________________________________________________________________________
187 void AliRun::InitLoaders()
189 //creates list of getters
191 TIter next(fModules);
193 while((mod = (AliModule*)next()))
195 mod->SetRunLoader(fRunLoader);
196 AliDetector *det = dynamic_cast<AliDetector*>(mod);
199 AliDebug(2, Form("Adding %s", det->GetName()));
200 fRunLoader->AddLoader(det);
206 //_______________________________________________________________________
207 void AliRun::Announce() const
210 // Announce the current version of AliRoot
213 "****************************************************************\n");
214 printf("%6s","*");printf("%64s","*\n");
217 printf(" You are running AliRoot version NewIO\n");
220 printf(" The SVN version for the current program is $Id$\n");
222 printf("%6s","*");printf("%64s","*\n");
224 "****************************************************************\n");
227 //_______________________________________________________________________
228 AliModule *AliRun::GetModule(const char *name) const
231 // Return pointer to detector from name
233 return dynamic_cast<AliModule*>(fModules->FindObject(name));
236 //_______________________________________________________________________
237 AliDetector *AliRun::GetDetector(const char *name) const
240 // Return pointer to detector from name
242 return dynamic_cast<AliDetector*>(fModules->FindObject(name));
245 //_______________________________________________________________________
246 Int_t AliRun::GetModuleID(const char *name) const
249 // Return galice internal detector identifier from name
252 TObject *mod=fModules->FindObject(name);
253 if(mod) i=fModules->IndexOf(mod);
257 //_______________________________________________________________________
258 Int_t AliRun::GetEvent(Int_t event)
261 // Reloads data containers in folders # event
262 // Set branch addresses
264 if (fRunLoader == 0x0)
266 AliError("RunLoader is not set. Can not load data.");
269 /*****************************************/
270 /**** P R E R E L O A D I N G ****/
271 /*****************************************/
272 // Reset existing structures
274 fMCApp->ResetTrackReferences();
275 fMCApp->ResetDigits();
276 fMCApp->ResetSDigits();
278 /*****************************************/
279 /**** R E L O A D ****/
280 /*****************************************/
282 AliRunLoader::GetRunLoader()->GetEvent(event);
284 /*****************************************/
285 /**** P O S T R E L O A D I N G ****/
286 /*****************************************/
288 // Set Trees branch addresses
289 TIter next(fModules);
290 AliDetector *detector;
291 while((detector = dynamic_cast<AliDetector*>(next())))
293 detector->SetTreeAddress();
296 return AliRunLoader::GetRunLoader()->GetHeader()->GetNtrack();
299 //_______________________________________________________________________
300 void AliRun::SetBaseFile(const char *filename)
302 fBaseFileName = filename;
306 //_______________________________________________________________________
307 void AliRun::Hits2Digits(const char *selected)
310 // Convert Hits to sumable digits
312 for (Int_t nevent=0; nevent<AliRunLoader::GetRunLoader()->TreeE()->GetEntries(); nevent++) {
314 Hits2SDigits(selected);
315 SDigits2Digits(selected);
320 //_______________________________________________________________________
322 void AliRun::Tree2Tree(Option_t *option, const char *selected)
325 // Function to transform the content of
327 // - TreeH to TreeS (option "S")
328 // - TreeS to TreeD (option "D")
329 // - TreeD to TreeR (option "R")
331 // If multiple options are specified ("SDR"), transformation will be done in sequence for
332 // selected detector and for all detectors if none is selected (detector string
333 // can contain blank separated list of detector names).
336 const char *oS = strstr(option,"S");
337 const char *oD = strstr(option,"D");
338 const char *oR = strstr(option,"R");
340 TObjArray *detectors = Detectors();
342 TIter next(detectors);
344 AliDetector *detector = 0;
346 while((detector = dynamic_cast<AliDetector*>(next()))) {
348 if (strcmp(detector->GetName(),selected)) continue;
349 if (detector->IsActive())
352 AliLoader* loader = detector->GetLoader();
353 if (loader == 0x0) continue;
357 AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName()));
358 loader->LoadHits("read");
359 if (loader->TreeS() == 0x0) loader->MakeTree("S");
360 detector->MakeBranch(option);
361 detector->SetTreeAddress();
362 detector->Hits2SDigits();
363 loader->UnloadHits();
364 loader->UnloadSDigits();
368 AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName()));
369 loader->LoadSDigits("read");
370 if (loader->TreeD() == 0x0) loader->MakeTree("D");
371 detector->MakeBranch(option);
372 detector->SetTreeAddress();
373 detector->SDigits2Digits();
374 loader->UnloadSDigits();
375 loader->UnloadDigits();
379 AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName()));
380 loader->LoadDigits("read");
381 if (loader->TreeR() == 0x0) loader->MakeTree("R");
382 detector->MakeBranch(option);
383 detector->SetTreeAddress();
384 detector->Digits2Reco();
385 loader->UnloadDigits();
386 loader->UnloadRecPoints();
394 //_______________________________________________________________________
395 void AliRun::Streamer(TBuffer &R__b)
397 // Stream an object of class AliRun.
399 if (R__b.IsReading()) {
400 if (!gAlice) gAlice = this;
401 AliRun::Class()->ReadBuffer(R__b, this);
402 gROOT->GetListOfBrowsables()->Add(this,"Run");
406 AliRun::Class()->WriteBuffer(R__b, this);
409 //_______________________________________________________________________
411 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
413 AliRunLoader::GetRunLoader()->GetHeader()->SetGenEventHeader(header);
417 //_______________________________________________________________________
419 Int_t AliRun::GetEvNumber() const
421 //Returns number of current event
422 if (fRunLoader == 0x0)
424 AliError("RunLoader is not set. Can not load data.");
428 return fRunLoader->GetEventNumber();
430 //_______________________________________________________________________
432 void AliRun::SetRunLoader(AliRunLoader* rloader)
435 // Set the loader of the run
437 fRunLoader = rloader;
438 if (fRunLoader == 0x0) return;
441 TFolder* evfold = fRunLoader->GetEventFolder();
442 if (evfold) evfoldname = evfold->GetName();
443 else AliWarning("Did not get Event Folder from Run Loader");
445 if ( fRunLoader->GetAliRun() )
446 {//if alrun already exists in folder
447 if (fRunLoader->GetAliRun() != this )
448 {//and is different than this - crash
449 AliFatal("AliRun is already in Folder and it is not this object");
455 evfold->Add(this);//Post this AliRun to Folder
458 TIter next(fModules);
460 while((module = (AliModule*)next()))
462 if (evfold) AliConfig::Instance()->Add(module,evfoldname);
463 module->SetRunLoader(fRunLoader);
464 AliDetector* detector = dynamic_cast<AliDetector*>(module);
467 AliLoader* loader = fRunLoader->GetLoader(detector);
470 AliError(Form("Can not get loader for detector %s", detector->GetName()));
474 AliDebug(1, Form("Setting loader for detector %s", detector->GetName()));
475 detector->SetLoader(loader);
481 void AliRun::AddModule(AliModule* mod)
484 // Add a module to the module list
486 if (mod == 0x0) return;
487 if (strlen(mod->GetName()) == 0) return;
488 if (GetModuleID(mod->GetName()) >= 0) return;
490 AliDebug(1, mod->GetName());
491 if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod);
492 else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName());