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>
52 #include "AliDetector.h"
53 #include "AliHeader.h"
58 #include "AliCDBManager.h"
59 #include "AliAlignObj.h"
60 #include "AliSimulation.h"
67 //_______________________________________________________________________
79 // Default constructor for AliRun
81 AliConfig::Instance();//skowron 29 Feb 2002
82 //ensures that the folder structure is build
86 //_____________________________________________________________________________
87 AliRun::AliRun(const char *name, const char *title):
90 fModules(new TObjArray(77)), // Support list for the Detectors
91 fMCApp(new AliMC(GetName(),GetTitle())),
93 fConfigFunction("Config();"),
98 // Constructor for the main processor.
99 // Creates the geometry
100 // Creates the list of Detectors.
101 // Creates the list of particles.
106 // Set random number generator
107 gRandom = new TRandom3();
109 if (gSystem->Getenv("CONFIG_SEED")) {
110 gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED"))));
113 // Add to list of browsable
114 gROOT->GetListOfBrowsables()->Add(this,name);
118 //_______________________________________________________________________
122 // Default AliRun destructor
124 gROOT->GetListOfBrowsables()->Remove(this);
128 TFolder* evfold = fRunLoader->GetEventFolder();
129 TFolder* modfold = dynamic_cast<TFolder*>(evfold->FindObjectAny(AliConfig::GetModulesFolderName()));
130 if(!modfold) AliFatal(Form("Folder %s not found\n",AliConfig::GetModulesFolderName().Data()));
131 TIter next(fModules);
133 while((mod = (AliModule*)next()))
135 modfold->Remove(mod);
148 //_____________________________________________________________________________
149 void AliRun::InitLoaders()
151 //creates list of getters
153 TIter next(fModules);
155 while((mod = (AliModule*)next()))
157 mod->SetRunLoader(fRunLoader);
158 AliDetector *det = dynamic_cast<AliDetector*>(mod);
161 AliDebug(2, Form("Adding %s", det->GetName()));
162 fRunLoader->AddLoader(det);
168 //_______________________________________________________________________
169 void AliRun::Announce() const
172 // Announce the current version of AliRoot
175 "****************************************************************\n");
176 printf("%6s","*");printf("%64s","*\n");
179 printf(" You are running AliRoot version NewIO\n");
182 printf(" The SVN version for the current program is $Id$\n");
184 printf("%6s","*");printf("%64s","*\n");
186 "****************************************************************\n");
189 //_______________________________________________________________________
190 AliModule *AliRun::GetModule(const char *name) const
193 // Return pointer to detector from name
195 return dynamic_cast<AliModule*>(fModules->FindObject(name));
198 //_______________________________________________________________________
199 AliDetector *AliRun::GetDetector(const char *name) const
202 // Return pointer to detector from name
204 return dynamic_cast<AliDetector*>(fModules->FindObject(name));
207 //_______________________________________________________________________
208 Int_t AliRun::GetModuleID(const char *name) const
211 // Return galice internal detector identifier from name
214 TObject *mod=fModules->FindObject(name);
215 if(mod) i=fModules->IndexOf(mod);
219 //_______________________________________________________________________
220 Int_t AliRun::GetEvent(Int_t event)
223 // Reloads data containers in folders # event
224 // Set branch addresses
226 if (fRunLoader == 0x0)
228 AliError("RunLoader is not set. Can not load data.");
231 /*****************************************/
232 /**** P R E R E L O A D I N G ****/
233 /*****************************************/
234 // Reset existing structures
236 fMCApp->ResetTrackReferences();
237 fMCApp->ResetDigits();
238 fMCApp->ResetSDigits();
240 /*****************************************/
241 /**** R E L O A D ****/
242 /*****************************************/
244 AliRunLoader::Instance()->GetEvent(event);
246 /*****************************************/
247 /**** P O S T R E L O A D I N G ****/
248 /*****************************************/
250 // Set Trees branch addresses
251 TIter next(fModules);
252 AliDetector *detector;
253 while((detector = dynamic_cast<AliDetector*>(next())))
255 detector->SetTreeAddress();
258 return AliRunLoader::Instance()->GetHeader()->GetNtrack();
261 //_______________________________________________________________________
262 void AliRun::SetBaseFile(const char *filename)
264 fBaseFileName = filename;
268 //_______________________________________________________________________
269 void AliRun::Hits2Digits(const char *selected)
272 // Convert Hits to sumable digits
274 for (Int_t nevent=0; nevent<AliRunLoader::Instance()->TreeE()->GetEntries(); nevent++) {
276 Hits2SDigits(selected);
277 SDigits2Digits(selected);
282 //_______________________________________________________________________
283 void AliRun::Tree2Tree(Option_t *option, const char *selected)
286 // Function to transform the content of
288 // - TreeH to TreeS (option "S")
289 // - TreeS to TreeD (option "D")
290 // - TreeD to TreeR (option "R")
292 // If multiple options are specified ("SDR"), transformation will be done in sequence for
293 // selected detector and for all detectors if none is selected (detector string
294 // can contain blank separated list of detector names).
297 const char *oS = strstr(option,"S");
298 const char *oD = strstr(option,"D");
299 const char *oR = strstr(option,"R");
301 TObjArray *detectors = Detectors();
303 TIter next(detectors);
305 AliDetector *detector = 0;
307 while((detector = dynamic_cast<AliDetector*>(next()))) {
309 if (strcmp(detector->GetName(),selected)) continue;
310 if (detector->IsActive())
313 AliLoader* loader = detector->GetLoader();
314 if (loader == 0x0) continue;
318 AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName()));
319 loader->LoadHits("read");
320 if (loader->TreeS() == 0x0) loader->MakeTree("S");
321 detector->MakeBranch(option);
322 detector->SetTreeAddress();
323 detector->Hits2SDigits();
324 loader->UnloadHits();
325 loader->UnloadSDigits();
329 AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName()));
330 loader->LoadSDigits("read");
331 if (loader->TreeD() == 0x0) loader->MakeTree("D");
332 detector->MakeBranch(option);
333 detector->SetTreeAddress();
334 detector->SDigits2Digits();
335 loader->UnloadSDigits();
336 loader->UnloadDigits();
340 AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName()));
341 loader->LoadDigits("read");
342 if (loader->TreeR() == 0x0) loader->MakeTree("R");
343 detector->MakeBranch(option);
344 detector->SetTreeAddress();
345 detector->Digits2Reco();
346 loader->UnloadDigits();
347 loader->UnloadRecPoints();
355 //_______________________________________________________________________
356 void AliRun::Streamer(TBuffer &R__b)
358 // Stream an object of class AliRun.
360 if (R__b.IsReading()) {
361 if (!gAlice) gAlice = this;
362 AliRun::Class()->ReadBuffer(R__b, this);
363 gROOT->GetListOfBrowsables()->Add(this,"Run");
364 gRandom = new TRandom3();
366 AliRun::Class()->WriteBuffer(R__b, this);
370 //_______________________________________________________________________
371 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
373 AliRunLoader::Instance()->GetHeader()->SetGenEventHeader(header);
377 //_______________________________________________________________________
378 Int_t AliRun::GetEvNumber() const
380 //Returns number of current event
381 if (fRunLoader == 0x0)
383 AliError("RunLoader is not set. Can not load data.");
387 return fRunLoader->GetEventNumber();
390 //_______________________________________________________________________
391 void AliRun::SetRunLoader(AliRunLoader* rloader)
394 // Set the loader of the run
396 fRunLoader = rloader;
397 if (fRunLoader == 0x0) return;
400 TFolder* evfold = fRunLoader->GetEventFolder();
401 if (evfold) evfoldname = evfold->GetName();
402 else AliFatal("Did not get Event Folder from Run Loader");
404 if ( fRunLoader->GetAliRun() )
405 {//if alrun already exists in folder
406 if (fRunLoader->GetAliRun() != this )
407 {//and is different than this - crash
408 AliFatal("AliRun is already in Folder and it is not this object");
414 evfold->Add(this);//Post this AliRun to Folder
417 TIter next(fModules);
419 while((module = (AliModule*)next()))
421 if (evfold) AliConfig::Instance()->Add(module,evfoldname);
422 module->SetRunLoader(fRunLoader);
423 AliDetector* detector = dynamic_cast<AliDetector*>(module);
426 AliLoader* loader = fRunLoader->GetLoader(detector);
429 AliError(Form("Can not get loader for detector %s", detector->GetName()));
433 AliDebug(1, Form("Setting loader for detector %s", detector->GetName()));
434 detector->SetLoader(loader);
440 //_______________________________________________________________________
441 void AliRun::AddModule(AliModule* mod)
444 // Add a module to the module list
446 if (mod == 0x0) return;
447 if (strlen(mod->GetName()) == 0) return;
448 if (GetModuleID(mod->GetName()) >= 0) return;
450 AliDebug(1, mod->GetName());
451 if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod);
452 else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName());