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