coding convention crrections
[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
acd84897 16/* $Id$ */
9e1a0ddb 17
b16a1b1e 18#include <Riostream.h>
19#include <TDatabasePDG.h>
20#include <TFolder.h>
21#include <TInterpreter.h>
22#include <TROOT.h>
23#include <TSystem.h>
98490ea9 24#include <TVirtualMC.h>
b16a1b1e 25
9e1a0ddb 26#include "AliConfig.h"
27#include "AliDetector.h"
b16a1b1e 28#include "AliGenerator.h"
7e90ff59 29#include "TObjString.h"
30#include "TString.h"
31#include "TTask.h"
9e1a0ddb 32
33ClassImp(AliConfig)
34
116cbefd 35AliConfig* AliConfig::fgInstance = 0;
9e1a0ddb 36
7e90ff59 37//____________________________________________________________________________
9e1a0ddb 38AliConfig* AliConfig::Instance ()
39{
40 //
41 // Instance method for singleton class
42 //
116cbefd 43 if(!fgInstance) fgInstance = new AliConfig ("Folders","Alice data exchange");
b16a1b1e 44
116cbefd 45 return fgInstance;
b16a1b1e 46}
47
48//____________________________________________________________________________
6644b9ca 49AliConfig::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)
b16a1b1e 58{
59 //
60 // Default constructor, mainly to keep coding conventions
61 //
116cbefd 62 fgInstance=0;
b16a1b1e 63
64 Fatal("ctor",
65 "Constructor should not be called for a singleton\n");
9e1a0ddb 66}
67
b16a1b1e 68//____________________________________________________________________________
e2afb3b6 69AliConfig::AliConfig(const AliConfig& conf):
70 TNamed(conf),
6644b9ca 71 fTopFolder(0),
72 fTasks(0),
73 fPDGFolder(0),
74 fGeneratorFolder(0),
75 fMCFolder(0),
76 fModuleFolder(0),
77 fDetectorFolder(0),
78 fDetectorTask(0)
b16a1b1e 79{
80 //
81 // Copy constructor, mainly to keep coding conventions
82 //
116cbefd 83 fgInstance=0;
b16a1b1e 84
85 Fatal("copy ctor",
86 "Copy constructor should not be called for a singleton\n");
87}
88
89//____________________________________________________________________________
90AliConfig::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"),
ef92dd70 98 fDetectorFolder(new const char*[kFolders]),
99 fDetectorTask(new const char*[kTasks])
9e1a0ddb 100{
101 //
7e90ff59 102 // Constructor
9e1a0ddb 103 //
116cbefd 104 fgInstance=this;
b16a1b1e 105
7e90ff59 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" ;
536b07c2 112 fDetectorFolder[6] = "RunMC/Event/Data/TrackReferences" ;
113 fDetectorFolder[7] = 0 ;
7e90ff59 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
7e90ff59 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
116cbefd 164 TFolder *runMC =
7e90ff59 165 fTopFolder->AddFolder ("RunMC", "MonteCarlo run dependent folders");
166
116cbefd 167 TFolder *configurationMC =
168 runMC->AddFolder ("Configuration","MonteCarlo run configuration");
7e90ff59 169
170 subfolder =
116cbefd 171 configurationMC->AddFolder ("Generators","list of generator objects");
7e90ff59 172
173 subfolder =
116cbefd 174 configurationMC->AddFolder ("VirtualMC", "the Virtual MC");
7e90ff59 175
116cbefd 176 TFolder *eventMC =
177 runMC->AddFolder ("Event", "MonteCarlo event folders");
7e90ff59 178
179 subfolder =
116cbefd 180 eventMC->AddFolder ("Header", "MonteCarlo event header");
7e90ff59 181
182 // subfolder =
116cbefd 183 // eventMC->AddFolder ("Kinematics", "MonteCarlo generated particles");
7e90ff59 184
116cbefd 185 TFolder *dataMC =
186 eventMC->AddFolder ("Data", "MonteCarlo data");
7e90ff59 187
188 subfolder =
116cbefd 189 dataMC->AddFolder ("Hits", "MonteCarlo Hits") ;
7e90ff59 190
191 subfolder =
116cbefd 192 dataMC->AddFolder ("SDigits", "MonteCarlo SDigits") ;
7e90ff59 193
536b07c2 194 subfolder =
116cbefd 195 dataMC->AddFolder ("TrackReferences", "MonteCarlo track references") ;
536b07c2 196
7e90ff59 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);
9e1a0ddb 214
215}
216
7e90ff59 217//____________________________________________________________________________
9e1a0ddb 218AliConfig::~AliConfig()
219{
536b07c2 220 delete [] fDetectorFolder ;
7e90ff59 221 delete fDetectorTask ;
222 delete fTopFolder ;
9e1a0ddb 223}
224
7e90ff59 225//____________________________________________________________________________
e2afb3b6 226void AliConfig::AddInFolder (const char *dir, TObject *obj)
9e1a0ddb 227{
7e90ff59 228 TFolder *folder =
229 dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
230 if (folder)
231 folder->Add (static_cast<TObject *>(obj));
9e1a0ddb 232}
233
7e90ff59 234//____________________________________________________________________________
ef92dd70 235void AliConfig::AddSubFolder(const char * dir[], TObject *obj)
9e1a0ddb 236{
7e90ff59 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}
9e1a0ddb 249
7e90ff59 250//____________________________________________________________________________
ef92dd70 251void AliConfig::AddSubTask(const char * dir[], TObject *obj)
7e90ff59 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 }
9e1a0ddb 266}
267
7e90ff59 268//____________________________________________________________________________
e2afb3b6 269TObject* AliConfig::FindInFolder (const char *dir, const char *name)
9e1a0ddb 270{
7e90ff59 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));
9e1a0ddb 275}
276
7e90ff59 277//____________________________________________________________________________
9e1a0ddb 278void AliConfig::Add (AliGenerator * obj)
279{
7e90ff59 280 AddInFolder(fGeneratorFolder, obj);
9e1a0ddb 281}
282
7e90ff59 283//____________________________________________________________________________
98490ea9 284void AliConfig::Add (TVirtualMC * obj)
9e1a0ddb 285{
7e90ff59 286 AddInFolder(fMCFolder, obj);
9e1a0ddb 287}
288
7e90ff59 289//____________________________________________________________________________
9e1a0ddb 290void AliConfig::Add (TDatabasePDG * obj)
291{
7e90ff59 292 AddInFolder(fPDGFolder, obj);
9e1a0ddb 293}
294
7e90ff59 295//____________________________________________________________________________
9e1a0ddb 296void AliConfig::Add (AliModule* obj)
297{
7e90ff59 298 AddInFolder(fModuleFolder, obj);
9e1a0ddb 299}
300
7e90ff59 301//____________________________________________________________________________
9e1a0ddb 302void AliConfig::Add (AliDetector * obj)
303{
7e90ff59 304 AddSubFolder(fDetectorFolder, obj);
305 AddSubTask(fDetectorTask, obj);
9e1a0ddb 306}
307
9e1a0ddb 308
7e90ff59 309//____________________________________________________________________________
310void AliConfig::Add (char *list)
311{
312 char *path;
313
116cbefd 314 const char *confPath = gSystem->Getenv ("ALICE_CONFIG_PATH");
315 if (confPath) {
316 path = new char[strlen (confPath)];
317 strcpy (path, confPath);
7e90ff59 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());
e2afb3b6 352 TString tpath = dir + "/" + token;
353 TString macro = tpath + ".C";
7e90ff59 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 {
e2afb3b6 367 TString macroDefault = tpath + "/Default.C";
7e90ff59 368 if (!gSystem->AccessPathName (macroDefault.Data())) {
369 gInterpreter->ExecuteMacro (macroDefault.Data());
370 found = "(" + macro + ")";
e2afb3b6 371 TString macroConfigure = tpath + "/Configure.C";
7e90ff59 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
9e1a0ddb 393}
394
395