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 // 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
24 #include <Riostream.h>
25 #include <TDatabasePDG.h>
27 #include <TInterpreter.h>
30 #include <TVirtualMC.h>
32 #include "AliConfig.h"
33 #include "AliDetector.h"
34 #include "AliGenerator.h"
35 #include "TObjString.h"
41 AliConfig* AliConfig::fgInstance = 0;
43 //____________________________________________________________________________
44 AliConfig* AliConfig::Instance ()
47 // Instance method for singleton class
49 if(!fgInstance) fgInstance = new AliConfig ("Folders","Alice data exchange");
54 //____________________________________________________________________________
55 AliConfig::AliConfig():
66 // Default constructor, mainly to keep coding conventions
71 "Constructor should not be called for a singleton\n");
74 //____________________________________________________________________________
75 AliConfig::AliConfig(const AliConfig& conf):
87 // Copy constructor, mainly to keep coding conventions
92 "Copy constructor should not be called for a singleton\n");
95 //____________________________________________________________________________
96 AliConfig::AliConfig(const char *name, const char *title):
98 fTopFolder(gROOT->GetRootFolder ()->AddFolder (name,title)),
100 fPDGFolder("Constants/DatabasePDG"),
101 fGeneratorFolder("RunMC/Configuration/Generators"),
102 fMCFolder("RunMC/Configuration/VirtualMC"),
103 fModuleFolder("Run/Configuration/Modules"),
104 fDetectorFolder(new const char*[kFolders]),
105 fDetectorTask(new const char*[kTasks])
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" ;
118 fDetectorFolder[6] = "RunMC/Event/Data/TrackReferences" ;
119 fDetectorFolder[7] = 0 ;
120 fDetectorTask[0] = "Tasks/QA" ;
121 fDetectorTask[1] = "Tasks/SDigitizer" ;
122 fDetectorTask[2] = "Tasks/Digitizer" ;
123 fDetectorTask[3] = "Tasks/Reconstructioner" ;
124 fDetectorTask[4] = 0 ;
126 fTopFolder->SetOwner() ;
127 gROOT->GetListOfBrowsables ()->Add (fTopFolder, name);
132 fTopFolder->AddFolder ("Constants", "Detector constants");
135 constants->AddFolder ("DatabasePDG", "PDG database");
138 fTopFolder->AddFolder ("Run", "Run dependent folders");
140 TFolder *conditions =
141 run->AddFolder ("Conditions", "Run conditions");
144 conditions->AddFolder ("Calibration","Detector calibration data");
147 conditions->AddFolder ("Aligment", "Detector aligment");
150 conditions->AddFolder ("QA", "Detector QA");
152 TFolder *configuration =
153 run->AddFolder ("Configuration", "Run configuration");
156 configuration->AddFolder ("Modules", "Detector objects");
159 configuration->AddFolder ("Field", "Magnetic field maps");
162 run->AddFolder ("Event", "Event folders");
165 event->AddFolder ("Data", "Detector raw data");
168 event->AddFolder ("RecData", "Detectors reconstucted data");
171 fTopFolder->AddFolder ("RunMC", "MonteCarlo run dependent folders");
173 TFolder *configurationMC =
174 runMC->AddFolder ("Configuration","MonteCarlo run configuration");
177 configurationMC->AddFolder ("Generators","list of generator objects");
180 configurationMC->AddFolder ("VirtualMC", "the Virtual MC");
183 runMC->AddFolder ("Event", "MonteCarlo event folders");
186 eventMC->AddFolder ("Header", "MonteCarlo event header");
189 // eventMC->AddFolder ("Kinematics", "MonteCarlo generated particles");
192 eventMC->AddFolder ("Data", "MonteCarlo data");
195 dataMC->AddFolder ("Hits", "MonteCarlo Hits") ;
198 dataMC->AddFolder ("SDigits", "MonteCarlo SDigits") ;
201 dataMC->AddFolder ("TrackReferences", "MonteCarlo track references") ;
205 // Add the tasks to //Folders
207 TFolder * tasksfolder = fTopFolder->AddFolder("Tasks", "ALICE Tasks") ;
209 TTask * qa = new TTask("QA", "Alice QA tasks") ;
210 tasksfolder->Add(qa);
212 TTask * sd = new TTask("SDigitizer", "Alice SDigitizer") ;
213 tasksfolder->Add(sd);
215 TTask * di = new TTask("Digitizer", "Alice Digitizer") ;
216 tasksfolder->Add(di);
218 TTask * re = new TTask("Reconstructioner", "Alice Reconstructioner") ;
219 tasksfolder->Add(re);
223 //____________________________________________________________________________
224 AliConfig::~AliConfig()
227 delete [] fDetectorFolder ;
228 delete fDetectorTask ;
232 //____________________________________________________________________________
233 void AliConfig::AddInFolder (const char *dir, TObject *obj)
235 // Adds an object "obj" to a folder named "dir"
237 dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
239 folder->Add (static_cast<TObject *>(obj));
242 //____________________________________________________________________________
243 void AliConfig::AddSubFolder(const char * dir[], TObject *obj)
245 // Adds a subfolder taken from "obj" to all the folders from dir,
246 // which are found in the top folder
251 TFolder * folder = dynamic_cast<TFolder *>(fTopFolder->FindObject (dir[iDir++]));
253 TFolder * subfolder = dynamic_cast<TFolder *>(folder->FindObject (obj->GetName()));
255 subfolder = folder->AddFolder (obj->GetName(),obj->GetTitle());
260 //____________________________________________________________________________
261 void AliConfig::AddSubTask(const char * dir[], TObject *obj)
263 // Adds a subtask taken from "obj" to all the folders from dir,
264 // which are found in the top folder
269 TTask * task = dynamic_cast<TTask *>(fTopFolder->FindObject (dir[iDir++]));
271 TTask * subtask = static_cast<TTask*>(task->GetListOfTasks()->FindObject (obj->GetName()));
273 subtask = new TTask(obj->GetName(), obj->GetTitle()) ;
280 //____________________________________________________________________________
281 TObject* AliConfig::FindInFolder (const char *dir, const char *name)
283 // Searches for object with "name" in the top directory and in
284 // the directory "dir"
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));
291 //____________________________________________________________________________
292 void AliConfig::Add (AliGenerator * obj)
294 // Adds new AliGenerator to the generator's folder
295 AddInFolder(fGeneratorFolder, obj);
298 //____________________________________________________________________________
299 void AliConfig::Add (TVirtualMC * obj)
301 // Adds new object of type TVirtualMC to the MC folder
302 AddInFolder(fMCFolder, obj);
305 //____________________________________________________________________________
306 void AliConfig::Add (TDatabasePDG * obj)
308 // Adds new TDatabasePDG to the PDG folder
309 AddInFolder(fPDGFolder, obj);
312 //____________________________________________________________________________
313 void AliConfig::Add (AliModule* obj)
315 // Adds new module to the folder of modules
316 AddInFolder(fModuleFolder, obj);
319 //____________________________________________________________________________
320 void AliConfig::Add (AliDetector * obj)
322 // Adds new detector to the detctor's folder as well as to
323 // the detector's task
324 AddSubFolder(fDetectorFolder, obj);
325 AddSubTask(fDetectorTask, obj);
329 //____________________________________________________________________________
330 void AliConfig::Add (char *list)
332 // Finds in the list of directories all macros named Configure.C
333 // and Default.C and uses them to configure the setup
336 const char *confPath = gSystem->Getenv ("ALICE_CONFIG_PATH");
338 path = new char[strlen (confPath)];
339 strcpy (path, confPath);
341 const char *alice = gSystem->Getenv ("ALICE_ROOT");
342 path = new char[strlen (alice) + 32];
346 strcat (path, alice);
348 strcat (path, "/macros/config");
351 char *token = strtok (path, ":");
353 TList *dirlist = new TList;
355 while (token != NULL)
357 dirlist->Add (new TObjString(token));
358 token = strtok (NULL, ":");
361 token = strtok (list, " ");
363 while (token != NULL)
365 cout << "Configuring " << token << ": ";
368 TIter next (dirlist);
369 TString found = "\0";
371 while ((obj = next ()))
373 TString dir(obj->GetName());
374 TString tpath = dir + "/" + token;
375 TString macro = tpath + ".C";
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";
389 TString macroDefault = tpath + "/Default.C";
390 if (!gSystem->AccessPathName (macroDefault.Data())) {
391 gInterpreter->ExecuteMacro (macroDefault.Data());
392 found = "(" + macro + ")";
393 TString macroConfigure = tpath + "/Configure.C";
394 if (!gSystem->AccessPathName (macroConfigure.Data())) {
395 gInterpreter->ExecuteMacro (macroConfigure.Data());
396 found += " => Configured";
403 if (strlen(found.Data())) {
404 cout << found << " => OK" << endl;
406 cout << " => FAILED." << endl;
410 token = strtok (NULL, " ");
413 if (dirlist) delete dirlist;