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():
55 /*****************************************************************************/
57 AliDataLoader::AliDataLoader(const char* filename, const char* contname, const char* name, Option_t* opt):
64 fBaseLoaders(new TObjArray(4)),
72 // creates a 0 loader, depending on option, default "T" is specialized loader for trees
73 // else standard object loader
74 // trees needs special care, becouse we need to set dir before writing
76 Info("AliDataLoader","File name is %s",fFileName.Data());
80 if (option.CompareTo("T",TString::kIgnoreCase) == 0)
81 bl = new AliTreeLoader(contname,this);
83 bl = new AliObjectLoader(contname,this);
84 fBaseLoaders->AddAt(bl,kData);
87 /*****************************************************************************/
88 AliDataLoader::AliDataLoader(const AliDataLoader& source):TNamed(source) {
90 Fatal("AliDataLoader","Copy constructor not implemented");
92 /*****************************************************************************/
93 AliDataLoader& AliDataLoader::operator=(const AliDataLoader& /*source*/) {
94 // Assignment operator
95 Fatal("AliDataLoader","Assignment operator not implemented");
98 /*****************************************************************************/
100 AliDataLoader::~AliDataLoader()
105 /*****************************************************************************/
107 Int_t AliDataLoader::SetEvent()
109 //basically the same that GetEvent but do not post data to folders
110 AliRunLoader* rl = GetRunLoader();
113 Error("SetEvent","Can not get RunGettr");
117 Int_t evno = rl->GetEventNumber();
119 TIter next(fBaseLoaders);
121 while ((bl = (AliBaseLoader*)next()))
123 if (bl->DoNotReload() == kFALSE) bl->Clean();
132 if (GetDebug()) Info("SetEvent","Reloading new file. File opt is %s",fFileOption.Data());
133 OpenFile(fFileOption);
136 fDirectory = AliLoader::ChangeDir(fFile,evno);
137 if (fDirectory == 0x0)
139 Error("SetEvent","Can not chage directory in file %s",fFile->GetName());
145 /*****************************************************************************/
147 Int_t AliDataLoader::GetEvent()
149 // posts all loaded data from files to White Board
150 // event number is defined in RunLoader
153 // 0 - in case of no error
154 // 1 - event not found
156 //for each base laoder post, if was loaded before GetEvent
158 //call set event to switch to new directory in file
161 //post all data that were loaded before
162 // ->SetEvent does not call Unload, but only cleans White Board
163 // such IsLoaded flag stays untached
165 if ( AliLoader::TestFileOption(fFileOption) == kTRUE ) //if file is read or update mode try to post
166 { //in other case there is no sense to post: file is new
167 TIter nextbl(fBaseLoaders);
169 while ((bl = (AliBaseLoader*)nextbl()))
173 if (bl->DoNotReload() == kFALSE) bl->Post();
179 /*****************************************************************************/
181 Int_t AliDataLoader::OpenFile(Option_t* opt)
183 //Opens file named 'filename', and assigns pointer to it to 'file'
184 //jumps to fDirectoryectory corresponding to current event and stores the pointer to it in 'fDirectory'
185 //option 'opt' is passed to TFile::Open
188 if(fFile->IsOpen() == kTRUE)
190 Warning("OpenFile"," File %s already opened. First close it.",fFile->GetName());
195 Warning("OpenFile","Pointer to file %s is not null, but file is not opened",
202 TString fname(SetFileOffset(fFileName));
204 fFile = (TFile *)(gROOT->GetListOfFiles()->FindObject(fname));
207 if(fFile->IsOpen() == kTRUE)
209 Warning("OpenFile","File %s already opened by sombody else. First close it.",
216 fFile = TFile::Open(fname,fFileOption);//open the file
219 Error("OpenFile","Can not open file %s",fname.Data());
222 if (fFile->IsOpen() == kFALSE)
224 Error("OpenFile","Can not open file %s",fname.Data());
228 fFile->SetCompressionLevel(fCompressionLevel);
230 AliRunLoader* rg = GetRunLoader();
233 Error("OpenFile","Can not find Run-Loader in folder.");
236 Int_t evno = rg->GetEventNumber();
238 fDirectory = AliLoader::ChangeDir(fFile,evno);
239 if (fDirectory == 0x0)
241 Error("OpenFile","Can not chage fDirectory in file %s.",fFile->GetName());
246 /*****************************************************************************/
248 void AliDataLoader::Unload()
250 //unloads main data - shortcut method
251 GetBaseLoader(0)->Unload();
253 /*****************************************************************************/
255 void AliDataLoader::UnloadAll()
257 //Unloads all data and tasks
258 if ( fFile == 0x0 ) return; //nothing loaded
260 TIter next(fBaseLoaders);
262 while ((bl = (AliBaseLoader*)next()))
267 /*****************************************************************************/
269 Int_t AliDataLoader::Reload()
271 //Unloads and loads data again
272 if ( fFile == 0x0 ) return 0;
274 TBits loaded(fBaseLoaders->GetEntries());
275 TIter next(fBaseLoaders);
279 while ((bl = (AliBaseLoader*)next()))
283 loaded.SetBitNumber(i++,kTRUE);
291 while ((bl = (AliBaseLoader*)next()))
293 if (loaded.TestBitNumber(i++))
295 retval = bl->Load(fFileOption);
298 Error("Reload","Error occur while loading %s",bl->GetName());
307 /*****************************************************************************/
308 Int_t AliDataLoader::WriteData(Option_t* opt)
310 //Writes primary data == first BaseLoader
312 Info("WriteData","Writing %s container for %s data. Option is %s.",
313 GetBaseLoader(0)->GetName(),GetName(),opt);
314 return GetBaseLoader(0)->WriteData(opt);
316 /*****************************************************************************/
318 Int_t AliDataLoader::Load(Option_t* opt)
320 //Writes primary data == first BaseLoader
321 return GetBaseLoader(0)->Load(opt);
323 /*****************************************************************************/
325 Int_t AliDataLoader::SetEventFolder(TFolder* eventfolder)
327 //sets the event folder
328 if (eventfolder == 0x0)
330 Error("SetEventFolder","Stupid joke. Argument is NULL");
334 Info("SetFolder","name = %s Setting Event Folder named %s.",
335 GetName(),eventfolder->GetName());
337 fEventFolder = eventfolder;
340 /*****************************************************************************/
342 Int_t AliDataLoader::SetFolder(TFolder* folder)
344 // Sets the folder and the data loaders
347 Error("SetFolder","Stupid joke. Argument is NULL");
351 if (GetDebug()) Info("SetFolder","name = %s Setting folder named %s.",GetName(),folder->GetName());
354 TIter next(fBaseLoaders);
357 while ((bl = (AliBaseLoader*)next()))
359 bl->SetDataLoader(this);
364 /******************************************************************/
366 TFolder* AliDataLoader::GetEventFolder()
368 //get EVENT folder (data that are changing from event to event, even in single run)
369 if (GetDebug()) Info("GetEventFolder","EF = %#x");
372 /*****************************************************************************/
374 AliRunLoader* AliDataLoader::GetRunLoader()
376 //gets the run-loader from event folder
377 AliRunLoader* rg = 0x0;
378 TFolder* ef = GetEventFolder();
381 Error("GetRunLoader","Can not get event folder.");
384 rg = dynamic_cast<AliRunLoader*>(ef->FindObject(AliRunLoader::GetRunLoaderName()));
388 /*****************************************************************************/
389 void AliDataLoader::CloseFile()
392 TIter next(fBaseLoaders);
394 while ((bl = (AliBaseLoader*)next()))
396 if (bl->IsLoaded()) return;
400 Info("CloseFile","Closing and deleting (object) file.");
406 /*****************************************************************************/
408 void AliDataLoader::Clean()
411 GetBaseLoader(0)->Clean();
413 /*****************************************************************************/
415 void AliDataLoader::CleanAll()
417 //Cleans all folders and tasks
418 TIter next(fBaseLoaders);
420 while ((bl = (AliBaseLoader*)next()))
425 /*****************************************************************************/
427 void AliDataLoader::SetFileNameSuffix(const TString& suffix)
429 //adds the suffix before ".root",
430 //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
431 //made on Jiri Chudoba demand
434 Info("SetFileNameSuffix","suffix=%s",suffix.Data());
435 Info("SetFileNameSuffix"," Digits File Name before: %s",fFileName.Data());
438 static TString dotroot(".root");
439 const TString& suffixdotroot = suffix + dotroot;
440 fFileName = fFileName.ReplaceAll(dotroot,suffixdotroot);
443 Info("SetDigitsFileNameSuffix"," after : %s",fFileName.Data());
445 /*****************************************************************************/
447 Bool_t AliDataLoader::CheckReload()
449 //checks if we have to reload given file
450 if (fFile == 0x0) return kFALSE;
451 TString tmp = SetFileOffset(fFileName);
452 if (tmp.CompareTo(fFile->GetName())) return kTRUE; //file must be reloaded
455 /*****************************************************************************/
457 const TString AliDataLoader::SetFileOffset(const TString& fname)
461 Long_t offset = (Long_t)GetRunLoader()->GetFileOffset();
462 if (offset < 1) return fname;
465 soffset += offset;//automatic conversion to string
466 TString dotroot(".root");
467 const TString& offfsetdotroot = offset + dotroot;
469 out = out.ReplaceAll(dotroot,offfsetdotroot);
470 if (GetDebug()) Info("SetFileOffset","in=%s out=%s.",fname.Data(),out.Data());
474 /*****************************************************************************/
476 void AliDataLoader::SetFileOption(Option_t* newopt)
479 if (fFileOption.CompareTo(newopt) == 0) return;
480 fFileOption = newopt;
483 /*****************************************************************************/
485 void AliDataLoader::SetCompressionLevel(Int_t cl)
487 //sets comression level for data defined by di
488 fCompressionLevel = cl;
489 if (fFile) fFile->SetCompressionLevel(cl);
491 /*****************************************************************************/
493 Int_t AliDataLoader::GetDebug() const
495 //it is not inline bacause AliLoader.h includes AliDataLoaer.h
496 //and there is circular depenedence
497 return AliLoader::GetDebug();
499 /*****************************************************************************/
501 void AliDataLoader::MakeTree()
503 // Makes tree for the current data loader
504 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(fBaseLoaders->At(0));
507 Error("MakeTree","Can not make a tree because main base loader is not a tree loader");
512 /*****************************************************************************/
514 Bool_t AliDataLoader::IsFileWritable() const
516 //returns true if file is writable
517 return (fFile)?fFile->IsWritable():kFALSE;
519 /*****************************************************************************/
521 Bool_t AliDataLoader::IsFileOpen() const
523 //returns true if file is writable
524 return (fFile)?fFile->IsOpen():kFALSE;
526 /*****************************************************************************/
528 Bool_t AliDataLoader::IsOptionContrary(const TString& option) const
530 //Checks if passed option is contrary with file open option
531 //which is passed option "writable" and existing option not wriable
532 //in reverse case it is no harm so it is NOT contrary
533 if (fFile == 0x0) return kFALSE; //file is not opened - no problem
535 if ( ( AliLoader::IsOptionWritable(option) == kTRUE ) && // passed option is writable and
536 ( AliLoader::IsOptionWritable(fFileOption) == kFALSE ) ) // existing one is not writable
543 /*****************************************************************************/
544 void AliDataLoader::AddBaseLoader(AliBaseLoader* bl)
546 //Adds a base loader to lits of base loaders managed by this data loader
547 //Managed data/task will be stored in proper root directory,
549 // - in case of tree/object - data folder connected with detector associated with this data loader
550 // - in case of task - parental task which defined in this AliTaskLoader
554 Warning("AddBaseLoader","Pointer is null.");
558 TObject* obj = fBaseLoaders->FindObject(bl->GetName());
561 Error("AddBaseLoader","Can not add this base loader.");
562 Error("AddBaseLoader","There exists already base loader which manages data named %s for this detector.");
567 fBaseLoaders->Add(bl);
570 /*****************************************************************************/
572 AliBaseLoader* AliDataLoader::GetBaseLoader(const TString& name) const
574 return dynamic_cast<AliBaseLoader*>(fBaseLoaders->FindObject(name));
576 /*****************************************************************************/
578 AliBaseLoader* AliDataLoader::GetBaseLoader(Int_t n) const
580 // Gets the n-th base loader (what is n?)
581 return dynamic_cast<AliBaseLoader*>(fBaseLoaders->At(n));
583 /*****************************************************************************/
585 TTree* AliDataLoader::Tree() const
587 //returns tree from the main base loader
588 //it is just shortcut method for comfort of user
589 //main storage object does not have to be Tree -
590 //that is why first we need to check if it is a TreeLoader
591 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(GetBaseLoader(0));
592 if (tl == 0x0) return 0x0;
595 /*****************************************************************************/
597 void AliDataLoader::SetDirName(TString& dirname)
599 // Sets the directory name where the files will be stored
600 if (GetDebug()>9) Info("SetDirName","FileName before %s",fFileName.Data());
602 Int_t n = fFileName.Last('/');
604 if (GetDebug()>9) Info("SetDirName","Slash found on pos %d",n);
606 if (n > 0) fFileName = fFileName.Remove(0,n+1);
608 if (GetDebug()>9) Info("SetDirName","Core FileName %s",fFileName.Data());
610 fFileName = dirname + "/" + fFileName;
612 if (GetDebug()>9) Info("SetDirName","FileName after %s",fFileName.Data());
614 /*****************************************************************************/
615 AliObjectLoader* AliDataLoader::GetBaseDataLoader()
617 // Gets the base data loader
618 return dynamic_cast<AliObjectLoader*>(GetBaseLoader(kData));
620 /*****************************************************************************/
621 AliTaskLoader* AliDataLoader::GetBaseTaskLoader()
623 // Gets the base task loader
624 return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kTask));
626 /*****************************************************************************/
627 AliBaseLoader* AliDataLoader::GetBaseQALoader()
629 // Gets the base QA loader
630 return GetBaseLoader(kQA);
632 /*****************************************************************************/
633 AliTaskLoader* AliDataLoader::GetBaseQATaskLoader()
635 //returns pointer to QA base loader
636 return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kQATask));
638 /*****************************************************************************/
639 void AliDataLoader::SetBaseDataLoader(AliBaseLoader* bl)
641 //sets data base loader
644 Error("SetBaseDataLoader","Parameter is null");
647 if (GetBaseDataLoader()) delete GetBaseDataLoader();
648 fBaseLoaders->AddAt(bl,kData);
650 /*****************************************************************************/
651 void AliDataLoader::SetBaseTaskLoader(AliTaskLoader* bl)
653 //sets Task base loader
656 Error("SetBaseTaskLoader","Parameter is null");
659 if (GetBaseTaskLoader()) delete GetBaseTaskLoader();
660 fBaseLoaders->AddAt(bl,kTask);
662 /*****************************************************************************/
663 void AliDataLoader::SetBaseQALoader(AliBaseLoader* bl)
665 //sets QA base loader
668 Error("SetBaseQALoader","Parameter is null");
671 if (GetBaseQALoader()) delete GetBaseQALoader();
672 fBaseLoaders->AddAt(bl,kQA);
674 /*****************************************************************************/
675 void AliDataLoader::SetBaseQATaskLoader(AliTaskLoader* bl)
677 //sets QA Task base loader
680 Error("SetBaseQATaskLoader","Parameter is null");
683 if (GetBaseQATaskLoader()) delete GetBaseQATaskLoader();
684 fBaseLoaders->AddAt(bl,kQATask);
686 void AliDataLoader::Synchronize()
688 //synchrinizes all writtable files
689 if ( fFile ) fFile->Flush();
692 /*****************************************************************************/
693 /*****************************************************************************/
694 /*****************************************************************************/
695 //__________________________________________
696 ///////////////////////////////////////////////////////////////////////////////
698 // class AliBaseLoader //
701 ///////////////////////////////////////////////////////////////////////////////
702 ClassImp(AliBaseLoader)
704 AliBaseLoader::AliBaseLoader():
706 fStoreInTopOfFile(kFALSE),
707 fDoNotReload(kFALSE),
710 //default constructor
712 /*****************************************************************************/
714 AliBaseLoader::AliBaseLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
715 TNamed(name,name+" Base Loader"),
717 fStoreInTopOfFile(storeontop),
718 fDoNotReload(storeontop),//if stored on top of file - this object is loaded ones pe
724 /*****************************************************************************/
725 AliBaseLoader::AliBaseLoader(const AliBaseLoader& source):TNamed(source) {
727 Fatal("AliBaseLoader","Copy constructor not implemented");
729 /*****************************************************************************/
730 AliBaseLoader& AliBaseLoader::operator=(const AliBaseLoader& /*source*/) {
731 // Assignment operator
732 Fatal("AliBaseLoader","Assignment operator not implemented");
735 /*****************************************************************************/
737 Int_t AliBaseLoader::Load(Option_t* opt)
739 // Loads and posts the data
741 Info("Load","data type = %s, option = %s",GetName(),opt);
746 Warning("Load","Data <<%s>> are already loaded. Use ReloadData to force reload. Nothing done",GetName());
752 if (GetDataLoader()->IsFileOpen() == kTRUE)
754 if (GetDataLoader()->IsOptionContrary(opt) == kTRUE)
756 Error("Load","Data Type %s, Container Name %s", GetDataLoader()->GetName(),GetName());
757 Error("Load","File was already opened in READ-ONLY mode, while now WRITEABLE access is requested.");
758 Error("Load","Use AliDataLoader::SetOption to enforce change of access mode OR");
759 Error("Load","Load previosly loaded data with coherent option.");
765 retval = GetDataLoader()->OpenFile(opt);
768 Error("Load","Error occured while opening <<%s>> file",GetName());
772 //if file is recreated there is no sense to search for data to post and get Error message
773 if (AliLoader::TestFileOption(opt) == kFALSE)
775 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(this);
776 if (tl) tl->MakeTree();
784 Error("Load","Error occured while posting %s from file to folder.",GetName());
791 /*****************************************************************************/
793 Int_t AliBaseLoader::Post()
795 //Posts data container to proper folders
797 if ( GetDirectory() == 0x0)
799 Error("Post","%s directory is NULL. Load before.",GetDataLoader()->GetName());
803 TObject* data = GetFromDirectory(fName);
806 //if such an obejct already exists - remove it first
811 //check if file is in update mode
812 Int_t fileupdate = GetDataLoader()->GetFileOption().CompareTo("update",TString::kIgnoreCase);
813 if ( fileupdate == 0)
814 { //if it is, it is normal that there is no data yet
817 Info("Post","Can not find %s in file %s (file is opened in UPDATE mode).",
818 GetName(),GetDataLoader()->GetFile()->GetName());
823 Error("Post","Can not find %s in file %s", GetName(),GetDataLoader()->GetFile()->GetName());
829 /*****************************************************************************/
831 Int_t AliBaseLoader::Post(TObject* data)
833 //Posts data container to proper folders
836 Error("Post","Pointer to object is NULL");
840 if ( fName.CompareTo(data->GetName()) != 0)
842 Fatal("Post(TObject*)","Object name is <<%s>> while <<%s>> expected",data->GetName(),GetName());
843 return -1;//pro forma
846 TObject* obj = Get();
849 if (GetDebug()) Warning("Post","This object was already posted.");
854 Warning("PostData","Object named %s already exitsts in data folder. Removing it",GetName());
857 return AddToBoard(data);
859 /*****************************************************************************/
861 Int_t AliBaseLoader::WriteData(Option_t* opt)
863 //Writes data defined by di object
864 //opt might be "OVERWRITE" in case of forcing overwriting
866 Info("WriteData","Writing %s container for %s data. Option is %s.",
867 GetName(),GetDataLoader()->GetName(),opt);
869 TObject *data = Get();
871 {//did not get, nothing to write
872 Warning("WriteData","Tree named %s not found in folder. Nothing to write.",GetName());
876 //check if file is opened
877 if (GetDirectory() == 0x0)
880 GetDataLoader()->SetFileOption("UPDATE");
881 if (GetDataLoader()->OpenFile("UPDATE"))
883 //oops, can not open the file, give an error message and return error code
884 Error("WriteData","Can not open hits file. %s ARE NOT WRITTEN",GetName());
889 if (GetDataLoader()->IsFileWritable() == kFALSE)
891 Error("WriteData","File %s is not writable",GetDataLoader()->GetFileName().Data());
895 GetDirectory()->cd(); //set the proper directory active
897 //see if hits container already exists in this (root) directory
898 TObject* obj = GetFromDirectory(GetName());
900 { //if they exist, see if option OVERWRITE is used
901 const char *oOverWrite = strstr(opt,"OVERWRITE");
903 {//if it is not used - give an error message and return an error code
904 Error("WriteData","Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
909 if (GetDebug()) Info("WriteData","DataName = %s, opt = %s, data object name = %s",
910 GetName(),opt,data->GetName());
911 if (GetDebug()) Info("WriteData","File Name = %s, Directory Name = %s Directory's File Name = %s",
912 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
913 GetDirectory()->GetFile()->GetName());
915 if (GetDebug()) Info("WriteData","Writing data");
916 data->Write(0,TObject::kOverwrite);
918 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
923 /*****************************************************************************/
925 Int_t AliBaseLoader::Reload()
927 //Unloads and loads datat again - if loaded before
931 return Load(GetDataLoader()->GetFileOption());
935 /*****************************************************************************/
937 void AliBaseLoader::Clean()
939 //removes objects from folder/task
940 if (GetDebug()) Info("Clean","%s %s",GetName(),GetDataLoader()->GetName());
941 TObject* obj = Get();
945 Info("Clean","cleaning %s.",GetName());
946 RemoveFromBoard(obj);
950 /*****************************************************************************/
952 void AliBaseLoader::Unload()
954 // Unloads data and closes the files
957 GetDataLoader()->CloseFile();
959 /*****************************************************************************/
960 AliDataLoader* AliBaseLoader::GetDataLoader() const
962 // Returns pointer to the data loader
963 if (fDataLoader == 0x0)
965 Fatal("GetDataLoader","Pointer to Data Loader is NULL");
969 /*****************************************************************************/
971 Int_t AliBaseLoader::GetDebug() const
973 // Returns debug level
974 return (Int_t)AliLoader::GetDebug();
977 TDirectory* AliBaseLoader::GetDirectory() const
979 // returnd TDirectory where data are to be saved
980 //if fStoreInTopOfFile flag is true - returns pointer to file
981 return (fStoreInTopOfFile)?GetDataLoader()->GetFile():GetDataLoader()->GetDirectory();
983 /*****************************************************************************/
984 /*****************************************************************************/
985 /*****************************************************************************/
986 //__________________________________________
987 ///////////////////////////////////////////////////////////////////////////////
989 // class AliObjectLoader //
992 ///////////////////////////////////////////////////////////////////////////////
994 ClassImp(AliObjectLoader)
996 AliObjectLoader::AliObjectLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
997 AliBaseLoader(name,dl,storeontop)
1001 /*****************************************************************************/
1003 TFolder* AliObjectLoader::GetFolder() const
1005 // Returns pointer to the object folder
1006 TFolder* df = GetDataLoader()->GetFolder();
1009 Fatal("GetFolder","Data Folder is NULL");
1013 /*****************************************************************************/
1014 AliObjectLoader::AliObjectLoader(const AliObjectLoader& source):
1015 AliBaseLoader(source) {
1017 Fatal("AliObjectLoader","Copy constructor not implemented");
1019 /*****************************************************************************/
1020 AliObjectLoader& AliObjectLoader::operator=(const AliObjectLoader& /*source*/) {
1021 // Assignment operator
1022 Fatal("AliObjectLoader","Assignment operator not implemented");
1025 /*****************************************************************************/
1027 void AliObjectLoader::RemoveFromBoard(TObject* obj)
1029 // Removes "obj" from the board
1030 GetFolder()->Remove(obj);
1032 /*****************************************************************************/
1033 Int_t AliObjectLoader::AddToBoard(TObject* obj)
1035 // Adds "obj" to the board
1036 GetFolder()->Add(obj);
1039 /*****************************************************************************/
1041 TObject* AliObjectLoader::Get() const
1043 // Returns pointer to the object loader
1044 return (GetFolder()) ? GetFolder()->FindObject(GetName()) : 0x0;
1047 /*****************************************************************************/
1048 /*****************************************************************************/
1049 /*****************************************************************************/
1050 //__________________________________________
1051 ///////////////////////////////////////////////////////////////////////////////
1053 // class AliTreeLoader //
1056 ///////////////////////////////////////////////////////////////////////////////
1058 ClassImp(AliTreeLoader)
1060 AliTreeLoader::AliTreeLoader(const TString& name, AliDataLoader* dl,Bool_t storeontop):
1061 AliObjectLoader(name,dl,storeontop)
1065 /*****************************************************************************/
1066 AliTreeLoader::AliTreeLoader(const AliTreeLoader& source):
1067 AliObjectLoader(source) {
1069 Fatal("AliTreeLoader","Copy constructor not implemented");
1071 /*****************************************************************************/
1072 AliTreeLoader& AliTreeLoader::operator=(const AliTreeLoader& /*source*/) {
1073 // Assignment operator
1074 Fatal("AliTreeLoader","Assignment operator not implemented");
1078 /*****************************************************************************/
1080 Int_t AliTreeLoader::WriteData(Option_t* opt)
1082 //Writes data defined by di object
1083 //opt might be "OVERWRITE" in case of forcing overwriting
1086 Info("WriteData","Writing %s container for %s data. Option is %s.",
1087 GetName(),GetDataLoader()->GetName(),opt);
1089 TObject *data = Get();
1091 {//did not get, nothing to write
1092 Warning("WriteData","Tree named %s not found in folder. Nothing to write.",GetName());
1096 //check if file is opened
1097 if (GetDirectory() == 0x0)
1099 //if not try to open
1100 GetDataLoader()->SetFileOption("UPDATE");
1101 if (GetDataLoader()->OpenFile("UPDATE"))
1103 //oops, can not open the file, give an error message and return error code
1104 Error("WriteData","Can not open hits file. %s ARE NOT WRITTEN",GetName());
1109 if (GetDataLoader()->IsFileWritable() == kFALSE)
1111 Error("WriteData","File %s is not writable",GetDataLoader()->GetFileName().Data());
1115 GetDirectory()->cd(); //set the proper directory active
1117 //see if hits container already exists in this (root) directory
1118 TObject* obj = GetFromDirectory(GetName());
1120 { //if they exist, see if option OVERWRITE is used
1121 const char *oOverWrite = strstr(opt,"OVERWRITE");
1123 {//if it is not used - give an error message and return an error code
1124 Error("WriteData","Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
1129 if (GetDebug()) Info("WriteData","DataName = %s, opt = %s, data object name = %s",
1130 GetName(),opt,data->GetName());
1131 if (GetDebug()) Info("WriteData","File Name = %s, Directory Name = %s Directory's File Name = %s",
1132 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
1133 GetDirectory()->GetFile()->GetName());
1135 //if a data object is a tree set the directory
1136 TTree* tree = dynamic_cast<TTree*>(data);
1137 if (tree) tree->SetDirectory(GetDirectory()); //forces setting the directory to this directory (we changed dir few lines above)
1139 if (GetDebug()) Info("WriteData","Writing tree");
1140 data->Write(0,TObject::kOverwrite);
1142 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
1147 /*****************************************************************************/
1149 void AliTreeLoader::MakeTree()
1151 //this virtual method creates the tree in the file
1155 Info("MakeTree","name = %s, Data Name = %s Tree already exists.",
1156 GetName(),GetDataLoader()->GetName());
1157 return;//tree already made
1160 Info("MakeTree","Making Tree named %s.",GetName());
1162 TString dtypename(GetDataLoader()->GetName());
1163 TTree* tree = new TTree(GetName(), dtypename + " Container"); //make a tree
1166 Error("MakeTree","Can not create %s tree.",GetName());
1169 tree->SetAutoSave(1000000000); //no autosave
1170 GetFolder()->Add(tree);
1171 WriteData("OVERWRITE");//write tree to the file
1175 /*****************************************************************************/
1176 /*****************************************************************************/
1177 /*****************************************************************************/
1178 //__________________________________________
1179 ///////////////////////////////////////////////////////////////////////////////
1181 // class AliTaskLoader //
1184 ///////////////////////////////////////////////////////////////////////////////
1186 ClassImp(AliTaskLoader)
1188 AliTaskLoader::AliTaskLoader(const TString& name, AliDataLoader* dl, TTask* parentaltask, Bool_t storeontop):
1189 AliBaseLoader(name,dl,storeontop),
1190 fParentalTask(parentaltask)
1195 /*****************************************************************************/
1196 AliTaskLoader::AliTaskLoader(const AliTaskLoader& source):
1197 AliBaseLoader(source) {
1199 Fatal("AliTaskLoader","Copy constructor not implemented");
1201 /*****************************************************************************/
1202 AliTaskLoader& AliTaskLoader::operator=(const AliTaskLoader& /*source*/) {
1203 // Assignment operator
1204 Fatal("AliTaskLoader","Assignment operator not implemented");
1207 /*****************************************************************************/
1208 void AliTaskLoader::Clean()
1210 //removes tasl from parental task
1211 // DO NOT DELETE OBJECT contrary to BaseLoader
1213 if (GetDebug()) Info("Clean","%s %s",GetName(),GetDataLoader()->GetName());
1214 TObject* obj = Get();
1218 Info("Clean","cleaning %s.",GetName());
1219 RemoveFromBoard(obj);
1222 /*****************************************************************************/
1224 void AliTaskLoader::RemoveFromBoard(TObject* obj)
1226 // Removes the task "obj" from the board
1227 GetParentalTask()->GetListOfTasks()->Remove(obj);
1229 /*****************************************************************************/
1231 Int_t AliTaskLoader::AddToBoard(TObject* obj)
1233 // Adds task "obj" to the board
1234 TTask* task = dynamic_cast<TTask*>(obj);
1237 Error("AddToBoard","To TTask board can be added only tasks.");
1240 GetParentalTask()->Add(task);
1243 /*****************************************************************************/
1245 TObject* AliTaskLoader::Get() const
1247 // Returns pointer to the current task
1248 return (GetParentalTask()) ? GetParentalTask()->GetListOfTasks()->FindObject(GetName()) : 0x0;
1250 /*****************************************************************************/
1252 TTask* AliTaskLoader::GetParentalTask() const
1254 //returns parental tasks for this task
1255 return fParentalTask;
1258 /*****************************************************************************/
1260 /*****************************************************************************/
1261 /*****************************************************************************/
1262 /*****************************************************************************/