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