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