]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliReconstruction.cxx
"Cleaned" initialization and usage of the run number.
[u/mrichter/AliRoot.git] / STEER / AliReconstruction.cxx
index d806a6e6f956a768bafbc7b4b36309760fcf776d..c34de491b99a04f301d01a759dec891efb8198cf 100644 (file)
 #include "AliGeomManager.h"
 #include "AliTrackPointArray.h"
 #include "AliCDBManager.h"
+#include "AliCDBStorage.h"
 #include "AliCDBEntry.h"
 #include "AliAlignObj.h"
 
@@ -194,7 +195,7 @@ ClassImp(AliReconstruction)
 const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
 
 //_____________________________________________________________________________
-AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdbUri,
+AliReconstruction::AliReconstruction(const char* gAliceFilename,
                                     const char* name, const char* title) :
   TNamed(name, title),
 
@@ -211,6 +212,8 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdb
   fFillTriggerESD(kTRUE),
 
   fCleanESD(kTRUE),
+  fV0DCAmax(3.),
+  fV0CsPmin(0.),
   fDmax(50.),
   fZmax(50.),
 
@@ -239,9 +242,12 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdb
   fGRPList(NULL),
 
   fAlignObjArray(NULL),
-  fCDBUri(cdbUri),
-  fRemoteCDBUri(""),
-  fSpecCDBUri()
+  fCDBUri(),
+  fSpecCDBUri(), 
+  fInitCDBCalled(kFALSE),
+  fSetRunNumberFromDataCalled(kFALSE),
+  fRunQA(kTRUE) 
+
 {
 // create reconstruction object with default parameters
   
@@ -272,6 +278,8 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fFillTriggerESD(rec.fFillTriggerESD),
 
   fCleanESD(rec.fCleanESD),
+  fV0DCAmax(rec.fV0DCAmax),
+  fV0CsPmin(rec.fV0CsPmin),
   fDmax(rec.fDmax),
   fZmax(rec.fZmax),
 
@@ -301,8 +309,10 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
 
   fAlignObjArray(rec.fAlignObjArray),
   fCDBUri(rec.fCDBUri),
-  fRemoteCDBUri(rec.fRemoteCDBUri),
-  fSpecCDBUri()
+  fInitCDBCalled(rec.fInitCDBCalled),
+  fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
+  fSpecCDBUri(), 
+  fRunQA(kTRUE)
 {
 // copy constructor
 
@@ -344,12 +354,15 @@ AliReconstruction::~AliReconstruction()
 }
 
 //_____________________________________________________________________________
-void AliReconstruction::InitCDBStorage()
+void AliReconstruction::InitCDB()
 {
 // activate a default CDB storage
 // First check if we have any CDB storage set, because it is used 
 // to retrieve the calibration and alignment constants
 
+  if (fInitCDBCalled) return;
+  fInitCDBCalled = kTRUE;
+
   AliCDBManager* man = AliCDBManager::Instance();
   if (man->IsDefaultStorageSet())
   {
@@ -357,33 +370,25 @@ void AliReconstruction::InitCDBStorage()
     AliWarning("Default CDB storage has been already set !");
     AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
     AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-    fCDBUri = "";
+    fCDBUri = man->GetDefaultStorage()->GetURI();
   }
   else {
-    AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-    AliDebug(2, Form("Default CDB storage is set to: %s",fCDBUri.Data()));
-    AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    if (fCDBUri.Length() > 0) 
+    {
+       AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+       AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
+       AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    } else {
+       fCDBUri="local://$ALICE_ROOT";
+       AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+       AliWarning("Default CDB storage not yet set !!!!");
+       AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
+       AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+               
+    }
     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 AliReconstruction: %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];
@@ -393,7 +398,7 @@ void AliReconstruction::InitCDBStorage()
     AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
     man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
   }
-  man->Print();
+  
 }
 
 //_____________________________________________________________________________
@@ -405,17 +410,6 @@ void AliReconstruction::SetDefaultStorage(const char* uri) {
 
 }
 
-//_____________________________________________________________________________
-void AliReconstruction::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
-
-  fRemoteCDBUri = uri;
-
-}
-
 //_____________________________________________________________________________
 void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
 // Store a detector-specific CDB storage location
@@ -458,19 +452,24 @@ void AliReconstruction::SetSpecificStorage(const char* calibType, const char* ur
 
 }
 
-
-
-
 //_____________________________________________________________________________
-Bool_t AliReconstruction::SetRunNumber()
+Bool_t AliReconstruction::SetRunNumberFromData()
 {
   // The method is called in Run() in order
   // to set a correct run number.
   // In case of raw data reconstruction the
   // run number is taken from the raw data header
 
-  if(AliCDBManager::Instance()->GetRun() < 0) {
-    if (!fRunLoader) {
+  if (fSetRunNumberFromDataCalled) return kTRUE;
+  fSetRunNumberFromDataCalled = kTRUE;
+  
+  AliCDBManager* man = AliCDBManager::Instance();
+  
+  if(man->GetRun() > 0) {
+       AliWarning("Run number is taken from event header! Ignoring settings in AliCDBManager!");
+  } 
+  
+  if (!fRunLoader) {
       AliError("No run loader is found !"); 
       return kFALSE;
     }
@@ -492,12 +491,21 @@ Bool_t AliReconstruction::SetRunNumber()
        AliError("Neither gAlice nor RawReader objects are found !");
        return kFALSE;
       }
-    }
-    AliInfo(Form("CDB Run number: %d",AliCDBManager::Instance()->GetRun()));
   }
+
+  man->Print();  
+  
   return kTRUE;
 }
 
+//_____________________________________________________________________________
+void AliReconstruction::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!
+  
+  AliCDBManager::Instance()->SetLock(1);
+}
+
 //_____________________________________________________________________________
 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
 {
@@ -592,12 +600,17 @@ Bool_t AliReconstruction::Run(const char* input)
    AliSysInfo::AddStamp("LoadLoader");
 
   // Initialize the CDB storage
-  InitCDBStorage();
-   AliSysInfo::AddStamp("LoadCDB");
+  InitCDB();
+  
+  AliSysInfo::AddStamp("LoadCDB");
 
   // Set run number in CDBManager (if it is not already set by the user)
-  if (!SetRunNumber()) if (fStopOnError) return kFALSE;
-
+  if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
+  
+  // Set CDB lock: from now on it is forbidden to reset the run number
+  // or the default storage or to activate any further storage!
+  SetCDBLock();
+  
   // Import ideal TGeo geometry and apply misalignment
   if (!gGeoManager) {
     TString geom(gSystem->DirName(fGAliceFileName));
@@ -609,6 +622,14 @@ Bool_t AliReconstruction::Run(const char* input)
   if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
    AliSysInfo::AddStamp("LoadGeom");
 
+  //QA 
+  AliQADataMakerSteer qas ; 
+  if ( fRunQA && fRawReader) 
+               qas.Run("ALL", fRawReader) ; 
+ // checking the QA of previous steps
+  CheckQA() ; 
   // local reconstruction
   if (!fRunLocalReconstruction.IsNull()) {
     if (!RunLocalReconstruction(fRunLocalReconstruction)) {
@@ -717,9 +738,6 @@ Bool_t AliReconstruction::Run(const char* input)
   gSystem->GetProcInfo(&ProcInfo);
   AliInfo(Form("Current memory usage %d %d", ProcInfo.fMemResident, ProcInfo.fMemVirtual));
   
-  // checking the QA of previous steps
-  CheckQA() ; 
-  
   for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
     if (fRawReader) fRawReader->NextEvent();
     if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
@@ -914,7 +932,35 @@ Bool_t AliReconstruction::Run(const char* input)
 
   tree->GetUserInfo()->Add(esd);
   hlttree->GetUserInfo()->Add(hltesd);
-
+  
+  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());        
+         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(id->Clone());         
+   }    
+        
+   tree->GetUserInfo()->Add(cdbMapCopy);        
+   tree->GetUserInfo()->Add(cdbListCopy);
 
 
   if(fESDPar.Contains("ESD.par")){
@@ -939,7 +985,7 @@ Bool_t AliReconstruction::Run(const char* input)
 
   gROOT->cd();
   CleanUp(file, fileOld);
-  
+    
   // Create tags for the events in the ESD tree (the ESD tree is always present)
   // In case of empty events the tags will contain dummy values
   AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
@@ -950,11 +996,16 @@ Bool_t AliReconstruction::Run(const char* input)
   }
 
   //QA 
-  AliQADataMakerSteer qas ; 
-  qas.Run(AliQA::kRECPOINTS) ;
-  qas.Reset() ;
-  qas.Run(AliQA::kESDS) ;
-
+  if ( fRunQA ) {
+       qas.Run(fRunLocalReconstruction.Data(), AliQA::kRECPOINTS) ;
+//     qas.Reset() ;
+       qas.Run(fRunTracking.Data(), AliQA::kESDS) ;
+  }
+  
+  // Cleanup of CDB manager: cache and active storages!
+  AliCDBManager::Instance()->ClearCache();
+  
+  
   return kTRUE;
 }
 
@@ -1411,12 +1462,16 @@ Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
   AliInfo("Cleaning the ESD...");
   Int_t nTracks=esd->GetNumberOfTracks();
   AliInfo(Form("Number of ESD tracks before cleaning %d",nTracks));
+  Int_t nV0s=esd->GetNumberOfV0s();
+  AliInfo(Form("Number of ESD V0s before cleaning %d",nV0s));
 
-  Float_t cleanPars[]={fDmax,fZmax};
+  Float_t cleanPars[]={fV0DCAmax,fV0CsPmin,fDmax,fZmax};
   Bool_t rc=esd->Clean(cleanPars);
 
   nTracks=esd->GetNumberOfTracks();
   AliInfo(Form("Number of ESD tracks after cleaning %d",nTracks));
+  nV0s=esd->GetNumberOfV0s();
+  AliInfo(Form("Number of ESD V0s after cleaning %d",nV0s));
 
   return rc;
 }
@@ -1429,11 +1484,11 @@ Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
   AliCodeTimerAuto("")
     static Int_t eventNr=0; 
   TString detStr = detectors;
+  
   for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
-    if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
+  if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
     AliReconstructor* reconstructor = GetReconstructor(iDet);
     if (!reconstructor) continue;
-
     if (!ReadESD(esd, fgkDetectorName[iDet])) {
       AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
       TTree* clustersTree = NULL;
@@ -1818,8 +1873,11 @@ void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
   }
   delete fVertexer;
   fVertexer = NULL;
-  delete fDiamondProfile;
-  fDiamondProfile = NULL;
+  
+  if(!(AliCDBManager::Instance()->GetCacheFlag())) {
+       delete fDiamondProfile;
+       fDiamondProfile = NULL;
+  }
 
   delete fGRPList;
   fGRPList = NULL;
@@ -1968,8 +2026,8 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
     Int_t nV0s      = esd->GetNumberOfV0s();
     Int_t nCascades = esd->GetNumberOfCascades();
     Int_t nKinks    = esd->GetNumberOfKinks();
-    Int_t nVertices = nV0s + nCascades + nKinks + 1 /* = prim. vtx*/;
-    Int_t nJets     = 0;
+       Int_t nVertices = nV0s + 2*nCascades /*could lead to two vertices, one V0 and the Xi */+ nKinks + 1 /* = prim. vtx*/;    
+       Int_t nJets     = 0;
     Int_t nCaloClus = esd->GetNumberOfCaloClusters();
     Int_t nFmdClus  = 0;
     Int_t nPmdClus  = esd->GetNumberOfPmdTracks();
@@ -2311,7 +2369,9 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
       // add it to the V0 array as well
       Double_t d0[2] = { 999., 99.};
       new(V0s[jV0s++]) AliAODv0(vV0, 999., 99., p_pos, p_neg, d0); // to be refined
-    } // end of the loop on V0s
+    }
+       V0s.Expand(jV0s);        
+    // end of the loop on V0s
     
     // Kinks: it is a big mess the access to the information in the kinks
     // The loop is on the tracks in order to find the mother and daugther of each kink
@@ -2446,10 +2506,10 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
        }
       }
     }
+    vertices.Expand(jVertices);
 
     // Tracks (primary and orphan)
     for (Int_t nTrack = 0; nTrack < nTracks; ++nTrack) {
-       
 
       if (usedTrack[nTrack]) continue;
 
@@ -2531,7 +2591,8 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
       else 
        aodTrack->SetChi2MatchTrigger(0.);
     }
-   
+    tracks.Expand(jTracks); // remove 'empty slots' due to unwritten tracks
+       
     // Access to the AOD container of PMD clusters
     TClonesArray &pmdClusters = *(aod->GetPmdClusters());
     Int_t jPmdClusters=0;
@@ -2596,7 +2657,9 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
       
       caloCluster->SetCaloCluster(); // to be refined!
 
-    } // end of loop on calo clusters
+    } 
+       caloClusters.Expand(jClusters); // resize TObjArray to 'remove' slots for pseudo clusters        
+       // end of loop on calo clusters
 
     // fill EMC cell info
     AliAODCaloCells &EMCCells = *(aod->GetCaloCells());
@@ -2632,9 +2695,6 @@ void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
 
   aodTree->GetUserInfo()->Add(aod);
 
-  // close ESD file
-  esdFile->Close();
-
   // write the tree to the specified file
   aodFile = aodTree->GetCurrentFile();
   aodFile->cd();
@@ -2857,33 +2917,36 @@ void AliReconstruction::CheckQA()
 // check the QA of SIM for this run and remove the detectors 
 // with status Fatal
   
-       TString newDetList ; 
+       TString newRunLocalReconstruction ; 
+       TString newRunTracking ;
+       TString newFillESD ;
+        
        for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
                TString detName(AliQA::GetDetName(iDet)) ;
-               if ( fRunLocalReconstruction.Contains(AliQA::GetDetName(iDet)) || 
-                       fRunLocalReconstruction.Contains("ALL") )  {
-                       AliQA * qa = AliQA::Instance(AliQA::DETECTORINDEX(iDet)) ; 
-                       if ( qa->IsSet(AliQA::DETECTORINDEX(iDet), AliQA::kSIM, AliQA::kFATAL)) {
+               AliQA * qa = AliQA::Instance(AliQA::DETECTORINDEX(iDet)) ; 
+               if ( qa->IsSet(AliQA::DETECTORINDEX(iDet), AliQA::kSIM, AliQA::kFATAL)) {
                                AliInfo(Form("QA status for %s in Hits and/or SDIGITS  and/or Digits was Fatal; No reconstruction performed", detName.Data())) ;
-                       } else if ( qa->IsSet(AliQA::DETECTORINDEX(iDet), AliQA::kSIM, AliQA::kERROR)) {
-                               AliError(Form("QA status for %s in Hits and/or SDIGITS  and/or Digits was ERROR", detName.Data())) ;
-                               newDetList += detName ; 
-                               newDetList += " " ; 
-                       } else if ( qa->IsSet(AliQA::DETECTORINDEX(iDet), AliQA::kSIM, AliQA::kWARNING) ) {
-                               AliWarning(Form("QA status for %s in Hits and/or SDIGITS  and/or Digits was WARNING", detName.Data())) ;
-                               newDetList += detName ; 
-                               newDetList += " " ; 
-                       } else if ( qa->IsSet(AliQA::DETECTORINDEX(iDet), AliQA::kSIM, AliQA::kINFO) ) {
-                               AliInfo(Form("QA status for %s in Hits and/or SDIGITS  and/or Digits was INFO", detName.Data())) ;
-                               newDetList += detName ; 
-                               newDetList += " " ; 
-                       } else {
-                               newDetList += detName ; 
-                               newDetList += " " ;                     
+               } else {
+                       if ( fRunLocalReconstruction.Contains(AliQA::GetDetName(iDet)) || 
+                                       fRunLocalReconstruction.Contains("ALL") )  {
+                               newRunLocalReconstruction += detName ; 
+                               newRunLocalReconstruction += " " ;                      
+                       }
+                       if ( fRunTracking.Contains(AliQA::GetDetName(iDet)) || 
+                                       fRunTracking.Contains("ALL") )  {
+                               newRunTracking += detName ; 
+                               newRunTracking += " " ;                         
+                       }
+                       if ( fFillESD.Contains(AliQA::GetDetName(iDet)) || 
+                                       fFillESD.Contains("ALL") )  {
+                               newFillESD += detName ; 
+                               newFillESD += " " ;                     
                        }
                }
        }
-       fRunLocalReconstruction = newDetList ; 
+       fRunLocalReconstruction = newRunLocalReconstruction ; 
+       fRunTracking            = newRunTracking ; 
+       fFillESD                = newFillESD ; 
 }
 
 //_____________________________________________________________________________