]>
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> |
c93255fe | 49 | #include <TTree.h> |
5d12ce38 | 50 | // |
21bf7095 | 51 | #include "AliLog.h" |
98490ea9 | 52 | #include "AliDetector.h" |
98490ea9 | 53 | #include "AliHeader.h" |
5d12ce38 | 54 | #include "AliMC.h" |
141f90e3 | 55 | #include "AliPDG.h" |
98490ea9 | 56 | #include "AliRun.h" |
57 | #include "AliStack.h" | |
b3276c04 | 58 | #include "AliCDBManager.h" |
995ad051 | 59 | #include "AliAlignObj.h" |
3e2e3ece | 60 | #include "AliSimulation.h" |
61 | #include "AliLego.h" | |
fe4da5cc | 62 | |
fe4da5cc | 63 | AliRun *gAlice; |
64 | ||
fe4da5cc | 65 | ClassImp(AliRun) |
66 | ||
e2afb3b6 | 67 | //_______________________________________________________________________ |
68 | AliRun::AliRun(): | |
33c3c91a | 69 | // fRun(-1), |
3e2e3ece | 70 | fEventNrInRun(-1), |
e2afb3b6 | 71 | fModules(0), |
5d12ce38 | 72 | fMCApp(0), |
e2afb3b6 | 73 | fNdets(0), |
4539539b | 74 | fConfigFunction(""), |
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 | 87 | AliRun::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();"), |
fe12e09c | 94 | fBaseFileName(""), |
b60e0f5e | 95 | fRunLoader(0x0) |
fe4da5cc | 96 | { |
97 | // | |
98 | // Constructor for the main processor. | |
99 | // Creates the geometry | |
100 | // Creates the list of Detectors. | |
101 | // Creates the list of particles. | |
102 | // | |
e2afb3b6 | 103 | |
fe4da5cc | 104 | gAlice = this; |
65fb704d | 105 | |
106 | // Set random number generator | |
26eac604 | 107 | gRandom = new TRandom3(); |
2ab0c725 | 108 | |
109 | if (gSystem->Getenv("CONFIG_SEED")) { | |
e2afb3b6 | 110 | gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED")))); |
2ab0c725 | 111 | } |
e2afb3b6 | 112 | |
113 | // Add to list of browsable | |
fe4da5cc | 114 | gROOT->GetListOfBrowsables()->Add(this,name); |
fe4da5cc | 115 | |
fe4da5cc | 116 | } |
117 | ||
e2afb3b6 | 118 | //_______________________________________________________________________ |
fe4da5cc | 119 | AliRun::~AliRun() |
120 | { | |
121 | // | |
2ab0c725 | 122 | // Default AliRun destructor |
fe4da5cc | 123 | // |
88cb7938 | 124 | gROOT->GetListOfBrowsables()->Remove(this); |
125 | ||
126 | if (fRunLoader) | |
127 | { | |
128 | TFolder* evfold = fRunLoader->GetEventFolder(); | |
129 | TFolder* modfold = dynamic_cast<TFolder*>(evfold->FindObjectAny(AliConfig::GetModulesFolderName())); | |
7275b148 | 130 | if(!modfold) AliFatal(Form("Folder %s not found\n",AliConfig::GetModulesFolderName().Data())); |
88cb7938 | 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 | 149 | void 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 | //_______________________________________________________________________ |
169 | void 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 | 190 | AliModule *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 | 199 | AliDetector *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 | 208 | Int_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 | 220 | Int_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 | //_______________________________________________________________________ |
262 | void AliRun::SetBaseFile(const char *filename) | |
2ab0c725 | 263 | { |
39de14fb | 264 | fBaseFileName = filename; |
2ab0c725 | 265 | } |
266 | ||
fe4da5cc | 267 | |
e2afb3b6 | 268 | //_______________________________________________________________________ |
2ab0c725 | 269 | void 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 | 283 | void 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 | 356 | void 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"); |
26eac604 | 364 | gRandom = new TRandom3(); |
7e90ff59 | 365 | } else { |
eef4b160 | 366 | AliRun::Class()->WriteBuffer(R__b, this); |
367 | } | |
2ab0c725 | 368 | } |
b9d0a01d | 369 | |
28da60d3 | 370 | //_______________________________________________________________________ |
27f087a9 | 371 | void AliRun::SetGenEventHeader(AliGenEventHeader* header) |
372 | { | |
33c3c91a | 373 | AliRunLoader::Instance()->GetHeader()->SetGenEventHeader(header); |
27f087a9 | 374 | } |
7dd2cbe4 | 375 | |
376 | ||
504b172d | 377 | //_______________________________________________________________________ |
88cb7938 | 378 | Int_t AliRun::GetEvNumber() const |
379 | { | |
380 | //Returns number of current event | |
381 | if (fRunLoader == 0x0) | |
382 | { | |
21bf7095 | 383 | AliError("RunLoader is not set. Can not load data."); |
88cb7938 | 384 | return -1; |
385 | } | |
0592d1ca | 386 | |
88cb7938 | 387 | return fRunLoader->GetEventNumber(); |
0592d1ca | 388 | } |
b9d0a01d | 389 | |
28da60d3 | 390 | //_______________________________________________________________________ |
88cb7938 | 391 | void AliRun::SetRunLoader(AliRunLoader* rloader) |
0592d1ca | 392 | { |
2057aecb | 393 | // |
394 | // Set the loader of the run | |
395 | // | |
88cb7938 | 396 | fRunLoader = rloader; |
397 | if (fRunLoader == 0x0) return; | |
398 | ||
399 | TString evfoldname; | |
400 | TFolder* evfold = fRunLoader->GetEventFolder(); | |
401 | if (evfold) evfoldname = evfold->GetName(); | |
04a6d27f | 402 | else AliFatal("Did not get Event Folder from Run Loader"); |
88cb7938 | 403 | |
404 | if ( fRunLoader->GetAliRun() ) | |
405 | {//if alrun already exists in folder | |
406 | if (fRunLoader->GetAliRun() != this ) | |
407 | {//and is different than this - crash | |
21bf7095 | 408 | AliFatal("AliRun is already in Folder and it is not this object"); |
88cb7938 | 409 | return;//pro forma |
410 | }//else do nothing | |
411 | } | |
412 | else | |
413 | { | |
414 | evfold->Add(this);//Post this AliRun to Folder | |
415 | } | |
416 | ||
417 | TIter next(fModules); | |
418 | AliModule *module; | |
419 | while((module = (AliModule*)next())) | |
420 | { | |
421 | if (evfold) AliConfig::Instance()->Add(module,evfoldname); | |
1d6fbf6e | 422 | module->SetRunLoader(fRunLoader); |
88cb7938 | 423 | AliDetector* detector = dynamic_cast<AliDetector*>(module); |
424 | if (detector) | |
425 | { | |
426 | AliLoader* loader = fRunLoader->GetLoader(detector); | |
427 | if (loader == 0x0) | |
428 | { | |
21bf7095 | 429 | AliError(Form("Can not get loader for detector %s", detector->GetName())); |
88cb7938 | 430 | } |
431 | else | |
432 | { | |
21bf7095 | 433 | AliDebug(1, Form("Setting loader for detector %s", detector->GetName())); |
88cb7938 | 434 | detector->SetLoader(loader); |
435 | } | |
0592d1ca | 436 | } |
88cb7938 | 437 | } |
0592d1ca | 438 | } |
439 | ||
28da60d3 | 440 | //_______________________________________________________________________ |
88cb7938 | 441 | void AliRun::AddModule(AliModule* mod) |
7a16e9cc | 442 | { |
2057aecb | 443 | // |
444 | // Add a module to the module list | |
445 | // | |
88cb7938 | 446 | if (mod == 0x0) return; |
447 | if (strlen(mod->GetName()) == 0) return; | |
448 | if (GetModuleID(mod->GetName()) >= 0) return; | |
449 | ||
21bf7095 | 450 | AliDebug(1, mod->GetName()); |
88cb7938 | 451 | if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod); |
452 | else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName()); | |
7a16e9cc | 453 | |
88cb7938 | 454 | Modules()->Add(mod); |
67d736ee | 455 | |
456 | fNdets++; | |
7a16e9cc | 457 | } |
21bf7095 | 458 |