]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONMCDataInterface.cxx
Compilation warning fixed.
[u/mrichter/AliRoot.git] / MUON / AliMUONMCDataInterface.cxx
index c5ccda8be7db10a9514d88a06ec4dde754564057..5dfb2a05fe4d00cf74f4f13075fbd36301b8627a 100644 (file)
 #include "AliMUONRegionalTrigger.h"
 #include "AliMUONGlobalTrigger.h"
 
-#include "AliMpIntPair.h"
+#include "AliMpEncodePair.h"
 #include "AliMpDEManager.h"
 #include "AliMpConstants.h"
-#include "AliMpSegmentation.h"
+#include "AliMpCDB.h"
 
 #include "AliLog.h"
 #include "AliRunLoader.h"
+#include "AliHeader.h"
 #include "AliStack.h"
+#include "AliCDBManager.h"
 
 #include <Riostream.h>
 #include <TClonesArray.h>
@@ -80,7 +82,17 @@ fIterator(0x0)
   
   ++fgInstanceCounter;
   
+  if ( AliCDBManager::Instance() != NULL &&
+       AliCDBManager::Instance()->GetDefaultStorage() == NULL ) {
+      AliFatal("CDB default storage not defined.");
+  }
+  
   Open(filename);
+
+  // Load mapping
+  if ( ! AliMpCDB::LoadMpSegmentation() ) {
+    AliFatal("Could not access mapping from OCDB !");
+  }
 }
 
 //_____________________________________________________________________________
@@ -101,16 +113,25 @@ AliMUONMCDataInterface::HitStore(Int_t event, Int_t track)
   /// Return the hitStore for a given track of one event
   /// Return 0x0 if event and/or track 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 fDataX == track  // using fDataX as track number.
-      and fHitStore != 0x0
-     )
+
+  if (event == fCurrentEvent)
+  {
+    if (track == fDataX and fHitStore != 0x0)  // using fDataX as track number.
       return fHitStore;
-  
-  ResetStores();
-  if (not LoadEvent(event)) return 0x0;
+  }
+  else
+  {
+    ResetStores();
+    if ( not LoadEvent(event) ) return 0x0;
+  }
   
   fLoader->LoadHits();
   
@@ -147,12 +168,25 @@ AliMUONMCDataInterface::SDigitStore(Int_t event)
   /// Return the SDigit store for a given event.
   /// Return 0 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 fSDigitStore != 0x0) return fSDigitStore;
   
-  ResetStores();
-  if (not LoadEvent(event)) return 0x0;
+  if (event == fCurrentEvent)
+  {
+    if (fSDigitStore != 0x0)
+      return fSDigitStore;
+  }
+  else
+  {
+    ResetStores();
+    if ( not LoadEvent(event) ) return 0x0;
+  }
   
   fLoader->LoadSDigits();
   
@@ -182,12 +216,25 @@ AliMUONMCDataInterface::DigitStore(Int_t event)
 {
   /// Return a pointer to the digitStore for a given event (or 0 if 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();
   
@@ -217,6 +264,12 @@ AliMUONMCDataInterface::Stack(Int_t event)
 {
   /// Get the Stack (list of generated particles) for one event
   /// 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;
 
@@ -237,18 +290,26 @@ AliMUONMCDataInterface::TrackRefs(Int_t event, Int_t track)
 {
   /// Get the track references for a given (generated) track of one event
   /// 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)
+  
+  if (event == fCurrentEvent)
+  {
+    if (track == fDataX and fTrackRefs != 0x0)  // using fDataX as track number.
+      return fTrackRefs;
+  }
+  else
   {
     ResetStores();
     if ( not LoadEvent(event) ) return 0x0;
   }
   
-  if (track == fDataX)  // using fDataX as track number.
-    return fTrackRefs;
-  
   fLoader->GetRunLoader()->LoadTrackRefs();
   
   TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
@@ -282,12 +343,25 @@ AliMUONMCDataInterface::TriggerStore(Int_t event)
   /// Return the triggerStore 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 fTriggerStore != 0x0) return fTriggerStore;
   
-  ResetStores();
-  if (not LoadEvent(event)) return 0x0;
+  if (event == fCurrentEvent)
+  {
+    if (fTriggerStore != 0x0)
+      return fTriggerStore;
+  }
+  else
+  {
+    ResetStores();
+    if ( not LoadEvent(event) ) return 0x0;
+  }
   
   fLoader->LoadDigits();
   
@@ -569,6 +643,19 @@ AliMUONMCDataInterface::Open(const char* filename)
     AliError(Form("Cannot open file %s",filename));    
     fIsValid = kFALSE;
   }
+  
+  // Get run number and set it to CDB manager
+  runLoader->LoadHeader();
+  if ( ! runLoader->GetHeader() ) {
+    AliError("Cannot load header.");    
+    fIsValid = kFALSE;
+  }
+  else {
+    Int_t runNumber = runLoader->GetHeader()->GetRun();
+    AliCDBManager::Instance()->SetRun(runNumber);
+  }  
+  runLoader->UnloadHeader(); 
+
   fLoader = runLoader->GetDetectorLoader("MUON");
   if (fLoader == 0x0)
   {
@@ -895,7 +982,6 @@ TIterator* AliMUONMCDataInterface::GetIterator(IteratorType type, Int_t x, Int_t
       Int_t detElem = x;
       AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
       if (store == 0x0) return 0x0;
-      AliMpSegmentation::ReadData(kFALSE); // kFALSE so that we do not get warning message.
       fIterator = store->CreateIterator(detElem, detElem, 2);
       if (fIterator == 0x0) return 0x0;
       fCurrentIteratorType = kSDigitIteratorByDetectorElement;
@@ -924,9 +1010,8 @@ TIterator* AliMUONMCDataInterface::GetIterator(IteratorType type, Int_t x, Int_t
       
       AliMUONVDigitStore* store = SDigitStore(fCurrentEvent);
       if (store == 0x0) return 0x0;
-      AliMpSegmentation::ReadData(kFALSE); // kFALSE so that we do not get warning message.
-      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 = kSDigitIteratorByChamberAndCathode;
       fDataX = chamber;
@@ -939,7 +1024,6 @@ TIterator* AliMUONMCDataInterface::GetIterator(IteratorType type, Int_t x, Int_t
       Int_t detElem = x;
       AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
       if (store == 0x0) return 0x0;
-      AliMpSegmentation::ReadData(kFALSE); // kFALSE so that we do not get warning message.
       fIterator = store->CreateIterator(detElem, detElem, 2);
       if (fIterator == 0x0) return 0x0;
       fCurrentIteratorType = kDigitIteratorByDetectorElement;
@@ -968,9 +1052,8 @@ TIterator* AliMUONMCDataInterface::GetIterator(IteratorType type, Int_t x, Int_t
       
       AliMUONVDigitStore* store = DigitStore(fCurrentEvent);
       if (store == 0x0) return 0x0;
-      AliMpSegmentation::ReadData(kFALSE); // kFALSE so that we do not get warning message.
-      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;