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 //////////////////////////////////////////////////////////////////////
52 #include <TGeometry.h>
53 #include <TObjArray.h>
60 #include "AliConfig.h"
61 #include "AliLoader.h"
62 #include "AliHeader.h"
64 #include "AliDetector.h"
65 #include "AliCDBManager.h"
66 #include "AliCDBLocal.h"
67 #include "AliCentralTrigger.h"
69 ClassImp(AliRunLoader)
71 AliRunLoader* AliRunLoader::fgRunLoader = 0x0;
73 const TString AliRunLoader::fgkRunLoaderName("RunLoader");
74 const TString AliRunLoader::fgkHeaderBranchName("Header");
75 const TString AliRunLoader::fgkTriggerBranchName("ClassMask");
76 const TString AliRunLoader::fgkHeaderContainerName("TE");
77 const TString AliRunLoader::fgkTriggerContainerName("TreeCT");
78 const TString AliRunLoader::fgkKineContainerName("TreeK");
79 const TString AliRunLoader::fgkTrackRefsContainerName("TreeTR");
80 const TString AliRunLoader::fgkKineBranchName("Particles");
81 const TString AliRunLoader::fgkDefaultKineFileName("Kinematics.root");
82 const TString AliRunLoader::fgkDefaultTrackRefsFileName("TrackRefs.root");
83 const TString AliRunLoader::fgkGAliceName("gAlice");
84 const TString AliRunLoader::fgkDefaultTriggerFileName("Trigger.root");
85 /**************************************************************************/
87 AliRunLoader::AliRunLoader():
96 fTrackRefsDataLoader(0x0),
100 AliConfig::Instance();//force to build the folder structure
101 if (!fgRunLoader) fgRunLoader = this;
103 /**************************************************************************/
105 AliRunLoader::AliRunLoader(const char* eventfoldername):
106 TNamed(fgkRunLoaderName,fgkRunLoaderName),
107 fLoaders(new TObjArray()),
114 fKineDataLoader(new AliDataLoader(fgkDefaultKineFileName,fgkKineContainerName,"Kinematics")),
115 fTrackRefsDataLoader(new AliDataLoader(fgkDefaultTrackRefsFileName,fgkTrackRefsContainerName,"Track References")),
120 SetEventFolderName(eventfoldername);
121 if (!fgRunLoader) fgRunLoader = this;
123 /**************************************************************************/
125 AliRunLoader::~AliRunLoader()
128 if (fgRunLoader == this) fgRunLoader = 0x0;
134 fLoaders->SetOwner();
138 delete fKineDataLoader;
139 delete fTrackRefsDataLoader;
144 //fEventFolder is deleted by the way of removing - TopAliceFolder owns it
145 if( fCTrigger ) delete fCTrigger;
150 /**************************************************************************/
152 AliRunLoader::AliRunLoader(TFolder* topfolder):
153 TNamed(fgkRunLoaderName,fgkRunLoaderName),
154 fLoaders(new TObjArray()),
155 fEventFolder(topfolder),
161 fKineDataLoader(new AliDataLoader(fgkDefaultKineFileName,fgkKineContainerName,"Kinematics")),
162 fTrackRefsDataLoader(new AliDataLoader(fgkDefaultTrackRefsFileName,fgkTrackRefsContainerName,"Track References")),
169 TString errmsg("Parameter is NULL");
170 AliError(errmsg.Data());
175 TObject* obj = fEventFolder->FindObject(fgkRunLoaderName);
177 { //if it is, then sth. is going wrong... exits aliroot session
178 TString errmsg("In Event Folder Named ");
179 errmsg+=fEventFolder->GetName();
180 errmsg+=" object named "+fgkRunLoaderName+" already exists. I am confused ...";
182 AliError(errmsg.Data());
184 return;//never reached
187 if (!fgRunLoader) fgRunLoader = this;
189 fEventFolder->Add(this);//put myself to the folder to accessible for all
193 /**************************************************************************/
195 Int_t AliRunLoader::GetEvent(Int_t evno)
197 //Gets event number evno
198 //Reloads all data properly
199 //PH if (fCurrentEvent == evno) return 0;
203 AliError("Can not give the event with negative number");
207 if (evno >= GetNumberOfEvents())
209 AliError(Form("There is no event with number %d",evno));
213 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
214 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
215 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
216 AliDebug(1, Form(" GETTING EVENT %d",evno));
217 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
218 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
219 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
221 fCurrentEvent = evno;
225 //Reload header (If header was loaded)
228 retval = TreeE()->GetEvent(fCurrentEvent);
231 AliError(Form("Cannot find event: %d\n ",fCurrentEvent));
235 //Reload stack (If header was loaded)
236 if (TreeE()) fStack = GetHeader()->Stack();
237 //Set event folder in stack (it does not mean that we read kinematics from file)
238 if( GetTrigger() && TreeCT() ) {
239 retval = TreeCT()->GetEvent(fCurrentEvent);
241 AliError(Form("Error occured while GetEvent for Trigger. Event %d",evno));
249 AliError(Form("Error occured while setting event %d",evno));
253 //Post Track References
254 retval = fTrackRefsDataLoader->GetEvent();
257 AliError(Form("Error occured while GetEvent for Track References. Event %d",evno));
261 //Read Kinematics if loaded
262 retval = fKineDataLoader->GetEvent();
265 AliError(Form("Error occured while GetEvent for Kinematics. Event %d",evno));
269 if (fStack && fKineDataLoader->GetBaseLoader(0)->IsLoaded())
271 fStack->ConnectTree(TreeK());
273 if (fStack->GetEvent() == kFALSE)
275 AliError(Form("Error occured while GetEvent for Stack. Event %d",evno));
280 //Trigger data reloading in all loaders
281 TIter next(fLoaders);
283 while((loader = (AliLoader*)next()))
285 retval = loader->GetEvent();
288 AliError(Form("Error occured while getting event for %s. Event %d.",
289 loader->GetDetectorName().Data(), evno));
294 SetDetectorAddresses();
298 /**************************************************************************/
299 Int_t AliRunLoader::SetEvent()
301 //if kinematics was loaded Cleans folder data
305 retval = fKineDataLoader->SetEvent();
308 AliError("SetEvent for Kinamtics Data Loader retutned error.");
311 retval = fTrackRefsDataLoader->SetEvent();
314 AliError("SetEvent for Track References Data Loader retutned error.");
318 TIter next(fLoaders);
320 while((loader = (AliLoader*)next()))
322 retval = loader->SetEvent();
325 AliError(Form("SetEvent for %s Data Loader retutned error.",loader->GetName()));
332 /**************************************************************************/
334 Int_t AliRunLoader::SetEventNumber(Int_t evno)
336 //cleans folders and sets the root dirs in files
337 if (fCurrentEvent == evno) return 0;
338 fCurrentEvent = evno;
342 /**************************************************************************/
343 AliCDBEntry* AliRunLoader::GetCDBEntry(const char* name) const
345 //Get an AliCDBEntry from the run data storage
347 if ( !(AliCDBManager::Instance()->IsDefaultStorageSet()) ) {
348 AliError("No run data storage defined!");
351 return AliCDBManager::Instance()->GetDefaultStorage()->Get(name, GetHeader()->GetRun());
355 /**************************************************************************/
356 AliRunLoader* AliRunLoader::Open
357 (const char* filename, const char* eventfoldername, Option_t* option)
359 //Opens a desired file 'filename'
360 //gets the the run-Loader and mounts it desired folder
361 //returns the pointer to run Loader which can be further used for accessing data
362 //in case of error returns NULL
364 static const TString kwebaddress("http://alisoft.cern.ch/people/skowron/codedoc/split/index.html");
365 AliDebugClass(1,Form("\n\n\nNew I/O strcture: See more info:\n %s\n\n\n",kwebaddress.Data()));
367 AliRunLoader* result = 0x0;
369 /* ************************************************ */
370 /* Chceck if folder with given name already exists */
371 /* ************************************************ */
373 TObject* obj = AliConfig::Instance()->GetTopFolder()->FindObject(eventfoldername);
376 TFolder* fold = dynamic_cast<TFolder*>(obj);
379 AliErrorClass("Such a obejct already exists in top alice folder and it is not a folder.");
383 //check if we can get RL from that folder
384 result = AliRunLoader::GetRunLoader(eventfoldername);
387 AliErrorClass(Form("Folder %s already exists, and can not find session there. Can not mount.",eventfoldername));
391 if (result->GetFileName().CompareTo(filename) != 0)
393 AliErrorClass("Other file is mounted in demanded folder. Can not mount.");
397 //check if now is demanded (re)creation
398 if ( AliLoader::TestFileOption(option) == kFALSE)
400 AliErrorClass(Form("Session already exists in folder %s and this session option is %s. Unable to proceed.",
401 eventfoldername,option));
405 //check if demanded option is update and existing one
406 TString tmpstr(option);
407 if ( (tmpstr.CompareTo("update",TString::kIgnoreCase) == 0) &&
408 (result->fGAFile->IsWritable() == kFALSE) )
410 AliErrorClass(Form("Session already exists in folder %s and is not writable while this session option is %s. Unable to proceed.",
411 eventfoldername,option));
415 AliWarningClass("Session is already opened and mounted in demanded folder");
416 if (!fgRunLoader) fgRunLoader = result; //PH get access from any place
418 } //end of checking in case of existance of object named identically that folder session is being opened
421 TFile * gAliceFile = TFile::Open(filename,option);//open a file
423 {//null pointer returned
424 AliFatalClass(Form("Can not open file %s.",filename));
428 if (gAliceFile->IsOpen() == kFALSE)
429 {//pointer to valid object returned but file is not opened
430 AliErrorClass(Form("Can not open file %s.",filename));
434 //if file is "read" or "update" than we try to find AliRunLoader there - if not found cry and exit
435 //else create new AliRunLoader
436 if ( AliLoader::TestFileOption(option) )
438 AliDebugClass(1, "Reading RL from file");
440 result = dynamic_cast<AliRunLoader*>(gAliceFile->Get(fgkRunLoaderName));//get the run Loader from the file
443 AliErrorClass(Form("Can not find run-Loader in file %s.",filename));
444 delete gAliceFile;//close the file
447 Int_t tmp = result->SetEventFolderName(eventfoldername);//mount a event folder
448 if (tmp)//if SetEvent returned error
450 AliErrorClass(Form("Can not mount event in folder %s.",eventfoldername));
451 delete result; //delete run-Loader
452 delete gAliceFile;//close the file
458 AliDebugClass(1, Form("Creating new AliRunLoader. Folder name is %s",eventfoldername));
461 result = new AliRunLoader(eventfoldername);
463 catch (TString& errmsg)
465 AliErrorClass(Form("AliRunLoader constrcutor has thrown exception: %s\n",errmsg.Data()));
467 delete gAliceFile;//close the file
472 //procedure for extracting dir name from the file name
473 TString fname(filename);
474 Int_t nsl = fname.Last('#');//look for hash in file name
476 if (nsl < 0) {//hash not found
477 nsl = fname.Last('/');// look for slash
479 nsl = fname.Last(':');// look for colon e.g. rfio:galice.root
482 if (nsl < 0) dirname = "./"; // no directory path, use "."
483 else dirname = fname.Remove(nsl+1);// directory path
485 AliDebugClass(1, Form("Dir name is : %s",dirname.Data()));
487 result->SetDirName(dirname);
488 result->SetGAliceFile(gAliceFile);//set the pointer to gAliceFile
489 if (!fgRunLoader) fgRunLoader = result; //PH get access from any place
492 /**************************************************************************/
493 Int_t AliRunLoader::GetNumberOfEvents()
495 //returns number of events in Run
499 retval = LoadHeader();
502 AliError("Error occured while loading header");
506 return (Int_t)TreeE()->GetEntries();
508 /**************************************************************************/
510 void AliRunLoader::MakeHeader()
512 //Makes header and connects it to header tree (if it exists)
516 AliDebug(1, "Creating new Header Object");
517 fHeader= new AliHeader();
519 TTree* tree = TreeE();
522 AliDebug(1, "Got Tree from folder.");
523 TBranch* branch = tree->GetBranch(fgkHeaderBranchName);
526 AliDebug(1, "Creating new branch");
527 branch = tree->Branch(fgkHeaderBranchName, "AliHeader", &fHeader, 4000, 0);
528 branch->SetAutoDelete(kFALSE);
532 AliDebug(1, "Got Branch from Tree");
533 branch->SetAddress(&fHeader);
534 tree->GetEvent(fCurrentEvent);
535 fStack = fHeader->Stack(); //should be safe - if we created Stack, header returns pointer to the same object
539 fStack->ConnectTree(TreeK());
545 AliDebug(1, "Header does not have a stack.");
549 AliDebug(1, "Exiting MakeHeader method");
551 /**************************************************************************/
553 void AliRunLoader::MakeStack()
555 //Creates the stack object - do not connect the tree
558 fStack = new AliStack(10000);
561 /**************************************************************************/
563 void AliRunLoader::MakeTrigger()
565 // Makes trigger object and connects it to trigger tree (if it exists)
567 if( fCTrigger == 0x0 ) {
568 AliDebug( 1, "Creating new Trigger Object" );
569 fCTrigger = new AliCentralTrigger();
571 TTree* tree = TreeCT();
573 fCTrigger->MakeBranch( fgkTriggerBranchName, tree );
574 tree->GetEvent( fCurrentEvent );
577 AliDebug( 1, "Exiting MakeTrigger method" );
579 /**************************************************************************/
581 void AliRunLoader::MakeTree(Option_t *option)
584 const char *oK = strstr(option,"K"); //Kine
585 const char *oE = strstr(option,"E"); //Header
586 const char *oGG = strstr(option,"GG"); //Central TriGGer
590 if (fKineDataLoader->GetBaseLoader(0)->IsLoaded() == kFALSE)
592 AliError("Load Kinematics first");
597 fKineDataLoader->MakeTree();
600 fStack->ConnectTree(TreeK());
601 WriteKinematics("OVERWRITE");
608 TTree* tree = new TTree(fgkHeaderContainerName,"Tree with Headers");
609 GetEventFolder()->Add(tree);
611 WriteHeader("OVERWRITE");
616 // create the CTP Trigger output file and tree
617 TFile* file = gROOT->GetFile( fgkDefaultTriggerFileName );
619 file = TFile::Open( gSystem->ConcatFileName( fUnixDirName.Data(), fgkDefaultTriggerFileName.Data() ), "RECREATE" ) ;
623 TTree* tree = new TTree( fgkTriggerContainerName, "Tree with Central Trigger Mask" );
624 GetEventFolder()->Add(tree);
626 // WriteHeader("OVERWRITE");
629 TIter next(fLoaders);
631 while((loader = (AliLoader*)next()))
633 loader->MakeTree(option);
637 /**************************************************************************/
639 Int_t AliRunLoader::LoadgAlice()
641 //Loads gAlice from file
644 AliWarning("AliRun is already in folder. Unload first.");
647 AliRun* alirun = dynamic_cast<AliRun*>(fGAFile->Get(fgkGAliceName));
650 AliError(Form("Can not find gAlice in file %s",fGAFile->GetName()));
653 alirun->SetRunLoader(this);
656 AliWarning(Form("gAlice already exists. Putting retrived object in folder named %s",
657 GetEventFolder()->GetName()));
663 SetDetectorAddresses();//calls SetTreeAddress for all detectors
666 /**************************************************************************/
668 Int_t AliRunLoader::LoadHeader()
670 //loads treeE and reads header object for current event
673 AliWarning("Header is already loaded. Use ReloadHeader to force reload. Nothing done");
677 if (GetEventFolder() == 0x0)
679 AliError("Event folder not specified yet");
685 AliError("Session not opened. Use AliRunLoader::Open");
689 if (fGAFile->IsOpen() == kFALSE)
691 AliError("Session not opened. Use AliRunLoader::Open");
695 TTree* tree = dynamic_cast<TTree*>(fGAFile->Get(fgkHeaderContainerName));
698 AliError(Form("Can not find header tree named %s in file %s",
699 fgkHeaderContainerName.Data(),fGAFile->GetName()));
703 if (tree == TreeE()) return 0;
706 GetEventFolder()->Add(tree);
707 MakeHeader();//creates header object and connects to tree
711 /**************************************************************************/
713 Int_t AliRunLoader::LoadTrigger(Option_t* option)
718 AliWarning("Trigger is already loaded. Nothing done");
722 if( GetEventFolder() == 0x0 ) {
723 AliError("Event folder not specified yet");
726 // get the CTP Trigger output file and tree
727 TString trgfile = gSystem->ConcatFileName( fUnixDirName.Data(),
728 fgkDefaultTriggerFileName.Data() );
729 TFile* file = gROOT->GetFile( trgfile );
731 file = TFile::Open( trgfile, option ) ;
732 if (!file || file->IsOpen() == kFALSE ) {
733 AliError( Form( "Can not open trigger file %s", trgfile.Data() ) );
739 TTree* tree = dynamic_cast<TTree*>(file->Get( fgkTriggerContainerName ));
741 AliError( Form( "Can not find trigger tree named %s in file %s",
742 fgkTriggerContainerName.Data(), file->GetName() ) );
748 fCTrigger = dynamic_cast<AliCentralTrigger*>(file->Get( "AliCentralTrigger" ));
749 GetEventFolder()->Add( tree );
755 /**************************************************************************/
757 Int_t AliRunLoader::LoadKinematics(Option_t* option)
759 //Loads the kinematics
760 Int_t retval = fKineDataLoader->GetBaseLoader(0)->Load(option);
763 AliError("Error occured while loading kinamatics tree.");
768 fStack->ConnectTree(TreeK());
769 retval = fStack->GetEvent();
770 if ( retval == kFALSE)
772 AliError("Error occured while loading kinamatics tree.");
779 /**************************************************************************/
781 Int_t AliRunLoader::OpenDataFile(const TString& filename,TFile*& file,TDirectory*& dir,Option_t* opt,Int_t cl)
783 //Opens File with kinematics
786 if (file->IsOpen() == kFALSE)
787 {//pointer is not null but file is not opened
788 AliWarning("Pointer to file is not null, but file is not opened");//risky any way
790 file = 0x0; //proceed with opening procedure
794 AliWarning(Form("File %s already opened",filename.Data()));
798 //try to find if that file is opened somewere else
799 file = (TFile *)( gROOT->GetListOfFiles()->FindObject(filename) );
802 if(file->IsOpen() == kTRUE)
804 AliWarning(Form("File %s already opened by sombody else.",file->GetName()));
809 file = TFile::Open(filename,opt);
812 AliError(Form("Can not open file %s",filename.Data()));
815 if (file->IsOpen() == kFALSE)
816 {//file is not opened
817 AliError(Form("Can not open file %s",filename.Data()));
821 file->SetCompressionLevel(cl);
823 dir = AliLoader::ChangeDir(file,fCurrentEvent);
826 AliError(Form("Can not change to root directory in file %s",filename.Data()));
831 /**************************************************************************/
833 TTree* AliRunLoader::TreeE() const
835 //returns the tree from folder; shortcut method
836 if (AliDebugLevel() > 10) fEventFolder->ls();
837 TObject *obj = fEventFolder->FindObject(fgkHeaderContainerName);
838 return (obj)?dynamic_cast<TTree*>(obj):0x0;
840 /**************************************************************************/
842 TTree* AliRunLoader::TreeCT() const
844 //returns the tree from folder; shortcut method
845 if (AliDebugLevel() > 10) fEventFolder->ls();
846 TObject *obj = fEventFolder->FindObject(fgkTriggerContainerName);
847 return (obj)?dynamic_cast<TTree*>(obj):0x0;
849 /**************************************************************************/
851 AliHeader* AliRunLoader::GetHeader() const
853 //returns pointer header object
856 /**************************************************************************/
858 AliCentralTrigger* AliRunLoader::GetTrigger() const
860 //returns pointer trigger object
864 /**************************************************************************/
866 TTree* AliRunLoader::TreeK() const
868 //returns the tree from folder; shortcut method
869 TObject *obj = GetEventFolder()->FindObject(fgkKineContainerName);
870 return (obj)?dynamic_cast<TTree*>(obj):0x0;
872 /**************************************************************************/
874 TTree* AliRunLoader::TreeTR() const
876 //returns the tree from folder; shortcut method
877 TObject* obj = GetEventFolder()->FindObject(fgkTrackRefsContainerName);
878 return (obj)?dynamic_cast<TTree*>(obj):0x0;
880 /**************************************************************************/
882 AliRun* AliRunLoader::GetAliRun() const
884 //returns AliRun which sits in the folder
885 if (fEventFolder == 0x0) return 0x0;
886 TObject *obj = fEventFolder->FindObject(fgkGAliceName);
887 return (obj)?dynamic_cast<AliRun*>(obj):0x0;
889 /**************************************************************************/
891 Int_t AliRunLoader::WriteHeader(Option_t* opt)
894 AliDebug(1, "WRITING HEADER");
896 TTree* tree = TreeE();
899 AliWarning("Can not find Header Tree in Folder");
902 if (fGAFile->IsWritable() == kFALSE)
904 AliError(Form("File %s is not writable",fGAFile->GetName()));
908 TObject* obj = fGAFile->Get(fgkHeaderContainerName);
910 { //if they exist, see if option OVERWRITE is used
912 if(tmp.Contains("OVERWRITE",TString::kIgnoreCase) == 0)
913 {//if it is not used - give an error message and return an error code
914 AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
919 tree->SetDirectory(fGAFile);
920 tree->Write(0,TObject::kOverwrite);
922 AliDebug(1, "WRITTEN\n\n");
927 /**************************************************************************/
929 Int_t AliRunLoader::WriteTrigger(Option_t* opt)
932 AliDebug( 1, "WRITING TRIGGER" );
934 TTree* tree = TreeCT();
936 AliWarning("Can not find Trigger Tree in Folder");
940 TFile* file = gROOT->GetFile( gSystem->ConcatFileName( fUnixDirName.Data(), fgkDefaultTriggerFileName.Data() ) ) ;
941 if( !file || !file->IsOpen() ) {
942 AliError( "can't write Trigger, file is not open" );
946 TObject* obj = file->Get( fgkTriggerContainerName );
947 if( obj ) { //if they exist, see if option OVERWRITE is used
949 if( tmp.Contains( "OVERWRITE", TString::kIgnoreCase ) == 0) {
950 //if it is not used - give an error message and return an error code
951 AliError( "Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data" );
956 fCTrigger->Write( 0, TObject::kOverwrite );
957 tree->Write( 0, TObject::kOverwrite );
960 AliDebug(1, "WRITTEN\n\n");
964 /**************************************************************************/
966 Int_t AliRunLoader::WriteAliRun(Option_t* /*opt*/)
968 //writes AliRun object to the file
970 if (GetAliRun()) GetAliRun()->Write();
973 /**************************************************************************/
975 Int_t AliRunLoader::WriteKinematics(Option_t* opt)
978 return fKineDataLoader->GetBaseLoader(0)->WriteData(opt);
980 /**************************************************************************/
981 Int_t AliRunLoader::WriteTrackRefs(Option_t* opt)
983 //writes Track References tree
984 return fTrackRefsDataLoader->GetBaseLoader(0)->WriteData(opt);
986 /**************************************************************************/
988 Int_t AliRunLoader::WriteHits(Option_t* opt)
990 //Calls WriteHits for all loaders
993 TIter next(fLoaders);
995 while((loader = (AliLoader*)next()))
997 res = loader->WriteHits(opt);
1000 AliError(Form("Failed to write hits for %s (%d)",loader->GetDetectorName().Data(),res));
1006 /**************************************************************************/
1008 Int_t AliRunLoader::WriteSDigits(Option_t* opt)
1010 //Calls WriteSDigits for all loaders
1013 TIter next(fLoaders);
1015 while((loader = (AliLoader*)next()))
1017 res = loader->WriteSDigits(opt);
1020 AliError(Form("Failed to write summable digits for %s.",loader->GetDetectorName().Data()));
1026 /**************************************************************************/
1028 Int_t AliRunLoader::WriteDigits(Option_t* opt)
1030 //Calls WriteDigits for all loaders
1033 TIter next(fLoaders);
1035 while((loader = (AliLoader*)next()))
1037 res = loader->WriteDigits(opt);
1040 AliError(Form("Failed to write digits for %s.",loader->GetDetectorName().Data()));
1046 /**************************************************************************/
1048 Int_t AliRunLoader::WriteRecPoints(Option_t* opt)
1050 //Calls WriteRecPoints for all loaders
1053 TIter next(fLoaders);
1055 while((loader = (AliLoader*)next()))
1057 res = loader->WriteRecPoints(opt);
1060 AliError(Form("Failed to write Reconstructed Points for %s.",
1061 loader->GetDetectorName().Data()));
1067 /**************************************************************************/
1069 Int_t AliRunLoader::WriteTracks(Option_t* opt)
1071 //Calls WriteTracks for all loaders
1074 TIter next(fLoaders);
1076 while((loader = (AliLoader*)next()))
1078 res = loader->WriteTracks(opt);
1081 AliError(Form("Failed to write Tracks for %s.",
1082 loader->GetDetectorName().Data()));
1088 /**************************************************************************/
1090 Int_t AliRunLoader::WriteRunLoader(Option_t* /*opt*/)
1092 //Writes itself to the file
1094 this->Write(0,TObject::kOverwrite);
1097 /**************************************************************************/
1099 Int_t AliRunLoader::SetEventFolderName(const TString& name)
1101 //sets top folder name for this run; of alread
1104 AliError("Name is empty");
1108 //check if such a folder already exists - try to find it in alice top folder
1109 TObject* obj = AliConfig::Instance()->GetTopFolder()->FindObject(name);
1112 TFolder* fold = dynamic_cast<TFolder*>(obj);
1115 AliError("Such a obejct already exists in top alice folder and it is not a folder.");
1118 //folder which was found is our folder
1119 if (fEventFolder == fold)
1125 AliError("Such a folder already exists in top alice folder. Can not mount.");
1130 //event is alredy connected, just change name of the folder
1133 fEventFolder->SetName(name);
1137 if (fKineDataLoader == 0x0)
1138 fKineDataLoader = new AliDataLoader(fgkDefaultKineFileName,fgkKineContainerName,"Kinematics");
1140 if ( fTrackRefsDataLoader == 0x0)
1141 fTrackRefsDataLoader = new AliDataLoader(fgkDefaultTrackRefsFileName,fgkTrackRefsContainerName,"Track References");
1143 //build the event folder structure
1144 AliDebug(1, Form("Creating new event folder named %s",name.Data()));
1145 fEventFolder = AliConfig::Instance()->BuildEventFolder(name,"Event Folder");
1146 fEventFolder->Add(this);//put myself to the folder to accessible for all
1148 TIter next(fLoaders);
1150 while((loader = (AliLoader*)next()))
1152 loader->Register(fEventFolder);//build folder structure for this detector
1155 fKineDataLoader->SetEventFolder(GetEventFolder());
1156 fTrackRefsDataLoader->SetEventFolder(GetEventFolder());
1157 fKineDataLoader->SetFolder(GetEventFolder());
1158 fTrackRefsDataLoader->SetFolder(GetEventFolder());
1160 fEventFolder->SetOwner();
1163 /**************************************************************************/
1165 void AliRunLoader::AddLoader(AliLoader* loader)
1167 //Adds the Loader for given detector
1168 if (loader == 0x0) //if null shout and exit
1170 AliError("Parameter is NULL");
1173 loader->SetDirName(fUnixDirName);
1174 if (fEventFolder) loader->SetEventFolder(fEventFolder); //if event folder is already defined,
1175 //pass information to the Loader
1176 fLoaders->Add(loader);//add the Loader to the array
1178 /**************************************************************************/
1180 void AliRunLoader::AddLoader(AliDetector* det)
1182 //Asks module (detector) ro make a Loader and stores in the array
1183 if (det == 0x0) return;
1184 AliLoader* get = det->GetLoader();//try to get loader
1185 if (get == 0x0) get = det->MakeLoader(fEventFolder->GetName());//if did not obtain, ask to make it
1189 AliDebug(1, Form("Detector: %s Loader : %s",det->GetName(),get->GetName()));
1194 /**************************************************************************/
1196 AliLoader* AliRunLoader::GetLoader(const char* detname) const
1198 //returns loader for given detector
1199 //note that naming convention is TPCLoader not just TPC
1200 return (AliLoader*)fLoaders->FindObject(detname);
1203 /**************************************************************************/
1205 AliLoader* AliRunLoader::GetLoader(AliDetector* det) const
1207 //get loader for detector det
1208 if(det == 0x0) return 0x0;
1209 TString getname(det->GetName());
1211 AliDebug(1, Form(" Loader name is %s",getname.Data()));
1212 return GetLoader(getname);
1215 /**************************************************************************/
1217 void AliRunLoader::CleanFolders()
1219 // fEventFolder->Add(this);//put myself to the folder to accessible for all
1226 /**************************************************************************/
1228 void AliRunLoader::CleanDetectors()
1230 //Calls CleanFolders for all detectors
1231 TIter next(fLoaders);
1233 while((loader = (AliLoader*)next()))
1235 loader->CleanFolders();
1238 /**************************************************************************/
1240 void AliRunLoader::RemoveEventFolder()
1242 //remove all the tree of event
1243 //all the stuff changing EbE stays untached (PDGDB, tasks, etc.)
1245 if (fEventFolder == 0x0) return;
1246 fEventFolder->SetOwner(kFALSE);//don't we want to deleted while removing the folder that we are sitting in
1247 fEventFolder->Remove(this);//remove us drom folder
1249 AliConfig::Instance()->GetTopFolder()->SetOwner(); //brings ownership back for fEventFolder since it sits in top folder
1250 AliConfig::Instance()->GetTopFolder()->Remove(fEventFolder); //remove the event tree
1251 delete fEventFolder;
1253 /**************************************************************************/
1255 void AliRunLoader::SetGAliceFile(TFile* gafile)
1257 //sets pointer to galice.root file
1261 /**************************************************************************/
1263 Int_t AliRunLoader::LoadHits(Option_t* detectors,Option_t* opt)
1265 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1267 AliDebug(1, "Loading Hits");
1271 const char* oAll = strstr(detectors,"all");
1274 AliDebug(1, "Option is All");
1279 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1280 loaders = &arr;//get the pointer array
1283 AliDebug(1, Form("For detectors. Number of detectors chosen for loading %d",loaders->GetEntries()));
1285 TIter next(loaders);
1287 while((loader = (AliLoader*)next()))
1289 AliDebug(1, Form(" Calling LoadHits(%s) for %s",opt,loader->GetName()));
1290 loader->LoadHits(opt);
1292 AliDebug(1, "Done");
1296 /**************************************************************************/
1298 Int_t AliRunLoader::LoadSDigits(Option_t* detectors,Option_t* opt)
1300 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1305 const char* oAll = strstr(detectors,"all");
1312 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1313 loaders = &arr;//get the pointer to array
1316 TIter next(loaders);
1318 while((loader = (AliLoader*)next()))
1320 loader->LoadSDigits(opt);
1325 /**************************************************************************/
1327 Int_t AliRunLoader::LoadDigits(Option_t* detectors,Option_t* opt)
1329 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1334 const char* oAll = strstr(detectors,"all");
1341 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1342 loaders = &arr;//get the pointer array
1345 TIter next(loaders);
1347 while((loader = (AliLoader*)next()))
1349 loader->LoadDigits(opt);
1353 /**************************************************************************/
1355 Int_t AliRunLoader::LoadRecPoints(Option_t* detectors,Option_t* opt)
1357 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1362 const char* oAll = strstr(detectors,"all");
1369 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1370 loaders = &arr;//get the pointer array
1373 TIter next(loaders);
1375 while((loader = (AliLoader*)next()))
1377 loader->LoadRecPoints(opt);
1381 /**************************************************************************/
1383 Int_t AliRunLoader::LoadRecParticles(Option_t* detectors,Option_t* opt)
1385 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1390 const char* oAll = strstr(detectors,"all");
1397 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1398 loaders = &arr;//get the pointer array
1401 TIter next(loaders);
1403 while((loader = (AliLoader*)next()))
1405 loader->LoadRecParticles(opt);
1409 /**************************************************************************/
1411 Int_t AliRunLoader::LoadTracks(Option_t* detectors,Option_t* opt)
1413 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1418 const char* oAll = strstr(detectors,"all");
1425 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1426 loaders = &arr;//get the pointer array
1429 TIter next(loaders);
1431 while((loader = (AliLoader*)next()))
1433 loader->LoadTracks(opt);
1437 /**************************************************************************/
1439 void AliRunLoader::UnloadHits(Option_t* detectors)
1441 //unloads hits for detectors specified in parameter
1445 const char* oAll = strstr(detectors,"all");
1452 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1453 loaders = &arr;//get the pointer to array
1456 TIter next(loaders);
1458 while((loader = (AliLoader*)next()))
1460 loader->UnloadHits();
1463 /**************************************************************************/
1465 void AliRunLoader::UnloadSDigits(Option_t* detectors)
1467 //unloads SDigits for detectors specified in parameter
1471 const char* oAll = strstr(detectors,"all");
1478 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1479 loaders = &arr;//get the pointer to array
1482 TIter next(loaders);
1484 while((loader = (AliLoader*)next()))
1486 loader->UnloadSDigits();
1489 /**************************************************************************/
1491 void AliRunLoader::UnloadDigits(Option_t* detectors)
1493 //unloads Digits for detectors specified in parameter
1497 const char* oAll = strstr(detectors,"all");
1504 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1505 loaders = &arr;//get the pointer to array
1508 TIter next(loaders);
1510 while((loader = (AliLoader*)next()))
1512 loader->UnloadDigits();
1515 /**************************************************************************/
1517 void AliRunLoader::UnloadRecPoints(Option_t* detectors)
1519 //unloads RecPoints for detectors specified in parameter
1523 const char* oAll = strstr(detectors,"all");
1530 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1531 loaders = &arr;//get the pointer to array
1534 TIter next(loaders);
1536 while((loader = (AliLoader*)next()))
1538 loader->UnloadRecPoints();
1541 /**************************************************************************/
1543 void AliRunLoader::UnloadAll(Option_t* detectors)
1545 //calls UnloadAll for detectors names specified in parameter
1546 // option "all" passed can be passed
1550 const char* oAll = strstr(detectors,"all");
1557 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1558 loaders = &arr;//get the pointer to array
1561 TIter next(loaders);
1563 while((loader = (AliLoader*)next()))
1565 loader->UnloadAll();
1568 /**************************************************************************/
1570 void AliRunLoader::UnloadTracks(Option_t* detectors)
1572 //unloads Tracks for detectors specified in parameter
1576 const char* oAll = strstr(detectors,"all");
1583 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1584 loaders = &arr;//get the pointer to array
1587 TIter next(loaders);
1589 while((loader = (AliLoader*)next()))
1591 loader->UnloadTracks();
1594 /**************************************************************************/
1596 void AliRunLoader::UnloadRecParticles(Option_t* detectors)
1598 //unloads Particles for detectors specified in parameter
1602 const char* oAll = strstr(detectors,"all");
1609 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1610 loaders = &arr;//get the pointer to array
1613 TIter next(loaders);
1615 while((loader = (AliLoader*)next()))
1617 loader->UnloadRecParticles();
1620 /**************************************************************************/
1622 AliRunLoader* AliRunLoader::GetRunLoader(const char* eventfoldername)
1624 //returns RunLoader from folder named eventfoldername
1625 TFolder* evfold= dynamic_cast<TFolder*>(AliConfig::Instance()->GetTopFolder()->FindObject(eventfoldername));
1630 AliRunLoader* runget = dynamic_cast<AliRunLoader*>(evfold->FindObject(AliRunLoader::fgkRunLoaderName));
1634 /**************************************************************************/
1636 AliLoader* AliRunLoader::GetDetectorLoader(const char* detname, const char* eventfoldername)
1638 //get the loader of the detector with the given name from the global
1640 AliRunLoader* runLoader = GetRunLoader(eventfoldername);
1642 AliErrorClass("No run loader found");
1645 return runLoader->GetDetectorLoader(detname);
1647 /**************************************************************************/
1649 AliLoader* AliRunLoader::GetDetectorLoader(const char* detname)
1651 //get the loader of the detector with the given name from the global
1654 char loadername[256];
1655 sprintf(loadername, "%sLoader", detname);
1656 AliLoader* loader = GetLoader(loadername);
1658 AliError(Form("No loader for %s found", detname));
1663 /**************************************************************************/
1665 TTree* AliRunLoader::GetTreeH(const char* detname, Bool_t maketree, const char* eventfoldername)
1667 //get the tree with hits of the detector with the given name
1668 //if maketree is true and the tree does not exist, the tree is created
1669 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1670 if (!loader) return NULL;
1671 if (!loader->TreeH() && maketree) loader->MakeTree("H");
1672 return loader->TreeH();
1675 /**************************************************************************/
1677 TTree* AliRunLoader::GetTreeH(const char* detname, Bool_t maketree)
1679 //get the tree with hits of the detector with the given name
1680 //if maketree is true and the tree does not exist, the tree is created
1681 AliLoader* loader = GetDetectorLoader(detname);
1682 if (!loader) return NULL;
1683 if (!loader->TreeH() && maketree) loader->MakeTree("H");
1684 return loader->TreeH();
1686 /**************************************************************************/
1688 TTree* AliRunLoader::GetTreeS(const char* detname, Bool_t maketree,const char* eventfoldername)
1690 //get the tree with summable digits of the detector with the given name
1691 //if maketree is true and the tree does not exist, the tree is created
1692 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1693 if (!loader) return NULL;
1694 if (!loader->TreeS() && maketree) loader->MakeTree("S");
1695 return loader->TreeS();
1697 /**************************************************************************/
1699 TTree* AliRunLoader::GetTreeS(const char* detname, Bool_t maketree)
1701 //get the tree with summable digits of the detector with the given name
1702 //if maketree is true and the tree does not exist, the tree is created
1703 AliLoader* loader = GetDetectorLoader(detname);
1704 if (!loader) return NULL;
1705 if (!loader->TreeS() && maketree) loader->MakeTree("S");
1706 return loader->TreeS();
1708 /**************************************************************************/
1710 TTree* AliRunLoader::GetTreeD(const char* detname, Bool_t maketree,const char* eventfoldername)
1712 //get the tree with digits of the detector with the given name
1713 //if maketree is true and the tree does not exist, the tree is created
1714 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1715 if (!loader) return NULL;
1716 if (!loader->TreeD() && maketree) loader->MakeTree("D");
1717 return loader->TreeD();
1719 /**************************************************************************/
1721 TTree* AliRunLoader::GetTreeD(const char* detname, Bool_t maketree)
1723 //get the tree with digits of the detector with the given name
1724 //if maketree is true and the tree does not exist, the tree is created
1725 AliLoader* loader = GetDetectorLoader(detname);
1726 if (!loader) return NULL;
1727 if (!loader->TreeD() && maketree) loader->MakeTree("D");
1728 return loader->TreeD();
1730 /**************************************************************************/
1731 TTree* AliRunLoader::GetTreeR(const char* detname, Bool_t maketree,const char* eventfoldername)
1733 //get the tree with clusters 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,eventfoldername);
1736 if (!loader) return NULL;
1737 if (!loader->TreeR() && maketree) loader->MakeTree("R");
1738 return loader->TreeR();
1740 /**************************************************************************/
1742 TTree* AliRunLoader::GetTreeR(const char* detname, Bool_t maketree)
1744 //get the tree with clusters of the detector with the given name
1745 //if maketree is true and the tree does not exist, the tree is created
1746 AliLoader* loader = GetDetectorLoader(detname);
1747 if (!loader) return NULL;
1748 if (!loader->TreeR() && maketree) loader->MakeTree("R");
1749 return loader->TreeR();
1751 /**************************************************************************/
1753 TTree* AliRunLoader::GetTreeT(const char* detname, Bool_t maketree,const char* eventfoldername)
1755 //get the tree with tracks of the detector with the given name
1756 //if maketree is true and the tree does not exist, the tree is created
1757 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1758 if (!loader) return NULL;
1759 if (!loader->TreeT() && maketree) loader->MakeTree("T");
1760 return loader->TreeT();
1762 /**************************************************************************/
1764 TTree* AliRunLoader::GetTreeT(const char* detname, Bool_t maketree)
1766 //get the tree with tracks of the detector with the given name
1767 //if maketree is true and the tree does not exist, the tree is created
1768 AliLoader* loader = GetDetectorLoader(detname);
1769 if (!loader) return NULL;
1770 if (!loader->TreeT() && maketree) loader->MakeTree("T");
1771 return loader->TreeT();
1773 /**************************************************************************/
1775 TTree* AliRunLoader::GetTreeP(const char* detname, Bool_t maketree,const char* eventfoldername)
1777 //get the tree with particles of the detector with the given name
1778 //if maketree is true and the tree does not exist, the tree is created
1779 AliLoader* loader = GetDetectorLoader(detname,eventfoldername);
1780 if (!loader) return NULL;
1781 if (!loader->TreeP() && maketree) loader->MakeTree("P");
1782 return loader->TreeP();
1784 /**************************************************************************/
1786 TTree* AliRunLoader::GetTreeP(const char* detname, Bool_t maketree)
1788 //get the tree with particles of the detector with the given name
1789 //if maketree is true and the tree does not exist, the tree is created
1790 AliLoader* loader = GetDetectorLoader(detname);
1791 if (!loader) return NULL;
1792 if (!loader->TreeP() && maketree) loader->MakeTree("P");
1793 return loader->TreeP();
1796 /**************************************************************************/
1798 void AliRunLoader::CdGAFile()
1800 //sets gDirectory to galice file
1802 if(fGAFile) fGAFile->cd();
1805 /**************************************************************************/
1807 void AliRunLoader::GetListOfDetectors(const char * namelist,TObjArray& pointerarray) const
1809 //this method looks for all Loaders corresponding
1810 //to names (many) specified in namelist i.e. namelist ("ITS TPC TRD")
1814 strcpy(dets,namelist);//compiler cries when char* = const Option_t*;
1815 dets[strlen(dets)+1] = '\n';//set endl at the end of string
1820 tmp = sscanf(pdet,"%s",buff);//read the string from the input string pdet into buff
1821 if ( (buff[0] == 0) || (tmp == 0) ) break; //if not read
1823 pdet = strstr(pdet,buff) + strlen(buff);//move the input pointer about number of bytes (letters) read
1824 //I am aware that is a little complicated. I don't know the number of spaces between detector names
1825 //so I read the string, than I find where it starts (strstr) and move the pointer about length of a string
1826 //If there is a better way, please write me (Piotr.Skowronski@cern.ch)
1827 //construct the Loader name
1828 TString getname(buff);
1830 AliLoader* loader = GetLoader(getname);//get the Loader
1833 pointerarray.Add(loader);
1837 AliError(Form("Can not find Loader for %s",buff));
1843 /*****************************************************************************/
1845 void AliRunLoader::Clean(const TString& name)
1847 //removes object with given name from event folder and deletes it
1848 if (GetEventFolder() == 0x0) return;
1849 TObject* obj = GetEventFolder()->FindObject(name);
1852 AliDebug(1, Form("name=%s, cleaning %s.",GetName(),name.Data()));
1853 GetEventFolder()->Remove(obj);
1859 /*****************************************************************************/
1861 TTask* AliRunLoader::GetRunDigitizer()
1863 //returns Run Digitizer from folder
1865 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1866 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetDigitizerTaskName());
1867 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1869 /*****************************************************************************/
1871 TTask* AliRunLoader::GetRunSDigitizer()
1873 //returns SDigitizer Task from folder
1875 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1876 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetSDigitizerTaskName());
1877 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1879 /*****************************************************************************/
1881 TTask* AliRunLoader::GetRunReconstructioner()
1883 //returns Reconstructioner Task from folder
1884 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1885 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetReconstructionerTaskName());
1886 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1888 /*****************************************************************************/
1890 TTask* AliRunLoader::GetRunTracker()
1892 //returns Tracker Task from folder
1893 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1894 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetTrackerTaskName());
1895 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1897 /*****************************************************************************/
1899 TTask* AliRunLoader::GetRunPIDTask()
1901 //returns Tracker Task from folder
1902 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1903 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetPIDTaskName());
1904 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1906 /*****************************************************************************/
1908 TTask* AliRunLoader::GetRunQATask()
1910 //returns Quality Assurance Task from folder
1911 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1914 AliErrorClass("Can not get task folder from AliConfig");
1917 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetQATaskName());
1918 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1921 /*****************************************************************************/
1923 void AliRunLoader::SetCompressionLevel(Int_t cl)
1925 //Sets Compression Level in all files
1926 if (fGAFile) fGAFile->SetCompressionLevel(cl);
1927 SetKineComprLevel(cl);
1928 SetTrackRefsComprLevel(cl);
1929 TIter next(fLoaders);
1931 while((loader = (AliLoader*)next()))
1933 loader->SetCompressionLevel(cl);
1936 /**************************************************************************/
1938 void AliRunLoader::SetKineComprLevel(Int_t cl)
1940 //Sets comression level in Kine File
1941 fKineDataLoader->SetCompressionLevel(cl);
1943 /**************************************************************************/
1945 void AliRunLoader::SetTrackRefsComprLevel(Int_t cl)
1947 //Sets comression level in Track Refences File
1948 fTrackRefsDataLoader->SetCompressionLevel(cl);
1950 /**************************************************************************/
1952 void AliRunLoader::UnloadHeader()
1954 //removes TreeE from folder and deletes it
1955 // as well as fHeader object
1960 /**************************************************************************/
1962 void AliRunLoader::UnloadTrigger()
1964 //removes TreeCT from folder and deletes it
1965 // as well as fHeader object
1971 /**************************************************************************/
1973 void AliRunLoader::UnloadKinematics()
1975 //Unloads Kinematics
1976 fKineDataLoader->GetBaseLoader(0)->Unload();
1978 /**************************************************************************/
1980 void AliRunLoader::UnloadTrackRefs()
1982 //Unloads Track Refernces
1983 fTrackRefsDataLoader->GetBaseLoader(0)->Unload();
1985 /**************************************************************************/
1987 void AliRunLoader::UnloadgAlice()
1990 if (gAlice == GetAliRun())
1992 AliDebug(1, "Set gAlice = 0x0");
1993 gAlice = 0x0;//if gAlice is the same that in folder (to be deleted by the way of folder)
1995 AliRun* alirun = GetAliRun();
1996 if (GetEventFolder()) GetEventFolder()->Remove(alirun);
1999 /**************************************************************************/
2001 void AliRunLoader::MakeTrackRefsContainer()
2003 // Makes a tree for Track References
2004 fTrackRefsDataLoader->MakeTree();
2006 /**************************************************************************/
2008 Int_t AliRunLoader::LoadTrackRefs(Option_t* option)
2010 //Load track references from file (opens file and posts tree to folder)
2012 return fTrackRefsDataLoader->GetBaseLoader(0)->Load(option);
2014 /**************************************************************************/
2016 void AliRunLoader::SetDirName(TString& dirname)
2018 //sets directory name
2019 if (dirname.IsNull()) return;
2020 fUnixDirName = dirname;
2021 fKineDataLoader->SetDirName(dirname);
2022 fTrackRefsDataLoader->SetDirName(dirname);
2024 TIter next(fLoaders);
2026 while((loader = (AliLoader*)next()))
2028 loader->SetDirName(dirname);
2032 /*****************************************************************************/
2034 Int_t AliRunLoader::GetFileOffset() const
2036 //returns the file number that is added to the file name for current event
2037 return Int_t(fCurrentEvent/fNEventsPerFile);
2040 /*****************************************************************************/
2041 const TString AliRunLoader::SetFileOffset(const TString& fname)
2043 //adds the the number to the file name at proper place for current event
2044 Long_t offset = (Long_t)GetFileOffset();
2045 if (offset < 1) return fname;
2047 soffset += offset;//automatic conversion to string
2048 TString dotroot(".root");
2049 const TString& offfsetdotroot = offset + dotroot;
2050 TString out = fname;
2051 out = out.ReplaceAll(dotroot,offfsetdotroot);
2052 AliDebug(1, Form(" in=%s out=%s",fname.Data(),out.Data()));
2055 /*****************************************************************************/
2057 void AliRunLoader::SetDigitsFileNameSuffix(const TString& suffix)
2059 //adds the suffix before ".root",
2060 //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
2061 //made on Jiri Chudoba demand
2063 TIter next(fLoaders);
2065 while((loader = (AliLoader*)next()))
2067 loader->SetDigitsFileNameSuffix(suffix);
2070 /*****************************************************************************/
2072 TString AliRunLoader::GetFileName() const
2074 //returns name of galice file
2076 if (fGAFile == 0x0) return result;
2077 result = fGAFile->GetName();
2080 /*****************************************************************************/
2082 void AliRunLoader::SetDetectorAddresses()
2084 //calls SetTreeAddress for all detectors
2085 if (GetAliRun()==0x0) return;
2086 TIter next(GetAliRun()->Modules());
2088 while((mod = (AliModule*)next()))
2090 AliDetector* det = dynamic_cast<AliDetector*>(mod);
2091 if (det) det->SetTreeAddress();
2094 /*****************************************************************************/
2096 void AliRunLoader::Synchronize()
2098 //synchrinizes all writtable files
2099 TIter next(fLoaders);
2101 while((loader = (AliLoader*)next()))
2103 loader->Synchronize();
2106 fKineDataLoader->Synchronize();
2107 fTrackRefsDataLoader->Synchronize();
2109 TFile* file = gROOT->GetFile( gSystem->ConcatFileName( fUnixDirName.Data(), fgkDefaultTriggerFileName.Data() ) ) ;
2110 if( file ) file->Flush();
2112 if (fGAFile) fGAFile->Flush();
2114 /*****************************************************************************/
2115 /*****************************************************************************/