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 //_______________________________________________________________________
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 TIter next(fModules);
131 while((mod = (AliModule*)next()))
133 modfold->Remove(mod);
146 //_____________________________________________________________________________
147 void AliRun::InitLoaders()
149 //creates list of getters
151 TIter next(fModules);
153 while((mod = (AliModule*)next()))
155 mod->SetRunLoader(fRunLoader);
156 AliDetector *det = dynamic_cast<AliDetector*>(mod);
159 AliDebug(2, Form("Adding %s", det->GetName()));
160 fRunLoader->AddLoader(det);
166 //_______________________________________________________________________
167 void AliRun::Announce() const
170 // Announce the current version of AliRoot
173 "****************************************************************\n");
174 printf("%6s","*");printf("%64s","*\n");
177 printf(" You are running AliRoot version NewIO\n");
180 printf(" The SVN version for the current program is $Id$\n");
182 printf("%6s","*");printf("%64s","*\n");
184 "****************************************************************\n");
187 //_______________________________________________________________________
188 AliModule *AliRun::GetModule(const char *name) const
191 // Return pointer to detector from name
193 return dynamic_cast<AliModule*>(fModules->FindObject(name));
196 //_______________________________________________________________________
197 AliDetector *AliRun::GetDetector(const char *name) const
200 // Return pointer to detector from name
202 return dynamic_cast<AliDetector*>(fModules->FindObject(name));
205 //_______________________________________________________________________
206 Int_t AliRun::GetModuleID(const char *name) const
209 // Return galice internal detector identifier from name
212 TObject *mod=fModules->FindObject(name);
213 if(mod) i=fModules->IndexOf(mod);
217 //_______________________________________________________________________
218 Int_t AliRun::GetEvent(Int_t event)
221 // Reloads data containers in folders # event
222 // Set branch addresses
224 if (fRunLoader == 0x0)
226 AliError("RunLoader is not set. Can not load data.");
229 /*****************************************/
230 /**** P R E R E L O A D I N G ****/
231 /*****************************************/
232 // Reset existing structures
234 fMCApp->ResetTrackReferences();
235 fMCApp->ResetDigits();
236 fMCApp->ResetSDigits();
238 /*****************************************/
239 /**** R E L O A D ****/
240 /*****************************************/
242 AliRunLoader::Instance()->GetEvent(event);
244 /*****************************************/
245 /**** P O S T R E L O A D I N G ****/
246 /*****************************************/
248 // Set Trees branch addresses
249 TIter next(fModules);
250 AliDetector *detector;
251 while((detector = dynamic_cast<AliDetector*>(next())))
253 detector->SetTreeAddress();
256 return AliRunLoader::Instance()->GetHeader()->GetNtrack();
259 //_______________________________________________________________________
260 void AliRun::SetBaseFile(const char *filename)
262 fBaseFileName = filename;
266 //_______________________________________________________________________
267 void AliRun::Hits2Digits(const char *selected)
270 // Convert Hits to sumable digits
272 for (Int_t nevent=0; nevent<AliRunLoader::Instance()->TreeE()->GetEntries(); nevent++) {
274 Hits2SDigits(selected);
275 SDigits2Digits(selected);
280 //_______________________________________________________________________
281 void AliRun::Tree2Tree(Option_t *option, const char *selected)
284 // Function to transform the content of
286 // - TreeH to TreeS (option "S")
287 // - TreeS to TreeD (option "D")
288 // - TreeD to TreeR (option "R")
290 // If multiple options are specified ("SDR"), transformation will be done in sequence for
291 // selected detector and for all detectors if none is selected (detector string
292 // can contain blank separated list of detector names).
295 const char *oS = strstr(option,"S");
296 const char *oD = strstr(option,"D");
297 const char *oR = strstr(option,"R");
299 TObjArray *detectors = Detectors();
301 TIter next(detectors);
303 AliDetector *detector = 0;
305 while((detector = dynamic_cast<AliDetector*>(next()))) {
307 if (strcmp(detector->GetName(),selected)) continue;
308 if (detector->IsActive())
311 AliLoader* loader = detector->GetLoader();
312 if (loader == 0x0) continue;
316 AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName()));
317 loader->LoadHits("read");
318 if (loader->TreeS() == 0x0) loader->MakeTree("S");
319 detector->MakeBranch(option);
320 detector->SetTreeAddress();
321 detector->Hits2SDigits();
322 loader->UnloadHits();
323 loader->UnloadSDigits();
327 AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName()));
328 loader->LoadSDigits("read");
329 if (loader->TreeD() == 0x0) loader->MakeTree("D");
330 detector->MakeBranch(option);
331 detector->SetTreeAddress();
332 detector->SDigits2Digits();
333 loader->UnloadSDigits();
334 loader->UnloadDigits();
338 AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName()));
339 loader->LoadDigits("read");
340 if (loader->TreeR() == 0x0) loader->MakeTree("R");
341 detector->MakeBranch(option);
342 detector->SetTreeAddress();
343 detector->Digits2Reco();
344 loader->UnloadDigits();
345 loader->UnloadRecPoints();
353 //_______________________________________________________________________
354 void AliRun::Streamer(TBuffer &R__b)
356 // Stream an object of class AliRun.
358 if (R__b.IsReading()) {
359 if (!gAlice) gAlice = this;
360 AliRun::Class()->ReadBuffer(R__b, this);
361 gROOT->GetListOfBrowsables()->Add(this,"Run");
362 gRandom = new TRandom3();
364 AliRun::Class()->WriteBuffer(R__b, this);
368 //_______________________________________________________________________
369 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
371 AliRunLoader::Instance()->GetHeader()->SetGenEventHeader(header);
375 //_______________________________________________________________________
376 Int_t AliRun::GetEvNumber() const
378 //Returns number of current event
379 if (fRunLoader == 0x0)
381 AliError("RunLoader is not set. Can not load data.");
385 return fRunLoader->GetEventNumber();
388 //_______________________________________________________________________
389 void AliRun::SetRunLoader(AliRunLoader* rloader)
392 // Set the loader of the run
394 fRunLoader = rloader;
395 if (fRunLoader == 0x0) return;
398 TFolder* evfold = fRunLoader->GetEventFolder();
399 if (evfold) evfoldname = evfold->GetName();
400 else AliWarning("Did not get Event Folder from Run Loader");
402 if ( fRunLoader->GetAliRun() )
403 {//if alrun already exists in folder
404 if (fRunLoader->GetAliRun() != this )
405 {//and is different than this - crash
406 AliFatal("AliRun is already in Folder and it is not this object");
412 evfold->Add(this);//Post this AliRun to Folder
415 TIter next(fModules);
417 while((module = (AliModule*)next()))
419 if (evfold) AliConfig::Instance()->Add(module,evfoldname);
420 module->SetRunLoader(fRunLoader);
421 AliDetector* detector = dynamic_cast<AliDetector*>(module);
424 AliLoader* loader = fRunLoader->GetLoader(detector);
427 AliError(Form("Can not get loader for detector %s", detector->GetName()));
431 AliDebug(1, Form("Setting loader for detector %s", detector->GetName()));
432 detector->SetLoader(loader);
438 //_______________________________________________________________________
439 void AliRun::AddModule(AliModule* mod)
442 // Add a module to the module list
444 if (mod == 0x0) return;
445 if (strlen(mod->GetName()) == 0) return;
446 if (GetModuleID(mod->GetName()) >= 0) return;
448 AliDebug(1, mod->GetName());
449 if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod);
450 else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName());