1 #include <AliDataLoader.h>
2 //__________________________________________
3 /////////////////////////////////////////////////////////////////////////////////////////////
5 // class AliDataLoader //
7 // Container of all data needed for full //
8 // description of each data type //
9 // (Hits, Kine, ...) //
11 // Each data loader has a basic standard setup of BaseLoaders //
12 // which can be identuified by indexes (defined by EStdBasicLoaders) //
13 // Data managed by these standard base loaders has fixed naming convention //
14 // e.g. - tree with hits is always named TreeH //
15 // (defined in AliLoader::fgkDefaultHitsContainerName) //
16 // - task DtectorName+Name defined //
18 // EStdBasicLoaders idx Object Type Description //
19 // kData 0 TTree or TObject main data itself (hits,digits,...) //
20 // kTask 1 TTask object producing main data //
21 // kQA 2 TTree quality assurance tree //
22 // kQATask 3 TTask task producing QA object //
25 // User can define and add more basic loaders even Run Time. //
26 // Caution: in order to save information about added base loader //
27 // user must rewrite Run Loader to galice.file, overwriting old setup //
29 /////////////////////////////////////////////////////////////////////////////////////////////
36 #include "AliRunLoader.h"
38 ClassImp(AliDataLoader)
40 AliDataLoader::AliDataLoader():
56 /*****************************************************************************/
58 AliDataLoader::AliDataLoader(const char* filename, const char* contname, const char* name, Option_t* opt):
66 fBaseLoaders(new TObjArray(4)),
74 // creates a 0 loader, depending on option, default "T" is specialized loader for trees
75 // else standard object loader
76 // trees needs special care, becouse we need to set dir before writing
78 Info("AliDataLoader","File name is %s",fFileName.Data());
82 if (option.CompareTo("T",TString::kIgnoreCase) == 0)
83 bl = new AliTreeLoader(contname,this);
85 bl = new AliObjectLoader(contname,this);
86 fBaseLoaders->AddAt(bl,kData);
89 /*****************************************************************************/
90 AliDataLoader::AliDataLoader(const AliDataLoader& source):TNamed(source) {
92 Fatal("AliDataLoader","Copy constructor not implemented");
94 /*****************************************************************************/
95 AliDataLoader& AliDataLoader::operator=(const AliDataLoader& /*source*/) {
96 // Assignment operator
97 Fatal("AliDataLoader","Assignment operator not implemented");
100 /*****************************************************************************/
102 AliDataLoader::~AliDataLoader()
107 /*****************************************************************************/
109 Int_t AliDataLoader::SetEvent()
111 //basically the same that GetEvent but do not post data to folders
112 AliRunLoader* rl = GetRunLoader();
115 Error("SetEvent","Can not get RunGettr");
119 Int_t evno = rl->GetEventNumber();
121 TIter next(fBaseLoaders);
123 while ((bl = (AliBaseLoader*)next()))
125 if (bl->DoNotReload() == kFALSE) bl->Clean();
134 if (GetDebug()) Info("SetEvent","Reloading new file. File opt is %s",fFileOption.Data());
135 OpenFile(fFileOption);
138 fDirectory = AliLoader::ChangeDir(fFile,evno);
139 if (fDirectory == 0x0)
141 Error("SetEvent","Can not chage directory in file %s",fFile->GetName());
147 /*****************************************************************************/
149 Int_t AliDataLoader::GetEvent()
151 // posts all loaded data from files to White Board
152 // event number is defined in RunLoader
155 // 0 - in case of no error
156 // 1 - event not found
158 //for each base laoder post, if was loaded before GetEvent
160 //call set event to switch to new directory in file
163 //post all data that were loaded before
164 // ->SetEvent does not call Unload, but only cleans White Board
165 // such IsLoaded flag stays untached
167 if ( AliLoader::TestFileOption(fFileOption) == kTRUE ) //if file is read or update mode try to post
168 { //in other case there is no sense to post: file is new
169 TIter nextbl(fBaseLoaders);
171 while ((bl = (AliBaseLoader*)nextbl()))
175 if (bl->DoNotReload() == kFALSE) bl->Post();
181 /*****************************************************************************/
183 Int_t AliDataLoader::OpenFile(Option_t* opt)
185 //Opens file named 'filename', and assigns pointer to it to 'file'
186 //jumps to fDirectoryectory corresponding to current event and stores the pointer to it in 'fDirectory'
187 //option 'opt' is passed to TFile::Open
190 if(fFile->IsOpen() == kTRUE)
192 Warning("OpenFile"," File %s already opened. First close it.",fFile->GetName());
197 Warning("OpenFile","Pointer to file %s is not null, but file is not opened",
204 TString fname(SetFileOffset(fFileName));
206 fFile = (TFile *)(gROOT->GetListOfFiles()->FindObject(fname));
209 if(fFile->IsOpen() == kTRUE)
211 Warning("OpenFile","File %s already opened by sombody else. First close it.",
218 fFile = TFile::Open(fname,fFileOption);//open the file
221 Error("OpenFile","Can not open file %s",fname.Data());
224 if (fFile->IsOpen() == kFALSE)
226 Error("OpenFile","Can not open file %s",fname.Data());
230 fFile->SetCompressionLevel(fCompressionLevel);
232 AliRunLoader* rg = GetRunLoader();
235 Error("OpenFile","Can not find Run-Loader in folder.");
238 Int_t evno = rg->GetEventNumber();
240 fDirectory = AliLoader::ChangeDir(fFile,evno);
241 if (fDirectory == 0x0)
243 Error("OpenFile","Can not chage fDirectory in file %s.",fFile->GetName());
248 /*****************************************************************************/
250 void AliDataLoader::Unload()
252 //unloads main data - shortcut method
253 GetBaseLoader(0)->Unload();
255 /*****************************************************************************/
257 void AliDataLoader::UnloadAll()
259 //Unloads all data and tasks
260 if ( fFile == 0x0 ) return; //nothing loaded
262 TIter next(fBaseLoaders);
264 while ((bl = (AliBaseLoader*)next()))
269 /*****************************************************************************/
271 Int_t AliDataLoader::Reload()
273 //Unloads and loads data again
274 if ( fFile == 0x0 ) return 0;
276 TBits loaded(fBaseLoaders->GetEntries());
277 TIter next(fBaseLoaders);
281 while ((bl = (AliBaseLoader*)next()))
285 loaded.SetBitNumber(i++,kTRUE);
293 while ((bl = (AliBaseLoader*)next()))
295 if (loaded.TestBitNumber(i++))
297 retval = bl->Load(fFileOption);
300 Error("Reload","Error occur while loading %s",bl->GetName());
309 /*****************************************************************************/
310 Int_t AliDataLoader::WriteData(Option_t* opt)
312 //Writes primary data == first BaseLoader
314 Info("WriteData","Writing %s container for %s data. Option is %s.",
315 GetBaseLoader(0)->GetName(),GetName(),opt);
316 return GetBaseLoader(0)->WriteData(opt);
318 /*****************************************************************************/
320 Int_t AliDataLoader::Load(Option_t* opt)
322 //Writes primary data == first BaseLoader
323 return GetBaseLoader(0)->Load(opt);
325 /*****************************************************************************/
327 Int_t AliDataLoader::SetEventFolder(TFolder* eventfolder)
329 //sets the event folder
330 if (eventfolder == 0x0)
332 Error("SetEventFolder","Stupid joke. Argument is NULL");
336 Info("SetFolder","name = %s Setting Event Folder named %s.",
337 GetName(),eventfolder->GetName());
339 fEventFolder = eventfolder;
342 /*****************************************************************************/
344 Int_t AliDataLoader::SetFolder(TFolder* folder)
346 // Sets the folder and the data loaders
349 Error("SetFolder","Stupid joke. Argument is NULL");
353 if (GetDebug()) Info("SetFolder","name = %s Setting folder named %s.",GetName(),folder->GetName());
356 TIter next(fBaseLoaders);
359 while ((bl = (AliBaseLoader*)next()))
361 bl->SetDataLoader(this);
366 /******************************************************************/
368 TFolder* AliDataLoader::GetEventFolder()
370 //get EVENT folder (data that are changing from event to event, even in single run)
371 if (GetDebug()) Info("GetEventFolder","EF = %#x");
374 /*****************************************************************************/
376 AliRunLoader* AliDataLoader::GetRunLoader()
378 //gets the run-loader from event folder
379 AliRunLoader* rg = 0x0;
380 TFolder* ef = GetEventFolder();
383 Error("GetRunLoader","Can not get event folder.");
386 rg = dynamic_cast<AliRunLoader*>(ef->FindObject(AliRunLoader::GetRunLoaderName()));
390 /*****************************************************************************/
391 void AliDataLoader::CloseFile()
394 TIter next(fBaseLoaders);
396 while ((bl = (AliBaseLoader*)next()))
398 if (bl->IsLoaded()) return;
402 Info("CloseFile","Closing and deleting (object) file.");
408 /*****************************************************************************/
410 void AliDataLoader::Clean()
413 GetBaseLoader(0)->Clean();
415 /*****************************************************************************/
417 void AliDataLoader::CleanAll()
419 //Cleans all folders and tasks
420 TIter next(fBaseLoaders);
422 while ((bl = (AliBaseLoader*)next()))
427 /*****************************************************************************/
429 void AliDataLoader::SetFileNameSuffix(const TString& suffix)
431 //adds the suffix before ".root",
432 //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
433 //made on Jiri Chudoba demand
436 Info("SetFileNameSuffix","suffix=%s",suffix.Data());
437 Info("SetFileNameSuffix"," Digits File Name before: %s",fFileName.Data());
440 static TString dotroot(".root");
441 const TString& suffixdotroot = suffix + dotroot;
442 fFileName = fFileName.ReplaceAll(dotroot,suffixdotroot);
445 Info("SetDigitsFileNameSuffix"," after : %s",fFileName.Data());
447 /*****************************************************************************/
449 Bool_t AliDataLoader::CheckReload()
451 //checks if we have to reload given file
452 if (fFile == 0x0) return kFALSE;
453 TString tmp = SetFileOffset(fFileName);
454 if (tmp.CompareTo(fFile->GetName())) return kTRUE; //file must be reloaded
457 /*****************************************************************************/
459 const TString AliDataLoader::SetFileOffset(const TString& fname)
463 Long_t offset = (Long_t)GetRunLoader()->GetFileOffset();
464 if (fNEventsPerFile > 0) {
465 offset = GetRunLoader()->GetEventNumber()/fNEventsPerFile;
467 if (offset < 1) return fname;
470 soffset += offset;//automatic conversion to string
471 TString dotroot(".root");
472 const TString& offfsetdotroot = offset + dotroot;
474 out = out.ReplaceAll(dotroot,offfsetdotroot);
475 if (GetDebug()) Info("SetFileOffset","in=%s out=%s.",fname.Data(),out.Data());
479 /*****************************************************************************/
481 void AliDataLoader::SetFileOption(Option_t* newopt)
484 if (fFileOption.CompareTo(newopt) == 0) return;
485 fFileOption = newopt;
488 /*****************************************************************************/
490 void AliDataLoader::SetCompressionLevel(Int_t cl)
492 //sets comression level for data defined by di
493 fCompressionLevel = cl;
494 if (fFile) fFile->SetCompressionLevel(cl);
496 /*****************************************************************************/
498 Int_t AliDataLoader::GetDebug() const
500 //it is not inline bacause AliLoader.h includes AliDataLoaer.h
501 //and there is circular depenedence
502 return AliLoader::GetDebug();
504 /*****************************************************************************/
506 void AliDataLoader::MakeTree()
508 // Makes tree for the current data loader
509 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(fBaseLoaders->At(0));
512 Error("MakeTree","Can not make a tree because main base loader is not a tree loader");
517 /*****************************************************************************/
519 Bool_t AliDataLoader::IsFileWritable() const
521 //returns true if file is writable
522 return (fFile)?fFile->IsWritable():kFALSE;
524 /*****************************************************************************/
526 Bool_t AliDataLoader::IsFileOpen() const
528 //returns true if file is writable
529 return (fFile)?fFile->IsOpen():kFALSE;
531 /*****************************************************************************/
533 Bool_t AliDataLoader::IsOptionContrary(const TString& option) const
535 //Checks if passed option is contrary with file open option
536 //which is passed option "writable" and existing option not wriable
537 //in reverse case it is no harm so it is NOT contrary
538 if (fFile == 0x0) return kFALSE; //file is not opened - no problem
540 if ( ( AliLoader::IsOptionWritable(option) == kTRUE ) && // passed option is writable and
541 ( AliLoader::IsOptionWritable(fFileOption) == kFALSE ) ) // existing one is not writable
548 /*****************************************************************************/
549 void AliDataLoader::AddBaseLoader(AliBaseLoader* bl)
551 //Adds a base loader to lits of base loaders managed by this data loader
552 //Managed data/task will be stored in proper root directory,
554 // - in case of tree/object - data folder connected with detector associated with this data loader
555 // - in case of task - parental task which defined in this AliTaskLoader
559 Warning("AddBaseLoader","Pointer is null.");
563 TObject* obj = fBaseLoaders->FindObject(bl->GetName());
566 Error("AddBaseLoader","Can not add this base loader.");
567 Error("AddBaseLoader","There exists already base loader which manages data named %s for this detector.");
572 fBaseLoaders->Add(bl);
575 /*****************************************************************************/
577 AliBaseLoader* AliDataLoader::GetBaseLoader(const TString& name) const
579 return dynamic_cast<AliBaseLoader*>(fBaseLoaders->FindObject(name));
581 /*****************************************************************************/
583 AliBaseLoader* AliDataLoader::GetBaseLoader(Int_t n) const
585 // Gets the n-th base loader (what is n?)
586 return dynamic_cast<AliBaseLoader*>(fBaseLoaders->At(n));
588 /*****************************************************************************/
590 TTree* AliDataLoader::Tree() const
592 //returns tree from the main base loader
593 //it is just shortcut method for comfort of user
594 //main storage object does not have to be Tree -
595 //that is why first we need to check if it is a TreeLoader
596 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(GetBaseLoader(0));
597 if (tl == 0x0) return 0x0;
600 /*****************************************************************************/
602 void AliDataLoader::SetDirName(TString& dirname)
604 // Sets the directory name where the files will be stored
605 if (GetDebug()>9) Info("SetDirName","FileName before %s",fFileName.Data());
607 Int_t n = fFileName.Last('/');
609 if (GetDebug()>9) Info("SetDirName","Slash found on pos %d",n);
611 if (n > 0) fFileName = fFileName.Remove(0,n+1);
613 if (GetDebug()>9) Info("SetDirName","Core FileName %s",fFileName.Data());
615 fFileName = dirname + "/" + fFileName;
617 if (GetDebug()>9) Info("SetDirName","FileName after %s",fFileName.Data());
619 /*****************************************************************************/
620 AliObjectLoader* AliDataLoader::GetBaseDataLoader()
622 // Gets the base data loader
623 return dynamic_cast<AliObjectLoader*>(GetBaseLoader(kData));
625 /*****************************************************************************/
626 AliTaskLoader* AliDataLoader::GetBaseTaskLoader()
628 // Gets the base task loader
629 return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kTask));
631 /*****************************************************************************/
632 AliBaseLoader* AliDataLoader::GetBaseQALoader()
634 // Gets the base QA loader
635 return GetBaseLoader(kQA);
637 /*****************************************************************************/
638 AliTaskLoader* AliDataLoader::GetBaseQATaskLoader()
640 //returns pointer to QA base loader
641 return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kQATask));
643 /*****************************************************************************/
644 void AliDataLoader::SetBaseDataLoader(AliBaseLoader* bl)
646 //sets data base loader
649 Error("SetBaseDataLoader","Parameter is null");
652 if (GetBaseDataLoader()) delete GetBaseDataLoader();
653 fBaseLoaders->AddAt(bl,kData);
655 /*****************************************************************************/
656 void AliDataLoader::SetBaseTaskLoader(AliTaskLoader* bl)
658 //sets Task base loader
661 Error("SetBaseTaskLoader","Parameter is null");
664 if (GetBaseTaskLoader()) delete GetBaseTaskLoader();
665 fBaseLoaders->AddAt(bl,kTask);
667 /*****************************************************************************/
668 void AliDataLoader::SetBaseQALoader(AliBaseLoader* bl)
670 //sets QA base loader
673 Error("SetBaseQALoader","Parameter is null");
676 if (GetBaseQALoader()) delete GetBaseQALoader();
677 fBaseLoaders->AddAt(bl,kQA);
679 /*****************************************************************************/
680 void AliDataLoader::SetBaseQATaskLoader(AliTaskLoader* bl)
682 //sets QA Task base loader
685 Error("SetBaseQATaskLoader","Parameter is null");
688 if (GetBaseQATaskLoader()) delete GetBaseQATaskLoader();
689 fBaseLoaders->AddAt(bl,kQATask);
691 void AliDataLoader::Synchronize()
693 //synchrinizes all writtable files
694 if ( fFile ) fFile->Flush();
697 /*****************************************************************************/
698 /*****************************************************************************/
699 /*****************************************************************************/
700 //__________________________________________
701 ///////////////////////////////////////////////////////////////////////////////
703 // class AliBaseLoader //
706 ///////////////////////////////////////////////////////////////////////////////
707 ClassImp(AliBaseLoader)
709 AliBaseLoader::AliBaseLoader():
711 fStoreInTopOfFile(kFALSE),
712 fDoNotReload(kFALSE),
715 //default constructor
717 /*****************************************************************************/
719 AliBaseLoader::AliBaseLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
720 TNamed(name,name+" Base Loader"),
722 fStoreInTopOfFile(storeontop),
723 fDoNotReload(storeontop),//if stored on top of file - this object is loaded ones pe
729 /*****************************************************************************/
730 AliBaseLoader::AliBaseLoader(const AliBaseLoader& source):TNamed(source) {
732 Fatal("AliBaseLoader","Copy constructor not implemented");
734 /*****************************************************************************/
735 AliBaseLoader& AliBaseLoader::operator=(const AliBaseLoader& /*source*/) {
736 // Assignment operator
737 Fatal("AliBaseLoader","Assignment operator not implemented");
740 /*****************************************************************************/
742 Int_t AliBaseLoader::Load(Option_t* opt)
744 // Loads and posts the data
746 Info("Load","data type = %s, option = %s",GetName(),opt);
751 Warning("Load","Data <<%s>> are already loaded. Use ReloadData to force reload. Nothing done",GetName());
757 if (GetDataLoader()->IsFileOpen() == kTRUE)
759 if (GetDataLoader()->IsOptionContrary(opt) == kTRUE)
761 Error("Load","Data Type %s, Container Name %s", GetDataLoader()->GetName(),GetName());
762 Error("Load","File was already opened in READ-ONLY mode, while now WRITEABLE access is requested.");
763 Error("Load","Use AliDataLoader::SetOption to enforce change of access mode OR");
764 Error("Load","Load previosly loaded data with coherent option.");
770 retval = GetDataLoader()->OpenFile(opt);
773 Error("Load","Error occured while opening <<%s>> file",GetName());
777 //if file is recreated there is no sense to search for data to post and get Error message
778 if (AliLoader::TestFileOption(opt) == kFALSE)
780 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(this);
781 if (tl) tl->MakeTree();
789 Error("Load","Error occured while posting %s from file to folder.",GetName());
796 /*****************************************************************************/
798 Int_t AliBaseLoader::Post()
800 //Posts data container to proper folders
802 if ( GetDirectory() == 0x0)
804 Error("Post","%s directory is NULL. Load before.",GetDataLoader()->GetName());
808 TObject* data = GetFromDirectory(fName);
811 //if such an obejct already exists - remove it first
816 //check if file is in update mode
817 Int_t fileupdate = GetDataLoader()->GetFileOption().CompareTo("update",TString::kIgnoreCase);
818 if ( fileupdate == 0)
819 { //if it is, it is normal that there is no data yet
822 Info("Post","Can not find %s in file %s (file is opened in UPDATE mode).",
823 GetName(),GetDataLoader()->GetFile()->GetName());
828 Error("Post","Can not find %s in file %s", GetName(),GetDataLoader()->GetFile()->GetName());
834 /*****************************************************************************/
836 Int_t AliBaseLoader::Post(TObject* data)
838 //Posts data container to proper folders
841 Error("Post","Pointer to object is NULL");
845 if ( fName.CompareTo(data->GetName()) != 0)
847 Fatal("Post(TObject*)","Object name is <<%s>> while <<%s>> expected",data->GetName(),GetName());
848 return -1;//pro forma
851 TObject* obj = Get();
854 if (GetDebug()) Warning("Post","This object was already posted.");
859 Warning("PostData","Object named %s already exitsts in data folder. Removing it",GetName());
862 return AddToBoard(data);
864 /*****************************************************************************/
866 Int_t AliBaseLoader::WriteData(Option_t* opt)
868 //Writes data defined by di object
869 //opt might be "OVERWRITE" in case of forcing overwriting
871 Info("WriteData","Writing %s container for %s data. Option is %s.",
872 GetName(),GetDataLoader()->GetName(),opt);
874 TObject *data = Get();
876 {//did not get, nothing to write
877 Warning("WriteData","Tree named %s not found in folder. Nothing to write.",GetName());
881 //check if file is opened
882 if (GetDirectory() == 0x0)
885 GetDataLoader()->SetFileOption("UPDATE");
886 if (GetDataLoader()->OpenFile("UPDATE"))
888 //oops, can not open the file, give an error message and return error code
889 Error("WriteData","Can not open hits file. %s ARE NOT WRITTEN",GetName());
894 if (GetDataLoader()->IsFileWritable() == kFALSE)
896 Error("WriteData","File %s is not writable",GetDataLoader()->GetFileName().Data());
900 GetDirectory()->cd(); //set the proper directory active
902 //see if hits container already exists in this (root) directory
903 TObject* obj = GetFromDirectory(GetName());
905 { //if they exist, see if option OVERWRITE is used
906 const char *oOverWrite = strstr(opt,"OVERWRITE");
908 {//if it is not used - give an error message and return an error code
909 Error("WriteData","Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
914 if (GetDebug()) Info("WriteData","DataName = %s, opt = %s, data object name = %s",
915 GetName(),opt,data->GetName());
916 if (GetDebug()) Info("WriteData","File Name = %s, Directory Name = %s Directory's File Name = %s",
917 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
918 GetDirectory()->GetFile()->GetName());
920 if (GetDebug()) Info("WriteData","Writing data");
921 data->Write(0,TObject::kOverwrite);
923 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
928 /*****************************************************************************/
930 Int_t AliBaseLoader::Reload()
932 //Unloads and loads datat again - if loaded before
936 return Load(GetDataLoader()->GetFileOption());
940 /*****************************************************************************/
942 void AliBaseLoader::Clean()
944 //removes objects from folder/task
945 if (GetDebug()) Info("Clean","%s %s",GetName(),GetDataLoader()->GetName());
946 TObject* obj = Get();
950 Info("Clean","cleaning %s.",GetName());
951 RemoveFromBoard(obj);
955 /*****************************************************************************/
957 void AliBaseLoader::Unload()
959 // Unloads data and closes the files
962 GetDataLoader()->CloseFile();
964 /*****************************************************************************/
965 AliDataLoader* AliBaseLoader::GetDataLoader() const
967 // Returns pointer to the data loader
968 if (fDataLoader == 0x0)
970 Fatal("GetDataLoader","Pointer to Data Loader is NULL");
974 /*****************************************************************************/
976 Int_t AliBaseLoader::GetDebug() const
978 // Returns debug level
979 return (Int_t)AliLoader::GetDebug();
982 TDirectory* AliBaseLoader::GetDirectory() const
984 // returnd TDirectory where data are to be saved
985 //if fStoreInTopOfFile flag is true - returns pointer to file
986 return (fStoreInTopOfFile)?GetDataLoader()->GetFile():GetDataLoader()->GetDirectory();
988 /*****************************************************************************/
989 /*****************************************************************************/
990 /*****************************************************************************/
991 //__________________________________________
992 ///////////////////////////////////////////////////////////////////////////////
994 // class AliObjectLoader //
997 ///////////////////////////////////////////////////////////////////////////////
999 ClassImp(AliObjectLoader)
1001 AliObjectLoader::AliObjectLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
1002 AliBaseLoader(name,dl,storeontop)
1006 /*****************************************************************************/
1008 TFolder* AliObjectLoader::GetFolder() const
1010 // Returns pointer to the object folder
1011 TFolder* df = GetDataLoader()->GetFolder();
1014 Fatal("GetFolder","Data Folder is NULL");
1018 /*****************************************************************************/
1019 AliObjectLoader::AliObjectLoader(const AliObjectLoader& source):
1020 AliBaseLoader(source) {
1022 Fatal("AliObjectLoader","Copy constructor not implemented");
1024 /*****************************************************************************/
1025 AliObjectLoader& AliObjectLoader::operator=(const AliObjectLoader& /*source*/) {
1026 // Assignment operator
1027 Fatal("AliObjectLoader","Assignment operator not implemented");
1030 /*****************************************************************************/
1032 void AliObjectLoader::RemoveFromBoard(TObject* obj)
1034 // Removes "obj" from the board
1035 GetFolder()->Remove(obj);
1037 /*****************************************************************************/
1038 Int_t AliObjectLoader::AddToBoard(TObject* obj)
1040 // Adds "obj" to the board
1041 GetFolder()->Add(obj);
1044 /*****************************************************************************/
1046 TObject* AliObjectLoader::Get() const
1048 // Returns pointer to the object loader
1049 return (GetFolder()) ? GetFolder()->FindObject(GetName()) : 0x0;
1052 /*****************************************************************************/
1053 /*****************************************************************************/
1054 /*****************************************************************************/
1055 //__________________________________________
1056 ///////////////////////////////////////////////////////////////////////////////
1058 // class AliTreeLoader //
1061 ///////////////////////////////////////////////////////////////////////////////
1063 ClassImp(AliTreeLoader)
1065 AliTreeLoader::AliTreeLoader(const TString& name, AliDataLoader* dl,Bool_t storeontop):
1066 AliObjectLoader(name,dl,storeontop)
1070 /*****************************************************************************/
1071 AliTreeLoader::AliTreeLoader(const AliTreeLoader& source):
1072 AliObjectLoader(source) {
1074 Fatal("AliTreeLoader","Copy constructor not implemented");
1076 /*****************************************************************************/
1077 AliTreeLoader& AliTreeLoader::operator=(const AliTreeLoader& /*source*/) {
1078 // Assignment operator
1079 Fatal("AliTreeLoader","Assignment operator not implemented");
1083 /*****************************************************************************/
1085 Int_t AliTreeLoader::WriteData(Option_t* opt)
1087 //Writes data defined by di object
1088 //opt might be "OVERWRITE" in case of forcing overwriting
1091 Info("WriteData","Writing %s container for %s data. Option is %s.",
1092 GetName(),GetDataLoader()->GetName(),opt);
1094 TObject *data = Get();
1096 {//did not get, nothing to write
1097 Warning("WriteData","Tree named %s not found in folder. Nothing to write.",GetName());
1101 //check if file is opened
1102 if (GetDirectory() == 0x0)
1104 //if not try to open
1105 GetDataLoader()->SetFileOption("UPDATE");
1106 if (GetDataLoader()->OpenFile("UPDATE"))
1108 //oops, can not open the file, give an error message and return error code
1109 Error("WriteData","Can not open hits file. %s ARE NOT WRITTEN",GetName());
1114 if (GetDataLoader()->IsFileWritable() == kFALSE)
1116 Error("WriteData","File %s is not writable",GetDataLoader()->GetFileName().Data());
1120 GetDirectory()->cd(); //set the proper directory active
1122 //see if hits container already exists in this (root) directory
1123 TObject* obj = GetFromDirectory(GetName());
1125 { //if they exist, see if option OVERWRITE is used
1126 const char *oOverWrite = strstr(opt,"OVERWRITE");
1128 {//if it is not used - give an error message and return an error code
1129 Error("WriteData","Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
1134 if (GetDebug()) Info("WriteData","DataName = %s, opt = %s, data object name = %s",
1135 GetName(),opt,data->GetName());
1136 if (GetDebug()) Info("WriteData","File Name = %s, Directory Name = %s Directory's File Name = %s",
1137 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
1138 GetDirectory()->GetFile()->GetName());
1140 //if a data object is a tree set the directory
1141 TTree* tree = dynamic_cast<TTree*>(data);
1142 if (tree) tree->SetDirectory(GetDirectory()); //forces setting the directory to this directory (we changed dir few lines above)
1144 if (GetDebug()) Info("WriteData","Writing tree");
1145 data->Write(0,TObject::kOverwrite);
1147 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
1152 /*****************************************************************************/
1154 void AliTreeLoader::MakeTree()
1156 //this virtual method creates the tree in the file
1160 Info("MakeTree","name = %s, Data Name = %s Tree already exists.",
1161 GetName(),GetDataLoader()->GetName());
1162 return;//tree already made
1165 Info("MakeTree","Making Tree named %s.",GetName());
1167 TString dtypename(GetDataLoader()->GetName());
1168 TTree* tree = new TTree(GetName(), dtypename + " Container"); //make a tree
1171 Error("MakeTree","Can not create %s tree.",GetName());
1174 tree->SetAutoSave(1000000000); //no autosave
1175 GetFolder()->Add(tree);
1176 WriteData("OVERWRITE");//write tree to the file
1180 /*****************************************************************************/
1181 /*****************************************************************************/
1182 /*****************************************************************************/
1183 //__________________________________________
1184 ///////////////////////////////////////////////////////////////////////////////
1186 // class AliTaskLoader //
1189 ///////////////////////////////////////////////////////////////////////////////
1191 ClassImp(AliTaskLoader)
1193 AliTaskLoader::AliTaskLoader(const TString& name, AliDataLoader* dl, TTask* parentaltask, Bool_t storeontop):
1194 AliBaseLoader(name,dl,storeontop),
1195 fParentalTask(parentaltask)
1200 /*****************************************************************************/
1201 AliTaskLoader::AliTaskLoader(const AliTaskLoader& source):
1202 AliBaseLoader(source) {
1204 Fatal("AliTaskLoader","Copy constructor not implemented");
1206 /*****************************************************************************/
1207 AliTaskLoader& AliTaskLoader::operator=(const AliTaskLoader& /*source*/) {
1208 // Assignment operator
1209 Fatal("AliTaskLoader","Assignment operator not implemented");
1212 /*****************************************************************************/
1213 void AliTaskLoader::Clean()
1215 //removes tasl from parental task
1216 // DO NOT DELETE OBJECT contrary to BaseLoader
1218 if (GetDebug()) Info("Clean","%s %s",GetName(),GetDataLoader()->GetName());
1219 TObject* obj = Get();
1223 Info("Clean","cleaning %s.",GetName());
1224 RemoveFromBoard(obj);
1227 /*****************************************************************************/
1229 void AliTaskLoader::RemoveFromBoard(TObject* obj)
1231 // Removes the task "obj" from the board
1232 GetParentalTask()->GetListOfTasks()->Remove(obj);
1234 /*****************************************************************************/
1236 Int_t AliTaskLoader::AddToBoard(TObject* obj)
1238 // Adds task "obj" to the board
1239 TTask* task = dynamic_cast<TTask*>(obj);
1242 Error("AddToBoard","To TTask board can be added only tasks.");
1245 GetParentalTask()->Add(task);
1248 /*****************************************************************************/
1250 TObject* AliTaskLoader::Get() const
1252 // Returns pointer to the current task
1253 return (GetParentalTask()) ? GetParentalTask()->GetListOfTasks()->FindObject(GetName()) : 0x0;
1255 /*****************************************************************************/
1257 TTask* AliTaskLoader::GetParentalTask() const
1259 //returns parental tasks for this task
1260 return fParentalTask;
1263 /*****************************************************************************/
1265 /*****************************************************************************/
1266 /*****************************************************************************/
1267 /*****************************************************************************/