]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONDataInterface.cxx
fix finding of pad neighbours; remove methods to write them in OCDB
[u/mrichter/AliRoot.git] / MUON / AliMUONDataInterface.cxx
index 8958dd4965093bfaafacc8383c48e0f93f27efbe..8ee174b1228267b4e11e7669a953a49045bf9954 100644 (file)
 #include "AliMUONGeometryTransformer.h"
 #include "AliMUONVDigit.h"
 #include "AliMUONVCluster.h"
-#include "AliMUONTrack.h"
 #include "AliMUONLocalTrigger.h"
 #include "AliMUONRegionalTrigger.h"
 #include "AliMUONGlobalTrigger.h"
-#include "AliMUONTriggerTrack.h"
 #include "AliMUONTriggerCircuit.h"
 #include "AliMUONVClusterStore.h"
 #include "AliMUONVDigitStore.h"
-#include "AliMUONVTrackStore.h"
 #include "AliMUONVTriggerStore.h"
-#include "AliMUONVTriggerTrackStore.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>
@@ -56,7 +52,7 @@
 /// \class AliMUONDataInterface
 ///
 /// An easy to use interface to the MUON data data stored in
-/// TreeS, TreeD, TreeR and TreeT.
+/// TreeS, TreeD and TreeR.
 ///
 /// For MC related information (i.e. TreeH, TreeK, TreeTR), see
 /// AliMUONMCDataInterface.
@@ -82,9 +78,8 @@ fLoader(0x0),
 fDigitStore(0x0),
 fTriggerStore(0x0),
 fClusterStore(0x0),
-fTrackStore(0x0),
-fTriggerTrackStore(0x0),
 fCurrentEvent(-1),
+fTreeLetter(""),
 fIsValid(kFALSE),
 fCurrentIteratorType(kNoIterator),
 fCurrentIndex(-1),
@@ -97,6 +92,11 @@ fIterator(0x0)
   
   ++fgInstanceCounter;
   
+  if ( AliCDBManager::Instance() != NULL &&
+       AliCDBManager::Instance()->GetDefaultStorage() == NULL ) {
+      AliFatal("CDB default storage not defined.");
+  }
+  
   Open(filename);
 
   // Load mapping
@@ -110,10 +110,6 @@ AliMUONDataInterface::~AliMUONDataInterface()
 {
   /// dtor
   ResetStores();
-  if ( fLoader != 0x0 ) 
-  {
-    delete fLoader->GetRunLoader();
-  }
   --fgInstanceCounter;  
 }
 
@@ -124,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();
   
@@ -160,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();
   
@@ -189,78 +211,6 @@ AliMUONDataInterface::ClusterStore(Int_t event)
   return fClusterStore;
 }
 
-//______________________________________________________________________________
-AliMUONVTrackStore* 
-AliMUONDataInterface::TrackStore(Int_t event)
-{
-  /// Return the trackStore for a given event.
-  /// Return 0x0 if event not found.
-  /// Returned pointer should not be deleted
-  
-  if (not IsValid()) return 0x0;
-  if (event == fCurrentEvent and fTrackStore != 0x0) return fTrackStore;
-  
-  ResetStores();
-  if (not LoadEvent(event)) return 0x0;
-  
-  fLoader->LoadTracks();
-  
-  TTree* treeT = fLoader->TreeT();
-  if (treeT == 0x0)
-  {
-    AliError("Could not get treeT");
-    return 0x0;
-  }
-  
-  fTrackStore = AliMUONVTrackStore::Create(*treeT);
-  if ( fTrackStore != 0x0 )
-  {
-    fTrackStore->Clear();
-    fTrackStore->Connect(*treeT);
-    treeT->GetEvent(0);
-  }
-  
-  fLoader->UnloadTracks();
-  
-  return fTrackStore;
-}
-
-//______________________________________________________________________________
-AliMUONVTriggerTrackStore* 
-AliMUONDataInterface::TriggerTrackStore(Int_t event)
-{
-  /// Return the triggerTrackStore for a given event.
-  /// Return 0x0 if event not found.
-  /// Returned pointer should not be deleted
-  
-  if (not IsValid()) return 0x0;
-  if (event == fCurrentEvent and fTriggerTrackStore != 0x0) return fTriggerTrackStore;
-  
-  ResetStores();
-  if (not LoadEvent(event)) return 0x0;
-  
-  fLoader->LoadTracks();
-  
-  TTree* treeT = fLoader->TreeT();
-  if (treeT == 0x0)
-  {
-    AliError("Could not get treeT");
-    return 0x0;
-  }
-  
-  fTriggerTrackStore = AliMUONVTriggerTrackStore::Create(*treeT);
-  if ( fTriggerTrackStore != 0x0 ) 
-  {
-    fTriggerTrackStore->Clear();
-    fTriggerTrackStore->Connect(*treeT);
-    treeT->GetEvent(0);
-  }
-  
-  fLoader->UnloadTracks();
-  
-  return fTriggerTrackStore;  
-}
-
 //_____________________________________________________________________________
 AliMUONVTriggerStore*
 AliMUONDataInterface::TriggerStore(Int_t event, const char* treeLetter)
@@ -269,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);
   
@@ -314,6 +291,7 @@ AliMUONDataInterface::TriggerStore(Int_t event, const char* treeLetter)
   {
     fLoader->UnloadRecPoints();
   }
+  fTreeLetter = stree;
   
   return fTriggerStore;
 }
@@ -377,48 +355,6 @@ AliMUONDataInterface::DumpSorted(const AliMUONVStore& store) const
   list.Print();
 }
 
-//______________________________________________________________________________
-void
-AliMUONDataInterface::DumpTracks(Int_t event, Bool_t sorted)
-{
-  /// Dump tracks for a given event, sorted if requested
-  
-  TrackStore(event);
-  
-  if ( fTrackStore != 0x0 ) 
-  {
-    if ( sorted ) 
-    {
-      DumpSorted(*fTrackStore);
-    }
-    else
-    {
-      fTrackStore->Print();
-    }
-  }
-}
-
-//______________________________________________________________________________
-void
-AliMUONDataInterface::DumpTriggerTracks(Int_t event, Bool_t sorted)
-{
-  /// Dump trigger tracks for a given event, sorted if requested
-
-  TriggerTrackStore(event);
-  
-  if ( fTriggerTrackStore != 0x0 ) 
-  {
-    if ( sorted ) 
-    {
-      DumpSorted(*fTriggerTrackStore);
-    }
-    else
-    {
-      fTriggerTrackStore->Print();
-    }
-  }
-}
-
 //_____________________________________________________________________________
 void
 AliMUONDataInterface::DumpTrigger(Int_t event, const char* treeLetter)
@@ -519,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                   
@@ -632,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) 
   {
@@ -653,9 +595,7 @@ Bool_t AliMUONDataInterface::GetEvent(Int_t event)
 
   if (DigitStore(event) == 0x0) return kFALSE;
   if (ClusterStore(event) == 0x0) return kFALSE;
-  if (TrackStore(event) == 0x0) return kFALSE;
   if (TriggerStore(event) == 0x0) return kFALSE;
-  if (TriggerTrackStore(event) == 0x0) return kFALSE;
   return kTRUE;
 }
 
@@ -729,26 +669,6 @@ AliMUONVCluster* AliMUONDataInterface::RawCluster(Int_t chamber, Int_t index)
   return static_cast<AliMUONVCluster*>( FetchObject(iter, index) );
 }
 
-//_____________________________________________________________________________
-Int_t AliMUONDataInterface::NumberOfTracks()
-{
-/// Returns the number of reconstructed tracks.
-
-  TIterator* iter = GetIterator(kTrackIterator);
-  return CountObjects(iter);
-}
-
-//_____________________________________________________________________________
-AliMUONTrack* AliMUONDataInterface::Track(Int_t index)
-{
-/// Returns a pointer to the index'th reconstructed track.
-/// @param index  The index number of the track to fetch in the range [0 .. N-1],
-///   where N = NumberOfTracks()
-
-  TIterator* iter = GetIterator(kTrackIterator);
-  return static_cast<AliMUONTrack*>( FetchObject(iter, index) );
-}
-
 //_____________________________________________________________________________
 Int_t AliMUONDataInterface::NumberOfLocalTriggers()
 {
@@ -799,26 +719,6 @@ AliMUONGlobalTrigger* AliMUONDataInterface::GlobalTrigger()
   return store->Global();
 }
 
-//_____________________________________________________________________________
-Int_t AliMUONDataInterface::NumberOfTriggerTracks()
-{
-/// Returns the number of reconstructed tracks in the trigger chambers.
-
-  TIterator* iter = GetIterator(kTriggerTrackIterator);
-  return CountObjects(iter);
-}
-
-//_____________________________________________________________________________
-AliMUONTriggerTrack* AliMUONDataInterface::TriggerTrack(Int_t index)
-{
-/// Returns a pointer to the index'th reconstructed trigger track object.
-/// @param index  The index number of the trigger track to fetch in the range [0 .. N-1],
-///   where N = NumberOfTriggerTracks()
-
-  TIterator* iter = GetIterator(kTriggerTrackIterator);
-  return static_cast<AliMUONTriggerTrack*>( FetchObject(iter, index) );
-}
-
 //_____________________________________________________________________________
 void AliMUONDataInterface::ResetStores()
 {
@@ -841,16 +741,6 @@ void AliMUONDataInterface::ResetStores()
     delete fClusterStore;
     fClusterStore = 0x0;
   }
-  if (fTrackStore != 0x0)
-  {
-    delete fTrackStore;
-    fTrackStore = 0x0;
-  }
-  if (fTriggerTrackStore != 0x0)
-  {
-    delete fTriggerTrackStore;
-    fTriggerTrackStore = 0x0;
-  }
 }
 
 //_____________________________________________________________________________
@@ -915,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;
@@ -936,16 +826,6 @@ TIterator* AliMUONDataInterface::GetIterator(IteratorType type, Int_t x, Int_t y
       return fIterator;
     }
     
-  case kTrackIterator:
-    {
-      AliMUONVTrackStore* store = TrackStore(fCurrentEvent);
-      if (store == 0x0) return 0x0;
-      fIterator = store->CreateIterator();
-      if (fIterator == 0x0) return 0x0;
-      fCurrentIteratorType = kTrackIterator;
-      return fIterator;
-    }
-    
   case kLocalTriggerIterator:
     {
       AliMUONVTriggerStore* store = TriggerStore(fCurrentEvent);
@@ -966,16 +846,6 @@ TIterator* AliMUONDataInterface::GetIterator(IteratorType type, Int_t x, Int_t y
       return fIterator;
     }
     
-  case kTriggerTrackIterator:
-    {
-      AliMUONVTriggerTrackStore* store = TriggerTrackStore(fCurrentEvent);
-      if (store == 0x0) return 0x0;
-      fIterator = store->CreateIterator();
-      if (fIterator == 0x0) return 0x0;
-      fCurrentIteratorType = kTriggerTrackIterator;
-      return fIterator;
-    }
-    
   default:
     return 0x0;
   }