]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliSimulation.cxx
delegating the qa task to AliQADataMakersteer
[u/mrichter/AliRoot.git] / STEER / AliSimulation.cxx
index ac92e34badcf89f5768a5d3d2834f619647cf227..27a4f27b93a0bf83a01d534434b3979b076040e3 100644 (file)
 #include <TObjString.h>
 #include <TSystem.h>
 #include <TFile.h>
+#include <TROOT.h>
 
 #include "AliCodeTimer.h"
 #include "AliCDBStorage.h"
 #include "AliMC.h"
 #include "AliHLTSimulation.h"
 #include "AliQADataMakerSteer.h"
+#include "AliSysInfo.h"
+#include "AliGenMC.h"
+#include "AliMagF.h"
 
 ClassImp(AliSimulation)
 
@@ -180,8 +184,12 @@ AliSimulation::AliSimulation(const char* configFileName,
   fInitRunNumberCalled(kFALSE),
   fSetRunNumberFromDataCalled(kFALSE),
   fEmbeddingFlag(kFALSE),
+  fQADetectors("ALL"),                  
+  fQATasks("ALL"),     
+  fQASteer(NULL), 
   fRunQA(kTRUE), 
-  fRunHLT("default")
+  fRunHLT("default"),
+  fWriteGRPEntry(kTRUE)
 {
 // create simulation object with default parameters
   fgInstance = this;
@@ -189,7 +197,10 @@ AliSimulation::AliSimulation(const char* configFileName,
   
 // for QA
    for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) 
-       fQACycles[iDet] = 999999;
+                fQACycles[iDet] = 999999;
+       fQASteer = new AliQADataMakerSteer("sim") ; 
+       fQASteer->SetActiveDetectors(fQADetectors) ; 
+       fQASteer->SetTasks(fQATasks) ;  
 }
 
 //_____________________________________________________________________________
@@ -226,8 +237,12 @@ AliSimulation::AliSimulation(const AliSimulation& sim) :
   fInitRunNumberCalled(sim.fInitRunNumberCalled),
   fSetRunNumberFromDataCalled(sim.fSetRunNumberFromDataCalled),
   fEmbeddingFlag(sim.fEmbeddingFlag),
-  fRunQA(kTRUE), 
-  fRunHLT(sim.fRunHLT)
+  fQADetectors(sim.fQADetectors),                  
+       fQATasks(sim.fQATasks), 
+       fQASteer(sim.fQASteer), 
+  fRunQA(sim.fRunQA), 
+  fRunHLT(sim.fRunHLT),
+  fWriteGRPEntry(sim.fWriteGRPEntry)
 {
 // copy constructor
 
@@ -279,6 +294,8 @@ AliSimulation::~AliSimulation()
   fSpecCDBUri.Delete();
   if (fgInstance==this) fgInstance = 0;
 
+       delete fQASteer ; 
+       
   AliCodeTimer::Instance()->Print();
 }
 
@@ -639,25 +656,46 @@ Bool_t AliSimulation::Run(Int_t nEvents)
   if (!AliGeomManager::GetGeometry()) {
     // Initialize the geometry manager
     AliGeomManager::LoadGeometry("geometry.root");
+    
+//    // Check that the consistency of symbolic names for the activated subdetectors
+//    // in the geometry loaded by AliGeomManager
+//    AliRunLoader* runLoader = LoadRun("READ");
+//    if (!runLoader) return kFALSE;
+//
+//    TString detsToBeChecked = "";
+//    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;
+//      detsToBeChecked += det->GetName();
+//      detsToBeChecked += " ";
+//    } // end loop over detectors
+//    if(!AliGeomManager::CheckSymNamesLUT(detsToBeChecked.Data()))
+    if(!AliGeomManager::CheckSymNamesLUT("ALL"))
+       AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
+       
     if (!AliGeomManager::GetGeometry()) if (fStopOnError) return kFALSE;
     // Misalign geometry
     if(!MisalignGeometry()) if (fStopOnError) return kFALSE;
   }
 
+
   // hits -> summable digits
+  AliSysInfo::AddStamp("Start_sdigitization");
   if (!fMakeSDigits.IsNull()) {
     if (!RunSDigitization(fMakeSDigits)) if (fStopOnError) return kFALSE;
  
   }
+  AliSysInfo::AddStamp("Stop_sdigitization");
   
-
-  
+  AliSysInfo::AddStamp("Start_digitization");  
   // summable digits -> digits  
   if (!fMakeDigits.IsNull()) {
     if (!RunDigitization(fMakeDigits, fMakeDigitsFromHits)) {
       if (fStopOnError) return kFALSE;
     }
    }
+  AliSysInfo::AddStamp("Stop_digitization");
 
   
   
@@ -829,6 +867,19 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
   // Misalign geometry
 #if ROOT_VERSION_CODE < 331527
   AliGeomManager::SetGeometry(gGeoManager);
+  
+  // Check that the consistency of symbolic names for the activated subdetectors
+  // in the geometry loaded by AliGeomManager
+  TString detsToBeChecked = "";
+  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;
+    detsToBeChecked += det->GetName();
+    detsToBeChecked += " ";
+  } // end loop over detectors
+  if(!AliGeomManager::CheckSymNamesLUT(detsToBeChecked.Data()))
+    AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
   MisalignGeometry(runLoader);
 #endif
 
@@ -845,6 +896,11 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
                   "Check your config file: %s", fConfigFileName.Data()));
     return kFALSE;
   }
+
+  // Write GRP entry corresponding to the setting found in Cofig.C
+  if (fWriteGRPEntry)
+    WriteGRPEntry();
+
   if (nEvents <= 0) nEvents = fNEvents;
 
   // get vertex from background file in case of merging
@@ -892,10 +948,11 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
   }
 
   AliInfo("running gAlice");
+  AliSysInfo::AddStamp("Start_simulation");
   StdoutToAliInfo(StderrToAliError(
     gAlice->Run(nEvents);
   ););
-
+  AliSysInfo::AddStamp("Stop_simulation");
   delete runLoader;
 
   return kTRUE;
@@ -905,7 +962,7 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
 Bool_t AliSimulation::RunSDigitization(const char* detectors)
 {
 // run the digitization and produce summable digits
-
+  static Int_t eventNr=0;
   AliCodeTimerAuto("")
 
   // initialize CDB storage, run number, set CDB lock
@@ -924,8 +981,8 @@ Bool_t AliSimulation::RunSDigitization(const char* detectors)
     if (IsSelected(det->GetName(), detStr)) {
       AliInfo(Form("creating summable digits for %s", det->GetName()));
       AliCodeTimerAuto(Form("creating summable digits for %s", det->GetName()));
-         
       det->Hits2SDigits();
+      AliSysInfo::AddStamp(Form("Digit_%s_%d",det->GetName(),eventNr), 0,1, eventNr);
     }
   }
 
@@ -934,7 +991,7 @@ Bool_t AliSimulation::RunSDigitization(const char* detectors)
                   detStr.Data()));
     if (fStopOnError) return kFALSE;
   }
-
+  eventNr++;
   delete runLoader;
 
   return kTRUE;
@@ -1065,8 +1122,15 @@ Bool_t AliSimulation::WriteRawData(const char* detectors,
 // accoring to the trigger cluster.
 
   AliCodeTimerAuto("")
+  
+  TString detStr = detectors;
+  if (IsSelected("HLT", detStr))
+  {
+       // Do nothing. "HLT" will be removed from detStr because the HLT raw
+       // data files are generated in RunHLT.
+  }
 
-  if (!WriteRawFiles(detectors)) {
+  if (!WriteRawFiles(detStr.Data())) {
     if (fStopOnError) return kFALSE;
   }
 
@@ -1247,7 +1311,7 @@ Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName,
 
   Int_t result = gSystem->ClosePipe(pipe);
 
-  if (!selrawdata && selEvents > 0) {
+  if (!(selrawdata && selEvents > 0)) {
     delete runLoader;
     return (result == 0);
   }
@@ -1266,7 +1330,7 @@ Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName,
     if (!runLoader->LoadTrigger()) {
       AliCentralTrigger *aCTP = runLoader->GetTrigger();
       if (aCTP->GetClassMask() == 0) continue;
-      detClust = aCTP->GetTriggeredDetectors();
+      detClust = AliDAQ::ListOfTriggeredDetectors(aCTP->GetClusterMask());
       AliInfo(Form("List of detectors to be read out: %s",detClust.Data()));
     }
 
@@ -1532,7 +1596,6 @@ Bool_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* e
       rawReader = new AliRawReaderRoot(fileName);
     } else if (!fileName.IsNull()) {
       rawReader = new AliRawReaderDate(fileName);
-      rawReader->SelectEvents(7);
     }
 //     if (!fEquipIdMap.IsNull() && fRawReader)
 //       fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
@@ -1681,9 +1744,15 @@ Bool_t AliSimulation::RunHLT()
   }
 
   // init the HLT simulation
-  if (fRunHLT.CompareTo("default")==0) fRunHLT="";
+  TString options;
+  if (fRunHLT.CompareTo("default")!=0) options=fRunHLT;
+  if (!IsSelected("HLT", fWriteRawData)) {
+    options+=" writerawfiles=";
+  } else {
+    options+=" writerawfiles=HLT";
+  }
   AliHLTSimulationInit_t fctInit=(AliHLTSimulationInit_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_INIT));
-  if (fctInit==NULL || (iResult=(fctInit(pHLT, pRunLoader, fRunHLT.Data())))<0) {
+  if (fctInit==NULL || (iResult=(fctInit(pHLT, pRunLoader, options.Data())))<0) {
     AliError(Form("can not init HLT simulation: error %d (init %p)", iResult, fctInit));
   } else {
     // run the HLT simulation
@@ -1707,21 +1776,63 @@ Bool_t AliSimulation::RunHLT()
 Bool_t AliSimulation::RunQA()
 {
        // run the QA on summable hits, digits or digits
-
-       AliQADataMakerSteer qas ; 
-    qas.SetRunLoader(gAlice->GetRunLoader()) ;
-
-       Bool_t rv =  qas.Run("ALL", AliQA::kHITS) ; 
-//     qas.Reset() ; 
-       rv *= qas.Run(fMakeSDigits.Data(), AliQA::kSDIGITS) ;   
-//     qas.Reset() ; 
-       rv *= qas.Run(fMakeDigits.Data(), AliQA::kDIGITS) ;     
-//     qas.Reset() ; 
-       rv *= qas.Run(fMakeDigitsFromHits.Data(), AliQA::kDIGITS) ; 
-
+       
+       fQASteer->SetRunLoader(gAlice->GetRunLoader()) ;
+
+       TString detectorsw("") ;  
+       Bool_t rv = kTRUE ; 
+       detectorsw = fQASteer->Run(fQADetectors.Data()) ; 
+       if ( detectorsw.IsNull() ) 
+               rv = kFALSE ; 
        return rv ; 
 }
 
+//_____________________________________________________________________________
+Bool_t AliSimulation::SetRunQA(TString detAndAction) 
+{
+       // Allows to run QA for a selected set of detectors
+       // and a selected set of tasks among HITS, SDIGITS and DIGITS
+       // all selected detectors run the same selected tasks
+       
+       if (!detAndAction.Contains(":")) {
+               AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
+               fRunQA = kFALSE ;
+               return kFALSE ;                 
+       }
+       Int_t colon = detAndAction.Index(":") ; 
+       fQADetectors = detAndAction(0, colon) ; 
+       if (fQADetectors.Contains("ALL") )
+               fQADetectors = Form("%s %s", fMakeDigits.Data(), fMakeDigitsFromHits.Data()) ; 
+       fQATasks   = detAndAction(colon+1, detAndAction.Sizeof() ) ; 
+       if (fQATasks.Contains("ALL") ) {
+               fQATasks = Form("%d %d %d", AliQA::kHITS, AliQA::kSDIGITS, AliQA::kDIGITS) ; 
+       } else {
+               fQATasks.ToUpper() ; 
+               TString tempo("") ; 
+               if ( fQATasks.Contains("HIT") ) 
+                       tempo = Form("%d ", AliQA::kHITS) ; 
+               if ( fQATasks.Contains("SDIGIT") ) 
+                       tempo += Form("%d ", AliQA::kSDIGITS) ; 
+               if ( fQATasks.Contains("DIGIT") ) 
+                       tempo += Form("%d ", AliQA::kDIGITS) ; 
+               fQATasks = tempo ; 
+               if (fQATasks.IsNull()) {
+                       AliInfo("No QA requested\n")  ;
+                       fRunQA = kFALSE ;
+                       return kTRUE ; 
+               }
+       }       
+       TString tempo(fQATasks) ; 
+    tempo.ReplaceAll(Form("%d", AliQA::kHITS), AliQA::GetTaskName(AliQA::kHITS))       ;
+    tempo.ReplaceAll(Form("%d", AliQA::kSDIGITS), AliQA::GetTaskName(AliQA::kSDIGITS)) ;       
+    tempo.ReplaceAll(Form("%d", AliQA::kDIGITS), AliQA::GetTaskName(AliQA::kDIGITS)) ;         
+       AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;  
+       fRunQA = kTRUE ;
+       fQASteer->SetActiveDetectors(fQADetectors) ; 
+       fQASteer->SetTasks(fQATasks) ; 
+       return kTRUE; 
+} 
+
 //_____________________________________________________________________________
 void AliSimulation::ProcessEnvironmentVars()
 {
@@ -1760,3 +1871,94 @@ void AliSimulation::ProcessEnvironmentVars()
     
     AliInfo(Form("Run number = %d", fRun)); 
 }
+
+//_____________________________________________________________________________
+void AliSimulation::WriteGRPEntry()
+{
+  // Get the necessary information from galice (generator, trigger etc) and
+  // write a GRP entry corresponding to the settings in the Config.C used
+  AliInfo("Writing global run parameters entry into the OCDB");
+
+  TMap *grpMap = new TMap();
+  grpMap->SetName("MONTECARLO");
+
+  grpMap->Add(new TObjString("fRunType"),new TObjString("PHYSICS"));
+  grpMap->Add(new TObjString("fAliceStartTime"),new TObjString("0"));
+  grpMap->Add(new TObjString("fAliceStopTime"),new TObjString("9999"));
+
+  AliGenMC *gen = dynamic_cast<AliGenMC*>(gAlice->Generator());
+  if (gen) {
+    grpMap->Add(new TObjString("fAliceBeamEnergy"),new TObjString(Form("%f",gen->GetEnergyCMS())));
+    TString projectile;
+    Int_t a,z;
+    gen->GetProjectile(projectile,a,z);
+    TString target;
+    gen->GetTarget(target,a,z);
+    TString beamType = projectile + "-" + target;
+    grpMap->Add(new TObjString("fAliceBeamType"),new TObjString(beamType.Data()));
+  }
+  else {
+    AliWarning("Unknown beam type and energy!");
+    grpMap->Add(new TObjString("fAliceBeamEnergy"),new TObjString("UNKNOWN"));
+    grpMap->Add(new TObjString("fAliceBeamType"),new TObjString("UNKNOWN"));
+  }
+
+  UInt_t detectorPattern  = 0;
+  Int_t nDets = 0;
+  TObjArray *detArray = gAlice->Detectors();
+  for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors-1; iDet++) {
+    if (detArray->FindObject(AliDAQ::OfflineModuleName(iDet))) {
+      detectorPattern |= (1 << iDet);
+      nDets++;
+    }
+  }
+  // HLT
+  if (!fRunHLT.IsNull())
+    detectorPattern |= (1 << AliDAQ::kHLTId);
+
+  grpMap->Add(new TObjString("fNumberOfDetectors"),new TObjString(Form("%d",nDets)));
+  grpMap->Add(new TObjString("fDetectorMask"),new TObjString(Form("%u",detectorPattern)));
+  grpMap->Add(new TObjString("fLHCPeriod"),new TObjString("LHC08c"));
+
+  grpMap->Add(new TObjString("fLHCState"),new TObjString("STABLE BEAMS"));
+  grpMap->Add(new TObjString("fLHCCondition"),new TObjString("0"));
+  grpMap->Add(new TObjString("fLHCLuminosity"),new TObjString("0"));
+  grpMap->Add(new TObjString("fBeamIntensity"),new TObjString("0"));
+
+  AliMagF *field = gAlice->Field();
+  Float_t solenoidField = TMath::Abs(field->SolenoidField());
+  Float_t factor = field->Factor();
+  Float_t l3current = TMath::Abs(factor)*solenoidField*30000./5.;
+  grpMap->Add(new TObjString("fL3Current"),new TObjString(Form("%f",l3current)));
+  
+  if (factor > 0) {
+    grpMap->Add(new TObjString("fL3Polarity"),new TObjString("0"));
+    grpMap->Add(new TObjString("fDipolePolarity"),new TObjString("0"));
+  }
+  else {
+    grpMap->Add(new TObjString("fL3Polarity"),new TObjString("1"));
+    grpMap->Add(new TObjString("fDipolePolarity"),new TObjString("1"));
+  }
+
+  if (TMath::Abs(factor) != 0)
+    grpMap->Add(new TObjString("fDipoleCurrent"),new TObjString("6000"));
+  else 
+    grpMap->Add(new TObjString("fDipoleCurrent"),new TObjString("0"));
+
+  grpMap->Add(new TObjString("fCavernTemperature"),new TObjString("0"));
+  grpMap->Add(new TObjString("fCavernPressure"),new TObjString("0"));
+
+  // Now store the entry in OCDB
+  AliCDBManager* man = AliCDBManager::Instance();
+
+  AliCDBId id("GRP/GRP/Data", man->GetRun(), man->GetRun());
+  AliCDBMetaData *metadata= new AliCDBMetaData();
+
+  // Get root version
+  const char* rootv = gROOT->GetVersion();
+  metadata->SetResponsible("alice-off@cern.ch");
+  metadata->SetComment("Automatically produced GRP entry for Monte Carlo");
+  man->Put(grpMap,id,metadata);
+}