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