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):
96 fModules(new TObjArray(77)), // Support list for the Detectors
97 fMCApp(new AliMC(GetName(),GetTitle())),
99 fConfigFunction("Config();"),
100 fRandom(new TRandom3()),
102 fIsRootGeometry(kFALSE),
103 fGeometryFromCDB(kFALSE),
104 fGeometryFileName(""),
105 fTriggerDescriptor(""),
109 // Constructor for the main processor.
110 // Creates the geometry
111 // Creates the list of Detectors.
112 // Creates the list of particles.
117 // Set random number generator
120 if (gSystem->Getenv("CONFIG_SEED")) {
121 gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED"))));
124 // Add to list of browsable
125 gROOT->GetListOfBrowsables()->Add(this,name);
130 //_______________________________________________________________________
134 // Default AliRun destructor
136 gROOT->GetListOfBrowsables()->Remove(this);
140 TFolder* evfold = fRunLoader->GetEventFolder();
141 TFolder* modfold = dynamic_cast<TFolder*>(evfold->FindObjectAny(AliConfig::GetModulesFolderName()));
142 TIter next(fModules);
144 while((mod = (AliModule*)next()))
146 modfold->Remove(mod);
160 //_______________________________________________________________________
161 void AliRun::SetRootGeometry(Bool_t flag)
163 // Instruct application that the geometry is to be retreived from a root file.
164 fIsRootGeometry = flag;
165 if (flag && gMC) gMC->SetRootGeometry();
168 //_______________________________________________________________________
169 void AliRun::SetGeometryFromCDB()
171 // Set the loading of geometry from cdb instead of creating it
172 // A default CDB storage needs to be set before this method is called
173 if(AliCDBManager::Instance()->IsDefaultStorageSet() &&
174 AliCDBManager::Instance()->GetRun() >= 0){
176 fGeometryFromCDB = kTRUE;
178 AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
179 AliError("Loading of geometry from CDB ignored. First set a default CDB storage!");
180 AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
184 //_____________________________________________________________________________
186 void AliRun::InitLoaders()
188 //creates list of getters
190 TIter next(fModules);
192 while((mod = (AliModule*)next()))
194 mod->SetRunLoader(fRunLoader);
195 AliDetector *det = dynamic_cast<AliDetector*>(mod);
198 AliDebug(2, Form("Adding %s", det->GetName()));
199 fRunLoader->AddLoader(det);
205 //_______________________________________________________________________
206 void AliRun::Announce() const
209 // Announce the current version of AliRoot
212 "****************************************************************\n");
213 printf("%6s","*");printf("%64s","*\n");
216 printf(" You are running AliRoot version NewIO\n");
219 printf(" The SVN version for the current program is $Id$\n");
221 printf("%6s","*");printf("%64s","*\n");
223 "****************************************************************\n");
226 //_______________________________________________________________________
227 AliModule *AliRun::GetModule(const char *name) const
230 // Return pointer to detector from name
232 return dynamic_cast<AliModule*>(fModules->FindObject(name));
235 //_______________________________________________________________________
236 AliDetector *AliRun::GetDetector(const char *name) const
239 // Return pointer to detector from name
241 return dynamic_cast<AliDetector*>(fModules->FindObject(name));
244 //_______________________________________________________________________
245 Int_t AliRun::GetModuleID(const char *name) const
248 // Return galice internal detector identifier from name
251 TObject *mod=fModules->FindObject(name);
252 if(mod) i=fModules->IndexOf(mod);
256 //_______________________________________________________________________
257 Int_t AliRun::GetEvent(Int_t event)
260 // Reloads data containers in folders # event
261 // Set branch addresses
263 if (fRunLoader == 0x0)
265 AliError("RunLoader is not set. Can not load data.");
268 /*****************************************/
269 /**** P R E R E L O A D I N G ****/
270 /*****************************************/
271 // Reset existing structures
273 fMCApp->ResetTrackReferences();
274 fMCApp->ResetDigits();
275 fMCApp->ResetSDigits();
277 /*****************************************/
278 /**** R E L O A D ****/
279 /*****************************************/
281 AliRunLoader::Instance()->GetEvent(event);
283 /*****************************************/
284 /**** P O S T R E L O A D I N G ****/
285 /*****************************************/
287 // Set Trees branch addresses
288 TIter next(fModules);
289 AliDetector *detector;
290 while((detector = dynamic_cast<AliDetector*>(next())))
292 detector->SetTreeAddress();
295 return AliRunLoader::Instance()->GetHeader()->GetNtrack();
298 //_______________________________________________________________________
299 void AliRun::SetBaseFile(const char *filename)
301 fBaseFileName = filename;
305 //_______________________________________________________________________
306 void AliRun::Hits2Digits(const char *selected)
309 // Convert Hits to sumable digits
311 for (Int_t nevent=0; nevent<AliRunLoader::Instance()->TreeE()->GetEntries(); nevent++) {
313 Hits2SDigits(selected);
314 SDigits2Digits(selected);
319 //_______________________________________________________________________
321 void AliRun::Tree2Tree(Option_t *option, const char *selected)
324 // Function to transform the content of
326 // - TreeH to TreeS (option "S")
327 // - TreeS to TreeD (option "D")
328 // - TreeD to TreeR (option "R")
330 // If multiple options are specified ("SDR"), transformation will be done in sequence for
331 // selected detector and for all detectors if none is selected (detector string
332 // can contain blank separated list of detector names).
335 const char *oS = strstr(option,"S");
336 const char *oD = strstr(option,"D");
337 const char *oR = strstr(option,"R");
339 TObjArray *detectors = Detectors();
341 TIter next(detectors);
343 AliDetector *detector = 0;
345 while((detector = dynamic_cast<AliDetector*>(next()))) {
347 if (strcmp(detector->GetName(),selected)) continue;
348 if (detector->IsActive())
351 AliLoader* loader = detector->GetLoader();
352 if (loader == 0x0) continue;
356 AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName()));
357 loader->LoadHits("read");
358 if (loader->TreeS() == 0x0) loader->MakeTree("S");
359 detector->MakeBranch(option);
360 detector->SetTreeAddress();
361 detector->Hits2SDigits();
362 loader->UnloadHits();
363 loader->UnloadSDigits();
367 AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName()));
368 loader->LoadSDigits("read");
369 if (loader->TreeD() == 0x0) loader->MakeTree("D");
370 detector->MakeBranch(option);
371 detector->SetTreeAddress();
372 detector->SDigits2Digits();
373 loader->UnloadSDigits();
374 loader->UnloadDigits();
378 AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName()));
379 loader->LoadDigits("read");
380 if (loader->TreeR() == 0x0) loader->MakeTree("R");
381 detector->MakeBranch(option);
382 detector->SetTreeAddress();
383 detector->Digits2Reco();
384 loader->UnloadDigits();
385 loader->UnloadRecPoints();
393 //_______________________________________________________________________
394 void AliRun::Streamer(TBuffer &R__b)
396 // Stream an object of class AliRun.
398 if (R__b.IsReading()) {
399 if (!gAlice) gAlice = this;
400 AliRun::Class()->ReadBuffer(R__b, this);
401 gROOT->GetListOfBrowsables()->Add(this,"Run");
405 AliRun::Class()->WriteBuffer(R__b, this);
408 //_______________________________________________________________________
410 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
412 AliRunLoader::Instance()->GetHeader()->SetGenEventHeader(header);
416 //_______________________________________________________________________
418 Int_t AliRun::GetEvNumber() const
420 //Returns number of current event
421 if (fRunLoader == 0x0)
423 AliError("RunLoader is not set. Can not load data.");
427 return fRunLoader->GetEventNumber();
429 //_______________________________________________________________________
431 void AliRun::SetRunLoader(AliRunLoader* rloader)
434 // Set the loader of the run
436 fRunLoader = rloader;
437 if (fRunLoader == 0x0) return;
440 TFolder* evfold = fRunLoader->GetEventFolder();
441 if (evfold) evfoldname = evfold->GetName();
442 else AliWarning("Did not get Event Folder from Run Loader");
444 if ( fRunLoader->GetAliRun() )
445 {//if alrun already exists in folder
446 if (fRunLoader->GetAliRun() != this )
447 {//and is different than this - crash
448 AliFatal("AliRun is already in Folder and it is not this object");
454 evfold->Add(this);//Post this AliRun to Folder
457 TIter next(fModules);
459 while((module = (AliModule*)next()))
461 if (evfold) AliConfig::Instance()->Add(module,evfoldname);
462 module->SetRunLoader(fRunLoader);
463 AliDetector* detector = dynamic_cast<AliDetector*>(module);
466 AliLoader* loader = fRunLoader->GetLoader(detector);
469 AliError(Form("Can not get loader for detector %s", detector->GetName()));
473 AliDebug(1, Form("Setting loader for detector %s", detector->GetName()));
474 detector->SetLoader(loader);
480 void AliRun::AddModule(AliModule* mod)
483 // Add a module to the module list
485 if (mod == 0x0) return;
486 if (strlen(mod->GetName()) == 0) return;
487 if (GetModuleID(mod->GetName()) >= 0) return;
489 AliDebug(1, mod->GetName());
490 if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod);
491 else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName());