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 fIsRootGeometry(kFALSE),
77 fGeometryFromCDB(kFALSE),
78 fGeometryFileName(""),
79 fTriggerDescriptor(""),
83 // Default constructor for AliRun
85 AliConfig::Instance();//skowron 29 Feb 2002
86 //ensures that the folder structure is build
90 //_____________________________________________________________________________
91 AliRun::AliRun(const char *name, const char *title):
94 fModules(new TObjArray(77)), // Support list for the Detectors
95 fMCApp(new AliMC(GetName(),GetTitle())),
97 fConfigFunction("Config();"),
98 fRandom(new TRandom3()),
100 fIsRootGeometry(kFALSE),
101 fGeometryFromCDB(kFALSE),
102 fGeometryFileName(""),
103 fTriggerDescriptor(""),
107 // Constructor for the main processor.
108 // Creates the geometry
109 // Creates the list of Detectors.
110 // Creates the list of particles.
115 // Set random number generator
118 if (gSystem->Getenv("CONFIG_SEED")) {
119 gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED"))));
122 // Add to list of browsable
123 gROOT->GetListOfBrowsables()->Add(this,name);
128 //_______________________________________________________________________
132 // Default AliRun destructor
134 gROOT->GetListOfBrowsables()->Remove(this);
138 TFolder* evfold = fRunLoader->GetEventFolder();
139 TFolder* modfold = dynamic_cast<TFolder*>(evfold->FindObjectAny(AliConfig::GetModulesFolderName()));
140 TIter next(fModules);
142 while((mod = (AliModule*)next()))
144 modfold->Remove(mod);
158 //_______________________________________________________________________
159 void AliRun::SetRootGeometry(Bool_t flag)
161 // Instruct application that the geometry is to be retreived from a root file.
162 fIsRootGeometry = flag;
163 if (flag && gMC) gMC->SetRootGeometry();
166 //_______________________________________________________________________
167 void AliRun::SetGeometryFromCDB()
169 // Set the loading of geometry from cdb instead of creating it
170 // A default CDB storage needs to be set before this method is called
171 if(AliCDBManager::Instance()->IsDefaultStorageSet() &&
172 AliCDBManager::Instance()->GetRun() >= 0){
174 fGeometryFromCDB = kTRUE;
176 AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
177 AliError("Loading of geometry from CDB ignored. First set a default CDB storage!");
178 AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
182 //_____________________________________________________________________________
184 void AliRun::InitLoaders()
186 //creates list of getters
188 TIter next(fModules);
190 while((mod = (AliModule*)next()))
192 mod->SetRunLoader(fRunLoader);
193 AliDetector *det = dynamic_cast<AliDetector*>(mod);
196 AliDebug(2, Form("Adding %s", det->GetName()));
197 fRunLoader->AddLoader(det);
203 //_______________________________________________________________________
204 void AliRun::Announce() const
207 // Announce the current version of AliRoot
210 "****************************************************************\n");
211 printf("%6s","*");printf("%64s","*\n");
214 printf(" You are running AliRoot version NewIO\n");
217 printf(" The SVN version for the current program is $Id$\n");
219 printf("%6s","*");printf("%64s","*\n");
221 "****************************************************************\n");
224 //_______________________________________________________________________
225 AliModule *AliRun::GetModule(const char *name) const
228 // Return pointer to detector from name
230 return dynamic_cast<AliModule*>(fModules->FindObject(name));
233 //_______________________________________________________________________
234 AliDetector *AliRun::GetDetector(const char *name) const
237 // Return pointer to detector from name
239 return dynamic_cast<AliDetector*>(fModules->FindObject(name));
242 //_______________________________________________________________________
243 Int_t AliRun::GetModuleID(const char *name) const
246 // Return galice internal detector identifier from name
249 TObject *mod=fModules->FindObject(name);
250 if(mod) i=fModules->IndexOf(mod);
254 //_______________________________________________________________________
255 Int_t AliRun::GetEvent(Int_t event)
258 // Reloads data containers in folders # event
259 // Set branch addresses
261 if (fRunLoader == 0x0)
263 AliError("RunLoader is not set. Can not load data.");
266 /*****************************************/
267 /**** P R E R E L O A D I N G ****/
268 /*****************************************/
269 // Reset existing structures
271 fMCApp->ResetTrackReferences();
272 fMCApp->ResetDigits();
273 fMCApp->ResetSDigits();
275 /*****************************************/
276 /**** R E L O A D ****/
277 /*****************************************/
279 AliRunLoader::Instance()->GetEvent(event);
281 /*****************************************/
282 /**** P O S T R E L O A D I N G ****/
283 /*****************************************/
285 // Set Trees branch addresses
286 TIter next(fModules);
287 AliDetector *detector;
288 while((detector = dynamic_cast<AliDetector*>(next())))
290 detector->SetTreeAddress();
293 return AliRunLoader::Instance()->GetHeader()->GetNtrack();
296 //_______________________________________________________________________
297 void AliRun::SetBaseFile(const char *filename)
299 fBaseFileName = filename;
303 //_______________________________________________________________________
304 void AliRun::Hits2Digits(const char *selected)
307 // Convert Hits to sumable digits
309 for (Int_t nevent=0; nevent<AliRunLoader::Instance()->TreeE()->GetEntries(); nevent++) {
311 Hits2SDigits(selected);
312 SDigits2Digits(selected);
317 //_______________________________________________________________________
319 void AliRun::Tree2Tree(Option_t *option, const char *selected)
322 // Function to transform the content of
324 // - TreeH to TreeS (option "S")
325 // - TreeS to TreeD (option "D")
326 // - TreeD to TreeR (option "R")
328 // If multiple options are specified ("SDR"), transformation will be done in sequence for
329 // selected detector and for all detectors if none is selected (detector string
330 // can contain blank separated list of detector names).
333 const char *oS = strstr(option,"S");
334 const char *oD = strstr(option,"D");
335 const char *oR = strstr(option,"R");
337 TObjArray *detectors = Detectors();
339 TIter next(detectors);
341 AliDetector *detector = 0;
343 while((detector = dynamic_cast<AliDetector*>(next()))) {
345 if (strcmp(detector->GetName(),selected)) continue;
346 if (detector->IsActive())
349 AliLoader* loader = detector->GetLoader();
350 if (loader == 0x0) continue;
354 AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName()));
355 loader->LoadHits("read");
356 if (loader->TreeS() == 0x0) loader->MakeTree("S");
357 detector->MakeBranch(option);
358 detector->SetTreeAddress();
359 detector->Hits2SDigits();
360 loader->UnloadHits();
361 loader->UnloadSDigits();
365 AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName()));
366 loader->LoadSDigits("read");
367 if (loader->TreeD() == 0x0) loader->MakeTree("D");
368 detector->MakeBranch(option);
369 detector->SetTreeAddress();
370 detector->SDigits2Digits();
371 loader->UnloadSDigits();
372 loader->UnloadDigits();
376 AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName()));
377 loader->LoadDigits("read");
378 if (loader->TreeR() == 0x0) loader->MakeTree("R");
379 detector->MakeBranch(option);
380 detector->SetTreeAddress();
381 detector->Digits2Reco();
382 loader->UnloadDigits();
383 loader->UnloadRecPoints();
391 //_______________________________________________________________________
392 void AliRun::Streamer(TBuffer &R__b)
394 // Stream an object of class AliRun.
396 if (R__b.IsReading()) {
397 if (!gAlice) gAlice = this;
398 AliRun::Class()->ReadBuffer(R__b, this);
399 gROOT->GetListOfBrowsables()->Add(this,"Run");
403 AliRun::Class()->WriteBuffer(R__b, this);
406 //_______________________________________________________________________
408 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
410 AliRunLoader::Instance()->GetHeader()->SetGenEventHeader(header);
414 //_______________________________________________________________________
416 Int_t AliRun::GetEvNumber() const
418 //Returns number of current event
419 if (fRunLoader == 0x0)
421 AliError("RunLoader is not set. Can not load data.");
425 return fRunLoader->GetEventNumber();
427 //_______________________________________________________________________
429 void AliRun::SetRunLoader(AliRunLoader* rloader)
432 // Set the loader of the run
434 fRunLoader = rloader;
435 if (fRunLoader == 0x0) return;
438 TFolder* evfold = fRunLoader->GetEventFolder();
439 if (evfold) evfoldname = evfold->GetName();
440 else AliWarning("Did not get Event Folder from Run Loader");
442 if ( fRunLoader->GetAliRun() )
443 {//if alrun already exists in folder
444 if (fRunLoader->GetAliRun() != this )
445 {//and is different than this - crash
446 AliFatal("AliRun is already in Folder and it is not this object");
452 evfold->Add(this);//Post this AliRun to Folder
455 TIter next(fModules);
457 while((module = (AliModule*)next()))
459 if (evfold) AliConfig::Instance()->Add(module,evfoldname);
460 module->SetRunLoader(fRunLoader);
461 AliDetector* detector = dynamic_cast<AliDetector*>(module);
464 AliLoader* loader = fRunLoader->GetLoader(detector);
467 AliError(Form("Can not get loader for detector %s", detector->GetName()));
471 AliDebug(1, Form("Setting loader for detector %s", detector->GetName()));
472 detector->SetLoader(loader);
478 void AliRun::AddModule(AliModule* mod)
481 // Add a module to the module list
483 if (mod == 0x0) return;
484 if (strlen(mod->GetName()) == 0) return;
485 if (GetModuleID(mod->GetName()) >= 0) return;
487 AliDebug(1, mod->GetName());
488 if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod);
489 else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName());