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>
37 #include <TVirtualMC.h>
39 #include "AliConfig.h"
40 #include "AliDetector.h"
41 #include "AliGenerator.h"
42 #include "AliLoader.h"
49 kDetTaskRecontructioner,
58 kDetFolderCalibration,
65 AliConfig* AliConfig::fInstance = 0;
68 const TString AliConfig::fgkTopFolderName("Folders");
71 const TString AliConfig::fgkTasksFolderName("Tasks"); //task folder, commn
72 const TString AliConfig::fgkConstantsFolderName("Constants");
73 const TString AliConfig::fgkDefaultEventFolderName("Event"); //default folder for event, always used except merging
76 //subfolder of event folder
77 const TString AliConfig::fgkDataFolderName("Data");//folder for data (hits, digits, points, tracks) grouped by detectors
78 const TString AliConfig::fgkModuleFolderName("Modules");//folder with modules objects
79 const TString AliConfig::fgkConditionsFolderName("Conditions");//folder with conditions (mag. field etc.)
80 const TString AliConfig::fgkConfigurationFolderName("Configuration");//folder with configuration (setup) of the detector
81 const TString AliConfig::fgkHeaderFolderName("Header");//folder with header and other MC information
83 //Tasks names, goes into fgkTasksFolderName folder
84 const TString AliConfig::fgkDigitizerTaskName("Digitizer");
85 const TString AliConfig::fgkSDigitizerTaskName("SDigitizer");
86 const TString AliConfig::fgkReconstructionerTaskName("Reconstructioner");
87 const TString AliConfig::fgkTrackerTaskName("Tracker");
88 const TString AliConfig::fgkPIDTaskName("PIDTask");//;=) PIDer???
89 const TString AliConfig::fgkQATaskName("QAtask");
92 //fgkConditionsFolderName subfolders
93 const TString AliConfig::fgkCalibrationFolderName("Calibration");
94 const TString AliConfig::fgkAligmentFolderName("Aligment");
95 const TString AliConfig::fgkQAFolderName("QAout");
98 //fgkConfigurationFolderName subfolders
99 const TString AliConfig::fgkFieldFolderName("Field");
100 const TString AliConfig::fgkGeneratorsFolderName("Generators");
101 const TString AliConfig::fgkVirtualMCFolderName("VirtualMC");
104 const TString AliConfig::fgkPDGFolderName("Constants/DatabasePDG");//folder with PDG Database
105 const TString AliConfig::fgkGeneratorFolderName("Configuration/Generators");//folder with generators
106 const TString AliConfig::fgkMCFolderName("Configuration/VirtualMC");
108 //____________________________________________________________________________
109 AliConfig* AliConfig::Instance ()
112 // Instance method for singleton class
116 fInstance = new AliConfig (fgkTopFolderName,"Alice data exchange board");
121 //____________________________________________________________________________
122 AliConfig::AliConfig():
130 // Default constructor, mainly to keep coding conventions
132 fInstance=0;//never mind, its going to exit in next step
133 Fatal("ctor","Constructor should not be called for a singleton\n");
135 //____________________________________________________________________________
137 AliConfig::AliConfig(const AliConfig& conf):
146 // Copy constructor, mainly to keep coding conventions
151 "Copy constructor should not be called for a singleton\n");
153 //____________________________________________________________________________
155 AliConfig::AliConfig(const char *name, const char *title):
157 fTopFolder(gROOT->GetRootFolder()->AddFolder(name,title)),
158 fTaskFolder(fTopFolder->AddFolder(fgkTasksFolderName, "ALICE Tasks")),
161 fDetectorFolder(new TString[kDetFolderLast+1])
165 //Main AliRoot Folder
166 if (fTopFolder == 0x0)
168 Fatal("AliConfig(const char*, const char*)","Can not create Top Alice Folder.");
169 return;//never reached
171 fTopFolder->SetOwner();
173 fDetectorFolder[kDetFolderData] = fgkDataFolderName;
174 fDetectorFolder[kDetFolderCalibration] = fgkConditionsFolderName+"/"+fgkCalibrationFolderName;
175 fDetectorFolder[kDetFolderAligmnet] = fgkConditionsFolderName+"/"+fgkAligmentFolderName;
176 fDetectorFolder[kDetFolderQA] = fgkConditionsFolderName+"/"+fgkQAFolderName;
177 fDetectorFolder[kDetFolderLast] = "";
179 gROOT->GetListOfBrowsables()->Add(fTopFolder, name);
182 TFolder *fConstFolder = fTopFolder->AddFolder (fgkConstantsFolderName, "Constant parameters");
183 fConstFolder->AddFolder("DatabasePDG", "PDG database");
185 // Add the tasks to //Folders
187 TTask * qa = new TTask(fgkQATaskName, "Alice QA tasks");
188 fTaskFolder->Add(qa);
189 TTask * sd = new TTask(fgkSDigitizerTaskName, "Alice SDigitizer") ;
190 fTaskFolder->Add(sd);
191 TTask * di = new TTask(fgkDigitizerTaskName, "Alice Digitizer") ;
192 fTaskFolder->Add(di);
193 TTask * re = new TTask(fgkReconstructionerTaskName, "Alice Reconstructioner") ;
194 fTaskFolder->Add(re);
195 TTask * tr = new TTask(fgkTrackerTaskName,"Alice Tracker");
196 fTaskFolder->Add(tr);
197 TTask * pid = new TTask(fgkPIDTaskName,"Alice Particle Identification Task");
198 fTaskFolder->Add(pid);
199 fDetectorTask = new TString[kDetTaskLast+1];
201 fDetectorTask[kDetTaskQA] = fgkQATaskName;
202 fDetectorTask[kDetTaskSDigitizer] = fgkSDigitizerTaskName;
203 fDetectorTask[kDetTaskDigitizer] = fgkDigitizerTaskName;
204 fDetectorTask[kDetTaskRecontructioner] = fgkReconstructionerTaskName;
205 fDetectorTask[kDetTaskTracker] = fgkTrackerTaskName;
206 fDetectorTask[kDetTaskPID] = fgkPIDTaskName;
207 fDetectorTask[kDetTaskLast] = "";
212 //____________________________________________________________________________
213 AliConfig::~AliConfig()
215 delete [] fDetectorFolder ;
216 delete [] fDetectorTask;
219 fTopFolder->SetOwner();
223 //____________________________________________________________________________
225 void AliConfig::AddInFolder (const char *dir, TObject *obj)
227 TFolder *folder = dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
229 folder->Add (static_cast<TObject *>(obj));
231 //____________________________________________________________________________
233 Int_t AliConfig::AddSubTask(const char *taskname, const char* name,const char* title)
235 //Create new task named 'name' and titled 'title'
236 //as a subtask of the task named 'taskname'
238 if (AliLoader::fgDebug) Info("AddSubTask","Try to get folder named %s",taskname);
239 TObject* obj = fTopFolder->FindObject(taskname);
240 TTask * task = (obj)?dynamic_cast<TTask*>(obj):0x0;
243 if (AliLoader::fgDebug) Info("AddSubTask"," Got");
244 TTask * subtask = static_cast<TTask*>(task->GetListOfTasks()->FindObject(name));
247 subtask = new TTask(name,title);
252 Warning("AddSubTask","Task named \"%s\" already exists in Task %s\n",name,taskname);
257 Error("AddSubTask","Can not find task %s to put a new task in.",taskname);
263 //____________________________________________________________________________
264 TObject* AliConfig::FindInFolder (const char *dir, const char *name)
266 if(!name) return(fTopFolder->FindObject(name));
267 TFolder * folder = dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
268 if (!folder) return (NULL);
269 return(folder->FindObject(name));
272 //____________________________________________________________________________
273 void AliConfig::Add (AliGenerator * obj,const char* eventfolder)
275 TString path(eventfolder);
276 path = path + "/" + fgkGeneratorsFolderName;
277 AddInFolder(path,obj);
280 //____________________________________________________________________________
281 void AliConfig::Add (TVirtualMC * obj,const char* eventfolder)
283 TString path(eventfolder);
284 path = path + "/" + fgkMCFolderName;
285 AddInFolder(path, obj);
288 //____________________________________________________________________________
289 void AliConfig::Add (TDatabasePDG * obj)
291 AddInFolder(fgkPDGFolderName, obj);
294 //____________________________________________________________________________
295 void AliConfig::Add(AliModule* obj,const char* eventfolder)
298 TString path(eventfolder);
299 path = path + "/" + fgkModuleFolderName;
300 if (AliLoader::fgDebug)
301 Info("Add(AliModule*)","module name = %s, Ev. Fold. Name is %s.",
302 obj->GetName(),eventfolder);
303 AddInFolder(path, obj);
305 //____________________________________________________________________________
307 Int_t AliConfig::AddDetector(TFolder* evntfolder, const char *name, const char* title)
309 //creates folders and tasks for the detector 'name'
310 Int_t retval;//returned value
311 retval = CreateDetectorFolders(evntfolder,name,title);
314 Error("AddDetector","CreateDetectorFolders returned error for detector %s",name);
319 //____________________________________________________________________________
321 Int_t AliConfig::AddDetector(const char* evntfoldername,const char *name, const char* title)
323 //creates folders and tasks for the detector 'name'
324 Int_t retval;//returned value
325 retval = CreateDetectorFolders(evntfoldername,name,title);
328 Error("AddDetector","CreateDetectorFolders returned error for detector %s",name);
331 // retval = CreateDetectorTasks(name,title);
334 // Error("AddDetector","CreateDetectorTasks returned error for detector %s",name);
339 //____________________________________________________________________________
341 void AliConfig::Add(AliDetector * obj,const char* eventfolder)
343 if (AliLoader::fgDebug)
344 Info("Add(AliDetector*)","detector name = %s, Ev. Fold. Name is %s.",
345 obj->GetName(),eventfolder);
347 TObject* foundobj = GetTopFolder()->FindObject(eventfolder);
348 TFolder* evfolder = (foundobj)?dynamic_cast<TFolder*>(foundobj):0x0;
351 Fatal("Add(AliDetector * obj,const char* eventfolder)",
352 "Can not find folder %s while adding detector %s",eventfolder,obj->GetName());
355 CreateDetectorFolders(evfolder, obj->GetName(), obj->GetTitle());
357 // CreateDetectorTasks(obj->GetName(),obj->GetTitle());
360 //____________________________________________________________________________
362 Int_t AliConfig::CreateDetectorFolders(const char* evntfoldername,const char *name, const char* title)
364 //creates a folders for detector named 'name' and titled 'title'
365 //in a event folder named 'evntfoldername'
366 //list of folder names where new folders are created is defined in fDetectorFolder array
367 //detector folders are named 'name' and titled 'title' as well
369 TFolder* evfolder = dynamic_cast<TFolder*>(GetTopFolder()->FindObject(evntfoldername));
372 Error("CreateDetectorFolders",
373 "Can not find folder %s while adding detector %s",evntfoldername,name);
376 return CreateDetectorFolders(evfolder,name,title);
378 //____________________________________________________________________________
379 Int_t AliConfig::CreateDetectorFolders(TFolder* evntfolder,const char *name, const char* title)
381 //creates a folders for detector named 'name' and titled 'title'
382 //in a event folder 'evntfolder'
383 //list of folder names where new folders are created is defined in fDetectorFolder array
384 //detector folders are named 'name' and titled 'title' as well
385 //Here we add only detector not an modules
388 Int_t i = 0;//iterator
389 while(!fDetectorFolder[i].IsNull())
391 tmp = AddSubFolder(evntfolder,fDetectorFolder[i],name,title);
394 Error("AddDetector(TFolder*","Failed to create subfolder of %s for detector %s",fDetectorFolder[i].Data(),name);
401 //____________________________________________________________________________
402 Int_t AliConfig::CreateDetectorTasks(const char *name, const char* title)
406 while (i < kDetTaskLast)
408 tmp = AddSubTask(fgkTasksFolderName+"/"+fDetectorTask[i],
409 name+fDetectorTask[i],(fDetectorTask[i]+" for ")+title);
412 Error("CreateDetectorTasks","Error occured while creating task for %s in %s.",
413 name,fDetectorTask[i-1].Data());
421 //____________________________________________________________________________
422 void AliConfig::Add (char *list)
426 const char *conf_path = gSystem->Getenv ("ALICE_CONFIG_PATH");
428 path = new char[strlen (conf_path)];
429 strcpy (path, conf_path);
431 const char *alice = gSystem->Getenv ("ALICE_ROOT");
432 path = new char[strlen (alice) + 32];
436 strcat (path, alice);
438 strcat (path, "/macros/config");
441 char *token = strtok (path, ":");
443 TList *dirlist = new TList;
445 while (token != NULL)
447 dirlist->Add (new TObjString(token));
448 token = strtok (NULL, ":");
451 token = strtok (list, " ");
453 while (token != NULL)
455 Info("Add(char *list)","Configuring token=%s",token);
458 TIter next (dirlist);
459 TString found = "\0";
461 while ((obj = next ()))
463 TString dir(obj->GetName());
464 TString path = dir + "/" + token;
465 TString macro = path + ".C";
466 if (!gSystem->AccessPathName (macro.Data()))
468 gInterpreter->ExecuteMacro (macro.Data());
469 found = "(" + macro + ")";
470 if (macro.Contains("/"))
472 TString dirname = gSystem->DirName(macro.Data());
473 TString macroConfigure = dirname + "/Configure.C";
474 if (!gSystem->AccessPathName (macroConfigure.Data()))
476 gInterpreter->ExecuteMacro (macroConfigure.Data());
477 found += " => Configured";
484 TString macroDefault = path + "/Default.C";
485 if (!gSystem->AccessPathName (macroDefault.Data()))
487 gInterpreter->ExecuteMacro (macroDefault.Data());
488 found = "(" + macro + ")";
489 TString macroConfigure = path + "/Configure.C";
490 if (!gSystem->AccessPathName (macroConfigure.Data()))
492 gInterpreter->ExecuteMacro (macroConfigure.Data());
493 found += " => Configured";
500 if (strlen(found.Data()))
502 Info("Add(char *list)","found=%s => OK",found.Data());
506 Error("Add(char *list)"," => FAILED.");
510 token = strtok (NULL," ");
513 if (dirlist) delete dirlist;
517 /*****************************************************************************/
519 TFolder* AliConfig::BuildEventFolder(const char* name,const char* title)
522 creates the folder structure for one event
533 | | Modules(detector objects)
543 | | | | Hits(object;e.g. tree)
546 | | | | SDigits(object)
549 | | | | Digits(object)
552 | | | | RecPoints(object)
560 | | | Hits(object;e.g. tree)
563 | | | SDigits(object)
569 | | | RecPoints(object)
579 Event2_ (to be merged with event)
581 | Modules(detector objects)
591 | | | Hits(object;e.g. tree)
594 | | | SDigits(object)
600 | | | RecPoints(object)
608 | | Hits(object;e.g. tree)
617 | | RecPoints(object)
626 TFolder* eventfolder = fTopFolder->AddFolder(name,title);
629 eventfolder->AddFolder(fgkModuleFolderName, "Detector objects");
631 eventfolder->AddFolder(fgkDataFolderName, "Detector data");
634 TFolder *conditions = eventfolder->AddFolder(fgkConditionsFolderName, "Run conditions");
635 conditions->AddFolder(fgkCalibrationFolderName,"Detector calibration data");
636 conditions->AddFolder(fgkAligmentFolderName,"Detector aligment");
637 conditions->AddFolder(fgkQAFolderName,"Quality Asurance Output"); //Folder with output of the QA task(s)
639 TFolder *configuration = eventfolder->AddFolder(fgkConfigurationFolderName, "Run configuration");
640 configuration->AddFolder(fgkFieldFolderName, "Magnetic field maps");
641 configuration->AddFolder(fgkGeneratorsFolderName,"list of generator objects");
642 configuration->AddFolder(fgkVirtualMCFolderName,"the Virtual MC");
644 eventfolder->AddFolder(fgkHeaderFolderName,"MonteCarlo event header");
646 eventfolder->SetOwner();
651 /*****************************************************************************/
653 TString AliConfig::GetQATaskName() const
656 return fDetectorTask[kDetTaskQA];
658 /*****************************************************************************/
660 TString AliConfig::GetDigitizerTaskName() const
663 return fDetectorTask[kDetTaskDigitizer];
665 /*****************************************************************************/
667 TString AliConfig::GetSDigitizerTaskName() const
670 return fDetectorTask[kDetTaskSDigitizer];
672 /*****************************************************************************/
674 TString AliConfig::GetReconstructionerTaskName() const
677 return fDetectorTask[kDetTaskRecontructioner];
679 /*****************************************************************************/
681 TString AliConfig::GetTrackerTaskName() const
684 return fDetectorTask[kDetTaskTracker];
686 /*****************************************************************************/
688 TString AliConfig::GetPIDTaskName() const
691 return fDetectorTask[kDetTaskPID];
693 /*****************************************************************************/
695 const TString& AliConfig::GetQAFolderName() const
697 //returns pathname of folder with QA output relative to Top Alice Folder
698 return fDetectorFolder[kDetFolderQA];
700 /*****************************************************************************/
702 const TString& AliConfig::GetDataFolderName()
704 //returns name of data folder path relative to event folder
705 return fgkDataFolderName;
707 /*****************************************************************************/
709 Int_t AliConfig::AddSubFolder(TFolder* topfolder, const char* infoler,
710 const char* newfoldname, const char* newfoldtitle)
713 //in topfolder looks for folder named 'infolder'
714 //and if it exist it creates inside a new folder named 'newfoldname' and titled 'newfoldtitle'
716 if (topfolder == 0x0)//check if exists top folder
718 Error("AddSubFodler(TFolder*, ....","Parameter TFolder* points to NULL.");
725 folder = dynamic_cast<TFolder*>(topfolder->FindObject(infoler));
726 if (folder == 0x0) //check if we got inolder
728 Error("AddSubFodler(TFolder*, ....","Can not find folder %s in folder %s.",infoler,topfolder->GetName());
731 obj = folder->FindObject(newfoldname); //see if such a subfolder already exists
732 if (obj == 0x0) //nope
734 TFolder *newfolder = folder->AddFolder(newfoldname,newfoldtitle);//add the desired subfolder
735 if (newfolder == 0x0) //check if we managed
737 Error("AddSubFodler(TFolder*, ....","Can not create folder %s in folder %s",newfoldname,infoler);
740 else return 0;//success
742 //such an object already exists
743 TFolder* fol = dynamic_cast<TFolder*>(obj);
746 Error("AddSubFodler(TFolder*, ....",
747 "Object named %s already exists in folder %s AND IT IS NOT A FOLDER",newfoldname,infoler);
750 Warning("AddSubFodler(TFolder*, ....",
751 "Folder named %s already exists in folder %s",newfoldname,infoler);