]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliSimulation.cxx
QA can be switched off SetQA(kFALSE)
[u/mrichter/AliRoot.git] / STEER / AliSimulation.cxx
index 142ef635846a8fef8699476cc7adaaecee22e864..ac0a734f503304af72c82d9e922e7208976a1cec 100644 (file)
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
+#include <TVirtualMCApplication.h>
 #include <TGeoManager.h>
 #include <TObjString.h>
-#include <TStopwatch.h>
 #include <TSystem.h>
 #include <TFile.h>
 
+#include "AliCodeTimer.h"
 #include "AliCDBStorage.h"
 #include "AliCDBEntry.h"
 #include "AliCDBManager.h"
+#include "AliGeomManager.h"
 #include "AliAlignObj.h"
 #include "AliCentralTrigger.h"
 #include "AliDAQ.h"
 #include "AliCentralTrigger.h"
 #include "AliCTPRawData.h"
 #include "AliRawReaderFile.h"
+#include "AliRawReaderRoot.h"
+#include "AliRawReaderDate.h"
 #include "AliESD.h"
 #include "AliHeader.h"
 #include "AliGenEventHeader.h"
+#include "AliMC.h"
+#include "AliHLTSimulation.h"
+#include "AliQADataMakerSteer.h"
 
 ClassImp(AliSimulation)
 
+AliSimulation *AliSimulation::fgInstance = 0;
+const char* AliSimulation::fgkDetectorName[AliSimulation::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
 
 //_____________________________________________________________________________
 AliSimulation::AliSimulation(const char* configFileName, const char* cdbUri,
@@ -144,7 +153,7 @@ AliSimulation::AliSimulation(const char* configFileName, const char* cdbUri,
   fRunGeneration(kTRUE),
   fRunSimulation(kTRUE),
   fLoadAlignFromCDB(kTRUE),
-  fLoadAlignData("ALL"),
+  fLoadAlObjsListOfDets("ALL"),
   fMakeSDigits("ALL"),
   fMakeDigits("ALL"),
   fMakeTrigger(""),
@@ -163,12 +172,19 @@ AliSimulation::AliSimulation(const char* configFileName, const char* cdbUri,
   fUseBkgrdVertex(kTRUE),
   fRegionOfInterest(kFALSE),
   fCDBUri(cdbUri),
+  fRemoteCDBUri(""),
   fSpecCDBUri(),
-  fEmbeddingFlag(kFALSE)
+  fEmbeddingFlag(kFALSE),
+  fRunQA(kTRUE), 
+  fRunHLT("default")
 {
 // create simulation object with default parameters
-
+  fgInstance = this;
   SetGAliceFile("galice.root");
+  
+// for QA
+   for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) 
+       fQACycles[iDet] = 999999;
 }
 
 //_____________________________________________________________________________
@@ -178,7 +194,7 @@ AliSimulation::AliSimulation(const AliSimulation& sim) :
   fRunGeneration(sim.fRunGeneration),
   fRunSimulation(sim.fRunSimulation),
   fLoadAlignFromCDB(sim.fLoadAlignFromCDB),
-  fLoadAlignData(sim.fLoadAlignData),
+  fLoadAlObjsListOfDets(sim.fLoadAlObjsListOfDets),
   fMakeSDigits(sim.fMakeSDigits),
   fMakeDigits(sim.fMakeDigits),
   fMakeTrigger(sim.fMakeTrigger),
@@ -197,8 +213,11 @@ AliSimulation::AliSimulation(const AliSimulation& sim) :
   fUseBkgrdVertex(sim.fUseBkgrdVertex),
   fRegionOfInterest(sim.fRegionOfInterest),
   fCDBUri(sim.fCDBUri),
+  fRemoteCDBUri(sim.fRemoteCDBUri),
   fSpecCDBUri(),
-  fEmbeddingFlag(sim.fEmbeddingFlag)
+  fEmbeddingFlag(sim.fEmbeddingFlag),
+  fRunQA(kTRUE), 
+  fRunHLT(sim.fRunHLT)
 {
 // copy constructor
 
@@ -216,7 +235,11 @@ AliSimulation::AliSimulation(const AliSimulation& sim) :
   for (Int_t i = 0; i < sim.fSpecCDBUri.GetEntriesFast(); i++) {
     if (sim.fSpecCDBUri[i]) fSpecCDBUri.Add(sim.fSpecCDBUri[i]->Clone());
   }
+  fgInstance = this;
 
+// for QA
+   for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) 
+       fQACycles[iDet] = sim.fQACycles[iDet];
 }
 
 //_____________________________________________________________________________
@@ -244,6 +267,9 @@ AliSimulation::~AliSimulation()
   }
 
   fSpecCDBUri.Delete();
+  if (fgInstance==this) fgInstance = 0;
+
+  AliCodeTimer::Instance()->Print();
 }
 
 
@@ -267,25 +293,43 @@ void AliSimulation::InitCDBStorage()
   {
     AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
     AliWarning("Default CDB storage has been already set !");
-    AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
+    AliWarning(Form("Ignoring the default storage declared in AliSimulation: %s",fCDBUri.Data()));
     AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
     fCDBUri = "";
   }
   else {
-    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-    AliWarning(Form("Default CDB storage is set to: %s",fCDBUri.Data()));
-    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    AliDebug(2, Form("Default CDB storage is set to: %s",fCDBUri.Data()));
+    AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
     man->SetDefaultStorage(fCDBUri);
   }
 
+  // Remote storage (the Grid storage) is used if it is activated
+  // and if the object is not found in the default storage
+  // OBSOLETE: Removed
+  //   if (man->IsRemoteStorageSet())
+  //   {
+  //     AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+  //     AliWarning("Remote CDB storage has been already set !");
+  //     AliWarning(Form("Ignoring the remote storage declared in AliSimulation: %s",fRemoteCDBUri.Data()));
+  //     AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+  //     fRemoteCDBUri = "";
+  //   }
+  //   else {
+  //     AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+  //     AliDebug(2, Form("Remote CDB storage is set to: %s",fRemoteCDBUri.Data()));
+  //     AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+  //     man->SetRemoteStorage(fRemoteCDBUri);
+  //   }
+
   // Now activate the detector specific CDB storage locations
   for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
     TObject* obj = fSpecCDBUri[i];
     if (!obj) continue;
-    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-    AliWarning(Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
-    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-    man->SetSpecificStorage(obj->GetName(),obj->GetTitle());
+    AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
+    AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
   }
   man->Print();
 }
@@ -300,13 +344,30 @@ void AliSimulation::SetDefaultStorage(const char* uri) {
 }
 
 //_____________________________________________________________________________
-void AliSimulation::SetSpecificStorage(const char* detName, const char* uri) {
+void AliSimulation::SetRemoteStorage(const char* uri) {
+// Store the desired remote CDB storage location
+// Activate it later within the Run() method
+// Remote storage (the Grid storage) is used if it is activated
+// and if the object is not found in the default storage (the local cache)
+
+  fRemoteCDBUri = uri;
+
+}
+
+//_____________________________________________________________________________
+void AliSimulation::SetSpecificStorage(const char* calibType, const char* uri) {
 // Store a detector-specific CDB storage location
 // Activate it later within the Run() method
 
-  TObject* obj = fSpecCDBUri.FindObject(detName);
+  AliCDBPath aPath(calibType);
+  if(!aPath.IsValid()){
+       AliError(Form("Not a valid path: %s", calibType));
+       return;
+  }
+
+  TObject* obj = fSpecCDBUri.FindObject(calibType);
   if (obj) fSpecCDBUri.Remove(obj);
-  fSpecCDBUri.Add(new TNamed(detName, uri));
+  fSpecCDBUri.Add(new TNamed(calibType, uri));
 
 }
 
@@ -347,148 +408,6 @@ void AliSimulation::SetEventsPerFile(const char* detector, const char* type,
   fEventsPerFile.Add(obj);
 }
 
-//_____________________________________________________________________________
-Bool_t AliSimulation::ApplyAlignObjsToGeom(TObjArray* alObjArray)
-{
-  // Read collection of alignment objects (AliAlignObj derived) saved
-  // in the TClonesArray ClArrayName and apply them to the geometry
-  // manager singleton.
-  //
-  alObjArray->Sort();
-  Int_t nvols = alObjArray->GetEntriesFast();
-
-  Bool_t flag = kTRUE;
-
-  for(Int_t j=0; j<nvols; j++)
-    {
-      AliAlignObj* alobj = (AliAlignObj*) alObjArray->UncheckedAt(j);
-      if (alobj->ApplyToGeometry() == kFALSE) flag = kFALSE;
-    }
-
-  if (AliDebugLevelClass() >= 1) {
-    gGeoManager->GetTopNode()->CheckOverlaps(20);
-    TObjArray* ovexlist = gGeoManager->GetListOfOverlaps();
-    if(ovexlist->GetEntriesFast()){  
-      AliError("The application of alignment objects to the geometry caused huge overlaps/extrusions!");
-   }
-  }
-
-  return flag;
-
-}
-
-//_____________________________________________________________________________
-Bool_t AliSimulation::ApplyAlignObjsToGeom(const char* fileName, const char* clArrayName)
-{
-  // read collection of alignment objects (AliAlignObj derived) saved
-  // in the TClonesArray ClArrayName in the file fileName and apply
-  // them to the TGeo geometry passed as argument
-  //
-
-  TFile* inFile = TFile::Open(fileName,"READ");
-  if (!inFile || !inFile->IsOpen()) {
-    AliErrorClass(Form("Could not open file %s !",fileName));
-    return kFALSE;
-  }
-
-  TClonesArray* alObjArray = ((TClonesArray*) inFile->Get(clArrayName));
-  inFile->Close();
-  if (!alObjArray) {
-    AliErrorClass(Form("Could not get array (%s) from file (%s) !",clArrayName,fileName));
-    return kFALSE;
-  }
-
-  return ApplyAlignObjsToGeom(alObjArray);
-
-}
-
-//_____________________________________________________________________________
-Bool_t AliSimulation::ApplyAlignObjsToGeom(AliCDBParam* param, AliCDBId& Id)
-{
-  // read collection of alignment objects (AliAlignObj derived) saved
-  // in the TClonesArray ClArrayName in the AliCDBEntry identified by
-  // param (to get the AliCDBStorage) and Id; apply the alignment objects
-  // to the TGeo geometry passed as argument
-  //
-
-  AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage(param);
-  AliCDBEntry* entry = storage->Get(Id);
-  TClonesArray* AlObjArray = ((TClonesArray*) entry->GetObject());
-
-  return ApplyAlignObjsToGeom(AlObjArray);
-
-}
-
-//_____________________________________________________________________________
-Bool_t AliSimulation::ApplyAlignObjsToGeom(const char* uri, const char* path, Int_t runnum, Int_t version, Int_t sversion)
-{
-  // read collection of alignment objects (AliAlignObj derived) saved
-  // in the TClonesArray ClArrayName in the AliCDBEntry identified by
-  // param (to get the AliCDBStorage) and Id; apply the alignment objects
-  // to the TGeo geometry passed as argument
-  //
-
-  AliCDBParam* param = AliCDBManager::Instance()->CreateParameter(uri);
-  AliCDBId id(path, runnum, runnum, version, sversion);
-
-  return ApplyAlignObjsToGeom(param, id);
-
-}
-
-//_____________________________________________________________________________
-Bool_t AliSimulation::ApplyAlignObjsToGeom(const char* detName, Int_t runnum, Int_t version, Int_t sversion)
-{
-  // read collection of alignment objects (AliAlignObj derived) saved
-  // in the TClonesArray ClArrayName in the AliCDBEntry identified by
-  // param (to get the AliCDBStorage) and Id; apply the alignment objects
-  // to the TGeo geometry passed as argument
-  //
-
-  AliCDBPath path(detName,"Align","Data");
-  AliCDBEntry* entry = AliCDBManager::Instance()->Get(path.GetPath(),runnum,version,sversion);
-
-  if(!entry) return kFALSE;
-  TClonesArray* AlObjArray = ((TClonesArray*) entry->GetObject());
-
-  return ApplyAlignObjsToGeom(AlObjArray);
-}
-
-//_____________________________________________________________________________
-Bool_t AliSimulation::SetAlignObjArraySingleDet(const char* detName)
-{
-  // Fills array of single detector's alignable objects from CDB
-  
-  AliDebug(2, Form("Loading alignment data for detector: %s",detName));
-  
-  AliCDBEntry *entry;
-       
-  AliCDBPath path(detName,"Align","Data");
-       
-  entry=AliCDBManager::Instance()->Get(path.GetPath());
-  if(!entry){ 
-       AliDebug(2,Form("Couldn't load alignment data for detector %s",detName));
-       return kFALSE;
-  }
-  entry->SetOwner(1);
-  TClonesArray *alignArray = (TClonesArray*) entry->GetObject();       
-  alignArray->SetOwner(0);
-  AliDebug(2,Form("Found %d alignment objects for %s",
-                       alignArray->GetEntries(),detName));
-
-  AliAlignObj *alignObj=0;
-  TIter iter(alignArray);
-       
-  // loop over align objects in detector
-  while( ( alignObj=(AliAlignObj *) iter.Next() ) ){
-       fAlignObjArray->Add(alignObj);
-  }
-  // delete entry --- Don't delete, it is cached!
-       
-  AliDebug(2, Form("fAlignObjArray entries: %d",fAlignObjArray->GetEntries() ));
-  return kTRUE;
-
-}
-
 //_____________________________________________________________________________
 Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
 {
@@ -500,6 +419,10 @@ Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
   // then applied to the TGeo geometry.
   // Finally an overlaps check is performed.
 
+  if (!AliGeomManager::GetGeometry() || !AliGeomManager::GetGeometry()->IsClosed()) {
+    AliError("Can't apply the misalignment! Geometry is not loaded or it is still opened!");
+    return kFALSE;
+  }  
   Bool_t delRunLoader = kFALSE;
   if (!runLoader) {
     runLoader = LoadRun("READ");
@@ -507,60 +430,54 @@ Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
     delRunLoader = kTRUE;
   }
 
-  // Load alignment data from CDB and fill fAlignObjArray 
+  // Export ideal geometry 
+  if(!gAlice->IsRootGeometry()) AliGeomManager::GetGeometry()->Export("geometry.root");
+
+  // Load alignment data from CDB and apply to geometry through AliGeomManager
   if(fLoadAlignFromCDB){
-       if(!fAlignObjArray) fAlignObjArray = new TObjArray();
-       
-       //fAlignObjArray->RemoveAll(); 
-       fAlignObjArray->Clear();        
-       fAlignObjArray->SetOwner(0);
-       TString detStr = fLoadAlignData;
-       TString dataNotLoaded="";
-       TString dataLoaded="";
-  
-       TObjArray* detArray = runLoader->GetAliRun()->Detectors();
-       for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
-               AliModule* det = (AliModule*) detArray->At(iDet);
-               if (!det) continue;
-               if (IsSelected(det->GetName(), detStr)) {
-                       if(!SetAlignObjArraySingleDet(det->GetName())){
-                               dataNotLoaded += det->GetName();
-                               dataNotLoaded += " ";
-                       } else {
-                               dataLoaded += det->GetName();
-                               dataLoaded += " ";
-                       }
-               }
-       } // end loop over detectors
-  
-       if ((detStr.CompareTo("ALL") == 0)) detStr = "";
-       dataNotLoaded += detStr;
-       AliInfo(Form("Alignment data loaded for: %s",
-                         dataLoaded.Data()));
-       AliInfo(Form("Didn't/couldn't load alignment data for: %s",
-                         dataNotLoaded.Data()));
-  } // fLoadAlignFromCDB flag
-  // Check if the array with alignment objects was
-  // provided by the user. If yes, apply the objects
-  // to the present TGeo geometry
-  if (fAlignObjArray) {
-    if (gGeoManager && gGeoManager->IsClosed()) {
-      if (ApplyAlignObjsToGeom(fAlignObjArray) == kFALSE) {
-       AliError("The misalignment of one or more volumes failed!"
-                "Compare the list of simulated detectors and the list of detector alignment data!");
-       if (delRunLoader) delete runLoader;
-       return kFALSE;
+    
+    TString detStr = fLoadAlObjsListOfDets;
+    TString loadAlObjsListOfDets = "";
+    
+    TObjArray* detArray = runLoader->GetAliRun()->Detectors();
+    for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
+      AliModule* det = (AliModule*) detArray->At(iDet);
+      if (!det || !det->IsActive()) continue;
+      if (IsSelected(det->GetName(), detStr)) {
+        //add det to list of dets to be aligned from CDB
+        loadAlObjsListOfDets += det->GetName();
+        loadAlObjsListOfDets += " ";
+      }
+    } // end loop over detectors
+    loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
+    AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
+  }else{
+    // Check if the array with alignment objects was
+    // provided by the user. If yes, apply the objects
+    // to the present TGeo geometry
+    if (fAlignObjArray) {
+      if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
+        AliError("The misalignment of one or more volumes failed!"
+                 "Compare the list of simulated detectors and the list of detector alignment data!");
+        if (delRunLoader) delete runLoader;
+        return kFALSE;
       }
-    }
-    else {
-      AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
-      if (delRunLoader) delete runLoader;
-      return kFALSE;
     }
   }
 
+  // Update the internal geometry of modules (ITS needs it)
+  TString detStr = fLoadAlObjsListOfDets;
+  TObjArray* detArray = runLoader->GetAliRun()->Detectors();
+  for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
+
+    AliModule* det = (AliModule*) detArray->At(iDet);
+    if (!det || !det->IsActive()) continue;
+    if (IsSelected(det->GetName(), detStr)) {
+      det->UpdateInternalGeometry();
+    }
+  } // end loop over detectors
+
+
   if (delRunLoader) delete runLoader;
 
   return kTRUE;
@@ -608,6 +525,9 @@ Bool_t AliSimulation::Run(Int_t nEvents)
 {
 // run the generation, simulation and digitization
 
+   AliCodeTimerAuto("")
+  
   InitCDBStorage();
 
   if (nEvents > 0) fNEvents = nEvents;
@@ -617,26 +537,43 @@ Bool_t AliSimulation::Run(Int_t nEvents)
     if (!RunSimulation()) if (fStopOnError) return kFALSE;
   }
 
+  //QA
+  if (fRunQA) 
+       if (!RunQA("ALL", AliQA::kHITS))
+               if (fStopOnError) 
+                       return kFALSE ;         
+
   // Set run number in CDBManager (if it is not already set in RunSimulation)
   if (!SetRunNumber()) if (fStopOnError) return kFALSE;
 
-  // Load and misalign the geometry
-  if (!gGeoManager) {
-    TGeoManager::Import("geometry.root");
-    if (!gGeoManager) if (fStopOnError) return kFALSE;
-    if (!MisalignGeometry()) if (fStopOnError) return kFALSE;
+  // If RunSimulation was not called, load the geometry and misalign it
+  if (!AliGeomManager::GetGeometry()) {
+    // Initialize the geometry manager
+    AliGeomManager::LoadGeometry("geometry.root");
+    if (!AliGeomManager::GetGeometry()) if (fStopOnError) return kFALSE;
+    // Misalign geometry
+    if(!MisalignGeometry()) if (fStopOnError) return kFALSE;
   }
-  
+
   // hits -> summable digits
   if (!fMakeSDigits.IsNull()) {
     if (!RunSDigitization(fMakeSDigits)) if (fStopOnError) return kFALSE;
+  //QA
+       if (fRunQA) 
+               RunQA(fMakeSDigits, AliQA::kSDIGITS) ;   
   }
+  
 
   // summable digits -> digits
   if (!fMakeDigits.IsNull()) {
     if (!RunDigitization(fMakeDigits, fMakeDigitsFromHits)) {
       if (fStopOnError) return kFALSE;
     }
+    //QA
+       if (fRunQA) 
+               if (!RunQA(fMakeDigits, AliQA::kDIGITS) )       
+                       if (fStopOnError) 
+                               return kFALSE ;         
   }
 
   // hits -> digits
@@ -650,6 +587,12 @@ Bool_t AliSimulation::Run(Int_t nEvents)
     if (!RunHitsDigitization(fMakeDigitsFromHits)) {
       if (fStopOnError) return kFALSE;
     }
+       //QA
+       if (fRunQA) 
+               if( !RunQA(fMakeDigitsFromHits, AliQA::kDIGITS) )       
+                       if (fStopOnError) 
+                               return kFALSE ;         
+
   }
 
   // digits -> trigger
@@ -665,6 +608,13 @@ Bool_t AliSimulation::Run(Int_t nEvents)
     }
   }
 
+  // run HLT simulation
+  if (!fRunHLT.IsNull()) {
+    if (!RunHLT()) {
+      if (fStopOnError) return kFALSE;
+    }
+  }
+
   return kTRUE;
 }
 
@@ -673,8 +623,7 @@ Bool_t AliSimulation::RunTrigger(const char* descriptors)
 {
   // run the trigger
 
-   TStopwatch stopwatch;
-   stopwatch.Start();
+  AliCodeTimerAuto("")
 
    AliRunLoader* runLoader = LoadRun("READ");
    if (!runLoader) return kFALSE;
@@ -690,7 +639,7 @@ Bool_t AliSimulation::RunTrigger(const char* descriptors)
      }
    }
 
-   runLoader->MakeTree( "CT" );
+   runLoader->MakeTree( "GG" );
    AliCentralTrigger* aCTP = runLoader->GetTrigger();
   // Load Descriptors
    aCTP->LoadDescriptor( des );
@@ -703,9 +652,6 @@ Bool_t AliSimulation::RunTrigger(const char* descriptors)
       }
    }
 
-   AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
-           stopwatch.RealTime(),stopwatch.CpuTime()));
-
    delete runLoader;
 
    return kTRUE;
@@ -728,8 +674,7 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
 {
 // run the generation and simulation
 
-  TStopwatch stopwatch;
-  stopwatch.Start();
+  AliCodeTimerAuto("")
 
   if (!gAlice) {
     AliError("no gAlice object. Restart aliroot and try again.");
@@ -757,7 +702,6 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
     gAlice->SetTriggerDescriptor(fMakeTrigger.Data());
 
   // Set run number in CDBManager
-  AliCDBManager::Instance()->SetRun(gAlice->GetRunNumber());
   AliInfo(Form("Run number: %d",AliCDBManager::Instance()->GetRun()));
 
   AliRunLoader* runLoader = gAlice->GetRunLoader();
@@ -768,18 +712,11 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
   }
   SetGAliceFile(runLoader->GetFileName());
  
-  // Export ideal geometry 
-  if (gGeoManager) gGeoManager->Export("geometry.root");
-
   // Misalign geometry
-//   if (!MisalignGeometry(runLoader)) {
-//     delete runLoader;
-//     return kFALSE;
-//   }
+#if ROOT_VERSION_CODE < 331527
+  AliGeomManager::SetGeometry(gGeoManager);
   MisalignGeometry(runLoader);
-
-  // Export (mis)aligned geometry 
-  if (gGeoManager) gGeoManager->Export("misaligned_geometry.root");
+#endif
 
 //   AliRunLoader* runLoader = gAlice->GetRunLoader();
 //   if (!runLoader) {
@@ -847,8 +784,6 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
 
   delete runLoader;
 
-  AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
-              stopwatch.RealTime(),stopwatch.CpuTime()));
 
   return kTRUE;
 }
@@ -858,8 +793,7 @@ Bool_t AliSimulation::RunSDigitization(const char* detectors)
 {
 // run the digitization and produce summable digits
 
-  TStopwatch stopwatch;
-  stopwatch.Start();
+  AliCodeTimerAuto("")
 
   AliRunLoader* runLoader = LoadRun();
   if (!runLoader) return kFALSE;
@@ -871,11 +805,9 @@ Bool_t AliSimulation::RunSDigitization(const char* detectors)
     if (!det || !det->IsActive()) continue;
     if (IsSelected(det->GetName(), detStr)) {
       AliInfo(Form("creating summable digits for %s", det->GetName()));
-      TStopwatch stopwatchDet;
-      stopwatchDet.Start();
+      AliCodeTimerAuto(Form("creating summable digits for %s", det->GetName()));
+         
       det->Hits2SDigits();
-      AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
-          det->GetName(),stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
     }
   }
 
@@ -887,9 +819,6 @@ Bool_t AliSimulation::RunSDigitization(const char* detectors)
 
   delete runLoader;
 
-  AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
-          stopwatch.RealTime(),stopwatch.CpuTime()));
-
   return kTRUE;
 }
 
@@ -900,8 +829,7 @@ Bool_t AliSimulation::RunDigitization(const char* detectors,
 {
 // run the digitization and produce digits from sdigits
 
-  TStopwatch stopwatch;
-  stopwatch.Start();
+  AliCodeTimerAuto("")
 
   while (AliRunLoader::GetRunLoader()) delete AliRunLoader::GetRunLoader();
   if (gAlice) delete gAlice;
@@ -954,9 +882,6 @@ Bool_t AliSimulation::RunDigitization(const char* detectors,
 
   delete manager;
 
-  AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
-              stopwatch.RealTime(),stopwatch.CpuTime()));
-  
   return kTRUE;
 }
 
@@ -965,8 +890,7 @@ Bool_t AliSimulation::RunHitsDigitization(const char* detectors)
 {
 // run the digitization and produce digits from hits
 
-  TStopwatch stopwatch;
-  stopwatch.Start();
+  AliCodeTimerAuto("")
 
   AliRunLoader* runLoader = LoadRun("READ");
   if (!runLoader) return kFALSE;
@@ -992,9 +916,6 @@ Bool_t AliSimulation::RunHitsDigitization(const char* detectors)
   //PH Temporary fix to avoid interference with the PHOS loder/getter
   //PH The problem has to be solved in more general way 09/06/05
 
-  AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
-              stopwatch.RealTime(),stopwatch.CpuTime()));
-
   return kTRUE;
 }
 
@@ -1012,8 +933,7 @@ Bool_t AliSimulation::WriteRawData(const char* detectors,
 // to a root file.
 // If deleteIntermediateFiles is true, the DATE file is deleted afterwards.
 
-  TStopwatch stopwatch;
-  stopwatch.Start();
+  AliCodeTimerAuto("")
 
   if (!WriteRawFiles(detectors)) {
     if (fStopOnError) return kFALSE;
@@ -1046,9 +966,6 @@ Bool_t AliSimulation::WriteRawData(const char* detectors,
     }
   }
 
-  AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
-              stopwatch.RealTime(),stopwatch.CpuTime()));
-
   return kTRUE;
 }
 
@@ -1057,6 +974,8 @@ Bool_t AliSimulation::WriteRawFiles(const char* detectors)
 {
 // convert the digits to raw data DDL files
 
+  AliCodeTimerAuto("")
+  
   AliRunLoader* runLoader = LoadRun("READ");
   if (!runLoader) return kFALSE;
 
@@ -1096,6 +1015,7 @@ Bool_t AliSimulation::WriteRawFiles(const char* detectors)
   }
 
   delete runLoader;
+  
   return kTRUE;
 }
 
@@ -1104,6 +1024,8 @@ Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName)
 {
 // convert raw data DDL files to a DATE file with the program "dateStream"
 
+  AliCodeTimerAuto("")
+  
   char* path = gSystem->Which(gSystem->Getenv("PATH"), "dateStream");
   if (!path) {
     AliError("the program dateStream was not found");
@@ -1117,7 +1039,9 @@ Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName)
 
   AliInfo(Form("converting raw data DDL files to DATE file %s", dateFileName));
   char command[256];
-  sprintf(command, "dateStream -D -o %s -# %d -C", 
+  // Note the option -s. It is used in order to avoid
+  // the generation of SOR/EOR events.
+  sprintf(command, "dateStream -s -D -o %s -# %d -C", 
          dateFileName, runLoader->GetNumberOfEvents());
   FILE* pipe = gSystem->OpenPipe(command, "w");
 
@@ -1168,7 +1092,7 @@ Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
 // convert a DATE file to a root file with the program "alimdc"
 
   // ALIMDC setup
-  const Int_t kDBSize = 1000000000;
+  const Int_t kDBSize = 2000000000;
   const Int_t kTagDBSize = 1000000000;
   const Bool_t kFilter = kFALSE;
   const Int_t kCompression = 1;
@@ -1186,7 +1110,6 @@ Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
 
   const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
   const char* tagDBFS    = "/tmp/mdc1/tags";
-  const char* runDBFS    = "/tmp/mdc1/meta";
 
   // User defined file system locations
   if (gSystem->Getenv("ALIMDC_RAWDB1")) 
@@ -1195,18 +1118,14 @@ Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
     rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
   if (gSystem->Getenv("ALIMDC_TAGDB")) 
     tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
-  if (gSystem->Getenv("ALIMDC_RUNDB")) 
-    runDBFS = gSystem->Getenv("ALIMDC_RUNDB");
 
   gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
   gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
   gSystem->Exec(Form("rm -rf %s",tagDBFS));
-  gSystem->Exec(Form("rm -rf %s",runDBFS));
 
   gSystem->Exec(Form("mkdir %s",rawDBFS[0]));
   gSystem->Exec(Form("mkdir %s",rawDBFS[1]));
   gSystem->Exec(Form("mkdir %s",tagDBFS));
-  gSystem->Exec(Form("mkdir %s",runDBFS));
 
   Int_t result = gSystem->Exec(Form("alimdc %d %d %d %d %s", 
                                    kDBSize, kTagDBSize, kFilter, kCompression, dateFileName));
@@ -1215,7 +1134,6 @@ Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
   gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
   gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
   gSystem->Exec(Form("rm -rf %s",tagDBFS));
-  gSystem->Exec(Form("rm -rf %s",runDBFS));
 
   return (result == 0);
 }
@@ -1376,7 +1294,18 @@ Bool_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* e
     }
     //
     // Create the RawReader
-    AliRawReaderFile* rawReader = new AliRawReaderFile(rawDirectory);
+    TString fileName(rawDirectory);
+    AliRawReader* rawReader = 0x0;
+    if (fileName.EndsWith("/")) {
+      rawReader = new AliRawReaderFile(fileName);
+    } else if (fileName.EndsWith(".root")) {
+      rawReader = new AliRawReaderRoot(fileName);
+    } else if (!fileName.IsNull()) {
+      rawReader = new AliRawReaderDate(fileName);
+      rawReader->SelectEvents(7);
+    }
+//     if (!fEquipIdMap.IsNull() && fRawReader)
+//       fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
     //
     // Get list of detectors
     TObjArray* detArray = runLoader->GetAliRun()->Detectors();
@@ -1384,6 +1313,7 @@ Bool_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* e
     // Get Header
     AliHeader* header = runLoader->GetHeader();
     //
+    TString detStr = fMakeSDigits;
     // Event loop
     Int_t nev = 0;
     while(kTRUE) {
@@ -1392,11 +1322,15 @@ Bool_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* e
        // Detector loop
        for (iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
            AliModule* det = (AliModule*) detArray->At(iDet);
-           AliInfo(Form("Calling Raw2SDigits for %s\n", det->GetName()));
-           det->Raw2SDigits(rawReader);
-           rawReader->Reset();
+           if (!det || !det->IsActive()) continue;
+           if (IsSelected(det->GetName(), detStr)) {
+             AliInfo(Form("Calling Raw2SDigits for %s\n", det->GetName()));
+             det->Raw2SDigits(rawReader);
+             rawReader->Reset();
+           }
        } // detectors
 
+
        //
        //  If ESD information available obtain reconstructed vertex and store in header.
        if (esdOK) {
@@ -1429,3 +1363,118 @@ Bool_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* e
 
     return kTRUE;
 }
+
+//_____________________________________________________________________________
+Int_t AliSimulation::GetDetIndex(const char* detector)
+{
+  // return the detector index corresponding to detector
+  Int_t index = -1 ; 
+  for (index = 0; index < fgkNDetectors ; index++) {
+    if ( strcmp(detector, fgkDetectorName[index]) == 0 )
+         break ; 
+  }    
+  return index ; 
+}
+
+//_____________________________________________________________________________
+Bool_t AliSimulation::RunHLT()
+{
+  // Run the HLT simulation
+  // HLT simulation is implemented in HLT/sim/AliHLTSimulation
+  // Disabled if fRunHLT is empty, default vaule is "default".
+  // AliSimulation::SetRunHLT can be used to set the options for HLT simulation
+  // The default simulation depends on the HLT component libraries and their
+  // corresponding agents which define components and chains to run. See
+  // http://web.ift.uib.no/~kjeks/doc/alice-hlt/
+  // http://web.ift.uib.no/~kjeks/doc/alice-hlt/classAliHLTModuleAgent.html
+  //
+  // The libraries to be loaded can be specified as an option.
+  // <pre>
+  // AliSimulation sim;
+  // sim.SetRunHLT("libAliHLTSample.so");
+  // </pre>
+  // will only load <tt>libAliHLTSample.so</tt>
+
+  // Other available options:
+  // \li loglevel=<i>level</i> <br>
+  //     logging level for this processing
+  // \li alilog=off
+  //     disable redirection of log messages to AliLog class
+  // \li config=<i>macro</i>
+  //     configuration macro
+  // \li localrec=<i>configuration</i>
+  //     comma separated list of configurations to be run during simulation
+
+  int iResult=0;
+  AliRunLoader* pRunLoader = LoadRun("READ");
+  if (!pRunLoader) return kFALSE;
+
+  // load the library dynamically
+  gSystem->Load(ALIHLTSIMULATION_LIBRARY);
+
+  // check for the library version
+  AliHLTSimulationGetLibraryVersion_t fctVersion=(AliHLTSimulationGetLibraryVersion_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_GET_LIBRARY_VERSION));
+  if (!fctVersion) {
+    AliError(Form("can not load library %s", ALIHLTSIMULATION_LIBRARY));
+    return kFALSE;
+  }
+  if (fctVersion()!= ALIHLTSIMULATION_LIBRARY_VERSION) {
+    AliError(Form("%s version does not match: compiled for version %d, loaded %d", ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_LIBRARY_VERSION, fctVersion()));
+    return kFALSE;
+  }
+
+  // print compile info
+  typedef void (*CompileInfo)( char*& date, char*& time);
+  CompileInfo fctInfo=(CompileInfo)gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, "CompileInfo");
+  if (fctInfo) {
+    char* date="";
+    char* time="";
+    (*fctInfo)(date, time);
+    if (!date) date="unknown";
+    if (!time) time="unknown";
+    AliInfo(Form("%s build on %s (%s)", ALIHLTSIMULATION_LIBRARY, date, time));
+  } else {
+    AliInfo(Form("no build info available for %s", ALIHLTSIMULATION_LIBRARY));
+  }
+
+  // create instance of the HLT simulation
+  AliHLTSimulationCreateInstance_t fctCreate=(AliHLTSimulationCreateInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_CREATE_INSTANCE));
+  AliHLTSimulation* pHLT=NULL;
+  if (fctCreate==NULL || (pHLT=(fctCreate()))==NULL) {
+    AliError(Form("can not create instance of HLT simulation (creator %p)", fctCreate));
+    return kFALSE;    
+  }
+
+  // init the HLT simulation
+  if (fRunHLT.CompareTo("default")==0) fRunHLT="";
+  AliHLTSimulationInit_t fctInit=(AliHLTSimulationInit_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_INIT));
+  if (fctInit==NULL || (iResult=(fctInit(pHLT, pRunLoader, fRunHLT.Data())))<0) {
+    AliError(Form("can not init HLT simulation: error %d (init %p)", iResult, fctInit));
+  } else {
+    // run the HLT simulation
+    AliHLTSimulationRun_t fctRun=(AliHLTSimulationRun_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_RUN));
+    if (fctRun==NULL || (iResult=(fctRun(pHLT, pRunLoader)))<0) {
+      AliError(Form("can not run HLT simulation: error %d (run %p)", iResult, fctRun));
+    }
+  }
+
+  // delete the instance
+  AliHLTSimulationDeleteInstance_t fctDelete=(AliHLTSimulationDeleteInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_DELETE_INSTANCE));
+  if (fctDelete==NULL || fctDelete(pHLT)<0) {
+    AliError(Form("can not delete instance of HLT simulation (creator %p)", fctDelete));
+  }
+  pHLT=NULL;
+
+  return iResult>=0?kTRUE:kFALSE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliSimulation::RunQA(const char* detectors, AliQA::TASKINDEX task)
+{
+// run the QA on summable digits pr digits
+
+         AliQADataMakerSteer qas ; 
+         qas.Reset() ; 
+         return qas.Run(task); 
+}
+