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 /////////////////////////////////////////////////////////////////////////////////////////////
37 #include "AliRunLoader.h"
39 ClassImp(AliDataLoader)
41 AliDataLoader::AliDataLoader():
56 /*****************************************************************************/
58 AliDataLoader::AliDataLoader(const char* filename, const char* contname, const char* name, Option_t* opt):
65 fBaseLoaders(new TObjArray(4)),
73 // creates a 0 loader, depending on option, default "T" is specialized loader for trees
74 // else standard object loader
75 // trees needs special care, becouse we need to set dir before writing
77 Info("AliDataLoader","File name is %s",fFileName.Data());
81 if (option.CompareTo("T",TString::kIgnoreCase) == 0)
82 bl = new AliTreeLoader(contname,this);
84 bl = new AliObjectLoader(contname,this);
85 fBaseLoaders->AddAt(bl,kData);
88 /*****************************************************************************/
89 AliDataLoader::AliDataLoader(const AliDataLoader& source):TNamed(source) {
91 Fatal("AliDataLoader","Copy constructor not implemented");
93 /*****************************************************************************/
94 AliDataLoader& AliDataLoader::operator=(const AliDataLoader& /*source*/) {
95 // Assignment operator
96 Fatal("AliDataLoader","Assignment operator not implemented");
99 /*****************************************************************************/
101 AliDataLoader::~AliDataLoader()
106 /*****************************************************************************/
108 Int_t AliDataLoader::SetEvent()
110 //basically the same that GetEvent but do not post data to folders
111 AliRunLoader* rl = GetRunLoader();
114 Error("SetEvent","Can not get RunGettr");
118 Int_t evno = rl->GetEventNumber();
120 TIter next(fBaseLoaders);
122 while ((bl = (AliBaseLoader*)next()))
124 if (bl->DoNotReload() == kFALSE) bl->Clean();
133 if (GetDebug()) Info("SetEvent","Reloading new file. File opt is %s",fFileOption.Data());
134 OpenFile(fFileOption);
137 fDirectory = AliLoader::ChangeDir(fFile,evno);
138 if (fDirectory == 0x0)
140 Error("SetEvent","Can not chage directory in file %s",fFile->GetName());
146 /*****************************************************************************/
148 Int_t AliDataLoader::GetEvent()
150 // posts all loaded data from files to White Board
151 // event number is defined in RunLoader
154 // 0 - in case of no error
155 // 1 - event not found
157 //for each base laoder post, if was loaded before GetEvent
159 //call set event to switch to new directory in file
162 //post all data that were loaded before
163 // ->SetEvent does not call Unload, but only cleans White Board
164 // such IsLoaded flag stays untached
166 if ( AliLoader::TestFileOption(fFileOption) == kTRUE ) //if file is read or update mode try to post
167 { //in other case there is no sense to post: file is new
168 TIter nextbl(fBaseLoaders);
170 while ((bl = (AliBaseLoader*)nextbl()))
174 if (bl->DoNotReload() == kFALSE) bl->Post();
180 /*****************************************************************************/
182 Int_t AliDataLoader::OpenFile(Option_t* opt)
184 //Opens file named 'filename', and assigns pointer to it to 'file'
185 //jumps to fDirectoryectory corresponding to current event and stores the pointer to it in 'fDirectory'
186 //option 'opt' is passed to TFile::Open
189 if(fFile->IsOpen() == kTRUE)
191 Warning("OpenFile"," File %s already opened. First close it.",fFile->GetName());
196 Warning("OpenFile","Pointer to file %s is not null, but file is not opened",
203 TString fname(SetFileOffset(fFileName));
205 fFile = (TFile *)(gROOT->GetListOfFiles()->FindObject(fname));
208 if(fFile->IsOpen() == kTRUE)
210 Warning("OpenFile","File %s already opened by sombody else. First close it.",
217 fFile = TFile::Open(fname,fFileOption);//open the file
220 Error("OpenFile","Can not open file %s",fname.Data());
223 if (fFile->IsOpen() == kFALSE)
225 Error("OpenFile","Can not open file %s",fname.Data());
229 fFile->SetCompressionLevel(fCompressionLevel);
231 AliRunLoader* rg = GetRunLoader();
234 Error("OpenFile","Can not find Run-Loader in folder.");
237 Int_t evno = rg->GetEventNumber();
239 fDirectory = AliLoader::ChangeDir(fFile,evno);
240 if (fDirectory == 0x0)
242 Error("OpenFile","Can not chage fDirectory in file %s.",fFile->GetName());
247 /*****************************************************************************/
249 void AliDataLoader::Unload()
251 //unloads main data - shortcut method
252 GetBaseLoader(0)->Unload();
254 /*****************************************************************************/
256 void AliDataLoader::UnloadAll()
258 //Unloads all data and tasks
259 if ( fFile == 0x0 ) return; //nothing loaded
261 TIter next(fBaseLoaders);
263 while ((bl = (AliBaseLoader*)next()))
268 /*****************************************************************************/
270 Int_t AliDataLoader::Reload()
272 //Unloads and loads data again
273 if ( fFile == 0x0 ) return 0;
275 TBits loaded(fBaseLoaders->GetEntries());
276 TIter next(fBaseLoaders);
280 while ((bl = (AliBaseLoader*)next()))
284 loaded.SetBitNumber(i++,kTRUE);
292 while ((bl = (AliBaseLoader*)next()))
294 if (loaded.TestBitNumber(i++))
296 retval = bl->Load(fFileOption);
299 Error("Reload","Error occur while loading %s",bl->GetName());
308 /*****************************************************************************/
309 Int_t AliDataLoader::WriteData(Option_t* opt)
311 //Writes primary data == first BaseLoader
313 Info("WriteData","Writing %s container for %s data. Option is %s.",
314 GetBaseLoader(0)->GetName(),GetName(),opt);
315 return GetBaseLoader(0)->WriteData(opt);
317 /*****************************************************************************/
319 Int_t AliDataLoader::Load(Option_t* opt)
321 //Writes primary data == first BaseLoader
322 return GetBaseLoader(0)->Load(opt);
324 /*****************************************************************************/
326 Int_t AliDataLoader::SetEventFolder(TFolder* eventfolder)
328 //sets the event folder
329 if (eventfolder == 0x0)
331 Error("SetEventFolder","Stupid joke. Argument is NULL");
335 Info("SetFolder","name = %s Setting Event Folder named %s.",
336 GetName(),eventfolder->GetName());
338 fEventFolder = eventfolder;
341 /*****************************************************************************/
343 Int_t AliDataLoader::SetFolder(TFolder* folder)
345 // Sets the folder and the data loaders
348 Error("SetFolder","Stupid joke. Argument is NULL");
352 if (GetDebug()) Info("SetFolder","name = %s Setting folder named %s.",GetName(),folder->GetName());
355 TIter next(fBaseLoaders);
358 while ((bl = (AliBaseLoader*)next()))
360 bl->SetDataLoader(this);
365 /******************************************************************/
367 TFolder* AliDataLoader::GetEventFolder()
369 //get EVENT folder (data that are changing from event to event, even in single run)
370 if (GetDebug()) Info("GetEventFolder","EF = %#x");
373 /*****************************************************************************/
375 AliRunLoader* AliDataLoader::GetRunLoader()
377 //gets the run-loader from event folder
378 AliRunLoader* rg = 0x0;
379 TFolder* ef = GetEventFolder();
382 Error("GetRunLoader","Can not get event folder.");
385 rg = dynamic_cast<AliRunLoader*>(ef->FindObject(AliRunLoader::fgkRunLoaderName));
389 /*****************************************************************************/
390 void AliDataLoader::CloseFile()
393 TIter next(fBaseLoaders);
395 while ((bl = (AliBaseLoader*)next()))
397 if (bl->IsLoaded()) return;
401 Info("CloseFile","Closing and deleting (object) file.");
407 /*****************************************************************************/
409 void AliDataLoader::Clean()
412 GetBaseLoader(0)->Clean();
414 /*****************************************************************************/
416 void AliDataLoader::CleanAll()
418 //Cleans all folders and tasks
419 TIter next(fBaseLoaders);
421 while ((bl = (AliBaseLoader*)next()))
426 /*****************************************************************************/
428 void AliDataLoader::SetFileNameSuffix(const TString& suffix)
430 //adds the suffix before ".root",
431 //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
432 //made on Jiri Chudoba demand
435 Info("SetFileNameSuffix","suffix=%s",suffix.Data());
436 Info("SetFileNameSuffix"," Digits File Name before: %s",fFileName.Data());
439 static TString dotroot(".root");
440 const TString& suffixdotroot = suffix + dotroot;
441 fFileName = fFileName.ReplaceAll(dotroot,suffixdotroot);
444 Info("SetDigitsFileNameSuffix"," after : %s",fFileName.Data());
446 /*****************************************************************************/
448 Bool_t AliDataLoader::CheckReload()
450 //checks if we have to reload given file
451 if (fFile == 0x0) return kFALSE;
452 TString tmp = SetFileOffset(fFileName);
453 if (tmp.CompareTo(fFile->GetName())) return kTRUE; //file must be reloaded
456 /*****************************************************************************/
458 const TString AliDataLoader::SetFileOffset(const TString& fname)
462 Long_t offset = (Long_t)GetRunLoader()->GetFileOffset();
463 if (offset < 1) return fname;
466 soffset += offset;//automatic conversion to string
467 TString dotroot(".root");
468 const TString& offfsetdotroot = offset + dotroot;
470 out = out.ReplaceAll(dotroot,offfsetdotroot);
471 if (GetDebug()) Info("SetFileOffset","in=%s out=%s.",fname.Data(),out.Data());
475 /*****************************************************************************/
477 void AliDataLoader::SetFileOption(Option_t* newopt)
480 if (fFileOption.CompareTo(newopt) == 0) return;
481 fFileOption = newopt;
484 /*****************************************************************************/
486 void AliDataLoader::SetCompressionLevel(Int_t cl)
488 //sets comression level for data defined by di
489 fCompressionLevel = cl;
490 if (fFile) fFile->SetCompressionLevel(cl);
492 /*****************************************************************************/
494 Int_t AliDataLoader::GetDebug() const
496 //it is not inline bacause AliLoader.h includes AliDataLoaer.h
497 //and there is circular depenedence
498 return AliLoader::GetDebug();
500 /*****************************************************************************/
502 void AliDataLoader::MakeTree()
504 // Makes tree for the current data loader
505 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(fBaseLoaders->At(0));
508 Error("MakeTree","Can not make a tree because main base loader is not a tree loader");
513 /*****************************************************************************/
515 Bool_t AliDataLoader::IsFileWritable() const
517 //returns true if file is writable
518 return (fFile)?fFile->IsWritable():kFALSE;
520 /*****************************************************************************/
522 Bool_t AliDataLoader::IsFileOpen() const
524 //returns true if file is writable
525 return (fFile)?fFile->IsOpen():kFALSE;
527 /*****************************************************************************/
529 Bool_t AliDataLoader::IsOptionContrary(const TString& option) const
531 //Checks if passed option is contrary with file open option
532 //which is passed option "writable" and existing option not wriable
533 //in reverse case it is no harm so it is NOT contrary
534 if (fFile == 0x0) return kFALSE; //file is not opened - no problem
536 if ( ( AliLoader::IsOptionWritable(option) == kTRUE ) && // passed option is writable and
537 ( AliLoader::IsOptionWritable(fFileOption) == kFALSE ) ) // existing one is not writable
544 /*****************************************************************************/
545 void AliDataLoader::AddBaseLoader(AliBaseLoader* bl)
547 //Adds a base loader to lits of base loaders managed by this data loader
548 //Managed data/task will be stored in proper root directory,
550 // - in case of tree/object - data folder connected with detector associated with this data loader
551 // - in case of task - parental task which defined in this AliTaskLoader
555 Warning("AddBaseLoader","Pointer is null.");
559 TObject* obj = fBaseLoaders->FindObject(bl->GetName());
562 Error("AddBaseLoader","Can not add this base loader.");
563 Error("AddBaseLoader","There exists already base loader which manages data named %s for this detector.");
568 fBaseLoaders->Add(bl);
571 /*****************************************************************************/
573 AliBaseLoader* AliDataLoader::GetBaseLoader(const TString& name) const
575 return dynamic_cast<AliBaseLoader*>(fBaseLoaders->FindObject(name));
577 /*****************************************************************************/
579 AliBaseLoader* AliDataLoader::GetBaseLoader(Int_t n) const
581 // Gets the n-th base loader (what is n?)
582 return dynamic_cast<AliBaseLoader*>(fBaseLoaders->At(n));
584 /*****************************************************************************/
586 TTree* AliDataLoader::Tree() const
588 //returns tree from the main base loader
589 //it is just shortcut method for comfort of user
590 //main storage object does not have to be Tree -
591 //that is why first we need to check if it is a TreeLoader
592 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(GetBaseLoader(0));
593 if (tl == 0x0) return 0x0;
596 /*****************************************************************************/
598 void AliDataLoader::SetDirName(TString& dirname)
600 // Sets the directory name where the files will be stored
601 if (GetDebug()>9) Info("SetDirName","FileName before %s",fFileName.Data());
603 Int_t n = fFileName.Last('/');
605 if (GetDebug()>9) Info("SetDirName","Slash found on pos %d",n);
607 if (n > 0) fFileName = fFileName.Remove(0,n+1);
609 if (GetDebug()>9) Info("SetDirName","Core FileName %s",fFileName.Data());
611 fFileName = dirname + "/" + fFileName;
613 if (GetDebug()>9) Info("SetDirName","FileName after %s",fFileName.Data());
615 /*****************************************************************************/
616 AliObjectLoader* AliDataLoader::GetBaseDataLoader()
618 // Gets the base data loader
619 return dynamic_cast<AliObjectLoader*>(GetBaseLoader(kData));
621 /*****************************************************************************/
622 AliTaskLoader* AliDataLoader::GetBaseTaskLoader()
624 // Gets the base task loader
625 return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kTask));
627 /*****************************************************************************/
628 AliBaseLoader* AliDataLoader::GetBaseQALoader()
630 // Gets the base QA loader
631 return GetBaseLoader(kQA);
633 /*****************************************************************************/
634 AliTaskLoader* AliDataLoader::GetBaseQATaskLoader()
636 //returns pointer to QA base loader
637 return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kQATask));
639 /*****************************************************************************/
640 void AliDataLoader::SetBaseDataLoader(AliBaseLoader* bl)
642 //sets data base loader
645 Error("SetBaseDataLoader","Parameter is null");
648 if (GetBaseDataLoader()) delete GetBaseDataLoader();
649 fBaseLoaders->AddAt(bl,kData);
651 /*****************************************************************************/
652 void AliDataLoader::SetBaseTaskLoader(AliTaskLoader* bl)
654 //sets Task base loader
657 Error("SetBaseTaskLoader","Parameter is null");
660 if (GetBaseTaskLoader()) delete GetBaseTaskLoader();
661 fBaseLoaders->AddAt(bl,kTask);
663 /*****************************************************************************/
664 void AliDataLoader::SetBaseQALoader(AliBaseLoader* bl)
666 //sets QA base loader
669 Error("SetBaseQALoader","Parameter is null");
672 if (GetBaseQALoader()) delete GetBaseQALoader();
673 fBaseLoaders->AddAt(bl,kQA);
675 /*****************************************************************************/
676 void AliDataLoader::SetBaseQATaskLoader(AliTaskLoader* bl)
678 //sets QA Task base loader
681 Error("SetBaseQATaskLoader","Parameter is null");
684 if (GetBaseQATaskLoader()) delete GetBaseQATaskLoader();
685 fBaseLoaders->AddAt(bl,kQATask);
687 void AliDataLoader::Synchronize()
689 //synchrinizes all writtable files
690 if ( fFile ) fFile->Flush();
693 /*****************************************************************************/
694 /*****************************************************************************/
695 /*****************************************************************************/
696 //__________________________________________
697 ///////////////////////////////////////////////////////////////////////////////
699 // class AliBaseLoader //
702 ///////////////////////////////////////////////////////////////////////////////
703 ClassImp(AliBaseLoader)
705 AliBaseLoader::AliBaseLoader():
707 fStoreInTopOfFile(kFALSE),
708 fDoNotReload(kFALSE),
711 //default constructor
713 /*****************************************************************************/
715 AliBaseLoader::AliBaseLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
716 TNamed(name,name+" Base Loader"),
718 fStoreInTopOfFile(storeontop),
719 fDoNotReload(storeontop),//if stored on top of file - this object is loaded ones pe
725 /*****************************************************************************/
726 AliBaseLoader::AliBaseLoader(const AliBaseLoader& source):TNamed(source) {
728 Fatal("AliBaseLoader","Copy constructor not implemented");
730 /*****************************************************************************/
731 AliBaseLoader& AliBaseLoader::operator=(const AliBaseLoader& /*source*/) {
732 // Assignment operator
733 Fatal("AliBaseLoader","Assignment operator not implemented");
736 /*****************************************************************************/
738 Int_t AliBaseLoader::Load(Option_t* opt)
740 // Loads and posts the data
742 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 Warning("Post","Can not find %s in file %s", GetName(),GetDataLoader()->GetFile()->GetName());
828 /*****************************************************************************/
830 Int_t AliBaseLoader::Post(TObject* data)
832 //Posts data container to proper folders
835 Error("Post","Pointer to object is NULL");
838 TObject* obj = Get();
841 if (GetDebug()) Warning("Post","This object was already posted.");
846 Warning("PostData","Object named %s already exitsts in data folder. Removing it",GetName());
849 return AddToBoard(data);
851 /*****************************************************************************/
853 Int_t AliBaseLoader::WriteData(Option_t* opt)
855 //Writes data defined by di object
856 //opt might be "OVERWRITE" in case of forcing overwriting
858 Info("WriteData","Writing %s container for %s data. Option is %s.",
859 GetName(),GetDataLoader()->GetName(),opt);
861 TObject *data = Get();
863 {//did not get, nothing to write
864 Warning("WriteData","Tree named %s not found in folder. Nothing to write.",GetName());
868 //check if file is opened
869 if (GetDirectory() == 0x0)
872 GetDataLoader()->SetFileOption("UPDATE");
873 if (GetDataLoader()->OpenFile("UPDATE"))
875 //oops, can not open the file, give an error message and return error code
876 Error("WriteData","Can not open hits file. %s ARE NOT WRITTEN",GetName());
881 if (GetDataLoader()->IsFileWritable() == kFALSE)
883 Error("WriteData","File %s is not writable",GetDataLoader()->GetFileName().Data());
887 GetDirectory()->cd(); //set the proper directory active
889 //see if hits container already exists in this (root) directory
890 TObject* obj = GetFromDirectory(GetName());
892 { //if they exist, see if option OVERWRITE is used
893 const char *oOverWrite = strstr(opt,"OVERWRITE");
895 {//if it is not used - give an error message and return an error code
896 Error("WriteData","Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
901 if (GetDebug()) Info("WriteData","DataName = %s, opt = %s, data object name = %s",
902 GetName(),opt,data->GetName());
903 if (GetDebug()) Info("WriteData","File Name = %s, Directory Name = %s Directory's File Name = %s",
904 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
905 GetDirectory()->GetFile()->GetName());
907 if (GetDebug()) Info("WriteData","Writing data");
908 data->Write(0,TObject::kOverwrite);
910 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
915 /*****************************************************************************/
917 Int_t AliBaseLoader::Reload()
919 //Unloads and loads datat again - if loaded before
923 return Load(GetDataLoader()->GetFileOption());
927 /*****************************************************************************/
929 void AliBaseLoader::Clean()
931 //removes objects from folder/task
932 if (GetDebug()) Info("Clean","%s %s",GetName(),GetDataLoader()->GetName());
933 TObject* obj = Get();
937 Info("Clean","cleaning %s.",GetName());
938 RemoveFromBoard(obj);
942 /*****************************************************************************/
944 void AliBaseLoader::Unload()
946 // Unloads data and closes the files
949 GetDataLoader()->CloseFile();
951 /*****************************************************************************/
952 AliDataLoader* AliBaseLoader::GetDataLoader() const
954 // Returns pointer to the data loader
955 if (fDataLoader == 0x0)
957 Fatal("GetDataLoader","Pointer to Data Loader is NULL");
961 /*****************************************************************************/
963 Int_t AliBaseLoader::GetDebug() const
965 // Returns debug level
966 return (Int_t)AliLoader::GetDebug();
969 TDirectory* AliBaseLoader::GetDirectory() const
971 // returnd TDirectory where data are to be saved
972 //if fStoreInTopOfFile flag is true - returns pointer to file
973 return (fStoreInTopOfFile)?GetDataLoader()->GetFile():GetDataLoader()->GetDirectory();
975 /*****************************************************************************/
976 /*****************************************************************************/
977 /*****************************************************************************/
978 //__________________________________________
979 ///////////////////////////////////////////////////////////////////////////////
981 // class AliObjectLoader //
984 ///////////////////////////////////////////////////////////////////////////////
986 ClassImp(AliObjectLoader)
988 AliObjectLoader::AliObjectLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
989 AliBaseLoader(name,dl,storeontop)
993 /*****************************************************************************/
995 TFolder* AliObjectLoader::GetFolder() const
997 // Returns pointer to the object folder
998 TFolder* df = GetDataLoader()->GetFolder();
1001 Fatal("GetFolder","Data Folder is NULL");
1005 /*****************************************************************************/
1006 AliObjectLoader::AliObjectLoader(const AliObjectLoader& source):
1007 AliBaseLoader(source) {
1009 Fatal("AliObjectLoader","Copy constructor not implemented");
1011 /*****************************************************************************/
1012 AliObjectLoader& AliObjectLoader::operator=(const AliObjectLoader& /*source*/) {
1013 // Assignment operator
1014 Fatal("AliObjectLoader","Assignment operator not implemented");
1017 /*****************************************************************************/
1019 void AliObjectLoader::RemoveFromBoard(TObject* obj)
1021 // Removes "obj" from the board
1022 GetFolder()->Remove(obj);
1024 /*****************************************************************************/
1025 Int_t AliObjectLoader::AddToBoard(TObject* obj)
1027 // Adds "obj" to the board
1028 GetFolder()->Add(obj);
1031 /*****************************************************************************/
1033 TObject* AliObjectLoader::Get() const
1035 // Returns pointer to the object loader
1036 return (GetFolder()) ? GetFolder()->FindObject(GetName()) : 0x0;
1039 /*****************************************************************************/
1040 /*****************************************************************************/
1041 /*****************************************************************************/
1042 //__________________________________________
1043 ///////////////////////////////////////////////////////////////////////////////
1045 // class AliTreeLoader //
1048 ///////////////////////////////////////////////////////////////////////////////
1050 ClassImp(AliTreeLoader)
1052 AliTreeLoader::AliTreeLoader(const TString& name, AliDataLoader* dl,Bool_t storeontop):
1053 AliObjectLoader(name,dl,storeontop)
1057 /*****************************************************************************/
1058 AliTreeLoader::AliTreeLoader(const AliTreeLoader& source):
1059 AliObjectLoader(source) {
1061 Fatal("AliTreeLoader","Copy constructor not implemented");
1063 /*****************************************************************************/
1064 AliTreeLoader& AliTreeLoader::operator=(const AliTreeLoader& /*source*/) {
1065 // Assignment operator
1066 Fatal("AliTreeLoader","Assignment operator not implemented");
1070 /*****************************************************************************/
1072 Int_t AliTreeLoader::WriteData(Option_t* opt)
1074 //Writes data defined by di object
1075 //opt might be "OVERWRITE" in case of forcing overwriting
1078 Info("WriteData","Writing %s container for %s data. Option is %s.",
1079 GetName(),GetDataLoader()->GetName(),opt);
1081 TObject *data = Get();
1083 {//did not get, nothing to write
1084 Warning("WriteData","Tree named %s not found in folder. Nothing to write.",GetName());
1088 //check if file is opened
1089 if (GetDirectory() == 0x0)
1091 //if not try to open
1092 GetDataLoader()->SetFileOption("UPDATE");
1093 if (GetDataLoader()->OpenFile("UPDATE"))
1095 //oops, can not open the file, give an error message and return error code
1096 Error("WriteData","Can not open hits file. %s ARE NOT WRITTEN",GetName());
1101 if (GetDataLoader()->IsFileWritable() == kFALSE)
1103 Error("WriteData","File %s is not writable",GetDataLoader()->GetFileName().Data());
1107 GetDirectory()->cd(); //set the proper directory active
1109 //see if hits container already exists in this (root) directory
1110 TObject* obj = GetFromDirectory(GetName());
1112 { //if they exist, see if option OVERWRITE is used
1113 const char *oOverWrite = strstr(opt,"OVERWRITE");
1115 {//if it is not used - give an error message and return an error code
1116 Error("WriteData","Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
1121 if (GetDebug()) Info("WriteData","DataName = %s, opt = %s, data object name = %s",
1122 GetName(),opt,data->GetName());
1123 if (GetDebug()) Info("WriteData","File Name = %s, Directory Name = %s Directory's File Name = %s",
1124 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
1125 GetDirectory()->GetFile()->GetName());
1127 //if a data object is a tree set the directory
1128 TTree* tree = dynamic_cast<TTree*>(data);
1129 if (tree) tree->SetDirectory(GetDirectory()); //forces setting the directory to this directory (we changed dir few lines above)
1131 if (GetDebug()) Info("WriteData","Writing tree");
1132 data->Write(0,TObject::kOverwrite);
1134 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
1139 /*****************************************************************************/
1141 void AliTreeLoader::MakeTree()
1143 //this virtual method creates the tree in the file
1147 Info("MakeTree","name = %s, Data Name = %s Tree already exists.",
1148 GetName(),GetDataLoader()->GetName());
1149 return;//tree already made
1152 Info("MakeTree","Making Tree named %s.",GetName());
1154 TString dtypename(GetDataLoader()->GetName());
1155 TTree* tree = new TTree(GetName(), dtypename + " Container"); //make a tree
1158 Error("MakeTree","Can not create %s tree.",GetName());
1161 tree->SetAutoSave(1000000000); //no autosave
1162 GetFolder()->Add(tree);
1163 WriteData("OVERWRITE");//write tree to the file
1167 /*****************************************************************************/
1168 /*****************************************************************************/
1169 /*****************************************************************************/
1170 //__________________________________________
1171 ///////////////////////////////////////////////////////////////////////////////
1173 // class AliTaskLoader //
1176 ///////////////////////////////////////////////////////////////////////////////
1178 ClassImp(AliTaskLoader)
1180 AliTaskLoader::AliTaskLoader(const TString& name, AliDataLoader* dl, TTask* parentaltask, Bool_t storeontop):
1181 AliBaseLoader(name,dl,storeontop),
1182 fParentalTask(parentaltask)
1187 /*****************************************************************************/
1188 AliTaskLoader::AliTaskLoader(const AliTaskLoader& source):
1189 AliBaseLoader(source) {
1191 Fatal("AliTaskLoader","Copy constructor not implemented");
1193 /*****************************************************************************/
1194 AliTaskLoader& AliTaskLoader::operator=(const AliTaskLoader& /*source*/) {
1195 // Assignment operator
1196 Fatal("AliTaskLoader","Assignment operator not implemented");
1199 /*****************************************************************************/
1201 void AliTaskLoader::RemoveFromBoard(TObject* obj)
1203 // Removes the task "obj" from the board
1204 GetParentalTask()->GetListOfTasks()->Remove(obj);
1206 /*****************************************************************************/
1208 Int_t AliTaskLoader::AddToBoard(TObject* obj)
1210 // Adds task "obj" to the board
1211 TTask* task = dynamic_cast<TTask*>(obj);
1214 Error("AddToBoard","To TTask board can be added only tasks.");
1217 GetParentalTask()->Add(task);
1220 /*****************************************************************************/
1222 TObject* AliTaskLoader::Get() const
1224 // Returns pointer to the current task
1225 return (GetParentalTask()) ? GetParentalTask()->GetListOfTasks()->FindObject(GetName()) : 0x0;
1227 /*****************************************************************************/
1229 TTask* AliTaskLoader::GetParentalTask() const
1231 //returns parental tasks for this task
1232 return fParentalTask;
1235 /*****************************************************************************/
1237 /*****************************************************************************/
1238 /*****************************************************************************/
1239 /*****************************************************************************/