]>
Commit | Line | Data |
---|---|---|
88cb7938 | 1 | #include "AliRunLoader.h" |
2 | //_____________________________________ | |
3 | ///////////////////////////////////////////////////////////////////////////////////// | |
4 | // | |
5 | // class AliRunLoader | |
6 | // | |
7 | //This class aims to be the only one interface for manging data | |
8 | //It stores Loaders for all modules which knows the filenames | |
9 | //of the data files to be stored. | |
10 | //It aims to substitude AliRun in automatic maging of data positioning | |
11 | //thus there won't be necessity of loading gAlice from file in order to | |
12 | //get fast ccess to the data | |
13 | // | |
14 | //logical place for putting the Loader specific to the given detector is detector itself | |
15 | // but, to load detector one need to load gAlice, and by the way all other detectors | |
f2a509af | 16 | // with their geometries and so on. |
88cb7938 | 17 | // So, if one need to open TPC clusters there is no principal need to read everything |
18 | // | |
19 | // When RunLoader is read from the file it does not connect to the folder structure | |
20 | // it must be connected (mounted) manualy in the macro or class code. | |
21 | // Default event folder is defined by AliConfig::fgkDefaultEventFolderName | |
22 | // but can be mounted elsewhere. Usefull specially in merging, when more than session | |
23 | // needs to be loaded | |
24 | // | |
25 | ////////////////////////////////////////////////////////////////////////////////////// | |
26 | /**************************************************************************/ | |
27 | ||
28 | #include <TString.h> | |
29 | #include <TFolder.h> | |
30 | #include <TFile.h> | |
31 | #include <TTree.h> | |
32 | #include <TROOT.h> | |
33 | #include <TBranch.h> | |
34 | #include <TGeometry.h> | |
35 | #include <TTask.h> | |
36 | #include <TError.h> | |
37 | ||
38 | #include "AliRun.h" | |
39 | #include "AliConfig.h" | |
40 | #include "AliLoader.h" | |
41 | #include "AliHeader.h" | |
42 | #include "AliStack.h" | |
43 | #include "TObjArray.h" | |
44 | #include "AliDetector.h" | |
45 | #include "AliRunDigitizer.h" | |
46 | ||
47 | ClassImp(AliRunLoader) | |
48 | ||
49 | AliRunLoader* AliRunLoader::fgRunLoader = 0x0; | |
50 | ||
51 | const TString AliRunLoader::fgkRunLoaderName("RunLoader"); | |
52 | ||
53 | const TString AliRunLoader::fgkHeaderBranchName("Header"); | |
54 | const TString AliRunLoader::fgkHeaderContainerName("TE"); | |
55 | const TString AliRunLoader::fgkKineContainerName("TreeK"); | |
56 | const TString AliRunLoader::fgkTrackRefsContainerName("TreeTR"); | |
57 | const TString AliRunLoader::fgkKineBranchName("Particles"); | |
58 | const TString AliRunLoader::fgkDefaultKineFileName("Kinematics.root"); | |
59 | const TString AliRunLoader::fgkDefaultTrackRefsFileName("TrackRefs.root"); | |
60 | const TString AliRunLoader::fgkGAliceName("gAlice"); | |
61 | /**************************************************************************/ | |
62 | ||
63 | AliRunLoader::AliRunLoader(): | |
64 | fLoaders(0x0), | |
65 | fEventFolder(0x0), | |
66 | fCurrentEvent(0), | |
67 | fGAFile(0x0), | |
68 | fHeader(0x0), | |
69 | fStack(0x0), | |
70 | fKineDataLoader(0x0), | |
71 | fTrackRefsDataLoader(0x0), | |
72 | fNEventsPerFile(1), | |
73 | fUnixDirName(".") | |
74 | { | |
75 | AliConfig::Instance();//force to build the folder structure | |
76 | } | |
77 | /**************************************************************************/ | |
78 | ||
79 | AliRunLoader::AliRunLoader(const char* eventfoldername): | |
80 | TNamed(fgkRunLoaderName,fgkRunLoaderName), | |
81 | fLoaders(new TObjArray()), | |
82 | fEventFolder(0x0), | |
83 | fCurrentEvent(0), | |
84 | fGAFile(0x0), | |
85 | fHeader(0x0), | |
86 | fStack(0x0), | |
87 | fKineDataLoader(new AliDataLoader(fgkDefaultKineFileName,fgkKineContainerName,"Kinematics")), | |
88 | fTrackRefsDataLoader(new AliDataLoader(fgkDefaultTrackRefsFileName,fgkTrackRefsContainerName,"Track References")), | |
89 | fNEventsPerFile(1), | |
90 | fUnixDirName(".") | |
91 | { | |
92 | //ctor | |
93 | SetEventFolderName(eventfoldername); | |
94 | } | |
95 | /**************************************************************************/ | |
96 | ||
97 | AliRunLoader::~AliRunLoader() | |
98 | { | |
f2a509af | 99 | //dtor |
88cb7938 | 100 | UnloadHeader(); |
101 | UnloadgAlice(); | |
102 | ||
103 | if(fLoaders) { | |
104 | fLoaders->SetOwner(); | |
105 | delete fLoaders; | |
106 | } | |
107 | ||
108 | delete fKineDataLoader; | |
109 | delete fTrackRefsDataLoader; | |
110 | ||
111 | ||
112 | RemoveEventFolder(); | |
113 | ||
114 | //fEventFolder is deleted by the way of removing - TopAliceFolder owns it | |
115 | delete fHeader; | |
116 | delete fStack; | |
117 | delete fGAFile; | |
118 | } | |
119 | /**************************************************************************/ | |
120 | ||
121 | AliRunLoader::AliRunLoader(TFolder* topfolder):TNamed(fgkRunLoaderName,fgkRunLoaderName) | |
122 | { | |
f2a509af | 123 | //ctor |
88cb7938 | 124 | if(topfolder == 0x0) |
125 | { | |
126 | Fatal("AliRunLoader(TFolder*)","Parameter is NULL"); | |
127 | return; | |
128 | } | |
129 | fEventFolder = topfolder; | |
130 | ||
131 | TObject* obj = fEventFolder->FindObject(fgkRunLoaderName); | |
132 | if (obj) | |
133 | { //if it is, then sth. is going wrong... exits aliroot session | |
134 | Fatal("AliRunLoader(const char*)", | |
135 | "In Event Folder Named %s object named %s already exists. I am confused ...", | |
136 | fEventFolder->GetName(),fgkRunLoaderName.Data()); | |
137 | return;//never reached | |
138 | } | |
139 | ||
140 | fLoaders = new TObjArray(); | |
141 | fEventFolder->Add(this);//put myself to the folder to accessible for all | |
142 | ||
143 | } | |
144 | /**************************************************************************/ | |
145 | ||
146 | Int_t AliRunLoader::GetEvent(Int_t evno) | |
147 | { | |
148 | //Gets event number evno | |
149 | //Reloads all data properly | |
150 | if (fCurrentEvent == evno) return 0; | |
151 | ||
152 | if (evno < 0) | |
153 | { | |
154 | Error("GetEvent","Can not give the event with negative number"); | |
155 | return 4; | |
156 | } | |
157 | ||
158 | if (evno >= GetNumberOfEvents()) | |
159 | { | |
160 | Error("GetEvent","There is no event with number %d",evno); | |
161 | return 3; | |
162 | } | |
163 | ||
164 | if (GetDebug()) | |
165 | { | |
166 | Info("GetEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); | |
167 | Info("GetEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); | |
168 | Info("GetEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); | |
169 | Info("GetEvent"," GETTING EVENT %d",evno); | |
170 | Info("GetEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); | |
171 | Info("GetEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); | |
172 | Info("GetEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); | |
173 | } | |
174 | ||
175 | fCurrentEvent = evno; | |
176 | ||
177 | Int_t retval; | |
178 | ||
179 | //Reload header (If header was loaded) | |
180 | if (GetHeader()) | |
181 | { | |
182 | retval = TreeE()->GetEvent(fCurrentEvent); | |
183 | if ( retval == 0) | |
184 | { | |
185 | Error("GetEvent","Cannot find event: %d\n ",fCurrentEvent); | |
186 | return 5; | |
187 | } | |
188 | } | |
189 | //Reload stack (If header was loaded) | |
190 | if (TreeE()) fStack = GetHeader()->Stack(); | |
191 | //Set event folder in stack (it does not mean that we read kinematics from file) | |
192 | if (fStack) | |
193 | { | |
194 | fStack->SetEventFolderName(fEventFolder->GetName()); | |
195 | } | |
196 | else | |
197 | { | |
198 | Warning("GetEvent","Stack not found in header"); | |
199 | } | |
200 | ||
201 | retval = SetEvent(); | |
202 | if (retval) | |
203 | { | |
204 | Error("GetEvent","Error occured while setting event %d",evno); | |
205 | return 1; | |
206 | } | |
207 | ||
208 | //Post Track References | |
209 | retval = fTrackRefsDataLoader->GetEvent(); | |
210 | if (retval) | |
211 | { | |
212 | Error("GetEvent","Error occured while GetEvent for Track References. Event %d",evno); | |
213 | return 2; | |
214 | } | |
215 | ||
216 | //Read Kinematics if loaded | |
217 | fKineDataLoader->GetEvent(); | |
218 | if (retval) | |
219 | { | |
220 | Error("GetEvent","Error occured while GetEvent for Kinematics. Event %d",evno); | |
221 | return 2; | |
222 | } | |
223 | ||
224 | if (fStack && fKineDataLoader->GetBaseLoader(0)->IsLoaded()) fStack->GetEvent(); | |
225 | ||
226 | //Trigger data reloading in all loaders | |
227 | TIter next(fLoaders); | |
228 | AliLoader *loader; | |
229 | while((loader = (AliLoader*)next())) | |
230 | { | |
231 | retval = loader->GetEvent(); | |
232 | if (retval) | |
233 | { | |
234 | Error("GetEvent","Error occured while getting event for %s. Event %d.", | |
235 | loader->GetDetectorName().Data(), evno); | |
236 | return 3; | |
237 | } | |
238 | } | |
239 | ||
240 | SetDetectorAddresses(); | |
241 | ||
242 | return 0; | |
243 | } | |
244 | /**************************************************************************/ | |
245 | Int_t AliRunLoader::SetEvent() | |
246 | { | |
f2a509af | 247 | //if kinematics was loaded Cleans folder data |
248 | ||
88cb7938 | 249 | Int_t retval; |
250 | ||
251 | retval = fKineDataLoader->SetEvent(); | |
252 | if (retval) | |
253 | { | |
254 | Error("SetEvent","SetEvent for Kinamtics Data Loader retutned error."); | |
255 | return retval; | |
256 | } | |
257 | retval = fTrackRefsDataLoader->SetEvent(); | |
258 | if (retval) | |
259 | { | |
260 | Error("SetEvent","SetEvent for Track References Data Loader retutned error."); | |
261 | return retval; | |
262 | } | |
263 | ||
264 | TIter next(fLoaders); | |
265 | AliLoader *loader; | |
266 | while((loader = (AliLoader*)next())) | |
267 | { | |
268 | retval = loader->SetEvent(); | |
269 | if (retval) | |
270 | { | |
271 | Error("SetEvent","SetEvent for %s Data Loader retutned error.",loader->GetName()); | |
272 | return retval; | |
273 | } | |
274 | } | |
275 | ||
276 | return 0; | |
277 | } | |
278 | /**************************************************************************/ | |
279 | ||
280 | Int_t AliRunLoader::SetEventNumber(Int_t evno) | |
281 | { | |
282 | //cleans folders and sets the root dirs in files | |
283 | if (fCurrentEvent == evno) return 0; | |
284 | fCurrentEvent = evno; | |
285 | return SetEvent(); | |
286 | } | |
287 | ||
288 | /**************************************************************************/ | |
289 | AliRunLoader* AliRunLoader::Open | |
290 | (const char* filename, const char* eventfoldername, Option_t* option) | |
291 | { | |
292 | //Opens a desired file 'filename' | |
293 | //gets the the run-Loader and mounts it desired folder | |
294 | //returns the pointer to run Loader which can be further used for accessing data | |
295 | //in case of error returns NULL | |
296 | ||
297 | static const TString webaddress("http://alisoft.cern.ch/people/skowron/codedoc/split/index.html"); | |
298 | if (AliLoader::fgDebug) | |
299 | ::Info("AliRunLoader::Open", | |
300 | "\n\n\nNew I/O strcture: See more info:\n %s\n\n\n",webaddress.Data()); | |
301 | ||
302 | AliRunLoader* result = 0x0; | |
303 | ||
304 | /* ************************************************ */ | |
305 | /* Chceck if folder with given name already exists */ | |
306 | /* ************************************************ */ | |
307 | ||
308 | TObject* obj = AliConfig::Instance()->GetTopFolder()->FindObject(eventfoldername); | |
309 | if(obj) | |
310 | { | |
311 | TFolder* fold = dynamic_cast<TFolder*>(obj); | |
312 | if (fold == 0x0) | |
313 | { | |
314 | ::Error("AliRunLoader::Open","Such a obejct already exists in top alice folder and it is not a folder."); | |
315 | return 0x0; | |
316 | } | |
317 | ||
318 | //check if we can get RL from that folder | |
319 | result = AliRunLoader::GetRunLoader(eventfoldername); | |
320 | if (result == 0x0) | |
321 | { | |
322 | ::Error("AliRunLoader::Open", | |
323 | "Folder %s already exists, and can not find session there. Can not mount.",eventfoldername); | |
324 | return 0x0; | |
325 | } | |
326 | ||
327 | if (result->GetFileName().CompareTo(filename) != 0) | |
328 | { | |
329 | ::Error("AliRunLoader::Open","Other file is mounted in demanded folder. Can not mount."); | |
330 | return 0x0; | |
331 | } | |
332 | ||
333 | //check if now is demanded (re)creation | |
334 | if ( AliLoader::TestFileOption(option) == kFALSE) | |
335 | { | |
336 | ::Error("AliRunLoader::Open", | |
337 | "Session already exists in folder %s and this session option is %s. Unable to proceed.", | |
338 | eventfoldername,option); | |
339 | return 0x0; | |
340 | } | |
341 | ||
342 | //check if demanded option is update and existing one | |
343 | TString tmpstr(option); | |
344 | if ( (tmpstr.CompareTo("update",TString::kIgnoreCase) == 0) && | |
345 | (result->fGAFile->IsWritable() == kFALSE) ) | |
346 | { | |
347 | ::Error("AliRunLoader::Open", | |
348 | "Session already exists in folder %s and is not writable while this session option is %s. Unable to proceed.", | |
349 | eventfoldername,option); | |
350 | return 0x0; | |
351 | } | |
352 | ||
353 | ::Warning("AliRunLoader::Open","Session is already opened and mounted in demanded folder"); | |
354 | return result; | |
355 | } //end of checking in case of existance of object named identically that folder session is being opened | |
356 | ||
357 | ||
358 | TFile * gAliceFile = TFile::Open(filename,option);//open a file | |
359 | if (!gAliceFile) | |
360 | {//null pointer returned | |
361 | ::Error("AliRunLoader::Open","Can not open file %s.",filename); | |
362 | return 0x0; | |
363 | } | |
364 | ||
365 | if (gAliceFile->IsOpen() == kFALSE) | |
366 | {//pointer to valid object returned but file is not opened | |
367 | ::Error("AliRunLoader::Open","Can not open file %s.",filename); | |
368 | return 0x0; | |
369 | } | |
370 | ||
371 | //if file is "read" or "update" than we try to find AliRunLoader there - if not found cry and exit | |
372 | //else create new AliRunLoader | |
373 | if ( AliLoader::TestFileOption(option) ) | |
374 | { | |
375 | if (AliLoader::fgDebug) | |
376 | ::Info("AliRunLoader::Open","Reading RL from file"); | |
377 | ||
378 | result = dynamic_cast<AliRunLoader*>(gAliceFile->Get(fgkRunLoaderName));//get the run Loader from the file | |
379 | if (result == 0x0) | |
380 | {//didn't get | |
381 | ::Error("AliRunLoader::Open","Can not find run-Loader in file %s.",filename); | |
382 | delete gAliceFile;//close the file | |
383 | return 0x0; | |
384 | } | |
385 | Int_t tmp = result->SetEventFolderName(eventfoldername);//mount a event folder | |
386 | if (tmp)//if SetEvent returned error | |
387 | { | |
388 | ::Error("AliRunLoader::Open","Can not mount event in folder %s.",eventfoldername); | |
389 | delete result; //delete run-Loader | |
390 | delete gAliceFile;//close the file | |
391 | return 0x0; | |
392 | } | |
393 | } | |
394 | else | |
395 | { | |
396 | if (AliLoader::fgDebug) | |
397 | ::Info("AliRunLoader::Open","Creating new AliRunLoader. Folder name is %s",eventfoldername); | |
398 | result = new AliRunLoader(eventfoldername); | |
399 | } | |
400 | ||
401 | //procedure for extracting dir name from the file name | |
402 | TString fname(filename); | |
403 | Int_t nsl = fname.Last('/');//look for slash in file name | |
404 | TString dirname; | |
405 | if (nsl < 0) | |
406 | {//slash not found | |
407 | Int_t nsl = fname.Last(':');//look for colon e.g. rfio:galice.root | |
408 | if (nsl < 0) dirname = ".";//not found | |
409 | else dirname = fname.Remove(nsl);//found | |
410 | } | |
411 | else dirname = fname.Remove(nsl);//slash found | |
412 | ||
413 | if (AliLoader::fgDebug) | |
414 | ::Info("AliRunLoader::Open","Dir name is : %s",dirname.Data()); | |
415 | ||
416 | result->SetDirName(dirname); | |
417 | result->SetGAliceFile(gAliceFile);//set the pointer to gAliceFile | |
418 | fgRunLoader = result; //PH get access from any place | |
419 | return result; | |
420 | } | |
421 | /**************************************************************************/ | |
422 | Int_t AliRunLoader::GetNumberOfEvents() | |
423 | { | |
424 | //returns number of events in Run | |
425 | Int_t retval; | |
426 | if( TreeE() == 0x0 ) | |
427 | { | |
428 | retval = LoadHeader(); | |
429 | if (retval) | |
430 | { | |
431 | Error("GetNumberOfEvents","Error occured while loading header"); | |
432 | return -1; | |
433 | } | |
434 | } | |
435 | return (Int_t)TreeE()->GetEntries(); | |
436 | } | |
88cb7938 | 437 | /**************************************************************************/ |
f2a509af | 438 | |
88cb7938 | 439 | void AliRunLoader::MakeHeader() |
440 | { | |
441 | //Makes header and connects it to header tree (if it exists) | |
442 | if (GetDebug()) Info("MakeHeader",""); | |
443 | if(fHeader == 0x0) | |
444 | { | |
445 | if (GetDebug()) Info("MakeHeader","Creating new Header Object"); | |
446 | fHeader= new AliHeader(); | |
447 | } | |
448 | TTree* tree = TreeE(); | |
449 | if (tree) | |
450 | { | |
451 | if (GetDebug()) Info("MakeHeader","Got Tree from folder."); | |
452 | TBranch* branch = tree->GetBranch(fgkHeaderBranchName); | |
453 | if (branch == 0x0) | |
454 | { | |
455 | if (GetDebug()) Info("MakeHeader","Creating new branch"); | |
456 | branch = tree->Branch(fgkHeaderBranchName, "AliHeader", &fHeader, 4000, 0); | |
457 | branch->SetAutoDelete(kFALSE); | |
458 | } | |
459 | else | |
460 | { | |
461 | if (GetDebug()) Info("MakeHeader","Got Branch from Tree"); | |
462 | branch->SetAddress(&fHeader); | |
463 | tree->GetEvent(fCurrentEvent); | |
464 | fStack = fHeader->Stack(); //should be safe - if we created Stack, header returns pointer to the same object | |
465 | if (fStack) | |
466 | { | |
467 | fStack->SetEventFolderName(fEventFolder->GetName()); | |
468 | if (TreeK()) fStack->GetEvent(); | |
469 | } | |
470 | else | |
471 | { | |
472 | if (GetDebug()) Info("MakeHeader","Haeder do not have a stack."); | |
473 | } | |
474 | } | |
475 | } | |
476 | if (GetDebug()) Info("MakeHeader","Exiting MakeHeader method"); | |
477 | } | |
478 | /**************************************************************************/ | |
479 | ||
480 | void AliRunLoader::MakeStack() | |
481 | { | |
482 | //Creates the stack object - do not connect the tree | |
483 | if(fStack == 0x0) | |
484 | { | |
485 | fStack = new AliStack(10000); | |
486 | fStack->SetEventFolderName(fEventFolder->GetName()); | |
487 | } | |
488 | } | |
489 | ||
490 | /**************************************************************************/ | |
491 | ||
492 | void AliRunLoader::MakeTree(Option_t *option) | |
493 | { | |
494 | //Creates trees | |
495 | const char *oK = strstr(option,"K"); //Kine | |
496 | const char *oE = strstr(option,"E"); //Header | |
497 | ||
498 | if(oK && !TreeK()) | |
499 | { | |
500 | if (fKineDataLoader->GetBaseLoader(0)->IsLoaded() == kFALSE) | |
501 | { | |
502 | Error("MakeTree(\"K\")","Load Kinematics first"); | |
503 | } | |
504 | else | |
505 | { | |
506 | fKineDataLoader->MakeTree(); | |
507 | MakeStack(); | |
508 | fStack->ConnectTree(); | |
509 | WriteKinematics("OVERWRITE"); | |
510 | } | |
511 | } | |
512 | ||
513 | if(oE && !TreeE()) | |
514 | { | |
515 | fGAFile->cd(); | |
516 | TTree* tree = new TTree(fgkHeaderContainerName,"Tree with Headers"); | |
517 | GetEventFolder()->Add(tree); | |
518 | MakeHeader(); | |
519 | WriteHeader("OVERWRITE"); | |
520 | } | |
521 | ||
522 | TIter next(fLoaders); | |
523 | AliLoader *loader; | |
524 | while((loader = (AliLoader*)next())) | |
525 | { | |
526 | loader->MakeTree(option); | |
527 | } | |
528 | ||
529 | } | |
530 | /**************************************************************************/ | |
531 | ||
532 | Int_t AliRunLoader::LoadgAlice() | |
533 | { | |
534 | //Loads gAlice from file | |
535 | if (GetAliRun()) | |
536 | { | |
537 | Warning("LoadgAlice","AliRun is already in folder. Unload first."); | |
538 | return 0; | |
539 | } | |
540 | AliRun* alirun = dynamic_cast<AliRun*>(fGAFile->Get(fgkGAliceName)); | |
541 | if (alirun == 0x0) | |
542 | { | |
543 | Error("LoadgAlice"," Can not find gAlice in file %s",fGAFile->GetName()); | |
544 | return 2; | |
545 | } | |
546 | alirun->SetRunLoader(this); | |
547 | if (gAlice) | |
548 | { | |
549 | Warning("LoadgAlice","gAlice already exists. Putting retrived object in folder named %s", | |
550 | GetEventFolder()->GetName()); | |
551 | } | |
552 | else | |
553 | { | |
554 | gAlice = alirun; | |
555 | } | |
556 | SetDetectorAddresses();//calls SetTreeAddress for all detectors | |
557 | return 0; | |
558 | } | |
559 | /**************************************************************************/ | |
560 | ||
561 | Int_t AliRunLoader::LoadHeader() | |
562 | { | |
f2a509af | 563 | //loads treeE and reads header object for current event |
88cb7938 | 564 | if (TreeE()) |
565 | { | |
566 | Warning("LoadHeader","Header is already loaded. Use ReloadHeader to force reload. Nothing done"); | |
567 | return 0; | |
568 | } | |
569 | ||
570 | if (GetEventFolder() == 0x0) | |
571 | { | |
572 | Error("LoadHaeder","Event folder not specified yet"); | |
573 | return 1; | |
574 | } | |
575 | ||
576 | if (fGAFile == 0x0) | |
577 | { | |
578 | Error("LoadHaeder","Session not opened. Use AliRunLoader::Open"); | |
579 | return 2; | |
580 | } | |
581 | ||
582 | if (fGAFile->IsOpen() == kFALSE) | |
583 | { | |
584 | Error("LoadHaeder","Session not opened. Use AliRunLoader::Open"); | |
585 | return 2; | |
586 | } | |
587 | ||
588 | TTree* tree = dynamic_cast<TTree*>(fGAFile->Get(fgkHeaderContainerName)); | |
589 | if (tree == 0x0) | |
590 | { | |
591 | Fatal("LoadHaeder","Can not find header tree named %s in file %s", | |
592 | fgkHeaderContainerName.Data(),fGAFile->GetName()); | |
593 | return 2; | |
594 | } | |
595 | ||
596 | if (tree == TreeE()) return 0; | |
597 | ||
598 | CleanHeader(); | |
599 | GetEventFolder()->Add(tree); | |
600 | MakeHeader();//creates header object and connects to tree | |
601 | return 0; | |
602 | ||
603 | } | |
604 | /**************************************************************************/ | |
605 | ||
606 | Int_t AliRunLoader::LoadKinematics(Option_t* option) | |
607 | { | |
608 | //Loads the kinematics | |
609 | Int_t retval = fKineDataLoader->GetBaseLoader(0)->Load(option); | |
610 | if (retval) | |
611 | { | |
612 | Error("LoadKinematics","Error occured while loading kinamatics tree."); | |
613 | return retval; | |
614 | } | |
615 | if (fStack) fStack->GetEvent(); | |
616 | return 0; | |
617 | } | |
618 | /**************************************************************************/ | |
619 | ||
620 | Int_t AliRunLoader::OpenDataFile(const TString& filename,TFile*& file,TDirectory*& dir,Option_t* opt,Int_t cl) | |
621 | { | |
622 | //Opens File with kinematics | |
623 | if (file) | |
624 | { | |
625 | if (file->IsOpen() == kFALSE) | |
626 | {//pointer is not null but file is not opened | |
627 | Warning("OpenDataFile","Pointer to file is not null, but file is not opened");//risky any way | |
628 | delete file; | |
629 | file = 0x0; //proceed with opening procedure | |
630 | } | |
631 | else | |
632 | { | |
633 | Warning("OpenDataFile","File %s already opened",filename.Data()); | |
634 | return 0; | |
635 | } | |
636 | } | |
637 | //try to find if that file is opened somewere else | |
638 | file = (TFile *)( gROOT->GetListOfFiles()->FindObject(filename) ); | |
639 | if (file) | |
640 | { | |
641 | if(file->IsOpen() == kTRUE) | |
642 | { | |
643 | Warning("OpenDataFile","File %s already opened by sombody else.",file->GetName()); | |
644 | return 0; | |
645 | } | |
646 | } | |
647 | ||
648 | file = TFile::Open(filename,opt); | |
649 | if (file == 0x0) | |
650 | {//file is null | |
651 | Error("LoadKinematics","Can not open file %s",filename.Data()); | |
652 | return 1; | |
653 | } | |
654 | if (file->IsOpen() == kFALSE) | |
655 | {//file is not opened | |
656 | Error("LoadKinematics","Can not open file %s",filename.Data()); | |
657 | return 1; | |
658 | } | |
659 | ||
660 | file->SetCompressionLevel(cl); | |
661 | ||
662 | dir = AliLoader::ChangeDir(file,fCurrentEvent); | |
663 | if (dir == 0x0) | |
664 | { | |
665 | Error("OpenKineFile","Can not change to root directory in file %s",filename.Data()); | |
666 | return 3; | |
667 | } | |
668 | return 0; | |
669 | } | |
670 | /**************************************************************************/ | |
671 | ||
672 | TTree* AliRunLoader::TreeE() const | |
673 | { | |
674 | //returns the tree from folder; shortcut method | |
675 | TObject *obj = fEventFolder->FindObject(fgkHeaderContainerName); | |
676 | return (obj)?dynamic_cast<TTree*>(obj):0x0; | |
677 | } | |
678 | /**************************************************************************/ | |
679 | ||
680 | AliHeader* AliRunLoader::GetHeader() const | |
681 | { | |
f2a509af | 682 | //returns pointer header object |
88cb7938 | 683 | return fHeader; |
684 | } | |
685 | /**************************************************************************/ | |
686 | ||
687 | TTree* AliRunLoader::TreeK() const | |
688 | { | |
689 | //returns the tree from folder; shortcut method | |
690 | TObject *obj = GetEventFolder()->FindObject(fgkKineContainerName); | |
691 | return (obj)?dynamic_cast<TTree*>(obj):0x0; | |
692 | } | |
693 | /**************************************************************************/ | |
694 | ||
695 | TTree* AliRunLoader::TreeTR() const | |
696 | { | |
697 | //returns the tree from folder; shortcut method | |
698 | TObject* obj = GetEventFolder()->FindObject(fgkTrackRefsContainerName); | |
699 | return (obj)?dynamic_cast<TTree*>(obj):0x0; | |
700 | } | |
701 | /**************************************************************************/ | |
702 | ||
703 | AliRun* AliRunLoader::GetAliRun() const | |
704 | { | |
705 | //returns AliRun which sits in the folder | |
706 | if (fEventFolder == 0x0) return 0x0; | |
707 | TObject *obj = fEventFolder->FindObject(fgkGAliceName); | |
708 | return (obj)?dynamic_cast<AliRun*>(obj):0x0; | |
709 | } | |
710 | /**************************************************************************/ | |
711 | ||
712 | Int_t AliRunLoader::WriteGeometry(Option_t* opt) | |
713 | { | |
f2a509af | 714 | //writes geometry to the file |
88cb7938 | 715 | fGAFile->cd(); |
716 | TGeometry* geo = GetAliRun()->GetGeometry(); | |
717 | if (geo == 0x0) | |
718 | { | |
719 | Error("WriteGeometry","Can not get geometry from gAlice"); | |
720 | return 1; | |
721 | } | |
722 | geo->Write(); | |
723 | return 0; | |
724 | } | |
725 | /**************************************************************************/ | |
726 | ||
727 | Int_t AliRunLoader::WriteHeader(Option_t* opt) | |
728 | { | |
f2a509af | 729 | //writes treeE |
88cb7938 | 730 | if (GetDebug()) Info("WriteHeader"," WRITING HEADER"); |
731 | ||
732 | TTree* tree = TreeE(); | |
733 | if ( tree == 0x0) | |
734 | { | |
735 | Warning("WriteHeader","Can not find Header Tree in Folder"); | |
736 | return 0; | |
737 | } | |
738 | if (fGAFile->IsWritable() == kFALSE) | |
739 | { | |
740 | Error("WriteHeader","File %s is not writable",fGAFile->GetName()); | |
741 | return 1; | |
742 | } | |
743 | ||
744 | TObject* obj = fGAFile->Get(fgkHeaderContainerName); | |
745 | if (obj) | |
746 | { //if they exist, see if option OVERWRITE is used | |
747 | TString tmp(opt); | |
748 | if(tmp.Contains("OVERWRITE",TString::kIgnoreCase) == 0) | |
749 | {//if it is not used - give an error message and return an error code | |
750 | Error("WriteHeader","Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data"); | |
751 | return 3; | |
752 | } | |
753 | } | |
754 | fGAFile->cd(); | |
755 | tree->SetDirectory(fGAFile); | |
756 | tree->Write(0,TObject::kOverwrite); | |
757 | ||
758 | if (GetDebug()) Info("WriteHeader","WRITTEN\n\n"); | |
759 | ||
760 | return 0; | |
761 | } | |
762 | /**************************************************************************/ | |
763 | ||
764 | Int_t AliRunLoader::WriteAliRun(Option_t* opt) | |
765 | { | |
f2a509af | 766 | //writes AliRun object to the file |
88cb7938 | 767 | fGAFile->cd(); |
f2a509af | 768 | if (GetAliRun()) GetAliRun()->Write(); |
88cb7938 | 769 | return 0; |
770 | } | |
771 | /**************************************************************************/ | |
772 | ||
773 | Int_t AliRunLoader::WriteKinematics(Option_t* opt) | |
774 | { | |
f2a509af | 775 | //writes Kinematics |
88cb7938 | 776 | return fKineDataLoader->GetBaseLoader(0)->WriteData(opt); |
777 | } | |
778 | /**************************************************************************/ | |
779 | Int_t AliRunLoader::WriteTrackRefs(Option_t* opt) | |
780 | { | |
f2a509af | 781 | //writes Track References tree |
88cb7938 | 782 | return fTrackRefsDataLoader->GetBaseLoader(0)->WriteData(opt); |
783 | } | |
784 | /**************************************************************************/ | |
785 | ||
786 | Int_t AliRunLoader::WriteHits(Option_t* opt) | |
787 | { | |
788 | //Calls WriteHits for all loaders | |
789 | Int_t res; | |
790 | Int_t result = 0; | |
791 | TIter next(fLoaders); | |
792 | AliLoader *loader; | |
793 | while((loader = (AliLoader*)next())) | |
794 | { | |
795 | res = loader->WriteHits(opt); | |
796 | if (res) | |
797 | { | |
798 | Error("WriteHits","Failed to write hits for %s (%d)",loader->GetDetectorName().Data(),res); | |
799 | result = 1; | |
800 | } | |
801 | } | |
802 | return result; | |
803 | } | |
804 | /**************************************************************************/ | |
805 | ||
806 | Int_t AliRunLoader::WriteSDigits(Option_t* opt) | |
807 | { | |
f2a509af | 808 | //Calls WriteSDigits for all loaders |
88cb7938 | 809 | Int_t res; |
810 | Int_t result = 0; | |
811 | TIter next(fLoaders); | |
812 | AliLoader *loader; | |
813 | while((loader = (AliLoader*)next())) | |
814 | { | |
815 | res = loader->WriteSDigits(opt); | |
816 | if (res) | |
817 | { | |
818 | Error("WriteSDigits","Failed to write summable digits for %s.",loader->GetDetectorName().Data()); | |
819 | result = 1; | |
820 | } | |
821 | } | |
822 | return result; | |
823 | } | |
824 | /**************************************************************************/ | |
825 | ||
826 | Int_t AliRunLoader::WriteDigits(Option_t* opt) | |
827 | { | |
f2a509af | 828 | //Calls WriteDigits for all loaders |
88cb7938 | 829 | Int_t res; |
830 | Int_t result = 0; | |
831 | TIter next(fLoaders); | |
832 | AliLoader *loader; | |
833 | while((loader = (AliLoader*)next())) | |
834 | { | |
835 | res = loader->WriteDigits(opt); | |
836 | if (res) | |
837 | { | |
838 | Error("WriteDigits","Failed to write digits for %s.",loader->GetDetectorName().Data()); | |
839 | result = 1; | |
840 | } | |
841 | } | |
842 | return result; | |
843 | } | |
844 | /**************************************************************************/ | |
845 | ||
846 | Int_t AliRunLoader::WriteRecPoints(Option_t* opt) | |
847 | { | |
f2a509af | 848 | //Calls WriteRecPoints for all loaders |
88cb7938 | 849 | Int_t res; |
850 | Int_t result = 0; | |
851 | TIter next(fLoaders); | |
852 | AliLoader *loader; | |
853 | while((loader = (AliLoader*)next())) | |
854 | { | |
855 | res = loader->WriteRecPoints(opt); | |
856 | if (res) | |
857 | { | |
858 | Error("WriteRecPoints","Failed to write Reconstructed Points for %s.", | |
859 | loader->GetDetectorName().Data()); | |
860 | result = 1; | |
861 | } | |
862 | } | |
863 | return result; | |
864 | } | |
865 | /**************************************************************************/ | |
866 | ||
867 | Int_t AliRunLoader::WriteTracks(Option_t* opt) | |
868 | { | |
f2a509af | 869 | //Calls WriteTracks for all loaders |
88cb7938 | 870 | Int_t res; |
871 | Int_t result = 0; | |
872 | TIter next(fLoaders); | |
873 | AliLoader *loader; | |
874 | while((loader = (AliLoader*)next())) | |
875 | { | |
876 | res = loader->WriteTracks(opt); | |
877 | if (res) | |
878 | { | |
879 | Error("WriteTracks","Failed to write Tracks for %s.", | |
880 | loader->GetDetectorName().Data()); | |
881 | result = 1; | |
882 | } | |
883 | } | |
884 | return result; | |
885 | } | |
886 | /**************************************************************************/ | |
887 | ||
888 | Int_t AliRunLoader::WriteRunLoader(Option_t* opt) | |
889 | { | |
f2a509af | 890 | //Writes itself to the file |
88cb7938 | 891 | CdGAFile(); |
892 | this->Write(0,TObject::kOverwrite); | |
893 | return 0; | |
894 | } | |
895 | /**************************************************************************/ | |
896 | ||
897 | Int_t AliRunLoader::SetEventFolderName(const TString& name) | |
f2a509af | 898 | { |
899 | //sets top folder name for this run; of alread | |
88cb7938 | 900 | if (name.IsNull()) |
901 | { | |
902 | Error("SetTopFolderName","Name is empty"); | |
903 | return 1; | |
904 | } | |
905 | ||
906 | //check if such a folder already exists - try to find it in alice top folder | |
907 | TObject* obj = AliConfig::Instance()->GetTopFolder()->FindObject(name); | |
908 | if(obj) | |
909 | { | |
910 | TFolder* fold = dynamic_cast<TFolder*>(obj); | |
911 | if (fold == 0x0) | |
912 | { | |
913 | Error("SetTopFolderName","Such a obejct already exists in top alice folder and it is not a folder."); | |
914 | return 2; | |
915 | } | |
916 | //folder which was found is our folder | |
917 | if (fEventFolder == fold) | |
918 | { | |
919 | return 0; | |
920 | } | |
921 | else | |
922 | { | |
923 | Error("SetTopFolderName","Such a folder already exists in top alice folder. Can not mount."); | |
924 | return 2; | |
925 | } | |
926 | } | |
927 | ||
928 | //event is alredy connected, just change name of the folder | |
929 | if (fEventFolder) | |
930 | { | |
931 | fEventFolder->SetName(name); | |
932 | return 0; | |
933 | } | |
934 | ||
935 | if (fKineDataLoader == 0x0) | |
936 | fKineDataLoader = new AliDataLoader(fgkDefaultKineFileName,fgkKineContainerName,"Kinematics"); | |
937 | ||
938 | if ( fTrackRefsDataLoader == 0x0) | |
939 | fTrackRefsDataLoader = new AliDataLoader(fgkDefaultTrackRefsFileName,fgkTrackRefsContainerName,"Track References"); | |
940 | ||
941 | //build the event folder structure | |
942 | if (GetDebug()) Info("SetEventFolderName","Creating new event folder named %s",name.Data()); | |
943 | fEventFolder = AliConfig::Instance()->BuildEventFolder(name,"Event Folder"); | |
944 | fEventFolder->Add(this);//put myself to the folder to accessible for all | |
945 | ||
946 | if (Stack()) Stack()->SetEventFolderName(fEventFolder->GetName()); | |
947 | TIter next(fLoaders); | |
948 | AliLoader *loader; | |
949 | while((loader = (AliLoader*)next())) | |
950 | { | |
951 | loader->Register(fEventFolder);//build folder structure for this detector | |
952 | } | |
953 | ||
954 | fKineDataLoader->SetEventFolder(GetEventFolder()); | |
955 | fTrackRefsDataLoader->SetEventFolder(GetEventFolder()); | |
956 | fKineDataLoader->SetFolder(GetEventFolder()); | |
957 | fTrackRefsDataLoader->SetFolder(GetEventFolder()); | |
958 | ||
959 | fEventFolder->SetOwner(); | |
960 | return 0; | |
961 | } | |
962 | /**************************************************************************/ | |
963 | ||
964 | void AliRunLoader::AddLoader(AliLoader* loader) | |
965 | { | |
966 | //Adds the Loader for given detector | |
967 | if (loader == 0x0) //if null shout and exit | |
968 | { | |
969 | Error("AddLoader","Parameter is NULL"); | |
970 | return; | |
971 | } | |
972 | loader->SetDirName(fUnixDirName); | |
973 | if (fEventFolder) loader->SetEventFolder(fEventFolder); //if event folder is already defined, | |
974 | //pass information to the Loader | |
975 | fLoaders->Add(loader);//add the Loader to the array | |
976 | } | |
977 | /**************************************************************************/ | |
978 | ||
979 | void AliRunLoader::AddLoader(AliDetector* det) | |
980 | { | |
981 | //Asks module (detector) ro make a Loader and stores in the array | |
982 | if (det == 0x0) return; | |
983 | AliLoader* get = det->GetLoader();//try to get loader | |
984 | if (get == 0x0) get = det->MakeLoader(fEventFolder->GetName());//if did not obtain, ask to make it | |
985 | ||
986 | if (get) | |
987 | { | |
988 | if (GetDebug()) Info("AddLoader","Detector: %s Loader : %s",det->GetName(),get->GetName()); | |
989 | AddLoader(get); | |
990 | } | |
991 | } | |
992 | ||
993 | /**************************************************************************/ | |
994 | ||
995 | AliLoader* AliRunLoader::GetLoader(const char* detname) const | |
996 | { | |
f2a509af | 997 | //returns loader for given detector |
998 | //note that naming convention is TPCLoader not just TPC | |
88cb7938 | 999 | return (AliLoader*)fLoaders->FindObject(detname); |
1000 | } | |
1001 | ||
1002 | /**************************************************************************/ | |
1003 | ||
1004 | AliLoader* AliRunLoader::GetLoader(AliDetector* det) const | |
1005 | { | |
f2a509af | 1006 | //get loader for detector det |
88cb7938 | 1007 | if(det == 0x0) return 0x0; |
1008 | TString getname(det->GetName()); | |
1009 | getname+="Loader"; | |
1010 | if (GetDebug()) Info("GetLoader(AliDetector* det)"," Loader name is %s",getname.Data()); | |
1011 | return GetLoader(getname); | |
1012 | } | |
1013 | ||
1014 | /**************************************************************************/ | |
1015 | ||
1016 | void AliRunLoader::CleanFolders() | |
1017 | { | |
1018 | // fEventFolder->Add(this);//put myself to the folder to accessible for all | |
1019 | ||
1020 | CleanDetectors(); | |
1021 | CleanHeader(); | |
1022 | CleanKinematics(); | |
1023 | } | |
1024 | /**************************************************************************/ | |
1025 | ||
1026 | void AliRunLoader::CleanDetectors() | |
1027 | { | |
1028 | //Calls CleanFolders for all detectors | |
1029 | TIter next(fLoaders); | |
1030 | AliLoader *Loader; | |
1031 | while((Loader = (AliLoader*)next())) | |
1032 | { | |
1033 | Loader->CleanFolders(); | |
1034 | } | |
1035 | } | |
1036 | /**************************************************************************/ | |
1037 | ||
1038 | void AliRunLoader::RemoveEventFolder() | |
1039 | { | |
1040 | //remove all the tree of event | |
1041 | //all the stuff changing EbE stays untached (PDGDB, tasks, etc.) | |
1042 | ||
1043 | if (fEventFolder == 0x0) return; | |
1044 | fEventFolder->SetOwner(kFALSE);//don't we want to deleted while removing the folder that we are sitting in | |
1045 | fEventFolder->Remove(this);//remove us drom folder | |
1046 | ||
1047 | AliConfig::Instance()->GetTopFolder()->SetOwner(); //brings ownership back for fEventFolder since it sits in top folder | |
1048 | AliConfig::Instance()->GetTopFolder()->Remove(fEventFolder); //remove the event tree | |
1049 | delete fEventFolder; | |
1050 | } | |
1051 | /**************************************************************************/ | |
1052 | ||
1053 | void AliRunLoader::SetGAliceFile(TFile* gafile) | |
1054 | { | |
f2a509af | 1055 | //sets pointer to galice.root file |
88cb7938 | 1056 | fGAFile = gafile; |
1057 | } | |
1058 | ||
1059 | /**************************************************************************/ | |
1060 | ||
1061 | Int_t AliRunLoader::LoadHits(Option_t* detectors,Option_t* opt) | |
1062 | { | |
1063 | //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all" | |
1064 | ||
1065 | if (GetDebug()) Info("LoadHits","Loading Hits"); | |
1066 | TObjArray* loaders; | |
1067 | TObjArray arr; | |
1068 | ||
1069 | const char* oAll = strstr(detectors,"all"); | |
1070 | if (oAll) | |
1071 | { | |
1072 | if (GetDebug()) Info("LoadHits","Option is All"); | |
1073 | loaders = fLoaders; | |
1074 | } | |
1075 | else | |
1076 | { | |
1077 | GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option | |
1078 | loaders = &arr;//get the pointer array | |
1079 | } | |
1080 | ||
1081 | if (GetDebug()) Info("LoadHits","For detectors. Number of detectors chosen for loading %d",loaders->GetEntries()); | |
1082 | ||
1083 | TIter next(loaders); | |
1084 | AliLoader *loader; | |
1085 | while((loader = (AliLoader*)next())) | |
1086 | { | |
1087 | if (GetDebug()) Info("LoadHits"," Calling LoadHits(%s) for %s",opt,loader->GetName()); | |
1088 | loader->LoadHits(opt); | |
1089 | } | |
1090 | if (GetDebug()) Info("LoadHits","Done"); | |
1091 | return 0; | |
1092 | } | |
1093 | ||
1094 | /**************************************************************************/ | |
1095 | ||
1096 | Int_t AliRunLoader::LoadSDigits(Option_t* detectors,Option_t* opt) | |
1097 | { | |
1098 | //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all" | |
1099 | ||
1100 | TObjArray* loaders; | |
1101 | TObjArray arr; | |
1102 | ||
1103 | const char* oAll = strstr(detectors,"all"); | |
1104 | if (oAll) | |
1105 | { | |
1106 | loaders = fLoaders; | |
1107 | } | |
1108 | else | |
1109 | { | |
1110 | GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option | |
1111 | loaders = &arr;//get the pointer array | |
1112 | } | |
1113 | ||
1114 | TIter next(loaders); | |
1115 | AliLoader *loader; | |
1116 | while((loader = (AliLoader*)next())) | |
1117 | { | |
1118 | loader->LoadSDigits(opt); | |
1119 | } | |
1120 | return 0; | |
1121 | } | |
1122 | ||
1123 | /**************************************************************************/ | |
1124 | ||
1125 | Int_t AliRunLoader::LoadDigits(Option_t* detectors,Option_t* opt) | |
1126 | { | |
1127 | //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all" | |
1128 | ||
1129 | TObjArray* Loaders; | |
1130 | TObjArray arr; | |
1131 | ||
1132 | const char* oAll = strstr(detectors,"all"); | |
1133 | if (oAll) | |
1134 | { | |
1135 | Loaders = fLoaders; | |
1136 | } | |
1137 | else | |
1138 | { | |
1139 | GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option | |
1140 | Loaders = &arr;//get the pointer array | |
1141 | } | |
1142 | ||
1143 | TIter next(Loaders); | |
1144 | AliLoader *Loader; | |
1145 | while((Loader = (AliLoader*)next())) | |
1146 | { | |
1147 | Loader->LoadDigits(opt); | |
1148 | } | |
1149 | return 0; | |
1150 | } | |
1151 | ||
1152 | /**************************************************************************/ | |
1153 | ||
1154 | Int_t AliRunLoader::LoadRecPoints(Option_t* detectors,Option_t* opt) | |
1155 | { | |
1156 | //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all" | |
1157 | ||
1158 | TObjArray* Loaders; | |
1159 | TObjArray arr; | |
1160 | ||
1161 | const char* oAll = strstr(detectors,"all"); | |
1162 | if (oAll) | |
1163 | { | |
1164 | Loaders = fLoaders; | |
1165 | } | |
1166 | else | |
1167 | { | |
1168 | GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option | |
1169 | Loaders = &arr;//get the pointer array | |
1170 | } | |
1171 | ||
1172 | TIter next(Loaders); | |
1173 | AliLoader *Loader; | |
1174 | while((Loader = (AliLoader*)next())) | |
1175 | { | |
1176 | Loader->LoadRecPoints(opt); | |
1177 | } | |
1178 | return 0; | |
1179 | } | |
1180 | ||
1181 | /**************************************************************************/ | |
1182 | ||
1183 | Int_t AliRunLoader::LoadTracks(Option_t* detectors,Option_t* opt) | |
1184 | { | |
1185 | //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all" | |
1186 | ||
1187 | TObjArray* Loaders; | |
1188 | TObjArray arr; | |
1189 | ||
1190 | const char* oAll = strstr(detectors,"all"); | |
1191 | if (oAll) | |
1192 | { | |
1193 | Loaders = fLoaders; | |
1194 | } | |
1195 | else | |
1196 | { | |
1197 | GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option | |
1198 | Loaders = &arr;//get the pointer array | |
1199 | } | |
1200 | ||
1201 | TIter next(Loaders); | |
1202 | AliLoader *Loader; | |
1203 | while((Loader = (AliLoader*)next())) | |
1204 | { | |
1205 | Loader->LoadTracks(opt); | |
1206 | } | |
1207 | return 0; | |
1208 | } | |
1209 | ||
1210 | /**************************************************************************/ | |
1211 | ||
1212 | AliRunLoader* AliRunLoader::GetRunLoader(const char* eventfoldername) | |
f2a509af | 1213 | { |
1214 | //returns RunLoader from folder named eventfoldername | |
88cb7938 | 1215 | TFolder* evfold= dynamic_cast<TFolder*>(AliConfig::Instance()->GetTopFolder()->FindObject(eventfoldername)); |
1216 | if (evfold == 0x0) | |
1217 | { | |
1218 | return 0x0; | |
1219 | } | |
1220 | AliRunLoader* runget = dynamic_cast<AliRunLoader*>(evfold->FindObject(AliRunLoader::fgkRunLoaderName)); | |
1221 | return runget; | |
1222 | ||
f2a509af | 1223 | } |
88cb7938 | 1224 | /**************************************************************************/ |
1225 | ||
8de97894 | 1226 | AliLoader* AliRunLoader::GetDetectorLoader(const char* detname) |
1227 | { | |
1228 | //get the loader of the detector with the given name from the global | |
1229 | //run loader object | |
1230 | AliRunLoader* runLoader = GetRunLoader(); | |
1231 | if (!runLoader) { | |
1232 | cerr << "AliRunLoader::GetDetectorLoader: no run loader found\n"; | |
1233 | return NULL; | |
1234 | } | |
1235 | char loadername[256]; | |
1236 | sprintf(loadername, "%sLoader", detname); | |
1237 | AliLoader* loader = runLoader->GetLoader(loadername); | |
1238 | if (!loader) { | |
1239 | runLoader->Error("GetDetectorLoader", "no loader for %s found", detname); | |
1240 | return NULL; | |
1241 | } | |
1242 | return loader; | |
1243 | } | |
1244 | ||
1245 | /**************************************************************************/ | |
1246 | ||
1247 | TTree* AliRunLoader::GetTreeH(const char* detname, Bool_t maketree) | |
1248 | { | |
1249 | //get the tree with hits of the detector with the given name | |
1250 | //if maketree is true and the tree does not exist, the tree is created | |
1251 | AliLoader* loader = GetDetectorLoader(detname); | |
1252 | if (!loader) return NULL; | |
1253 | if (!loader->TreeH() && maketree) loader->MakeTree("H"); | |
1254 | return loader->TreeH(); | |
1255 | } | |
1256 | ||
1257 | /**************************************************************************/ | |
1258 | ||
1259 | TTree* AliRunLoader::GetTreeS(const char* detname, Bool_t maketree) | |
1260 | { | |
1261 | //get the tree with summable digits of the detector with the given name | |
1262 | //if maketree is true and the tree does not exist, the tree is created | |
1263 | AliLoader* loader = GetDetectorLoader(detname); | |
1264 | if (!loader) return NULL; | |
1265 | if (!loader->TreeS() && maketree) loader->MakeTree("S"); | |
1266 | return loader->TreeS(); | |
1267 | } | |
1268 | ||
1269 | /**************************************************************************/ | |
1270 | ||
1271 | TTree* AliRunLoader::GetTreeD(const char* detname, Bool_t maketree) | |
1272 | { | |
1273 | //get the tree with digits of the detector with the given name | |
1274 | //if maketree is true and the tree does not exist, the tree is created | |
1275 | AliLoader* loader = GetDetectorLoader(detname); | |
1276 | if (!loader) return NULL; | |
1277 | if (!loader->TreeD() && maketree) loader->MakeTree("D"); | |
1278 | return loader->TreeD(); | |
1279 | } | |
1280 | ||
1281 | /**************************************************************************/ | |
1282 | ||
1283 | TTree* AliRunLoader::GetTreeR(const char* detname, Bool_t maketree) | |
1284 | { | |
1285 | //get the tree with clusters of the detector with the given name | |
1286 | //if maketree is true and the tree does not exist, the tree is created | |
1287 | AliLoader* loader = GetDetectorLoader(detname); | |
1288 | if (!loader) return NULL; | |
1289 | if (!loader->TreeR() && maketree) loader->MakeTree("R"); | |
1290 | return loader->TreeR(); | |
1291 | } | |
1292 | ||
1293 | /**************************************************************************/ | |
1294 | ||
1295 | TTree* AliRunLoader::GetTreeT(const char* detname, Bool_t maketree) | |
1296 | { | |
1297 | //get the tree with tracks of the detector with the given name | |
1298 | //if maketree is true and the tree does not exist, the tree is created | |
1299 | AliLoader* loader = GetDetectorLoader(detname); | |
1300 | if (!loader) return NULL; | |
1301 | if (!loader->TreeT() && maketree) loader->MakeTree("T"); | |
1302 | return loader->TreeT(); | |
1303 | } | |
1304 | ||
1305 | /**************************************************************************/ | |
1306 | ||
1307 | TTree* AliRunLoader::GetTreeP(const char* detname, Bool_t maketree) | |
1308 | { | |
1309 | //get the tree with particles of the detector with the given name | |
1310 | //if maketree is true and the tree does not exist, the tree is created | |
1311 | AliLoader* loader = GetDetectorLoader(detname); | |
1312 | if (!loader) return NULL; | |
1313 | if (!loader->TreeP() && maketree) loader->MakeTree("P"); | |
1314 | return loader->TreeP(); | |
1315 | } | |
1316 | ||
1317 | /**************************************************************************/ | |
1318 | ||
88cb7938 | 1319 | void AliRunLoader::CdGAFile() |
1320 | { | |
1321 | //sets gDirectory to galice file | |
1322 | //work around | |
1323 | if(fGAFile) fGAFile->cd(); | |
1324 | } | |
1325 | ||
1326 | /**************************************************************************/ | |
1327 | ||
1328 | void AliRunLoader::GetListOfDetectors(const char * namelist,TObjArray& pointerarray) const | |
1329 | { | |
1330 | //this method looks for all Loaders corresponding | |
1331 | //to names (many) specified in namelist i.e. namelist ("ITS TPC TRD") | |
1332 | ||
1333 | char buff[10]; | |
1334 | char dets [200]; | |
1335 | strcpy(dets,namelist);//compiler cries when char* = const Option_t*; | |
1336 | dets[strlen(dets)+1] = '\n';//set endl at the end of string | |
1337 | char* pdet = dets; | |
1338 | Int_t tmp; | |
1339 | for(;;) | |
1340 | { | |
1341 | tmp = sscanf(pdet,"%s",buff);//read the string from the input string pdet into buff | |
1342 | if ( (buff[0] == 0) || (tmp == 0) ) break; //if not read | |
1343 | ||
f2a509af | 1344 | pdet = strstr(pdet,buff) + strlen(buff);//move the input pointer about number of bytes (letters) read |
88cb7938 | 1345 | //I am aware that is a little complicated. I don't know the number of spaces between detector names |
1346 | //so I read the string, than I find where it starts (strstr) and move the pointer about length of a string | |
1347 | //If there is a better way, please write me (Piotr.Skowronski@cern.ch) | |
1348 | //construct the Loader name | |
1349 | TString getname(buff); | |
1350 | getname+="Loader"; | |
1351 | AliLoader* loader = GetLoader(getname);//get the Loader | |
1352 | if (loader) | |
1353 | { | |
1354 | pointerarray.Add(loader); | |
1355 | } | |
1356 | else | |
1357 | { | |
1358 | Error("GetListOfDetectors","Can not find Loader for %s",buff); | |
1359 | } | |
1360 | ||
1361 | buff[0] = 0; | |
1362 | } | |
1363 | } | |
1364 | /*****************************************************************************/ | |
1365 | ||
1366 | void AliRunLoader::Clean(const TString& name) | |
1367 | { | |
1368 | //removes object with given name from event folder and deletes it | |
1369 | if (GetEventFolder() == 0x0) return; | |
1370 | TObject* obj = GetEventFolder()->FindObject(name); | |
1371 | if(obj) | |
1372 | { | |
1373 | if (GetDebug()) Info("Clean(const TString&)","name=%s, cleaning %s.",GetName(),name.Data()); | |
1374 | GetEventFolder()->Remove(obj); | |
1375 | delete obj; | |
1376 | } | |
1377 | } | |
1378 | ||
1379 | /*****************************************************************************/ | |
1380 | ||
1381 | TTask* AliRunLoader::GetRunDigitizer() | |
1382 | { | |
1383 | //returns Run Digitizer from folder | |
1384 | ||
1385 | TFolder* topf = AliConfig::Instance()->GetTaskFolder(); | |
1386 | TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetDigitizerTaskName()); | |
1387 | return (obj)?dynamic_cast<TTask*>(obj):0x0; | |
1388 | } | |
1389 | /*****************************************************************************/ | |
1390 | ||
1391 | TTask* AliRunLoader::GetRunSDigitizer() | |
1392 | { | |
1393 | //returns SDigitizer Task from folder | |
1394 | ||
1395 | TFolder* topf = AliConfig::Instance()->GetTaskFolder(); | |
1396 | TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetSDigitizerTaskName()); | |
1397 | return (obj)?dynamic_cast<TTask*>(obj):0x0; | |
1398 | } | |
1399 | /*****************************************************************************/ | |
1400 | ||
1401 | TTask* AliRunLoader::GetRunReconstructioner() | |
1402 | { | |
1403 | //returns Reconstructioner Task from folder | |
1404 | TFolder* topf = AliConfig::Instance()->GetTaskFolder(); | |
1405 | TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetReconstructionerTaskName()); | |
1406 | return (obj)?dynamic_cast<TTask*>(obj):0x0; | |
1407 | } | |
1408 | /*****************************************************************************/ | |
1409 | ||
1410 | TTask* AliRunLoader::GetRunTracker() | |
1411 | { | |
1412 | //returns Tracker Task from folder | |
1413 | TFolder* topf = AliConfig::Instance()->GetTaskFolder(); | |
1414 | TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetTrackerTaskName()); | |
1415 | return (obj)?dynamic_cast<TTask*>(obj):0x0; | |
1416 | } | |
1417 | /*****************************************************************************/ | |
1418 | ||
1419 | TTask* AliRunLoader::GetRunPIDTask() | |
1420 | { | |
1421 | //returns Tracker Task from folder | |
1422 | TFolder* topf = AliConfig::Instance()->GetTaskFolder(); | |
1423 | TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetPIDTaskName()); | |
1424 | return (obj)?dynamic_cast<TTask*>(obj):0x0; | |
1425 | } | |
1426 | /*****************************************************************************/ | |
1427 | ||
1428 | TTask* AliRunLoader::GetRunQATask() | |
1429 | { | |
1430 | //returns Quality Assurance Task from folder | |
1431 | TFolder* topf = AliConfig::Instance()->GetTaskFolder(); | |
1432 | if (topf == 0x0) | |
1433 | { | |
1434 | ::Error("AliRunLoader::GetRunQATask","Can not get task folder from AliConfig"); | |
1435 | return 0x0; | |
1436 | } | |
1437 | TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetQATaskName()); | |
1438 | return (obj)?dynamic_cast<TTask*>(obj):0x0; | |
1439 | } | |
1440 | ||
1441 | /*****************************************************************************/ | |
1442 | ||
1443 | void AliRunLoader::SetCompressionLevel(Int_t cl) | |
1444 | { | |
1445 | //Sets Compression Level in all files | |
1446 | if (fGAFile) fGAFile->SetCompressionLevel(cl); | |
1447 | SetKineComprLevel(cl); | |
1448 | SetTrackRefsComprLevel(cl); | |
1449 | TIter next(fLoaders); | |
1450 | AliLoader *loader; | |
1451 | while((loader = (AliLoader*)next())) | |
1452 | { | |
1453 | loader->SetCompressionLevel(cl); | |
1454 | } | |
1455 | } | |
1456 | /**************************************************************************/ | |
1457 | ||
1458 | void AliRunLoader::SetKineComprLevel(Int_t cl) | |
1459 | { | |
1460 | //Sets comression level in Kine File | |
1461 | fKineDataLoader->SetCompressionLevel(cl); | |
1462 | } | |
1463 | /**************************************************************************/ | |
1464 | ||
1465 | void AliRunLoader::SetTrackRefsComprLevel(Int_t cl) | |
1466 | { | |
1467 | //Sets comression level in Track Refences File | |
1468 | fTrackRefsDataLoader->SetCompressionLevel(cl); | |
1469 | } | |
1470 | /**************************************************************************/ | |
1471 | ||
1472 | void AliRunLoader::UnloadHeader() | |
1473 | { | |
1474 | //removes TreeE from folder and deletes it | |
1475 | // as well as fHeader object | |
1476 | CleanHeader(); | |
1477 | delete fHeader; | |
1478 | fHeader = 0x0; | |
1479 | } | |
1480 | /**************************************************************************/ | |
1481 | ||
1482 | void AliRunLoader::UnloadKinematics() | |
1483 | { | |
f2a509af | 1484 | //Unloads Kinematics |
88cb7938 | 1485 | fKineDataLoader->GetBaseLoader(0)->Unload(); |
1486 | } | |
1487 | /**************************************************************************/ | |
1488 | ||
1489 | void AliRunLoader::UnloadTrackRefs() | |
1490 | { | |
f2a509af | 1491 | //Unloads Track Refernces |
88cb7938 | 1492 | fTrackRefsDataLoader->GetBaseLoader(0)->Unload(); |
1493 | } | |
1494 | /**************************************************************************/ | |
1495 | ||
1496 | void AliRunLoader::UnloadgAlice() | |
1497 | { | |
f2a509af | 1498 | //Unloads gAlice |
88cb7938 | 1499 | if (gAlice == GetAliRun()) |
1500 | { | |
1501 | if (GetDebug()) Info("UnloadgAlice","Set gAlice = 0x0"); | |
1502 | gAlice = 0x0;//if gAlice is the same that in folder (to be deleted by the way of folder) | |
1503 | } | |
1504 | AliRun* alirun = GetAliRun(); | |
1505 | if (GetEventFolder()) GetEventFolder()->Remove(alirun); | |
1506 | delete alirun; | |
1507 | } | |
1508 | /**************************************************************************/ | |
1509 | ||
1510 | void AliRunLoader::MakeTrackRefsContainer() | |
1511 | { | |
1512 | // Makes a tree for Track References | |
1513 | fTrackRefsDataLoader->MakeTree(); | |
1514 | } | |
1515 | /**************************************************************************/ | |
1516 | ||
1517 | Int_t AliRunLoader::LoadTrackRefs(Option_t* option) | |
1518 | { | |
1519 | //Load track references from file (opens file and posts tree to folder) | |
1520 | ||
f2a509af | 1521 | return fTrackRefsDataLoader->GetBaseLoader(0)->Load(option); |
88cb7938 | 1522 | } |
1523 | /**************************************************************************/ | |
1524 | ||
1525 | void AliRunLoader::SetDirName(TString& dirname) | |
1526 | { | |
1527 | //sets directory name | |
1528 | if (dirname.IsNull()) return; | |
1529 | fUnixDirName = dirname; | |
1530 | fKineDataLoader->SetDirName(dirname); | |
1531 | fTrackRefsDataLoader->SetDirName(dirname); | |
1532 | ||
1533 | TIter next(fLoaders); | |
1534 | AliLoader *loader; | |
1535 | while((loader = (AliLoader*)next())) | |
1536 | { | |
1537 | loader->SetDirName(dirname); | |
1538 | } | |
1539 | ||
1540 | } | |
1541 | /*****************************************************************************/ | |
1542 | ||
1543 | Int_t AliRunLoader::GetFileOffset() const | |
1544 | { | |
f2a509af | 1545 | //returns the file number that is added to the file name for current event |
88cb7938 | 1546 | return Int_t(fCurrentEvent/fNEventsPerFile); |
1547 | } | |
1548 | ||
1549 | /*****************************************************************************/ | |
1550 | const TString AliRunLoader::SetFileOffset(const TString& fname) | |
1551 | { | |
f2a509af | 1552 | //adds the the number to the file name at proper place for current event |
88cb7938 | 1553 | Long_t offset = (Long_t)GetFileOffset(); |
1554 | if (offset < 1) return fname; | |
1555 | TString soffset; | |
1556 | soffset += offset;//automatic conversion to string | |
1557 | TString dotroot(".root"); | |
1558 | const TString& offfsetdotroot = offset + dotroot; | |
1559 | TString out = fname; | |
1560 | out = out.ReplaceAll(dotroot,offfsetdotroot); | |
1561 | if (GetDebug()) Info("SetFileOffset"," in=%s out=%s",fname.Data(),out.Data()); | |
1562 | return out; | |
1563 | } | |
1564 | /*****************************************************************************/ | |
1565 | ||
1566 | void AliRunLoader::SetDigitsFileNameSuffix(const TString& suffix) | |
1567 | { | |
1568 | //adds the suffix before ".root", | |
1569 | //e.g. TPC.Digits.root -> TPC.DigitsMerged.root | |
1570 | //made on Jiri Chudoba demand | |
1571 | ||
1572 | TIter next(fLoaders); | |
1573 | AliLoader *Loader; | |
1574 | while((Loader = (AliLoader*)next())) | |
1575 | { | |
1576 | Loader->SetDigitsFileNameSuffix(suffix); | |
1577 | } | |
1578 | } | |
1579 | /*****************************************************************************/ | |
1580 | ||
1581 | TString AliRunLoader::GetFileName() const | |
1582 | { | |
1583 | //returns name of galice file | |
1584 | TString result; | |
1585 | if (fGAFile == 0x0) return result; | |
1586 | result = fGAFile->GetName(); | |
1587 | return result; | |
1588 | } | |
1589 | /*****************************************************************************/ | |
1590 | ||
1591 | void AliRunLoader::SetDetectorAddresses() | |
1592 | { | |
1593 | //calls SetTreeAddress for all detectors | |
1594 | if (GetAliRun()==0x0) return; | |
1595 | TIter next(GetAliRun()->Modules()); | |
1596 | AliModule* mod; | |
1597 | while((mod = (AliModule*)next())) | |
1598 | { | |
1599 | AliDetector* det = dynamic_cast<AliDetector*>(mod); | |
1600 | if (det) det->SetTreeAddress(); | |
1601 | } | |
1602 | } | |
1603 | /*****************************************************************************/ | |
1604 | /*****************************************************************************/ | |
1605 | /*****************************************************************************/ |