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 ///////////////////////////////////////////////////////////////////////////////
46 #include <TVirtualMC.h>
47 #include <TGeoManager.h>
51 #include "AliDetector.h"
52 #include "AliHeader.h"
57 #include "AliCDBManager.h"
58 #include "AliAlignObj.h"
59 #include "AliSimulation.h"
66 //_______________________________________________________________________
78 // Default constructor for AliRun
80 AliConfig::Instance();//skowron 29 Feb 2002
81 //ensures that the folder structure is build
85 //_____________________________________________________________________________
86 AliRun::AliRun(const char *name, const char *title):
89 fModules(new TObjArray(77)), // Support list for the Detectors
90 fMCApp(new AliMC(GetName(),GetTitle())),
92 fConfigFunction("Config();"),
97 // Constructor for the main processor.
98 // Creates the geometry
99 // Creates the list of Detectors.
100 // Creates the list of particles.
105 // Set random number generator
106 gRandom = new TRandom3();
108 if (gSystem->Getenv("CONFIG_SEED")) {
109 gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED"))));
112 // Add to list of browsable
113 gROOT->GetListOfBrowsables()->Add(this,name);
117 //_______________________________________________________________________
121 // Default AliRun destructor
123 gROOT->GetListOfBrowsables()->Remove(this);
127 TFolder* evfold = fRunLoader->GetEventFolder();
128 TFolder* modfold = dynamic_cast<TFolder*>(evfold->FindObjectAny(AliConfig::GetModulesFolderName()));
129 if(!modfold) AliFatal(Form("Folder %s not found\n",AliConfig::GetModulesFolderName().Data()));
130 TIter next(fModules);
132 while((mod = (AliModule*)next()))
134 modfold->Remove(mod);
139 delete TVirtualMC::GetMC(); //gMC=0;
147 //_____________________________________________________________________________
148 void AliRun::InitLoaders()
150 //creates list of getters
152 TIter next(fModules);
154 while((mod = (AliModule*)next()))
156 mod->SetRunLoader(fRunLoader);
157 AliDetector *det = dynamic_cast<AliDetector*>(mod);
160 AliDebug(2, Form("Adding %s", det->GetName()));
161 fRunLoader->AddLoader(det);
167 //_______________________________________________________________________
168 void AliRun::Announce() const
171 // Announce the current version of AliRoot
174 "****************************************************************\n");
175 printf("%6s","*");printf("%64s","*\n");
178 printf(" You are running AliRoot version NewIO\n");
181 printf(" The SVN version for the current program is $Id$\n");
183 printf("%6s","*");printf("%64s","*\n");
185 "****************************************************************\n");
188 //_______________________________________________________________________
189 AliModule *AliRun::GetModule(const char *name) const
192 // Return pointer to detector from name
194 return dynamic_cast<AliModule*>(fModules->FindObject(name));
197 //_______________________________________________________________________
198 AliDetector *AliRun::GetDetector(const char *name) const
201 // Return pointer to detector from name
203 return dynamic_cast<AliDetector*>(fModules->FindObject(name));
206 //_______________________________________________________________________
207 Int_t AliRun::GetModuleID(const char *name) const
210 // Return galice internal detector identifier from name
213 TObject *mod=fModules->FindObject(name);
214 if(mod) i=fModules->IndexOf(mod);
218 //_______________________________________________________________________
219 Int_t AliRun::GetEvent(Int_t event)
222 // Reloads data containers in folders # event
223 // Set branch addresses
225 if (fRunLoader == 0x0)
227 AliError("RunLoader is not set. Can not load data.");
230 /*****************************************/
231 /**** P R E R E L O A D I N G ****/
232 /*****************************************/
233 // Reset existing structures
235 fMCApp->ResetTrackReferences();
236 fMCApp->ResetDigits();
237 fMCApp->ResetSDigits();
239 /*****************************************/
240 /**** R E L O A D ****/
241 /*****************************************/
243 AliRunLoader::Instance()->GetEvent(event);
245 /*****************************************/
246 /**** P O S T R E L O A D I N G ****/
247 /*****************************************/
249 // Set Trees branch addresses
250 TIter next(fModules);
251 AliDetector *detector;
252 while((detector = dynamic_cast<AliDetector*>(next())))
254 detector->SetTreeAddress();
257 return AliRunLoader::Instance()->GetHeader()->GetNtrack();
260 //_______________________________________________________________________
261 void AliRun::SetBaseFile(const char *filename)
263 fBaseFileName = filename;
267 //_______________________________________________________________________
268 void AliRun::Hits2Digits(const char *selected)
271 // Convert Hits to sumable digits
273 for (Int_t nevent=0; nevent<AliRunLoader::Instance()->TreeE()->GetEntries(); nevent++) {
275 Hits2SDigits(selected);
276 SDigits2Digits(selected);
281 //_______________________________________________________________________
282 void AliRun::Tree2Tree(Option_t *option, const char *selected)
285 // Function to transform the content of
287 // - TreeH to TreeS (option "S")
288 // - TreeS to TreeD (option "D")
289 // - TreeD to TreeR (option "R")
291 // If multiple options are specified ("SDR"), transformation will be done in sequence for
292 // selected detector and for all detectors if none is selected (detector string
293 // can contain blank separated list of detector names).
296 const char *oS = strstr(option,"S");
297 const char *oD = strstr(option,"D");
298 const char *oR = strstr(option,"R");
300 TObjArray *detectors = Detectors();
302 TIter next(detectors);
304 AliDetector *detector = 0;
306 while((detector = dynamic_cast<AliDetector*>(next()))) {
308 if (strcmp(detector->GetName(),selected)) continue;
309 if (detector->IsActive())
312 AliLoader* loader = detector->GetLoader();
313 if (loader == 0x0) continue;
317 AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName()));
318 loader->LoadHits("read");
319 if (loader->TreeS() == 0x0) loader->MakeTree("S");
320 detector->MakeBranch(option);
321 detector->SetTreeAddress();
322 detector->Hits2SDigits();
323 loader->UnloadHits();
324 loader->UnloadSDigits();
328 AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName()));
329 loader->LoadSDigits("read");
330 if (loader->TreeD() == 0x0) loader->MakeTree("D");
331 detector->MakeBranch(option);
332 detector->SetTreeAddress();
333 detector->SDigits2Digits();
334 loader->UnloadSDigits();
335 loader->UnloadDigits();
339 AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName()));
340 loader->LoadDigits("read");
341 if (loader->TreeR() == 0x0) loader->MakeTree("R");
342 detector->MakeBranch(option);
343 detector->SetTreeAddress();
344 detector->Digits2Reco();
345 loader->UnloadDigits();
346 loader->UnloadRecPoints();
354 //_______________________________________________________________________
355 void AliRun::Streamer(TBuffer &R__b)
357 // Stream an object of class AliRun.
359 if (R__b.IsReading()) {
360 if (!gAlice) gAlice = this;
361 AliRun::Class()->ReadBuffer(R__b, this);
362 gROOT->GetListOfBrowsables()->Add(this,"Run");
363 gRandom = new TRandom3();
365 AliRun::Class()->WriteBuffer(R__b, this);
369 //_______________________________________________________________________
370 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
372 AliRunLoader::Instance()->GetHeader()->SetGenEventHeader(header);
376 //_______________________________________________________________________
377 Int_t AliRun::GetEvNumber() const
379 //Returns number of current event
380 if (fRunLoader == 0x0)
382 AliError("RunLoader is not set. Can not load data.");
386 return fRunLoader->GetEventNumber();
389 //_______________________________________________________________________
390 void AliRun::SetRunLoader(AliRunLoader* rloader)
393 // Set the loader of the run
395 fRunLoader = rloader;
396 if (fRunLoader == 0x0) return;
399 TFolder* evfold = fRunLoader->GetEventFolder();
400 if (evfold) evfoldname = evfold->GetName();
401 else AliFatal("Did not get Event Folder from Run Loader");
403 if ( fRunLoader->GetAliRun() )
404 {//if alrun already exists in folder
405 if (fRunLoader->GetAliRun() != this )
406 {//and is different than this - crash
407 AliFatal("AliRun is already in Folder and it is not this object");
413 evfold->Add(this);//Post this AliRun to Folder
416 TIter next(fModules);
418 while((module = (AliModule*)next()))
420 if (evfold) AliConfig::Instance()->Add(module,evfoldname);
421 module->SetRunLoader(fRunLoader);
422 AliDetector* detector = dynamic_cast<AliDetector*>(module);
425 AliLoader* loader = fRunLoader->GetLoader(detector);
428 AliError(Form("Can not get loader for detector %s", detector->GetName()));
432 AliDebug(1, Form("Setting loader for detector %s", detector->GetName()));
433 detector->SetLoader(loader);
439 //_______________________________________________________________________
440 void AliRun::AddModule(AliModule* mod)
443 // Add a module to the module list
445 if (mod == 0x0) return;
446 if (strlen(mod->GetName()) == 0) return;
447 if (GetModuleID(mod->GetName()) >= 0) return;
449 AliDebug(1, mod->GetName());
450 if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod);
451 else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName());