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