]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliConfig.cxx
Completely Updated (Mario Sitta)
[u/mrichter/AliRoot.git] / STEER / AliConfig.cxx
index 2064e8a9ac6b0d0ee64b380bc7ab1db4ce686bec..b77967f2e9fd3b45ca0ef46bce0e445ec48397f4 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.5  2002/10/14 14:57:32  hristov
-Merging the VirtualMC branch to the main development branch (HEAD)
-
-Revision 1.3.8.1  2002/06/10 14:43:06  hristov
-Merged with v3-08-02
-
-Revision 1.4  2002/05/27 14:26:59  hristov
-New folder for track references added
-
-Revision 1.3  2001/10/04 15:30:56  hristov
-Changes to accommodate the set of PHOS folders and tasks (Y.Schutz)
-
-Revision 1.2  2001/05/21 17:22:50  buncic
-Fixed problem with missing AliConfig while reading galice.root
-
-Revision 1.1  2001/05/16 14:57:22  alibrary
-New files for folders and Stack
-
-*/
+/* $Id$ */
+
+//  Description:
+//  This class is responsible for creating folder structure
+//  All stuff of aliroot sits in one folder with name defined by
+//  fgkTopFolderName data wich do not very trough event to event are
+//  sitting in directly in "top folder" all data which changes from
+//  event to event are sitting in one folder (which has more subfolders)
+//  Idea is to have more than one event in folder structure which allows
+//  usage of standard procedures in merging
+//  Add(AliDetector*) calls Add(AliModule*) as AliDetector is a AliModule
+//  as well and should be listed in module list
 
-#include <Riostream.h>
 #include <TDatabasePDG.h>
 #include <TFolder.h>
 #include <TInterpreter.h>
+#include <TObjString.h>
 #include <TROOT.h>
+#include <TString.h>
 #include <TSystem.h>
+#include <TTask.h>
+#include <TVirtualMC.h>
 
 #include "AliConfig.h"
 #include "AliDetector.h"
 #include "AliGenerator.h" 
-#include "TObjString.h" 
-#include "TString.h"
-#include "TTask.h" 
-
+#include "AliLoader.h"
+#include "AliLog.h"
+
+enum 
+ {
+  kDetTaskQA = 0,
+  kDetTaskSDigitizer,
+  kDetTaskDigitizer,
+  kDetTaskRecontructioner,
+  kDetTaskTracker,
+  kDetTaskPID,
+  kDetTaskLast
+ };
+
+enum
+ {
+   kDetFolderData = 0,
+   kDetFolderCalibration,
+   kDetFolderAligmnet,
+   kDetFolderQA,
+   kDetFolderLast
+ };
 ClassImp(AliConfig)
 
-AliConfig* AliConfig::fInstance = 0;
+AliConfig* AliConfig::fgInstance = 0;
+
+//0 level folder
+const TString AliConfig::fgkTopFolderName("Folders");
+
+//1st level folder
+const TString AliConfig::fgkTasksFolderName("Tasks"); //task folder, commn
+const TString AliConfig::fgkConstantsFolderName("Constants");
+const TString AliConfig::fgkDefaultEventFolderName("Event");  //default folder for event, always used except merging
+
+//2st level folder
+//subfolder of event folder
+const TString AliConfig::fgkDataFolderName("Data");//folder for data (hits, digits, points, tracks) grouped by detectors
+const TString AliConfig::fgkModuleFolderName("Modules");//folder with modules objects
+const TString AliConfig::fgkConditionsFolderName("Conditions");//folder with conditions (mag. field etc.)
+const TString AliConfig::fgkConfigurationFolderName("Configuration");//folder with configuration (setup) of the detector
+const TString AliConfig::fgkHeaderFolderName("Header");//folder with header and other MC information
+
+//Tasks names, goes into fgkTasksFolderName folder
+const TString AliConfig::fgkDigitizerTaskName("Digitizer");
+const TString AliConfig::fgkSDigitizerTaskName("SDigitizer");
+const TString AliConfig::fgkReconstructionerTaskName("Reconstructioner");
+const TString AliConfig::fgkTrackerTaskName("Tracker");
+const TString AliConfig::fgkPIDTaskName("PIDTask");//;=) PIDer???
+const TString AliConfig::fgkQATaskName("QAtask");
+
+//3rd level folder
+//fgkConditionsFolderName subfolders
+const TString AliConfig::fgkCalibrationFolderName("Calibration");
+const TString AliConfig::fgkAligmentFolderName("Aligment");
+const TString AliConfig::fgkQAFolderName("QAout");
+  
+//3rd level folder
+//fgkConfigurationFolderName subfolders
+const TString AliConfig::fgkFieldFolderName("Field");
+const TString AliConfig::fgkGeneratorsFolderName("Generators");
+const TString AliConfig::fgkVirtualMCFolderName("VirtualMC");
+
+
+const TString AliConfig::fgkPDGFolderName("Constants/DatabasePDG");//folder with PDG Database
+const TString AliConfig::fgkGeneratorFolderName("Configuration/Generators");//folder with generators
+const TString AliConfig::fgkMCFolderName("Configuration/VirtualMC");
 
 //____________________________________________________________________________
 AliConfig* AliConfig::Instance ()
@@ -59,235 +112,172 @@ AliConfig* AliConfig::Instance ()
   //
   // Instance method for singleton class
   //
-  if(!fInstance) fInstance = new AliConfig ("Folders","Alice data exchange");
-
-  return fInstance;
+   if(fgInstance == 0) 
+    {
+     fgInstance = new AliConfig (fgkTopFolderName,"Alice data exchange board");
+    }
+   return fgInstance;
 }
 
 //____________________________________________________________________________
-AliConfig::AliConfig(): TNamed("","")
+AliConfig::AliConfig():
+  fTopFolder(0x0),
+  fTaskFolder(0x0),
+  fConstFolder(0x0),
+  fDetectorTask(0x0),
+  fDetectorFolder(0x0)
 {
   //
   // Default constructor, mainly to keep coding conventions
   //
-  fTopFolder=0;
-  fTasks=0;
-
-  fPDGFolder=0; 
-  fGeneratorFolder=0; 
-  fMCFolder=0; 
-  fModuleFolder=0; 
-  fDetectorFolder=0;
-  fDetectorTask=0; 
-  fInstance=0;
-    
-  Fatal("ctor",
-   "Constructor should not be called for a singleton\n");
+  fgInstance=0;//never mind, its going to exit in next step
+  AliFatal("Constructor should not be called for a singleton");
 }
-
 //____________________________________________________________________________
-AliConfig::AliConfig(const AliConfig&): TNamed("","")
+
+AliConfig::AliConfig(const AliConfig& conf):
+  TNamed(conf),
+  fTopFolder(0x0),
+  fTaskFolder(0x0),
+  fConstFolder(0x0),
+  fDetectorTask(0x0),
+  fDetectorFolder(0x0)
 {
   //
   // Copy constructor, mainly to keep coding conventions
   //
-  fTopFolder=0;
-  fTasks=0;
-
-  fPDGFolder=0; 
-  fGeneratorFolder=0; 
-  fMCFolder=0; 
-  fModuleFolder=0; 
-  fDetectorFolder=0;
-  fDetectorTask=0; 
-  fInstance=0;
+  fgInstance=0;
     
-  Fatal("copy ctor",
-   "Copy constructor should not be called for a singleton\n");
+  AliFatal("Copy constructor should not be called for a singleton");
 }
+//____________________________________________________________________________
 
+AliConfig& AliConfig::operator=(const AliConfig& /*conf*/)
+{
+  //
+  // Assignment, mainly to keep coding conventions
+  //
+  fgInstance=0;
+    
+  AliFatal("Assignment operator should not be called for a singleton");
+  return *this;
+}
 //____________________________________________________________________________
+
 AliConfig::AliConfig(const char *name, const char *title): 
   TNamed(name,title), 
-  fTopFolder(gROOT->GetRootFolder ()->AddFolder (name,title)),
-  fTasks(0),
-  fPDGFolder("Constants/DatabasePDG"),
-  fGeneratorFolder("RunMC/Configuration/Generators"),
-  fMCFolder("RunMC/Configuration/VirtualMC"),
-  fModuleFolder("Run/Configuration/Modules"),
-  fDetectorFolder(new char*[kFolders]),
-  fDetectorTask(new char*[kTasks])
+  fTopFolder(gROOT->GetRootFolder()->AddFolder(name,title)),
+  fTaskFolder(fTopFolder->AddFolder(fgkTasksFolderName, "ALICE Tasks")),
+  fConstFolder(0x0),
+  fDetectorTask(0x0),
+  fDetectorFolder(new TString[kDetFolderLast+1])
 {
-  //
-  // Constructor
-  //
-  fInstance=this;
-  
-  fDetectorFolder[0] = "Run/Conditions/Calibration" ;
-  fDetectorFolder[1] = "Run/Event/Data" ;
-  fDetectorFolder[2] = "Run/Event/RecData" ;
-  fDetectorFolder[3] = "RunMC/Event/Data/Hits" ;
-  fDetectorFolder[4] = "RunMC/Event/Data/SDigits" ;
-  fDetectorFolder[5] = "Run/Conditions/QA" ;  
-  fDetectorFolder[6] = "RunMC/Event/Data/TrackReferences" ;  
-  fDetectorFolder[7] = 0 ;  
-  fDetectorTask[0] = "Tasks/QA" ;  
-  fDetectorTask[1] = "Tasks/SDigitizer" ;  
-  fDetectorTask[2] = "Tasks/Digitizer" ;  
-  fDetectorTask[3] = "Tasks/Reconstructioner" ;  
-  fDetectorTask[4] = 0 ;  
-
-  fTopFolder->SetOwner() ; 
-  gROOT->GetListOfBrowsables ()->Add (fTopFolder, name);
-  
-  TFolder *subfolder;
-  
-  TFolder *constants =
-    fTopFolder->AddFolder ("Constants", "Detector constants");
-  
-  subfolder = 
-    constants->AddFolder ("DatabasePDG", "PDG database");
-  
-  TFolder *run = 
-    fTopFolder->AddFolder ("Run", "Run dependent folders");
-  
-  TFolder *conditions = 
-    run->AddFolder ("Conditions", "Run conditions");
-  
-  subfolder =
-    conditions->AddFolder ("Calibration","Detector calibration data");
-  
-  subfolder =
-    conditions->AddFolder ("Aligment", "Detector aligment");
-  
-  subfolder =
-    conditions->AddFolder ("QA", "Detector QA");
-  
-  TFolder *configuration =
-    run->AddFolder ("Configuration", "Run configuration");
-  
-  subfolder =
-    configuration->AddFolder ("Modules", "Detector objects");
-  
-  subfolder =
-    configuration->AddFolder ("Field", "Magnetic field maps");
-  
-  TFolder *event = 
-    run->AddFolder ("Event", "Event folders");
-  
-  subfolder = 
-    event->AddFolder ("Data", "Detector raw data");
-  
-  subfolder =
-    event->AddFolder ("RecData", "Detectors reconstucted data");
-  
-  TFolder *run_mc =
-    fTopFolder->AddFolder ("RunMC", "MonteCarlo run dependent folders");
-  
-  TFolder *configuration_mc =
-    run_mc->AddFolder ("Configuration","MonteCarlo run configuration");
-  
-  subfolder =
-    configuration_mc->AddFolder ("Generators","list of generator objects");
-  
-  subfolder =
-    configuration_mc->AddFolder ("VirtualMC", "the Virtual MC");
-  
-  TFolder *event_mc =
-    run_mc->AddFolder ("Event", "MonteCarlo event folders");
-  
-  subfolder =
-    event_mc->AddFolder ("Header", "MonteCarlo event header");
-  
-  //           subfolder =
-  //               event_mc->AddFolder ("Kinematics", "MonteCarlo generated particles");
+// Constructor
+
+  //Main AliRoot Folder
+  if (fTopFolder == 0x0)
+   {
+     AliFatal("Can not create Top Alice Folder.");
+     return;//never reached
+   }
+  fTopFolder->SetOwner();
   
-  TFolder *data_mc =
-    event_mc->AddFolder ("Data", "MonteCarlo data");
+  fDetectorFolder[kDetFolderData] = fgkDataFolderName;
+  fDetectorFolder[kDetFolderCalibration] = fgkConditionsFolderName+"/"+fgkCalibrationFolderName;
+  fDetectorFolder[kDetFolderAligmnet] = fgkConditionsFolderName+"/"+fgkAligmentFolderName;
+  fDetectorFolder[kDetFolderQA] = fgkConditionsFolderName+"/"+fgkQAFolderName;
+  fDetectorFolder[kDetFolderLast] = "";
   
-  subfolder = 
-    data_mc->AddFolder ("Hits", "MonteCarlo Hits") ; 
- subfolder = 
-    data_mc->AddFolder ("SDigits", "MonteCarlo SDigits") ; 
-
- subfolder = 
-    data_mc->AddFolder ("TrackReferences", "MonteCarlo track references") ; 
-
+  gROOT->GetListOfBrowsables()->Add(fTopFolder, name);
 
+  //Constants folder
+  fConstFolder = fTopFolder->AddFolder (fgkConstantsFolderName, "Constant parameters");
+  fConstFolder->AddFolder("DatabasePDG", "PDG database");
   
   // Add the tasks to //Folders
   
-  TFolder * tasksfolder = fTopFolder->AddFolder("Tasks", "ALICE Tasks") ; 
-  
-  TTask * qa = new TTask("QA", "Alice QA tasks") ;
-  tasksfolder->Add(qa); 
-  
-  TTask * sd = new TTask("SDigitizer", "Alice SDigitizer") ;
-  tasksfolder->Add(sd); 
-
-  TTask * di = new TTask("Digitizer", "Alice Digitizer") ;
-  tasksfolder->Add(di); 
-
-  TTask * re = new TTask("Reconstructioner", "Alice Reconstructioner") ;
-  tasksfolder->Add(re); 
-
+  TTask * qa = new TTask(fgkQATaskName, "Alice QA tasks");
+  fTaskFolder->Add(qa); 
+  TTask * sd = new TTask(fgkSDigitizerTaskName, "Alice SDigitizer") ;
+  fTaskFolder->Add(sd); 
+  TTask * di = new TTask(fgkDigitizerTaskName, "Alice Digitizer") ;
+  fTaskFolder->Add(di); 
+  TTask * re = new TTask(fgkReconstructionerTaskName, "Alice Reconstructioner") ;
+  fTaskFolder->Add(re); 
+  TTask * tr = new TTask(fgkTrackerTaskName,"Alice Tracker");
+  fTaskFolder->Add(tr);
+  TTask * pid = new TTask(fgkPIDTaskName,"Alice Particle Identification Task");
+  fTaskFolder->Add(pid);
+  fDetectorTask    =  new TString[kDetTaskLast+1];
+  
+  fDetectorTask[kDetTaskQA] = fgkQATaskName;
+  fDetectorTask[kDetTaskSDigitizer] = fgkSDigitizerTaskName;
+  fDetectorTask[kDetTaskDigitizer] =  fgkDigitizerTaskName;
+  fDetectorTask[kDetTaskRecontructioner] = fgkReconstructionerTaskName;
+  fDetectorTask[kDetTaskTracker] = fgkTrackerTaskName;
+  fDetectorTask[kDetTaskPID] = fgkPIDTaskName;
+  fDetectorTask[kDetTaskLast] = "";
+
+  fgInstance=this;
 }
 
 //____________________________________________________________________________
 AliConfig::~AliConfig()
 { 
+  // destructor
   delete [] fDetectorFolder ;  
-  delete fDetectorTask ;  
-  delete fTopFolder ; 
+  delete [] fDetectorTask;
+  if (fTopFolder)
+   {
+    fTopFolder->SetOwner();
+    delete fTopFolder; 
+   }
 }
-
 //____________________________________________________________________________
-void AliConfig::AddInFolder (char *dir, TObject *obj)
+
+void AliConfig::AddInFolder (const char *dir, TObject *obj)
 {
-  TFolder *folder =
-    dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
+  // Adds object "obj" to folder "dir"
+  TFolder *folder = dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
   if (folder)
     folder->Add (static_cast<TObject *>(obj));
 }
-
 //____________________________________________________________________________
-void    AliConfig::AddSubFolder(char * dir[], TObject *obj)
-{
-  int iDir = 0;
-  
-  while (dir[iDir]) 
-    {
-      TFolder * folder = dynamic_cast<TFolder *>(fTopFolder->FindObject (dir[iDir++]));
-      if (folder) {
-       TFolder * subfolder = dynamic_cast<TFolder *>(folder->FindObject (obj->GetName()));
-       if (!subfolder)
-         subfolder = folder->AddFolder (obj->GetName(),obj->GetTitle());                          
-      }
-    }
-}
 
-//____________________________________________________________________________
-void    AliConfig::AddSubTask(char * dir[], TObject *obj)
+Int_t AliConfig::AddSubTask(const char *taskname, const char* name,const char* title)
 {
-  int iDir = 0;
-  
-  while (dir[iDir]) 
-    {
-      TTask * task = dynamic_cast<TTask *>(fTopFolder->FindObject (dir[iDir++]));
-      if (task) {
-       TTask * subtask = static_cast<TTask*>(task->GetListOfTasks()->FindObject (obj->GetName()));
-       if (!subtask) {
-         subtask = new TTask(obj->GetName(), obj->GetTitle()) ; 
-         task->Add(subtask);                      
-       }
-      }
-    }
+//Create new task named 'name' and titled 'title' 
+//as a subtask of the task named 'taskname'
+
+   AliDebug(1, Form("Try to get folder named %s",taskname));
+   TObject* obj = fTopFolder->FindObject(taskname);
+   TTask * task = (obj)?dynamic_cast<TTask*>(obj):0x0;
+   if (task)
+     {
+      AliDebug(1, "          Got");
+      TTask * subtask = static_cast<TTask*>(task->GetListOfTasks()->FindObject(name));
+      if (!subtask) 
+        {
+          subtask = new TTask(name,title);
+          task->Add(subtask);
+        }
+      else
+       {
+         AliWarning(Form("Task named \"%s\" already exists in Task %s",name,taskname));
+       }
+     }
+   else
+     {
+       AliError(Form("Can not find task %s to put a new task in.",taskname));
+       return 1;
+     }
+  return 0;
 }
 
 //____________________________________________________________________________
-TObject* AliConfig::FindInFolder (char *dir, const char *name)
+TObject* AliConfig::FindInFolder (const char *dir, const char *name)
 {
+  // Finds object with name "name" in folder "dir"
   if(!name) return(fTopFolder->FindObject(name));
   TFolder * folder = dynamic_cast<TFolder *>(fTopFolder->FindObject(dir));
   if (!folder) return (NULL);
@@ -295,46 +285,166 @@ TObject* AliConfig::FindInFolder (char *dir, const char *name)
 }
 
 //____________________________________________________________________________
-void    AliConfig::Add (AliGenerator * obj)
+void    AliConfig::Add (AliGenerator * obj,const char* eventfolder)
 {
-  AddInFolder(fGeneratorFolder, obj);
+  // Adds generator "obj" to the event folder "eventfolder"
+  TString path(eventfolder);
+  path = path + "/" + fgkGeneratorsFolderName;
+  AddInFolder(path,obj);
 }
 
 //____________________________________________________________________________
-void    AliConfig::Add (AliMC * obj)
+void AliConfig::Add (TVirtualMC * obj,const char* eventfolder)
 {
-  AddInFolder(fMCFolder, obj);
+  // Adds TVirtualMC object to the event folder
+  TString path(eventfolder);
+  path = path + "/" + fgkMCFolderName;
+  AddInFolder(path, obj);
 }
 
 //____________________________________________________________________________
-void    AliConfig::Add (TDatabasePDG * obj)
+void  AliConfig::Add (TDatabasePDG * obj)
 {
-  AddInFolder(fPDGFolder, obj);
+  // Adds TDataBase object
+  AddInFolder(fgkPDGFolderName, obj);
 }
 
 //____________________________________________________________________________
-void    AliConfig::Add (AliModule* obj)
+void AliConfig::Add(AliModule* obj,const char* eventfolder)
 {
-  AddInFolder(fModuleFolder, obj);
+  // Adds module to the event folder
+  TString path(eventfolder);
+  path = path + "/" + fgkModuleFolderName;
+  AliDebug(1, Form("module name = %s, Ev. Fold. Name is %s.",
+                  obj->GetName(),eventfolder));
+  AddInFolder(path, obj);
 }
+//____________________________________________________________________________
 
+Int_t AliConfig::AddDetector(TFolder* evntfolder, const char *name, const char* title)
+{
+//creates folders and tasks for the detector 'name'
+ Int_t retval;//returned value
+ retval = CreateDetectorFolders(evntfolder,name,title);
+ if (retval)
+  {
+    AliError(Form("CreateDetectorFolders returned error for detector %s",name));
+    return retval;
+  }
+ return 0; 
+}
 //____________________________________________________________________________
-void    AliConfig::Add (AliDetector * obj)
+
+Int_t AliConfig::AddDetector(const char* evntfoldername,const char *name, const char* title)
 {
-  AddSubFolder(fDetectorFolder, obj); 
-  AddSubTask(fDetectorTask, obj);
+//creates folders and tasks for the detector 'name'
+ Int_t retval;//returned value
+ retval = CreateDetectorFolders(evntfoldername,name,title);
+ if (retval)
+  {
+    AliError(Form("CreateDetectorFolders returned error for detector %s",name));
+    return retval;
+  }
+// retval = CreateDetectorTasks(name,title);
+// if (retval)
+//  {
+//    Error("AddDetector","CreateDetectorTasks returned error for detector %s",name);
+//    return retval;
+//  }
+ return 0; 
 }
+//____________________________________________________________________________
 
+void  AliConfig::Add(AliDetector * obj,const char* eventfolder)
+{
+  // Adds new AliDetector objest to the correspondent event folder
+  AliDebug(1, Form("detector name = %s, Ev. Fold. Name is %s.",
+                  obj->GetName(),eventfolder));
+
+  TObject* foundobj = GetTopFolder()->FindObject(eventfolder);
+  TFolder* evfolder = (foundobj)?dynamic_cast<TFolder*>(foundobj):0x0;
+  if (evfolder == 0x0)
+   {
+     AliFatal(Form("Can not find folder %s while adding detector %s",eventfolder,obj->GetName()));
+     return;
+   } 
+  CreateDetectorFolders(evfolder, obj->GetName(), obj->GetTitle());
+  
+//  CreateDetectorTasks(obj->GetName(),obj->GetTitle());
+
+}
+//____________________________________________________________________________
+
+Int_t  AliConfig::CreateDetectorFolders(const char* evntfoldername,const char *name, const char* title)
+{
+//creates a folders for detector named 'name' and titled 'title'
+//in a event folder named 'evntfoldername'
+//list of folder names where new folders are created is defined in fDetectorFolder array 
+//detector folders are named 'name' and titled 'title' as well
+
+ TFolder* evfolder = dynamic_cast<TFolder*>(GetTopFolder()->FindObject(evntfoldername));
+ if (evfolder == 0x0)
+  {
+   AliError(Form("Can not find folder %s while adding detector %s",evntfoldername,name));
+   return 1;
+  }
+ return CreateDetectorFolders(evfolder,name,title);
+}
+//____________________________________________________________________________
+Int_t  AliConfig::CreateDetectorFolders(TFolder* evntfolder,const char *name, const char* title)
+{
+//creates a folders for detector named 'name' and titled 'title'
+//in a event folder 'evntfolder'
+//list of folder names where new folders are created is defined in fDetectorFolder array 
+//detector folders are named 'name' and titled 'title' as well
+//Here we add only detector not an modules
+ Int_t tmp;
+ Int_t i = 0;//iterator
+ while(!fDetectorFolder[i].IsNull())
+  {
+    tmp = AddSubFolder(evntfolder,fDetectorFolder[i],name,title);
+    if (tmp)
+     {
+      AliError(Form("Failed to create subfolder of %s for detector %s",fDetectorFolder[i].Data(),name));
+      return 1;
+     }
+    i++;
+  }
+ return 0;
+}
+//____________________________________________________________________________
+Int_t AliConfig::CreateDetectorTasks(const char *name, const char* title)
+{
+  // Creates new detector's task "name"
+   Int_t i = 0;
+   Int_t tmp;
+   while (i < kDetTaskLast)
+    {
+      tmp = AddSubTask(fgkTasksFolderName+"/"+fDetectorTask[i],
+                       name+fDetectorTask[i],(fDetectorTask[i]+" for ")+title);
+      if (tmp)
+       {
+         AliError(Form("Error occured while creating task for %s in %s.",
+                      name,fDetectorTask[i-1].Data()));
+         return 1;
+       }
+      i++;
+    }
+   return 0;
+}
 
 //____________________________________________________________________________
 void    AliConfig::Add (char *list)
 {
+  // Adds space separated list of objects to the
+  // configuration macro (?)
   char *path;
   
-  const char   *conf_path = gSystem->Getenv ("ALICE_CONFIG_PATH");
-  if  (conf_path) {
-    path = new char[strlen (conf_path)];
-    strcpy (path, conf_path);
+  const char   *confPath = gSystem->Getenv ("ALICE_CONFIG_PATH");
+  if  (confPath) {
+    path = new char[strlen (confPath)];
+    strcpy (path, confPath);
   } else {
     const char   *alice = gSystem->Getenv ("ALICE_ROOT");
     path = new char[strlen (alice) + 32];
@@ -359,57 +469,301 @@ void    AliConfig::Add (char *list)
   token = strtok (list, " ");
   
   while (token != NULL)
-    {
-      cout << "Configuring " << token << ": ";
+    { 
+      AliInfo(Form("Configuring token=%s",token));
       
       TObject *obj;
       TIter   next (dirlist);
       TString found = "\0";
       
       while ((obj = next ()))
-       {
-         TString dir(obj->GetName());
-         TString path  = dir + "/" + token;
-         TString macro = path + ".C";
-         if (!gSystem->AccessPathName (macro.Data()))  {
-           gInterpreter->ExecuteMacro (macro.Data());                             
-           found = "(" + macro + ")";
-           if (macro.Contains("/")) {
-             TString dirname = gSystem->DirName(macro.Data());
-             TString macroConfigure = dirname + "/Configure.C";
-             if (!gSystem->AccessPathName (macroConfigure.Data()))     {
-               gInterpreter->ExecuteMacro (macroConfigure.Data());                                 
-               found += " => Configured";
-             }                       
-           }
-           break;
-         } else {
-           TString macroDefault = path + "/Default.C";
-           if (!gSystem->AccessPathName (macroDefault.Data())) {
-             gInterpreter->ExecuteMacro (macroDefault.Data());
-             found = "(" + macro + ")";
-             TString macroConfigure = path + "/Configure.C";
-             if (!gSystem->AccessPathName (macroConfigure.Data()))     {
-               gInterpreter->ExecuteMacro (macroConfigure.Data());                                 
-               found += " => Configured";
-             }
-             break;                                
-           }
-         }
-       }
+        {
+          TString dir(obj->GetName());
+          TString apath  = dir + "/" + token;
+          TString macro = apath + ".C";
+          if (!gSystem->AccessPathName (macro.Data())) 
+           {
+            gInterpreter->ExecuteMacro (macro.Data());                            
+            found = "(" + macro + ")";
+            if (macro.Contains("/")) 
+             {
+               TString dirname = gSystem->DirName(macro.Data());
+               TString macroConfigure = dirname + "/Configure.C";
+               if (!gSystem->AccessPathName (macroConfigure.Data()))
+                {
+                  gInterpreter->ExecuteMacro (macroConfigure.Data());                              
+                  found += " => Configured";
+                }                            
+             }
+            break;
+           } 
+          else 
+           {
+            TString macroDefault = apath + "/Default.C";
+            if (!gSystem->AccessPathName (macroDefault.Data()))
+              {
+                gInterpreter->ExecuteMacro (macroDefault.Data());
+                found = "(" + macro + ")";
+                TString macroConfigure = apath + "/Configure.C";
+                if (!gSystem->AccessPathName (macroConfigure.Data()))  
+                  {
+                    gInterpreter->ExecuteMacro (macroConfigure.Data());                                    
+                    found += " => Configured";
+                  }
+                break;                                     
+              }
+           }
+        }
       
-      if (strlen(found.Data())) {
-       cout << found << " => OK" << endl;
-      } else {
-       cout << " => FAILED." << endl;
-       exit(1); 
-      }            
+      if (strlen(found.Data())) 
+        {
+          AliInfo(Form("found=%s  => OK",found.Data()));
+        } 
+      else 
+        {
+          AliError(" => FAILED.");
+          exit(1); 
+        }          
       
-      token = strtok (NULL, " ");
+      token = strtok (NULL," ");
     }
   
   if (dirlist) delete dirlist;
   
 }
 
+/*****************************************************************************/
 
+TFolder* AliConfig::BuildEventFolder(const char* name,const char* title)
+{
+/*
+ creates the folder structure for one event
+ TopFolder_
+         | \
+         |  Tasks
+         |_
+         | \
+         |  Constants
+         |_
+         | \
+         |  Event_
+         |      | \
+         |      |  Modules(detector objects)
+         |      |_
+         |      | \              
+         |      |  Header
+         |      |_
+         |      | \              
+         |      |  Data_
+         |      |     | \ 
+         |      |     |  TPC_
+         |      |     |    | \
+         |      |     |    |  Hits(object;e.g. tree)
+         |      |     |    |_  
+         |      |     |    | \ 
+         |      |     |    |  SDigits(object)
+         |      |     |    |_
+         |      |     |    | \ 
+         |      |     |    |  Digits(object)
+         |      |     |    |_
+         |      |     |    | \ 
+         |      |     |    |  RecPoints(object)
+         |      |     |    |_
+         |      |     |      \ 
+         |      |     |       Tracks(object)
+         |      |     |_ 
+         |      |       \
+         |      |        ITS_
+         |      |          | \
+         |      |          |  Hits(object;e.g. tree)
+         |      |          |_  
+         |      |          | \ 
+         |      |          |  SDigits(object)
+         |      |          |_
+         |      |          | \ 
+         |      |          |  Digits(object)
+         |      |          |_
+         |      |          | \ 
+         |      |          |  RecPoints(object)
+         |      |          |_
+         |      |            \ 
+         |      |             Tracks(object)
+         |      |_         
+         |        \       
+         |         Configuration
+         |               
+         |_
+           \
+            Event2_  (to be merged with event)
+                |  \
+                |   Modules(detector objects)
+                |_
+                | \              
+                |  Header
+                |_
+                | \              
+                |  Data_
+                |     | \ 
+                |     |  TPC_
+                |     |    | \
+                |     |    |  Hits(object;e.g. tree)
+                |     |    |_  
+                |     |    | \ 
+                |     |    |  SDigits(object)
+                |     |    |_
+                |     |    | \ 
+                |     |    |  Digits(object)
+                |     |    |_
+                |     |    | \ 
+                |     |    |  RecPoints(object)
+                |     |    |_
+                |     |      \ 
+                |     |       Tracks(object)
+                |     |_ 
+                |       \
+                |        ITS_
+                |          | \
+                |          |  Hits(object;e.g. tree)
+                |          |_  
+                |          | \ 
+                |          |  SDigits(object)
+                |          |_
+                |          | \ 
+                |          |  Digits(object)
+                |          |_
+                |          | \ 
+                |          |  RecPoints(object)
+                |          |_
+                |            \ 
+                |             Tracks(object)
+                |_         
+                  \       
+                   Configuration
+                         
+*/
+  TFolder* eventfolder = fTopFolder->AddFolder(name,title); 
+   
+  //modules
+  eventfolder->AddFolder(fgkModuleFolderName, "Detector objects");
+  //event data
+  eventfolder->AddFolder(fgkDataFolderName, "Detector data");
+  
+    //Conditions
+  TFolder *conditions = eventfolder->AddFolder(fgkConditionsFolderName, "Run conditions");
+  conditions->AddFolder(fgkCalibrationFolderName,"Detector calibration data");
+  conditions->AddFolder(fgkAligmentFolderName,"Detector aligment");
+  conditions->AddFolder(fgkQAFolderName,"Quality Asurance Output"); //Folder with output of the QA task(s)
+  //Configuration
+  TFolder *configuration = eventfolder->AddFolder(fgkConfigurationFolderName, "Run configuration");
+  configuration->AddFolder(fgkFieldFolderName, "Magnetic field maps");
+  configuration->AddFolder(fgkGeneratorsFolderName,"list of generator objects");
+  configuration->AddFolder(fgkVirtualMCFolderName,"the Virtual MC");
+
+  eventfolder->AddFolder(fgkHeaderFolderName,"MonteCarlo event header");
+
+  eventfolder->SetOwner();
+
+  return eventfolder;
+}
+
+/*****************************************************************************/
+
+TString AliConfig::GetQATaskName() const
+ {
+ //returns task name
+  return fDetectorTask[kDetTaskQA];
+ }
+/*****************************************************************************/
+TString AliConfig::GetDigitizerTaskName() const
+ {
+ //returns task name
+  return fDetectorTask[kDetTaskDigitizer];
+ }
+/*****************************************************************************/
+TString AliConfig::GetSDigitizerTaskName() const
+ {
+ //returns task name
+  return fDetectorTask[kDetTaskSDigitizer];
+ }
+/*****************************************************************************/
+
+TString AliConfig::GetReconstructionerTaskName() const
+ {
+ //returns task name
+  return fDetectorTask[kDetTaskRecontructioner];
+ }
+/*****************************************************************************/
+
+TString AliConfig::GetTrackerTaskName() const
+ {
+ //returns task name
+  return fDetectorTask[kDetTaskTracker];
+ }
+/*****************************************************************************/
+
+TString AliConfig::GetPIDTaskName() const
+ {
+ //returns task name
+  return fDetectorTask[kDetTaskPID];
+ }
+/*****************************************************************************/
+
+const TString& AliConfig::GetQAFolderName() const
+{
+//returns pathname of folder with QA output relative to Top Alice Folder
+  return fDetectorFolder[kDetFolderQA];
+}
+/*****************************************************************************/
+
+const TString& AliConfig::GetDataFolderName() const
+{
+//returns name of data folder path relative to event folder
+ return fgkDataFolderName;
+}
+/*****************************************************************************/
+
+Int_t AliConfig::AddSubFolder(TFolder* topfolder, const char* infoler, 
+                     const char* newfoldname, const char* newfoldtitle)
+{
+//helper method
+//in topfolder looks for folder named 'infolder'
+//and if it exist it creates inside a new folder named 'newfoldname' and titled 'newfoldtitle'
+
+ if (topfolder == 0x0)//check if exists top folder
+  {
+   AliError("Parameter TFolder* points to NULL.");
+   return 1;
+  }
+ TObject *obj;
+ TFolder* folder;
+ folder = dynamic_cast<TFolder*>(topfolder->FindObject(infoler));
+ if (folder == 0x0) //check if we got inolder
+  {
+   AliError(Form("Can not find folder %s in folder %s.",infoler,topfolder->GetName()));
+   return 1;
+  }
+ obj = folder->FindObject(newfoldname); //see if such a subfolder already exists
+ if (obj == 0x0) //nope
+  {
+   TFolder *newfolder = folder->AddFolder(newfoldname,newfoldtitle);//add the desired subfolder
+   if (newfolder == 0x0) //check if we managed
+    {
+     AliError(Form("Can not create folder %s in folder %s",newfoldname,infoler));
+     return 2;
+    }
+   else return 0;//success
+  }
+ //such an object already exists
+ TFolder* fol = dynamic_cast<TFolder*>(obj);
+ if (fol == 0x0)
+   {
+     AliError(Form("Object named %s already exists in folder %s AND IT IS NOT A FOLDER",newfoldname,infoler));
+     return 3;
+   }
+ AliWarning(Form("Folder named %s already exists in folder %s",newfoldname,infoler));
+ return 0;
+}