]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/STEER/AliSimulation.cxx
Technical fix in the CheckRecoCDBvsSimuCDB
[u/mrichter/AliRoot.git] / STEER / STEER / AliSimulation.cxx
index 9c19de17b6f25c830a0fe9ceeac755930a05fc3b..2fbf9872af78085c2f06514dc4538b6b37916fc4 100644 (file)
@@ -13,7 +13,7 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/* $Id$ */
+/* $Id: AliSimulation.cxx 64623 2013-10-21 13:38:58Z rgrosso $ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-#include <TCint.h>
 #include <TFile.h>
 #include <TGeoGlobalMagField.h>
 #include <TGeoManager.h>
 #include "AliRun.h"
 #include "AliDigitizationInput.h"
 #include "AliRunLoader.h"
+#include "AliStack.h"
 #include "AliSimulation.h"
 #include "AliSysInfo.h"
 #include "AliVertexGenFile.h"
@@ -156,19 +156,16 @@ using std::ofstream;
 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"
-// #ifdef MFT_UPGRADE
-//                                                                             ,"MFT"
-// #endif 
-                                                                            ,"MFT"    // AU
-                                                                           ,"HLT"
-};
+ const char* AliSimulation::fgkDetectorName[AliSimulation::fgkNDetectors] = {"ITS", "TPC", "TRD", 
+ "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE","AD",
+ "FIT","MFT","HLT"};
 
 //_____________________________________________________________________________
 AliSimulation::AliSimulation(const char* configFileName,
                             const char* name, const char* title) :
   TNamed(name, title),
 
+  fRunGeneratorOnly(kFALSE),
   fRunGeneration(kTRUE),
   fRunSimulation(kTRUE),
   fLoadAlignFromCDB(kTRUE),
@@ -182,6 +179,7 @@ AliSimulation::AliSimulation(const char* configFileName,
   fDeleteIntermediateFiles(kFALSE),
   fWriteSelRawData(kFALSE),
   fStopOnError(kFALSE),
+  fUseMonitoring(kFALSE),
   fNEvents(1),
   fConfigFileName(configFileName),
   fGAliceFileName("galice.root"),
@@ -378,7 +376,7 @@ void AliSimulation::SetCDBLock() {
   // Set CDB lock: from now on it is forbidden to reset the run number
   // or the default storage or to activate any further storage!
   
-  ULong_t key = AliCDBManager::Instance()->SetLock(1);
+  ULong64_t key = AliCDBManager::Instance()->SetLock(1);
   if (key) fKey = key;
 }
 
@@ -631,6 +629,17 @@ Bool_t AliSimulation::Run(Int_t nEvents)
    
   if (nEvents > 0) fNEvents = nEvents;
 
+  // Run generator-only code on demand
+  if (fRunGeneratorOnly)
+  {
+    if(!RunGeneratorOnly())
+    {
+      if (fStopOnError) return kFALSE;
+    }
+    else
+      return kTRUE;
+  }
+
   // create and setup the HLT instance
   if (!fRunHLT.IsNull() && !CreateHLT()) {
     if (fStopOnError) return kFALSE;
@@ -1003,6 +1012,9 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
     AliError("gAlice was already run. Restart aliroot and try again.");
     return kFALSE;
   }
+  
+  // Setup monitoring if requested
+  gAlice->GetMCApp()->SetUseMonitoring(fUseMonitoring);
 
   AliInfo(Form("initializing gAlice with config file %s",
           fConfigFileName.Data()));
@@ -1091,7 +1103,6 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
 
    gMC->SetMagField(TGeoGlobalMagField::Instance()->GetField());
    AliSysInfo::AddStamp("RunSimulation_GetField");
-   
    gAlice->GetMCApp()->Init();
    AliSysInfo::AddStamp("RunSimulation_InitMCApp");
 
@@ -1211,7 +1222,6 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
 
   // Create the Root Tree with one branch per detector
   //Hits moved to begin event -> now we are crating separate tree for each event
-
   gMC->ProcessRun(nEvents);
 
   // End of this run, close files
@@ -1223,6 +1233,75 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
   return kTRUE;
 }
 
+//_____________________________________________________________________________
+Bool_t AliSimulation::RunGeneratorOnly()
+{
+  // Execute Config.C
+  TInterpreter::EErrorCode interpreterError=TInterpreter::kNoError;
+  gROOT->LoadMacro(fConfigFileName.Data());
+  Long_t interpreterResult=gInterpreter->ProcessLine(gAlice->GetConfigFunction(), &interpreterError);
+  if (interpreterResult!=0 || interpreterError!=TInterpreter::kNoError) {
+    AliFatal(Form("execution of config file \"%s\" failed with error %d", fConfigFileName.Data(), (int)interpreterError));
+  }
+
+  // Setup the runloader and generator, check if everything is OK
+  AliRunLoader* runLoader = AliRunLoader::Instance();
+  AliGenerator* generator = gAlice->GetMCApp()->Generator();
+  if (!runLoader) {
+    AliError(Form("gAlice has no run loader object. "
+                  "Check your config file: %s", fConfigFileName.Data()));
+    return kFALSE;
+  }
+  if (!generator) {
+    AliError(Form("gAlice has no generator object. "
+                  "Check your config file: %s", fConfigFileName.Data()));
+    return kFALSE;
+  }
+
+  runLoader->LoadKinematics("RECREATE");
+  runLoader->MakeTree("E");
+
+  // Create stack and header
+  runLoader->MakeStack();
+  AliStack*  stack      = runLoader->Stack();
+  AliHeader* header     = runLoader->GetHeader();
+
+  // Intialize generator
+  generator->Init();
+  generator->SetStack(stack);
+
+  // Run main generator loop
+
+  for (Int_t iev=0; iev<fNEvents; iev++)
+  {
+    // Initialize event
+    header->Reset(0,iev);
+    runLoader->SetEventNumber(iev);
+    stack->Reset();
+    runLoader->MakeTree("K");
+
+    // Generate event
+    generator->Generate();
+
+    // Finish event
+    header->SetNprimary(stack->GetNprimary());
+    header->SetNtrack(stack->GetNtrack());
+    stack->FinishEvent();
+    header->SetStack(stack);
+    runLoader->TreeE()->Fill();
+    runLoader->WriteKinematics("OVERWRITE");
+  }
+
+  // Finalize
+  generator->FinishRun();
+  // Write file
+  runLoader->WriteHeader("OVERWRITE");
+  generator->Write();
+  runLoader->Write();
+
+  return kTRUE;
+}
+
 //_____________________________________________________________________________
 Bool_t AliSimulation::RunSDigitization(const char* detectors)
 {
@@ -2027,7 +2106,9 @@ void AliSimulation::FinishRun()
   AliRunLoader::Instance()->CdGAFile();
   gAlice->Write(0,TObject::kOverwrite);//write AliRun
   AliRunLoader::Instance()->Write(0,TObject::kOverwrite);//write RunLoader itself
-  
+  //
+  StoreUsedCDBMaps();
+  //  
   if(gAlice->GetMCApp()) gAlice->GetMCApp()->FinishRun();  
   AliRunLoader::Instance()->Synchronize();
 }
@@ -2434,3 +2515,46 @@ time_t AliSimulation::GenerateTimeStamp() const
   else
     return 0;
 }
+
+//_____________________________________________________________________________
+void AliSimulation::StoreUsedCDBMaps() const
+{
+  // write in galice.root maps with used CDB paths
+  //
+  const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();      
+  const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();  
+  //
+  TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());    
+  cdbMapCopy->SetOwner(1);      
+  //  cdbMapCopy->SetName("cdbMap");    
+  TIter iter(cdbMap->GetTable());       
+  //    
+  TPair* pair = 0;      
+  while((pair = dynamic_cast<TPair*> (iter.Next()))){   
+    TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());       
+    TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
+    if (keyStr && valStr)
+      cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));    
+  }     
+  //    
+  TList *cdbListCopy = new TList();     
+  cdbListCopy->SetOwner(1);     
+  //  cdbListCopy->SetName("cdbList");  
+  //
+  TIter iter2(cdbList);         
+  
+  AliCDBId* id=0;
+  while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){         
+    cdbListCopy->Add(new TObjString(id->ToString().Data()));    
+  }     
+  //
+  AliRunLoader::Instance()->CdGAFile();
+  gDirectory->WriteObject(cdbMapCopy,"cdbMap","kSingleKey");
+  gDirectory->WriteObject(cdbListCopy,"cdbList","kSingleKey");  
+  //
+  AliInfo(Form("Stored used OCDB entries as TMap %s and TList %s in %s",
+              cdbMapCopy->GetName(),
+              cdbListCopy->GetName(),
+              fGAliceFileName.Data()));
+  //
+}