]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliTreeLoader.cxx
Removing warnings on alphacxx6
[u/mrichter/AliRoot.git] / STEER / AliTreeLoader.cxx
1 /////////////////////////////////////////////////////////////////////////////////////////////
2 //                                                                                         //
3 //  class AliTreeLoader                                                                    //
4 //                                                                                         //
5 //  Container of all data needed for full                                                  //
6 //  description of each data type                                                          //
7 //  (Hits, Kine, ...)                                                                      //
8 //                                                                                         //
9 //  Each data loader has a basic standard setup of BaseLoaders                             //
10 //  which can be identuified by indexes (defined by EStdBasicLoaders)                      //
11 //  Data managed by these standard base loaders has fixed naming convention                //
12 //  e.g. - tree with hits is always named TreeH                                            //
13 //                     (defined in AliLoader::fgkDefaultHitsContainerName)                 //
14 //       - task DtectorName+Name defined                                                   //
15 //                                                                                         //
16 //  EStdBasicLoaders   idx     Object Type        Description                              //
17 //      kData           0    TTree or TObject     main data itself (hits,digits,...)       //
18 //      kTask           1        TTask            object producing main data               //
19 //      kQA             2        TTree                quality assurance tree               //
20 //      kQATask         3        TTask            task producing QA object                 //
21 //                                                                                         //
22 //                                                                                         //
23 //  User can define and add more basic loaders even Run Time.                              //
24 //  Caution: in order to save information about added base loader                          //
25 //  user must rewrite Run Loader to galice.file, overwriting old setup                     //
26 //                                                                                         //
27 /////////////////////////////////////////////////////////////////////////////////////////////
28
29 /* $Id$ */
30
31 #include "AliTreeLoader.h"
32 #include "AliLog.h"
33 #include "AliRunLoader.h"
34
35
36 ClassImp(AliTreeLoader)
37
38 //______________________________________________________________________________
39 AliTreeLoader::AliTreeLoader(const TString& name, AliDataLoader* dl,Bool_t storeontop):
40  AliObjectLoader(name,dl,storeontop)
41 {
42   //
43   // Constructor
44   //
45 }
46
47 //______________________________________________________________________________
48 AliTreeLoader::AliTreeLoader(const AliTreeLoader& source):
49   AliObjectLoader(source) 
50 {
51   //
52   // copy constructor
53   //
54   AliFatal("Copy constructor not implemented");
55 }
56
57 //______________________________________________________________________________
58 AliTreeLoader& AliTreeLoader::operator=(const AliTreeLoader& /*source*/) 
59 {
60   //
61   // Assignment operator
62   //
63   AliFatal("Assignment operator not implemented");
64   return *this;
65 }
66
67 //______________________________________________________________________________
68 Int_t AliTreeLoader::WriteData(Option_t* opt)
69 {
70   //
71   // Writes data defined by di object
72   // opt might be "OVERWRITE" in case of forcing overwriting
73   //
74   AliDebug(1, Form("Writing %s container for %s data. Option is %s.",
75                    GetName(),GetDataLoader()->GetName(),opt));
76   
77   TObject *data = Get();
78   if(data == 0x0)
79     {//did not get, nothing to write
80       AliWarning(Form("Tree named %s not found in folder. Nothing to write.",GetName()));
81       return 0;
82     }
83   
84   //check if file is opened
85   if (GetDirectory() == 0x0)
86     { 
87       //if not try to open
88       GetDataLoader()->SetFileOption("UPDATE");
89       if (GetDataLoader()->OpenFile("UPDATE"))
90         {  
91           //oops, can not open the file, give an error message and return error code
92           AliError(Form("Can not open hits file. %s ARE NOT WRITTEN",GetName()));
93           return 1;
94         }
95     }
96   
97   if (GetDataLoader()->IsFileWritable() == kFALSE)
98     {
99       AliError(Form("File %s is not writable",GetDataLoader()->GetFileName().Data()));
100       return 2;
101     }
102   
103   GetDirectory()->cd(); //set the proper directory active
104   
105   //see if hits container already exists in this (root) directory
106   TObject* obj = GetFromDirectory(GetName());
107   if (obj)
108     { //if they exist, see if option OVERWRITE is used
109       const char *oOverWrite = strstr(opt,"OVERWRITE");
110       if(!oOverWrite)
111         {//if it is not used -  give an error message and return an error code
112           AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
113           return 3;
114         }
115     }
116   
117   AliDebug(1, Form("DataName = %s, opt = %s, data object name = %s",
118                    GetName(),opt,data->GetName()));
119   AliDebug(1, Form("File Name = %s, Directory Name = %s Directory's File Name = %s",
120                    GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
121                    GetDirectory()->GetFile()->GetName()));
122   
123   //if a data object is a tree set the directory
124   TTree* tree = dynamic_cast<TTree*>(data);
125   if (tree) tree->SetDirectory(GetDirectory()); //forces setting the directory to this directory (we changed dir few lines above)
126   
127   AliDebug(1, "Writing tree");
128   data->Write(0,TObject::kOverwrite);
129   
130   fIsLoaded = kTRUE;  // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
131   
132   return 0;
133   
134 }
135
136 //______________________________________________________________________________
137 void AliTreeLoader::MakeTree()
138 {
139   //
140   // This virtual method creates the tree in the file
141   //
142   if (Tree()) 
143     {
144       AliDebug(1, Form("name = %s, Data Name = %s Tree already exists.",
145                        GetName(),GetDataLoader()->GetName()));
146       return;//tree already made 
147     }
148   AliDebug(1, Form("Making Tree named %s.",GetName()));
149   
150   TString dtypename(GetDataLoader()->GetName());
151   TTree* tree = new TTree(GetName(), dtypename + " Container"); //make a tree
152   if (tree == 0x0)
153     {
154       AliError(Form("Can not create %s tree.",GetName()));
155       return;
156    }
157   tree->SetAutoSave(1000000000); //no autosave
158   GetFolder()->Add(tree);
159   WriteData("OVERWRITE");//write tree to the file
160 }
161
162