]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONDataInterface.cxx
CID 22679: Out-of-bounds write (OVERRUN_STATIC)
[u/mrichter/AliRoot.git] / MUON / AliMUONDataInterface.cxx
index 7a0a6f3fe90bb2fdee075bbe2fc0a1f563056528..8ee174b1228267b4e11e7669a953a49045bf9954 100644 (file)
 #include "AliMUONVTriggerStore.h"
 #include "AliMpCDB.h"
 
-#include "AliMpIntPair.h"
+#include "AliMpEncodePair.h"
 #include "AliMpDEManager.h"
 #include "AliMpConstants.h"
 #include "AliMpCDB.h"
 
 #include "AliLoader.h"
-#include "AliLog.h"
 #include "AliRunLoader.h"
+#include "AliHeader.h"
+#include "AliCDBManager.h"
+#include "AliLog.h"
 
-#include <TError.h>
-#include <TParticle.h>
 #include <Riostream.h>
 #include <TFile.h>
 #include <TList.h>
@@ -79,6 +79,7 @@ fDigitStore(0x0),
 fTriggerStore(0x0),
 fClusterStore(0x0),
 fCurrentEvent(-1),
+fTreeLetter(""),
 fIsValid(kFALSE),
 fCurrentIteratorType(kNoIterator),
 fCurrentIndex(-1),
@@ -91,6 +92,11 @@ fIterator(0x0)
   
   ++fgInstanceCounter;
   
+  if ( AliCDBManager::Instance() != NULL &&
+       AliCDBManager::Instance()->GetDefaultStorage() == NULL ) {
+      AliFatal("CDB default storage not defined.");
+  }
+  
   Open(filename);
 
   // Load mapping
@@ -104,10 +110,6 @@ AliMUONDataInterface::~AliMUONDataInterface()
 {
   /// dtor
   ResetStores();
-  if ( fLoader != 0x0 ) 
-  {
-    delete fLoader->GetRunLoader();
-  }
   --fgInstanceCounter;  
 }
 
@@ -118,12 +120,25 @@ AliMUONDataInterface::DigitStore(Int_t event)
   /// Return digitStore for a given event.
   /// Return 0x0 if event not found.
   /// Returned pointer should not be deleted
+  ///
+  /// \note If a previous store has been retrieved by one of the methods of
+  /// this class, but for a different event number, then those stores will
+  /// be deleted and no longer valid.
+  /// If you require access to the data for the earlier retrieved store,
+  /// but for different events, then you should deep copy / clone the object.
   
   if (not IsValid()) return 0x0;
-  if (event == fCurrentEvent and fDigitStore != 0x0) return fDigitStore;
   
-  ResetStores();
-  if (not LoadEvent(event)) return 0x0;
+  if (event == fCurrentEvent)
+  {
+    if (fDigitStore != 0x0)
+      return fDigitStore;
+  }
+  else
+  {
+    ResetStores();
+    if ( not LoadEvent(event) ) return 0x0;
+  }
   
   fLoader->LoadDigits();
   
@@ -154,12 +169,25 @@ AliMUONDataInterface::ClusterStore(Int_t event)
   /// Return clusterStore for a given event.
   /// Return 0x0 if event not found.
   /// Returned pointer should not be deleted
+  ///
+  /// \note If a previous store has been retrieved by one of the methods of
+  /// this class, but for a different event number, then those stores will
+  /// be deleted and no longer valid.
+  /// If you require access to the data for the earlier retrieved store,
+  /// but for different events, then you should deep copy / clone the object.
   
   if (not IsValid()) return 0x0;
-  if (event == fCurrentEvent and fClusterStore != 0x0) return fClusterStore;
   
-  ResetStores();
-  if (not LoadEvent(event)) return 0x0;
+  if (event == fCurrentEvent)
+  {
+    if (fClusterStore != 0x0)
+      return fClusterStore;
+  }
+  else
+  {
+    ResetStores();
+    if ( not LoadEvent(event) ) return 0x0;
+  }
   
   fLoader->LoadRecPoints();
   
@@ -191,12 +219,39 @@ AliMUONDataInterface::TriggerStore(Int_t event, const char* treeLetter)
   /// Return 0x0 if event not found.
   /// Returned pointer should not be deleted
   /// treeLetter can be R or D to tell from which tree to read the information
+  ///
+  /// \note If a previous store has been retrieved by one of the methods of
+  /// this class, but for a different event number, then those stores will
+  /// be deleted and no longer valid.
+  /// If you require access to the data for the earlier retrieved store,
+  /// but for different events, then you should deep copy / clone the object.
   
   if (not IsValid()) return 0x0;
-  if (event == fCurrentEvent and fTriggerStore != 0x0) return fTriggerStore;
   
-  ResetStores();
-  if (not LoadEvent(event)) return 0x0;
+  if (event == fCurrentEvent)
+  {
+    if (fTreeLetter == treeLetter)
+    {
+      if (fTriggerStore != 0x0)
+        return fTriggerStore;
+    }
+    else
+    {
+      // Reset only the fTriggerStore since the others might still be valid
+      // for the same event.
+      if (fTriggerStore != 0x0)
+      {
+        delete fTriggerStore;
+        fTriggerStore = 0x0;
+      }
+    }
+  }
+  else
+  {
+    // Event has changed so reset all the stores.
+    ResetStores();
+    if ( not LoadEvent(event) ) return 0x0;
+  }
   
   TTree* tree(0x0);
   
@@ -236,6 +291,7 @@ AliMUONDataInterface::TriggerStore(Int_t event, const char* treeLetter)
   {
     fLoader->UnloadRecPoints();
   }
+  fTreeLetter = stree;
   
   return fTriggerStore;
 }
@@ -399,15 +455,8 @@ AliMUONDataInterface::NtupleTrigger(const char* treeLetter)
     AliMUONLocalTrigger* locTrg(0x0);
     while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
     {
-      Bool_t xTrig=kFALSE;
-      Bool_t yTrig=kFALSE;
-      
-      if ( locTrg->LoSdev()==1 && locTrg->LoDev()==0 && 
-           locTrg->LoStripX()==0) xTrig=kFALSE; // no trigger in X
-      else xTrig=kTRUE;                         // trigger in X
-      if (locTrg->LoTrigY()==1 && 
-          locTrg->LoStripY()==15 ) yTrig = kFALSE; // no trigger in Y
-      else yTrig = kTRUE;                          // trigger in Y
+      Bool_t xTrig=locTrg->IsTrigX();
+      Bool_t yTrig=locTrg->IsTrigY();
       
       if (xTrig && yTrig) 
       { // fill ntuple if trigger in X and Y                   
@@ -512,7 +561,20 @@ AliMUONDataInterface::Open(const char* filename)
   {
     AliError(Form("Cannot open file %s",filename));    
     fIsValid = kFALSE;
+    return;
   }
+
+  runLoader->LoadHeader();
+  if ( ! runLoader->GetHeader() ) {
+    AliError("Cannot load header.");    
+    fIsValid = kFALSE;
+  }
+  else {
+    Int_t runNumber = runLoader->GetHeader()->GetRun();
+    AliCDBManager::Instance()->SetRun(runNumber>=0 ? runNumber : 1);
+  }  
+  runLoader->UnloadHeader(); 
+
   fLoader = runLoader->GetDetectorLoader("MUON");
   if (fLoader == 0x0) 
   {
@@ -743,8 +805,8 @@ TIterator* AliMUONDataInterface::GetIterator(IteratorType type, Int_t x, Int_t y
       
       AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
       if (store == 0x0) return 0x0;
-      AliMpIntPair pair = AliMpDEManager::GetDetElemIdRange(chamber);
-      fIterator = store->CreateIterator(pair.GetFirst(), pair.GetSecond(), cathode);
+      MpPair_t pair = AliMpDEManager::GetDetElemIdRange(chamber);
+      fIterator = store->CreateIterator(AliMp::PairFirst(pair), AliMp::PairSecond(pair), cathode);
       if (fIterator == 0x0) return 0x0;
       fCurrentIteratorType = kDigitIteratorByChamberAndCathode;
       fDataX = chamber;