]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliRun.cxx
This is a backward incompatible change in AliRoot. The following methods have been...
[u/mrichter/AliRoot.git] / STEER / AliRun.cxx
CommitLineData
99d554c8 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
acd84897 16/* $Id$ */
99d554c8 17
fe4da5cc 18///////////////////////////////////////////////////////////////////////////////
19// //
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. //
24// //
8494b010 25// -Supports the list of all Alice Detectors (fModules). //
fe4da5cc 26// -Supports the list of particles (fParticles). //
27// -Supports the Trees. //
28// -Supports the geometry. //
29// -Supports the event display. //
30//Begin_Html
31/*
1439f98e 32<img src="picts/AliRunClass.gif">
fe4da5cc 33*/
34//End_Html
35//Begin_Html
36/*
1439f98e 37<img src="picts/alirun.gif">
fe4da5cc 38*/
39//End_Html
40// //
41///////////////////////////////////////////////////////////////////////////////
42
88cb7938 43#include <TCint.h>
88cb7938 44#include <TROOT.h>
88cb7938 45#include <TRandom3.h>
46#include <TSystem.h>
88cb7938 47#include <TVirtualMC.h>
178a256c 48#include <TGeoManager.h>
5d12ce38 49//
21bf7095 50#include "AliLog.h"
98490ea9 51#include "AliDetector.h"
98490ea9 52#include "AliHeader.h"
5d12ce38 53#include "AliMC.h"
141f90e3 54#include "AliPDG.h"
98490ea9 55#include "AliRun.h"
56#include "AliStack.h"
b3276c04 57#include "AliCDBManager.h"
995ad051 58#include "AliAlignObj.h"
3e2e3ece 59#include "AliSimulation.h"
60#include "AliLego.h"
fe4da5cc 61
fe4da5cc 62AliRun *gAlice;
63
fe4da5cc 64ClassImp(AliRun)
65
e2afb3b6 66//_______________________________________________________________________
67AliRun::AliRun():
33c3c91a 68// fRun(-1),
3e2e3ece 69 fEventNrInRun(-1),
e2afb3b6 70 fModules(0),
5d12ce38 71 fMCApp(0),
e2afb3b6 72 fNdets(0),
4539539b 73 fConfigFunction(""),
e2afb3b6 74 fRandom(0),
fe12e09c 75 fBaseFileName(""),
5d12ce38 76 fRunLoader(0x0)
fe4da5cc 77{
78 //
79 // Default constructor for AliRun
80 //
88cb7938 81 AliConfig::Instance();//skowron 29 Feb 2002
82 //ensures that the folder structure is build
3d45e923 83
e2afb3b6 84}
85
fe4da5cc 86//_____________________________________________________________________________
e2afb3b6 87AliRun::AliRun(const char *name, const char *title):
5d12ce38 88 TNamed(name,title),
3e2e3ece 89 fEventNrInRun(-1),
e2afb3b6 90 fModules(new TObjArray(77)), // Support list for the Detectors
3e2e3ece 91 fMCApp(new AliMC(GetName(),GetTitle())),
e2afb3b6 92 fNdets(0),
e2afb3b6 93 fConfigFunction("Config();"),
94 fRandom(new TRandom3()),
fe12e09c 95 fBaseFileName(""),
b60e0f5e 96 fRunLoader(0x0)
fe4da5cc 97{
98 //
99 // Constructor for the main processor.
100 // Creates the geometry
101 // Creates the list of Detectors.
102 // Creates the list of particles.
103 //
e2afb3b6 104
fe4da5cc 105 gAlice = this;
65fb704d 106
107 // Set random number generator
e2afb3b6 108 gRandom = fRandom;
2ab0c725 109
110 if (gSystem->Getenv("CONFIG_SEED")) {
e2afb3b6 111 gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED"))));
2ab0c725 112 }
e2afb3b6 113
114 // Add to list of browsable
fe4da5cc 115 gROOT->GetListOfBrowsables()->Add(this,name);
fe4da5cc 116
fe4da5cc 117}
118
e2afb3b6 119//_______________________________________________________________________
fe4da5cc 120AliRun::~AliRun()
121{
122 //
2ab0c725 123 // Default AliRun destructor
fe4da5cc 124 //
88cb7938 125 gROOT->GetListOfBrowsables()->Remove(this);
126
127 if (fRunLoader)
128 {
129 TFolder* evfold = fRunLoader->GetEventFolder();
130 TFolder* modfold = dynamic_cast<TFolder*>(evfold->FindObjectAny(AliConfig::GetModulesFolderName()));
131 TIter next(fModules);
132 AliModule *mod;
133 while((mod = (AliModule*)next()))
134 {
135 modfold->Remove(mod);
136 }
137 }
3e2e3ece 138
5d12ce38 139 delete fMCApp;
f5bc1485 140 delete gMC; gMC=0;
8494b010 141 if (fModules) {
142 fModules->Delete();
143 delete fModules;
fe4da5cc 144 }
88cb7938 145
fe4da5cc 146}
147
88cb7938 148//_____________________________________________________________________________
88cb7938 149void AliRun::InitLoaders()
150{
151 //creates list of getters
21bf7095 152 AliDebug(1, "");
88cb7938 153 TIter next(fModules);
154 AliModule *mod;
155 while((mod = (AliModule*)next()))
156 {
1d6fbf6e 157 mod->SetRunLoader(fRunLoader);
88cb7938 158 AliDetector *det = dynamic_cast<AliDetector*>(mod);
159 if (det)
160 {
21bf7095 161 AliDebug(2, Form("Adding %s", det->GetName()));
88cb7938 162 fRunLoader->AddLoader(det);
163 }
164 }
21bf7095 165 AliDebug(1, "Done");
88cb7938 166}
fe4da5cc 167
eb1b8d29 168//_______________________________________________________________________
169void AliRun::Announce() const
170{
171 //
37d06d5b 172 // Announce the current version of AliRoot
173 //
174 printf("%70s",
175 "****************************************************************\n");
176 printf("%6s","*");printf("%64s","*\n");
177
178 printf("%6s","*");
88cb7938 179 printf(" You are running AliRoot version NewIO\n");
37d06d5b 180
181 printf("%6s","*");
5960f18d 182 printf(" The SVN version for the current program is $Id$\n");
37d06d5b 183
184 printf("%6s","*");printf("%64s","*\n");
185 printf("%70s",
186 "****************************************************************\n");
eb1b8d29 187}
188
e2afb3b6 189//_______________________________________________________________________
94de3818 190AliModule *AliRun::GetModule(const char *name) const
fe4da5cc 191{
192 //
193 // Return pointer to detector from name
194 //
e2afb3b6 195 return dynamic_cast<AliModule*>(fModules->FindObject(name));
fe4da5cc 196}
197
e2afb3b6 198//_______________________________________________________________________
94de3818 199AliDetector *AliRun::GetDetector(const char *name) const
a68348e9 200{
201 //
202 // Return pointer to detector from name
203 //
e2afb3b6 204 return dynamic_cast<AliDetector*>(fModules->FindObject(name));
a68348e9 205}
206
e2afb3b6 207//_______________________________________________________________________
94de3818 208Int_t AliRun::GetModuleID(const char *name) const
fe4da5cc 209{
210 //
211 // Return galice internal detector identifier from name
212 //
23370b7a 213 Int_t i=-1;
214 TObject *mod=fModules->FindObject(name);
215 if(mod) i=fModules->IndexOf(mod);
216 return i;
fe4da5cc 217}
218
e2afb3b6 219//_______________________________________________________________________
fe4da5cc 220Int_t AliRun::GetEvent(Int_t event)
221{
88cb7938 222//
223// Reloads data containers in folders # event
224// Set branch addresses
225//
226 if (fRunLoader == 0x0)
227 {
21bf7095 228 AliError("RunLoader is not set. Can not load data.");
88cb7938 229 return -1;
230 }
231/*****************************************/
232/**** P R E R E L O A D I N G ****/
233/*****************************************/
234// Reset existing structures
5d12ce38 235 fMCApp->ResetHits();
236 fMCApp->ResetTrackReferences();
3e2e3ece 237 fMCApp->ResetDigits();
238 fMCApp->ResetSDigits();
50a6540a 239
88cb7938 240/*****************************************/
241/**** R E L O A D ****/
242/*****************************************/
aab9c8d5 243
33c3c91a 244 AliRunLoader::Instance()->GetEvent(event);
b9d0a01d 245
88cb7938 246/*****************************************/
247/**** P O S T R E L O A D I N G ****/
248/*****************************************/
82711e7a 249
fe4da5cc 250 // Set Trees branch addresses
8494b010 251 TIter next(fModules);
07d55def 252 AliDetector *detector;
253 while((detector = dynamic_cast<AliDetector*>(next())))
88cb7938 254 {
255 detector->SetTreeAddress();
256 }
257
33c3c91a 258 return AliRunLoader::Instance()->GetHeader()->GetNtrack();
fe4da5cc 259}
260
e2afb3b6 261//_______________________________________________________________________
262void AliRun::SetBaseFile(const char *filename)
2ab0c725 263{
39de14fb 264 fBaseFileName = filename;
2ab0c725 265}
266
fe4da5cc 267
e2afb3b6 268//_______________________________________________________________________
2ab0c725 269void AliRun::Hits2Digits(const char *selected)
270{
9e1a0ddb 271
d47c658f 272 // Convert Hits to sumable digits
273 //
33c3c91a 274 for (Int_t nevent=0; nevent<AliRunLoader::Instance()->TreeE()->GetEntries(); nevent++) {
9e1a0ddb 275 GetEvent(nevent);
9e1a0ddb 276 Hits2SDigits(selected);
277 SDigits2Digits(selected);
278 }
2ab0c725 279}
280
d47c658f 281
e2afb3b6 282//_______________________________________________________________________
d47c658f 283void AliRun::Tree2Tree(Option_t *option, const char *selected)
2ab0c725 284{
285 //
d47c658f 286 // Function to transform the content of
287 //
288 // - TreeH to TreeS (option "S")
289 // - TreeS to TreeD (option "D")
290 // - TreeD to TreeR (option "R")
291 //
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).
2ab0c725 295
2ab0c725 296
5cf7bbad 297 const char *oS = strstr(option,"S");
298 const char *oD = strstr(option,"D");
299 const char *oR = strstr(option,"R");
2ab0c725 300
9e1a0ddb 301 TObjArray *detectors = Detectors();
2ab0c725 302
303 TIter next(detectors);
304
d47c658f 305 AliDetector *detector = 0;
2ab0c725 306
88cb7938 307 while((detector = dynamic_cast<AliDetector*>(next()))) {
d47c658f 308 if (selected)
2ab0c725 309 if (strcmp(detector->GetName(),selected)) continue;
88cb7938 310 if (detector->IsActive())
311 {
312
313 AliLoader* loader = detector->GetLoader();
314 if (loader == 0x0) continue;
315
316 if (oS)
317 {
21bf7095 318 AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName()));
88cb7938 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();
326 }
327 if (oD)
328 {
21bf7095 329 AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName()));
88cb7938 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();
337 }
338 if (oR)
339 {
21bf7095 340 AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName()));
88cb7938 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();
348
349 }
350 }
351 }
2ab0c725 352}
353
b9d0a01d 354
e2afb3b6 355//_______________________________________________________________________
fe4da5cc 356void AliRun::Streamer(TBuffer &R__b)
357{
eef4b160 358 // Stream an object of class AliRun.
2ab0c725 359
7e90ff59 360 if (R__b.IsReading()) {
361 if (!gAlice) gAlice = this;
7e90ff59 362 AliRun::Class()->ReadBuffer(R__b, this);
7e90ff59 363 gROOT->GetListOfBrowsables()->Add(this,"Run");
eef4b160 364
7e90ff59 365 gRandom = fRandom;
366 } else {
eef4b160 367 AliRun::Class()->WriteBuffer(R__b, this);
368 }
2ab0c725 369}
b9d0a01d 370
28da60d3 371//_______________________________________________________________________
27f087a9 372void AliRun::SetGenEventHeader(AliGenEventHeader* header)
373{
33c3c91a 374 AliRunLoader::Instance()->GetHeader()->SetGenEventHeader(header);
27f087a9 375}
7dd2cbe4 376
377
504b172d 378//_______________________________________________________________________
88cb7938 379Int_t AliRun::GetEvNumber() const
380{
381//Returns number of current event
382 if (fRunLoader == 0x0)
383 {
21bf7095 384 AliError("RunLoader is not set. Can not load data.");
88cb7938 385 return -1;
386 }
0592d1ca 387
88cb7938 388 return fRunLoader->GetEventNumber();
0592d1ca 389}
b9d0a01d 390
28da60d3 391//_______________________________________________________________________
88cb7938 392void AliRun::SetRunLoader(AliRunLoader* rloader)
0592d1ca 393{
2057aecb 394 //
395 // Set the loader of the run
396 //
88cb7938 397 fRunLoader = rloader;
398 if (fRunLoader == 0x0) return;
399
400 TString evfoldname;
401 TFolder* evfold = fRunLoader->GetEventFolder();
402 if (evfold) evfoldname = evfold->GetName();
21bf7095 403 else AliWarning("Did not get Event Folder from Run Loader");
88cb7938 404
405 if ( fRunLoader->GetAliRun() )
406 {//if alrun already exists in folder
407 if (fRunLoader->GetAliRun() != this )
408 {//and is different than this - crash
21bf7095 409 AliFatal("AliRun is already in Folder and it is not this object");
88cb7938 410 return;//pro forma
411 }//else do nothing
412 }
413 else
414 {
415 evfold->Add(this);//Post this AliRun to Folder
416 }
417
418 TIter next(fModules);
419 AliModule *module;
420 while((module = (AliModule*)next()))
421 {
422 if (evfold) AliConfig::Instance()->Add(module,evfoldname);
1d6fbf6e 423 module->SetRunLoader(fRunLoader);
88cb7938 424 AliDetector* detector = dynamic_cast<AliDetector*>(module);
425 if (detector)
426 {
427 AliLoader* loader = fRunLoader->GetLoader(detector);
428 if (loader == 0x0)
429 {
21bf7095 430 AliError(Form("Can not get loader for detector %s", detector->GetName()));
88cb7938 431 }
432 else
433 {
21bf7095 434 AliDebug(1, Form("Setting loader for detector %s", detector->GetName()));
88cb7938 435 detector->SetLoader(loader);
436 }
0592d1ca 437 }
88cb7938 438 }
0592d1ca 439}
440
28da60d3 441//_______________________________________________________________________
88cb7938 442void AliRun::AddModule(AliModule* mod)
7a16e9cc 443{
2057aecb 444 //
445 // Add a module to the module list
446 //
88cb7938 447 if (mod == 0x0) return;
448 if (strlen(mod->GetName()) == 0) return;
449 if (GetModuleID(mod->GetName()) >= 0) return;
450
21bf7095 451 AliDebug(1, mod->GetName());
88cb7938 452 if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod);
453 else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName());
7a16e9cc 454
88cb7938 455 Modules()->Add(mod);
67d736ee 456
457 fNdets++;
7a16e9cc 458}
21bf7095 459