]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliConfig.cxx
New files for folders and Stack
[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$
18*/
19
20#include "TString.h"
21
22#include "AliConfig.h"
23#include "AliDetector.h"
24
25#include <iostream.h>
26
27ClassImp(AliConfig)
28
29
30static char* gPDGFolder=
31 "Constants/DatabasePDG";
32
33static char* gGeneratorFolder =
34 "RunMC/Configuration/Generators";
35
36static char* gMCFolder =
37 "RunMC/Configuration/VirtualMC";
38
39static char* gModuleFolder =
40 "Run/Configuration/Modules";
41
42static char* gDetectorFolder[] = {
43 "Run/Conditions/Calibration",
44 "Run/Event/Data",
45 "Run/Event/RecData",
46 "RunMC/Event/Data",0};
47
48AliConfig* AliConfig::fInstance = 0;
49
50AliConfig* AliConfig::Instance ()
51{
52 //
53 // Instance method for singleton class
54 //
55 if(fInstance == 0) {
56 fInstance = new AliConfig ();
57 }
58 return fInstance;
59}
60
61
62AliConfig::AliConfig(const char *name, const char *title)
63{
64 //
65 // Default constructor
66 //
67 //
68 fInstance=this;
69
70 fTopFolder = gROOT->GetRootFolder ()->AddFolder (name,title);
71
72 gROOT->GetListOfBrowsables ()->Add (fTopFolder, name);
73
74 TFolder *subfolder;
75
76 TFolder *constants =
77 fTopFolder->AddFolder ("Constants", "Detector constants");
78
79 subfolder =
80 constants->AddFolder ("DatabasePDG", "PDG database");
81
82 TFolder *run =
83 fTopFolder->AddFolder ("Run", "Run dependent folders");
84
85 TFolder *conditions =
86 run->AddFolder ("Conditions", "Run conditions");
87
88 subfolder =
89 conditions->AddFolder ("Calibration","Detector calibration data");
90
91 subfolder =
92 conditions->AddFolder ("Aligment", "Detector aligment");
93
94 TFolder *configuration =
95 run->AddFolder ("Configuration", "Run configuration");
96
97 subfolder =
98 configuration->AddFolder ("Modules", "Detector objects");
99
100 subfolder =
101 configuration->AddFolder ("Field", "Magnetic field maps");
102
103 TFolder *event =
104 run->AddFolder ("Event", "Event folders");
105
106 subfolder =
107 event->AddFolder ("Data", "Detector raw data");
108
109 subfolder =
110 event->AddFolder ("RecData", "Detectors reconstucted data");
111
112 TFolder *run_mc =
113 fTopFolder->AddFolder ("RunMC", "MonteCarlo run dependent folders");
114
115 TFolder *configuration_mc =
116 run_mc->AddFolder ("Configuration","MonteCarlo run configuration");
117
118 subfolder =
119 configuration_mc->AddFolder ("Generators","list of generator objects");
120
121 subfolder =
122 configuration_mc->AddFolder ("VirtualMC", "the Virtual MC");
123
124 TFolder *event_mc =
125 run_mc->AddFolder ("Event", "MonteCarlo event folders");
126
127 subfolder =
128 event_mc->AddFolder ("Header", "MonteCarlo event header");
129
130// subfolder =
131// event_mc->AddFolder ("Kinematics", "MonteCarlo generated particles");
132
133 subfolder =
134 event_mc->AddFolder ("Data", "MonteCarlo data");
135
136}
137
138AliConfig::~AliConfig()
139{
140}
141
142void AliConfig::AddInFolder (char *dir, TObject *obj)
143{
144 TFolder *folder =
145 (TFolder *) fTopFolder->FindObject (dir);
146 if (folder)
147 folder->Add ((TObject *)obj);
148}
149
150void AliConfig::AddSubFolder(char *dir[], TObject *obj)
151{
152 int iDir = 0;
153
154 while (dir[iDir])
155 {
156 TFolder * folder = (TFolder *) fTopFolder->FindObject (dir[iDir++]);
157 if (folder) {
158 TFolder * subfolder = (TFolder *) folder->FindObject (obj->GetName());
159 if (!subfolder)
160 subfolder = folder->AddFolder (obj->GetName(),obj->GetTitle());
161 }
162 }
163
164}
165
166TObject* AliConfig::FindInFolder (char *dir, const char *name)
167{
168 if(!name) return(fTopFolder->FindObject(name));
169 TFolder * folder = (TFolder *) fTopFolder->FindObject (dir);
170 if (!folder) return (NULL);
171 return(folder->FindObject(name));
172}
173
174void AliConfig::Add (AliGenerator * obj)
175{
176 AddInFolder(gGeneratorFolder, (TObject *) obj);
177}
178
179void AliConfig::Add (AliMC * obj)
180{
181 AddInFolder(gMCFolder, (TObject *) obj);
182}
183
184void AliConfig::Add (TDatabasePDG * obj)
185{
186 AddInFolder(gPDGFolder, (TObject *) obj);
187}
188
189void AliConfig::Add (AliModule* obj)
190{
191 AddInFolder(gModuleFolder, (TObject *) obj);
192}
193
194void AliConfig::Add (AliDetector * obj)
195{
196 AddSubFolder(gDetectorFolder, (TObject *) obj);
197}
198
199
200void AliConfig::Add (const char *list)
201{
202 char *path;
203
204 const char *conf_path = gSystem->Getenv ("ALICE_CONFIG_PATH");
205 if (conf_path) {
206 path = new char[strlen (conf_path)];
207 strcpy (path, conf_path);
208 } else {
209 const char *alice = gSystem->Getenv ("ALICE_ROOT");
210 path = new char[strlen (alice) + 32];
211
212 strcpy (path, ".:");
213 if (alice) {
214 strcat (path, alice);
215 }
216 strcat (path, "/macros/config");
217 }
218
219 char *token = strtok (path, ":");
220
221 TList *dirlist = new TList;
222
223 while (token != NULL)
224 {
225 dirlist->Add ((TObject *) token);
226 token = strtok (NULL, ":");
227 }
228
229 token = strtok ((char *)list, " ");
230
231 while (token != NULL)
232 {
233 cout << "Configuring " << token << ": ";
234
235 TObject *obj;
236 TIter next (dirlist);
237 TString found = "\0";
238
239 while ((obj = next ()))
240 {
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";
253 }
254 }
255 break;
256 } else {
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";
265 }
266 break;
267 }
268 }
269 }
270
271 if (strlen(found.Data())) {
272 cout << found << " => OK" << endl;
273 } else {
274 cout << " => FAILED." << endl;
275 exit(1);
276 }
277
278 token = strtok (NULL, " ");
279 }
280
281 if (dirlist) delete dirlist;
282
283}
284
285