]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Reverting the last changes, they are incompatible with PHOS and EMCAL Getters
authorhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 28 Jan 2004 10:33:56 +0000 (10:33 +0000)
committerhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 28 Jan 2004 10:33:56 +0000 (10:33 +0000)
STEER/AliSimulation.cxx
STEER/AliSimulation.h

index 853df4ef9b4ad3d091d745bc7bf2cd89acf5714b..8b8cddf1abfc4d6de9c6de115ab3b0e2fc53ce88 100644 (file)
@@ -30,8 +30,7 @@
 //                                                                           //
 //   sim.SetNumberOfEvents(n);                                               //
 //                                                                           //
-// The name of the configuration file can be passed as argument to the       //
-// AliSimulation constructor or can be specified by                          //
+// The name of the configuration file can be specified by                    //
 //                                                                           //
 //   sim.SetConfigFile("...");                                               //
 //                                                                           //
 // to merge more than two event streams. It is assumed that the sdigits      //
 // were already produced for the background events.                          //
 //                                                                           //
-// The methods RunSimulation, RunSDigitization, RunDigitization and          //
-// RunHitsDigitization can be used to run only parts of the full simulation  //
-// chain.                                                                    //
-//                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
 
@@ -92,51 +87,37 @@ ClassImp(AliSimulation)
 
 
 //_____________________________________________________________________________
-AliSimulation::AliSimulation(const char* configFileName,
-                            const char* name, const char* title) :
-  TNamed(name, title),
-
-  fRunGeneration(kTRUE),
-  fRunSimulation(kTRUE),
-  fMakeSDigits("ALL"),
-  fMakeDigits("ALL"),
-  fMakeDigitsFromHits(""),
-  fStopOnError(kFALSE),
-
-  fNEvents(1),
-  fConfigFileName(configFileName),
-  fGAliceFileName("galice.root"),
-  fBkgrdFileNames(NULL),
-  fRegionOfInterest(kTRUE)
+AliSimulation::AliSimulation(const char* name, const char* title) :
+  TNamed(name, title)
 {
 // create simulation object with default parameters
 
+  Init();
 }
 
 //_____________________________________________________________________________
 AliSimulation::AliSimulation(const AliSimulation& sim) :
-  TNamed(sim),
-
-  fRunGeneration(sim.fRunGeneration),
-  fRunSimulation(sim.fRunSimulation),
-  fMakeSDigits(sim.fMakeSDigits),
-  fMakeDigits(sim.fMakeDigits),
-  fMakeDigitsFromHits(sim.fMakeDigitsFromHits),
-  fStopOnError(sim.fStopOnError),
-
-  fNEvents(sim.fNEvents),
-  fConfigFileName(sim.fConfigFileName),
-  fGAliceFileName(sim.fGAliceFileName),
-  fBkgrdFileNames(NULL),
-  fRegionOfInterest(sim.fRegionOfInterest)
+  TNamed(sim)
 {
 // copy constructor
 
+  fRunGeneration = sim.fRunGeneration;
+  fRunSimulation = sim.fRunSimulation;
+  fMakeSDigits = sim.fMakeSDigits;
+  fMakeDigits = sim.fMakeDigits;
+  fMakeDigitsFromHits = sim.fMakeDigitsFromHits;
+  fStopOnError = sim.fStopOnError;
+
+  fNEvents = sim.fNEvents;
+  fConfigFileName = sim.fConfigFileName;
+  fGAliceFileName = sim.fGAliceFileName;
   fBkgrdFileNames = new TObjArray;
   for (Int_t i = 0; i < sim.fBkgrdFileNames->GetEntriesFast(); i++) {
     if (!sim.fBkgrdFileNames->At(i)) continue;
     fBkgrdFileNames->Add(sim.fBkgrdFileNames->At(i)->Clone());
   }
+
+  fRunLoader = NULL;
 }
 
 //_____________________________________________________________________________
@@ -154,10 +135,29 @@ AliSimulation::~AliSimulation()
 {
 // clean up
 
-  if (fBkgrdFileNames) {
-    fBkgrdFileNames->Delete();
-    delete fBkgrdFileNames;
-  }
+  fBkgrdFileNames->Delete();
+  delete fBkgrdFileNames;
+}
+
+//_____________________________________________________________________________
+void AliSimulation::Init()
+{
+// set default parameters
+
+  fRunGeneration = kTRUE;
+  fRunSimulation = kTRUE;
+  fMakeSDigits = "ALL";
+  fMakeDigits = "ALL";
+  fMakeDigitsFromHits = "";
+  fStopOnError = kFALSE;
+
+  fNEvents = 1;
+  fConfigFileName = "Config.C";
+  fGAliceFileName = "galice.root";
+  fBkgrdFileNames = new TObjArray;
+  fRegionOfInterest = kTRUE;
+
+  fRunLoader = NULL;
 }
 
 
@@ -184,7 +184,6 @@ void AliSimulation::MergeWith(const char* fileName, Int_t nSignalPerBkgrd)
 
   TObjString* fileNameStr = new TObjString(fileName);
   fileNameStr->SetUniqueID(nSignalPerBkgrd);
-  if (!fBkgrdFileNames) fBkgrdFileNames = new TObjArray;
   fBkgrdFileNames->Add(fileNameStr);
 }
 
@@ -198,9 +197,33 @@ Bool_t AliSimulation::Run(Int_t nEvents)
 
   // generation and simulation -> hits
   if (fRunGeneration) {
+    if (!gAlice) {
+      Error("Run", "no gAlice object. Restart aliroot and try again.");
+      return kFALSE;
+    }
+    if (gAlice->Modules()->GetEntries() > 0) {
+      Error("Run", "gAlice was already run. Restart aliroot and try again.");
+      return kFALSE;
+    }
     if (!RunSimulation()) if (fStopOnError) return kFALSE;
   }
 
+  // reopen the run loader
+  if (fRunLoader) delete fRunLoader;
+  fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),AliConfig::fgkDefaultEventFolderName,"UPDATE");
+  if (!fRunLoader) {
+    Error("Run", "no run loader found in file %s", 
+         fGAliceFileName.Data());
+    return kFALSE;
+  }
+  fRunLoader->LoadgAlice();
+  gAlice = fRunLoader->GetAliRun();
+  if (!gAlice) {
+    Error("Run", "no gAlice object found in file %s", 
+         fGAliceFileName.Data());
+    return kFALSE;
+  }
+
   // hits -> summable digits
   if (!fMakeSDigits.IsNull()) {
     if (!RunSDigitization(fMakeSDigits)) if (fStopOnError) return kFALSE;
@@ -215,7 +238,7 @@ Bool_t AliSimulation::Run(Int_t nEvents)
 
   // hits -> digits
   if (!fMakeDigitsFromHits.IsNull()) {
-    if (fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
+    if (fBkgrdFileNames->GetEntriesFast() > 0) {
       Warning("Run", "Merging and direct creation of digits from hits " 
              "was selected for some detectors. "
              "No merging will be done for the following detectors: %s",
@@ -230,33 +253,23 @@ Bool_t AliSimulation::Run(Int_t nEvents)
 }
 
 //_____________________________________________________________________________
-Bool_t AliSimulation::RunSimulation(Int_t nEvents)
+Bool_t AliSimulation::RunSimulation()
 {
 // run the generation and simulation
 
   TStopwatch stopwatch;
   stopwatch.Start();
 
-  if (!gAlice) {
-    Error("RunSimulation", "no gAlice object. Restart aliroot and try again.");
-    return kFALSE;
-  }
-  if (gAlice->Modules()->GetEntries() > 0) {
-    Error("RunSimulation", 
-         "gAlice was already run. Restart aliroot and try again.");
-    return kFALSE;
-  }
-
   Info("RunSimulation", "initializing gAlice with config file %s",
        fConfigFileName.Data());
   gAlice->Init(fConfigFileName.Data());
-  AliRunLoader* runLoader = gAlice->GetRunLoader();
-  if (!runLoader) {
+  fRunLoader = gAlice->GetRunLoader();
+  if (!fRunLoader) {
     Error("RunSimulation", "gAlice has no run loader object. "
          "Check your config file: %s", fConfigFileName.Data());
     return kFALSE;
   }
-  fGAliceFileName = runLoader->GetFileName();
+  fGAliceFileName = fRunLoader->GetFileName();
 
   if (!fRunSimulation) {
     if (!gAlice->Generator()) {
@@ -268,10 +281,7 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
   }
 
   Info("RunSimulation", "running gAlice");
-  if (nEvents <= 0) nEvents = fNEvents;
-  gAlice->Run(nEvents);
-
-  delete runLoader;
+  gAlice->Run(fNEvents);
 
   Info("RunSimulation", "execution time:");
   stopwatch.Print();
@@ -280,18 +290,15 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
 }
 
 //_____________________________________________________________________________
-Bool_t AliSimulation::RunSDigitization(const char* detectors)
+Bool_t AliSimulation::RunSDigitization(const TString& detectors)
 {
 // run the digitization and produce summable digits
 
   TStopwatch stopwatch;
   stopwatch.Start();
 
-  AliRunLoader* runLoader = LoadRun();
-  if (!runLoader) return kFALSE;
-
   TString detStr = detectors;
-  TObjArray* detArray = runLoader->GetAliRun()->Detectors();
+  TObjArray* detArray = gAlice->Detectors();
   for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
     AliModule* det = (AliModule*) detArray->At(iDet);
     if (!det || !det->IsActive()) continue;
@@ -308,8 +315,6 @@ Bool_t AliSimulation::RunSDigitization(const char* detectors)
     if (fStopOnError) return kFALSE;
   }
 
-  delete runLoader;
-
   Info("RunSDigitization", "execution time:");
   stopwatch.Print();
 
@@ -318,24 +323,17 @@ Bool_t AliSimulation::RunSDigitization(const char* detectors)
 
 
 //_____________________________________________________________________________
-Bool_t AliSimulation::RunDigitization(const char* detectors, 
-                                     const char* excludeDetectors)
+Bool_t AliSimulation::RunDigitization(const TString& detectors, 
+                                     const TString& excludeDetectors)
 {
 // run the digitization and produce digits from sdigits
 
   TStopwatch stopwatch;
   stopwatch.Start();
 
-  while (AliRunLoader::GetRunLoader()) delete AliRunLoader::GetRunLoader();
-  if (gAlice) delete gAlice;
-  gAlice = NULL;
-
-  Int_t nStreams = 1;
+  Int_t nStreams = fBkgrdFileNames->GetEntriesFast() + 1;
   Int_t signalPerBkgrd = 1;
-  if (fBkgrdFileNames) {
-    nStreams = fBkgrdFileNames->GetEntriesFast() + 1;
-    if (nStreams > 1) signalPerBkgrd = fBkgrdFileNames->At(0)->GetUniqueID();
-  }
+  if (nStreams > 1) signalPerBkgrd = fBkgrdFileNames->At(0)->GetUniqueID();
   AliRunDigitizer* manager = new AliRunDigitizer(nStreams, signalPerBkgrd);
   manager->SetInputStream(0, fGAliceFileName.Data());
   for (Int_t iStream = 1; iStream < nStreams; iStream++) {
@@ -346,10 +344,7 @@ Bool_t AliSimulation::RunDigitization(const char* detectors,
 
   TString detStr = detectors;
   TString detExcl = excludeDetectors;
-  manager->GetInputStream(0)->ImportgAlice();
-  AliRunLoader* runLoader = 
-    AliRunLoader::GetRunLoader(manager->GetInputStream(0)->GetFolderName());
-  TObjArray* detArray = runLoader->GetAliRun()->Detectors();
+  TObjArray* detArray = gAlice->Detectors();
   for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
     AliModule* det = (AliModule*) detArray->At(iDet);
     if (!det || !det->IsActive()) continue;
@@ -375,7 +370,6 @@ Bool_t AliSimulation::RunDigitization(const char* detectors,
     Info("RunDigitization", "executing digitization");
     manager->Exec("");
   }
-
   delete manager;
 
   Info("RunDigitization", "execution time:");
@@ -385,18 +379,15 @@ Bool_t AliSimulation::RunDigitization(const char* detectors,
 }
 
 //_____________________________________________________________________________
-Bool_t AliSimulation::RunHitsDigitization(const char* detectors)
+Bool_t AliSimulation::RunHitsDigitization(const TString& detectors)
 {
 // run the digitization and produce digits from hits
 
   TStopwatch stopwatch;
   stopwatch.Start();
 
-  AliRunLoader* runLoader = LoadRun();
-  if (!runLoader) return kFALSE;
-
   TString detStr = detectors;
-  TObjArray* detArray = runLoader->GetAliRun()->Detectors();
+  TObjArray* detArray = gAlice->Detectors();
   for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
     AliModule* det = (AliModule*) detArray->At(iDet);
     if (!det || !det->IsActive()) continue;
@@ -413,8 +404,6 @@ Bool_t AliSimulation::RunHitsDigitization(const char* detectors)
     if (fStopOnError) return kFALSE;
   }
 
-  delete runLoader;
-
   Info("RunHitsDigitization", "execution time:");
   stopwatch.Print();
 
@@ -422,30 +411,6 @@ Bool_t AliSimulation::RunHitsDigitization(const char* detectors)
 }
 
 
-//_____________________________________________________________________________
-AliRunLoader* AliSimulation::LoadRun() const
-{
-// delete existing run loaders, open a new one and load gAlice
-
-  while (AliRunLoader::GetRunLoader()) delete AliRunLoader::GetRunLoader();
-  AliRunLoader* runLoader = 
-    AliRunLoader::Open(fGAliceFileName.Data(), 
-                      AliConfig::fgkDefaultEventFolderName, "UPDATE");
-  if (!runLoader) {
-    Error("LoadRun", "no run loader found in file %s", 
-         fGAliceFileName.Data());
-    return NULL;
-  }
-  runLoader->LoadgAlice();
-  gAlice = runLoader->GetAliRun();
-  if (!gAlice) {
-    Error("LoadRun", "no gAlice object found in file %s", 
-         fGAliceFileName.Data());
-    return NULL;
-  }
-  return runLoader;
-}
-
 //_____________________________________________________________________________
 Bool_t AliSimulation::IsSelected(TString detName, TString& detectors) const
 {
index bda4d911bf53bd5eda2f0019b677480f3687d7f8..d09e93ce42f9a0a824da96a25d266128a5efb6e0 100644 (file)
@@ -13,8 +13,7 @@ class AliRunLoader;
 
 class AliSimulation: public TNamed {
 public:
-  AliSimulation(const char* configFileName = "Config.C",
-               const char* name = "AliSimulation", 
+  AliSimulation(const char* name = "AliSimulation", 
                const char* title = "generation, simulation and digitization");
   AliSimulation(const AliSimulation& sim);
   AliSimulation& operator = (const AliSimulation& sim);
@@ -36,16 +35,17 @@ public:
 
   virtual Bool_t Run(Int_t nEvents = 0);
 
-  virtual Bool_t RunSimulation(Int_t nEvents = 0);
-  virtual Bool_t RunSDigitization(const char* detectors = "ALL");
-  virtual Bool_t RunDigitization(const char* detectors = "ALL",
-                                const char* excludeDetectors = "");
-  virtual Bool_t RunHitsDigitization(const char* detectors = "ALL");
-
 private:
-  AliRunLoader*  LoadRun() const;
+  void           Init();
+
   Bool_t         IsSelected(TString detName, TString& detectors) const;
 
+  Bool_t         RunSimulation();
+  Bool_t         RunSDigitization(const TString& detectors);
+  Bool_t         RunDigitization(const TString& detectors,
+                                const TString& excludeDetectors);
+  Bool_t         RunHitsDigitization(const TString& detectors);
+
   Bool_t         fRunGeneration;      // generate prim. particles or not
   Bool_t         fRunSimulation;      // simulate detectors (hits) or not
   TString        fMakeSDigits;        // create sdigits for these detectors
@@ -59,6 +59,8 @@ private:
   TObjArray*     fBkgrdFileNames;     // names of background files for merging
   Bool_t         fRegionOfInterest;   // digitization in region of interest
 
+  AliRunLoader*  fRunLoader;          //! current run loader object
+
   ClassDef(AliSimulation, 1)  // class for running generation, simulation and digitization
 };