]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliConfig.cxx
More exact rounding function, but also much slower.
[u/mrichter/AliRoot.git] / STEER / AliConfig.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.3  2001/10/04 15:30:56  hristov
19 Changes to accommodate the set of PHOS folders and tasks (Y.Schutz)
20
21 Revision 1.2  2001/05/21 17:22:50  buncic
22 Fixed problem with missing AliConfig while reading galice.root
23
24 Revision 1.1  2001/05/16 14:57:22  alibrary
25 New files for folders and Stack
26
27 */
28
29 #include "AliConfig.h"
30 #include "AliDetector.h"
31 #include "TObjString.h" 
32 #include "TString.h"
33 #include "TTask.h" 
34 #include "AliGenerator.h" 
35 #include "AliMC.h" 
36
37 ClassImp(AliConfig)
38
39
40 AliConfig* AliConfig::fInstance = 0;
41
42 //____________________________________________________________________________
43 AliConfig* AliConfig::Instance ()
44 {
45   //
46   // Instance method for singleton class
47   //
48         if(fInstance == 0) {
49                     fInstance = new AliConfig ("Folders","Alice data exchange");
50                 }
51                 return fInstance;
52 }
53
54
55 AliConfig::AliConfig(const char *name, const char *title)
56 {
57   //
58   // Constructor
59   //
60   //
61   fInstance=this;
62   SetName(name) ; 
63   SetTitle(title) ; 
64   
65   fPDGFolder         =  "Constants/DatabasePDG" ;
66   fGeneratorFolder   =  "RunMC/Configuration/Generators" ;
67   fMCFolder          =  "RunMC/Configuration/VirtualMC" ;
68   fModuleFolder      =  "Run/Configuration/Modules" ;
69   fDetectorFolder    =  new char*[8] ; 
70   fDetectorFolder[0] = "Run/Conditions/Calibration" ;
71   fDetectorFolder[1] = "Run/Event/Data" ;
72   fDetectorFolder[2] = "Run/Event/RecData" ;
73   fDetectorFolder[3] = "RunMC/Event/Data/Hits" ;
74   fDetectorFolder[4] = "RunMC/Event/Data/SDigits" ;
75   fDetectorFolder[5] = "Run/Conditions/QA" ;  
76   fDetectorFolder[6] = "RunMC/Event/Data/TrackReferences" ;  
77   fDetectorFolder[7] = 0 ;  
78   fDetectorTask    =  new char*[5] ; 
79   fDetectorTask[0] = "Tasks/QA" ;  
80   fDetectorTask[1] = "Tasks/SDigitizer" ;  
81   fDetectorTask[2] = "Tasks/Digitizer" ;  
82   fDetectorTask[3] = "Tasks/Reconstructioner" ;  
83   fDetectorTask[4] = 0 ;  
84
85   fTopFolder = gROOT->GetRootFolder ()->AddFolder (name,title);
86   fTopFolder->SetOwner() ; 
87   gROOT->GetListOfBrowsables ()->Add (fTopFolder, name);
88   
89   TFolder *subfolder;
90   
91   TFolder *constants =
92     fTopFolder->AddFolder ("Constants", "Detector constants");
93   
94   subfolder = 
95     constants->AddFolder ("DatabasePDG", "PDG database");
96   
97   TFolder *run = 
98     fTopFolder->AddFolder ("Run", "Run dependent folders");
99   
100   TFolder *conditions = 
101     run->AddFolder ("Conditions", "Run conditions");
102   
103   subfolder =
104     conditions->AddFolder ("Calibration","Detector calibration data");
105   
106   subfolder =
107     conditions->AddFolder ("Aligment", "Detector aligment");
108   
109   subfolder =
110     conditions->AddFolder ("QA", "Detector QA");
111   
112   TFolder *configuration =
113     run->AddFolder ("Configuration", "Run configuration");
114   
115   subfolder =
116     configuration->AddFolder ("Modules", "Detector objects");
117   
118   subfolder =
119     configuration->AddFolder ("Field", "Magnetic field maps");
120   
121   TFolder *event = 
122     run->AddFolder ("Event", "Event folders");
123   
124   subfolder = 
125     event->AddFolder ("Data", "Detector raw data");
126   
127   subfolder =
128     event->AddFolder ("RecData", "Detectors reconstucted data");
129   
130   TFolder *run_mc =
131     fTopFolder->AddFolder ("RunMC", "MonteCarlo run dependent folders");
132   
133   TFolder *configuration_mc =
134     run_mc->AddFolder ("Configuration","MonteCarlo run configuration");
135   
136   subfolder =
137     configuration_mc->AddFolder ("Generators","list of generator objects");
138   
139   subfolder =
140     configuration_mc->AddFolder ("VirtualMC", "the Virtual MC");
141   
142   TFolder *event_mc =
143     run_mc->AddFolder ("Event", "MonteCarlo event folders");
144   
145   subfolder =
146     event_mc->AddFolder ("Header", "MonteCarlo event header");
147   
148   //            subfolder =
149   //                event_mc->AddFolder ("Kinematics", "MonteCarlo generated particles");
150   
151   TFolder *data_mc =
152     event_mc->AddFolder ("Data", "MonteCarlo data");
153   
154   subfolder = 
155     data_mc->AddFolder ("Hits", "MonteCarlo Hits") ; 
156  
157  subfolder = 
158     data_mc->AddFolder ("SDigits", "MonteCarlo SDigits") ; 
159
160  subfolder = 
161     data_mc->AddFolder ("TrackReferences", "MonteCarlo track references") ; 
162
163
164   
165   // Add the tasks to //Folders
166   
167   TFolder * tasksfolder = fTopFolder->AddFolder("Tasks", "ALICE Tasks") ; 
168   
169   TTask * qa = new TTask("QA", "Alice QA tasks") ;
170   tasksfolder->Add(qa); 
171   
172   TTask * sd = new TTask("SDigitizer", "Alice SDigitizer") ;
173   tasksfolder->Add(sd); 
174
175   TTask * di = new TTask("Digitizer", "Alice Digitizer") ;
176   tasksfolder->Add(di); 
177
178   TTask * re = new TTask("Reconstructioner", "Alice Reconstructioner") ;
179   tasksfolder->Add(re); 
180
181 }
182
183 //____________________________________________________________________________
184 AliConfig::~AliConfig()
185
186   delete [] fDetectorFolder ;  
187   delete fDetectorTask ;  
188   delete fTopFolder ; 
189 }
190
191 //____________________________________________________________________________
192 void    AliConfig::AddInFolder (char *dir, TObject *obj)
193 {
194   TFolder *folder =
195     dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
196   if (folder)
197     folder->Add (static_cast<TObject *>(obj));
198 }
199
200 //____________________________________________________________________________
201 void    AliConfig::AddSubFolder(char * dir[], TObject *obj)
202 {
203   int iDir = 0;
204   
205   while (dir[iDir]) 
206     {
207       TFolder * folder = dynamic_cast<TFolder *>(fTopFolder->FindObject (dir[iDir++]));
208       if (folder) {
209         TFolder * subfolder = dynamic_cast<TFolder *>(folder->FindObject (obj->GetName()));
210         if (!subfolder)
211           subfolder = folder->AddFolder (obj->GetName(),obj->GetTitle());                          
212       }
213     }
214 }
215
216 //____________________________________________________________________________
217 void    AliConfig::AddSubTask(char * dir[], TObject *obj)
218 {
219   int iDir = 0;
220   
221   while (dir[iDir]) 
222     {
223       TTask * task = dynamic_cast<TTask *>(fTopFolder->FindObject (dir[iDir++]));
224       if (task) {
225         TTask * subtask = static_cast<TTask*>(task->GetListOfTasks()->FindObject (obj->GetName()));
226         if (!subtask) {
227           subtask = new TTask(obj->GetName(), obj->GetTitle()) ; 
228           task->Add(subtask);                      
229         }
230       }
231     }
232 }
233
234 //____________________________________________________________________________
235 TObject* AliConfig::FindInFolder (char *dir, const char *name)
236 {
237   if(!name) return(fTopFolder->FindObject(name));
238   TFolder * folder = dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
239   if (!folder) return (NULL);
240   return(folder->FindObject(name));
241 }
242
243 //____________________________________________________________________________
244 void    AliConfig::Add (AliGenerator * obj)
245 {
246   AddInFolder(fGeneratorFolder, obj);
247 }
248
249 //____________________________________________________________________________
250 void    AliConfig::Add (AliMC * obj)
251 {
252   AddInFolder(fMCFolder, obj);
253 }
254
255 //____________________________________________________________________________
256 void    AliConfig::Add (TDatabasePDG * obj)
257 {
258   AddInFolder(fPDGFolder, obj);
259 }
260
261 //____________________________________________________________________________
262 void    AliConfig::Add (AliModule* obj)
263 {
264   AddInFolder(fModuleFolder, obj);
265 }
266
267 //____________________________________________________________________________
268 void    AliConfig::Add (AliDetector * obj)
269 {
270   AddSubFolder(fDetectorFolder, obj); 
271   AddSubTask(fDetectorTask, obj);
272 }
273
274
275 //____________________________________________________________________________
276 void    AliConfig::Add (char *list)
277 {
278   char *path;
279   
280   const char   *conf_path = gSystem->Getenv ("ALICE_CONFIG_PATH");
281   if  (conf_path) {
282     path = new char[strlen (conf_path)];
283     strcpy (path, conf_path);
284   } else {
285     const char   *alice = gSystem->Getenv ("ALICE_ROOT");
286     path = new char[strlen (alice) + 32];
287     
288     strcpy (path, ".:");
289     if (alice) {
290       strcat (path, alice);
291     }
292     strcat (path, "/macros/config");
293   }
294   
295   char   *token = strtok (path, ":");
296   
297   TList  *dirlist = new TList;
298   
299   while (token != NULL) 
300     {
301       dirlist->Add (new TObjString(token));
302       token = strtok (NULL, ":");
303     }
304   
305   token = strtok (list, " ");
306   
307   while (token != NULL)
308     {
309       cout << "Configuring " << token << ": ";
310       
311       TObject *obj;
312       TIter   next (dirlist);
313       TString found = "\0";
314       
315       while ((obj = next ()))
316         {
317           TString dir(obj->GetName());
318           TString path  = dir + "/" + token;
319           TString macro = path + ".C";
320           if (!gSystem->AccessPathName (macro.Data()))  {
321             gInterpreter->ExecuteMacro (macro.Data());                             
322             found = "(" + macro + ")";
323             if (macro.Contains("/")) {
324               TString dirname = gSystem->DirName(macro.Data());
325               TString macroConfigure = dirname + "/Configure.C";
326               if (!gSystem->AccessPathName (macroConfigure.Data()))     {
327                 gInterpreter->ExecuteMacro (macroConfigure.Data());                                 
328                 found += " => Configured";
329               }                       
330             }
331             break;
332           } else {
333             TString macroDefault = path + "/Default.C";
334             if (!gSystem->AccessPathName (macroDefault.Data())) {
335               gInterpreter->ExecuteMacro (macroDefault.Data());
336               found = "(" + macro + ")";
337               TString macroConfigure = path + "/Configure.C";
338               if (!gSystem->AccessPathName (macroConfigure.Data()))     {
339                 gInterpreter->ExecuteMacro (macroConfigure.Data());                                 
340                 found += " => Configured";
341               }
342               break;                                
343             }
344           }
345         }
346       
347       if (strlen(found.Data())) {
348         cout << found << " => OK" << endl;
349       } else {
350         cout << " => FAILED." << endl;
351         exit(1); 
352       }             
353       
354       token = strtok (NULL, " ");
355     }
356   
357   if (dirlist) delete dirlist;
358   
359 }
360
361