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