]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliRun.cxx
adding new library libAliHLTGlobal for global HLT components; adding global track...
[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 <TBRIK.h>
88cb7938 44#include <TCint.h>
88cb7938 45#include <TGeometry.h>
88cb7938 46#include <TROOT.h>
88cb7938 47#include <TRandom3.h>
48#include <TSystem.h>
88cb7938 49#include <TVirtualMC.h>
178a256c 50#include <TGeoManager.h>
5d12ce38 51//
21bf7095 52#include "AliLog.h"
98490ea9 53#include "AliDetector.h"
98490ea9 54#include "AliHeader.h"
dffd31ef 55#include "AliLego.h"
98490ea9 56#include "AliLegoGenerator.h"
5d12ce38 57#include "AliMC.h"
aee8290b 58#include "AliMagFC.h"
59#include "AliMagFCM.h"
60#include "AliMagFDM.h"
141f90e3 61#include "AliPDG.h"
98490ea9 62#include "AliRun.h"
63#include "AliStack.h"
b3276c04 64#include "AliCDBManager.h"
995ad051 65#include "AliAlignObj.h"
fe4da5cc 66
fe4da5cc 67AliRun *gAlice;
68
fe4da5cc 69ClassImp(AliRun)
70
e2afb3b6 71//_______________________________________________________________________
72AliRun::AliRun():
3d45e923 73 fRun(-1),
e2afb3b6 74 fEvent(0),
75 fEventNrInRun(0),
e2afb3b6 76 fModules(0),
5d12ce38 77 fMCApp(0),
e2afb3b6 78 fField(0),
e2afb3b6 79 fNdets(0),
e2afb3b6 80 fLego(0),
4539539b 81 fConfigFunction(""),
e2afb3b6 82 fRandom(0),
fe12e09c 83 fBaseFileName(""),
4a9de4af 84 fIsRootGeometry(kFALSE),
ced249e6 85 fGeometryFromCDB(kFALSE),
4539539b 86 fGeometryFileName(""),
87 fTriggerDescriptor(""),
5d12ce38 88 fRunLoader(0x0)
fe4da5cc 89{
90 //
91 // Default constructor for AliRun
92 //
88cb7938 93 AliConfig::Instance();//skowron 29 Feb 2002
94 //ensures that the folder structure is build
3d45e923 95
e2afb3b6 96}
97
fe4da5cc 98//_____________________________________________________________________________
e2afb3b6 99AliRun::AliRun(const char *name, const char *title):
5d12ce38 100 TNamed(name,title),
3d45e923 101 fRun(-1),
e2afb3b6 102 fEvent(0),
103 fEventNrInRun(0),
e2afb3b6 104 fModules(new TObjArray(77)), // Support list for the Detectors
5d12ce38 105 fMCApp(0),
e2afb3b6 106 fField(0),
e2afb3b6 107 fNdets(0),
e2afb3b6 108 fLego(0),
e2afb3b6 109 fConfigFunction("Config();"),
110 fRandom(new TRandom3()),
fe12e09c 111 fBaseFileName(""),
4a9de4af 112 fIsRootGeometry(kFALSE),
ced249e6 113 fGeometryFromCDB(kFALSE),
4539539b 114 fGeometryFileName(""),
115 fTriggerDescriptor(""),
b60e0f5e 116 fRunLoader(0x0)
fe4da5cc 117{
118 //
119 // Constructor for the main processor.
120 // Creates the geometry
121 // Creates the list of Detectors.
122 // Creates the list of particles.
123 //
e2afb3b6 124
fe4da5cc 125 gAlice = this;
65fb704d 126
127 // Set random number generator
e2afb3b6 128 gRandom = fRandom;
2ab0c725 129
130 if (gSystem->Getenv("CONFIG_SEED")) {
e2afb3b6 131 gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED"))));
2ab0c725 132 }
e2afb3b6 133
134 // Add to list of browsable
fe4da5cc 135 gROOT->GetListOfBrowsables()->Add(this,name);
fe4da5cc 136
fe4da5cc 137 // Create default mag field
138 SetField();
e2afb3b6 139
fe4da5cc 140}
141
aee8290b 142
e2afb3b6 143//_______________________________________________________________________
fe4da5cc 144AliRun::~AliRun()
145{
146 //
2ab0c725 147 // Default AliRun destructor
fe4da5cc 148 //
88cb7938 149 gROOT->GetListOfBrowsables()->Remove(this);
150
151 if (fRunLoader)
152 {
153 TFolder* evfold = fRunLoader->GetEventFolder();
154 TFolder* modfold = dynamic_cast<TFolder*>(evfold->FindObjectAny(AliConfig::GetModulesFolderName()));
155 TIter next(fModules);
156 AliModule *mod;
157 while((mod = (AliModule*)next()))
158 {
159 modfold->Remove(mod);
160 }
161 }
5d12ce38 162
163
fe4da5cc 164 delete fField;
5d12ce38 165 delete fMCApp;
f5bc1485 166 delete gMC; gMC=0;
fe4da5cc 167 delete fLego;
8494b010 168 if (fModules) {
169 fModules->Delete();
170 delete fModules;
fe4da5cc 171 }
88cb7938 172
fe4da5cc 173}
174
e2afb3b6 175//_______________________________________________________________________
5d12ce38 176void AliRun::ResetHits()
fe4da5cc 177{
5d12ce38 178 fMCApp->ResetHits();
fe4da5cc 179}
180
e2afb3b6 181//_______________________________________________________________________
5d12ce38 182AliGenerator* AliRun::Generator() const
fe4da5cc 183{
5d12ce38 184 return fMCApp->Generator();
fe4da5cc 185}
186
e2afb3b6 187//_______________________________________________________________________
d8408e76 188void AliRun::SetField(AliMagF* magField)
189{
2057aecb 190 //
191 // Set Magnetic Field Map
192 //
193 fField = magField;
194 fField->ReadField();
d8408e76 195}
196
4a9de4af 197//_______________________________________________________________________
198void AliRun::SetRootGeometry(Bool_t flag)
199{
200// Instruct application that the geometry is to be retreived from a root file.
201 fIsRootGeometry = flag;
e8572077 202 if (flag && gMC) gMC->SetRootGeometry();
4a9de4af 203}
ced249e6 204
205//_______________________________________________________________________
206void AliRun::SetGeometryFromCDB()
207{
208 // Set the loading of geometry from cdb instead of creating it
209 // A default CDB storage needs to be set before this method is called
3d45e923 210 if(AliCDBManager::Instance()->IsDefaultStorageSet() &&
211 AliCDBManager::Instance()->GetRun() >= 0){
ced249e6 212 SetRootGeometry();
213 fGeometryFromCDB = kTRUE;
214 }else{
215 AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
216 AliError("Loading of geometry from CDB ignored. First set a default CDB storage!");
217 AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
218 }
219}
220
e2afb3b6 221//_______________________________________________________________________
fe4da5cc 222void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
07c4aae4 223 Float_t maxField, const char* filename)
fe4da5cc 224{
225 //
226 // Set magnetic field parameters
227 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
228 // version Magnetic field map version (only 1 active now)
229 // scale Scale factor for the magnetic field
230 // maxField Maximum value for the magnetic field
231
232 //
233 // --- Sanity check on mag field flags
fe4da5cc 234 if(fField) delete fField;
235 if(version==1) {
d8408e76 236 fField = new AliMagFC("Map1"," ",type,scale,maxField);
f1b9d7c3 237 } else if(version<=2) {
d8408e76 238 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
fe4da5cc 239 fField->ReadField();
f1b9d7c3 240 } else if(version==3) {
d8408e76 241 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
f1b9d7c3 242 fField->ReadField();
fe4da5cc 243 } else {
21bf7095 244 AliWarning(Form("Invalid map %d",version));
fe4da5cc 245 }
246}
88cb7938 247
248//_____________________________________________________________________________
249
250void AliRun::InitLoaders()
251{
252 //creates list of getters
21bf7095 253 AliDebug(1, "");
88cb7938 254 TIter next(fModules);
255 AliModule *mod;
256 while((mod = (AliModule*)next()))
257 {
1d6fbf6e 258 mod->SetRunLoader(fRunLoader);
88cb7938 259 AliDetector *det = dynamic_cast<AliDetector*>(mod);
260 if (det)
261 {
21bf7095 262 AliDebug(2, Form("Adding %s", det->GetName()));
88cb7938 263 fRunLoader->AddLoader(det);
264 }
265 }
21bf7095 266 AliDebug(1, "Done");
88cb7938 267}
268//_____________________________________________________________________________
269
fe4da5cc 270void AliRun::FinishRun()
271{
272 //
273 // Called at the end of the run.
274 //
07d55def 275
88cb7938 276 if(fLego)
277 {
21bf7095 278 AliDebug(1, "Finish Lego");
7dd2cbe4 279 AliRunLoader::GetRunLoader()->CdGAFile();
88cb7938 280 fLego->FinishRun();
281 }
8e70f139 282
fe4da5cc 283 // Clean detector information
8494b010 284 TIter next(fModules);
285 AliModule *detector;
e2afb3b6 286 while((detector = dynamic_cast<AliModule*>(next()))) {
21bf7095 287 AliDebug(2, Form("%s->FinishRun()", detector->GetName()));
fe4da5cc 288 detector->FinishRun();
289 }
290
7dd2cbe4 291 AliDebug(1, "AliRunLoader::GetRunLoader()->WriteHeader(OVERWRITE)");
292 AliRunLoader::GetRunLoader()->WriteHeader("OVERWRITE");
682a4a95 293
88cb7938 294 // Write AliRun info and all detectors parameters
7dd2cbe4 295 AliRunLoader::GetRunLoader()->CdGAFile();
88cb7938 296 Write(0,TObject::kOverwrite);//write AliRun
7dd2cbe4 297 AliRunLoader::GetRunLoader()->Write(0,TObject::kOverwrite);//write RunLoader itself
88cb7938 298
07d55def 299 if(fMCApp) fMCApp->FinishRun();
7dd2cbe4 300 AliRunLoader::GetRunLoader()->Synchronize();
fe4da5cc 301}
302
eb1b8d29 303//_______________________________________________________________________
304void AliRun::Announce() const
305{
306 //
37d06d5b 307 // Announce the current version of AliRoot
308 //
309 printf("%70s",
310 "****************************************************************\n");
311 printf("%6s","*");printf("%64s","*\n");
312
313 printf("%6s","*");
88cb7938 314 printf(" You are running AliRoot version NewIO\n");
37d06d5b 315
316 printf("%6s","*");
5960f18d 317 printf(" The SVN version for the current program is $Id$\n");
37d06d5b 318
319 printf("%6s","*");printf("%64s","*\n");
320 printf("%70s",
321 "****************************************************************\n");
eb1b8d29 322}
323
e2afb3b6 324//_______________________________________________________________________
94de3818 325AliModule *AliRun::GetModule(const char *name) const
fe4da5cc 326{
327 //
328 // Return pointer to detector from name
329 //
e2afb3b6 330 return dynamic_cast<AliModule*>(fModules->FindObject(name));
fe4da5cc 331}
332
e2afb3b6 333//_______________________________________________________________________
94de3818 334AliDetector *AliRun::GetDetector(const char *name) const
a68348e9 335{
336 //
337 // Return pointer to detector from name
338 //
e2afb3b6 339 return dynamic_cast<AliDetector*>(fModules->FindObject(name));
a68348e9 340}
341
e2afb3b6 342//_______________________________________________________________________
94de3818 343Int_t AliRun::GetModuleID(const char *name) const
fe4da5cc 344{
345 //
346 // Return galice internal detector identifier from name
347 //
23370b7a 348 Int_t i=-1;
349 TObject *mod=fModules->FindObject(name);
350 if(mod) i=fModules->IndexOf(mod);
351 return i;
fe4da5cc 352}
353
e2afb3b6 354//_______________________________________________________________________
fe4da5cc 355Int_t AliRun::GetEvent(Int_t event)
356{
88cb7938 357//
358// Reloads data containers in folders # event
359// Set branch addresses
360//
361 if (fRunLoader == 0x0)
362 {
21bf7095 363 AliError("RunLoader is not set. Can not load data.");
88cb7938 364 return -1;
365 }
366/*****************************************/
367/**** P R E R E L O A D I N G ****/
368/*****************************************/
369// Reset existing structures
5d12ce38 370 fMCApp->ResetHits();
371 fMCApp->ResetTrackReferences();
fe4da5cc 372 ResetDigits();
2ab0c725 373 ResetSDigits();
50a6540a 374
88cb7938 375/*****************************************/
376/**** R E L O A D ****/
377/*****************************************/
aab9c8d5 378
7dd2cbe4 379 AliRunLoader::GetRunLoader()->GetEvent(event);
b9d0a01d 380
88cb7938 381/*****************************************/
382/**** P O S T R E L O A D I N G ****/
383/*****************************************/
82711e7a 384
fe4da5cc 385 // Set Trees branch addresses
8494b010 386 TIter next(fModules);
07d55def 387 AliDetector *detector;
388 while((detector = dynamic_cast<AliDetector*>(next())))
88cb7938 389 {
390 detector->SetTreeAddress();
391 }
392
7dd2cbe4 393 return AliRunLoader::GetRunLoader()->GetHeader()->GetNtrack();
fe4da5cc 394}
395
e2afb3b6 396//_______________________________________________________________________
397void AliRun::SetBaseFile(const char *filename)
2ab0c725 398{
39de14fb 399 fBaseFileName = filename;
2ab0c725 400}
401
e2afb3b6 402//_______________________________________________________________________
b9d0a01d 403void AliRun::ResetDigits()
fe4da5cc 404{
405 //
b9d0a01d 406 // Reset all Detectors digits
fe4da5cc 407 //
b9d0a01d 408 TIter next(fModules);
409 AliModule *detector;
e2afb3b6 410 while((detector = dynamic_cast<AliModule*>(next()))) {
b9d0a01d 411 detector->ResetDigits();
412 }
413}
414
e2afb3b6 415//_______________________________________________________________________
b9d0a01d 416void AliRun::ResetSDigits()
417{
dffd31ef 418 //
b9d0a01d 419 // Reset all Detectors digits
9e1a0ddb 420 //
b9d0a01d 421 TIter next(fModules);
422 AliModule *detector;
e2afb3b6 423 while((detector = dynamic_cast<AliModule*>(next()))) {
b9d0a01d 424 detector->ResetSDigits();
425 }
426}
dffd31ef 427
2b22f272 428
e2afb3b6 429//_______________________________________________________________________
b9d0a01d 430void AliRun::InitMC(const char *setup)
2ab0c725 431{
432 //
5d12ce38 433 // Initialize ALICE Simulation run
2ab0c725 434 //
124253ee 435
436 static Bool_t initDone=kFALSE;
437
37d06d5b 438 Announce();
439
124253ee 440 if(initDone) {
441 AliError("AliRun already initialised! Check your logic!");
b9d0a01d 442 return;
124253ee 443 } else initDone=kTRUE;
b9d0a01d 444
67d736ee 445 if (!fMCApp)
446 fMCApp=new AliMC(GetName(),GetTitle());
5d12ce38 447
b9d0a01d 448 gROOT->LoadMacro(setup);
449 gInterpreter->ProcessLine(fConfigFunction.Data());
fe4da5cc 450
3d45e923 451 if(AliCDBManager::Instance()->GetRun() >= 0) {
452 SetRunNumber(AliCDBManager::Instance()->GetRun());
453 } else {
454 AliWarning("Run number not initialized!!");
455 }
b3276c04 456
7dd2cbe4 457 AliRunLoader::GetRunLoader()->CdGAFile();
07d55def 458
7dd2cbe4 459 AliPDG::AddParticlesToPdgDataBase();
aab9c8d5 460
5d12ce38 461 fMCApp->Init();
b9d0a01d 462
504b172d 463 //Must be here because some MCs (G4) adds detectors here and not in Config.C
464 InitLoaders();
7dd2cbe4 465 AliRunLoader::GetRunLoader()->MakeTree("E");
504b172d 466 if (fLego == 0x0)
467 {
7dd2cbe4 468 AliRunLoader::GetRunLoader()->LoadKinematics("RECREATE");
469 AliRunLoader::GetRunLoader()->LoadTrackRefs("RECREATE");
470 AliRunLoader::GetRunLoader()->LoadHits("all","RECREATE");
504b172d 471 }
b9d0a01d 472 //
473 // Save stuff at the beginning of the file to avoid file corruption
7dd2cbe4 474 AliRunLoader::GetRunLoader()->CdGAFile();
b9d0a01d 475 Write();
88cb7938 476 fEventNrInRun = -1; //important - we start Begin event from increasing current number in run
fe4da5cc 477}
478
e2afb3b6 479//_______________________________________________________________________
2ab0c725 480void AliRun::Hits2Digits(const char *selected)
481{
9e1a0ddb 482
d47c658f 483 // Convert Hits to sumable digits
484 //
7dd2cbe4 485 for (Int_t nevent=0; nevent<AliRunLoader::GetRunLoader()->TreeE()->GetEntries(); nevent++) {
9e1a0ddb 486 GetEvent(nevent);
9e1a0ddb 487 Hits2SDigits(selected);
488 SDigits2Digits(selected);
489 }
2ab0c725 490}
491
d47c658f 492
e2afb3b6 493//_______________________________________________________________________
2ab0c725 494
d47c658f 495void AliRun::Tree2Tree(Option_t *option, const char *selected)
2ab0c725 496{
497 //
d47c658f 498 // Function to transform the content of
499 //
500 // - TreeH to TreeS (option "S")
501 // - TreeS to TreeD (option "D")
502 // - TreeD to TreeR (option "R")
503 //
504 // If multiple options are specified ("SDR"), transformation will be done in sequence for
505 // selected detector and for all detectors if none is selected (detector string
506 // can contain blank separated list of detector names).
2ab0c725 507
2ab0c725 508
5cf7bbad 509 const char *oS = strstr(option,"S");
510 const char *oD = strstr(option,"D");
511 const char *oR = strstr(option,"R");
2ab0c725 512
9e1a0ddb 513 TObjArray *detectors = Detectors();
2ab0c725 514
515 TIter next(detectors);
516
d47c658f 517 AliDetector *detector = 0;
2ab0c725 518
88cb7938 519 while((detector = dynamic_cast<AliDetector*>(next()))) {
d47c658f 520 if (selected)
2ab0c725 521 if (strcmp(detector->GetName(),selected)) continue;
88cb7938 522 if (detector->IsActive())
523 {
524
525 AliLoader* loader = detector->GetLoader();
526 if (loader == 0x0) continue;
527
528 if (oS)
529 {
21bf7095 530 AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName()));
88cb7938 531 loader->LoadHits("read");
532 if (loader->TreeS() == 0x0) loader->MakeTree("S");
533 detector->MakeBranch(option);
534 detector->SetTreeAddress();
535 detector->Hits2SDigits();
536 loader->UnloadHits();
537 loader->UnloadSDigits();
538 }
539 if (oD)
540 {
21bf7095 541 AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName()));
88cb7938 542 loader->LoadSDigits("read");
543 if (loader->TreeD() == 0x0) loader->MakeTree("D");
544 detector->MakeBranch(option);
545 detector->SetTreeAddress();
546 detector->SDigits2Digits();
547 loader->UnloadSDigits();
548 loader->UnloadDigits();
549 }
550 if (oR)
551 {
21bf7095 552 AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName()));
88cb7938 553 loader->LoadDigits("read");
554 if (loader->TreeR() == 0x0) loader->MakeTree("R");
555 detector->MakeBranch(option);
556 detector->SetTreeAddress();
557 detector->Digits2Reco();
558 loader->UnloadDigits();
559 loader->UnloadRecPoints();
560
561 }
562 }
563 }
2ab0c725 564}
565
e2afb3b6 566//_______________________________________________________________________
0a520a66 567void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
568 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
93dccc77 569 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener, Int_t nev)
fe4da5cc 570{
571 //
572 // Generates lego plots of:
573 // - radiation length map phi vs theta
574 // - radiation length map phi vs eta
575 // - interaction length map
576 // - g/cm2 length map
577 //
578 // ntheta bins in theta, eta
579 // themin minimum angle in theta (degrees)
580 // themax maximum angle in theta (degrees)
581 // nphi bins in phi
582 // phimin minimum angle in phi (degrees)
583 // phimax maximum angle in phi (degrees)
584 // rmin minimum radius
585 // rmax maximum radius
586 //
587 //
588 // The number of events generated = ntheta*nphi
589 // run input parameters in macro setup (default="Config.C")
590 //
591 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
592 //Begin_Html
593 /*
1439f98e 594 <img src="picts/AliRunLego1.gif">
fe4da5cc 595 */
596 //End_Html
597 //Begin_Html
598 /*
1439f98e 599 <img src="picts/AliRunLego2.gif">
fe4da5cc 600 */
601 //End_Html
602 //Begin_Html
603 /*
1439f98e 604 <img src="picts/AliRunLego3.gif">
fe4da5cc 605 */
606 //End_Html
607 //
93dccc77 608 // Number of events
609 if (nev == -1) nev = nc1 * nc2;
610
fe4da5cc 611 // check if initialisation has been done
2cacde38 612 // If runloader has been initialized, set the number of events per file to nc1 * nc2
93dccc77 613
0a520a66 614 // Set new generator
615 if (!gener) gener = new AliLegoGenerator();
0a520a66 616 //
617 // Configure Generator
07d55def 618
0a520a66 619 gener->SetRadiusRange(rmin, rmax);
620 gener->SetZMax(zmax);
621 gener->SetCoor1Range(nc1, c1min, c1max);
622 gener->SetCoor2Range(nc2, c2min, c2max);
623
624
b13db077 625 //Create Lego object
0a520a66 626 fLego = new AliLego("lego",gener);
b13db077 627
124253ee 628 InitMC(setup);
504b172d 629 //Save current generator
630
631 AliGenerator *gen=fMCApp->Generator();
632 fMCApp->ResetGenerator(gener);
dffd31ef 633 //Prepare MC for Lego Run
634 gMC->InitLego();
635
b13db077 636 //Run Lego Object
0a520a66 637
07d55def 638
93dccc77 639 if (fRunLoader) fRunLoader->SetNumberOfEventsPerFile(nev);
93dccc77 640 gMC->ProcessRun(nev);
fe4da5cc 641
fe4da5cc 642 // End of this run, close files
80762cb1 643 FinishRun();
0a520a66 644 // Restore current generator
5d12ce38 645 fMCApp->ResetGenerator(gen);
838edcaf 646 // Delete Lego Object
647 delete fLego; fLego=0;
fe4da5cc 648}
649
e2afb3b6 650//_______________________________________________________________________
94de3818 651void AliRun::SetConfigFunction(const char * config)
652{
653 //
654 // Set the signature of the function contained in Config.C to configure
655 // the run
656 //
657 fConfigFunction=config;
658}
659
b9d0a01d 660//
661// MC Application
662//
663
e2afb3b6 664//_______________________________________________________________________
b9d0a01d 665void AliRun::Field(const Double_t* x, Double_t *b) const
666{
2057aecb 667 //
668 // Return the value of the magnetic field
669 //
07d55def 670
2057aecb 671 Float_t xfloat[3];
672 for (Int_t i=0; i<3; i++) xfloat[i] = x[i];
673
674 if (Field()) {
07d55def 675
2057aecb 676 Float_t bfloat[3];
677 Field()->Field(xfloat,bfloat);
678 for (Int_t j=0; j<3; j++) b[j] = bfloat[j];
679 }
680 else {
21bf7095 681 AliError("No mag field defined!");
2057aecb 682 b[0]=b[1]=b[2]=0.;
683 }
07d55def 684
685
b9d0a01d 686}
687
688//
689// End of MC Application
690//
691
e2afb3b6 692//_______________________________________________________________________
fe4da5cc 693void AliRun::Streamer(TBuffer &R__b)
694{
eef4b160 695 // Stream an object of class AliRun.
2ab0c725 696
7e90ff59 697 if (R__b.IsReading()) {
698 if (!gAlice) gAlice = this;
7e90ff59 699 AliRun::Class()->ReadBuffer(R__b, this);
7e90ff59 700 gROOT->GetListOfBrowsables()->Add(this,"Run");
eef4b160 701
7e90ff59 702 gRandom = fRandom;
703 } else {
eef4b160 704 AliRun::Class()->WriteBuffer(R__b, this);
705 }
2ab0c725 706}
e2afb3b6 707//_______________________________________________________________________
b9d0a01d 708
27f087a9 709void AliRun::SetGenEventHeader(AliGenEventHeader* header)
710{
7dd2cbe4 711 AliRunLoader::GetRunLoader()->GetHeader()->SetGenEventHeader(header);
27f087a9 712}
7dd2cbe4 713
714
504b172d 715//_______________________________________________________________________
0592d1ca 716
88cb7938 717Int_t AliRun::GetEvNumber() const
718{
719//Returns number of current event
720 if (fRunLoader == 0x0)
721 {
21bf7095 722 AliError("RunLoader is not set. Can not load data.");
88cb7938 723 return -1;
724 }
0592d1ca 725
88cb7938 726 return fRunLoader->GetEventNumber();
0592d1ca 727}
504b172d 728//_______________________________________________________________________
b9d0a01d 729
88cb7938 730void AliRun::SetRunLoader(AliRunLoader* rloader)
0592d1ca 731{
2057aecb 732 //
733 // Set the loader of the run
734 //
88cb7938 735 fRunLoader = rloader;
736 if (fRunLoader == 0x0) return;
737
738 TString evfoldname;
739 TFolder* evfold = fRunLoader->GetEventFolder();
740 if (evfold) evfoldname = evfold->GetName();
21bf7095 741 else AliWarning("Did not get Event Folder from Run Loader");
88cb7938 742
743 if ( fRunLoader->GetAliRun() )
744 {//if alrun already exists in folder
745 if (fRunLoader->GetAliRun() != this )
746 {//and is different than this - crash
21bf7095 747 AliFatal("AliRun is already in Folder and it is not this object");
88cb7938 748 return;//pro forma
749 }//else do nothing
750 }
751 else
752 {
753 evfold->Add(this);//Post this AliRun to Folder
754 }
755
756 TIter next(fModules);
757 AliModule *module;
758 while((module = (AliModule*)next()))
759 {
760 if (evfold) AliConfig::Instance()->Add(module,evfoldname);
1d6fbf6e 761 module->SetRunLoader(fRunLoader);
88cb7938 762 AliDetector* detector = dynamic_cast<AliDetector*>(module);
763 if (detector)
764 {
765 AliLoader* loader = fRunLoader->GetLoader(detector);
766 if (loader == 0x0)
767 {
21bf7095 768 AliError(Form("Can not get loader for detector %s", detector->GetName()));
88cb7938 769 }
770 else
771 {
21bf7095 772 AliDebug(1, Form("Setting loader for detector %s", detector->GetName()));
88cb7938 773 detector->SetLoader(loader);
774 }
0592d1ca 775 }
88cb7938 776 }
0592d1ca 777}
778
88cb7938 779void AliRun::AddModule(AliModule* mod)
7a16e9cc 780{
2057aecb 781 //
782 // Add a module to the module list
783 //
88cb7938 784 if (mod == 0x0) return;
785 if (strlen(mod->GetName()) == 0) return;
786 if (GetModuleID(mod->GetName()) >= 0) return;
787
21bf7095 788 AliDebug(1, mod->GetName());
88cb7938 789 if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod);
790 else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName());
7a16e9cc 791
88cb7938 792 Modules()->Add(mod);
67d736ee 793
794 fNdets++;
7a16e9cc 795}
21bf7095 796
4d81e5e7 797//_____________________________________________________________________________
798/*inline*/ Bool_t AliRun::IsFileAccessible(const char* fnam, EAccessMode mode)
799{ return !gSystem->AccessPathName(fnam,mode);}
800
801//______________________________________________________
802/*inline*/ Bool_t AliRun::IsFileAccessible(Char_t* name,EAccessMode mode)
803{
804 TString str = name; gSystem->ExpandPathName(str);
805 return !gSystem->AccessPathName(str.Data(),mode);
806}