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"
55 #include "AliMagFCM.h"
56 #include "AliMagFDM.h"
60 #include "AliCDBManager.h"
61 #include "AliAlignObj.h"
62 #include "AliSimulation.h"
69 //_______________________________________________________________________
81 fIsRootGeometry(kFALSE),
82 fGeometryFromCDB(kFALSE),
83 fGeometryFileName(""),
84 fTriggerDescriptor(""),
88 // Default constructor for AliRun
90 AliConfig::Instance();//skowron 29 Feb 2002
91 //ensures that the folder structure is build
95 //_____________________________________________________________________________
96 AliRun::AliRun(const char *name, const char *title):
101 fModules(new TObjArray(77)), // Support list for the Detectors
102 fMCApp(new AliMC(GetName(),GetTitle())),
105 fConfigFunction("Config();"),
106 fRandom(new TRandom3()),
108 fIsRootGeometry(kFALSE),
109 fGeometryFromCDB(kFALSE),
110 fGeometryFileName(""),
111 fTriggerDescriptor(""),
115 // Constructor for the main processor.
116 // Creates the geometry
117 // Creates the list of Detectors.
118 // Creates the list of particles.
123 // Set random number generator
126 if (gSystem->Getenv("CONFIG_SEED")) {
127 gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED"))));
130 // Add to list of browsable
131 gROOT->GetListOfBrowsables()->Add(this,name);
133 // Create default mag field
134 fField = new AliMagFC("Map1"," ",2.,1.,10.);
139 //_______________________________________________________________________
143 // Default AliRun destructor
145 gROOT->GetListOfBrowsables()->Remove(this);
149 TFolder* evfold = fRunLoader->GetEventFolder();
150 TFolder* modfold = dynamic_cast<TFolder*>(evfold->FindObjectAny(AliConfig::GetModulesFolderName()));
151 TIter next(fModules);
153 while((mod = (AliModule*)next()))
155 modfold->Remove(mod);
169 //_______________________________________________________________________
170 void AliRun::SetField(AliMagF* magField)
173 // Set Magnetic Field Map
179 //_______________________________________________________________________
180 void AliRun::SetRootGeometry(Bool_t flag)
182 // Instruct application that the geometry is to be retreived from a root file.
183 fIsRootGeometry = flag;
184 if (flag && gMC) gMC->SetRootGeometry();
187 //_______________________________________________________________________
188 void AliRun::SetGeometryFromCDB()
190 // Set the loading of geometry from cdb instead of creating it
191 // A default CDB storage needs to be set before this method is called
192 if(AliCDBManager::Instance()->IsDefaultStorageSet() &&
193 AliCDBManager::Instance()->GetRun() >= 0){
195 fGeometryFromCDB = kTRUE;
197 AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
198 AliError("Loading of geometry from CDB ignored. First set a default CDB storage!");
199 AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
203 //_____________________________________________________________________________
205 void AliRun::InitLoaders()
207 //creates list of getters
209 TIter next(fModules);
211 while((mod = (AliModule*)next()))
213 mod->SetRunLoader(fRunLoader);
214 AliDetector *det = dynamic_cast<AliDetector*>(mod);
217 AliDebug(2, Form("Adding %s", det->GetName()));
218 fRunLoader->AddLoader(det);
224 //_______________________________________________________________________
225 void AliRun::Announce() const
228 // Announce the current version of AliRoot
231 "****************************************************************\n");
232 printf("%6s","*");printf("%64s","*\n");
235 printf(" You are running AliRoot version NewIO\n");
238 printf(" The SVN version for the current program is $Id$\n");
240 printf("%6s","*");printf("%64s","*\n");
242 "****************************************************************\n");
245 //_______________________________________________________________________
246 AliModule *AliRun::GetModule(const char *name) const
249 // Return pointer to detector from name
251 return dynamic_cast<AliModule*>(fModules->FindObject(name));
254 //_______________________________________________________________________
255 AliDetector *AliRun::GetDetector(const char *name) const
258 // Return pointer to detector from name
260 return dynamic_cast<AliDetector*>(fModules->FindObject(name));
263 //_______________________________________________________________________
264 Int_t AliRun::GetModuleID(const char *name) const
267 // Return galice internal detector identifier from name
270 TObject *mod=fModules->FindObject(name);
271 if(mod) i=fModules->IndexOf(mod);
275 //_______________________________________________________________________
276 Int_t AliRun::GetEvent(Int_t event)
279 // Reloads data containers in folders # event
280 // Set branch addresses
282 if (fRunLoader == 0x0)
284 AliError("RunLoader is not set. Can not load data.");
287 /*****************************************/
288 /**** P R E R E L O A D I N G ****/
289 /*****************************************/
290 // Reset existing structures
292 fMCApp->ResetTrackReferences();
293 fMCApp->ResetDigits();
294 fMCApp->ResetSDigits();
296 /*****************************************/
297 /**** R E L O A D ****/
298 /*****************************************/
300 AliRunLoader::GetRunLoader()->GetEvent(event);
302 /*****************************************/
303 /**** P O S T R E L O A D I N G ****/
304 /*****************************************/
306 // Set Trees branch addresses
307 TIter next(fModules);
308 AliDetector *detector;
309 while((detector = dynamic_cast<AliDetector*>(next())))
311 detector->SetTreeAddress();
314 return AliRunLoader::GetRunLoader()->GetHeader()->GetNtrack();
317 //_______________________________________________________________________
318 void AliRun::SetBaseFile(const char *filename)
320 fBaseFileName = filename;
324 //_______________________________________________________________________
325 void AliRun::Hits2Digits(const char *selected)
328 // Convert Hits to sumable digits
330 for (Int_t nevent=0; nevent<AliRunLoader::GetRunLoader()->TreeE()->GetEntries(); nevent++) {
332 Hits2SDigits(selected);
333 SDigits2Digits(selected);
338 //_______________________________________________________________________
340 void AliRun::Tree2Tree(Option_t *option, const char *selected)
343 // Function to transform the content of
345 // - TreeH to TreeS (option "S")
346 // - TreeS to TreeD (option "D")
347 // - TreeD to TreeR (option "R")
349 // If multiple options are specified ("SDR"), transformation will be done in sequence for
350 // selected detector and for all detectors if none is selected (detector string
351 // can contain blank separated list of detector names).
354 const char *oS = strstr(option,"S");
355 const char *oD = strstr(option,"D");
356 const char *oR = strstr(option,"R");
358 TObjArray *detectors = Detectors();
360 TIter next(detectors);
362 AliDetector *detector = 0;
364 while((detector = dynamic_cast<AliDetector*>(next()))) {
366 if (strcmp(detector->GetName(),selected)) continue;
367 if (detector->IsActive())
370 AliLoader* loader = detector->GetLoader();
371 if (loader == 0x0) continue;
375 AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName()));
376 loader->LoadHits("read");
377 if (loader->TreeS() == 0x0) loader->MakeTree("S");
378 detector->MakeBranch(option);
379 detector->SetTreeAddress();
380 detector->Hits2SDigits();
381 loader->UnloadHits();
382 loader->UnloadSDigits();
386 AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName()));
387 loader->LoadSDigits("read");
388 if (loader->TreeD() == 0x0) loader->MakeTree("D");
389 detector->MakeBranch(option);
390 detector->SetTreeAddress();
391 detector->SDigits2Digits();
392 loader->UnloadSDigits();
393 loader->UnloadDigits();
397 AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName()));
398 loader->LoadDigits("read");
399 if (loader->TreeR() == 0x0) loader->MakeTree("R");
400 detector->MakeBranch(option);
401 detector->SetTreeAddress();
402 detector->Digits2Reco();
403 loader->UnloadDigits();
404 loader->UnloadRecPoints();
415 //_______________________________________________________________________
416 void AliRun::Field(const Double_t* x, Double_t *b) const
419 // Return the value of the magnetic field
422 if (Field()) Field()->Field(x,b);
425 AliError("No mag field defined!");
433 // End of MC Application
436 //_______________________________________________________________________
437 void AliRun::Streamer(TBuffer &R__b)
439 // Stream an object of class AliRun.
441 if (R__b.IsReading()) {
442 if (!gAlice) gAlice = this;
443 AliRun::Class()->ReadBuffer(R__b, this);
444 gROOT->GetListOfBrowsables()->Add(this,"Run");
448 AliRun::Class()->WriteBuffer(R__b, this);
451 //_______________________________________________________________________
453 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
455 AliRunLoader::GetRunLoader()->GetHeader()->SetGenEventHeader(header);
459 //_______________________________________________________________________
461 Int_t AliRun::GetEvNumber() const
463 //Returns number of current event
464 if (fRunLoader == 0x0)
466 AliError("RunLoader is not set. Can not load data.");
470 return fRunLoader->GetEventNumber();
472 //_______________________________________________________________________
474 void AliRun::SetRunLoader(AliRunLoader* rloader)
477 // Set the loader of the run
479 fRunLoader = rloader;
480 if (fRunLoader == 0x0) return;
483 TFolder* evfold = fRunLoader->GetEventFolder();
484 if (evfold) evfoldname = evfold->GetName();
485 else AliWarning("Did not get Event Folder from Run Loader");
487 if ( fRunLoader->GetAliRun() )
488 {//if alrun already exists in folder
489 if (fRunLoader->GetAliRun() != this )
490 {//and is different than this - crash
491 AliFatal("AliRun is already in Folder and it is not this object");
497 evfold->Add(this);//Post this AliRun to Folder
500 TIter next(fModules);
502 while((module = (AliModule*)next()))
504 if (evfold) AliConfig::Instance()->Add(module,evfoldname);
505 module->SetRunLoader(fRunLoader);
506 AliDetector* detector = dynamic_cast<AliDetector*>(module);
509 AliLoader* loader = fRunLoader->GetLoader(detector);
512 AliError(Form("Can not get loader for detector %s", detector->GetName()));
516 AliDebug(1, Form("Setting loader for detector %s", detector->GetName()));
517 detector->SetLoader(loader);
523 void AliRun::AddModule(AliModule* mod)
526 // Add a module to the module list
528 if (mod == 0x0) return;
529 if (strlen(mod->GetName()) == 0) return;
530 if (GetModuleID(mod->GetName()) >= 0) return;
532 AliDebug(1, mod->GetName());
533 if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod);
534 else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName());