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