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 **************************************************************************/
22 #include "AliConfig.h"
23 #include "AliDetector.h"
30 static char* gPDGFolder=
31 "Constants/DatabasePDG";
33 static char* gGeneratorFolder =
34 "RunMC/Configuration/Generators";
36 static char* gMCFolder =
37 "RunMC/Configuration/VirtualMC";
39 static char* gModuleFolder =
40 "Run/Configuration/Modules";
42 static char* gDetectorFolder[] = {
43 "Run/Conditions/Calibration",
46 "RunMC/Event/Data",0};
48 AliConfig* AliConfig::fInstance = 0;
50 AliConfig* AliConfig::Instance ()
53 // Instance method for singleton class
56 fInstance = new AliConfig ();
62 AliConfig::AliConfig(const char *name, const char *title)
65 // Default constructor
70 fTopFolder = gROOT->GetRootFolder ()->AddFolder (name,title);
72 gROOT->GetListOfBrowsables ()->Add (fTopFolder, name);
77 fTopFolder->AddFolder ("Constants", "Detector constants");
80 constants->AddFolder ("DatabasePDG", "PDG database");
83 fTopFolder->AddFolder ("Run", "Run dependent folders");
86 run->AddFolder ("Conditions", "Run conditions");
89 conditions->AddFolder ("Calibration","Detector calibration data");
92 conditions->AddFolder ("Aligment", "Detector aligment");
94 TFolder *configuration =
95 run->AddFolder ("Configuration", "Run configuration");
98 configuration->AddFolder ("Modules", "Detector objects");
101 configuration->AddFolder ("Field", "Magnetic field maps");
104 run->AddFolder ("Event", "Event folders");
107 event->AddFolder ("Data", "Detector raw data");
110 event->AddFolder ("RecData", "Detectors reconstucted data");
113 fTopFolder->AddFolder ("RunMC", "MonteCarlo run dependent folders");
115 TFolder *configuration_mc =
116 run_mc->AddFolder ("Configuration","MonteCarlo run configuration");
119 configuration_mc->AddFolder ("Generators","list of generator objects");
122 configuration_mc->AddFolder ("VirtualMC", "the Virtual MC");
125 run_mc->AddFolder ("Event", "MonteCarlo event folders");
128 event_mc->AddFolder ("Header", "MonteCarlo event header");
131 // event_mc->AddFolder ("Kinematics", "MonteCarlo generated particles");
134 event_mc->AddFolder ("Data", "MonteCarlo data");
138 AliConfig::~AliConfig()
142 void AliConfig::AddInFolder (char *dir, TObject *obj)
145 (TFolder *) fTopFolder->FindObject (dir);
147 folder->Add ((TObject *)obj);
150 void AliConfig::AddSubFolder(char *dir[], TObject *obj)
156 TFolder * folder = (TFolder *) fTopFolder->FindObject (dir[iDir++]);
158 TFolder * subfolder = (TFolder *) folder->FindObject (obj->GetName());
160 subfolder = folder->AddFolder (obj->GetName(),obj->GetTitle());
166 TObject* AliConfig::FindInFolder (char *dir, const char *name)
168 if(!name) return(fTopFolder->FindObject(name));
169 TFolder * folder = (TFolder *) fTopFolder->FindObject (dir);
170 if (!folder) return (NULL);
171 return(folder->FindObject(name));
174 void AliConfig::Add (AliGenerator * obj)
176 AddInFolder(gGeneratorFolder, (TObject *) obj);
179 void AliConfig::Add (AliMC * obj)
181 AddInFolder(gMCFolder, (TObject *) obj);
184 void AliConfig::Add (TDatabasePDG * obj)
186 AddInFolder(gPDGFolder, (TObject *) obj);
189 void AliConfig::Add (AliModule* obj)
191 AddInFolder(gModuleFolder, (TObject *) obj);
194 void AliConfig::Add (AliDetector * obj)
196 AddSubFolder(gDetectorFolder, (TObject *) obj);
200 void AliConfig::Add (const char *list)
204 const char *conf_path = gSystem->Getenv ("ALICE_CONFIG_PATH");
206 path = new char[strlen (conf_path)];
207 strcpy (path, conf_path);
209 const char *alice = gSystem->Getenv ("ALICE_ROOT");
210 path = new char[strlen (alice) + 32];
214 strcat (path, alice);
216 strcat (path, "/macros/config");
219 char *token = strtok (path, ":");
221 TList *dirlist = new TList;
223 while (token != NULL)
225 dirlist->Add ((TObject *) token);
226 token = strtok (NULL, ":");
229 token = strtok ((char *)list, " ");
231 while (token != NULL)
233 cout << "Configuring " << token << ": ";
236 TIter next (dirlist);
237 TString found = "\0";
239 while ((obj = next ()))
241 TString dir = (char *) obj;
242 TString path = dir + "/" + token;
243 TString macro = path + ".C";
244 if (!gSystem->AccessPathName (macro.Data())) {
245 gInterpreter->ExecuteMacro (macro.Data());
246 found = "(" + macro + ")";
247 if (macro.Contains("/")) {
248 TString dirname = gSystem->DirName(macro.Data());
249 TString macroConfigure = dirname + "/Configure.C";
250 if (!gSystem->AccessPathName (macroConfigure.Data())) {
251 gInterpreter->ExecuteMacro (macroConfigure.Data());
252 found += " => Configured";
257 TString macroDefault = path + "/Default.C";
258 if (!gSystem->AccessPathName (macroDefault.Data())) {
259 gInterpreter->ExecuteMacro (macroDefault.Data());
260 found = "(" + macro + ")";
261 TString macroConfigure = path + "/Configure.C";
262 if (!gSystem->AccessPathName (macroConfigure.Data())) {
263 gInterpreter->ExecuteMacro (macroConfigure.Data());
264 found += " => Configured";
271 if (strlen(found.Data())) {
272 cout << found << " => OK" << endl;
274 cout << " => FAILED." << endl;
278 token = strtok (NULL, " ");
281 if (dirlist) delete dirlist;