1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include <Riostream.h>
19 #include <TDatabasePDG.h>
21 #include <TInterpreter.h>
24 #include <TVirtualMC.h>
26 #include "AliConfig.h"
27 #include "AliDetector.h"
28 #include "AliGenerator.h"
29 #include "TObjString.h"
35 AliConfig* AliConfig::fgInstance = 0;
37 //____________________________________________________________________________
38 AliConfig* AliConfig::Instance ()
41 // Instance method for singleton class
43 if(!fgInstance) fgInstance = new AliConfig ("Folders","Alice data exchange");
48 //____________________________________________________________________________
49 AliConfig::AliConfig():
60 // Default constructor, mainly to keep coding conventions
65 "Constructor should not be called for a singleton\n");
68 //____________________________________________________________________________
69 AliConfig::AliConfig(const AliConfig& conf):
81 // Copy constructor, mainly to keep coding conventions
86 "Copy constructor should not be called for a singleton\n");
89 //____________________________________________________________________________
90 AliConfig::AliConfig(const char *name, const char *title):
92 fTopFolder(gROOT->GetRootFolder ()->AddFolder (name,title)),
94 fPDGFolder("Constants/DatabasePDG"),
95 fGeneratorFolder("RunMC/Configuration/Generators"),
96 fMCFolder("RunMC/Configuration/VirtualMC"),
97 fModuleFolder("Run/Configuration/Modules"),
98 fDetectorFolder(new const char*[kFolders]),
99 fDetectorTask(new const char*[kTasks])
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" ;
112 fDetectorFolder[6] = "RunMC/Event/Data/TrackReferences" ;
113 fDetectorFolder[7] = 0 ;
114 fDetectorTask[0] = "Tasks/QA" ;
115 fDetectorTask[1] = "Tasks/SDigitizer" ;
116 fDetectorTask[2] = "Tasks/Digitizer" ;
117 fDetectorTask[3] = "Tasks/Reconstructioner" ;
118 fDetectorTask[4] = 0 ;
120 fTopFolder->SetOwner() ;
121 gROOT->GetListOfBrowsables ()->Add (fTopFolder, name);
126 fTopFolder->AddFolder ("Constants", "Detector constants");
129 constants->AddFolder ("DatabasePDG", "PDG database");
132 fTopFolder->AddFolder ("Run", "Run dependent folders");
134 TFolder *conditions =
135 run->AddFolder ("Conditions", "Run conditions");
138 conditions->AddFolder ("Calibration","Detector calibration data");
141 conditions->AddFolder ("Aligment", "Detector aligment");
144 conditions->AddFolder ("QA", "Detector QA");
146 TFolder *configuration =
147 run->AddFolder ("Configuration", "Run configuration");
150 configuration->AddFolder ("Modules", "Detector objects");
153 configuration->AddFolder ("Field", "Magnetic field maps");
156 run->AddFolder ("Event", "Event folders");
159 event->AddFolder ("Data", "Detector raw data");
162 event->AddFolder ("RecData", "Detectors reconstucted data");
165 fTopFolder->AddFolder ("RunMC", "MonteCarlo run dependent folders");
167 TFolder *configurationMC =
168 runMC->AddFolder ("Configuration","MonteCarlo run configuration");
171 configurationMC->AddFolder ("Generators","list of generator objects");
174 configurationMC->AddFolder ("VirtualMC", "the Virtual MC");
177 runMC->AddFolder ("Event", "MonteCarlo event folders");
180 eventMC->AddFolder ("Header", "MonteCarlo event header");
183 // eventMC->AddFolder ("Kinematics", "MonteCarlo generated particles");
186 eventMC->AddFolder ("Data", "MonteCarlo data");
189 dataMC->AddFolder ("Hits", "MonteCarlo Hits") ;
192 dataMC->AddFolder ("SDigits", "MonteCarlo SDigits") ;
195 dataMC->AddFolder ("TrackReferences", "MonteCarlo track references") ;
199 // Add the tasks to //Folders
201 TFolder * tasksfolder = fTopFolder->AddFolder("Tasks", "ALICE Tasks") ;
203 TTask * qa = new TTask("QA", "Alice QA tasks") ;
204 tasksfolder->Add(qa);
206 TTask * sd = new TTask("SDigitizer", "Alice SDigitizer") ;
207 tasksfolder->Add(sd);
209 TTask * di = new TTask("Digitizer", "Alice Digitizer") ;
210 tasksfolder->Add(di);
212 TTask * re = new TTask("Reconstructioner", "Alice Reconstructioner") ;
213 tasksfolder->Add(re);
217 //____________________________________________________________________________
218 AliConfig::~AliConfig()
220 delete [] fDetectorFolder ;
221 delete fDetectorTask ;
225 //____________________________________________________________________________
226 void AliConfig::AddInFolder (const char *dir, TObject *obj)
229 dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
231 folder->Add (static_cast<TObject *>(obj));
234 //____________________________________________________________________________
235 void AliConfig::AddSubFolder(const char * dir[], TObject *obj)
241 TFolder * folder = dynamic_cast<TFolder *>(fTopFolder->FindObject (dir[iDir++]));
243 TFolder * subfolder = dynamic_cast<TFolder *>(folder->FindObject (obj->GetName()));
245 subfolder = folder->AddFolder (obj->GetName(),obj->GetTitle());
250 //____________________________________________________________________________
251 void AliConfig::AddSubTask(const char * dir[], TObject *obj)
257 TTask * task = dynamic_cast<TTask *>(fTopFolder->FindObject (dir[iDir++]));
259 TTask * subtask = static_cast<TTask*>(task->GetListOfTasks()->FindObject (obj->GetName()));
261 subtask = new TTask(obj->GetName(), obj->GetTitle()) ;
268 //____________________________________________________________________________
269 TObject* AliConfig::FindInFolder (const char *dir, const char *name)
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));
277 //____________________________________________________________________________
278 void AliConfig::Add (AliGenerator * obj)
280 AddInFolder(fGeneratorFolder, obj);
283 //____________________________________________________________________________
284 void AliConfig::Add (TVirtualMC * obj)
286 AddInFolder(fMCFolder, obj);
289 //____________________________________________________________________________
290 void AliConfig::Add (TDatabasePDG * obj)
292 AddInFolder(fPDGFolder, obj);
295 //____________________________________________________________________________
296 void AliConfig::Add (AliModule* obj)
298 AddInFolder(fModuleFolder, obj);
301 //____________________________________________________________________________
302 void AliConfig::Add (AliDetector * obj)
304 AddSubFolder(fDetectorFolder, obj);
305 AddSubTask(fDetectorTask, obj);
309 //____________________________________________________________________________
310 void AliConfig::Add (char *list)
314 const char *confPath = gSystem->Getenv ("ALICE_CONFIG_PATH");
316 path = new char[strlen (confPath)];
317 strcpy (path, confPath);
319 const char *alice = gSystem->Getenv ("ALICE_ROOT");
320 path = new char[strlen (alice) + 32];
324 strcat (path, alice);
326 strcat (path, "/macros/config");
329 char *token = strtok (path, ":");
331 TList *dirlist = new TList;
333 while (token != NULL)
335 dirlist->Add (new TObjString(token));
336 token = strtok (NULL, ":");
339 token = strtok (list, " ");
341 while (token != NULL)
343 cout << "Configuring " << token << ": ";
346 TIter next (dirlist);
347 TString found = "\0";
349 while ((obj = next ()))
351 TString dir(obj->GetName());
352 TString tpath = dir + "/" + token;
353 TString macro = tpath + ".C";
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";
367 TString macroDefault = tpath + "/Default.C";
368 if (!gSystem->AccessPathName (macroDefault.Data())) {
369 gInterpreter->ExecuteMacro (macroDefault.Data());
370 found = "(" + macro + ")";
371 TString macroConfigure = tpath + "/Configure.C";
372 if (!gSystem->AccessPathName (macroConfigure.Data())) {
373 gInterpreter->ExecuteMacro (macroConfigure.Data());
374 found += " => Configured";
381 if (strlen(found.Data())) {
382 cout << found << " => OK" << endl;
384 cout << " => FAILED." << endl;
388 token = strtok (NULL, " ");
391 if (dirlist) delete dirlist;