]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliConfig.cxx
Pycell configurable.
[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
5d8718b8 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
b16a1b1e 24#include <Riostream.h>
25#include <TDatabasePDG.h>
26#include <TFolder.h>
27#include <TInterpreter.h>
28#include <TROOT.h>
29#include <TSystem.h>
98490ea9 30#include <TVirtualMC.h>
b16a1b1e 31
9e1a0ddb 32#include "AliConfig.h"
33#include "AliDetector.h"
b16a1b1e 34#include "AliGenerator.h"
7e90ff59 35#include "TObjString.h"
36#include "TString.h"
37#include "TTask.h"
9e1a0ddb 38
39ClassImp(AliConfig)
40
116cbefd 41AliConfig* AliConfig::fgInstance = 0;
9e1a0ddb 42
7e90ff59 43//____________________________________________________________________________
9e1a0ddb 44AliConfig* AliConfig::Instance ()
45{
46 //
47 // Instance method for singleton class
48 //
116cbefd 49 if(!fgInstance) fgInstance = new AliConfig ("Folders","Alice data exchange");
b16a1b1e 50
116cbefd 51 return fgInstance;
b16a1b1e 52}
53
54//____________________________________________________________________________
6644b9ca 55AliConfig::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)
b16a1b1e 64{
65 //
66 // Default constructor, mainly to keep coding conventions
67 //
116cbefd 68 fgInstance=0;
b16a1b1e 69
70 Fatal("ctor",
71 "Constructor should not be called for a singleton\n");
9e1a0ddb 72}
73
b16a1b1e 74//____________________________________________________________________________
e2afb3b6 75AliConfig::AliConfig(const AliConfig& conf):
76 TNamed(conf),
6644b9ca 77 fTopFolder(0),
78 fTasks(0),
79 fPDGFolder(0),
80 fGeneratorFolder(0),
81 fMCFolder(0),
82 fModuleFolder(0),
83 fDetectorFolder(0),
84 fDetectorTask(0)
b16a1b1e 85{
86 //
87 // Copy constructor, mainly to keep coding conventions
88 //
116cbefd 89 fgInstance=0;
b16a1b1e 90
91 Fatal("copy ctor",
92 "Copy constructor should not be called for a singleton\n");
93}
94
95//____________________________________________________________________________
96AliConfig::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"),
ef92dd70 104 fDetectorFolder(new const char*[kFolders]),
105 fDetectorTask(new const char*[kTasks])
9e1a0ddb 106{
107 //
7e90ff59 108 // Constructor
9e1a0ddb 109 //
116cbefd 110 fgInstance=this;
b16a1b1e 111
7e90ff59 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" ;
536b07c2 118 fDetectorFolder[6] = "RunMC/Event/Data/TrackReferences" ;
119 fDetectorFolder[7] = 0 ;
7e90ff59 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
7e90ff59 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
116cbefd 170 TFolder *runMC =
7e90ff59 171 fTopFolder->AddFolder ("RunMC", "MonteCarlo run dependent folders");
172
116cbefd 173 TFolder *configurationMC =
174 runMC->AddFolder ("Configuration","MonteCarlo run configuration");
7e90ff59 175
176 subfolder =
116cbefd 177 configurationMC->AddFolder ("Generators","list of generator objects");
7e90ff59 178
179 subfolder =
116cbefd 180 configurationMC->AddFolder ("VirtualMC", "the Virtual MC");
7e90ff59 181
116cbefd 182 TFolder *eventMC =
183 runMC->AddFolder ("Event", "MonteCarlo event folders");
7e90ff59 184
185 subfolder =
116cbefd 186 eventMC->AddFolder ("Header", "MonteCarlo event header");
7e90ff59 187
188 // subfolder =
116cbefd 189 // eventMC->AddFolder ("Kinematics", "MonteCarlo generated particles");
7e90ff59 190
116cbefd 191 TFolder *dataMC =
192 eventMC->AddFolder ("Data", "MonteCarlo data");
7e90ff59 193
194 subfolder =
116cbefd 195 dataMC->AddFolder ("Hits", "MonteCarlo Hits") ;
7e90ff59 196
197 subfolder =
116cbefd 198 dataMC->AddFolder ("SDigits", "MonteCarlo SDigits") ;
7e90ff59 199
536b07c2 200 subfolder =
116cbefd 201 dataMC->AddFolder ("TrackReferences", "MonteCarlo track references") ;
536b07c2 202
7e90ff59 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);
9e1a0ddb 220
221}
222
7e90ff59 223//____________________________________________________________________________
9e1a0ddb 224AliConfig::~AliConfig()
225{
5d8718b8 226 // destructor
536b07c2 227 delete [] fDetectorFolder ;
7e90ff59 228 delete fDetectorTask ;
229 delete fTopFolder ;
9e1a0ddb 230}
231
7e90ff59 232//____________________________________________________________________________
e2afb3b6 233void AliConfig::AddInFolder (const char *dir, TObject *obj)
9e1a0ddb 234{
5d8718b8 235 // Adds an object "obj" to a folder named "dir"
7e90ff59 236 TFolder *folder =
237 dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
238 if (folder)
239 folder->Add (static_cast<TObject *>(obj));
9e1a0ddb 240}
241
7e90ff59 242//____________________________________________________________________________
ef92dd70 243void AliConfig::AddSubFolder(const char * dir[], TObject *obj)
9e1a0ddb 244{
5d8718b8 245 // Adds a subfolder taken from "obj" to all the folders from dir,
246 // which are found in the top folder
7e90ff59 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}
9e1a0ddb 259
7e90ff59 260//____________________________________________________________________________
ef92dd70 261void AliConfig::AddSubTask(const char * dir[], TObject *obj)
7e90ff59 262{
5d8718b8 263 // Adds a subtask taken from "obj" to all the folders from dir,
264 // which are found in the top folder
7e90ff59 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 }
9e1a0ddb 278}
279
7e90ff59 280//____________________________________________________________________________
e2afb3b6 281TObject* AliConfig::FindInFolder (const char *dir, const char *name)
9e1a0ddb 282{
5d8718b8 283 // Searches for object with "name" in the top directory and in
284 // the directory "dir"
7e90ff59 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));
9e1a0ddb 289}
290
7e90ff59 291//____________________________________________________________________________
9e1a0ddb 292void AliConfig::Add (AliGenerator * obj)
293{
5d8718b8 294 // Adds new AliGenerator to the generator's folder
7e90ff59 295 AddInFolder(fGeneratorFolder, obj);
9e1a0ddb 296}
297
7e90ff59 298//____________________________________________________________________________
98490ea9 299void AliConfig::Add (TVirtualMC * obj)
9e1a0ddb 300{
5d8718b8 301 // Adds new object of type TVirtualMC to the MC folder
7e90ff59 302 AddInFolder(fMCFolder, obj);
9e1a0ddb 303}
304
7e90ff59 305//____________________________________________________________________________
9e1a0ddb 306void AliConfig::Add (TDatabasePDG * obj)
307{
5d8718b8 308 // Adds new TDatabasePDG to the PDG folder
7e90ff59 309 AddInFolder(fPDGFolder, obj);
9e1a0ddb 310}
311
7e90ff59 312//____________________________________________________________________________
9e1a0ddb 313void AliConfig::Add (AliModule* obj)
314{
5d8718b8 315 // Adds new module to the folder of modules
7e90ff59 316 AddInFolder(fModuleFolder, obj);
9e1a0ddb 317}
318
7e90ff59 319//____________________________________________________________________________
9e1a0ddb 320void AliConfig::Add (AliDetector * obj)
321{
5d8718b8 322 // Adds new detector to the detctor's folder as well as to
323 // the detector's task
7e90ff59 324 AddSubFolder(fDetectorFolder, obj);
325 AddSubTask(fDetectorTask, obj);
9e1a0ddb 326}
327
9e1a0ddb 328
7e90ff59 329//____________________________________________________________________________
330void AliConfig::Add (char *list)
331{
5d8718b8 332 // Finds in the list of directories all macros named Configure.C
333 // and Default.C and uses them to configure the setup
7e90ff59 334 char *path;
335
116cbefd 336 const char *confPath = gSystem->Getenv ("ALICE_CONFIG_PATH");
337 if (confPath) {
338 path = new char[strlen (confPath)];
339 strcpy (path, confPath);
7e90ff59 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());
e2afb3b6 374 TString tpath = dir + "/" + token;
375 TString macro = tpath + ".C";
7e90ff59 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 {
e2afb3b6 389 TString macroDefault = tpath + "/Default.C";
7e90ff59 390 if (!gSystem->AccessPathName (macroDefault.Data())) {
391 gInterpreter->ExecuteMacro (macroDefault.Data());
392 found = "(" + macro + ")";
e2afb3b6 393 TString macroConfigure = tpath + "/Configure.C";
7e90ff59 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
9e1a0ddb 415}
416
417