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):
145 // Copy constructor, mainly to keep coding conventions
150 "Copy constructor should not be called for a singleton\n");
152 //____________________________________________________________________________
154 AliConfig::AliConfig(const char *name, const char *title):
156 fTopFolder(gROOT->GetRootFolder()->AddFolder(name,title)),
157 fTaskFolder(fTopFolder->AddFolder(fgkTasksFolderName, "ALICE Tasks")),
160 fDetectorFolder(new TString[kDetFolderLast+1])
164 //Main AliRoot Folder
165 if (fTopFolder == 0x0)
167 Fatal("AliConfig(const char*, const char*)","Can not create Top Alice Folder.");
168 return;//never reached
170 fTopFolder->SetOwner();
172 fDetectorFolder[kDetFolderData] = fgkDataFolderName;
173 fDetectorFolder[kDetFolderCalibration] = fgkConditionsFolderName+"/"+fgkCalibrationFolderName;
174 fDetectorFolder[kDetFolderAligmnet] = fgkConditionsFolderName+"/"+fgkAligmentFolderName;
175 fDetectorFolder[kDetFolderQA] = fgkConditionsFolderName+"/"+fgkQAFolderName;
176 fDetectorFolder[kDetFolderLast] = "";
178 gROOT->GetListOfBrowsables()->Add(fTopFolder, name);
181 TFolder *fConstFolder = fTopFolder->AddFolder (fgkConstantsFolderName, "Constant parameters");
182 fConstFolder->AddFolder("DatabasePDG", "PDG database");
184 // Add the tasks to //Folders
186 TTask * qa = new TTask(fgkQATaskName, "Alice QA tasks");
187 fTaskFolder->Add(qa);
188 TTask * sd = new TTask(fgkSDigitizerTaskName, "Alice SDigitizer") ;
189 fTaskFolder->Add(sd);
190 TTask * di = new TTask(fgkDigitizerTaskName, "Alice Digitizer") ;
191 fTaskFolder->Add(di);
192 TTask * re = new TTask(fgkReconstructionerTaskName, "Alice Reconstructioner") ;
193 fTaskFolder->Add(re);
194 TTask * tr = new TTask(fgkTrackerTaskName,"Alice Tracker");
195 fTaskFolder->Add(tr);
196 TTask * pid = new TTask(fgkPIDTaskName,"Alice Particle Identification Task");
197 fTaskFolder->Add(pid);
198 fDetectorTask = new TString[kDetTaskLast+1];
200 fDetectorTask[kDetTaskQA] = fgkQATaskName;
201 fDetectorTask[kDetTaskSDigitizer] = fgkSDigitizerTaskName;
202 fDetectorTask[kDetTaskDigitizer] = fgkDigitizerTaskName;
203 fDetectorTask[kDetTaskRecontructioner] = fgkReconstructionerTaskName;
204 fDetectorTask[kDetTaskTracker] = fgkTrackerTaskName;
205 fDetectorTask[kDetTaskPID] = fgkPIDTaskName;
206 fDetectorTask[kDetTaskLast] = "";
211 //____________________________________________________________________________
212 AliConfig::~AliConfig()
214 delete [] fDetectorFolder ;
215 delete [] fDetectorTask;
218 fTopFolder->SetOwner();
222 //____________________________________________________________________________
224 void AliConfig::AddInFolder (const char *dir, TObject *obj)
226 TFolder *folder = dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
228 folder->Add (static_cast<TObject *>(obj));
230 //____________________________________________________________________________
232 Int_t AliConfig::AddSubTask(const char *taskname, const char* name,const char* title)
234 //Create new task named 'name' and titled 'title'
235 //as a subtask of the task named 'taskname'
237 if (AliLoader::fgDebug) Info("AddSubTask","Try to get folder named %s",taskname);
238 TObject* obj = fTopFolder->FindObject(taskname);
239 TTask * task = (obj)?dynamic_cast<TTask*>(obj):0x0;
242 if (AliLoader::fgDebug) Info("AddSubTask"," Got");
243 TTask * subtask = static_cast<TTask*>(task->GetListOfTasks()->FindObject(name));
246 subtask = new TTask(name,title);
251 Warning("AddSubTask","Task named \"%s\" already exists in Task %s\n",name,taskname);
256 Error("AddSubTask","Can not find task %s to put a new task in.",taskname);
262 //____________________________________________________________________________
263 TObject* AliConfig::FindInFolder (const char *dir, const char *name)
265 if(!name) return(fTopFolder->FindObject(name));
266 TFolder * folder = dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
267 if (!folder) return (NULL);
268 return(folder->FindObject(name));
271 //____________________________________________________________________________
272 void AliConfig::Add (AliGenerator * obj,const char* eventfolder)
274 TString path(eventfolder);
275 path = path + "/" + fgkGeneratorsFolderName;
276 AddInFolder(path,obj);
279 //____________________________________________________________________________
280 void AliConfig::Add (TVirtualMC * obj,const char* eventfolder)
282 TString path(eventfolder);
283 path = path + "/" + fgkMCFolderName;
284 AddInFolder(path, obj);
287 //____________________________________________________________________________
288 void AliConfig::Add (TDatabasePDG * obj)
290 AddInFolder(fgkPDGFolderName, obj);
293 //____________________________________________________________________________
294 void AliConfig::Add(AliModule* obj,const char* eventfolder)
297 TString path(eventfolder);
298 path = path + "/" + fgkModuleFolderName;
299 if (AliLoader::fgDebug)
300 Info("Add(AliModule*)","module name = %s, Ev. Fold. Name is %s.",
301 obj->GetName(),eventfolder);
302 AddInFolder(path, obj);
304 //____________________________________________________________________________
306 Int_t AliConfig::AddDetector(TFolder* evntfolder, const char *name, const char* title)
308 //creates folders and tasks for the detector 'name'
309 Int_t retval;//returned value
310 retval = CreateDetectorFolders(evntfolder,name,title);
313 Error("AddDetector","CreateDetectorFolders returned error for detector %s",name);
318 //____________________________________________________________________________
320 Int_t AliConfig::AddDetector(const char* evntfoldername,const char *name, const char* title)
322 //creates folders and tasks for the detector 'name'
323 Int_t retval;//returned value
324 retval = CreateDetectorFolders(evntfoldername,name,title);
327 Error("AddDetector","CreateDetectorFolders returned error for detector %s",name);
330 // retval = CreateDetectorTasks(name,title);
333 // Error("AddDetector","CreateDetectorTasks returned error for detector %s",name);
338 //____________________________________________________________________________
340 void AliConfig::Add(AliDetector * obj,const char* eventfolder)
342 if (AliLoader::fgDebug)
343 Info("Add(AliDetector*)","detector name = %s, Ev. Fold. Name is %s.",
344 obj->GetName(),eventfolder);
346 TObject* foundobj = GetTopFolder()->FindObject(eventfolder);
347 TFolder* evfolder = (foundobj)?dynamic_cast<TFolder*>(foundobj):0x0;
350 Fatal("Add(AliDetector * obj,const char* eventfolder)",
351 "Can not find folder %s while adding detector %s",eventfolder,obj->GetName());
354 CreateDetectorFolders(evfolder, obj->GetName(), obj->GetTitle());
356 // CreateDetectorTasks(obj->GetName(),obj->GetTitle());
359 //____________________________________________________________________________
361 Int_t AliConfig::CreateDetectorFolders(const char* evntfoldername,const char *name, const char* title)
363 //creates a folders for detector named 'name' and titled 'title'
364 //in a event folder named 'evntfoldername'
365 //list of folder names where new folders are created is defined in fDetectorFolder array
366 //detector folders are named 'name' and titled 'title' as well
368 TFolder* evfolder = dynamic_cast<TFolder*>(GetTopFolder()->FindObject(evntfoldername));
371 Error("CreateDetectorFolders",
372 "Can not find folder %s while adding detector %s",evntfoldername,name);
375 return CreateDetectorFolders(evfolder,name,title);
377 //____________________________________________________________________________
378 Int_t AliConfig::CreateDetectorFolders(TFolder* evntfolder,const char *name, const char* title)
380 //creates a folders for detector named 'name' and titled 'title'
381 //in a event folder 'evntfolder'
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
384 //Here we add only detector not an modules
387 Int_t i = 0;//iterator
388 while(!fDetectorFolder[i].IsNull())
390 tmp = AddSubFolder(evntfolder,fDetectorFolder[i],name,title);
393 Error("AddDetector(TFolder*","Failed to create subfolder of %s for detector %s",fDetectorFolder[i].Data(),name);
400 //____________________________________________________________________________
401 Int_t AliConfig::CreateDetectorTasks(const char *name, const char* title)
405 while (i < kDetTaskLast)
407 tmp = AddSubTask(fgkTasksFolderName+"/"+fDetectorTask[i],
408 name+fDetectorTask[i],(fDetectorTask[i]+" for ")+title);
411 Error("CreateDetectorTasks","Error occured while creating task for %s in %s.",
412 name,fDetectorTask[i-1].Data());
420 //____________________________________________________________________________
421 void AliConfig::Add (char *list)
425 const char *conf_path = gSystem->Getenv ("ALICE_CONFIG_PATH");
427 path = new char[strlen (conf_path)];
428 strcpy (path, conf_path);
430 const char *alice = gSystem->Getenv ("ALICE_ROOT");
431 path = new char[strlen (alice) + 32];
435 strcat (path, alice);
437 strcat (path, "/macros/config");
440 char *token = strtok (path, ":");
442 TList *dirlist = new TList;
444 while (token != NULL)
446 dirlist->Add (new TObjString(token));
447 token = strtok (NULL, ":");
450 token = strtok (list, " ");
452 while (token != NULL)
454 Info("Add(char *list)","Configuring token=%s",token);
457 TIter next (dirlist);
458 TString found = "\0";
460 while ((obj = next ()))
462 TString dir(obj->GetName());
463 TString path = dir + "/" + token;
464 TString macro = path + ".C";
465 if (!gSystem->AccessPathName (macro.Data()))
467 gInterpreter->ExecuteMacro (macro.Data());
468 found = "(" + macro + ")";
469 if (macro.Contains("/"))
471 TString dirname = gSystem->DirName(macro.Data());
472 TString macroConfigure = dirname + "/Configure.C";
473 if (!gSystem->AccessPathName (macroConfigure.Data()))
475 gInterpreter->ExecuteMacro (macroConfigure.Data());
476 found += " => Configured";
483 TString macroDefault = path + "/Default.C";
484 if (!gSystem->AccessPathName (macroDefault.Data()))
486 gInterpreter->ExecuteMacro (macroDefault.Data());
487 found = "(" + macro + ")";
488 TString macroConfigure = path + "/Configure.C";
489 if (!gSystem->AccessPathName (macroConfigure.Data()))
491 gInterpreter->ExecuteMacro (macroConfigure.Data());
492 found += " => Configured";
499 if (strlen(found.Data()))
501 Info("Add(char *list)","found=%s => OK",found.Data());
505 Error("Add(char *list)"," => FAILED.");
509 token = strtok (NULL," ");
512 if (dirlist) delete dirlist;
516 /*****************************************************************************/
518 TFolder* AliConfig::BuildEventFolder(const char* name,const char* title)
521 creates the folder structure for one event
532 | | Modules(detector objects)
542 | | | | Hits(object;e.g. tree)
545 | | | | SDigits(object)
548 | | | | Digits(object)
551 | | | | RecPoints(object)
559 | | | Hits(object;e.g. tree)
562 | | | SDigits(object)
568 | | | RecPoints(object)
578 Event2_ (to be merged with event)
580 | Modules(detector objects)
590 | | | Hits(object;e.g. tree)
593 | | | SDigits(object)
599 | | | RecPoints(object)
607 | | Hits(object;e.g. tree)
616 | | RecPoints(object)
625 TFolder* eventfolder = fTopFolder->AddFolder(name,title);
628 eventfolder->AddFolder(fgkModuleFolderName, "Detector objects");
630 eventfolder->AddFolder(fgkDataFolderName, "Detector data");
633 TFolder *conditions = eventfolder->AddFolder(fgkConditionsFolderName, "Run conditions");
634 conditions->AddFolder(fgkCalibrationFolderName,"Detector calibration data");
635 conditions->AddFolder(fgkAligmentFolderName,"Detector aligment");
636 conditions->AddFolder(fgkQAFolderName,"Quality Asurance Output"); //Folder with output of the QA task(s)
638 TFolder *configuration = eventfolder->AddFolder(fgkConfigurationFolderName, "Run configuration");
639 configuration->AddFolder(fgkFieldFolderName, "Magnetic field maps");
640 configuration->AddFolder(fgkGeneratorsFolderName,"list of generator objects");
641 configuration->AddFolder(fgkVirtualMCFolderName,"the Virtual MC");
643 eventfolder->AddFolder(fgkHeaderFolderName,"MonteCarlo event header");
645 eventfolder->SetOwner();
650 /*****************************************************************************/
652 TString AliConfig::GetQATaskName() const
655 return fDetectorTask[kDetTaskQA];
657 /*****************************************************************************/
659 TString AliConfig::GetDigitizerTaskName() const
662 return fDetectorTask[kDetTaskDigitizer];
664 /*****************************************************************************/
666 TString AliConfig::GetSDigitizerTaskName() const
669 return fDetectorTask[kDetTaskSDigitizer];
671 /*****************************************************************************/
673 TString AliConfig::GetReconstructionerTaskName() const
676 return fDetectorTask[kDetTaskRecontructioner];
678 /*****************************************************************************/
680 TString AliConfig::GetTrackerTaskName() const
683 return fDetectorTask[kDetTaskTracker];
685 /*****************************************************************************/
687 TString AliConfig::GetPIDTaskName() const
690 return fDetectorTask[kDetTaskPID];
692 /*****************************************************************************/
694 const TString& AliConfig::GetQAFolderName() const
696 //returns pathname of folder with QA output relative to Top Alice Folder
697 return fDetectorFolder[kDetFolderQA];
699 /*****************************************************************************/
701 const TString& AliConfig::GetDataFolderName()
703 //returns name of data folder path relative to event folder
704 return fgkDataFolderName;
706 /*****************************************************************************/
708 Int_t AliConfig::AddSubFolder(TFolder* topfolder, const char* infoler,
709 const char* newfoldname, const char* newfoldtitle)
712 //in topfolder looks for folder named 'infolder'
713 //and if it exist it creates inside a new folder named 'newfoldname' and titled 'newfoldtitle'
715 if (topfolder == 0x0)//check if exists top folder
717 Error("AddSubFodler(TFolder*, ....","Parameter TFolder* points to NULL.");
724 folder = dynamic_cast<TFolder*>(topfolder->FindObject(infoler));
725 if (folder == 0x0) //check if we got inolder
727 Error("AddSubFodler(TFolder*, ....","Can not find folder %s in folder %s.",infoler,topfolder->GetName());
730 obj = folder->FindObject(newfoldname); //see if such a subfolder already exists
731 if (obj == 0x0) //nope
733 TFolder *newfolder = folder->AddFolder(newfoldname,newfoldtitle);//add the desired subfolder
734 if (newfolder == 0x0) //check if we managed
736 Error("AddSubFodler(TFolder*, ....","Can not create folder %s in folder %s",newfoldname,infoler);
739 else return 0;//success
741 //such an object already exists
742 TFolder* fol = dynamic_cast<TFolder*>(obj);
745 Error("AddSubFodler(TFolder*, ....",
746 "Object named %s already exists in folder %s AND IT IS NOT A FOLDER",newfoldname,infoler);
749 Warning("AddSubFodler(TFolder*, ....",
750 "Folder named %s already exists in folder %s",newfoldname,infoler);