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