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