]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliConfig.cxx
Code clean-up (F.Carminati)
[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.7  2002/10/23 07:43:00  alibrary
19 Introducing some effective C++ suggestions
20
21 Revision 1.6  2002/10/22 15:02:15  alibrary
22 Introducing Riostream.h
23
24 Revision 1.5  2002/10/14 14:57:32  hristov
25 Merging the VirtualMC branch to the main development branch (HEAD)
26
27 Revision 1.3.8.1  2002/06/10 14:43:06  hristov
28 Merged with v3-08-02
29
30 Revision 1.4  2002/05/27 14:26:59  hristov
31 New folder for track references added
32
33 Revision 1.3  2001/10/04 15:30:56  hristov
34 Changes to accommodate the set of PHOS folders and tasks (Y.Schutz)
35
36 Revision 1.2  2001/05/21 17:22:50  buncic
37 Fixed problem with missing AliConfig while reading galice.root
38
39 Revision 1.1  2001/05/16 14:57:22  alibrary
40 New files for folders and Stack
41
42 */
43
44 #include <Riostream.h>
45 #include <TDatabasePDG.h>
46 #include <TFolder.h>
47 #include <TInterpreter.h>
48 #include <TROOT.h>
49 #include <TSystem.h>
50
51 #include "AliConfig.h"
52 #include "AliDetector.h"
53 #include "AliGenerator.h" 
54 #include "TObjString.h" 
55 #include "TString.h"
56 #include "TTask.h" 
57
58 ClassImp(AliConfig)
59
60 AliConfig* AliConfig::fInstance = 0;
61
62 //____________________________________________________________________________
63 AliConfig* AliConfig::Instance ()
64 {
65   //
66   // Instance method for singleton class
67   //
68   if(!fInstance) fInstance = new AliConfig ("Folders","Alice data exchange");
69
70   return fInstance;
71 }
72
73 //____________________________________________________________________________
74 AliConfig::AliConfig():
75   fTopFolder(0),
76   fTasks(0),
77   fPDGFolder(0),
78   fGeneratorFolder(0),
79   fMCFolder(0),
80   fModuleFolder(0),
81   fDetectorFolder(0),
82   fDetectorTask(0)
83 {
84   //
85   // Default constructor, mainly to keep coding conventions
86   //
87   fInstance=0;
88     
89   Fatal("ctor",
90    "Constructor should not be called for a singleton\n");
91 }
92
93 //____________________________________________________________________________
94 AliConfig::AliConfig(const AliConfig& conf):
95   TNamed(conf),
96   fTopFolder(0),
97   fTasks(0),
98   fPDGFolder(0),
99   fGeneratorFolder(0),
100   fMCFolder(0),
101   fModuleFolder(0),
102   fDetectorFolder(0),
103   fDetectorTask(0)
104 {
105   //
106   // Copy constructor, mainly to keep coding conventions
107   //
108   fInstance=0;
109     
110   Fatal("copy ctor",
111    "Copy constructor should not be called for a singleton\n");
112 }
113
114 //____________________________________________________________________________
115 AliConfig::AliConfig(const char *name, const char *title): 
116   TNamed(name,title), 
117   fTopFolder(gROOT->GetRootFolder ()->AddFolder (name,title)),
118   fTasks(0),
119   fPDGFolder("Constants/DatabasePDG"),
120   fGeneratorFolder("RunMC/Configuration/Generators"),
121   fMCFolder("RunMC/Configuration/VirtualMC"),
122   fModuleFolder("Run/Configuration/Modules"),
123   fDetectorFolder(new char*[kFolders]),
124   fDetectorTask(new char*[kTasks])
125 {
126   //
127   // Constructor
128   //
129   fInstance=this;
130   
131   fDetectorFolder[0] = "Run/Conditions/Calibration" ;
132   fDetectorFolder[1] = "Run/Event/Data" ;
133   fDetectorFolder[2] = "Run/Event/RecData" ;
134   fDetectorFolder[3] = "RunMC/Event/Data/Hits" ;
135   fDetectorFolder[4] = "RunMC/Event/Data/SDigits" ;
136   fDetectorFolder[5] = "Run/Conditions/QA" ;  
137   fDetectorFolder[6] = "RunMC/Event/Data/TrackReferences" ;  
138   fDetectorFolder[7] = 0 ;  
139   fDetectorTask[0] = "Tasks/QA" ;  
140   fDetectorTask[1] = "Tasks/SDigitizer" ;  
141   fDetectorTask[2] = "Tasks/Digitizer" ;  
142   fDetectorTask[3] = "Tasks/Reconstructioner" ;  
143   fDetectorTask[4] = 0 ;  
144
145   fTopFolder->SetOwner() ; 
146   gROOT->GetListOfBrowsables ()->Add (fTopFolder, name);
147   
148   TFolder *subfolder;
149   
150   TFolder *constants =
151     fTopFolder->AddFolder ("Constants", "Detector constants");
152   
153   subfolder = 
154     constants->AddFolder ("DatabasePDG", "PDG database");
155   
156   TFolder *run = 
157     fTopFolder->AddFolder ("Run", "Run dependent folders");
158   
159   TFolder *conditions = 
160     run->AddFolder ("Conditions", "Run conditions");
161   
162   subfolder =
163     conditions->AddFolder ("Calibration","Detector calibration data");
164   
165   subfolder =
166     conditions->AddFolder ("Aligment", "Detector aligment");
167   
168   subfolder =
169     conditions->AddFolder ("QA", "Detector QA");
170   
171   TFolder *configuration =
172     run->AddFolder ("Configuration", "Run configuration");
173   
174   subfolder =
175     configuration->AddFolder ("Modules", "Detector objects");
176   
177   subfolder =
178     configuration->AddFolder ("Field", "Magnetic field maps");
179   
180   TFolder *event = 
181     run->AddFolder ("Event", "Event folders");
182   
183   subfolder = 
184     event->AddFolder ("Data", "Detector raw data");
185   
186   subfolder =
187     event->AddFolder ("RecData", "Detectors reconstucted data");
188   
189   TFolder *run_mc =
190     fTopFolder->AddFolder ("RunMC", "MonteCarlo run dependent folders");
191   
192   TFolder *configuration_mc =
193     run_mc->AddFolder ("Configuration","MonteCarlo run configuration");
194   
195   subfolder =
196     configuration_mc->AddFolder ("Generators","list of generator objects");
197   
198   subfolder =
199     configuration_mc->AddFolder ("VirtualMC", "the Virtual MC");
200   
201   TFolder *event_mc =
202     run_mc->AddFolder ("Event", "MonteCarlo event folders");
203   
204   subfolder =
205     event_mc->AddFolder ("Header", "MonteCarlo event header");
206   
207   //            subfolder =
208   //                event_mc->AddFolder ("Kinematics", "MonteCarlo generated particles");
209   
210   TFolder *data_mc =
211     event_mc->AddFolder ("Data", "MonteCarlo data");
212   
213   subfolder = 
214     data_mc->AddFolder ("Hits", "MonteCarlo Hits") ; 
215  
216  subfolder = 
217     data_mc->AddFolder ("SDigits", "MonteCarlo SDigits") ; 
218
219  subfolder = 
220     data_mc->AddFolder ("TrackReferences", "MonteCarlo track references") ; 
221
222
223   
224   // Add the tasks to //Folders
225   
226   TFolder * tasksfolder = fTopFolder->AddFolder("Tasks", "ALICE Tasks") ; 
227   
228   TTask * qa = new TTask("QA", "Alice QA tasks") ;
229   tasksfolder->Add(qa); 
230   
231   TTask * sd = new TTask("SDigitizer", "Alice SDigitizer") ;
232   tasksfolder->Add(sd); 
233
234   TTask * di = new TTask("Digitizer", "Alice Digitizer") ;
235   tasksfolder->Add(di); 
236
237   TTask * re = new TTask("Reconstructioner", "Alice Reconstructioner") ;
238   tasksfolder->Add(re); 
239
240 }
241
242 //____________________________________________________________________________
243 AliConfig::~AliConfig()
244
245   delete [] fDetectorFolder ;  
246   delete fDetectorTask ;  
247   delete fTopFolder ; 
248 }
249
250 //____________________________________________________________________________
251 void AliConfig::AddInFolder (const char *dir, TObject *obj)
252 {
253   TFolder *folder =
254     dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
255   if (folder)
256     folder->Add (static_cast<TObject *>(obj));
257 }
258
259 //____________________________________________________________________________
260 void    AliConfig::AddSubFolder(char * dir[], TObject *obj)
261 {
262   int iDir = 0;
263   
264   while (dir[iDir]) 
265     {
266       TFolder * folder = dynamic_cast<TFolder *>(fTopFolder->FindObject (dir[iDir++]));
267       if (folder) {
268         TFolder * subfolder = dynamic_cast<TFolder *>(folder->FindObject (obj->GetName()));
269         if (!subfolder)
270           subfolder = folder->AddFolder (obj->GetName(),obj->GetTitle());                          
271       }
272     }
273 }
274
275 //____________________________________________________________________________
276 void    AliConfig::AddSubTask(char * dir[], TObject *obj)
277 {
278   int iDir = 0;
279   
280   while (dir[iDir]) 
281     {
282       TTask * task = dynamic_cast<TTask *>(fTopFolder->FindObject (dir[iDir++]));
283       if (task) {
284         TTask * subtask = static_cast<TTask*>(task->GetListOfTasks()->FindObject (obj->GetName()));
285         if (!subtask) {
286           subtask = new TTask(obj->GetName(), obj->GetTitle()) ; 
287           task->Add(subtask);                      
288         }
289       }
290     }
291 }
292
293 //____________________________________________________________________________
294 TObject* AliConfig::FindInFolder (const char *dir, const char *name)
295 {
296   if(!name) return(fTopFolder->FindObject(name));
297   TFolder * folder = dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
298   if (!folder) return (NULL);
299   return(folder->FindObject(name));
300 }
301
302 //____________________________________________________________________________
303 void    AliConfig::Add (AliGenerator * obj)
304 {
305   AddInFolder(fGeneratorFolder, obj);
306 }
307
308 //____________________________________________________________________________
309 void    AliConfig::Add (AliMC * obj)
310 {
311   AddInFolder(fMCFolder, obj);
312 }
313
314 //____________________________________________________________________________
315 void    AliConfig::Add (TDatabasePDG * obj)
316 {
317   AddInFolder(fPDGFolder, obj);
318 }
319
320 //____________________________________________________________________________
321 void    AliConfig::Add (AliModule* obj)
322 {
323   AddInFolder(fModuleFolder, obj);
324 }
325
326 //____________________________________________________________________________
327 void    AliConfig::Add (AliDetector * obj)
328 {
329   AddSubFolder(fDetectorFolder, obj); 
330   AddSubTask(fDetectorTask, obj);
331 }
332
333
334 //____________________________________________________________________________
335 void    AliConfig::Add (char *list)
336 {
337   char *path;
338   
339   const char   *conf_path = gSystem->Getenv ("ALICE_CONFIG_PATH");
340   if  (conf_path) {
341     path = new char[strlen (conf_path)];
342     strcpy (path, conf_path);
343   } else {
344     const char   *alice = gSystem->Getenv ("ALICE_ROOT");
345     path = new char[strlen (alice) + 32];
346     
347     strcpy (path, ".:");
348     if (alice) {
349       strcat (path, alice);
350     }
351     strcat (path, "/macros/config");
352   }
353   
354   char   *token = strtok (path, ":");
355   
356   TList  *dirlist = new TList;
357   
358   while (token != NULL) 
359     {
360       dirlist->Add (new TObjString(token));
361       token = strtok (NULL, ":");
362     }
363   
364   token = strtok (list, " ");
365   
366   while (token != NULL)
367     {
368       cout << "Configuring " << token << ": ";
369       
370       TObject *obj;
371       TIter   next (dirlist);
372       TString found = "\0";
373       
374       while ((obj = next ()))
375         {
376           TString dir(obj->GetName());
377           TString tpath  = dir + "/" + token;
378           TString macro = tpath + ".C";
379           if (!gSystem->AccessPathName (macro.Data()))  {
380             gInterpreter->ExecuteMacro (macro.Data());                             
381             found = "(" + macro + ")";
382             if (macro.Contains("/")) {
383               TString dirname = gSystem->DirName(macro.Data());
384               TString macroConfigure = dirname + "/Configure.C";
385               if (!gSystem->AccessPathName (macroConfigure.Data()))     {
386                 gInterpreter->ExecuteMacro (macroConfigure.Data());                                 
387                 found += " => Configured";
388               }                       
389             }
390             break;
391           } else {
392             TString macroDefault = tpath + "/Default.C";
393             if (!gSystem->AccessPathName (macroDefault.Data())) {
394               gInterpreter->ExecuteMacro (macroDefault.Data());
395               found = "(" + macro + ")";
396               TString macroConfigure = tpath + "/Configure.C";
397               if (!gSystem->AccessPathName (macroConfigure.Data()))     {
398                 gInterpreter->ExecuteMacro (macroConfigure.Data());                                 
399                 found += " => Configured";
400               }
401               break;                                
402             }
403           }
404         }
405       
406       if (strlen(found.Data())) {
407         cout << found << " => OK" << endl;
408       } else {
409         cout << " => FAILED." << endl;
410         exit(1); 
411       }             
412       
413       token = strtok (NULL, " ");
414     }
415   
416   if (dirlist) delete dirlist;
417   
418 }
419
420