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 **************************************************************************/
19 // This class is responsible for creating folder structure
20 // All stuff of aliroot sits in one folder with name defined by
21 // fgkTopFolderName data wich do not very trough event to event are
22 // sitting in directly in "top folder" all data which changes from
23 // event to event are sitting in one folder (which has more subfolders)
24 // Idea is to have more than one event in folder structure which allows
25 // usage of standard procedures in merging
26 // Add(AliDetector*) calls Add(AliModule*) as AliDetector is a AliModule
27 // as well and should be listed in module list
29 #include <TDatabasePDG.h>
31 #include <TInterpreter.h>
32 #include <TObjString.h>
36 #include <TVirtualMC.h>
38 #include "AliConfig.h"
39 #include "AliDetector.h"
40 #include "AliGenerator.h"
41 #include "AliLoader.h"
47 kDetFolderCalibration,
53 AliConfig* AliConfig::fgInstance = 0;
56 const TString AliConfig::fgkTopFolderName("Folders");
59 const TString AliConfig::fgkConstantsFolderName("Constants");
60 const TString AliConfig::fgkDefaultEventFolderName("Event"); //default folder for event, always used except merging
63 //subfolder of event folder
64 const TString AliConfig::fgkDataFolderName("Data");//folder for data (hits, digits, points, tracks) grouped by detectors
65 const TString AliConfig::fgkModuleFolderName("Modules");//folder with modules objects
66 const TString AliConfig::fgkConditionsFolderName("Conditions");//folder with conditions (mag. field etc.)
67 const TString AliConfig::fgkConfigurationFolderName("Configuration");//folder with configuration (setup) of the detector
68 const TString AliConfig::fgkHeaderFolderName("Header");//folder with header and other MC information
71 //fgkConditionsFolderName subfolders
72 const TString AliConfig::fgkCalibrationFolderName("Calibration");
73 const TString AliConfig::fgkAligmentFolderName("Aligment");
76 //fgkConfigurationFolderName subfolders
77 const TString AliConfig::fgkFieldFolderName("Field");
78 const TString AliConfig::fgkGeneratorsFolderName("Generators");
79 const TString AliConfig::fgkVirtualMCFolderName("VirtualMC");
82 const TString AliConfig::fgkPDGFolderName("Constants/DatabasePDG");//folder with PDG Database
83 const TString AliConfig::fgkGeneratorFolderName("Configuration/Generators");//folder with generators
84 const TString AliConfig::fgkMCFolderName("Configuration/VirtualMC");
86 //____________________________________________________________________________
87 AliConfig* AliConfig::Instance ()
90 // Instance method for singleton class
94 fgInstance = new AliConfig (fgkTopFolderName,"Alice data exchange board");
98 //____________________________________________________________________________
100 AliConfig::AliConfig(const char *name, const char *title):
102 fTopFolder(gROOT->GetRootFolder()->AddFolder(name,title)),
104 fDetectorFolder(new TString[kDetFolderLast+1])
108 //Main AliRoot Folder
109 if (fTopFolder == 0x0)
111 AliFatal("Can not create Top Alice Folder.");
112 return;//never reached
114 fTopFolder->SetOwner();
116 fDetectorFolder[kDetFolderData] = fgkDataFolderName;
117 fDetectorFolder[kDetFolderCalibration] = fgkConditionsFolderName+"/"+fgkCalibrationFolderName;
118 fDetectorFolder[kDetFolderAligmnet] = fgkConditionsFolderName+"/"+fgkAligmentFolderName;
119 fDetectorFolder[kDetFolderLast] = "";
121 gROOT->GetListOfBrowsables()->Add(fTopFolder, name);
124 fConstFolder = fTopFolder->AddFolder (fgkConstantsFolderName, "Constant parameters");
125 fConstFolder->AddFolder("DatabasePDG", "PDG database");
130 //____________________________________________________________________________
131 AliConfig::~AliConfig()
134 delete [] fDetectorFolder ;
137 fTopFolder->SetOwner();
141 //____________________________________________________________________________
143 void AliConfig::AddInFolder (const char *dir, TObject *obj)
145 // Adds object "obj" to folder "dir"
146 TFolder *folder = dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
148 folder->Add (static_cast<TObject *>(obj));
151 //____________________________________________________________________________
152 TObject* AliConfig::FindInFolder (const char *dir, const char *name)
154 // Finds object with name "name" in folder "dir"
155 if(!name) return(fTopFolder->FindObject(name));
156 TFolder * folder = dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
157 if (!folder) return (NULL);
158 return(folder->FindObject(name));
161 //____________________________________________________________________________
162 void AliConfig::Add (AliGenerator * obj,const char* eventfolder)
164 // Adds generator "obj" to the event folder "eventfolder"
165 TString path(eventfolder);
166 path = path + "/" + fgkGeneratorsFolderName;
167 AddInFolder(path,obj);
170 //____________________________________________________________________________
171 void AliConfig::Add (TVirtualMC * obj,const char* eventfolder)
173 // Adds TVirtualMC object to the event folder
174 TString path(eventfolder);
175 path = path + "/" + fgkMCFolderName;
176 AddInFolder(path, obj);
179 //____________________________________________________________________________
180 void AliConfig::Add (TDatabasePDG * obj)
182 // Adds TDataBase object
183 AddInFolder(fgkPDGFolderName, obj);
186 //____________________________________________________________________________
187 void AliConfig::Add(AliModule* obj,const char* eventfolder)
189 // Adds module to the event folder
190 TString path(eventfolder);
191 path = path + "/" + fgkModuleFolderName;
192 AliDebug(1, Form("module name = %s, Ev. Fold. Name is %s.",
193 obj->GetName(),eventfolder));
194 AddInFolder(path, obj);
196 //____________________________________________________________________________
198 Int_t AliConfig::AddDetector(TFolder* evntfolder, const char *name, const char* title)
200 //creates folders for the detector 'name'
201 Int_t retval;//returned value
202 retval = CreateDetectorFolders(evntfolder,name,title);
205 AliError(Form("CreateDetectorFolders returned error for detector %s",name));
210 //____________________________________________________________________________
212 Int_t AliConfig::AddDetector(const char* evntfoldername,const char *name, const char* title)
214 //creates folders for the detector 'name'
215 Int_t retval;//returned value
216 retval = CreateDetectorFolders(evntfoldername,name,title);
219 AliError(Form("CreateDetectorFolders returned error for detector %s",name));
224 //____________________________________________________________________________
226 void AliConfig::Add(AliDetector * obj,const char* eventfolder)
228 // Adds new AliDetector objest to the correspondent event folder
229 AliDebug(1, Form("detector name = %s, Ev. Fold. Name is %s.",
230 obj->GetName(),eventfolder));
232 TObject* foundobj = GetTopFolder()->FindObject(eventfolder);
233 TFolder* evfolder = (foundobj)?dynamic_cast<TFolder*>(foundobj):0x0;
236 AliFatal(Form("Can not find folder %s while adding detector %s",eventfolder,obj->GetName()));
239 CreateDetectorFolders(evfolder, obj->GetName(), obj->GetTitle());
242 //____________________________________________________________________________
244 Int_t AliConfig::CreateDetectorFolders(const char* evntfoldername,const char *name, const char* title)
246 //creates a folders for detector named 'name' and titled 'title'
247 //in a event folder named 'evntfoldername'
248 //list of folder names where new folders are created is defined in fDetectorFolder array
249 //detector folders are named 'name' and titled 'title' as well
251 TFolder* evfolder = dynamic_cast<TFolder*>(GetTopFolder()->FindObject(evntfoldername));
254 AliError(Form("Can not find folder %s while adding detector %s",evntfoldername,name));
257 return CreateDetectorFolders(evfolder,name,title);
259 //____________________________________________________________________________
260 Int_t AliConfig::CreateDetectorFolders(TFolder* evntfolder,const char *name, const char* title)
262 //creates a folders for detector named 'name' and titled 'title'
263 //in a event folder 'evntfolder'
264 //list of folder names where new folders are created is defined in fDetectorFolder array
265 //detector folders are named 'name' and titled 'title' as well
266 //Here we add only detector not an modules
269 Int_t i = 0;//iterator
270 while(!fDetectorFolder[i].IsNull())
272 tmp = AddSubFolder(evntfolder,fDetectorFolder[i],name,title);
275 AliError(Form("Failed to create subfolder of %s for detector %s",fDetectorFolder[i].Data(),name));
283 /*****************************************************************************/
285 TFolder* AliConfig::BuildEventFolder(const char* name,const char* title)
288 creates the folder structure for one event
297 | | Modules(detector objects)
307 | | | | Hits(object;e.g. tree)
310 | | | | SDigits(object)
313 | | | | Digits(object)
316 | | | | RecPoints(object)
324 | | | Hits(object;e.g. tree)
327 | | | SDigits(object)
333 | | | RecPoints(object)
343 Event2_ (to be merged with event)
345 | Modules(detector objects)
355 | | | Hits(object;e.g. tree)
358 | | | SDigits(object)
364 | | | RecPoints(object)
372 | | Hits(object;e.g. tree)
381 | | RecPoints(object)
390 TFolder* eventfolder = fTopFolder->AddFolder(name,title);
393 eventfolder->AddFolder(fgkModuleFolderName, "Detector objects");
395 eventfolder->AddFolder(fgkDataFolderName, "Detector data");
398 TFolder *conditions = eventfolder->AddFolder(fgkConditionsFolderName, "Run conditions");
399 conditions->AddFolder(fgkCalibrationFolderName,"Detector calibration data");
400 conditions->AddFolder(fgkAligmentFolderName,"Detector aligment");
402 TFolder *configuration = eventfolder->AddFolder(fgkConfigurationFolderName, "Run configuration");
403 configuration->AddFolder(fgkFieldFolderName, "Magnetic field maps");
404 configuration->AddFolder(fgkGeneratorsFolderName,"list of generator objects");
405 //PH configuration->AddFolder(fgkVirtualMCFolderName,"the Virtual MC");
407 eventfolder->AddFolder(fgkHeaderFolderName,"MonteCarlo event header");
409 eventfolder->SetOwner();
414 /*****************************************************************************/
416 const TString& AliConfig::GetDataFolderName() const
418 //returns name of data folder path relative to event folder
419 return fgkDataFolderName;
422 /*****************************************************************************/
424 Int_t AliConfig::AddSubFolder(TFolder* topfolder, const char* infoler,
425 const char* newfoldname, const char* newfoldtitle)
428 //in topfolder looks for folder named 'infolder'
429 //and if it exist it creates inside a new folder named 'newfoldname' and titled 'newfoldtitle'
431 if (topfolder == 0x0)//check if exists top folder
433 AliError("Parameter TFolder* points to NULL.");
440 folder = dynamic_cast<TFolder*>(topfolder->FindObject(infoler));
441 if (folder == 0x0) //check if we got inolder
443 AliError(Form("Can not find folder %s in folder %s.",infoler,topfolder->GetName()));
446 obj = folder->FindObject(newfoldname); //see if such a subfolder already exists
447 if (obj == 0x0) //nope
449 TFolder *newfolder = folder->AddFolder(newfoldname,newfoldtitle);//add the desired subfolder
450 if (newfolder == 0x0) //check if we managed
452 AliError(Form("Can not create folder %s in folder %s",newfoldname,infoler));
455 else return 0;//success
457 //such an object already exists
458 TFolder* fol = dynamic_cast<TFolder*>(obj);
461 AliError(Form("Object named %s already exists in folder %s AND IT IS NOT A FOLDER",newfoldname,infoler));
464 AliWarning(Form("Folder named %s already exists in folder %s",newfoldname,infoler));