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");
121 //____________________________________________________________________________
123 AliConfig::AliConfig(const char *name, const char *title):
125 fTopFolder(gROOT->GetRootFolder()->AddFolder(name,title)),
126 fTaskFolder(fTopFolder->AddFolder(fgkTasksFolderName, "ALICE Tasks")),
129 fDetectorFolder(new TString[kDetFolderLast+1])
133 //Main AliRoot Folder
134 if (fTopFolder == 0x0)
136 AliFatal("Can not create Top Alice Folder.");
137 return;//never reached
139 fTopFolder->SetOwner();
141 fDetectorFolder[kDetFolderData] = fgkDataFolderName;
142 fDetectorFolder[kDetFolderCalibration] = fgkConditionsFolderName+"/"+fgkCalibrationFolderName;
143 fDetectorFolder[kDetFolderAligmnet] = fgkConditionsFolderName+"/"+fgkAligmentFolderName;
144 fDetectorFolder[kDetFolderQA] = fgkConditionsFolderName+"/"+fgkQAFolderName;
145 fDetectorFolder[kDetFolderLast] = "";
147 gROOT->GetListOfBrowsables()->Add(fTopFolder, name);
150 fConstFolder = fTopFolder->AddFolder (fgkConstantsFolderName, "Constant parameters");
151 fConstFolder->AddFolder("DatabasePDG", "PDG database");
153 // Add the tasks to //Folders
155 TTask * qa = new TTask(fgkQATaskName, "Alice QA tasks");
156 fTaskFolder->Add(qa);
157 TTask * sd = new TTask(fgkSDigitizerTaskName, "Alice SDigitizer") ;
158 fTaskFolder->Add(sd);
159 TTask * di = new TTask(fgkDigitizerTaskName, "Alice Digitizer") ;
160 fTaskFolder->Add(di);
161 TTask * re = new TTask(fgkReconstructionerTaskName, "Alice Reconstructioner") ;
162 fTaskFolder->Add(re);
163 TTask * tr = new TTask(fgkTrackerTaskName,"Alice Tracker");
164 fTaskFolder->Add(tr);
165 TTask * pid = new TTask(fgkPIDTaskName,"Alice Particle Identification Task");
166 fTaskFolder->Add(pid);
167 fDetectorTask = new TString[kDetTaskLast+1];
169 fDetectorTask[kDetTaskQA] = fgkQATaskName;
170 fDetectorTask[kDetTaskSDigitizer] = fgkSDigitizerTaskName;
171 fDetectorTask[kDetTaskDigitizer] = fgkDigitizerTaskName;
172 fDetectorTask[kDetTaskRecontructioner] = fgkReconstructionerTaskName;
173 fDetectorTask[kDetTaskTracker] = fgkTrackerTaskName;
174 fDetectorTask[kDetTaskPID] = fgkPIDTaskName;
175 fDetectorTask[kDetTaskLast] = "";
180 //____________________________________________________________________________
181 AliConfig::~AliConfig()
184 delete [] fDetectorFolder ;
185 delete [] fDetectorTask;
188 fTopFolder->SetOwner();
192 //____________________________________________________________________________
194 void AliConfig::AddInFolder (const char *dir, TObject *obj)
196 // Adds object "obj" to folder "dir"
197 TFolder *folder = dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
199 folder->Add (static_cast<TObject *>(obj));
201 //____________________________________________________________________________
203 Int_t AliConfig::AddSubTask(const char *taskname, const char* name,const char* title)
205 //Create new task named 'name' and titled 'title'
206 //as a subtask of the task named 'taskname'
208 AliDebug(1, Form("Try to get folder named %s",taskname));
209 TObject* obj = fTopFolder->FindObject(taskname);
210 TTask * task = (obj)?dynamic_cast<TTask*>(obj):0x0;
214 TTask * subtask = static_cast<TTask*>(task->GetListOfTasks()->FindObject(name));
217 subtask = new TTask(name,title);
222 AliWarning(Form("Task named \"%s\" already exists in Task %s",name,taskname));
227 AliError(Form("Can not find task %s to put a new task in.",taskname));
233 //____________________________________________________________________________
234 TObject* AliConfig::FindInFolder (const char *dir, const char *name)
236 // Finds object with name "name" in folder "dir"
237 if(!name) return(fTopFolder->FindObject(name));
238 TFolder * folder = dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
239 if (!folder) return (NULL);
240 return(folder->FindObject(name));
243 //____________________________________________________________________________
244 void AliConfig::Add (AliGenerator * obj,const char* eventfolder)
246 // Adds generator "obj" to the event folder "eventfolder"
247 TString path(eventfolder);
248 path = path + "/" + fgkGeneratorsFolderName;
249 AddInFolder(path,obj);
252 //____________________________________________________________________________
253 void AliConfig::Add (TVirtualMC * obj,const char* eventfolder)
255 // Adds TVirtualMC object to the event folder
256 TString path(eventfolder);
257 path = path + "/" + fgkMCFolderName;
258 AddInFolder(path, obj);
261 //____________________________________________________________________________
262 void AliConfig::Add (TDatabasePDG * obj)
264 // Adds TDataBase object
265 AddInFolder(fgkPDGFolderName, obj);
268 //____________________________________________________________________________
269 void AliConfig::Add(AliModule* obj,const char* eventfolder)
271 // Adds module to the event folder
272 TString path(eventfolder);
273 path = path + "/" + fgkModuleFolderName;
274 AliDebug(1, Form("module name = %s, Ev. Fold. Name is %s.",
275 obj->GetName(),eventfolder));
276 AddInFolder(path, obj);
278 //____________________________________________________________________________
280 Int_t AliConfig::AddDetector(TFolder* evntfolder, const char *name, const char* title)
282 //creates folders and tasks for the detector 'name'
283 Int_t retval;//returned value
284 retval = CreateDetectorFolders(evntfolder,name,title);
287 AliError(Form("CreateDetectorFolders returned error for detector %s",name));
292 //____________________________________________________________________________
294 Int_t AliConfig::AddDetector(const char* evntfoldername,const char *name, const char* title)
296 //creates folders and tasks for the detector 'name'
297 Int_t retval;//returned value
298 retval = CreateDetectorFolders(evntfoldername,name,title);
301 AliError(Form("CreateDetectorFolders returned error for detector %s",name));
304 // retval = CreateDetectorTasks(name,title);
307 // Error("AddDetector","CreateDetectorTasks returned error for detector %s",name);
312 //____________________________________________________________________________
314 void AliConfig::Add(AliDetector * obj,const char* eventfolder)
316 // Adds new AliDetector objest to the correspondent event folder
317 AliDebug(1, Form("detector name = %s, Ev. Fold. Name is %s.",
318 obj->GetName(),eventfolder));
320 TObject* foundobj = GetTopFolder()->FindObject(eventfolder);
321 TFolder* evfolder = (foundobj)?dynamic_cast<TFolder*>(foundobj):0x0;
324 AliFatal(Form("Can not find folder %s while adding detector %s",eventfolder,obj->GetName()));
327 CreateDetectorFolders(evfolder, obj->GetName(), obj->GetTitle());
329 // CreateDetectorTasks(obj->GetName(),obj->GetTitle());
332 //____________________________________________________________________________
334 Int_t AliConfig::CreateDetectorFolders(const char* evntfoldername,const char *name, const char* title)
336 //creates a folders for detector named 'name' and titled 'title'
337 //in a event folder named 'evntfoldername'
338 //list of folder names where new folders are created is defined in fDetectorFolder array
339 //detector folders are named 'name' and titled 'title' as well
341 TFolder* evfolder = dynamic_cast<TFolder*>(GetTopFolder()->FindObject(evntfoldername));
344 AliError(Form("Can not find folder %s while adding detector %s",evntfoldername,name));
347 return CreateDetectorFolders(evfolder,name,title);
349 //____________________________________________________________________________
350 Int_t AliConfig::CreateDetectorFolders(TFolder* evntfolder,const char *name, const char* title)
352 //creates a folders for detector named 'name' and titled 'title'
353 //in a event folder 'evntfolder'
354 //list of folder names where new folders are created is defined in fDetectorFolder array
355 //detector folders are named 'name' and titled 'title' as well
356 //Here we add only detector not an modules
359 Int_t i = 0;//iterator
360 while(!fDetectorFolder[i].IsNull())
362 tmp = AddSubFolder(evntfolder,fDetectorFolder[i],name,title);
365 AliError(Form("Failed to create subfolder of %s for detector %s",fDetectorFolder[i].Data(),name));
372 //____________________________________________________________________________
373 Int_t AliConfig::CreateDetectorTasks(const char *name, const char* title)
375 // Creates new detector's task "name"
378 while (i < kDetTaskLast)
380 tmp = AddSubTask(fgkTasksFolderName+"/"+fDetectorTask[i],
381 name+fDetectorTask[i],(fDetectorTask[i]+" for ")+title);
384 AliError(Form("Error occured while creating task for %s in %s.",
385 name,fDetectorTask[i-1].Data()));
393 //____________________________________________________________________________
394 void AliConfig::Add (char *list)
396 // Adds space separated list of objects to the
397 // configuration macro (?)
400 const char *confPath = gSystem->Getenv ("ALICE_CONFIG_PATH");
402 path = new char[strlen (confPath)];
403 strcpy (path, confPath);
405 const char *alice = gSystem->Getenv ("ALICE_ROOT");
406 path = new char[strlen (alice) + 32];
410 strcat (path, alice);
412 strcat (path, "/macros/config");
415 char *token = strtok (path, ":");
417 TList *dirlist = new TList;
419 while (token != NULL)
421 dirlist->Add (new TObjString(token));
422 token = strtok (NULL, ":");
425 token = strtok (list, " ");
427 while (token != NULL)
429 AliInfo(Form("Configuring token=%s",token));
432 TIter next (dirlist);
433 TString found = "\0";
435 while ((obj = next ()))
437 TString dir(obj->GetName());
438 TString apath = dir + "/" + token;
439 TString macro = apath + ".C";
440 if (!gSystem->AccessPathName (macro.Data()))
442 gInterpreter->ExecuteMacro (macro.Data());
443 found = "(" + macro + ")";
444 if (macro.Contains("/"))
446 TString dirname = gSystem->DirName(macro.Data());
447 TString macroConfigure = dirname + "/Configure.C";
448 if (!gSystem->AccessPathName (macroConfigure.Data()))
450 gInterpreter->ExecuteMacro (macroConfigure.Data());
451 found += " => Configured";
458 TString macroDefault = apath + "/Default.C";
459 if (!gSystem->AccessPathName (macroDefault.Data()))
461 gInterpreter->ExecuteMacro (macroDefault.Data());
462 found = "(" + macro + ")";
463 TString macroConfigure = apath + "/Configure.C";
464 if (!gSystem->AccessPathName (macroConfigure.Data()))
466 gInterpreter->ExecuteMacro (macroConfigure.Data());
467 found += " => Configured";
474 if (strlen(found.Data()))
476 AliInfo(Form("found=%s => OK",found.Data()));
480 AliError(" => FAILED.");
484 token = strtok (NULL," ");
487 if (dirlist) delete dirlist;
491 /*****************************************************************************/
493 TFolder* AliConfig::BuildEventFolder(const char* name,const char* title)
496 creates the folder structure for one event
507 | | Modules(detector objects)
517 | | | | Hits(object;e.g. tree)
520 | | | | SDigits(object)
523 | | | | Digits(object)
526 | | | | RecPoints(object)
534 | | | Hits(object;e.g. tree)
537 | | | SDigits(object)
543 | | | RecPoints(object)
553 Event2_ (to be merged with event)
555 | Modules(detector objects)
565 | | | Hits(object;e.g. tree)
568 | | | SDigits(object)
574 | | | RecPoints(object)
582 | | Hits(object;e.g. tree)
591 | | RecPoints(object)
600 TFolder* eventfolder = fTopFolder->AddFolder(name,title);
603 eventfolder->AddFolder(fgkModuleFolderName, "Detector objects");
605 eventfolder->AddFolder(fgkDataFolderName, "Detector data");
608 TFolder *conditions = eventfolder->AddFolder(fgkConditionsFolderName, "Run conditions");
609 conditions->AddFolder(fgkCalibrationFolderName,"Detector calibration data");
610 conditions->AddFolder(fgkAligmentFolderName,"Detector aligment");
611 conditions->AddFolder(fgkQAFolderName,"Quality Asurance Output"); //Folder with output of the QA task(s)
613 TFolder *configuration = eventfolder->AddFolder(fgkConfigurationFolderName, "Run configuration");
614 configuration->AddFolder(fgkFieldFolderName, "Magnetic field maps");
615 configuration->AddFolder(fgkGeneratorsFolderName,"list of generator objects");
616 configuration->AddFolder(fgkVirtualMCFolderName,"the Virtual MC");
618 eventfolder->AddFolder(fgkHeaderFolderName,"MonteCarlo event header");
620 eventfolder->SetOwner();
625 /*****************************************************************************/
627 TString AliConfig::GetQATaskName() const
630 return fDetectorTask[kDetTaskQA];
632 /*****************************************************************************/
634 TString AliConfig::GetDigitizerTaskName() const
637 return fDetectorTask[kDetTaskDigitizer];
639 /*****************************************************************************/
641 TString AliConfig::GetSDigitizerTaskName() const
644 return fDetectorTask[kDetTaskSDigitizer];
646 /*****************************************************************************/
648 TString AliConfig::GetReconstructionerTaskName() const
651 return fDetectorTask[kDetTaskRecontructioner];
653 /*****************************************************************************/
655 TString AliConfig::GetTrackerTaskName() const
658 return fDetectorTask[kDetTaskTracker];
660 /*****************************************************************************/
662 TString AliConfig::GetPIDTaskName() const
665 return fDetectorTask[kDetTaskPID];
667 /*****************************************************************************/
669 const TString& AliConfig::GetQAFolderName() const
671 //returns pathname of folder with QA output relative to Top Alice Folder
672 return fDetectorFolder[kDetFolderQA];
674 /*****************************************************************************/
676 const TString& AliConfig::GetDataFolderName() const
678 //returns name of data folder path relative to event folder
679 return fgkDataFolderName;
681 /*****************************************************************************/
683 Int_t AliConfig::AddSubFolder(TFolder* topfolder, const char* infoler,
684 const char* newfoldname, const char* newfoldtitle)
687 //in topfolder looks for folder named 'infolder'
688 //and if it exist it creates inside a new folder named 'newfoldname' and titled 'newfoldtitle'
690 if (topfolder == 0x0)//check if exists top folder
692 AliError("Parameter TFolder* points to NULL.");
699 folder = dynamic_cast<TFolder*>(topfolder->FindObject(infoler));
700 if (folder == 0x0) //check if we got inolder
702 AliError(Form("Can not find folder %s in folder %s.",infoler,topfolder->GetName()));
705 obj = folder->FindObject(newfoldname); //see if such a subfolder already exists
706 if (obj == 0x0) //nope
708 TFolder *newfolder = folder->AddFolder(newfoldname,newfoldtitle);//add the desired subfolder
709 if (newfolder == 0x0) //check if we managed
711 AliError(Form("Can not create folder %s in folder %s",newfoldname,infoler));
714 else return 0;//success
716 //such an object already exists
717 TFolder* fol = dynamic_cast<TFolder*>(obj);
720 AliError(Form("Object named %s already exists in folder %s AND IT IS NOT A FOLDER",newfoldname,infoler));
723 AliWarning(Form("Folder named %s already exists in folder %s",newfoldname,infoler));