]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliRun.cxx
added merging for QA
[u/mrichter/AliRoot.git] / STEER / AliRun.cxx
index fe45e36d5d935b53bca585538c9d1492846bc326..9b91c4e3492f361059b6ec517ee5b70412fb5e10 100644 (file)
 #include <TROOT.h>
 #include <TRandom3.h>
 #include <TSystem.h>
-#include <TVector.h>
 #include <TVirtualMC.h>
+#include <TGeoManager.h>
 // 
+#include "AliLog.h"
 #include "AliDetector.h"
 #include "AliDisplay.h"
 #include "AliHeader.h"
 #include "AliPDG.h"
 #include "AliRun.h"
 #include "AliStack.h"
+#include "AliCDBManager.h"
+#include "AliAlignObj.h"
 
 AliRun *gAlice;
 
-
 ClassImp(AliRun)
 
 //_______________________________________________________________________
 AliRun::AliRun():
-  fRun(0),
+  fRun(-1),
   fEvent(0),
   fEventNrInRun(0),
   fEventsPerRun(0),
-  fDebug(0),
   fModules(0),
   fGeometry(0),
   fMCApp(0),
   fDisplay(0),
-  fTimer(),
   fField(0),
-  fMC(0),
   fNdets(0),
   fInitDone(kFALSE),
   fLego(0),
   fPDGDB(0),  //Particle factory object
-  fConfigFunction("\0"),
+  fConfigFunction(""),
   fRandom(0),
+  fBaseFileName(""),
+  fIsRootGeometry(kFALSE),
+  fGeometryFromCDB(kFALSE),
+  fGeometryFileName(""),
+  fTriggerDescriptor(""),
   fRunLoader(0x0)
 {
   //
@@ -96,29 +100,32 @@ AliRun::AliRun():
   //
   AliConfig::Instance();//skowron 29 Feb 2002
                         //ensures that the folder structure is build
+
 }
 
 //_______________________________________________________________________
 AliRun::AliRun(const AliRun& arun):
   TNamed(arun),
-  fRun(0),
+  fRun(-1),
   fEvent(0),
   fEventNrInRun(0),
   fEventsPerRun(0),
-  fDebug(0),
   fModules(0),
   fGeometry(0),
   fMCApp(0),
   fDisplay(0),
-  fTimer(),
   fField(0),
-  fMC(0),
   fNdets(0),
   fInitDone(kFALSE),
   fLego(0),
   fPDGDB(0),  //Particle factory object
   fConfigFunction("\0"),
   fRandom(0),
+  fBaseFileName(""),
+  fIsRootGeometry(kFALSE),
+  fGeometryFromCDB(kFALSE),
+  fGeometryFileName(""),
+  fTriggerDescriptor(""),
   fRunLoader(0x0)
 {
   //
@@ -130,24 +137,26 @@ AliRun::AliRun(const AliRun& arun):
 //_____________________________________________________________________________
 AliRun::AliRun(const char *name, const char *title):
   TNamed(name,title),
-  fRun(0),
+  fRun(-1),
   fEvent(0),
   fEventNrInRun(0),
   fEventsPerRun(0),
-  fDebug(0),
   fModules(new TObjArray(77)), // Support list for the Detectors
   fGeometry(0),
   fMCApp(0),
   fDisplay(0),
-  fTimer(),
   fField(0),
-  fMC(gMC),
   fNdets(0),
   fInitDone(kFALSE),
   fLego(0),
   fPDGDB(TDatabasePDG::Instance()),        //Particle factory object!
   fConfigFunction("Config();"),
   fRandom(new TRandom3()),
+  fBaseFileName(""),
+  fIsRootGeometry(kFALSE),
+  fGeometryFromCDB(kFALSE),
+  fGeometryFileName(""),
+  fTriggerDescriptor(""),
   fRunLoader(0x0)
 {
   //
@@ -168,8 +177,6 @@ AliRun::AliRun(const char *name, const char *title):
 
   // Add to list of browsable  
   gROOT->GetListOfBrowsables()->Add(this,name);
-  // Create the TNode geometry for the event display
-  BuildSimpleGeometry();
   
   // Create default mag field
   SetField();
@@ -216,9 +223,9 @@ AliRun::~AliRun()
 }
 
 //_______________________________________________________________________
-void AliRun::Copy(AliRun &) const
+void AliRun::Copy(TObject &) const
 {
-  Fatal("Copy","Not implemented!\n");
+  AliFatal("Not implemented!");
 }
 
 //_______________________________________________________________________
@@ -269,14 +276,40 @@ AliGenerator* AliRun::Generator() const
 //_______________________________________________________________________
 void  AliRun::SetField(AliMagF* magField)
 {
-    // Set Magnetic Field Map
-    fField = magField;
-    fField->ReadField();
+  //
+  // Set Magnetic Field Map
+  //
+  fField = magField;
+  fField->ReadField();
+}
+
+//_______________________________________________________________________
+void AliRun::SetRootGeometry(Bool_t flag)
+{
+// Instruct application that the geometry is to be retreived from a root file.
+   fIsRootGeometry = flag;
+   if (flag && gMC) gMC->SetRootGeometry();
+}
+
+//_______________________________________________________________________
+void AliRun::SetGeometryFromCDB()
+{
+  // Set the loading of geometry from cdb instead of creating it
+  // A default CDB storage needs to be set before this method is called
+  if(AliCDBManager::Instance()->IsDefaultStorageSet() &&
+       AliCDBManager::Instance()->GetRun() >= 0){
+    SetRootGeometry();
+    fGeometryFromCDB = kTRUE;
+  }else{
+    AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    AliError("Loading of geometry from CDB ignored. First set a default CDB storage!");
+    AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+  }
 }
 
 //_______________________________________________________________________
 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
-                     Float_t maxField, char* filename)
+                     Float_t maxField, const char* filename)
 {
   //
   //  Set magnetic field parameters
@@ -297,7 +330,7 @@ void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
     fField = new AliMagFDM("Map4",filename,type,scale,maxField);
     fField->ReadField();
   } else {
-    Warning("SetField","Invalid map %d\n",version);
+    AliWarning(Form("Invalid map %d",version));
   }
 }
 
@@ -306,19 +339,20 @@ void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
 void AliRun::InitLoaders()
 {
   //creates list of getters
-  if (GetDebug()) Info("InitLoaders","");
+  AliDebug(1, "");
   TIter next(fModules);
   AliModule *mod;
   while((mod = (AliModule*)next()))
    { 
+     mod->SetRunLoader(fRunLoader);
      AliDetector *det = dynamic_cast<AliDetector*>(mod);
      if (det) 
       {
-        if (GetDebug()) Info("InitLoaders"," Adding %s ",det->GetName());
+        AliDebug(2, Form("Adding %s", det->GetName()));
         fRunLoader->AddLoader(det);
       }
    }
-  if (GetDebug()) Info("InitLoaders","Done");
+  AliDebug(1, "Done");
 }
 //_____________________________________________________________________________
 
@@ -327,10 +361,10 @@ void AliRun::FinishRun()
   //
   // Called at the end of the run.
   //
-  
+
   if(fLego) 
    {
-    if (GetDebug()) Info("FinishRun"," Finish Lego");
+    AliDebug(1, "Finish Lego");
     fRunLoader->CdGAFile();
     fLego->FinishRun();
    }
@@ -339,11 +373,11 @@ void AliRun::FinishRun()
   TIter next(fModules);
   AliModule *detector;
   while((detector = dynamic_cast<AliModule*>(next()))) {
-    if (GetDebug()) Info("FinishRun"," %s->FinishRun()",detector->GetName());
+    AliDebug(2, Form("%s->FinishRun()", detector->GetName()));
     detector->FinishRun();
   }
   
-  if (GetDebug()) Info("FinishRun"," fRunLoader->WriteHeader(OVERWRITE)");
+  AliDebug(1, "fRunLoader->WriteHeader(OVERWRITE)");
   fRunLoader->WriteHeader("OVERWRITE");
 
   // Write AliRun info and all detectors parameters
@@ -351,12 +385,7 @@ void AliRun::FinishRun()
   Write(0,TObject::kOverwrite);//write AliRun
   fRunLoader->Write(0,TObject::kOverwrite);//write RunLoader itself
   
-  // Clean tree information
-  if (GetDebug()) Info("FinishRun"," fRunLoader->Stack()->FinishRun()");
-  fRunLoader->Stack()->FinishRun();
-
-  if(fMCApp) fMCApp->FinishRun();
-
+  if(fMCApp) fMCApp->FinishRun();  
   fRunLoader->Synchronize();
 }
 
@@ -374,7 +403,7 @@ void AliRun::Announce() const
   printf("    You are running AliRoot version NewIO\n");
 
   printf("%6s","*");
-  printf("    The cvs tag for the current program is $Name$\n");
+  printf("    The SVN version for the current program is $Id$\n");
 
   printf("%6s","*");printf("%64s","*\n");
   printf("%70s",
@@ -420,7 +449,7 @@ Int_t AliRun::GetEvent(Int_t event)
 //
   if (fRunLoader == 0x0)
    {
-     Error("GetEvent","RunLoader is not set. Can not load data.");
+     AliError("RunLoader is not set. Can not load data.");
      return -1;
    }
 /*****************************************/ 
@@ -444,8 +473,8 @@ Int_t AliRun::GetEvent(Int_t event)
 
   // Set Trees branch addresses
   TIter next(fModules);
-  AliModule *detector;
-  while((detector = dynamic_cast<AliModule*>(next()))) 
+  AliDetector *detector;
+  while((detector = dynamic_cast<AliDetector*>(next()))) 
    {
      detector->SetTreeAddress();
    }
@@ -456,27 +485,28 @@ Int_t AliRun::GetEvent(Int_t event)
 //_______________________________________________________________________
 TGeometry *AliRun::GetGeometry()
 {
-  //
-  // Import Alice geometry from current file
-  // Return pointer to geometry object
-  //
-  if (!fGeometry) fGeometry = dynamic_cast<TGeometry*>(gDirectory->Get("AliceGeom"));
-  //
-  // Unlink and relink nodes in detectors
-  // This is bad and there must be a better way...
-  //
+
+  // Create the TNode geometry for the event display
+  if (!fGeometry) { 
+    BuildSimpleGeometry();
+    //
+    // Unlink and relink nodes in detectors
+    // This is bad and there must be a better way...
+    //
   
-  TIter next(fModules);
-  AliModule *detector;
-  while((detector = dynamic_cast<AliModule*>(next()))) {
-    TList *dnodes=detector->Nodes();
-    Int_t j;
-    TNode *node, *node1;
-    for ( j=0; j<dnodes->GetSize(); j++) {
-      node = dynamic_cast<TNode*>(dnodes->At(j));
-      node1 = fGeometry->GetNode(node->GetName());
-      dnodes->Remove(node);
-      dnodes->AddAt(node1,j);
+    TIter next(fModules);
+    AliModule *detector;
+    while((detector = dynamic_cast<AliModule*>(next()))) {
+      detector->BuildGeometry();
+      TList *dnodes=detector->Nodes();
+      Int_t j;
+      TNode *node, *node1;
+      for ( j=0; j<dnodes->GetSize(); j++) {
+       node = dynamic_cast<TNode*>(dnodes->At(j));
+       node1 = fGeometry->GetNode(node->GetName());
+       dnodes->Remove(node);
+       dnodes->AddAt(node1,j);
+      }
     }
   }
   return fGeometry;
@@ -538,34 +568,27 @@ void AliRun::InitMC(const char *setup)
   Announce();
 
   if(fInitDone) {
-    Warning("Init","Cannot initialise AliRun twice!\n");
+    AliWarning("Cannot initialise AliRun twice!");
     return;
   }
     
-  fMCApp=new AliMC(GetName(),GetTitle());
+  if (!fMCApp)  
+    fMCApp=new AliMC(GetName(),GetTitle());
     
   gROOT->LoadMacro(setup);
   gInterpreter->ProcessLine(fConfigFunction.Data());
 
-  InitLoaders();
-
-  fRunLoader->MakeTree("E");
-  fRunLoader->LoadKinematics("RECREATE");
-  fRunLoader->LoadTrackRefs("RECREATE");
-  fRunLoader->LoadHits("all","RECREATE");
-  
+  if(AliCDBManager::Instance()->GetRun() >= 0) { 
+       SetRunNumber(AliCDBManager::Instance()->GetRun());
+  } else {
+       AliWarning("Run number not initialized!!");
+  }
   
   fRunLoader->CdGAFile();
-
+    
   AliPDG::AddParticlesToPdgDataBase();  
 
   fNdets = fModules->GetLast()+1;
-
-  //
-
-  // Added also after in case of interactive initialisation of modules
-  fNdets = fModules->GetLast()+1;
-
   TIter next(fModules);
   for(Int_t i=0; i<fNdets; ++i)
    {
@@ -585,10 +608,19 @@ void AliRun::InitMC(const char *setup)
    
    fMCApp->Init();
    
+   //Must be here because some MCs (G4) adds detectors here and not in Config.C
+   InitLoaders();
+   fRunLoader->MakeTree("E");
+   if (fLego == 0x0)
+    {
+      fRunLoader->LoadKinematics("RECREATE");
+      fRunLoader->LoadTrackRefs("RECREATE");
+      fRunLoader->LoadHits("all","RECREATE");
+    }
    fInitDone = kTRUE;
-
    //
    // Save stuff at the beginning of the file to avoid file corruption
+   fRunLoader->CdGAFile();
    Write();
    fEventNrInRun = -1; //important - we start Begin event from increasing current number in run
 }
@@ -624,12 +656,12 @@ void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
   // Main function to be called to reconstruct Alice event
   // 
    Int_t nev = fRunLoader->GetNumberOfEvents();
-   if (GetDebug()) Info("RunReco","Found %d events",nev);
+   AliDebug(1, Form("Found %d events", nev));
    Int_t nFirst = first;
    Int_t nLast  = (last < 0)? nev : last;
    
    for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
-     if (GetDebug()) Info("RunReco","Processing event %d",nevent);
+     AliDebug(1, Form("Processing event %d", nevent));
      GetEvent(nevent);
      Digits2Reco(selected);
    }
@@ -687,7 +719,7 @@ void AliRun::Tree2Tree(Option_t *option, const char *selected)
        
        if (oS) 
         {
-          if (GetDebug()) Info("Tree2Tree","Processing Hits2SDigits for %s ...",detector->GetName());
+          AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName()));
           loader->LoadHits("read");
           if (loader->TreeS() == 0x0) loader->MakeTree("S");
           detector->MakeBranch(option);
@@ -698,7 +730,7 @@ void AliRun::Tree2Tree(Option_t *option, const char *selected)
         }  
        if (oD) 
         {
-          if (GetDebug()) Info("Tree2Tree","Processing SDigits2Digits for %s ...",detector->GetName());
+          AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName()));
           loader->LoadSDigits("read");
           if (loader->TreeD() == 0x0) loader->MakeTree("D");
           detector->MakeBranch(option);
@@ -709,7 +741,7 @@ void AliRun::Tree2Tree(Option_t *option, const char *selected)
         } 
        if (oR) 
         {
-          if (GetDebug()) Info("Tree2Tree","Processing Digits2Reco for %s ...",detector->GetName());
+          AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName()));
           loader->LoadDigits("read");
           if (loader->TreeR() == 0x0) loader->MakeTree("R");
           detector->MakeBranch(option);
@@ -726,7 +758,7 @@ void AliRun::Tree2Tree(Option_t *option, const char *selected)
 //_______________________________________________________________________
 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
                     Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
-                    Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
+                    Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener, Int_t nev)
 {
   //
   // Generates lego plots of:
@@ -765,19 +797,17 @@ void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
   */
   //End_Html
   //
-
+  // Number of events 
+    if (nev == -1) nev  = nc1 * nc2;
+    
   // check if initialisation has been done
-  if (!fInitDone) InitMC(setup);
-  //Save current generator
-  AliGenerator *gen=fMCApp->Generator();
   // If runloader has been initialized, set the number of events per file to nc1 * nc2
-  if (fRunLoader) fRunLoader->SetNumberOfEventsPerFile(nc1 * nc2);
-
+    
   // Set new generator
   if (!gener) gener  = new AliLegoGenerator();
-  fMCApp->ResetGenerator(gener);
   //
   // Configure Generator
+  
   gener->SetRadiusRange(rmin, rmax);
   gener->SetZMax(zmax);
   gener->SetCoor1Range(nc1, c1min, c1max);
@@ -787,16 +817,19 @@ void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
   //Create Lego object  
   fLego = new AliLego("lego",gener);
 
+  if (!fInitDone) InitMC(setup);
+  //Save current generator
+  
+  AliGenerator *gen=fMCApp->Generator();
+  fMCApp->ResetGenerator(gener);
   //Prepare MC for Lego Run
   gMC->InitLego();
   
   //Run Lego Object
 
-  //gMC->ProcessRun(nc1*nc2+1);
-  gMC->ProcessRun(nc1*nc2);
-  
-  // Create only the Root event Tree
-  fRunLoader->MakeTree("E");
+
+  if (fRunLoader) fRunLoader->SetNumberOfEventsPerFile(nev);
+  gMC->ProcessRun(nev);
   
   // End of this run, close files
   FinishRun();
@@ -823,19 +856,25 @@ void AliRun::SetConfigFunction(const char * config)
 //_______________________________________________________________________
 void AliRun::Field(const Double_t* x, Double_t *b) const
 {
-   Float_t xfloat[3];
-   for (Int_t i=0; i<3; i++) xfloat[i] = x[i]; 
-
-   if (Field()) {
-         Float_t bfloat[3];
-         Field()->Field(xfloat,bfloat);
-         for (Int_t j=0; j<3; j++) b[j] = bfloat[j]; 
-   } 
-   else {
-         printf("No mag field defined!\n");
-         b[0]=b[1]=b[2]=0.;
-   }
+  //
+  // Return the value of the magnetic field
+  //
+    
+  Float_t xfloat[3];
+  for (Int_t i=0; i<3; i++) xfloat[i] = x[i]; 
+  
+  if (Field()) {
+
+    Float_t bfloat[3];
+    Field()->Field(xfloat,bfloat);
+    for (Int_t j=0; j<3; j++) b[j] = bfloat[j]; 
+  } 
+  else {
+    AliError("No mag field defined!");
+    b[0]=b[1]=b[2]=0.;
+  }
 
+  
 }      
 
 // 
@@ -857,45 +896,45 @@ void AliRun::Streamer(TBuffer &R__b)
     AliRun::Class()->WriteBuffer(R__b, this);
   }
 }
-
-
 //_______________________________________________________________________
 
-//_______________________________________________________________________
 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
 {
   fRunLoader->GetHeader()->SetGenEventHeader(header);
 }
-
-//___________________________________________________________________________
+//_______________________________________________________________________
 
 Int_t AliRun::GetEvNumber() const
 { 
 //Returns number of current event  
   if (fRunLoader == 0x0)
    {
-     Error("GetEvent","RunLoader is not set. Can not load data.");
+     AliError("RunLoader is not set. Can not load data.");
      return -1;
    }
 
   return fRunLoader->GetEventNumber();
 }
+//_______________________________________________________________________
 
 void AliRun::SetRunLoader(AliRunLoader* rloader)
 {
+  //
+  // Set the loader of the run
+  //
   fRunLoader = rloader;
   if (fRunLoader == 0x0) return;
   
   TString evfoldname;
   TFolder* evfold = fRunLoader->GetEventFolder();
   if (evfold) evfoldname = evfold->GetName();
-  else Warning("SetRunLoader","Did not get Event Folder from Run Loader");
+  else AliWarning("Did not get Event Folder from Run Loader");
   
   if ( fRunLoader->GetAliRun() )
    {//if alrun already exists in folder
     if (fRunLoader->GetAliRun() != this )
      {//and is different than this - crash
-       Fatal("AliRun","AliRun is already in Folder and it is not this object");
+       AliFatal("AliRun is already in Folder and it is not this object");
        return;//pro forma
      }//else do nothing
    }
@@ -909,17 +948,18 @@ void AliRun::SetRunLoader(AliRunLoader* rloader)
   while((module = (AliModule*)next())) 
    {
      if (evfold) AliConfig::Instance()->Add(module,evfoldname);
+     module->SetRunLoader(fRunLoader);
      AliDetector* detector = dynamic_cast<AliDetector*>(module);
      if (detector)
       {
         AliLoader* loader = fRunLoader->GetLoader(detector);
         if (loader == 0x0)
          {
-           Error("SetRunLoader","Can not get loader for detector %s",detector->GetName());
+           AliError(Form("Can not get loader for detector %s", detector->GetName()));
          }
         else
          {
-           if (GetDebug()) Info("SetRunLoader","Setting loader for detector %s",detector->GetName());
+           AliDebug(1, Form("Setting loader for detector %s", detector->GetName()));
            detector->SetLoader(loader);
          }
       }
@@ -928,13 +968,29 @@ void AliRun::SetRunLoader(AliRunLoader* rloader)
 
 void AliRun::AddModule(AliModule* mod)
 {
+  //
+  // Add a module to the module list
+  //
   if (mod == 0x0) return;
   if (strlen(mod->GetName()) == 0) return;
   if (GetModuleID(mod->GetName()) >= 0) return;
   
-  if (GetDebug()) Info("AddModule","%s",mod->GetName());
+  AliDebug(1, mod->GetName());
   if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod);
   else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName());
 
   Modules()->Add(mod);
+  
+  fNdets++;
+}
+
+//_____________________________________________________________________________
+/*inline*/ Bool_t AliRun::IsFileAccessible(const char* fnam, EAccessMode mode)
+{ return !gSystem->AccessPathName(fnam,mode);}
+
+//______________________________________________________
+/*inline*/ Bool_t AliRun::IsFileAccessible(Char_t* name,EAccessMode mode)
+{
+  TString str = name; gSystem->ExpandPathName(str);
+  return !gSystem->AccessPathName(str.Data(),mode);
 }