]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONDataInterface.cxx
Moving required CMake version from 2.8.4 to 2.8.8
[u/mrichter/AliRoot.git] / MUON / AliMUONDataInterface.cxx
index 4f670bcca5f79f28a4f41add7032967badfdf78b..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>
@@ -81,6 +79,7 @@ fDigitStore(0x0),
 fTriggerStore(0x0),
 fClusterStore(0x0),
 fCurrentEvent(-1),
+fTreeLetter(""),
 fIsValid(kFALSE),
 fCurrentIteratorType(kNoIterator),
 fCurrentIndex(-1),
@@ -93,6 +92,11 @@ fIterator(0x0)
   
   ++fgInstanceCounter;
   
+  if ( AliCDBManager::Instance() != NULL &&
+       AliCDBManager::Instance()->GetDefaultStorage() == NULL ) {
+      AliFatal("CDB default storage not defined.");
+  }
+  
   Open(filename);
 
   // Load mapping
@@ -106,10 +110,6 @@ AliMUONDataInterface::~AliMUONDataInterface()
 {
   /// dtor
   ResetStores();
-  if ( fLoader != 0x0 ) 
-  {
-    delete fLoader->GetRunLoader();
-  }
   --fgInstanceCounter;  
 }
 
@@ -120,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();
   
@@ -156,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();
   
@@ -193,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);
   
@@ -238,6 +291,7 @@ AliMUONDataInterface::TriggerStore(Int_t event, const char* treeLetter)
   {
     fLoader->UnloadRecPoints();
   }
+  fTreeLetter = stree;
   
   return fTriggerStore;
 }
@@ -507,6 +561,7 @@ AliMUONDataInterface::Open(const char* filename)
   {
     AliError(Form("Cannot open file %s",filename));    
     fIsValid = kFALSE;
+    return;
   }
 
   runLoader->LoadHeader();
@@ -516,7 +571,7 @@ AliMUONDataInterface::Open(const char* filename)
   }
   else {
     Int_t runNumber = runLoader->GetHeader()->GetRun();
-    AliCDBManager::Instance()->SetRun(runNumber);
+    AliCDBManager::Instance()->SetRun(runNumber>=0 ? runNumber : 1);
   }  
   runLoader->UnloadHeader(); 
 
@@ -750,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;