]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliRunLoader.cxx
Typo fixed, and removing unused variable.
[u/mrichter/AliRoot.git] / STEER / AliRunLoader.cxx
CommitLineData
8364b0ef 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
16/* $Id$ */
17
504b172d 18//____________________________________________________________________
19//////////////////////////////////////////////////////////////////////
20// //
21// class AliRunLoader //
22// //
23// This class aims to be the unque interface for managing data I/O. //
24// It stores Loaders for all modules which, knows names //
25// of the files were data are to be stored. //
26// //
27// It aims to substitud AliRun in automatic data managing //
28// thus there is no necessity of loading gAlice from file in order //
29// to get access to the data. //
30// //
31// Logical place to put the specific Loader to the given //
32// detector is detector itself (i.e ITSLoader in ITS). //
33// But, to load detector object one need to load gAlice, and //
34// by the way all other detectors with their geometrieces and //
35// so on. So, if one need to open TPC clusters there is no //
36// principal need to read everything. //
37// //
38// //
39// When RunLoader is read from the file it does not connect to //
40// the folder structure automatically. It must be connected //
41// (mounted) manualy. Default event folder is defined by //
e191bb57 42// AliConfig::GetDefaultEventFolderName() //
504b172d 43// but can be mounted elsewhere. Usefull specially in merging case, //
44// when more than pone session needs to be loaded //
45// //
46//////////////////////////////////////////////////////////////////////
88cb7938 47
134d2ab3 48#include <TROOT.h>
4095d1ca 49#include <TBranch.h>
4095d1ca 50#include <TFile.h>
51#include <TFolder.h>
4095d1ca 52#include <TObjArray.h>
88cb7938 53#include <TString.h>
024a7e64 54class TTask;
88cb7938 55#include <TTree.h>
88cb7938 56
21bf7095 57#include "AliLog.h"
88cb7938 58#include "AliRun.h"
59#include "AliConfig.h"
60#include "AliLoader.h"
61#include "AliHeader.h"
62#include "AliStack.h"
88cb7938 63#include "AliDetector.h"
9e1ceb13 64#include "AliCDBManager.h"
fe913d8f 65#include "AliCDBLocal.h"
bacbe0fd 66#include "AliCentralTrigger.h"
88cb7938 67
68ClassImp(AliRunLoader)
69
70AliRunLoader* AliRunLoader::fgRunLoader = 0x0;
71
72const TString AliRunLoader::fgkRunLoaderName("RunLoader");
88cb7938 73const TString AliRunLoader::fgkHeaderBranchName("Header");
bacbe0fd 74const TString AliRunLoader::fgkTriggerBranchName("ClassMask");
88cb7938 75const TString AliRunLoader::fgkHeaderContainerName("TE");
bacbe0fd 76const TString AliRunLoader::fgkTriggerContainerName("TreeCT");
88cb7938 77const TString AliRunLoader::fgkKineContainerName("TreeK");
78const TString AliRunLoader::fgkTrackRefsContainerName("TreeTR");
79const TString AliRunLoader::fgkKineBranchName("Particles");
80const TString AliRunLoader::fgkDefaultKineFileName("Kinematics.root");
81const TString AliRunLoader::fgkDefaultTrackRefsFileName("TrackRefs.root");
82const TString AliRunLoader::fgkGAliceName("gAlice");
bacbe0fd 83const TString AliRunLoader::fgkDefaultTriggerFileName("Trigger.root");
88cb7938 84/**************************************************************************/
85
86AliRunLoader::AliRunLoader():
87 fLoaders(0x0),
88 fEventFolder(0x0),
33c3c91a 89 fRun(-1),
88cb7938 90 fCurrentEvent(0),
91 fGAFile(0x0),
92 fHeader(0x0),
93 fStack(0x0),
bacbe0fd 94 fCTrigger(0x0),
88cb7938 95 fKineDataLoader(0x0),
96 fTrackRefsDataLoader(0x0),
97 fNEventsPerFile(1),
c516e34c 98 fNEventsPerRun(0),
88cb7938 99 fUnixDirName(".")
100{
101 AliConfig::Instance();//force to build the folder structure
85a5290f 102 if (!fgRunLoader) fgRunLoader = this;
88cb7938 103}
104/**************************************************************************/
105
106AliRunLoader::AliRunLoader(const char* eventfoldername):
107 TNamed(fgkRunLoaderName,fgkRunLoaderName),
108 fLoaders(new TObjArray()),
109 fEventFolder(0x0),
33c3c91a 110 fRun(-1),
88cb7938 111 fCurrentEvent(0),
112 fGAFile(0x0),
113 fHeader(0x0),
114 fStack(0x0),
bacbe0fd 115 fCTrigger(0x0),
88cb7938 116 fKineDataLoader(new AliDataLoader(fgkDefaultKineFileName,fgkKineContainerName,"Kinematics")),
117 fTrackRefsDataLoader(new AliDataLoader(fgkDefaultTrackRefsFileName,fgkTrackRefsContainerName,"Track References")),
118 fNEventsPerFile(1),
c516e34c 119 fNEventsPerRun(0),
88cb7938 120 fUnixDirName(".")
121{
122//ctor
123 SetEventFolderName(eventfoldername);
85a5290f 124 if (!fgRunLoader) fgRunLoader = this;
88cb7938 125}
126/**************************************************************************/
127
128AliRunLoader::~AliRunLoader()
129{
f2a509af 130//dtor
1bb20a37 131 if (fgRunLoader == this) fgRunLoader = 0x0;
132
88cb7938 133 UnloadHeader();
134 UnloadgAlice();
135
136 if(fLoaders) {
137 fLoaders->SetOwner();
138 delete fLoaders;
139 }
140
141 delete fKineDataLoader;
142 delete fTrackRefsDataLoader;
143
144
145 RemoveEventFolder();
146
147 //fEventFolder is deleted by the way of removing - TopAliceFolder owns it
bacbe0fd 148 if( fCTrigger ) delete fCTrigger;
88cb7938 149 delete fStack;
150 delete fGAFile;
151}
152/**************************************************************************/
153
85a5290f 154AliRunLoader::AliRunLoader(TFolder* topfolder):
155 TNamed(fgkRunLoaderName,fgkRunLoaderName),
156 fLoaders(new TObjArray()),
157 fEventFolder(topfolder),
8513c72c 158 fRun(-1),
85a5290f 159 fCurrentEvent(0),
160 fGAFile(0x0),
161 fHeader(0x0),
162 fStack(0x0),
bacbe0fd 163 fCTrigger(0x0),
85a5290f 164 fKineDataLoader(new AliDataLoader(fgkDefaultKineFileName,fgkKineContainerName,"Kinematics")),
165 fTrackRefsDataLoader(new AliDataLoader(fgkDefaultTrackRefsFileName,fgkTrackRefsContainerName,"Track References")),
166 fNEventsPerFile(1),
c516e34c 167 fNEventsPerRun(0),
85a5290f 168 fUnixDirName(".")
88cb7938 169{
f2a509af 170//ctor
88cb7938 171 if(topfolder == 0x0)
172 {
131d919a 173 TString errmsg("Parameter is NULL");
21bf7095 174 AliError(errmsg.Data());
131d919a 175 throw errmsg;
88cb7938 176 return;
177 }
88cb7938 178
179 TObject* obj = fEventFolder->FindObject(fgkRunLoaderName);
180 if (obj)
181 { //if it is, then sth. is going wrong... exits aliroot session
131d919a 182 TString errmsg("In Event Folder Named ");
183 errmsg+=fEventFolder->GetName();
184 errmsg+=" object named "+fgkRunLoaderName+" already exists. I am confused ...";
185
21bf7095 186 AliError(errmsg.Data());
131d919a 187 throw errmsg;
88cb7938 188 return;//never reached
189 }
131d919a 190
191 if (!fgRunLoader) fgRunLoader = this;
88cb7938 192
88cb7938 193 fEventFolder->Add(this);//put myself to the folder to accessible for all
194
195}
88cb7938 196
024a7e64 197/**************************************************************************/
198
88cb7938 199Int_t AliRunLoader::GetEvent(Int_t evno)
200{
201//Gets event number evno
202//Reloads all data properly
04096ea4 203//PH if (fCurrentEvent == evno) return 0;
88cb7938 204
205 if (evno < 0)
206 {
21bf7095 207 AliError("Can not give the event with negative number");
88cb7938 208 return 4;
209 }
210
211 if (evno >= GetNumberOfEvents())
212 {
21bf7095 213 AliError(Form("There is no event with number %d",evno));
88cb7938 214 return 3;
215 }
216
21bf7095 217 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
218 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
219 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
220 AliDebug(1, Form(" GETTING EVENT %d",evno));
221 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
222 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
223 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
88cb7938 224
225 fCurrentEvent = evno;
226
227 Int_t retval;
228
229 //Reload header (If header was loaded)
230 if (GetHeader())
231 {
232 retval = TreeE()->GetEvent(fCurrentEvent);
233 if ( retval == 0)
234 {
21bf7095 235 AliError(Form("Cannot find event: %d\n ",fCurrentEvent));
88cb7938 236 return 5;
237 }
238 }
239 //Reload stack (If header was loaded)
240 if (TreeE()) fStack = GetHeader()->Stack();
241 //Set event folder in stack (it does not mean that we read kinematics from file)
bacbe0fd 242 if( GetTrigger() && TreeCT() ) {
243 retval = TreeCT()->GetEvent(fCurrentEvent);
c4e6edd3 244 if ( retval < 0 ) {
bacbe0fd 245 AliError(Form("Error occured while GetEvent for Trigger. Event %d",evno));
246 return 2;
247 }
248 }
88cb7938 249
250 retval = SetEvent();
251 if (retval)
252 {
21bf7095 253 AliError(Form("Error occured while setting event %d",evno));
88cb7938 254 return 1;
255 }
256
257 //Post Track References
258 retval = fTrackRefsDataLoader->GetEvent();
259 if (retval)
260 {
21bf7095 261 AliError(Form("Error occured while GetEvent for Track References. Event %d",evno));
88cb7938 262 return 2;
263 }
264
265 //Read Kinematics if loaded
b180b606 266 retval = fKineDataLoader->GetEvent();
88cb7938 267 if (retval)
268 {
21bf7095 269 AliError(Form("Error occured while GetEvent for Kinematics. Event %d",evno));
88cb7938 270 return 2;
271 }
272
a43369dc 273 if (fStack && fKineDataLoader->GetBaseLoader(0)->IsLoaded())
274 {
9ca424c1 275 fStack->ConnectTree(TreeK());
276
a43369dc 277 if (fStack->GetEvent() == kFALSE)
278 {
279 AliError(Form("Error occured while GetEvent for Stack. Event %d",evno));
280 return 2;
281 }
282 }
283
88cb7938 284 //Trigger data reloading in all loaders
285 TIter next(fLoaders);
286 AliLoader *loader;
287 while((loader = (AliLoader*)next()))
288 {
289 retval = loader->GetEvent();
290 if (retval)
291 {
21bf7095 292 AliError(Form("Error occured while getting event for %s. Event %d.",
293 loader->GetDetectorName().Data(), evno));
88cb7938 294 return 3;
295 }
296 }
297
298 SetDetectorAddresses();
299
300 return 0;
301}
302/**************************************************************************/
303Int_t AliRunLoader::SetEvent()
304{
f2a509af 305//if kinematics was loaded Cleans folder data
306
88cb7938 307 Int_t retval;
308
309 retval = fKineDataLoader->SetEvent();
310 if (retval)
311 {
21bf7095 312 AliError("SetEvent for Kinamtics Data Loader retutned error.");
88cb7938 313 return retval;
314 }
315 retval = fTrackRefsDataLoader->SetEvent();
316 if (retval)
317 {
21bf7095 318 AliError("SetEvent for Track References Data Loader retutned error.");
88cb7938 319 return retval;
320 }
321
322 TIter next(fLoaders);
323 AliLoader *loader;
324 while((loader = (AliLoader*)next()))
325 {
326 retval = loader->SetEvent();
327 if (retval)
328 {
21bf7095 329 AliError(Form("SetEvent for %s Data Loader retutned error.",loader->GetName()));
88cb7938 330 return retval;
331 }
332 }
333
334 return 0;
335}
336/**************************************************************************/
337
338Int_t AliRunLoader::SetEventNumber(Int_t evno)
339{
340 //cleans folders and sets the root dirs in files
341 if (fCurrentEvent == evno) return 0;
342 fCurrentEvent = evno;
343 return SetEvent();
344}
345
2c8628dd 346/**************************************************************************/
9e1ceb13 347AliCDBEntry* AliRunLoader::GetCDBEntry(const char* name) const
2c8628dd 348{
9e1ceb13 349//Get an AliCDBEntry from the run data storage
2c8628dd 350
9e1ceb13 351 if ( !(AliCDBManager::Instance()->IsDefaultStorageSet()) ) {
352 AliError("No run data storage defined!");
353 return 0x0;
2c8628dd 354 }
9e1ceb13 355 return AliCDBManager::Instance()->GetDefaultStorage()->Get(name, GetHeader()->GetRun());
356
2c8628dd 357}
358
88cb7938 359/**************************************************************************/
360AliRunLoader* AliRunLoader::Open
361 (const char* filename, const char* eventfoldername, Option_t* option)
362{
363//Opens a desired file 'filename'
364//gets the the run-Loader and mounts it desired folder
365//returns the pointer to run Loader which can be further used for accessing data
366//in case of error returns NULL
367
024a7e64 368 static const TString kwebaddress("http://alisoft.cern.ch/people/skowron/codedoc/split/index.html");
21bf7095 369 AliDebugClass(1,Form("\n\n\nNew I/O strcture: See more info:\n %s\n\n\n",kwebaddress.Data()));
88dc6d4a 370
88cb7938 371 AliRunLoader* result = 0x0;
88dc6d4a 372
88cb7938 373 /* ************************************************ */
374 /* Chceck if folder with given name already exists */
375 /* ************************************************ */
88dc6d4a 376
88cb7938 377 TObject* obj = AliConfig::Instance()->GetTopFolder()->FindObject(eventfoldername);
378 if(obj)
379 {
380 TFolder* fold = dynamic_cast<TFolder*>(obj);
381 if (fold == 0x0)
382 {
21bf7095 383 AliErrorClass("Such a obejct already exists in top alice folder and it is not a folder.");
88cb7938 384 return 0x0;
385 }
386
387 //check if we can get RL from that folder
388 result = AliRunLoader::GetRunLoader(eventfoldername);
389 if (result == 0x0)
390 {
21bf7095 391 AliErrorClass(Form("Folder %s already exists, and can not find session there. Can not mount.",eventfoldername));
88cb7938 392 return 0x0;
393 }
394
395 if (result->GetFileName().CompareTo(filename) != 0)
396 {
21bf7095 397 AliErrorClass("Other file is mounted in demanded folder. Can not mount.");
88cb7938 398 return 0x0;
399 }
400
401 //check if now is demanded (re)creation
402 if ( AliLoader::TestFileOption(option) == kFALSE)
403 {
21bf7095 404 AliErrorClass(Form("Session already exists in folder %s and this session option is %s. Unable to proceed.",
405 eventfoldername,option));
88cb7938 406 return 0x0;
407 }
408
409 //check if demanded option is update and existing one
410 TString tmpstr(option);
411 if ( (tmpstr.CompareTo("update",TString::kIgnoreCase) == 0) &&
412 (result->fGAFile->IsWritable() == kFALSE) )
413 {
21bf7095 414 AliErrorClass(Form("Session already exists in folder %s and is not writable while this session option is %s. Unable to proceed.",
415 eventfoldername,option));
88cb7938 416 return 0x0;
417 }
418
21bf7095 419 AliWarningClass("Session is already opened and mounted in demanded folder");
bacbe0fd 420 if (!fgRunLoader) fgRunLoader = result; //PH get access from any place
88cb7938 421 return result;
422 } //end of checking in case of existance of object named identically that folder session is being opened
423
424
425 TFile * gAliceFile = TFile::Open(filename,option);//open a file
426 if (!gAliceFile)
427 {//null pointer returned
21bf7095 428 AliFatalClass(Form("Can not open file %s.",filename));
88cb7938 429 return 0x0;
430 }
431
432 if (gAliceFile->IsOpen() == kFALSE)
433 {//pointer to valid object returned but file is not opened
21bf7095 434 AliErrorClass(Form("Can not open file %s.",filename));
88cb7938 435 return 0x0;
436 }
437
438 //if file is "read" or "update" than we try to find AliRunLoader there - if not found cry and exit
439 //else create new AliRunLoader
440 if ( AliLoader::TestFileOption(option) )
441 {
21bf7095 442 AliDebugClass(1, "Reading RL from file");
88cb7938 443
444 result = dynamic_cast<AliRunLoader*>(gAliceFile->Get(fgkRunLoaderName));//get the run Loader from the file
445 if (result == 0x0)
446 {//didn't get
21bf7095 447 AliErrorClass(Form("Can not find run-Loader in file %s.",filename));
88cb7938 448 delete gAliceFile;//close the file
449 return 0x0;
450 }
451 Int_t tmp = result->SetEventFolderName(eventfoldername);//mount a event folder
452 if (tmp)//if SetEvent returned error
453 {
21bf7095 454 AliErrorClass(Form("Can not mount event in folder %s.",eventfoldername));
88cb7938 455 delete result; //delete run-Loader
456 delete gAliceFile;//close the file
457 return 0x0;
458 }
459 }
460 else
461 {
21bf7095 462 AliDebugClass(1, Form("Creating new AliRunLoader. Folder name is %s",eventfoldername));
131d919a 463 try
464 {
465 result = new AliRunLoader(eventfoldername);
466 }
467 catch (TString& errmsg)
468 {
21bf7095 469 AliErrorClass(Form("AliRunLoader constrcutor has thrown exception: %s\n",errmsg.Data()));
131d919a 470 delete result;
471 delete gAliceFile;//close the file
472 return 0x0;
473 }
88cb7938 474 }
475
476//procedure for extracting dir name from the file name
477 TString fname(filename);
fca6cd9f 478 Int_t nsl = fname.Last('#');//look for hash in file name
88cb7938 479 TString dirname;
fca6cd9f 480 if (nsl < 0) {//hash not found
481 nsl = fname.Last('/');// look for slash
482 if (nsl < 0)
483 nsl = fname.Last(':');// look for colon e.g. rfio:galice.root
484 }
485
486 if (nsl < 0) dirname = "./"; // no directory path, use "."
487 else dirname = fname.Remove(nsl+1);// directory path
88cb7938 488
21bf7095 489 AliDebugClass(1, Form("Dir name is : %s",dirname.Data()));
88cb7938 490
491 result->SetDirName(dirname);
492 result->SetGAliceFile(gAliceFile);//set the pointer to gAliceFile
85a5290f 493 if (!fgRunLoader) fgRunLoader = result; //PH get access from any place
88cb7938 494 return result;
495}
496/**************************************************************************/
497Int_t AliRunLoader::GetNumberOfEvents()
498{
499 //returns number of events in Run
500 Int_t retval;
501 if( TreeE() == 0x0 )
502 {
503 retval = LoadHeader();
504 if (retval)
505 {
21bf7095 506 AliError("Error occured while loading header");
88cb7938 507 return -1;
508 }
509 }
510 return (Int_t)TreeE()->GetEntries();
511}
88cb7938 512/**************************************************************************/
f2a509af 513
88cb7938 514void AliRunLoader::MakeHeader()
515{
516 //Makes header and connects it to header tree (if it exists)
21bf7095 517 AliDebug(1, "");
88cb7938 518 if(fHeader == 0x0)
519 {
21bf7095 520 AliDebug(1, "Creating new Header Object");
88cb7938 521 fHeader= new AliHeader();
522 }
523 TTree* tree = TreeE();
524 if (tree)
525 {
21bf7095 526 AliDebug(1, "Got Tree from folder.");
88cb7938 527 TBranch* branch = tree->GetBranch(fgkHeaderBranchName);
528 if (branch == 0x0)
529 {
21bf7095 530 AliDebug(1, "Creating new branch");
88cb7938 531 branch = tree->Branch(fgkHeaderBranchName, "AliHeader", &fHeader, 4000, 0);
532 branch->SetAutoDelete(kFALSE);
533 }
534 else
535 {
21bf7095 536 AliDebug(1, "Got Branch from Tree");
88cb7938 537 branch->SetAddress(&fHeader);
538 tree->GetEvent(fCurrentEvent);
539 fStack = fHeader->Stack(); //should be safe - if we created Stack, header returns pointer to the same object
540 if (fStack)
541 {
9ca424c1 542 if (TreeK()) {
543 fStack->ConnectTree(TreeK());
544 fStack->GetEvent();
545 }
88cb7938 546 }
547 else
548 {
21bf7095 549 AliDebug(1, "Header does not have a stack.");
88cb7938 550 }
551 }
552 }
21bf7095 553 AliDebug(1, "Exiting MakeHeader method");
88cb7938 554}
555/**************************************************************************/
556
557void AliRunLoader::MakeStack()
558{
559//Creates the stack object - do not connect the tree
560 if(fStack == 0x0)
561 {
562 fStack = new AliStack(10000);
88cb7938 563 }
564}
bacbe0fd 565/**************************************************************************/
566
567void AliRunLoader::MakeTrigger()
568{
569 // Makes trigger object and connects it to trigger tree (if it exists)
570 AliDebug( 1, "" );
571 if( fCTrigger == 0x0 ) {
572 AliDebug( 1, "Creating new Trigger Object" );
573 fCTrigger = new AliCentralTrigger();
574 }
575 TTree* tree = TreeCT();
576 if( tree ) {
577 fCTrigger->MakeBranch( fgkTriggerBranchName, tree );
578 tree->GetEvent( fCurrentEvent );
579 }
88cb7938 580
bacbe0fd 581 AliDebug( 1, "Exiting MakeTrigger method" );
582}
88cb7938 583/**************************************************************************/
584
585void AliRunLoader::MakeTree(Option_t *option)
586{
587//Creates trees
bacbe0fd 588 const char *oK = strstr(option,"K"); //Kine
589 const char *oE = strstr(option,"E"); //Header
0f46f5fa 590 const char *oGG = strstr(option,"GG"); //Central TriGGer
9ca424c1 591
592 if(oK)
593 {
594 if (fKineDataLoader->GetBaseLoader(0)->IsLoaded() == kFALSE)
88cb7938 595 {
9ca424c1 596 AliError("Load Kinematics first");
88cb7938 597 }
9ca424c1 598 else
88cb7938 599 {
9ca424c1 600 if (!TreeK()) {
601 fKineDataLoader->MakeTree();
602 MakeStack();
603 }
604 fStack->ConnectTree(TreeK());
605 WriteKinematics("OVERWRITE");
606 }
607 } // TreeK
88cb7938 608
609 if(oE && !TreeE())
610 {
611 fGAFile->cd();
612 TTree* tree = new TTree(fgkHeaderContainerName,"Tree with Headers");
613 GetEventFolder()->Add(tree);
614 MakeHeader();
615 WriteHeader("OVERWRITE");
616 }
617
0f46f5fa 618 if(oGG && !TreeCT())
bacbe0fd 619 {
620 // create the CTP Trigger output file and tree
621 TFile* file = gROOT->GetFile( fgkDefaultTriggerFileName );
622 if( !file ) {
3136db6f 623 char* tmp = gSystem->ConcatFileName( fUnixDirName.Data(), fgkDefaultTriggerFileName.Data() );
624 file = TFile::Open(tmp , "RECREATE" ) ;
625 delete[] tmp;
bacbe0fd 626 }
627
628 file->cd();
629 TTree* tree = new TTree( fgkTriggerContainerName, "Tree with Central Trigger Mask" );
630 GetEventFolder()->Add(tree);
631 MakeTrigger();
632 // WriteHeader("OVERWRITE");
633 }
634
88cb7938 635 TIter next(fLoaders);
636 AliLoader *loader;
637 while((loader = (AliLoader*)next()))
638 {
639 loader->MakeTree(option);
640 }
641
642}
643/**************************************************************************/
644
645Int_t AliRunLoader::LoadgAlice()
646{
647//Loads gAlice from file
648 if (GetAliRun())
649 {
21bf7095 650 AliWarning("AliRun is already in folder. Unload first.");
88cb7938 651 return 0;
652 }
653 AliRun* alirun = dynamic_cast<AliRun*>(fGAFile->Get(fgkGAliceName));
654 if (alirun == 0x0)
655 {
21bf7095 656 AliError(Form("Can not find gAlice in file %s",fGAFile->GetName()));
88cb7938 657 return 2;
658 }
659 alirun->SetRunLoader(this);
660 if (gAlice)
661 {
21bf7095 662 AliWarning(Form("gAlice already exists. Putting retrived object in folder named %s",
663 GetEventFolder()->GetName()));
88cb7938 664 }
665 else
666 {
667 gAlice = alirun;
668 }
669 SetDetectorAddresses();//calls SetTreeAddress for all detectors
670 return 0;
671}
672/**************************************************************************/
673
674Int_t AliRunLoader::LoadHeader()
675{
f2a509af 676//loads treeE and reads header object for current event
88cb7938 677 if (TreeE())
678 {
21bf7095 679 AliWarning("Header is already loaded. Use ReloadHeader to force reload. Nothing done");
88cb7938 680 return 0;
681 }
682
683 if (GetEventFolder() == 0x0)
684 {
21bf7095 685 AliError("Event folder not specified yet");
88cb7938 686 return 1;
687 }
688
689 if (fGAFile == 0x0)
690 {
21bf7095 691 AliError("Session not opened. Use AliRunLoader::Open");
88cb7938 692 return 2;
693 }
694
695 if (fGAFile->IsOpen() == kFALSE)
696 {
21bf7095 697 AliError("Session not opened. Use AliRunLoader::Open");
88cb7938 698 return 2;
699 }
700
701 TTree* tree = dynamic_cast<TTree*>(fGAFile->Get(fgkHeaderContainerName));
702 if (tree == 0x0)
703 {
21bf7095 704 AliError(Form("Can not find header tree named %s in file %s",
705 fgkHeaderContainerName.Data(),fGAFile->GetName()));
88cb7938 706 return 2;
707 }
708
709 if (tree == TreeE()) return 0;
710
711 CleanHeader();
712 GetEventFolder()->Add(tree);
713 MakeHeader();//creates header object and connects to tree
714 return 0;
715
716}
717/**************************************************************************/
718
bacbe0fd 719Int_t AliRunLoader::LoadTrigger(Option_t* option)
720{
721 //Load treeCT
722
723 if( TreeCT() ) {
724 AliWarning("Trigger is already loaded. Nothing done");
725 return 0;
726 }
727
728 if( GetEventFolder() == 0x0 ) {
729 AliError("Event folder not specified yet");
730 return 1;
731 }
732 // get the CTP Trigger output file and tree
3136db6f 733 char* tmp = gSystem->ConcatFileName( fUnixDirName.Data(),
734 fgkDefaultTriggerFileName.Data() );
735 TString trgfile(tmp);
736 delete[] tmp;
737
bacbe0fd 738 TFile* file = gROOT->GetFile( trgfile );
739 if( !file ) {
740 file = TFile::Open( trgfile, option ) ;
741 if (!file || file->IsOpen() == kFALSE ) {
742 AliError( Form( "Can not open trigger file %s", trgfile.Data() ) );
743 return 2;
744 }
745 }
746 file->cd();
747
748 TTree* tree = dynamic_cast<TTree*>(file->Get( fgkTriggerContainerName ));
749 if( !tree ) {
750 AliError( Form( "Can not find trigger tree named %s in file %s",
751 fgkTriggerContainerName.Data(), file->GetName() ) );
752 return 2;
753 }
754
755 CleanTrigger();
756
757 fCTrigger = dynamic_cast<AliCentralTrigger*>(file->Get( "AliCentralTrigger" ));
758 GetEventFolder()->Add( tree );
759 MakeTrigger();
760
761 return 0;
762}
763
764/**************************************************************************/
765
88cb7938 766Int_t AliRunLoader::LoadKinematics(Option_t* option)
767{
88dc6d4a 768//Loads the kinematics
88cb7938 769 Int_t retval = fKineDataLoader->GetBaseLoader(0)->Load(option);
770 if (retval)
771 {
21bf7095 772 AliError("Error occured while loading kinamatics tree.");
88cb7938 773 return retval;
774 }
443b7449 775 if (fStack)
776 {
9ca424c1 777 fStack->ConnectTree(TreeK());
778 retval = fStack->GetEvent();
443b7449 779 if ( retval == kFALSE)
780 {
21bf7095 781 AliError("Error occured while loading kinamatics tree.");
443b7449 782 return retval;
783 }
784
785 }
88cb7938 786 return 0;
787}
788/**************************************************************************/
789
790Int_t AliRunLoader::OpenDataFile(const TString& filename,TFile*& file,TDirectory*& dir,Option_t* opt,Int_t cl)
791{
792//Opens File with kinematics
793 if (file)
794 {
795 if (file->IsOpen() == kFALSE)
796 {//pointer is not null but file is not opened
21bf7095 797 AliWarning("Pointer to file is not null, but file is not opened");//risky any way
88cb7938 798 delete file;
799 file = 0x0; //proceed with opening procedure
800 }
801 else
802 {
21bf7095 803 AliWarning(Form("File %s already opened",filename.Data()));
88cb7938 804 return 0;
805 }
806 }
807//try to find if that file is opened somewere else
808 file = (TFile *)( gROOT->GetListOfFiles()->FindObject(filename) );
809 if (file)
810 {
811 if(file->IsOpen() == kTRUE)
812 {
21bf7095 813 AliWarning(Form("File %s already opened by sombody else.",file->GetName()));
88cb7938 814 return 0;
815 }
816 }
817
818 file = TFile::Open(filename,opt);
819 if (file == 0x0)
820 {//file is null
21bf7095 821 AliError(Form("Can not open file %s",filename.Data()));
88cb7938 822 return 1;
823 }
824 if (file->IsOpen() == kFALSE)
825 {//file is not opened
21bf7095 826 AliError(Form("Can not open file %s",filename.Data()));
88cb7938 827 return 1;
828 }
829
830 file->SetCompressionLevel(cl);
831
832 dir = AliLoader::ChangeDir(file,fCurrentEvent);
833 if (dir == 0x0)
834 {
21bf7095 835 AliError(Form("Can not change to root directory in file %s",filename.Data()));
88cb7938 836 return 3;
837 }
838 return 0;
839}
840/**************************************************************************/
841
842TTree* AliRunLoader::TreeE() const
843{
844 //returns the tree from folder; shortcut method
21bf7095 845 if (AliDebugLevel() > 10) fEventFolder->ls();
88cb7938 846 TObject *obj = fEventFolder->FindObject(fgkHeaderContainerName);
847 return (obj)?dynamic_cast<TTree*>(obj):0x0;
848}
849/**************************************************************************/
850
bacbe0fd 851TTree* AliRunLoader::TreeCT() const
852{
853 //returns the tree from folder; shortcut method
854 if (AliDebugLevel() > 10) fEventFolder->ls();
855 TObject *obj = fEventFolder->FindObject(fgkTriggerContainerName);
856 return (obj)?dynamic_cast<TTree*>(obj):0x0;
857}
858/**************************************************************************/
859
88cb7938 860AliHeader* AliRunLoader::GetHeader() const
861{
f2a509af 862//returns pointer header object
88cb7938 863 return fHeader;
864}
865/**************************************************************************/
bacbe0fd 866
867AliCentralTrigger* AliRunLoader::GetTrigger() const
868{
869//returns pointer trigger object
870 return fCTrigger;
871}
872
873/**************************************************************************/
88cb7938 874
875TTree* AliRunLoader::TreeK() const
876{
877 //returns the tree from folder; shortcut method
878 TObject *obj = GetEventFolder()->FindObject(fgkKineContainerName);
879 return (obj)?dynamic_cast<TTree*>(obj):0x0;
880}
881/**************************************************************************/
882
883TTree* AliRunLoader::TreeTR() const
884{
885 //returns the tree from folder; shortcut method
886 TObject* obj = GetEventFolder()->FindObject(fgkTrackRefsContainerName);
887 return (obj)?dynamic_cast<TTree*>(obj):0x0;
888}
889/**************************************************************************/
890
891AliRun* AliRunLoader::GetAliRun() const
892{
893//returns AliRun which sits in the folder
894 if (fEventFolder == 0x0) return 0x0;
895 TObject *obj = fEventFolder->FindObject(fgkGAliceName);
896 return (obj)?dynamic_cast<AliRun*>(obj):0x0;
897}
898/**************************************************************************/
899
88cb7938 900Int_t AliRunLoader::WriteHeader(Option_t* opt)
901{
f2a509af 902//writes treeE
21bf7095 903 AliDebug(1, "WRITING HEADER");
88cb7938 904
905 TTree* tree = TreeE();
906 if ( tree == 0x0)
907 {
21bf7095 908 AliWarning("Can not find Header Tree in Folder");
88cb7938 909 return 0;
910 }
911 if (fGAFile->IsWritable() == kFALSE)
912 {
21bf7095 913 AliError(Form("File %s is not writable",fGAFile->GetName()));
88cb7938 914 return 1;
915 }
916
917 TObject* obj = fGAFile->Get(fgkHeaderContainerName);
918 if (obj)
919 { //if they exist, see if option OVERWRITE is used
920 TString tmp(opt);
921 if(tmp.Contains("OVERWRITE",TString::kIgnoreCase) == 0)
922 {//if it is not used - give an error message and return an error code
21bf7095 923 AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
88cb7938 924 return 3;
925 }
926 }
927 fGAFile->cd();
928 tree->SetDirectory(fGAFile);
929 tree->Write(0,TObject::kOverwrite);
930
21bf7095 931 AliDebug(1, "WRITTEN\n\n");
88cb7938 932
933 return 0;
934}
bacbe0fd 935
936/**************************************************************************/
937
938Int_t AliRunLoader::WriteTrigger(Option_t* opt)
939{
940 //writes TreeCT
941 AliDebug( 1, "WRITING TRIGGER" );
942
943 TTree* tree = TreeCT();
944 if ( tree == 0x0) {
945 AliWarning("Can not find Trigger Tree in Folder");
946 return 0;
947 }
948
949 TFile* file = gROOT->GetFile( gSystem->ConcatFileName( fUnixDirName.Data(), fgkDefaultTriggerFileName.Data() ) ) ;
950 if( !file || !file->IsOpen() ) {
951 AliError( "can't write Trigger, file is not open" );
952 return kFALSE;
953 }
954
955 TObject* obj = file->Get( fgkTriggerContainerName );
956 if( obj ) { //if they exist, see if option OVERWRITE is used
957 TString tmp(opt);
958 if( tmp.Contains( "OVERWRITE", TString::kIgnoreCase ) == 0) {
959 //if it is not used - give an error message and return an error code
960 AliError( "Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data" );
961 return 3;
962 }
963 }
964 file->cd();
965 fCTrigger->Write( 0, TObject::kOverwrite );
966 tree->Write( 0, TObject::kOverwrite );
967 file->Flush();
968
969 AliDebug(1, "WRITTEN\n\n");
970
971 return 0;
972}
88cb7938 973/**************************************************************************/
974
d1898505 975Int_t AliRunLoader::WriteAliRun(Option_t* /*opt*/)
88cb7938 976{
f2a509af 977//writes AliRun object to the file
88cb7938 978 fGAFile->cd();
f2a509af 979 if (GetAliRun()) GetAliRun()->Write();
88cb7938 980 return 0;
981}
982/**************************************************************************/
983
984Int_t AliRunLoader::WriteKinematics(Option_t* opt)
985{
f2a509af 986//writes Kinematics
88cb7938 987 return fKineDataLoader->GetBaseLoader(0)->WriteData(opt);
988}
989/**************************************************************************/
990Int_t AliRunLoader::WriteTrackRefs(Option_t* opt)
991{
f2a509af 992//writes Track References tree
88cb7938 993 return fTrackRefsDataLoader->GetBaseLoader(0)->WriteData(opt);
994}
995/**************************************************************************/
996
997Int_t AliRunLoader::WriteHits(Option_t* opt)
998{
999//Calls WriteHits for all loaders
1000 Int_t res;
1001 Int_t result = 0;
1002 TIter next(fLoaders);
1003 AliLoader *loader;
1004 while((loader = (AliLoader*)next()))
1005 {
1006 res = loader->WriteHits(opt);
1007 if (res)
1008 {
21bf7095 1009 AliError(Form("Failed to write hits for %s (%d)",loader->GetDetectorName().Data(),res));
88cb7938 1010 result = 1;
1011 }
1012 }
1013 return result;
1014}
1015/**************************************************************************/
1016
1017Int_t AliRunLoader::WriteSDigits(Option_t* opt)
1018{
f2a509af 1019//Calls WriteSDigits for all loaders
88cb7938 1020 Int_t res;
1021 Int_t result = 0;
1022 TIter next(fLoaders);
1023 AliLoader *loader;
1024 while((loader = (AliLoader*)next()))
1025 {
1026 res = loader->WriteSDigits(opt);
1027 if (res)
1028 {
21bf7095 1029 AliError(Form("Failed to write summable digits for %s.",loader->GetDetectorName().Data()));
88cb7938 1030 result = 1;
1031 }
1032 }
1033 return result;
1034}
1035/**************************************************************************/
1036
1037Int_t AliRunLoader::WriteDigits(Option_t* opt)
1038{
f2a509af 1039//Calls WriteDigits for all loaders
88cb7938 1040 Int_t res;
1041 Int_t result = 0;
1042 TIter next(fLoaders);
1043 AliLoader *loader;
1044 while((loader = (AliLoader*)next()))
1045 {
1046 res = loader->WriteDigits(opt);
1047 if (res)
1048 {
21bf7095 1049 AliError(Form("Failed to write digits for %s.",loader->GetDetectorName().Data()));
88cb7938 1050 result = 1;
1051 }
1052 }
1053 return result;
1054}
1055/**************************************************************************/
1056
1057Int_t AliRunLoader::WriteRecPoints(Option_t* opt)
1058{
f2a509af 1059//Calls WriteRecPoints for all loaders
88cb7938 1060 Int_t res;
1061 Int_t result = 0;
1062 TIter next(fLoaders);
1063 AliLoader *loader;
1064 while((loader = (AliLoader*)next()))
1065 {
1066 res = loader->WriteRecPoints(opt);
1067 if (res)
1068 {
21bf7095 1069 AliError(Form("Failed to write Reconstructed Points for %s.",
1070 loader->GetDetectorName().Data()));
88cb7938 1071 result = 1;
1072 }
1073 }
1074 return result;
1075}
1076/**************************************************************************/
1077
1078Int_t AliRunLoader::WriteTracks(Option_t* opt)
1079{
f2a509af 1080//Calls WriteTracks for all loaders
88cb7938 1081 Int_t res;
1082 Int_t result = 0;
1083 TIter next(fLoaders);
1084 AliLoader *loader;
1085 while((loader = (AliLoader*)next()))
1086 {
1087 res = loader->WriteTracks(opt);
1088 if (res)
1089 {
21bf7095 1090 AliError(Form("Failed to write Tracks for %s.",
1091 loader->GetDetectorName().Data()));
88cb7938 1092 result = 1;
1093 }
1094 }
1095 return result;
1096}
1097/**************************************************************************/
1098
d1898505 1099Int_t AliRunLoader::WriteRunLoader(Option_t* /*opt*/)
88cb7938 1100{
f2a509af 1101//Writes itself to the file
88cb7938 1102 CdGAFile();
1103 this->Write(0,TObject::kOverwrite);
1104 return 0;
1105}
1106/**************************************************************************/
1107
1108Int_t AliRunLoader::SetEventFolderName(const TString& name)
f2a509af 1109{
1110//sets top folder name for this run; of alread
88cb7938 1111 if (name.IsNull())
1112 {
21bf7095 1113 AliError("Name is empty");
88cb7938 1114 return 1;
1115 }
1116
1117 //check if such a folder already exists - try to find it in alice top folder
1118 TObject* obj = AliConfig::Instance()->GetTopFolder()->FindObject(name);
1119 if(obj)
1120 {
1121 TFolder* fold = dynamic_cast<TFolder*>(obj);
1122 if (fold == 0x0)
1123 {
21bf7095 1124 AliError("Such a obejct already exists in top alice folder and it is not a folder.");
88cb7938 1125 return 2;
1126 }
1127 //folder which was found is our folder
1128 if (fEventFolder == fold)
1129 {
1130 return 0;
1131 }
1132 else
1133 {
21bf7095 1134 AliError("Such a folder already exists in top alice folder. Can not mount.");
88cb7938 1135 return 2;
1136 }
1137 }
1138
1139 //event is alredy connected, just change name of the folder
1140 if (fEventFolder)
1141 {
1142 fEventFolder->SetName(name);
1143 return 0;
1144 }
1145
1146 if (fKineDataLoader == 0x0)
1147 fKineDataLoader = new AliDataLoader(fgkDefaultKineFileName,fgkKineContainerName,"Kinematics");
1148
1149 if ( fTrackRefsDataLoader == 0x0)
1150 fTrackRefsDataLoader = new AliDataLoader(fgkDefaultTrackRefsFileName,fgkTrackRefsContainerName,"Track References");
1151
1152 //build the event folder structure
21bf7095 1153 AliDebug(1, Form("Creating new event folder named %s",name.Data()));
88cb7938 1154 fEventFolder = AliConfig::Instance()->BuildEventFolder(name,"Event Folder");
1155 fEventFolder->Add(this);//put myself to the folder to accessible for all
1156
88cb7938 1157 TIter next(fLoaders);
1158 AliLoader *loader;
1159 while((loader = (AliLoader*)next()))
1160 {
1161 loader->Register(fEventFolder);//build folder structure for this detector
1162 }
1163
1164 fKineDataLoader->SetEventFolder(GetEventFolder());
1165 fTrackRefsDataLoader->SetEventFolder(GetEventFolder());
1166 fKineDataLoader->SetFolder(GetEventFolder());
1167 fTrackRefsDataLoader->SetFolder(GetEventFolder());
1168
1169 fEventFolder->SetOwner();
1170 return 0;
1171}
1172/**************************************************************************/
1173
1174void AliRunLoader::AddLoader(AliLoader* loader)
1175 {
1176 //Adds the Loader for given detector
1177 if (loader == 0x0) //if null shout and exit
1178 {
21bf7095 1179 AliError("Parameter is NULL");
88cb7938 1180 return;
1181 }
1182 loader->SetDirName(fUnixDirName);
1183 if (fEventFolder) loader->SetEventFolder(fEventFolder); //if event folder is already defined,
1184 //pass information to the Loader
1185 fLoaders->Add(loader);//add the Loader to the array
1186 }
1187/**************************************************************************/
1188
1189void AliRunLoader::AddLoader(AliDetector* det)
1190 {
1191//Asks module (detector) ro make a Loader and stores in the array
1192 if (det == 0x0) return;
1193 AliLoader* get = det->GetLoader();//try to get loader
1194 if (get == 0x0) get = det->MakeLoader(fEventFolder->GetName());//if did not obtain, ask to make it
1195
1196 if (get)
1197 {
21bf7095 1198 AliDebug(1, Form("Detector: %s Loader : %s",det->GetName(),get->GetName()));
88cb7938 1199 AddLoader(get);
1200 }
1201 }
1202
1203/**************************************************************************/
1204
1205AliLoader* AliRunLoader::GetLoader(const char* detname) const
1206{
f2a509af 1207//returns loader for given detector
1208//note that naming convention is TPCLoader not just TPC
88cb7938 1209 return (AliLoader*)fLoaders->FindObject(detname);
1210}
1211
1212/**************************************************************************/
1213
1214AliLoader* AliRunLoader::GetLoader(AliDetector* det) const
1215{
f2a509af 1216//get loader for detector det
88cb7938 1217 if(det == 0x0) return 0x0;
1218 TString getname(det->GetName());
1219 getname+="Loader";
21bf7095 1220 AliDebug(1, Form(" Loader name is %s",getname.Data()));
88cb7938 1221 return GetLoader(getname);
1222}
1223
1224/**************************************************************************/
1225
1226void AliRunLoader::CleanFolders()
1227{
1228// fEventFolder->Add(this);//put myself to the folder to accessible for all
1229
1230 CleanDetectors();
1231 CleanHeader();
1232 CleanKinematics();
bacbe0fd 1233 CleanTrigger();
88cb7938 1234}
1235/**************************************************************************/
1236
1237void AliRunLoader::CleanDetectors()
1238{
1239//Calls CleanFolders for all detectors
1240 TIter next(fLoaders);
d0d4a6b3 1241 AliLoader *loader;
1242 while((loader = (AliLoader*)next()))
88cb7938 1243 {
d0d4a6b3 1244 loader->CleanFolders();
88cb7938 1245 }
1246}
1247/**************************************************************************/
1248
1249void AliRunLoader::RemoveEventFolder()
1250{
1251//remove all the tree of event
1252//all the stuff changing EbE stays untached (PDGDB, tasks, etc.)
1253
1254 if (fEventFolder == 0x0) return;
1255 fEventFolder->SetOwner(kFALSE);//don't we want to deleted while removing the folder that we are sitting in
1256 fEventFolder->Remove(this);//remove us drom folder
1257
1258 AliConfig::Instance()->GetTopFolder()->SetOwner(); //brings ownership back for fEventFolder since it sits in top folder
1259 AliConfig::Instance()->GetTopFolder()->Remove(fEventFolder); //remove the event tree
1260 delete fEventFolder;
1261}
1262/**************************************************************************/
1263
1264void AliRunLoader::SetGAliceFile(TFile* gafile)
1265{
f2a509af 1266//sets pointer to galice.root file
88cb7938 1267 fGAFile = gafile;
1268}
1269
1270/**************************************************************************/
1271
1272Int_t AliRunLoader::LoadHits(Option_t* detectors,Option_t* opt)
1273{
1274//LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1275
21bf7095 1276 AliDebug(1, "Loading Hits");
88cb7938 1277 TObjArray* loaders;
1278 TObjArray arr;
1279
1280 const char* oAll = strstr(detectors,"all");
1281 if (oAll)
1282 {
21bf7095 1283 AliDebug(1, "Option is All");
88cb7938 1284 loaders = fLoaders;
1285 }
1286 else
1287 {
1288 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1289 loaders = &arr;//get the pointer array
1290 }
1291
21bf7095 1292 AliDebug(1, Form("For detectors. Number of detectors chosen for loading %d",loaders->GetEntries()));
88cb7938 1293
1294 TIter next(loaders);
1295 AliLoader *loader;
1296 while((loader = (AliLoader*)next()))
1297 {
21bf7095 1298 AliDebug(1, Form(" Calling LoadHits(%s) for %s",opt,loader->GetName()));
88cb7938 1299 loader->LoadHits(opt);
1300 }
21bf7095 1301 AliDebug(1, "Done");
88cb7938 1302 return 0;
1303}
1304
1305/**************************************************************************/
1306
1307Int_t AliRunLoader::LoadSDigits(Option_t* detectors,Option_t* opt)
1308{
1309//LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1310
1311 TObjArray* loaders;
1312 TObjArray arr;
1313
1314 const char* oAll = strstr(detectors,"all");
1315 if (oAll)
1316 {
1317 loaders = fLoaders;
1318 }
1319 else
1320 {
1321 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1bb20a37 1322 loaders = &arr;//get the pointer to array
88cb7938 1323 }
1324
1325 TIter next(loaders);
1326 AliLoader *loader;
1327 while((loader = (AliLoader*)next()))
1328 {
1329 loader->LoadSDigits(opt);
1330 }
1331 return 0;
1332}
1333
1334/**************************************************************************/
1335
1336Int_t AliRunLoader::LoadDigits(Option_t* detectors,Option_t* opt)
1337{
1338//LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1339
d0d4a6b3 1340 TObjArray* loaders;
88cb7938 1341 TObjArray arr;
1342
1343 const char* oAll = strstr(detectors,"all");
1344 if (oAll)
1345 {
d0d4a6b3 1346 loaders = fLoaders;
88cb7938 1347 }
1348 else
1349 {
1350 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
d0d4a6b3 1351 loaders = &arr;//get the pointer array
88cb7938 1352 }
1353
d0d4a6b3 1354 TIter next(loaders);
1355 AliLoader *loader;
1356 while((loader = (AliLoader*)next()))
88cb7938 1357 {
d0d4a6b3 1358 loader->LoadDigits(opt);
88cb7938 1359 }
1360 return 0;
1361}
88cb7938 1362/**************************************************************************/
1363
1364Int_t AliRunLoader::LoadRecPoints(Option_t* detectors,Option_t* opt)
1365{
1366//LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1367
d0d4a6b3 1368 TObjArray* loaders;
88cb7938 1369 TObjArray arr;
1370
1371 const char* oAll = strstr(detectors,"all");
1372 if (oAll)
1373 {
d0d4a6b3 1374 loaders = fLoaders;
88cb7938 1375 }
1376 else
1377 {
1378 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
d0d4a6b3 1379 loaders = &arr;//get the pointer array
88cb7938 1380 }
1381
d0d4a6b3 1382 TIter next(loaders);
1383 AliLoader *loader;
1384 while((loader = (AliLoader*)next()))
88cb7938 1385 {
d0d4a6b3 1386 loader->LoadRecPoints(opt);
88cb7938 1387 }
1388 return 0;
1389}
1bb20a37 1390/**************************************************************************/
88cb7938 1391
1bb20a37 1392Int_t AliRunLoader::LoadRecParticles(Option_t* detectors,Option_t* opt)
1393{
1394//LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1395
d0d4a6b3 1396 TObjArray* loaders;
1bb20a37 1397 TObjArray arr;
1398
1399 const char* oAll = strstr(detectors,"all");
1400 if (oAll)
1401 {
d0d4a6b3 1402 loaders = fLoaders;
1bb20a37 1403 }
1404 else
1405 {
1406 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
d0d4a6b3 1407 loaders = &arr;//get the pointer array
1bb20a37 1408 }
1409
d0d4a6b3 1410 TIter next(loaders);
1411 AliLoader *loader;
1412 while((loader = (AliLoader*)next()))
1bb20a37 1413 {
d0d4a6b3 1414 loader->LoadRecParticles(opt);
1bb20a37 1415 }
1416 return 0;
1417}
88cb7938 1418/**************************************************************************/
1419
1420Int_t AliRunLoader::LoadTracks(Option_t* detectors,Option_t* opt)
1421{
1422//LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1423
d0d4a6b3 1424 TObjArray* loaders;
88cb7938 1425 TObjArray arr;
1426
1427 const char* oAll = strstr(detectors,"all");
1428 if (oAll)
1429 {
d0d4a6b3 1430 loaders = fLoaders;
88cb7938 1431 }
1432 else
1433 {
1434 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
d0d4a6b3 1435 loaders = &arr;//get the pointer array
88cb7938 1436 }
1437
d0d4a6b3 1438 TIter next(loaders);
1439 AliLoader *loader;
1440 while((loader = (AliLoader*)next()))
88cb7938 1441 {
d0d4a6b3 1442 loader->LoadTracks(opt);
88cb7938 1443 }
1444 return 0;
1445}
1bb20a37 1446/**************************************************************************/
1447
1448void AliRunLoader::UnloadHits(Option_t* detectors)
1449{
1450 //unloads hits for detectors specified in parameter
1451 TObjArray* loaders;
1452 TObjArray arr;
1453
1454 const char* oAll = strstr(detectors,"all");
1455 if (oAll)
1456 {
1457 loaders = fLoaders;
1458 }
1459 else
1460 {
1461 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1462 loaders = &arr;//get the pointer to array
1463 }
1464
1465 TIter next(loaders);
1466 AliLoader *loader;
1467 while((loader = (AliLoader*)next()))
1468 {
1469 loader->UnloadHits();
1470 }
1471}
1472/**************************************************************************/
1473
1474void AliRunLoader::UnloadSDigits(Option_t* detectors)
1475{
1476 //unloads SDigits for detectors specified in parameter
1477 TObjArray* loaders;
1478 TObjArray arr;
1479
1480 const char* oAll = strstr(detectors,"all");
1481 if (oAll)
1482 {
1483 loaders = fLoaders;
1484 }
1485 else
1486 {
1487 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1488 loaders = &arr;//get the pointer to array
1489 }
1490
1491 TIter next(loaders);
1492 AliLoader *loader;
1493 while((loader = (AliLoader*)next()))
1494 {
1495 loader->UnloadSDigits();
1496 }
1497}
1498/**************************************************************************/
1499
1500void AliRunLoader::UnloadDigits(Option_t* detectors)
1501{
1502 //unloads Digits for detectors specified in parameter
1503 TObjArray* loaders;
1504 TObjArray arr;
1505
1506 const char* oAll = strstr(detectors,"all");
1507 if (oAll)
1508 {
1509 loaders = fLoaders;
1510 }
1511 else
1512 {
1513 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1514 loaders = &arr;//get the pointer to array
1515 }
1516
1517 TIter next(loaders);
1518 AliLoader *loader;
1519 while((loader = (AliLoader*)next()))
1520 {
1521 loader->UnloadDigits();
1522 }
1523}
1524/**************************************************************************/
1525
1526void AliRunLoader::UnloadRecPoints(Option_t* detectors)
1527{
1528 //unloads RecPoints for detectors specified in parameter
1529 TObjArray* loaders;
1530 TObjArray arr;
1531
1532 const char* oAll = strstr(detectors,"all");
1533 if (oAll)
1534 {
1535 loaders = fLoaders;
1536 }
1537 else
1538 {
1539 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1540 loaders = &arr;//get the pointer to array
1541 }
1542
1543 TIter next(loaders);
1544 AliLoader *loader;
1545 while((loader = (AliLoader*)next()))
1546 {
1547 loader->UnloadRecPoints();
1548 }
1549}
1550/**************************************************************************/
1551
1552void AliRunLoader::UnloadAll(Option_t* detectors)
1553{
1554 //calls UnloadAll for detectors names specified in parameter
1555 // option "all" passed can be passed
1556 TObjArray* loaders;
1557 TObjArray arr;
1558
1559 const char* oAll = strstr(detectors,"all");
1560 if (oAll)
1561 {
1562 loaders = fLoaders;
1563 }
1564 else
1565 {
1566 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1567 loaders = &arr;//get the pointer to array
1568 }
88cb7938 1569
1bb20a37 1570 TIter next(loaders);
1571 AliLoader *loader;
1572 while((loader = (AliLoader*)next()))
1573 {
1574 loader->UnloadAll();
1575 }
1576}
1577/**************************************************************************/
1578
1579void AliRunLoader::UnloadTracks(Option_t* detectors)
1580{
1581 //unloads Tracks for detectors specified in parameter
1582 TObjArray* loaders;
1583 TObjArray arr;
1584
1585 const char* oAll = strstr(detectors,"all");
1586 if (oAll)
1587 {
1588 loaders = fLoaders;
1589 }
1590 else
1591 {
1592 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1593 loaders = &arr;//get the pointer to array
1594 }
1595
1596 TIter next(loaders);
1597 AliLoader *loader;
1598 while((loader = (AliLoader*)next()))
1599 {
1600 loader->UnloadTracks();
1601 }
1602}
1603/**************************************************************************/
1604
1605void AliRunLoader::UnloadRecParticles(Option_t* detectors)
1606{
1607 //unloads Particles for detectors specified in parameter
1608 TObjArray* loaders;
1609 TObjArray arr;
1610
1611 const char* oAll = strstr(detectors,"all");
1612 if (oAll)
1613 {
1614 loaders = fLoaders;
1615 }
1616 else
1617 {
1618 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1619 loaders = &arr;//get the pointer to array
1620 }
1621
1622 TIter next(loaders);
1623 AliLoader *loader;
1624 while((loader = (AliLoader*)next()))
1625 {
1626 loader->UnloadRecParticles();
1627 }
1628}
88cb7938 1629/**************************************************************************/
1630
1631AliRunLoader* AliRunLoader::GetRunLoader(const char* eventfoldername)
f2a509af 1632{
1633//returns RunLoader from folder named eventfoldername
88cb7938 1634 TFolder* evfold= dynamic_cast<TFolder*>(AliConfig::Instance()->GetTopFolder()->FindObject(eventfoldername));
1635 if (evfold == 0x0)
1636 {
1637 return 0x0;
1638 }
1639 AliRunLoader* runget = dynamic_cast<AliRunLoader*>(evfold->FindObject(AliRunLoader::fgkRunLoaderName));
1640 return runget;
1641
f2a509af 1642}
88cb7938 1643/**************************************************************************/
1644
1bb20a37 1645AliLoader* AliRunLoader::GetDetectorLoader(const char* detname, const char* eventfoldername)
8de97894 1646{
1647//get the loader of the detector with the given name from the global
1648//run loader object
1bb20a37 1649 AliRunLoader* runLoader = GetRunLoader(eventfoldername);
8de97894 1650 if (!runLoader) {
21bf7095 1651 AliErrorClass("No run loader found");
8de97894 1652 return NULL;
1653 }
1bb20a37 1654 return runLoader->GetDetectorLoader(detname);
1655}
1656/**************************************************************************/
1657
1658AliLoader* AliRunLoader::GetDetectorLoader(const char* detname)
1659{
1660//get the loader of the detector with the given name from the global
1661//run loader object
1662
8de97894 1663 char loadername[256];
1664 sprintf(loadername, "%sLoader", detname);
1bb20a37 1665 AliLoader* loader = GetLoader(loadername);
8de97894 1666 if (!loader) {
21bf7095 1667 AliError(Form("No loader for %s found", detname));
8de97894 1668 return NULL;
1669 }
1670 return loader;
1671}
1bb20a37 1672/**************************************************************************/
1673
1674TTree* AliRunLoader::GetTreeH(const char* detname, Bool_t maketree, const char* eventfoldername)
1675{
1676//get the tree with hits of the detector with the given name
1677//if maketree is true and the tree does not exist, the tree is created
1678 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1679 if (!loader) return NULL;
1680 if (!loader->TreeH() && maketree) loader->MakeTree("H");
1681 return loader->TreeH();
1682}
8de97894 1683
1684/**************************************************************************/
1685
1686TTree* AliRunLoader::GetTreeH(const char* detname, Bool_t maketree)
1687{
1688//get the tree with hits of the detector with the given name
1689//if maketree is true and the tree does not exist, the tree is created
1690 AliLoader* loader = GetDetectorLoader(detname);
1691 if (!loader) return NULL;
1692 if (!loader->TreeH() && maketree) loader->MakeTree("H");
1693 return loader->TreeH();
1694}
1bb20a37 1695/**************************************************************************/
8de97894 1696
1bb20a37 1697TTree* AliRunLoader::GetTreeS(const char* detname, Bool_t maketree,const char* eventfoldername)
1698{
1699//get the tree with summable digits of the detector with the given name
1700//if maketree is true and the tree does not exist, the tree is created
1701 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1702 if (!loader) return NULL;
1703 if (!loader->TreeS() && maketree) loader->MakeTree("S");
1704 return loader->TreeS();
1705}
8de97894 1706/**************************************************************************/
1707
1708TTree* AliRunLoader::GetTreeS(const char* detname, Bool_t maketree)
1709{
1710//get the tree with summable digits of the detector with the given name
1711//if maketree is true and the tree does not exist, the tree is created
1712 AliLoader* loader = GetDetectorLoader(detname);
1713 if (!loader) return NULL;
1714 if (!loader->TreeS() && maketree) loader->MakeTree("S");
1715 return loader->TreeS();
1716}
1bb20a37 1717/**************************************************************************/
8de97894 1718
1bb20a37 1719TTree* AliRunLoader::GetTreeD(const char* detname, Bool_t maketree,const char* eventfoldername)
1720{
1721//get the tree with digits of the detector with the given name
1722//if maketree is true and the tree does not exist, the tree is created
1723 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1724 if (!loader) return NULL;
1725 if (!loader->TreeD() && maketree) loader->MakeTree("D");
1726 return loader->TreeD();
1727}
8de97894 1728/**************************************************************************/
1729
1730TTree* AliRunLoader::GetTreeD(const char* detname, Bool_t maketree)
1731{
1732//get the tree with digits of the detector with the given name
1733//if maketree is true and the tree does not exist, the tree is created
1734 AliLoader* loader = GetDetectorLoader(detname);
1735 if (!loader) return NULL;
1736 if (!loader->TreeD() && maketree) loader->MakeTree("D");
1737 return loader->TreeD();
1738}
1bb20a37 1739/**************************************************************************/
1740TTree* AliRunLoader::GetTreeR(const char* detname, Bool_t maketree,const char* eventfoldername)
1741{
1742//get the tree with clusters of the detector with the given name
1743//if maketree is true and the tree does not exist, the tree is created
1744 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1745 if (!loader) return NULL;
1746 if (!loader->TreeR() && maketree) loader->MakeTree("R");
1747 return loader->TreeR();
1748}
8de97894 1749/**************************************************************************/
1750
1751TTree* AliRunLoader::GetTreeR(const char* detname, Bool_t maketree)
1752{
1753//get the tree with clusters of the detector with the given name
1754//if maketree is true and the tree does not exist, the tree is created
1755 AliLoader* loader = GetDetectorLoader(detname);
1756 if (!loader) return NULL;
1757 if (!loader->TreeR() && maketree) loader->MakeTree("R");
1758 return loader->TreeR();
1759}
1bb20a37 1760/**************************************************************************/
8de97894 1761
1bb20a37 1762TTree* AliRunLoader::GetTreeT(const char* detname, Bool_t maketree,const char* eventfoldername)
1763{
1764//get the tree with tracks of the detector with the given name
1765//if maketree is true and the tree does not exist, the tree is created
1766 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1767 if (!loader) return NULL;
1768 if (!loader->TreeT() && maketree) loader->MakeTree("T");
1769 return loader->TreeT();
1770}
8de97894 1771/**************************************************************************/
1772
1773TTree* AliRunLoader::GetTreeT(const char* detname, Bool_t maketree)
1774{
1775//get the tree with tracks of the detector with the given name
1776//if maketree is true and the tree does not exist, the tree is created
1777 AliLoader* loader = GetDetectorLoader(detname);
1778 if (!loader) return NULL;
1779 if (!loader->TreeT() && maketree) loader->MakeTree("T");
1780 return loader->TreeT();
1781}
1bb20a37 1782/**************************************************************************/
8de97894 1783
1bb20a37 1784TTree* AliRunLoader::GetTreeP(const char* detname, Bool_t maketree,const char* eventfoldername)
1785{
1786//get the tree with particles of the detector with the given name
1787//if maketree is true and the tree does not exist, the tree is created
1788 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1789 if (!loader) return NULL;
1790 if (!loader->TreeP() && maketree) loader->MakeTree("P");
1791 return loader->TreeP();
1792}
8de97894 1793/**************************************************************************/
1794
1795TTree* AliRunLoader::GetTreeP(const char* detname, Bool_t maketree)
1796{
1797//get the tree with particles of the detector with the given name
1798//if maketree is true and the tree does not exist, the tree is created
1799 AliLoader* loader = GetDetectorLoader(detname);
1800 if (!loader) return NULL;
1801 if (!loader->TreeP() && maketree) loader->MakeTree("P");
1802 return loader->TreeP();
1803}
1804
1805/**************************************************************************/
1806
88cb7938 1807void AliRunLoader::CdGAFile()
1808{
1809//sets gDirectory to galice file
1810//work around
1811 if(fGAFile) fGAFile->cd();
1812}
1813
1814/**************************************************************************/
1815
1816void AliRunLoader::GetListOfDetectors(const char * namelist,TObjArray& pointerarray) const
1817 {
1818//this method looks for all Loaders corresponding
1819//to names (many) specified in namelist i.e. namelist ("ITS TPC TRD")
1820
1821 char buff[10];
1822 char dets [200];
1823 strcpy(dets,namelist);//compiler cries when char* = const Option_t*;
1824 dets[strlen(dets)+1] = '\n';//set endl at the end of string
1825 char* pdet = dets;
1826 Int_t tmp;
1827 for(;;)
1828 {
1829 tmp = sscanf(pdet,"%s",buff);//read the string from the input string pdet into buff
1830 if ( (buff[0] == 0) || (tmp == 0) ) break; //if not read
1831
f2a509af 1832 pdet = strstr(pdet,buff) + strlen(buff);//move the input pointer about number of bytes (letters) read
88cb7938 1833 //I am aware that is a little complicated. I don't know the number of spaces between detector names
1834 //so I read the string, than I find where it starts (strstr) and move the pointer about length of a string
1835 //If there is a better way, please write me (Piotr.Skowronski@cern.ch)
1836 //construct the Loader name
1837 TString getname(buff);
1838 getname+="Loader";
1839 AliLoader* loader = GetLoader(getname);//get the Loader
1840 if (loader)
1841 {
1842 pointerarray.Add(loader);
1843 }
1844 else
1845 {
21bf7095 1846 AliError(Form("Can not find Loader for %s",buff));
88cb7938 1847 }
1848
1849 buff[0] = 0;
1850 }
1851 }
1852/*****************************************************************************/
1853
1854void AliRunLoader::Clean(const TString& name)
1855{
1856//removes object with given name from event folder and deletes it
1857 if (GetEventFolder() == 0x0) return;
1858 TObject* obj = GetEventFolder()->FindObject(name);
1859 if(obj)
1860 {
21bf7095 1861 AliDebug(1, Form("name=%s, cleaning %s.",GetName(),name.Data()));
88cb7938 1862 GetEventFolder()->Remove(obj);
1863 delete obj;
bacbe0fd 1864 obj = 0x0;
88cb7938 1865 }
1866}
1867
1868/*****************************************************************************/
1869
1870TTask* AliRunLoader::GetRunDigitizer()
1871{
1872//returns Run Digitizer from folder
1873
1874 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1875 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetDigitizerTaskName());
1876 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1877}
1878/*****************************************************************************/
1879
1880TTask* AliRunLoader::GetRunSDigitizer()
1881{
1882//returns SDigitizer Task from folder
1883
1884 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1885 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetSDigitizerTaskName());
1886 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1887}
1888/*****************************************************************************/
1889
1890TTask* AliRunLoader::GetRunReconstructioner()
1891{
1892//returns Reconstructioner Task from folder
1893 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1894 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetReconstructionerTaskName());
1895 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1896}
1897/*****************************************************************************/
1898
1899TTask* AliRunLoader::GetRunTracker()
1900{
1901//returns Tracker Task from folder
1902 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1903 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetTrackerTaskName());
1904 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1905}
1906/*****************************************************************************/
1907
1908TTask* AliRunLoader::GetRunPIDTask()
1909{
1910//returns Tracker Task from folder
1911 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1912 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetPIDTaskName());
1913 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1914}
1915/*****************************************************************************/
1916
1917TTask* AliRunLoader::GetRunQATask()
1918{
1919//returns Quality Assurance Task from folder
1920 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1921 if (topf == 0x0)
1922 {
21bf7095 1923 AliErrorClass("Can not get task folder from AliConfig");
88cb7938 1924 return 0x0;
1925 }
1926 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetQATaskName());
1927 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1928}
1929
1930/*****************************************************************************/
1931
1932void AliRunLoader::SetCompressionLevel(Int_t cl)
1933{
1934//Sets Compression Level in all files
1935 if (fGAFile) fGAFile->SetCompressionLevel(cl);
1936 SetKineComprLevel(cl);
1937 SetTrackRefsComprLevel(cl);
1938 TIter next(fLoaders);
1939 AliLoader *loader;
1940 while((loader = (AliLoader*)next()))
1941 {
1942 loader->SetCompressionLevel(cl);
1943 }
1944}
1945/**************************************************************************/
1946
1947void AliRunLoader::SetKineComprLevel(Int_t cl)
1948{
1949//Sets comression level in Kine File
1950 fKineDataLoader->SetCompressionLevel(cl);
1951}
1952/**************************************************************************/
1953
1954void AliRunLoader::SetTrackRefsComprLevel(Int_t cl)
1955{
1956//Sets comression level in Track Refences File
1957 fTrackRefsDataLoader->SetCompressionLevel(cl);
1958}
1959/**************************************************************************/
1960
1961void AliRunLoader::UnloadHeader()
1962{
1963 //removes TreeE from folder and deletes it
1964 // as well as fHeader object
1965 CleanHeader();
88cb7938 1966 fHeader = 0x0;
1967}
1968/**************************************************************************/
1969
bacbe0fd 1970void AliRunLoader::UnloadTrigger()
1971{
1972 //removes TreeCT from folder and deletes it
1973 // as well as fHeader object
1974 CleanTrigger();
1975 delete fCTrigger;
1976 fCTrigger = 0x0;
1977}
1978
1979/**************************************************************************/
1980
88cb7938 1981void AliRunLoader::UnloadKinematics()
1982{
f2a509af 1983//Unloads Kinematics
88cb7938 1984 fKineDataLoader->GetBaseLoader(0)->Unload();
1985}
1986/**************************************************************************/
1987
1988void AliRunLoader::UnloadTrackRefs()
1989{
f2a509af 1990//Unloads Track Refernces
88cb7938 1991 fTrackRefsDataLoader->GetBaseLoader(0)->Unload();
1992}
1993/**************************************************************************/
1994
1995void AliRunLoader::UnloadgAlice()
1996{
f2a509af 1997//Unloads gAlice
88cb7938 1998 if (gAlice == GetAliRun())
1999 {
21bf7095 2000 AliDebug(1, "Set gAlice = 0x0");
88cb7938 2001 gAlice = 0x0;//if gAlice is the same that in folder (to be deleted by the way of folder)
2002 }
2003 AliRun* alirun = GetAliRun();
2004 if (GetEventFolder()) GetEventFolder()->Remove(alirun);
2005 delete alirun;
2006}
2007/**************************************************************************/
2008
2009void AliRunLoader::MakeTrackRefsContainer()
2010{
2011// Makes a tree for Track References
2012 fTrackRefsDataLoader->MakeTree();
2013}
2014/**************************************************************************/
2015
2016Int_t AliRunLoader::LoadTrackRefs(Option_t* option)
2017{
2018//Load track references from file (opens file and posts tree to folder)
2019
f2a509af 2020 return fTrackRefsDataLoader->GetBaseLoader(0)->Load(option);
88cb7938 2021}
2022/**************************************************************************/
2023
2024void AliRunLoader::SetDirName(TString& dirname)
2025{
2026//sets directory name
2027 if (dirname.IsNull()) return;
2028 fUnixDirName = dirname;
2029 fKineDataLoader->SetDirName(dirname);
2030 fTrackRefsDataLoader->SetDirName(dirname);
2031
2032 TIter next(fLoaders);
2033 AliLoader *loader;
2034 while((loader = (AliLoader*)next()))
2035 {
2036 loader->SetDirName(dirname);
2037 }
2038
2039}
2040/*****************************************************************************/
2041
2042Int_t AliRunLoader::GetFileOffset() const
2043{
f2a509af 2044//returns the file number that is added to the file name for current event
88cb7938 2045 return Int_t(fCurrentEvent/fNEventsPerFile);
2046}
2047
2048/*****************************************************************************/
2049const TString AliRunLoader::SetFileOffset(const TString& fname)
2050{
f2a509af 2051//adds the the number to the file name at proper place for current event
88cb7938 2052 Long_t offset = (Long_t)GetFileOffset();
2053 if (offset < 1) return fname;
2054 TString soffset;
2055 soffset += offset;//automatic conversion to string
2056 TString dotroot(".root");
2057 const TString& offfsetdotroot = offset + dotroot;
2058 TString out = fname;
2059 out = out.ReplaceAll(dotroot,offfsetdotroot);
21bf7095 2060 AliDebug(1, Form(" in=%s out=%s",fname.Data(),out.Data()));
88cb7938 2061 return out;
2062}
2063/*****************************************************************************/
2064
2065void AliRunLoader::SetDigitsFileNameSuffix(const TString& suffix)
2066{
2067//adds the suffix before ".root",
2068//e.g. TPC.Digits.root -> TPC.DigitsMerged.root
2069//made on Jiri Chudoba demand
2070
2071 TIter next(fLoaders);
d0d4a6b3 2072 AliLoader *loader;
2073 while((loader = (AliLoader*)next()))
88cb7938 2074 {
d0d4a6b3 2075 loader->SetDigitsFileNameSuffix(suffix);
88cb7938 2076 }
2077}
2078/*****************************************************************************/
2079
2080TString AliRunLoader::GetFileName() const
2081{
2082//returns name of galice file
2083 TString result;
2084 if (fGAFile == 0x0) return result;
2085 result = fGAFile->GetName();
2086 return result;
2087}
2088/*****************************************************************************/
2089
2090void AliRunLoader::SetDetectorAddresses()
2091{
2092 //calls SetTreeAddress for all detectors
2093 if (GetAliRun()==0x0) return;
2094 TIter next(GetAliRun()->Modules());
2095 AliModule* mod;
2096 while((mod = (AliModule*)next()))
2097 {
2098 AliDetector* det = dynamic_cast<AliDetector*>(mod);
2099 if (det) det->SetTreeAddress();
2100 }
2101}
2102/*****************************************************************************/
f0f6f856 2103
2104void AliRunLoader::Synchronize()
2105{
2106 //synchrinizes all writtable files
2107 TIter next(fLoaders);
2108 AliLoader *loader;
2109 while((loader = (AliLoader*)next()))
2110 {
2111 loader->Synchronize();
2112 }
2113
2114 fKineDataLoader->Synchronize();
2115 fTrackRefsDataLoader->Synchronize();
bacbe0fd 2116
2117 TFile* file = gROOT->GetFile( gSystem->ConcatFileName( fUnixDirName.Data(), fgkDefaultTriggerFileName.Data() ) ) ;
2118 if( file ) file->Flush();
f0f6f856 2119
504b172d 2120 if (fGAFile) fGAFile->Flush();
f0f6f856 2121}
88cb7938 2122/*****************************************************************************/
2123/*****************************************************************************/