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 /*****************************************************************************/
90 AliDataLoader::~AliDataLoader()
95 /*****************************************************************************/
97 Int_t AliDataLoader::SetEvent()
99 //basically the same that GetEvent but do not post data to folders
100 AliRunLoader* rl = GetRunLoader();
103 Error("SetEvent","Can not get RunGettr");
107 Int_t evno = rl->GetEventNumber();
109 TIter next(fBaseLoaders);
111 while ((bl = (AliBaseLoader*)next()))
113 if (bl->DoNotReload() == kFALSE) bl->Clean();
122 if (GetDebug()) Info("SetEvent","Reloading new file. File opt is %s",fFileOption.Data());
123 OpenFile(fFileOption);
126 fDirectory = AliLoader::ChangeDir(fFile,evno);
127 if (fDirectory == 0x0)
129 Error("SetEvent","Can not chage directory in file %s",fFile->GetName());
135 /*****************************************************************************/
137 Int_t AliDataLoader::GetEvent()
139 // posts all loaded data from files to White Board
140 // event number is defined in RunLoader
143 // 0 - in case of no error
144 // 1 - event not found
146 //for each base laoder post, if was loaded before GetEvent
148 //call set event to switch to new directory in file
151 //post all data that were loaded before
152 // ->SetEvent does not call Unload, but only cleans White Board
153 // such IsLoaded flag stays untached
155 if ( AliLoader::TestFileOption(fFileOption) == kTRUE ) //if file is read or update mode try to post
156 { //in other case there is no sense to post: file is new
157 TIter nextbl(fBaseLoaders);
159 while ((bl = (AliBaseLoader*)nextbl()))
163 if (bl->DoNotReload() == kFALSE) bl->Post();
169 /*****************************************************************************/
171 Int_t AliDataLoader::OpenFile(Option_t* opt)
173 //Opens file named 'filename', and assigns pointer to it to 'file'
174 //jumps to fDirectoryectory corresponding to current event and stores the pointer to it in 'fDirectory'
175 //option 'opt' is passed to TFile::Open
178 if(fFile->IsOpen() == kTRUE)
180 Warning("OpenFile"," File %s already opened. First close it.",fFile->GetName());
185 Warning("OpenFile","Pointer to file %s is not null, but file is not opened",
192 TString fname(SetFileOffset(fFileName));
194 fFile = (TFile *)(gROOT->GetListOfFiles()->FindObject(fname));
197 if(fFile->IsOpen() == kTRUE)
199 Warning("OpenFile","File %s already opened by sombody else. First close it.",
206 fFile = TFile::Open(fname,fFileOption);//open the file
209 Error("OpenFile","Can not open file %s",fname.Data());
212 if (fFile->IsOpen() == kFALSE)
214 Error("OpenFile","Can not open file %s",fname.Data());
218 fFile->SetCompressionLevel(fCompressionLevel);
220 AliRunLoader* rg = GetRunLoader();
223 Error("OpenFile","Can not find Run-Loader in folder.");
226 Int_t evno = rg->GetEventNumber();
228 fDirectory = AliLoader::ChangeDir(fFile,evno);
229 if (fDirectory == 0x0)
231 Error("OpenFile","Can not chage fDirectory in file %s.",fFile->GetName());
236 /*****************************************************************************/
238 void AliDataLoader::Unload()
240 //unloads main data - shortcut method
241 GetBaseLoader(0)->Unload();
243 /*****************************************************************************/
245 void AliDataLoader::UnloadAll()
247 //Unloads all data and tasks
248 TIter next(fBaseLoaders);
250 while ((bl = (AliBaseLoader*)next()))
255 /*****************************************************************************/
257 Int_t AliDataLoader::Reload()
259 //Unloads and loads data again
260 if ( fFile == 0x0 ) return 0;
262 TBits loaded(fBaseLoaders->GetEntries());
263 TIter next(fBaseLoaders);
267 while ((bl = (AliBaseLoader*)next()))
271 loaded.SetBitNumber(i++,kTRUE);
279 while ((bl = (AliBaseLoader*)next()))
281 if (loaded.TestBitNumber(i++))
283 retval = bl->Load(fFileOption);
286 Error("Reload","Error occur while loading %s",bl->GetName());
295 /*****************************************************************************/
296 Int_t AliDataLoader::WriteData(Option_t* opt)
298 //Writes primary data == first BaseLoader
300 Info("WriteData","Writing %s container for %s data. Option is %s.",
301 GetBaseLoader(0)->GetName(),GetName(),opt);
302 return GetBaseLoader(0)->WriteData(opt);
304 /*****************************************************************************/
306 Int_t AliDataLoader::Load(Option_t* opt)
308 //Writes primary data == first BaseLoader
309 return GetBaseLoader(0)->Load(opt);
311 /*****************************************************************************/
313 Int_t AliDataLoader::SetEventFolder(TFolder* eventfolder)
315 //sets the event folder
316 if (eventfolder == 0x0)
318 Error("SetEventFolder","Stupid joke. Argument is NULL");
322 Info("SetFolder","name = %s Setting Event Folder named %s.",
323 GetName(),eventfolder->GetName());
325 fEventFolder = eventfolder;
328 /*****************************************************************************/
330 Int_t AliDataLoader::SetFolder(TFolder* folder)
335 Error("SetFolder","Stupid joke. Argument is NULL");
339 if (GetDebug()) Info("SetFolder","name = %s Setting folder named %s.",GetName(),folder->GetName());
342 TIter next(fBaseLoaders);
345 while ((bl = (AliBaseLoader*)next()))
347 bl->SetDataLoader(this);
352 /******************************************************************/
354 TFolder* AliDataLoader::GetEventFolder()
356 //get EVENT folder (data that are changing from event to event, even in single run)
357 if (GetDebug()) Info("GetEventFolder","EF = %#x");
360 /*****************************************************************************/
362 AliRunLoader* AliDataLoader::GetRunLoader()
364 //gets the run-loader from event folder
365 AliRunLoader* rg = 0x0;
366 TFolder* ef = GetEventFolder();
369 Error("GetRunLoader","Can not get event folder.");
372 rg = dynamic_cast<AliRunLoader*>(ef->FindObject(AliRunLoader::fgkRunLoaderName));
376 /*****************************************************************************/
377 void AliDataLoader::CloseFile()
380 TIter next(fBaseLoaders);
382 while ((bl = (AliBaseLoader*)next()))
384 if (bl->IsLoaded()) return;
388 Info("CloseFile","Closing and deleting (object) file.");
394 /*****************************************************************************/
396 void AliDataLoader::Clean()
399 GetBaseLoader(0)->Clean();
401 /*****************************************************************************/
403 void AliDataLoader::CleanAll()
405 //Cleans all folders and tasks
406 TIter next(fBaseLoaders);
408 while ((bl = (AliBaseLoader*)next()))
413 /*****************************************************************************/
415 void AliDataLoader::SetFileNameSuffix(const TString& suffix)
417 //adds the suffix before ".root",
418 //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
419 //made on Jiri Chudoba demand
422 Info("SetFileNameSuffix","suffix=%s",suffix.Data());
423 Info("SetFileNameSuffix"," Digits File Name before: %s",fFileName.Data());
426 static TString dotroot(".root");
427 const TString& suffixdotroot = suffix + dotroot;
428 fFileName = fFileName.ReplaceAll(dotroot,suffixdotroot);
431 Info("SetDigitsFileNameSuffix"," after : %s",fFileName.Data());
433 /*****************************************************************************/
435 Bool_t AliDataLoader::CheckReload()
437 //checks if we have to reload given file
438 if (fFile == 0x0) return kFALSE;
439 TString tmp = SetFileOffset(fFileName);
440 if (tmp.CompareTo(fFile->GetName())) return kTRUE; //file must be reloaded
443 /*****************************************************************************/
445 const TString AliDataLoader::SetFileOffset(const TString& fname)
449 Long_t offset = (Long_t)GetRunLoader()->GetFileOffset();
450 if (offset < 1) return fname;
453 soffset += offset;//automatic conversion to string
454 TString dotroot(".root");
455 const TString& offfsetdotroot = offset + dotroot;
457 out = out.ReplaceAll(dotroot,offfsetdotroot);
458 if (GetDebug()) Info("SetFileOffset","in=%s out=%s.",fname.Data(),out.Data());
462 /*****************************************************************************/
464 void AliDataLoader::SetFileOption(Option_t* newopt)
467 if (fFileOption.CompareTo(newopt) == 0) return;
468 fFileOption = newopt;
471 /*****************************************************************************/
473 void AliDataLoader::SetCompressionLevel(Int_t cl)
475 //sets comression level for data defined by di
476 fCompressionLevel = cl;
477 if (fFile) fFile->SetCompressionLevel(cl);
479 /*****************************************************************************/
481 Int_t AliDataLoader::GetDebug() const
483 //it is not inline bacause AliLoader.h includes AliDataLoaer.h
484 //and there is circular depenedence
485 return AliLoader::GetDebug();
487 /*****************************************************************************/
489 void AliDataLoader::MakeTree()
491 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(fBaseLoaders->At(0));
494 Error("MakeTree","Can not make a tree because main base loader is not a tree loader");
499 /*****************************************************************************/
501 Bool_t AliDataLoader::IsFileWritable() const
503 //returns true if file is writable
504 return (fFile)?fFile->IsWritable():kFALSE;
506 /*****************************************************************************/
508 Bool_t AliDataLoader::IsFileOpen() const
510 //returns true if file is writable
511 return (fFile)?fFile->IsOpen():kFALSE;
513 /*****************************************************************************/
515 Bool_t AliDataLoader::IsOptionContrary(const TString& option) const
517 //Checks if passed option is contrary with file open option
518 //which is passed option "writable" and existing option not wriable
519 //in reverse case it is no harm so it is NOT contrary
520 if (fFile == 0x0) return kFALSE; //file is not opened - no problem
522 if ( ( AliLoader::IsOptionWritable(option) == kTRUE ) && // passed option is writable and
523 ( AliLoader::IsOptionWritable(fFileOption) == kFALSE ) ) // existing one is not writable
530 /*****************************************************************************/
531 void AliDataLoader::AddBaseLoader(AliBaseLoader* bl)
533 //Adds a base loader to lits of base loaders managed by this data loader
534 //Managed data/task will be stored in proper root directory,
536 // - in case of tree/object - data folder connected with detector associated with this data loader
537 // - in case of task - parental task which defined in this AliTaskLoader
541 Warning("AddBaseLoader","Pointer is null.");
545 TObject* obj = fBaseLoaders->FindObject(bl->GetName());
548 Error("AddBaseLoader","Can not add this base loader.");
549 Error("AddBaseLoader","There exists already base loader which manages data named %s for this detector.");
554 fBaseLoaders->Add(bl);
557 /*****************************************************************************/
559 AliBaseLoader* AliDataLoader::GetBaseLoader(const TString& name) const
561 return dynamic_cast<AliBaseLoader*>(fBaseLoaders->FindObject(name));
563 /*****************************************************************************/
565 AliBaseLoader* AliDataLoader::GetBaseLoader(Int_t n) const
567 return dynamic_cast<AliBaseLoader*>(fBaseLoaders->At(n));
569 /*****************************************************************************/
571 TTree* AliDataLoader::Tree() const
573 //returns tree from the main base loader
574 //it is just shortcut method for comfort of user
575 //main storage object does not have to be Tree -
576 //that is why first we need to check if it is a TreeLoader
577 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(GetBaseLoader(0));
578 if (tl == 0x0) return 0x0;
581 /*****************************************************************************/
583 void AliDataLoader::SetDirName(TString& dirname)
585 if (GetDebug()>9) Info("SetDirName","FileName before %s",fFileName.Data());
587 Int_t n = fFileName.Last('/');
589 if (GetDebug()>9) Info("SetDirName","Slash found on pos %d",n);
591 if (n > 0) fFileName = fFileName.Remove(0,n+1);
593 if (GetDebug()>9) Info("SetDirName","Core FileName %s",fFileName.Data());
595 fFileName = dirname + "/" + fFileName;
597 if (GetDebug()>9) Info("SetDirName","FileName after %s",fFileName.Data());
599 /*****************************************************************************/
600 AliObjectLoader* AliDataLoader::GetBaseDataLoader()
602 return dynamic_cast<AliObjectLoader*>(GetBaseLoader(kData));
604 /*****************************************************************************/
605 AliTaskLoader* AliDataLoader::GetBaseTaskLoader()
607 return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kTask));
609 /*****************************************************************************/
610 AliBaseLoader* AliDataLoader::GetBaseQALoader()
612 return GetBaseLoader(kQA);
614 /*****************************************************************************/
615 AliTaskLoader* AliDataLoader::GetBaseQATaskLoader()
617 //returns pointer to QA base loader
618 return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kQATask));
620 /*****************************************************************************/
621 void AliDataLoader::SetBaseDataLoader(AliBaseLoader* bl)
623 //sets data base loader
626 Error("SetBaseDataLoader","Parameter is null");
629 if (GetBaseDataLoader()) delete GetBaseDataLoader();
630 fBaseLoaders->AddAt(bl,kData);
632 /*****************************************************************************/
633 void AliDataLoader::SetBaseTaskLoader(AliTaskLoader* bl)
635 //sets Task base loader
638 Error("SetBaseTaskLoader","Parameter is null");
641 if (GetBaseTaskLoader()) delete GetBaseTaskLoader();
642 fBaseLoaders->AddAt(bl,kTask);
644 /*****************************************************************************/
645 void AliDataLoader::SetBaseQALoader(AliBaseLoader* bl)
647 //sets QA base loader
650 Error("SetBaseQALoader","Parameter is null");
653 if (GetBaseQALoader()) delete GetBaseQALoader();
654 fBaseLoaders->AddAt(bl,kQA);
656 /*****************************************************************************/
657 void AliDataLoader::SetBaseQATaskLoader(AliTaskLoader* bl)
659 //sets QA Task base loader
662 Error("SetBaseQATaskLoader","Parameter is null");
665 if (GetBaseQATaskLoader()) delete GetBaseQATaskLoader();
666 fBaseLoaders->AddAt(bl,kQATask);
668 void AliDataLoader::Synchronize()
670 //synchrinizes all writtable files
671 if ( fFile == 0x0 ) return;
672 if ( fFile->IsWritable() == kFALSE ) return;
673 fFile->Write(0,TObject::kOverwrite);
676 /*****************************************************************************/
677 /*****************************************************************************/
678 /*****************************************************************************/
679 //__________________________________________
680 ///////////////////////////////////////////////////////////////////////////////
682 // class AliBaseLoader //
685 ///////////////////////////////////////////////////////////////////////////////
686 ClassImp(AliBaseLoader)
688 AliBaseLoader::AliBaseLoader():
690 fStoreInTopOfFile(kFALSE),
691 fDoNotReload(kFALSE),
695 /*****************************************************************************/
697 AliBaseLoader::AliBaseLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
698 TNamed(name,name+" Base Loader"),
700 fStoreInTopOfFile(storeontop),
701 fDoNotReload(storeontop),//if stored on top of file - this object is loaded ones pe
706 /*****************************************************************************/
708 Int_t AliBaseLoader::Load(Option_t* opt)
711 Info("Load","data type = %s, option = %s",GetName(),opt);
715 Warning("Load","Data <<%s>> are already loaded. Use ReloadData to force reload. Nothing done",GetName());
721 if (GetDataLoader()->IsFileOpen() == kTRUE)
723 if (GetDataLoader()->IsOptionContrary(opt) == kTRUE)
725 Error("Load","Data Type %s, Container Name %s", GetDataLoader()->GetName(),GetName());
726 Error("Load","File was already opened in READ-ONLY mode, while now WRITEABLE access is requested.");
727 Error("Load","Use AliDataLoader::SetOption to enforce change of access mode OR");
728 Error("Load","Load previosly loaded data with coherent option.");
734 retval = GetDataLoader()->OpenFile(opt);
737 Error("Load","Error occured while opening <<%s>> file",GetName());
741 //if file is recreated there is no sense to search for data to post and get Error message
742 if (AliLoader::TestFileOption(opt) == kFALSE)
744 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(this);
745 if (tl) tl->MakeTree();
753 Error("Load","Error occured while posting %s from file to folder.",GetName());
760 /*****************************************************************************/
762 Int_t AliBaseLoader::Post()
764 //Posts data container to proper folders
766 if ( GetDirectory() == 0x0)
768 Error("Post","%s directory is NULL. Load before.",GetDataLoader()->GetName());
772 TObject* data = GetFromDirectory(fName);
775 //if such an obejct already exists - remove it first
780 //check if file is in update mode
781 Int_t fileupdate = GetDataLoader()->GetFileOption().CompareTo("update",TString::kIgnoreCase);
782 if ( fileupdate == 0)
783 { //if it is, it is normal that there is no data yet
786 Info("Post","Can not find %s in file %s (file is opened in UPDATE mode).",
787 GetName(),GetDataLoader()->GetFile()->GetName());
792 Warning("Post","Can not find %s in file %s", GetName(),GetDataLoader()->GetFile()->GetName());
797 /*****************************************************************************/
799 Int_t AliBaseLoader::Post(TObject* data)
801 //Posts data container to proper folders
804 Error("Post","Pointer to object is NULL");
807 TObject* obj = Get();
810 if (GetDebug()) Warning("Post","This object was already posted.");
815 Warning("PostData","Object named %s already exitsts in data folder. Removing it",GetName());
818 return AddToBoard(data);
820 /*****************************************************************************/
822 Int_t AliBaseLoader::WriteData(Option_t* opt)
824 //Writes data defined by di object
825 //opt might be "OVERWRITE" in case of forcing overwriting
827 Info("WriteData","Writing %s container for %s data. Option is %s.",
828 GetName(),GetDataLoader()->GetName(),opt);
830 TObject *data = Get();
832 {//did not get, nothing to write
833 Warning("WriteData","Tree named %s not found in folder. Nothing to write.",GetName());
837 //check if file is opened
838 if (GetDirectory() == 0x0)
841 GetDataLoader()->SetFileOption("UPDATE");
842 if (GetDataLoader()->OpenFile("UPDATE"))
844 //oops, can not open the file, give an error message and return error code
845 Error("WriteData","Can not open hits file. %s ARE NOT WRITTEN",GetName());
850 if (GetDataLoader()->IsFileWritable() == kFALSE)
852 Error("WriteData","File %s is not writable",GetDataLoader()->GetFileName().Data());
856 GetDirectory()->cd(); //set the proper directory active
858 //see if hits container already exists in this (root) directory
859 TObject* obj = GetFromDirectory(GetName());
861 { //if they exist, see if option OVERWRITE is used
862 const char *oOverWrite = strstr(opt,"OVERWRITE");
864 {//if it is not used - give an error message and return an error code
865 Error("WriteData","Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
870 if (GetDebug()) Info("WriteData","DataName = %s, opt = %s, data object name = %s",
871 GetName(),opt,data->GetName());
872 if (GetDebug()) Info("WriteData","File Name = %s, Directory Name = %s Directory's File Name = %s",
873 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
874 GetDirectory()->GetFile()->GetName());
876 if (GetDebug()) Info("WriteData","Writing data");
877 data->Write(0,TObject::kOverwrite);
879 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
884 /*****************************************************************************/
886 Int_t AliBaseLoader::Reload()
888 //Unloads and loads datat again - if loaded before
892 return Load(GetDataLoader()->GetFileOption());
896 /*****************************************************************************/
898 void AliBaseLoader::Clean()
900 //removes objects from folder/task
901 if (GetDebug()) Info("Clean","%s %s",GetName(),GetDataLoader()->GetName());
902 TObject* obj = Get();
906 Info("Clean","cleaning %s.",GetName());
907 RemoveFromBoard(obj);
911 /*****************************************************************************/
913 void AliBaseLoader::Unload()
917 GetDataLoader()->CloseFile();
919 /*****************************************************************************/
920 AliDataLoader* AliBaseLoader::GetDataLoader() const
922 if (fDataLoader == 0x0)
924 Fatal("GetDataLoader","Pointer to Data Loader is NULL");
928 /*****************************************************************************/
930 Int_t AliBaseLoader::GetDebug() const
932 return (Int_t)AliLoader::fgDebug;
935 TDirectory* AliBaseLoader::GetDirectory()
937 // returnd TDirectory where data are to be saved
938 //if fStoreInTopOfFile flag is true - returns pointer to file
939 return (fStoreInTopOfFile)?GetDataLoader()->GetFile():GetDataLoader()->GetDirectory();
941 /*****************************************************************************/
942 /*****************************************************************************/
943 /*****************************************************************************/
944 //__________________________________________
945 ///////////////////////////////////////////////////////////////////////////////
947 // class AliObjectLoader //
950 ///////////////////////////////////////////////////////////////////////////////
952 ClassImp(AliObjectLoader)
954 AliObjectLoader::AliObjectLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
955 AliBaseLoader(name,dl,storeontop)
959 /*****************************************************************************/
961 TFolder* AliObjectLoader::GetFolder() const
963 TFolder* df = GetDataLoader()->GetFolder();
966 Fatal("GetFolder","Data Folder is NULL");
970 /*****************************************************************************/
972 void AliObjectLoader::RemoveFromBoard(TObject* obj)
974 GetFolder()->Remove(obj);
976 /*****************************************************************************/
977 Int_t AliObjectLoader::AddToBoard(TObject* obj)
979 GetFolder()->Add(obj);
982 /*****************************************************************************/
984 TObject* AliObjectLoader::Get() const
986 return (GetFolder()) ? GetFolder()->FindObject(GetName()) : 0x0;
989 /*****************************************************************************/
990 /*****************************************************************************/
991 /*****************************************************************************/
992 //__________________________________________
993 ///////////////////////////////////////////////////////////////////////////////
995 // class AliTreeLoader //
998 ///////////////////////////////////////////////////////////////////////////////
1000 ClassImp(AliTreeLoader)
1002 AliTreeLoader::AliTreeLoader(const TString& name, AliDataLoader* dl,Bool_t storeontop):
1003 AliObjectLoader(name,dl,storeontop)
1008 /*****************************************************************************/
1010 Int_t AliTreeLoader::WriteData(Option_t* opt)
1012 //Writes data defined by di object
1013 //opt might be "OVERWRITE" in case of forcing overwriting
1016 Info("WriteData","Writing %s container for %s data. Option is %s.",
1017 GetName(),GetDataLoader()->GetName(),opt);
1019 TObject *data = Get();
1021 {//did not get, nothing to write
1022 Warning("WriteData","Tree named %s not found in folder. Nothing to write.",GetName());
1026 //check if file is opened
1027 if (GetDirectory() == 0x0)
1029 //if not try to open
1030 GetDataLoader()->SetFileOption("UPDATE");
1031 if (GetDataLoader()->OpenFile("UPDATE"))
1033 //oops, can not open the file, give an error message and return error code
1034 Error("WriteData","Can not open hits file. %s ARE NOT WRITTEN",GetName());
1039 if (GetDataLoader()->IsFileWritable() == kFALSE)
1041 Error("WriteData","File %s is not writable",GetDataLoader()->GetFileName().Data());
1045 GetDirectory()->cd(); //set the proper directory active
1047 //see if hits container already exists in this (root) directory
1048 TObject* obj = GetFromDirectory(GetName());
1050 { //if they exist, see if option OVERWRITE is used
1051 const char *oOverWrite = strstr(opt,"OVERWRITE");
1053 {//if it is not used - give an error message and return an error code
1054 Error("WriteData","Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
1059 if (GetDebug()) Info("WriteData","DataName = %s, opt = %s, data object name = %s",
1060 GetName(),opt,data->GetName());
1061 if (GetDebug()) Info("WriteData","File Name = %s, Directory Name = %s Directory's File Name = %s",
1062 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
1063 GetDirectory()->GetFile()->GetName());
1065 //if a data object is a tree set the directory
1066 TTree* tree = dynamic_cast<TTree*>(data);
1067 if (tree) tree->SetDirectory(GetDirectory()); //forces setting the directory to this directory (we changed dir few lines above)
1069 if (GetDebug()) Info("WriteData","Writing tree");
1070 data->Write(0,TObject::kOverwrite);
1072 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
1077 /*****************************************************************************/
1079 void AliTreeLoader::MakeTree()
1081 //this virtual method creates the tree in the file
1085 Info("MakeTree","name = %s, Data Name = %s Tree already exists.",
1086 GetName(),GetDataLoader()->GetName());
1087 return;//tree already made
1090 Info("MakeTree","Making Tree named %s.",GetName());
1092 TString dtypename(GetDataLoader()->GetName());
1093 TTree* tree = new TTree(GetName(), dtypename + " Container"); //make a tree
1096 Error("MakeTree","Can not create %s tree.",GetName());
1099 tree->SetAutoSave(1000000000); //no autosave
1100 GetFolder()->Add(tree);
1101 WriteData("OVERWRITE");//write tree to the file
1105 /*****************************************************************************/
1106 /*****************************************************************************/
1107 /*****************************************************************************/
1108 //__________________________________________
1109 ///////////////////////////////////////////////////////////////////////////////
1111 // class AliTaskLoader //
1114 ///////////////////////////////////////////////////////////////////////////////
1116 ClassImp(AliTaskLoader)
1118 AliTaskLoader::AliTaskLoader(const TString& name, AliDataLoader* dl, TTask* parentaltask, Bool_t storeontop):
1119 AliBaseLoader(name,dl,storeontop),
1120 fParentalTask(parentaltask)
1125 /*****************************************************************************/
1127 void AliTaskLoader::RemoveFromBoard(TObject* obj)
1129 GetParentalTask()->GetListOfTasks()->Remove(obj);
1131 /*****************************************************************************/
1133 Int_t AliTaskLoader::AddToBoard(TObject* obj)
1135 TTask* task = dynamic_cast<TTask*>(obj);
1138 Error("AddToBoard","To TTask board can be added only tasks.");
1141 GetParentalTask()->Add(task);
1144 /*****************************************************************************/
1146 TObject* AliTaskLoader::Get() const
1148 return (GetParentalTask()) ? GetParentalTask()->GetListOfTasks()->FindObject(GetName()) : 0x0;
1150 /*****************************************************************************/
1152 TTask* AliTaskLoader::GetParentalTask() const
1154 //returns parental tasks for this task
1155 return fParentalTask;
1158 /*****************************************************************************/
1160 /*****************************************************************************/
1161 /*****************************************************************************/
1162 /*****************************************************************************/