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