1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //____________________________________________________________________
19 //////////////////////////////////////////////////////////////////////
21 // class AliRunLoader //
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. //
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. //
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. //
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 //
42 // AliConfig::GetDefaultEventFolderName() //
43 // but can be mounted elsewhere. Usefull specially in merging case, //
44 // when more than pone session needs to be loaded //
46 //////////////////////////////////////////////////////////////////////
48 #include "AliRunLoader.h"
51 #include "AliLoader.h"
52 #include "AliHeader.h"
54 #include "AliDetector.h"
55 #include "AliCDBManager.h"
56 #include "AliCDBLocal.h"
57 #include "AliCentralTrigger.h"
64 #include <TObjArray.h>
68 ClassImp(AliRunLoader)
70 AliRunLoader* AliRunLoader::fgRunLoader = 0x0;
72 const TString AliRunLoader::fgkRunLoaderName("RunLoader");
73 const TString AliRunLoader::fgkHeaderBranchName("Header");
74 const TString AliRunLoader::fgkTriggerBranchName("ClassMask");
75 const TString AliRunLoader::fgkHeaderContainerName("TE");
76 const TString AliRunLoader::fgkTriggerContainerName("TreeCT");
77 const TString AliRunLoader::fgkKineContainerName("TreeK");
78 const TString AliRunLoader::fgkTrackRefsContainerName("TreeTR");
79 const TString AliRunLoader::fgkKineBranchName("Particles");
80 const TString AliRunLoader::fgkDefaultKineFileName("Kinematics.root");
81 const TString AliRunLoader::fgkDefaultTrackRefsFileName("TrackRefs.root");
82 const TString AliRunLoader::fgkGAliceName("gAlice");
83 const TString AliRunLoader::fgkDefaultTriggerFileName("Trigger.root");
84 /**************************************************************************/
86 AliRunLoader::AliRunLoader():
96 fTrackRefsDataLoader(0x0),
101 AliConfig::Instance();//force to build the folder structure
102 if (!fgRunLoader) fgRunLoader = this;
104 /**************************************************************************/
106 AliRunLoader::AliRunLoader(const char* eventfoldername):
107 TNamed(fgkRunLoaderName,fgkRunLoaderName),
108 fLoaders(new TObjArray()),
116 fKineDataLoader(new AliDataLoader(fgkDefaultKineFileName,fgkKineContainerName,"Kinematics")),
117 fTrackRefsDataLoader(new AliDataLoader(fgkDefaultTrackRefsFileName,fgkTrackRefsContainerName,"Track References")),
123 SetEventFolderName(eventfoldername);
124 if (!fgRunLoader) fgRunLoader = this;
126 /**************************************************************************/
128 AliRunLoader::~AliRunLoader()
135 if (fgRunLoader == this) fgRunLoader = 0x0;
137 fLoaders->SetOwner();
141 delete fKineDataLoader;
142 delete fTrackRefsDataLoader;
147 //fEventFolder is deleted by the way of removing - TopAliceFolder owns it
148 if( fCTrigger ) delete fCTrigger;
152 /**************************************************************************/
154 AliRunLoader::AliRunLoader(TFolder* topfolder):
155 TNamed(fgkRunLoaderName,fgkRunLoaderName),
156 fLoaders(new TObjArray()),
157 fEventFolder(topfolder),
164 fKineDataLoader(new AliDataLoader(fgkDefaultKineFileName,fgkKineContainerName,"Kinematics")),
165 fTrackRefsDataLoader(new AliDataLoader(fgkDefaultTrackRefsFileName,fgkTrackRefsContainerName,"Track References")),
173 TString errmsg("Parameter is NULL");
174 AliError(errmsg.Data());
179 TObject* obj = fEventFolder->FindObject(fgkRunLoaderName);
181 { //if it is, then sth. is going wrong... exits aliroot session
182 TString errmsg("In Event Folder Named ");
183 errmsg+=fEventFolder->GetName();
184 errmsg+=" object named "+fgkRunLoaderName+" already exists. I am confused ...";
186 AliError(errmsg.Data());
188 return;//never reached
191 if (!fgRunLoader) fgRunLoader = this;
193 fEventFolder->Add(this);//put myself to the folder to accessible for all
197 /**************************************************************************/
199 Int_t AliRunLoader::GetEvent(Int_t evno)
201 //Gets event number evno
202 //Reloads all data properly
203 //PH if (fCurrentEvent == evno) return 0;
207 AliError("Can not give the event with negative number");
211 if (evno >= GetNumberOfEvents())
213 AliError(Form("There is no event with number %d",evno));
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, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
225 fCurrentEvent = evno;
229 //Reload header (If header was loaded)
232 retval = TreeE()->GetEvent(fCurrentEvent);
235 AliError(Form("Cannot find event: %d\n ",fCurrentEvent));
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)
242 if( GetTrigger() && TreeCT() ) {
243 retval = TreeCT()->GetEvent(fCurrentEvent);
245 AliError(Form("Error occured while GetEvent for Trigger. Event %d",evno));
253 AliError(Form("Error occured while setting event %d",evno));
257 //Post Track References
258 retval = fTrackRefsDataLoader->GetEvent();
261 AliError(Form("Error occured while GetEvent for Track References. Event %d",evno));
265 //Read Kinematics if loaded
266 retval = fKineDataLoader->GetEvent();
269 AliError(Form("Error occured while GetEvent for Kinematics. Event %d",evno));
273 if (fStack && fKineDataLoader->GetBaseLoader(0)->IsLoaded())
275 fStack->ConnectTree(TreeK());
277 if (fStack->GetEvent() == kFALSE)
279 AliError(Form("Error occured while GetEvent for Stack. Event %d",evno));
284 //Trigger data reloading in all loaders
285 TIter next(fLoaders);
287 while((loader = (AliLoader*)next()))
289 retval = loader->GetEvent();
292 AliError(Form("Error occured while getting event for %s. Event %d.",
293 loader->GetDetectorName().Data(), evno));
298 SetDetectorAddresses();
302 /**************************************************************************/
303 Int_t AliRunLoader::SetEvent()
305 //if kinematics was loaded Cleans folder data
309 retval = fKineDataLoader->SetEvent();
312 AliError("SetEvent for Kinamtics Data Loader retutned error.");
315 retval = fTrackRefsDataLoader->SetEvent();
318 AliError("SetEvent for Track References Data Loader retutned error.");
322 TIter next(fLoaders);
324 while((loader = (AliLoader*)next()))
326 retval = loader->SetEvent();
329 AliError(Form("SetEvent for %s Data Loader retutned error.",loader->GetName()));
336 /**************************************************************************/
338 Int_t AliRunLoader::SetEventNumber(Int_t evno)
340 //cleans folders and sets the root dirs in files
341 if (fCurrentEvent == evno) return 0;
342 fCurrentEvent = evno;
346 /**************************************************************************/
347 AliCDBEntry* AliRunLoader::GetCDBEntry(const char* name) const
349 //Get an AliCDBEntry from the run data storage
351 if ( !(AliCDBManager::Instance()->IsDefaultStorageSet()) ) {
352 AliError("No run data storage defined!");
355 return AliCDBManager::Instance()->GetDefaultStorage()->Get(name, GetHeader()->GetRun());
359 /**************************************************************************/
360 AliRunLoader* AliRunLoader::Open
361 (const char* filename, const char* eventfoldername, Option_t* option)
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
368 static const TString kwebaddress("http://alisoft.cern.ch/people/skowron/codedoc/split/index.html");
369 AliDebugClass(1,Form("\n\n\nNew I/O strcture: See more info:\n %s\n\n\n",kwebaddress.Data()));
371 AliRunLoader* result = 0x0;
373 /* ************************************************ */
374 /* Chceck if folder with given name already exists */
375 /* ************************************************ */
377 TObject* obj = AliConfig::Instance()->GetTopFolder()->FindObject(eventfoldername);
380 TFolder* fold = dynamic_cast<TFolder*>(obj);
383 AliErrorClass("Such a obejct already exists in top alice folder and it is not a folder.");
387 //check if we can get RL from that folder
388 result = AliRunLoader::GetRunLoader(eventfoldername);
391 AliErrorClass(Form("Folder %s already exists, and can not find session there. Can not mount.",eventfoldername));
395 if (result->GetFileName().CompareTo(filename) != 0)
397 AliErrorClass("Other file is mounted in demanded folder. Can not mount.");
401 //check if now is demanded (re)creation
402 if ( AliLoader::TestFileOption(option) == kFALSE)
404 AliErrorClass(Form("Session already exists in folder %s and this session option is %s. Unable to proceed.",
405 eventfoldername,option));
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) )
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));
419 AliWarningClass("Session is already opened and mounted in demanded folder");
420 if (!fgRunLoader) fgRunLoader = result; //PH get access from any place
422 } //end of checking in case of existance of object named identically that folder session is being opened
425 TFile * gAliceFile = TFile::Open(filename,option);//open a file
427 {//null pointer returned
428 AliFatalClass(Form("Can not open file %s.",filename));
432 if (gAliceFile->IsOpen() == kFALSE)
433 {//pointer to valid object returned but file is not opened
434 AliErrorClass(Form("Can not open file %s.",filename));
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) )
442 AliDebugClass(1, "Reading RL from file");
444 result = dynamic_cast<AliRunLoader*>(gAliceFile->Get(fgkRunLoaderName));//get the run Loader from the file
447 AliErrorClass(Form("Can not find run-Loader in file %s.",filename));
448 delete gAliceFile;//close the file
451 Int_t tmp = result->SetEventFolderName(eventfoldername);//mount a event folder
452 if (tmp)//if SetEvent returned error
454 AliErrorClass(Form("Can not mount event in folder %s.",eventfoldername));
455 delete result; //delete run-Loader
456 delete gAliceFile;//close the file
462 AliDebugClass(1, Form("Creating new AliRunLoader. Folder name is %s",eventfoldername));
465 result = new AliRunLoader(eventfoldername);
467 catch (TString& errmsg)
469 AliErrorClass(Form("AliRunLoader constrcutor has thrown exception: %s\n",errmsg.Data()));
471 delete gAliceFile;//close the file
476 //procedure for extracting dir name from the file name
477 TString fname(filename);
478 Int_t nsl = fname.Last('#');//look for hash in file name
480 if (nsl < 0) {//hash not found
481 nsl = fname.Last('/');// look for slash
483 nsl = fname.Last(':');// look for colon e.g. rfio:galice.root
486 if (nsl < 0) dirname = "./"; // no directory path, use "."
487 else dirname = fname.Remove(nsl+1);// directory path
489 AliDebugClass(1, Form("Dir name is : %s",dirname.Data()));
491 result->SetDirName(dirname);
492 result->SetGAliceFile(gAliceFile);//set the pointer to gAliceFile
493 if (!fgRunLoader) fgRunLoader = result; //PH get access from any place
496 /**************************************************************************/
497 Int_t AliRunLoader::GetNumberOfEvents()
499 //returns number of events in Run
503 retval = LoadHeader();
506 AliError("Error occured while loading header");
510 return (Int_t)TreeE()->GetEntries();
512 /**************************************************************************/
514 void AliRunLoader::MakeHeader()
516 //Makes header and connects it to header tree (if it exists)
520 AliDebug(1, "Creating new Header Object");
521 fHeader= new AliHeader();
523 TTree* tree = TreeE();
526 AliDebug(1, "Got Tree from folder.");
527 TBranch* branch = tree->GetBranch(fgkHeaderBranchName);
530 AliDebug(1, "Creating new branch");
531 branch = tree->Branch(fgkHeaderBranchName, "AliHeader", &fHeader, 4000, 0);
532 branch->SetAutoDelete(kFALSE);
536 AliDebug(1, "Got Branch from Tree");
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
543 fStack->ConnectTree(TreeK());
549 AliDebug(1, "Header does not have a stack.");
553 AliDebug(1, "Exiting MakeHeader method");
555 /**************************************************************************/
557 void AliRunLoader::MakeStack()
559 //Creates the stack object - do not connect the tree
562 fStack = new AliStack(10000);
565 /**************************************************************************/
567 void AliRunLoader::MakeTrigger()
569 // Makes trigger object and connects it to trigger tree (if it exists)
571 if( fCTrigger == 0x0 ) {
572 AliDebug( 1, "Creating new Trigger Object" );
573 fCTrigger = new AliCentralTrigger();
575 TTree* tree = TreeCT();
577 fCTrigger->MakeBranch( fgkTriggerBranchName, tree );
578 tree->GetEvent( fCurrentEvent );
581 AliDebug( 1, "Exiting MakeTrigger method" );
583 /**************************************************************************/
585 void AliRunLoader::MakeTree(Option_t *option)
588 const char *oK = strstr(option,"K"); //Kine
589 const char *oE = strstr(option,"E"); //Header
590 const char *oGG = strstr(option,"GG"); //Central TriGGer
594 if (fKineDataLoader->GetBaseLoader(0)->IsLoaded() == kFALSE)
596 AliError("Load Kinematics first");
601 fKineDataLoader->MakeTree();
604 fStack->ConnectTree(TreeK());
605 WriteKinematics("OVERWRITE");
612 TTree* tree = new TTree(fgkHeaderContainerName,"Tree with Headers");
613 GetEventFolder()->Add(tree);
615 WriteHeader("OVERWRITE");
620 // create the CTP Trigger output file and tree
621 TFile* file = gROOT->GetFile( fgkDefaultTriggerFileName );
623 char* tmp = gSystem->ConcatFileName( fUnixDirName.Data(), fgkDefaultTriggerFileName.Data() );
624 file = TFile::Open(tmp , "RECREATE" ) ;
629 TTree* tree = new TTree( fgkTriggerContainerName, "Tree with Central Trigger Mask" );
630 GetEventFolder()->Add(tree);
632 // WriteHeader("OVERWRITE");
635 TIter next(fLoaders);
637 while((loader = (AliLoader*)next()))
639 loader->MakeTree(option);
643 /**************************************************************************/
645 Int_t AliRunLoader::LoadgAlice()
647 //Loads gAlice from file
650 AliWarning("AliRun is already in folder. Unload first.");
653 AliRun* alirun = dynamic_cast<AliRun*>(fGAFile->Get(fgkGAliceName));
656 AliError(Form("Can not find gAlice in file %s",fGAFile->GetName()));
659 alirun->SetRunLoader(this);
662 AliWarning(Form("gAlice already exists. Putting retrived object in folder named %s",
663 GetEventFolder()->GetName()));
669 SetDetectorAddresses();//calls SetTreeAddress for all detectors
672 /**************************************************************************/
674 Int_t AliRunLoader::LoadHeader()
676 //loads treeE and reads header object for current event
679 AliWarning("Header is already loaded. Use ReloadHeader to force reload. Nothing done");
683 if (GetEventFolder() == 0x0)
685 AliError("Event folder not specified yet");
691 AliError("Session not opened. Use AliRunLoader::Open");
695 if (fGAFile->IsOpen() == kFALSE)
697 AliError("Session not opened. Use AliRunLoader::Open");
701 TTree* tree = dynamic_cast<TTree*>(fGAFile->Get(fgkHeaderContainerName));
704 AliError(Form("Can not find header tree named %s in file %s",
705 fgkHeaderContainerName.Data(),fGAFile->GetName()));
709 if (tree == TreeE()) return 0;
712 GetEventFolder()->Add(tree);
713 MakeHeader();//creates header object and connects to tree
717 /**************************************************************************/
719 Int_t AliRunLoader::LoadTrigger(Option_t* option)
722 static Bool_t warned = kFALSE;
724 if (!warned) AliWarning("Trigger is already loaded. Nothing done. Message will not be repeated.");
729 if( GetEventFolder() == 0x0 ) {
730 AliError("Event folder not specified yet");
733 // get the CTP Trigger output file and tree
734 char* tmp = gSystem->ConcatFileName( fUnixDirName.Data(),
735 fgkDefaultTriggerFileName.Data() );
736 TString trgfile(tmp);
739 TFile* file = gROOT->GetFile( trgfile );
741 file = TFile::Open( trgfile, option ) ;
742 if (!file || file->IsOpen() == kFALSE ) {
743 AliError( Form( "Can not open trigger file %s", trgfile.Data() ) );
749 TTree* tree = dynamic_cast<TTree*>(file->Get( fgkTriggerContainerName ));
751 AliError( Form( "Can not find trigger tree named %s in file %s",
752 fgkTriggerContainerName.Data(), file->GetName() ) );
758 fCTrigger = dynamic_cast<AliCentralTrigger*>(file->Get( "AliCentralTrigger" ));
759 GetEventFolder()->Add( tree );
765 /**************************************************************************/
767 Int_t AliRunLoader::LoadKinematics(Option_t* option)
769 //Loads the kinematics
770 Int_t retval = fKineDataLoader->GetBaseLoader(0)->Load(option);
773 AliError("Error occured while loading kinamatics tree.");
778 fStack->ConnectTree(TreeK());
779 retval = fStack->GetEvent();
780 if ( retval == kFALSE)
782 AliError("Error occured while loading kinamatics tree.");
789 /**************************************************************************/
791 Int_t AliRunLoader::OpenDataFile(const TString& filename,TFile*& file,TDirectory*& dir,Option_t* opt,Int_t cl)
793 //Opens File with kinematics
796 if (file->IsOpen() == kFALSE)
797 {//pointer is not null but file is not opened
798 AliWarning("Pointer to file is not null, but file is not opened");//risky any way
800 file = 0x0; //proceed with opening procedure
804 AliWarning(Form("File %s already opened",filename.Data()));
808 //try to find if that file is opened somewere else
809 file = (TFile *)( gROOT->GetListOfFiles()->FindObject(filename) );
812 if(file->IsOpen() == kTRUE)
814 AliWarning(Form("File %s already opened by sombody else.",file->GetName()));
819 file = TFile::Open(filename,opt);
822 AliError(Form("Can not open file %s",filename.Data()));
825 if (file->IsOpen() == kFALSE)
826 {//file is not opened
827 AliError(Form("Can not open file %s",filename.Data()));
831 file->SetCompressionLevel(cl);
833 dir = AliLoader::ChangeDir(file,fCurrentEvent);
836 AliError(Form("Can not change to root directory in file %s",filename.Data()));
841 /**************************************************************************/
843 TTree* AliRunLoader::TreeE() const
845 //returns the tree from folder; shortcut method
846 if (AliDebugLevel() > 10) fEventFolder->ls();
847 TObject *obj = fEventFolder->FindObject(fgkHeaderContainerName);
848 return (obj)?dynamic_cast<TTree*>(obj):0x0;
850 /**************************************************************************/
852 TTree* AliRunLoader::TreeCT() const
854 //returns the tree from folder; shortcut method
855 if (AliDebugLevel() > 10) fEventFolder->ls();
856 TObject *obj = fEventFolder->FindObject(fgkTriggerContainerName);
857 return (obj)?dynamic_cast<TTree*>(obj):0x0;
859 /**************************************************************************/
861 AliHeader* AliRunLoader::GetHeader() const
863 //returns pointer header object
866 /**************************************************************************/
868 AliCentralTrigger* AliRunLoader::GetTrigger() const
870 //returns pointer trigger object
874 /**************************************************************************/
876 TTree* AliRunLoader::TreeK() const
878 //returns the tree from folder; shortcut method
879 TObject *obj = GetEventFolder()->FindObject(fgkKineContainerName);
880 return (obj)?dynamic_cast<TTree*>(obj):0x0;
882 /**************************************************************************/
884 TTree* AliRunLoader::TreeTR() const
886 //returns the tree from folder; shortcut method
887 TObject* obj = GetEventFolder()->FindObject(fgkTrackRefsContainerName);
888 return (obj)?dynamic_cast<TTree*>(obj):0x0;
890 /**************************************************************************/
892 AliRun* AliRunLoader::GetAliRun() const
894 //returns AliRun which sits in the folder
895 if (fEventFolder == 0x0) return 0x0;
896 TObject *obj = fEventFolder->FindObject(fgkGAliceName);
897 return (obj)?dynamic_cast<AliRun*>(obj):0x0;
899 /**************************************************************************/
901 Int_t AliRunLoader::WriteHeader(Option_t* opt)
904 AliDebug(1, "WRITING HEADER");
906 TTree* tree = TreeE();
909 AliWarning("Can not find Header Tree in Folder");
912 if (fGAFile->IsWritable() == kFALSE)
914 AliError(Form("File %s is not writable",fGAFile->GetName()));
918 TObject* obj = fGAFile->Get(fgkHeaderContainerName);
920 { //if they exist, see if option OVERWRITE is used
922 if(tmp.Contains("OVERWRITE",TString::kIgnoreCase) == 0)
923 {//if it is not used - give an error message and return an error code
924 AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
929 tree->SetDirectory(fGAFile);
930 tree->Write(0,TObject::kOverwrite);
932 AliDebug(1, "WRITTEN\n\n");
937 /**************************************************************************/
939 Int_t AliRunLoader::WriteTrigger(Option_t* opt)
942 AliDebug( 1, "WRITING TRIGGER" );
944 TTree* tree = TreeCT();
946 AliWarning("Can not find Trigger Tree in Folder");
950 TFile* file = gROOT->GetFile( gSystem->ConcatFileName( fUnixDirName.Data(), fgkDefaultTriggerFileName.Data() ) ) ;
951 if( !file || !file->IsOpen() ) {
952 AliError( "can't write Trigger, file is not open" );
956 TObject* obj = file->Get( fgkTriggerContainerName );
957 if( obj ) { //if they exist, see if option OVERWRITE is used
959 if( tmp.Contains( "OVERWRITE", TString::kIgnoreCase ) == 0) {
960 //if it is not used - give an error message and return an error code
961 AliError( "Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data" );
966 fCTrigger->Write( 0, TObject::kOverwrite );
967 tree->Write( 0, TObject::kOverwrite );
970 AliDebug(1, "WRITTEN\n\n");
974 /**************************************************************************/
976 Int_t AliRunLoader::WriteAliRun(Option_t* /*opt*/)
978 //writes AliRun object to the file
980 if (GetAliRun()) GetAliRun()->Write();
983 /**************************************************************************/
985 Int_t AliRunLoader::WriteKinematics(Option_t* opt)
988 return fKineDataLoader->GetBaseLoader(0)->WriteData(opt);
990 /**************************************************************************/
991 Int_t AliRunLoader::WriteTrackRefs(Option_t* opt)
993 //writes Track References tree
994 return fTrackRefsDataLoader->GetBaseLoader(0)->WriteData(opt);
996 /**************************************************************************/
998 Int_t AliRunLoader::WriteHits(Option_t* opt)
1000 //Calls WriteHits for all loaders
1003 TIter next(fLoaders);
1005 while((loader = (AliLoader*)next()))
1007 res = loader->WriteHits(opt);
1010 AliError(Form("Failed to write hits for %s (%d)",loader->GetDetectorName().Data(),res));
1016 /**************************************************************************/
1018 Int_t AliRunLoader::WriteSDigits(Option_t* opt)
1020 //Calls WriteSDigits for all loaders
1023 TIter next(fLoaders);
1025 while((loader = (AliLoader*)next()))
1027 res = loader->WriteSDigits(opt);
1030 AliError(Form("Failed to write summable digits for %s.",loader->GetDetectorName().Data()));
1036 /**************************************************************************/
1038 Int_t AliRunLoader::WriteDigits(Option_t* opt)
1040 //Calls WriteDigits for all loaders
1043 TIter next(fLoaders);
1045 while((loader = (AliLoader*)next()))
1047 res = loader->WriteDigits(opt);
1050 AliError(Form("Failed to write digits for %s.",loader->GetDetectorName().Data()));
1056 /**************************************************************************/
1058 Int_t AliRunLoader::WriteRecPoints(Option_t* opt)
1060 //Calls WriteRecPoints for all loaders
1063 TIter next(fLoaders);
1065 while((loader = (AliLoader*)next()))
1067 res = loader->WriteRecPoints(opt);
1070 AliError(Form("Failed to write Reconstructed Points for %s.",
1071 loader->GetDetectorName().Data()));
1077 /**************************************************************************/
1079 Int_t AliRunLoader::WriteTracks(Option_t* opt)
1081 //Calls WriteTracks for all loaders
1084 TIter next(fLoaders);
1086 while((loader = (AliLoader*)next()))
1088 res = loader->WriteTracks(opt);
1091 AliError(Form("Failed to write Tracks for %s.",
1092 loader->GetDetectorName().Data()));
1098 /**************************************************************************/
1100 Int_t AliRunLoader::WriteRunLoader(Option_t* /*opt*/)
1102 //Writes itself to the file
1104 this->Write(0,TObject::kOverwrite);
1107 /**************************************************************************/
1109 Int_t AliRunLoader::SetEventFolderName(const TString& name)
1111 //sets top folder name for this run; of alread
1114 AliError("Name is empty");
1118 //check if such a folder already exists - try to find it in alice top folder
1119 TObject* obj = AliConfig::Instance()->GetTopFolder()->FindObject(name);
1122 TFolder* fold = dynamic_cast<TFolder*>(obj);
1125 AliError("Such a obejct already exists in top alice folder and it is not a folder.");
1128 //folder which was found is our folder
1129 if (fEventFolder == fold)
1135 AliError("Such a folder already exists in top alice folder. Can not mount.");
1140 //event is alredy connected, just change name of the folder
1143 fEventFolder->SetName(name);
1147 if (fKineDataLoader == 0x0)
1148 fKineDataLoader = new AliDataLoader(fgkDefaultKineFileName,fgkKineContainerName,"Kinematics");
1150 if ( fTrackRefsDataLoader == 0x0)
1151 fTrackRefsDataLoader = new AliDataLoader(fgkDefaultTrackRefsFileName,fgkTrackRefsContainerName,"Track References");
1153 //build the event folder structure
1154 AliDebug(1, Form("Creating new event folder named %s",name.Data()));
1155 fEventFolder = AliConfig::Instance()->BuildEventFolder(name,"Event Folder");
1156 fEventFolder->Add(this);//put myself to the folder to accessible for all
1158 TIter next(fLoaders);
1160 while((loader = (AliLoader*)next()))
1162 loader->Register(fEventFolder);//build folder structure for this detector
1165 fKineDataLoader->SetEventFolder(GetEventFolder());
1166 fTrackRefsDataLoader->SetEventFolder(GetEventFolder());
1167 fKineDataLoader->SetFolder(GetEventFolder());
1168 fTrackRefsDataLoader->SetFolder(GetEventFolder());
1170 fEventFolder->SetOwner();
1173 /**************************************************************************/
1175 void AliRunLoader::AddLoader(AliLoader* loader)
1177 //Adds the Loader for given detector
1178 if (loader == 0x0) //if null shout and exit
1180 AliError("Parameter is NULL");
1183 loader->SetDirName(fUnixDirName);
1184 if (fEventFolder) loader->SetEventFolder(fEventFolder); //if event folder is already defined,
1185 //pass information to the Loader
1186 fLoaders->Add(loader);//add the Loader to the array
1188 /**************************************************************************/
1190 void AliRunLoader::AddLoader(AliDetector* det)
1192 //Asks module (detector) ro make a Loader and stores in the array
1193 if (det == 0x0) return;
1194 AliLoader* get = det->GetLoader();//try to get loader
1195 if (get == 0x0) get = det->MakeLoader(fEventFolder->GetName());//if did not obtain, ask to make it
1199 AliDebug(1, Form("Detector: %s Loader : %s",det->GetName(),get->GetName()));
1204 /**************************************************************************/
1206 AliLoader* AliRunLoader::GetLoader(const char* detname) const
1208 //returns loader for given detector
1209 //note that naming convention is TPCLoader not just TPC
1210 return (AliLoader*)fLoaders->FindObject(detname);
1213 /**************************************************************************/
1215 AliLoader* AliRunLoader::GetLoader(AliDetector* det) const
1217 //get loader for detector det
1218 if(det == 0x0) return 0x0;
1219 TString getname(det->GetName());
1221 AliDebug(1, Form(" Loader name is %s",getname.Data()));
1222 return GetLoader(getname);
1225 /**************************************************************************/
1227 void AliRunLoader::CleanFolders()
1229 // fEventFolder->Add(this);//put myself to the folder to accessible for all
1236 /**************************************************************************/
1238 void AliRunLoader::CleanDetectors()
1240 //Calls CleanFolders for all detectors
1241 TIter next(fLoaders);
1243 while((loader = (AliLoader*)next()))
1245 loader->CleanFolders();
1248 /**************************************************************************/
1250 void AliRunLoader::RemoveEventFolder()
1252 //remove all the tree of event
1253 //all the stuff changing EbE stays untached (PDGDB, tasks, etc.)
1255 if (fEventFolder == 0x0) return;
1256 fEventFolder->SetOwner(kFALSE);//don't we want to deleted while removing the folder that we are sitting in
1257 fEventFolder->Remove(this);//remove us drom folder
1259 AliConfig::Instance()->GetTopFolder()->SetOwner(); //brings ownership back for fEventFolder since it sits in top folder
1260 AliConfig::Instance()->GetTopFolder()->Remove(fEventFolder); //remove the event tree
1261 delete fEventFolder;
1263 /**************************************************************************/
1265 void AliRunLoader::SetGAliceFile(TFile* gafile)
1267 //sets pointer to galice.root file
1271 /**************************************************************************/
1273 Int_t AliRunLoader::LoadHits(Option_t* detectors,Option_t* opt)
1275 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1277 AliDebug(1, "Loading Hits");
1281 const char* oAll = strstr(detectors,"all");
1284 AliDebug(1, "Option is All");
1289 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1290 loaders = &arr;//get the pointer array
1293 AliDebug(1, Form("For detectors. Number of detectors chosen for loading %d",loaders->GetEntries()));
1295 TIter next(loaders);
1297 while((loader = (AliLoader*)next()))
1299 AliDebug(1, Form(" Calling LoadHits(%s) for %s",opt,loader->GetName()));
1300 loader->LoadHits(opt);
1302 AliDebug(1, "Done");
1306 /**************************************************************************/
1308 Int_t AliRunLoader::LoadSDigits(Option_t* detectors,Option_t* opt)
1310 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1315 const char* oAll = strstr(detectors,"all");
1322 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1323 loaders = &arr;//get the pointer to array
1326 TIter next(loaders);
1328 while((loader = (AliLoader*)next()))
1330 loader->LoadSDigits(opt);
1335 /**************************************************************************/
1337 Int_t AliRunLoader::LoadDigits(Option_t* detectors,Option_t* opt)
1339 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1344 const char* oAll = strstr(detectors,"all");
1351 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1352 loaders = &arr;//get the pointer array
1355 TIter next(loaders);
1357 while((loader = (AliLoader*)next()))
1359 loader->LoadDigits(opt);
1363 /**************************************************************************/
1365 Int_t AliRunLoader::LoadRecPoints(Option_t* detectors,Option_t* opt)
1367 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1372 const char* oAll = strstr(detectors,"all");
1379 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1380 loaders = &arr;//get the pointer array
1383 TIter next(loaders);
1385 while((loader = (AliLoader*)next()))
1387 loader->LoadRecPoints(opt);
1391 /**************************************************************************/
1393 Int_t AliRunLoader::LoadRecParticles(Option_t* detectors,Option_t* opt)
1395 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1400 const char* oAll = strstr(detectors,"all");
1407 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1408 loaders = &arr;//get the pointer array
1411 TIter next(loaders);
1413 while((loader = (AliLoader*)next()))
1415 loader->LoadRecParticles(opt);
1419 /**************************************************************************/
1421 Int_t AliRunLoader::LoadTracks(Option_t* detectors,Option_t* opt)
1423 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1428 const char* oAll = strstr(detectors,"all");
1435 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1436 loaders = &arr;//get the pointer array
1439 TIter next(loaders);
1441 while((loader = (AliLoader*)next()))
1443 loader->LoadTracks(opt);
1447 /**************************************************************************/
1449 void AliRunLoader::UnloadHits(Option_t* detectors)
1451 //unloads hits for detectors specified in parameter
1455 const char* oAll = strstr(detectors,"all");
1462 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1463 loaders = &arr;//get the pointer to array
1466 TIter next(loaders);
1468 while((loader = (AliLoader*)next()))
1470 loader->UnloadHits();
1473 /**************************************************************************/
1475 void AliRunLoader::UnloadSDigits(Option_t* detectors)
1477 //unloads SDigits for detectors specified in parameter
1481 const char* oAll = strstr(detectors,"all");
1488 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1489 loaders = &arr;//get the pointer to array
1492 TIter next(loaders);
1494 while((loader = (AliLoader*)next()))
1496 loader->UnloadSDigits();
1499 /**************************************************************************/
1501 void AliRunLoader::UnloadDigits(Option_t* detectors)
1503 //unloads Digits for detectors specified in parameter
1507 const char* oAll = strstr(detectors,"all");
1514 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1515 loaders = &arr;//get the pointer to array
1518 TIter next(loaders);
1520 while((loader = (AliLoader*)next()))
1522 loader->UnloadDigits();
1525 /**************************************************************************/
1527 void AliRunLoader::UnloadRecPoints(Option_t* detectors)
1529 //unloads RecPoints for detectors specified in parameter
1533 const char* oAll = strstr(detectors,"all");
1540 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1541 loaders = &arr;//get the pointer to array
1544 TIter next(loaders);
1546 while((loader = (AliLoader*)next()))
1548 loader->UnloadRecPoints();
1551 /**************************************************************************/
1553 void AliRunLoader::UnloadAll(Option_t* detectors)
1555 //calls UnloadAll for detectors names specified in parameter
1556 // option "all" passed can be passed
1560 const char* oAll = strstr(detectors,"all");
1567 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1568 loaders = &arr;//get the pointer to array
1571 TIter next(loaders);
1573 while((loader = (AliLoader*)next()))
1575 loader->UnloadAll();
1578 /**************************************************************************/
1580 void AliRunLoader::UnloadTracks(Option_t* detectors)
1582 //unloads Tracks for detectors specified in parameter
1586 const char* oAll = strstr(detectors,"all");
1593 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1594 loaders = &arr;//get the pointer to array
1597 TIter next(loaders);
1599 while((loader = (AliLoader*)next()))
1601 loader->UnloadTracks();
1604 /**************************************************************************/
1606 void AliRunLoader::UnloadRecParticles(Option_t* detectors)
1608 //unloads Particles for detectors specified in parameter
1612 const char* oAll = strstr(detectors,"all");
1619 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1620 loaders = &arr;//get the pointer to array
1623 TIter next(loaders);
1625 while((loader = (AliLoader*)next()))
1627 loader->UnloadRecParticles();
1630 /**************************************************************************/
1632 AliRunLoader* AliRunLoader::GetRunLoader(const char* eventfoldername)
1634 //returns RunLoader from folder named eventfoldername
1635 TFolder* evfold= dynamic_cast<TFolder*>(AliConfig::Instance()->GetTopFolder()->FindObject(eventfoldername));
1640 AliRunLoader* runget = dynamic_cast<AliRunLoader*>(evfold->FindObject(AliRunLoader::fgkRunLoaderName));
1644 /**************************************************************************/
1646 AliLoader* AliRunLoader::GetDetectorLoader(const char* detname, const char* eventfoldername)
1648 //get the loader of the detector with the given name from the global
1650 AliRunLoader* runLoader = GetRunLoader(eventfoldername);
1652 AliErrorClass("No run loader found");
1655 return runLoader->GetDetectorLoader(detname);
1657 /**************************************************************************/
1659 AliLoader* AliRunLoader::GetDetectorLoader(const char* detname)
1661 //get the loader of the detector with the given name from the global
1664 char loadername[256];
1665 snprintf(loadername, 255, "%sLoader", detname);
1666 AliLoader* loader = GetLoader(loadername);
1668 AliError(Form("No loader for %s found", detname));
1673 /**************************************************************************/
1675 TTree* AliRunLoader::GetTreeH(const char* detname, Bool_t maketree, const char* eventfoldername)
1677 //get the tree with hits of the detector with the given name
1678 //if maketree is true and the tree does not exist, the tree is created
1679 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1680 if (!loader) return NULL;
1681 if (!loader->TreeH() && maketree) loader->MakeTree("H");
1682 return loader->TreeH();
1685 /**************************************************************************/
1687 TTree* AliRunLoader::GetTreeH(const char* detname, Bool_t maketree)
1689 //get the tree with hits of the detector with the given name
1690 //if maketree is true and the tree does not exist, the tree is created
1691 AliLoader* loader = GetDetectorLoader(detname);
1692 if (!loader) return NULL;
1693 if (!loader->TreeH() && maketree) loader->MakeTree("H");
1694 return loader->TreeH();
1696 /**************************************************************************/
1698 TTree* AliRunLoader::GetTreeS(const char* detname, Bool_t maketree,const char* eventfoldername)
1700 //get the tree with summable digits of the detector with the given name
1701 //if maketree is true and the tree does not exist, the tree is created
1702 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1703 if (!loader) return NULL;
1704 if (!loader->TreeS() && maketree) loader->MakeTree("S");
1705 return loader->TreeS();
1707 /**************************************************************************/
1709 TTree* AliRunLoader::GetTreeS(const char* detname, Bool_t maketree)
1711 //get the tree with summable digits of the detector with the given name
1712 //if maketree is true and the tree does not exist, the tree is created
1713 AliLoader* loader = GetDetectorLoader(detname);
1714 if (!loader) return NULL;
1715 if (!loader->TreeS() && maketree) loader->MakeTree("S");
1716 return loader->TreeS();
1718 /**************************************************************************/
1720 TTree* AliRunLoader::GetTreeD(const char* detname, Bool_t maketree,const char* eventfoldername)
1722 //get the tree with digits of the detector with the given name
1723 //if maketree is true and the tree does not exist, the tree is created
1724 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1725 if (!loader) return NULL;
1726 if (!loader->TreeD() && maketree) loader->MakeTree("D");
1727 return loader->TreeD();
1729 /**************************************************************************/
1731 TTree* AliRunLoader::GetTreeD(const char* detname, Bool_t maketree)
1733 //get the tree with digits of the detector with the given name
1734 //if maketree is true and the tree does not exist, the tree is created
1735 AliLoader* loader = GetDetectorLoader(detname);
1736 if (!loader) return NULL;
1737 if (!loader->TreeD() && maketree) loader->MakeTree("D");
1738 return loader->TreeD();
1740 /**************************************************************************/
1741 TTree* AliRunLoader::GetTreeR(const char* detname, Bool_t maketree,const char* eventfoldername)
1743 //get the tree with clusters of the detector with the given name
1744 //if maketree is true and the tree does not exist, the tree is created
1745 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1746 if (!loader) return NULL;
1747 if (!loader->TreeR() && maketree) loader->MakeTree("R");
1748 return loader->TreeR();
1750 /**************************************************************************/
1752 TTree* AliRunLoader::GetTreeR(const char* detname, Bool_t maketree)
1754 //get the tree with clusters of the detector with the given name
1755 //if maketree is true and the tree does not exist, the tree is created
1756 AliLoader* loader = GetDetectorLoader(detname);
1757 if (!loader) return NULL;
1758 if (!loader->TreeR() && maketree) loader->MakeTree("R");
1759 return loader->TreeR();
1761 /**************************************************************************/
1763 TTree* AliRunLoader::GetTreeT(const char* detname, Bool_t maketree,const char* eventfoldername)
1765 //get the tree with tracks of the detector with the given name
1766 //if maketree is true and the tree does not exist, the tree is created
1767 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1768 if (!loader) return NULL;
1769 if (!loader->TreeT() && maketree) loader->MakeTree("T");
1770 return loader->TreeT();
1772 /**************************************************************************/
1774 TTree* AliRunLoader::GetTreeT(const char* detname, Bool_t maketree)
1776 //get the tree with tracks of the detector with the given name
1777 //if maketree is true and the tree does not exist, the tree is created
1778 AliLoader* loader = GetDetectorLoader(detname);
1779 if (!loader) return NULL;
1780 if (!loader->TreeT() && maketree) loader->MakeTree("T");
1781 return loader->TreeT();
1783 /**************************************************************************/
1785 TTree* AliRunLoader::GetTreeP(const char* detname, Bool_t maketree,const char* eventfoldername)
1787 //get the tree with particles of the detector with the given name
1788 //if maketree is true and the tree does not exist, the tree is created
1789 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1790 if (!loader) return NULL;
1791 if (!loader->TreeP() && maketree) loader->MakeTree("P");
1792 return loader->TreeP();
1794 /**************************************************************************/
1796 TTree* AliRunLoader::GetTreeP(const char* detname, Bool_t maketree)
1798 //get the tree with particles of the detector with the given name
1799 //if maketree is true and the tree does not exist, the tree is created
1800 AliLoader* loader = GetDetectorLoader(detname);
1801 if (!loader) return NULL;
1802 if (!loader->TreeP() && maketree) loader->MakeTree("P");
1803 return loader->TreeP();
1806 /**************************************************************************/
1808 void AliRunLoader::CdGAFile()
1810 //sets gDirectory to galice file
1812 if(fGAFile) fGAFile->cd();
1815 /**************************************************************************/
1817 void AliRunLoader::GetListOfDetectors(const char * namelist,TObjArray& pointerarray) const
1819 //this method looks for all Loaders corresponding
1820 //to names (many) specified in namelist i.e. namelist ("ITS TPC TRD")
1824 strncpy(dets,namelist,199);//compiler cries when char* = const Option_t*;
1825 // dets[strlen(dets)+1] = '\n';//set endl at the end of string
1830 tmp = sscanf(pdet,"%9s",buff);//read the string from the input string pdet into buff
1831 if ( (buff[0] == 0) || (tmp == 0) ) break; //if not read
1833 pdet = strstr(pdet,buff) + strlen(buff);//move the input pointer about number of bytes (letters) read
1834 //I am aware that is a little complicated. I don't know the number of spaces between detector names
1835 //so I read the string, than I find where it starts (strstr) and move the pointer about length of a string
1836 //If there is a better way, please write me (Piotr.Skowronski@cern.ch)
1837 //construct the Loader name
1838 TString getname(buff);
1840 AliLoader* loader = GetLoader(getname);//get the Loader
1843 pointerarray.Add(loader);
1847 AliError(Form("Can not find Loader for %s",buff));
1853 /*****************************************************************************/
1855 void AliRunLoader::Clean(const TString& name)
1857 //removes object with given name from event folder and deletes it
1858 if (GetEventFolder() == 0x0) return;
1859 TObject* obj = GetEventFolder()->FindObject(name);
1862 AliDebug(1, Form("name=%s, cleaning %s.",GetName(),name.Data()));
1863 GetEventFolder()->Remove(obj);
1869 /*****************************************************************************/
1871 TTask* AliRunLoader::GetRunDigitizer()
1873 //returns Run Digitizer from folder
1875 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1876 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetDigitizerTaskName());
1877 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1879 /*****************************************************************************/
1881 TTask* AliRunLoader::GetRunSDigitizer()
1883 //returns SDigitizer Task from folder
1885 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1886 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetSDigitizerTaskName());
1887 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1889 /*****************************************************************************/
1891 TTask* AliRunLoader::GetRunReconstructioner()
1893 //returns Reconstructioner Task from folder
1894 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1895 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetReconstructionerTaskName());
1896 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1898 /*****************************************************************************/
1900 TTask* AliRunLoader::GetRunTracker()
1902 //returns Tracker Task from folder
1903 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1904 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetTrackerTaskName());
1905 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1907 /*****************************************************************************/
1909 TTask* AliRunLoader::GetRunPIDTask()
1911 //returns Tracker Task from folder
1912 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1913 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetPIDTaskName());
1914 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1916 /*****************************************************************************/
1918 TTask* AliRunLoader::GetRunQATask()
1920 //returns Quality Assurance Task from folder
1921 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1924 AliErrorClass("Can not get task folder from AliConfig");
1927 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetQATaskName());
1928 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1931 /*****************************************************************************/
1933 void AliRunLoader::SetCompressionLevel(Int_t cl)
1935 //Sets Compression Level in all files
1936 if (fGAFile) fGAFile->SetCompressionLevel(cl);
1937 SetKineComprLevel(cl);
1938 SetTrackRefsComprLevel(cl);
1939 TIter next(fLoaders);
1941 while((loader = (AliLoader*)next()))
1943 loader->SetCompressionLevel(cl);
1946 /**************************************************************************/
1948 void AliRunLoader::SetKineComprLevel(Int_t cl)
1950 //Sets comression level in Kine File
1951 fKineDataLoader->SetCompressionLevel(cl);
1953 /**************************************************************************/
1955 void AliRunLoader::SetTrackRefsComprLevel(Int_t cl)
1957 //Sets comression level in Track Refences File
1958 fTrackRefsDataLoader->SetCompressionLevel(cl);
1960 /**************************************************************************/
1962 void AliRunLoader::UnloadHeader()
1964 //removes TreeE from folder and deletes it
1965 // as well as fHeader object
1969 /**************************************************************************/
1971 void AliRunLoader::UnloadTrigger()
1973 //removes TreeCT from folder and deletes it
1974 // as well as fHeader object
1980 /**************************************************************************/
1982 void AliRunLoader::UnloadKinematics()
1984 //Unloads Kinematics
1985 fKineDataLoader->GetBaseLoader(0)->Unload();
1987 /**************************************************************************/
1989 void AliRunLoader::UnloadTrackRefs()
1991 //Unloads Track Refernces
1992 fTrackRefsDataLoader->GetBaseLoader(0)->Unload();
1994 /**************************************************************************/
1996 void AliRunLoader::UnloadgAlice()
1999 if (gAlice == GetAliRun())
2001 AliDebug(1, "Set gAlice = 0x0");
2002 gAlice = 0x0;//if gAlice is the same that in folder (to be deleted by the way of folder)
2004 AliRun* alirun = GetAliRun();
2005 if (GetEventFolder()) GetEventFolder()->Remove(alirun);
2008 /**************************************************************************/
2010 void AliRunLoader::MakeTrackRefsContainer()
2012 // Makes a tree for Track References
2013 fTrackRefsDataLoader->MakeTree();
2015 /**************************************************************************/
2017 Int_t AliRunLoader::LoadTrackRefs(Option_t* option)
2019 //Load track references from file (opens file and posts tree to folder)
2021 return fTrackRefsDataLoader->GetBaseLoader(0)->Load(option);
2023 /**************************************************************************/
2025 void AliRunLoader::SetDirName(TString& dirname)
2027 //sets directory name
2028 if (dirname.IsNull()) return;
2029 fUnixDirName = dirname;
2030 fKineDataLoader->SetDirName(dirname);
2031 fTrackRefsDataLoader->SetDirName(dirname);
2033 TIter next(fLoaders);
2035 while((loader = (AliLoader*)next()))
2037 loader->SetDirName(dirname);
2041 /*****************************************************************************/
2043 Int_t AliRunLoader::GetFileOffset() const
2045 //returns the file number that is added to the file name for current event
2046 return Int_t(fCurrentEvent/fNEventsPerFile);
2049 /*****************************************************************************/
2050 const TString AliRunLoader::SetFileOffset(const TString& fname)
2052 //adds the the number to the file name at proper place for current event
2053 Long_t offset = (Long_t)GetFileOffset();
2054 if (offset < 1) return fname;
2056 soffset += offset;//automatic conversion to string
2057 TString dotroot(".root");
2058 const TString& offfsetdotroot = offset + dotroot;
2059 TString out = fname;
2060 out = out.ReplaceAll(dotroot,offfsetdotroot);
2061 AliDebug(1, Form(" in=%s out=%s",fname.Data(),out.Data()));
2064 /*****************************************************************************/
2066 void AliRunLoader::SetDigitsFileNameSuffix(const TString& suffix)
2068 //adds the suffix before ".root",
2069 //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
2070 //made on Jiri Chudoba demand
2072 TIter next(fLoaders);
2074 while((loader = (AliLoader*)next()))
2076 loader->SetDigitsFileNameSuffix(suffix);
2079 /*****************************************************************************/
2081 TString AliRunLoader::GetFileName() const
2083 //returns name of galice file
2085 if (fGAFile == 0x0) return result;
2086 result = fGAFile->GetName();
2089 /*****************************************************************************/
2091 void AliRunLoader::SetDetectorAddresses()
2093 //calls SetTreeAddress for all detectors
2094 if (GetAliRun()==0x0) return;
2095 TIter next(GetAliRun()->Modules());
2097 while((mod = (AliModule*)next()))
2099 AliDetector* det = dynamic_cast<AliDetector*>(mod);
2100 if (det) det->SetTreeAddress();
2103 /*****************************************************************************/
2105 void AliRunLoader::Synchronize()
2107 //synchrinizes all writtable files
2108 TIter next(fLoaders);
2110 while((loader = (AliLoader*)next()))
2112 loader->Synchronize();
2115 fKineDataLoader->Synchronize();
2116 fTrackRefsDataLoader->Synchronize();
2118 TFile* file = gROOT->GetFile( gSystem->ConcatFileName( fUnixDirName.Data(), fgkDefaultTriggerFileName.Data() ) ) ;
2119 if( file ) file->Flush();
2121 if (fGAFile) fGAFile->Flush();
2123 /*****************************************************************************/
2124 /*****************************************************************************/