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"
50 kDetTaskRecontructioner,
59 kDetFolderCalibration,
66 AliConfig* AliConfig::fgInstance = 0;
69 const TString AliConfig::fgkTopFolderName("Folders");
72 const TString AliConfig::fgkTasksFolderName("Tasks"); //task folder, commn
73 const TString AliConfig::fgkConstantsFolderName("Constants");
74 const TString AliConfig::fgkDefaultEventFolderName("Event"); //default folder for event, always used except merging
77 //subfolder of event folder
78 const TString AliConfig::fgkDataFolderName("Data");//folder for data (hits, digits, points, tracks) grouped by detectors
79 const TString AliConfig::fgkModuleFolderName("Modules");//folder with modules objects
80 const TString AliConfig::fgkConditionsFolderName("Conditions");//folder with conditions (mag. field etc.)
81 const TString AliConfig::fgkConfigurationFolderName("Configuration");//folder with configuration (setup) of the detector
82 const TString AliConfig::fgkHeaderFolderName("Header");//folder with header and other MC information
84 //Tasks names, goes into fgkTasksFolderName folder
85 const TString AliConfig::fgkDigitizerTaskName("Digitizer");
86 const TString AliConfig::fgkSDigitizerTaskName("SDigitizer");
87 const TString AliConfig::fgkReconstructionerTaskName("Reconstructioner");
88 const TString AliConfig::fgkTrackerTaskName("Tracker");
89 const TString AliConfig::fgkPIDTaskName("PIDTask");//;=) PIDer???
90 const TString AliConfig::fgkQATaskName("QAtask");
93 //fgkConditionsFolderName subfolders
94 const TString AliConfig::fgkCalibrationFolderName("Calibration");
95 const TString AliConfig::fgkAligmentFolderName("Aligment");
96 const TString AliConfig::fgkQAFolderName("QAout");
99 //fgkConfigurationFolderName subfolders
100 const TString AliConfig::fgkFieldFolderName("Field");
101 const TString AliConfig::fgkGeneratorsFolderName("Generators");
102 const TString AliConfig::fgkVirtualMCFolderName("VirtualMC");
105 const TString AliConfig::fgkPDGFolderName("Constants/DatabasePDG");//folder with PDG Database
106 const TString AliConfig::fgkGeneratorFolderName("Configuration/Generators");//folder with generators
107 const TString AliConfig::fgkMCFolderName("Configuration/VirtualMC");
109 //____________________________________________________________________________
110 AliConfig* AliConfig::Instance ()
113 // Instance method for singleton class
117 fgInstance = new AliConfig (fgkTopFolderName,"Alice data exchange board");
122 //____________________________________________________________________________
123 AliConfig::AliConfig():
131 // Default constructor, mainly to keep coding conventions
133 fgInstance=0;//never mind, its going to exit in next step
134 AliFatal("Constructor should not be called for a singleton");
136 //____________________________________________________________________________
138 AliConfig::AliConfig(const AliConfig& conf):
147 // Copy constructor, mainly to keep coding conventions
151 AliFatal("Copy constructor should not be called for a singleton");
153 //____________________________________________________________________________
155 AliConfig& AliConfig::operator=(const AliConfig& /*conf*/)
158 // Assignment, mainly to keep coding conventions
162 AliFatal("Assignment operator should not be called for a singleton");
165 //____________________________________________________________________________
167 AliConfig::AliConfig(const char *name, const char *title):
169 fTopFolder(gROOT->GetRootFolder()->AddFolder(name,title)),
170 fTaskFolder(fTopFolder->AddFolder(fgkTasksFolderName, "ALICE Tasks")),
173 fDetectorFolder(new TString[kDetFolderLast+1])
177 //Main AliRoot Folder
178 if (fTopFolder == 0x0)
180 AliFatal("Can not create Top Alice Folder.");
181 return;//never reached
183 fTopFolder->SetOwner();
185 fDetectorFolder[kDetFolderData] = fgkDataFolderName;
186 fDetectorFolder[kDetFolderCalibration] = fgkConditionsFolderName+"/"+fgkCalibrationFolderName;
187 fDetectorFolder[kDetFolderAligmnet] = fgkConditionsFolderName+"/"+fgkAligmentFolderName;
188 fDetectorFolder[kDetFolderQA] = fgkConditionsFolderName+"/"+fgkQAFolderName;
189 fDetectorFolder[kDetFolderLast] = "";
191 gROOT->GetListOfBrowsables()->Add(fTopFolder, name);
194 fConstFolder = fTopFolder->AddFolder (fgkConstantsFolderName, "Constant parameters");
195 fConstFolder->AddFolder("DatabasePDG", "PDG database");
197 // Add the tasks to //Folders
199 TTask * qa = new TTask(fgkQATaskName, "Alice QA tasks");
200 fTaskFolder->Add(qa);
201 TTask * sd = new TTask(fgkSDigitizerTaskName, "Alice SDigitizer") ;
202 fTaskFolder->Add(sd);
203 TTask * di = new TTask(fgkDigitizerTaskName, "Alice Digitizer") ;
204 fTaskFolder->Add(di);
205 TTask * re = new TTask(fgkReconstructionerTaskName, "Alice Reconstructioner") ;
206 fTaskFolder->Add(re);
207 TTask * tr = new TTask(fgkTrackerTaskName,"Alice Tracker");
208 fTaskFolder->Add(tr);
209 TTask * pid = new TTask(fgkPIDTaskName,"Alice Particle Identification Task");
210 fTaskFolder->Add(pid);
211 fDetectorTask = new TString[kDetTaskLast+1];
213 fDetectorTask[kDetTaskQA] = fgkQATaskName;
214 fDetectorTask[kDetTaskSDigitizer] = fgkSDigitizerTaskName;
215 fDetectorTask[kDetTaskDigitizer] = fgkDigitizerTaskName;
216 fDetectorTask[kDetTaskRecontructioner] = fgkReconstructionerTaskName;
217 fDetectorTask[kDetTaskTracker] = fgkTrackerTaskName;
218 fDetectorTask[kDetTaskPID] = fgkPIDTaskName;
219 fDetectorTask[kDetTaskLast] = "";
224 //____________________________________________________________________________
225 AliConfig::~AliConfig()
228 delete [] fDetectorFolder ;
229 delete [] fDetectorTask;
232 fTopFolder->SetOwner();
236 //____________________________________________________________________________
238 void AliConfig::AddInFolder (const char *dir, TObject *obj)
240 // Adds object "obj" to folder "dir"
241 TFolder *folder = dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
243 folder->Add (static_cast<TObject *>(obj));
245 //____________________________________________________________________________
247 Int_t AliConfig::AddSubTask(const char *taskname, const char* name,const char* title)
249 //Create new task named 'name' and titled 'title'
250 //as a subtask of the task named 'taskname'
252 AliDebug(1, Form("Try to get folder named %s",taskname));
253 TObject* obj = fTopFolder->FindObject(taskname);
254 TTask * task = (obj)?dynamic_cast<TTask*>(obj):0x0;
258 TTask * subtask = static_cast<TTask*>(task->GetListOfTasks()->FindObject(name));
261 subtask = new TTask(name,title);
266 AliWarning(Form("Task named \"%s\" already exists in Task %s",name,taskname));
271 AliError(Form("Can not find task %s to put a new task in.",taskname));
277 //____________________________________________________________________________
278 TObject* AliConfig::FindInFolder (const char *dir, const char *name)
280 // Finds object with name "name" in folder "dir"
281 if(!name) return(fTopFolder->FindObject(name));
282 TFolder * folder = dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
283 if (!folder) return (NULL);
284 return(folder->FindObject(name));
287 //____________________________________________________________________________
288 void AliConfig::Add (AliGenerator * obj,const char* eventfolder)
290 // Adds generator "obj" to the event folder "eventfolder"
291 TString path(eventfolder);
292 path = path + "/" + fgkGeneratorsFolderName;
293 AddInFolder(path,obj);
296 //____________________________________________________________________________
297 void AliConfig::Add (TVirtualMC * obj,const char* eventfolder)
299 // Adds TVirtualMC object to the event folder
300 TString path(eventfolder);
301 path = path + "/" + fgkMCFolderName;
302 AddInFolder(path, obj);
305 //____________________________________________________________________________
306 void AliConfig::Add (TDatabasePDG * obj)
308 // Adds TDataBase object
309 AddInFolder(fgkPDGFolderName, obj);
312 //____________________________________________________________________________
313 void AliConfig::Add(AliModule* obj,const char* eventfolder)
315 // Adds module to the event folder
316 TString path(eventfolder);
317 path = path + "/" + fgkModuleFolderName;
318 AliDebug(1, Form("module name = %s, Ev. Fold. Name is %s.",
319 obj->GetName(),eventfolder));
320 AddInFolder(path, obj);
322 //____________________________________________________________________________
324 Int_t AliConfig::AddDetector(TFolder* evntfolder, const char *name, const char* title)
326 //creates folders and tasks for the detector 'name'
327 Int_t retval;//returned value
328 retval = CreateDetectorFolders(evntfolder,name,title);
331 AliError(Form("CreateDetectorFolders returned error for detector %s",name));
336 //____________________________________________________________________________
338 Int_t AliConfig::AddDetector(const char* evntfoldername,const char *name, const char* title)
340 //creates folders and tasks for the detector 'name'
341 Int_t retval;//returned value
342 retval = CreateDetectorFolders(evntfoldername,name,title);
345 AliError(Form("CreateDetectorFolders returned error for detector %s",name));
348 // retval = CreateDetectorTasks(name,title);
351 // Error("AddDetector","CreateDetectorTasks returned error for detector %s",name);
356 //____________________________________________________________________________
358 void AliConfig::Add(AliDetector * obj,const char* eventfolder)
360 // Adds new AliDetector objest to the correspondent event folder
361 AliDebug(1, Form("detector name = %s, Ev. Fold. Name is %s.",
362 obj->GetName(),eventfolder));
364 TObject* foundobj = GetTopFolder()->FindObject(eventfolder);
365 TFolder* evfolder = (foundobj)?dynamic_cast<TFolder*>(foundobj):0x0;
368 AliFatal(Form("Can not find folder %s while adding detector %s",eventfolder,obj->GetName()));
371 CreateDetectorFolders(evfolder, obj->GetName(), obj->GetTitle());
373 // CreateDetectorTasks(obj->GetName(),obj->GetTitle());
376 //____________________________________________________________________________
378 Int_t AliConfig::CreateDetectorFolders(const char* evntfoldername,const char *name, const char* title)
380 //creates a folders for detector named 'name' and titled 'title'
381 //in a event folder named 'evntfoldername'
382 //list of folder names where new folders are created is defined in fDetectorFolder array
383 //detector folders are named 'name' and titled 'title' as well
385 TFolder* evfolder = dynamic_cast<TFolder*>(GetTopFolder()->FindObject(evntfoldername));
388 AliError(Form("Can not find folder %s while adding detector %s",evntfoldername,name));
391 return CreateDetectorFolders(evfolder,name,title);
393 //____________________________________________________________________________
394 Int_t AliConfig::CreateDetectorFolders(TFolder* evntfolder,const char *name, const char* title)
396 //creates a folders for detector named 'name' and titled 'title'
397 //in a event folder 'evntfolder'
398 //list of folder names where new folders are created is defined in fDetectorFolder array
399 //detector folders are named 'name' and titled 'title' as well
400 //Here we add only detector not an modules
403 Int_t i = 0;//iterator
404 while(!fDetectorFolder[i].IsNull())
406 tmp = AddSubFolder(evntfolder,fDetectorFolder[i],name,title);
409 AliError(Form("Failed to create subfolder of %s for detector %s",fDetectorFolder[i].Data(),name));
416 //____________________________________________________________________________
417 Int_t AliConfig::CreateDetectorTasks(const char *name, const char* title)
419 // Creates new detector's task "name"
422 while (i < kDetTaskLast)
424 tmp = AddSubTask(fgkTasksFolderName+"/"+fDetectorTask[i],
425 name+fDetectorTask[i],(fDetectorTask[i]+" for ")+title);
428 AliError(Form("Error occured while creating task for %s in %s.",
429 name,fDetectorTask[i-1].Data()));
437 //____________________________________________________________________________
438 void AliConfig::Add (char *list)
440 // Adds space separated list of objects to the
441 // configuration macro (?)
444 const char *confPath = gSystem->Getenv ("ALICE_CONFIG_PATH");
446 path = new char[strlen (confPath)];
447 strcpy (path, confPath);
449 const char *alice = gSystem->Getenv ("ALICE_ROOT");
450 path = new char[strlen (alice) + 32];
454 strcat (path, alice);
456 strcat (path, "/macros/config");
459 char *token = strtok (path, ":");
461 TList *dirlist = new TList;
463 while (token != NULL)
465 dirlist->Add (new TObjString(token));
466 token = strtok (NULL, ":");
469 token = strtok (list, " ");
471 while (token != NULL)
473 AliInfo(Form("Configuring token=%s",token));
476 TIter next (dirlist);
477 TString found = "\0";
479 while ((obj = next ()))
481 TString dir(obj->GetName());
482 TString apath = dir + "/" + token;
483 TString macro = apath + ".C";
484 if (!gSystem->AccessPathName (macro.Data()))
486 gInterpreter->ExecuteMacro (macro.Data());
487 found = "(" + macro + ")";
488 if (macro.Contains("/"))
490 TString dirname = gSystem->DirName(macro.Data());
491 TString macroConfigure = dirname + "/Configure.C";
492 if (!gSystem->AccessPathName (macroConfigure.Data()))
494 gInterpreter->ExecuteMacro (macroConfigure.Data());
495 found += " => Configured";
502 TString macroDefault = apath + "/Default.C";
503 if (!gSystem->AccessPathName (macroDefault.Data()))
505 gInterpreter->ExecuteMacro (macroDefault.Data());
506 found = "(" + macro + ")";
507 TString macroConfigure = apath + "/Configure.C";
508 if (!gSystem->AccessPathName (macroConfigure.Data()))
510 gInterpreter->ExecuteMacro (macroConfigure.Data());
511 found += " => Configured";
518 if (strlen(found.Data()))
520 AliInfo(Form("found=%s => OK",found.Data()));
524 AliError(" => FAILED.");
528 token = strtok (NULL," ");
531 if (dirlist) delete dirlist;
535 /*****************************************************************************/
537 TFolder* AliConfig::BuildEventFolder(const char* name,const char* title)
540 creates the folder structure for one event
551 | | Modules(detector objects)
561 | | | | Hits(object;e.g. tree)
564 | | | | SDigits(object)
567 | | | | Digits(object)
570 | | | | RecPoints(object)
578 | | | Hits(object;e.g. tree)
581 | | | SDigits(object)
587 | | | RecPoints(object)
597 Event2_ (to be merged with event)
599 | Modules(detector objects)
609 | | | Hits(object;e.g. tree)
612 | | | SDigits(object)
618 | | | RecPoints(object)
626 | | Hits(object;e.g. tree)
635 | | RecPoints(object)
644 TFolder* eventfolder = fTopFolder->AddFolder(name,title);
647 eventfolder->AddFolder(fgkModuleFolderName, "Detector objects");
649 eventfolder->AddFolder(fgkDataFolderName, "Detector data");
652 TFolder *conditions = eventfolder->AddFolder(fgkConditionsFolderName, "Run conditions");
653 conditions->AddFolder(fgkCalibrationFolderName,"Detector calibration data");
654 conditions->AddFolder(fgkAligmentFolderName,"Detector aligment");
655 conditions->AddFolder(fgkQAFolderName,"Quality Asurance Output"); //Folder with output of the QA task(s)
657 TFolder *configuration = eventfolder->AddFolder(fgkConfigurationFolderName, "Run configuration");
658 configuration->AddFolder(fgkFieldFolderName, "Magnetic field maps");
659 configuration->AddFolder(fgkGeneratorsFolderName,"list of generator objects");
660 configuration->AddFolder(fgkVirtualMCFolderName,"the Virtual MC");
662 eventfolder->AddFolder(fgkHeaderFolderName,"MonteCarlo event header");
664 eventfolder->SetOwner();
669 /*****************************************************************************/
671 TString AliConfig::GetQATaskName() const
674 return fDetectorTask[kDetTaskQA];
676 /*****************************************************************************/
678 TString AliConfig::GetDigitizerTaskName() const
681 return fDetectorTask[kDetTaskDigitizer];
683 /*****************************************************************************/
685 TString AliConfig::GetSDigitizerTaskName() const
688 return fDetectorTask[kDetTaskSDigitizer];
690 /*****************************************************************************/
692 TString AliConfig::GetReconstructionerTaskName() const
695 return fDetectorTask[kDetTaskRecontructioner];
697 /*****************************************************************************/
699 TString AliConfig::GetTrackerTaskName() const
702 return fDetectorTask[kDetTaskTracker];
704 /*****************************************************************************/
706 TString AliConfig::GetPIDTaskName() const
709 return fDetectorTask[kDetTaskPID];
711 /*****************************************************************************/
713 const TString& AliConfig::GetQAFolderName() const
715 //returns pathname of folder with QA output relative to Top Alice Folder
716 return fDetectorFolder[kDetFolderQA];
718 /*****************************************************************************/
720 const TString& AliConfig::GetDataFolderName() const
722 //returns name of data folder path relative to event folder
723 return fgkDataFolderName;
725 /*****************************************************************************/
727 Int_t AliConfig::AddSubFolder(TFolder* topfolder, const char* infoler,
728 const char* newfoldname, const char* newfoldtitle)
731 //in topfolder looks for folder named 'infolder'
732 //and if it exist it creates inside a new folder named 'newfoldname' and titled 'newfoldtitle'
734 if (topfolder == 0x0)//check if exists top folder
736 AliError("Parameter TFolder* points to NULL.");
743 folder = dynamic_cast<TFolder*>(topfolder->FindObject(infoler));
744 if (folder == 0x0) //check if we got inolder
746 AliError(Form("Can not find folder %s in folder %s.",infoler,topfolder->GetName()));
749 obj = folder->FindObject(newfoldname); //see if such a subfolder already exists
750 if (obj == 0x0) //nope
752 TFolder *newfolder = folder->AddFolder(newfoldname,newfoldtitle);//add the desired subfolder
753 if (newfolder == 0x0) //check if we managed
755 AliError(Form("Can not create folder %s in folder %s",newfoldname,infoler));
758 else return 0;//success
760 //such an object already exists
761 TFolder* fol = dynamic_cast<TFolder*>(obj);
764 AliError(Form("Object named %s already exists in folder %s AND IT IS NOT A FOLDER",newfoldname,infoler));
767 AliWarning(Form("Folder named %s already exists in folder %s",newfoldname,infoler));