]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
AliMpSegFactory replaced with AliMpSegmentation
authorivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 26 Oct 2006 11:44:00 +0000 (11:44 +0000)
committerivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 26 Oct 2006 11:44:00 +0000 (11:44 +0000)
MUON/mapping/AliMpSegFactory.h [deleted file]
MUON/mapping/AliMpSegmentation.cxx [moved from MUON/mapping/AliMpSegFactory.cxx with 54% similarity]
MUON/mapping/AliMpSegmentation.h [new file with mode: 0644]

diff --git a/MUON/mapping/AliMpSegFactory.h b/MUON/mapping/AliMpSegFactory.h
deleted file mode 100644 (file)
index 7377234..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-#ifndef ALI_MP_SEG_FACTORY_H
-#define ALI_MP_SEG_FACTORY_H
-
-/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- * See cxx source for full Copyright notice                               */
-
-// $Id$ 
-// $MpId: AliMpSegFactory.h,v 1.7 2006/05/24 13:58:16 ivana Exp $ 
-
-/// \ingroup management
-/// \class AliMpSegFactory
-/// \brief The factory for building mapping segmentations
-//
-/// The factory does not delete the created segmentation objects.
-/// They have to be deleted in the client code.
-/// As the same segmentation objects can be shared with more detection elements,
-/// the class provides Clear() method for a safe deleting.
-///
-/// \author Ivana Hrivnacova, IPN Orsay
-
-#ifndef ROOT_TObject
-#  include <TObject.h>
-#endif
-
-#ifndef ALI_MP_STRING_OBJ_MAP_H
-#  include "AliMpStringObjMap.h"
-#endif
-
-class AliMpExMap;
-class AliMpVSegmentation;
-
-class AliMpSegFactory : public  TObject {
-
-  public:
-    AliMpSegFactory();
-    virtual ~AliMpSegFactory();
-    
-    // methods
-    AliMpVSegmentation* CreateMpSegmentation(
-                              Int_t detElemId, Int_t cath);
-
-    AliMpVSegmentation* CreateMpSegmentationByElectronics(
-                              Int_t detElemId, Int_t elCardID);
-
-    void DeleteSegmentations();
-
-    static Int_t NumberOfInstances() { return fgNumberOfInstances; }
-    
-  private:
-    AliMpSegFactory(const AliMpSegFactory& rhs);
-    AliMpSegFactory& operator=(const AliMpSegFactory& rhs);
-
-    AliMpExMap* FillMpMap(Int_t detElemId);
-
-    AliMpStringObjMap  fMpSegmentations;///< Map of mapping segmentations to DE names
-    AliMpExMap*        fMpMap;          ///< Map of el. cards IDs to segmentations
-      
-    static Int_t fgNumberOfInstances; ///< number of AliMpSegFactory objects...
-    
-  ClassDef(AliMpSegFactory,0)  // The factory for building mapping segmentations
-};
-
-#endif //ALI_MP_SEG_FACTORY_H
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
similarity index 54%
rename from MUON/mapping/AliMpSegFactory.cxx
rename to MUON/mapping/AliMpSegmentation.cxx
index 2ca59be4e60ad67940dc7ffe00f4e75fbc626e8f..39901407a6210cefd31c352c3cba071556a84890 100644 (file)
  **************************************************************************/
 
 // $Id$
-// $MpId: AliMpSegFactory.cxx,v 1.7 2006/05/24 13:58:34 ivana Exp $
+// $MpId: AliMpSegmentation.cxx,v 1.7 2006/05/24 13:58:34 ivana Exp $
 // Category: management
 
 // -----------------------
-// Class AliMpSegFactory
+// Class AliMpSegmentation
 // -----------------------
-// The factory for building mapping segmentations
+// Singleton container class for mapping segmentations
 // Authors: Ivana Hrivnacova, IPN Orsay
 //          Laurent Aphecetche, SUBATECH
 
-#include "AliMpSegFactory.h"
+#include "AliMpSegmentation.h"
 
 #include "AliMpDEManager.h"
+#include "AliMpDEIterator.h"
 #include "AliMpExMap.h"
 #include "AliMpSector.h"
 #include "AliMpSectorReader.h"
 #include <TSystem.h>
 
 /// \cond CLASSIMP
-ClassImp(AliMpSegFactory)
+ClassImp(AliMpSegmentation)
 /// \endcond
 
-Int_t AliMpSegFactory::fgNumberOfInstances(0);
+AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
+
+//
+// static methods
+//
+
+//______________________________________________________________________________
+AliMpSegmentation* AliMpSegmentation::Instance()
+{
+/// Create the sementation if it does not yet exist
+/// and return its instance
+
+  if ( ! fgInstance )
+    fgInstance = new AliMpSegmentation();
+    
+  return fgInstance;
+}    
+
+//
+// ctors, dtor
+//
 
 //______________________________________________________________________________
-AliMpSegFactory::AliMpSegFactory()
+AliMpSegmentation::AliMpSegmentation()
 : TObject(),
-  fMpSegmentations(),
-  fMpMap(new AliMpExMap(true))
+  fMpSegmentations(true),
+  fElCardsMap(true)
 {  
-    /// Standard constructor
-    AliDebug(1,"");
-    fMpMap->SetOwner(true);
-    ++fgNumberOfInstances;
+/// Standard constructor
+
+  AliDebug(1,"");
+  fElCardsMap.SetOwner(true);
+
+  // Create mapping segmentations for all detection elements
+  for ( Int_t cath = 0; cath < 2; cath ++ ) { 
+    AliMpDEIterator it;
+    for ( it.First(); ! it.IsDone(); it.Next() ) {
+      //if ( AliMpDEManager::GetChamberId(it.CurrentDE()) >= 4 ) break;
+      CreateMpSegmentation(it.CurrentDE(), cath);
+    } 
+  }  
+
+  // Fill el cards map for all detection elements
+  // of tracking chambers
+  AliMpDEIterator it;
+  for ( it.First(); ! it.IsDone(); it.Next() ) { 
+    //if ( AliMpDEManager::GetChamberId(it.CurrentDE()) >= 4 ) break;
+    if ( AliMpDEManager::GetChamberId(it.CurrentDE()) >= 10 ) break;
+    FillElCardsMap(it.CurrentDE());
+  }  
 }
 
 //______________________________________________________________________________
+AliMpSegmentation::AliMpSegmentation(TRootIOCtor* /*ioCtor*/)
+: TObject(),
+  fMpSegmentations(),
+  fElCardsMap()
+{  
+/// Constructor for IO
+
+  fgInstance = this;
+}
 
-AliMpSegFactory::~AliMpSegFactory()
+//______________________________________________________________________________
+AliMpSegmentation::~AliMpSegmentation()
 {
 /// Destructor
 
-  // The segmentations is supposed to be deleted in the client code
   AliDebug(1,"");
-  --fgNumberOfInstances;
-}
-
-//
-// private methods
-//
 
-//_____________________________________________________________________________
-AliMpExMap*
-AliMpSegFactory::FillMpMap(Int_t detElemId)
-{
-/// Fill the map of electronic cards IDs to segmentations for
-/// given detElemId
-
-  AliDebugStream(2) << "detElemId=" << detElemId << endl;;
+  // Segmentations are deleted with fMpSegmentations 
+  // El cards arrays are deleted with fElCardsMap
   
-  AliMpExMap* mde = new AliMpExMap(true);
-  mde->SetOwner(kFALSE);
-  fMpMap->Add(detElemId,mde);
-  
-  AliMpVSegmentation* seg[2];
-  TArrayI ecn[2];
-  
-  // Do it in 2 steps to be able to set the AliMpExMap size once for all,
-  // to avoid annoying warning message in case of dynamical resizing.
-  // (not critical).
-  for ( Int_t cathode = 0; cathode < 2; ++cathode )
-  {
-    seg[cathode] = CreateMpSegmentation(detElemId,cathode);
-    seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
-  }
-  
-  mde->SetSize(ecn[0].GetSize()+ecn[1].GetSize());
-  
-  for ( Int_t cathode = 0; cathode < 2; ++ cathode )
-  {
-    for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
-    {
-      mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
-    }
-  }
-  
-  return mde;
+  fgInstance = 0;
 }
 
 //
-// public methods
+// private methods
 //
 
 //______________________________________________________________________________
 AliMpVSegmentation* 
-AliMpSegFactory::CreateMpSegmentation(Int_t detElemId, Int_t cath)
+AliMpSegmentation::CreateMpSegmentation(Int_t detElemId, Int_t cath)
 {
 /// Create mapping segmentation for given detElemId and cath
 /// or return it if it was already built
@@ -151,15 +161,15 @@ AliMpSegFactory::CreateMpSegmentation(Int_t detElemId, Int_t cath)
   if ( stationType == kStation1 || stationType == kStation2 ) {
     AliMpSectorReader reader(stationType, planeType);
     AliMpSector* sector = reader.BuildSector();
-    mpSegmentation = new AliMpSectorSegmentation(sector);
+    mpSegmentation = new AliMpSectorSegmentation(sector, true);
   }
   else if ( stationType == kStation345 ) { 
     AliMpSlat* slat = AliMpSt345Reader::ReadSlat(deTypeName, planeType);
-    mpSegmentation =  new AliMpSlatSegmentation(slat);
+    mpSegmentation =  new AliMpSlatSegmentation(slat, true);
   }
   else if ( stationType == kStationTrigger ) {
     AliMpTrigger* trigger = AliMpTriggerReader::ReadSlat(deTypeName, planeType);
-    mpSegmentation = new AliMpTriggerSegmentation(trigger);
+    mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
   }
   else   
     AliErrorStream() << "Unknown station type" << endl;
@@ -169,33 +179,104 @@ AliMpSegFactory::CreateMpSegmentation(Int_t detElemId, Int_t cath)
 } 
 
 //_____________________________________________________________________________
-AliMpVSegmentation* 
-AliMpSegFactory::CreateMpSegmentationByElectronics(Int_t detElemId,
-                                                   Int_t ecId)
+AliMpExMap*
+AliMpSegmentation::FillElCardsMap(Int_t detElemId)
 {
-/// Create mapping segmentation for given detElemId and electronic card Id
-/// (motif position Id) or return it if it was already built
+/// Fill the map of electronic cards IDs to segmentations for
+/// given detElemId
 
-  AliMpExMap* m = static_cast<AliMpExMap*>(fMpMap->GetValue(detElemId));
+  AliDebugStream(2) << "detElemId=" << detElemId << endl;;
   
-  if (!m)
+  AliMpExMap* mde = new AliMpExMap(true);
+  mde->SetOwner(kFALSE);
+  fElCardsMap.Add(detElemId,mde);
+
+  const AliMpVSegmentation* seg[2];
+  TArrayI ecn[2];
+  
+  // Do it in 2 steps to be able to set the AliMpExMap size once for all,
+  // to avoid annoying warning message in case of dynamical resizing.
+  // (not critical).
+  for ( Int_t cathode = 0; cathode < 2; ++cathode )
   {
-    m = FillMpMap(detElemId);
+    seg[cathode] = GetMpSegmentation(detElemId,cathode);
+    seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
   }
   
-  return static_cast<AliMpVSegmentation*>(m->GetValue(ecId));
+  mde->SetSize(ecn[0].GetSize()+ecn[1].GetSize());
+  
+  for ( Int_t cathode = 0; cathode < 2; ++ cathode )
+  {
+    for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
+    {
+      mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
+    }
+  }
+  
+  return mde;
 }
-    
+
+//
+// public methods
+//
+
 //______________________________________________________________________________
-void AliMpSegFactory::DeleteSegmentations()
+const AliMpVSegmentation* 
+AliMpSegmentation::GetMpSegmentation(
+                      Int_t detElemId, Int_t cath, Bool_t warn) const
 {
-/// Delete all segmentations created with this manager
-
-  AliDebug(1,"deleting mpSegmentations");
-  fMpSegmentations.Clear();
-  AliDebug(1,"deleting mpMap");
-  delete fMpMap;
-  fMpMap = 0; 
-  AliDebug(1,"done");
-}
+/// Return mapping segmentation for given detElemId and cath
+
+  // Check detElemId & cath  
+  if ( ! AliMpDEManager::IsValid(detElemId, cath, false) ) {
+    
+    if ( warn ) {
+      AliWarningStream() 
+        << "Invalid detElemId/cathod (" 
+       << detElemId << ", " << cath << ")" << endl;
+    }  
+    return 0;
+  }  
+
+  TString deName = AliMpDEManager::GetDEName(detElemId, cath);
+  TObject* object = fMpSegmentations.Get(deName);
+  if ( ! object ) {
+    // Should never happen
+    AliErrorStream() 
+      << "Segmentation for detElemId/cathod " 
+       << detElemId << ", " << cath << " not defined" << endl;
+    return 0;
+  }  
+  
+  return static_cast<AliMpVSegmentation*>(object);
+} 
 
+//_____________________________________________________________________________
+const AliMpVSegmentation* 
+AliMpSegmentation::GetMpSegmentationByElectronics(
+                      Int_t detElemId, Int_t ecId, Bool_t warn) const
+{
+/// Return mapping segmentation for given detElemId and electronic card Id
+/// (motif position Id)
+
+  AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
+  
+  if (!m) {
+    // Should never happen
+    AliErrorStream() 
+      << "Cannot find the el cards map for detElemId " << detElemId << endl;
+    return 0;
+  }  
+
+  TObject* object = m->GetValue(ecId);
+  if ( ! object ) {
+    if ( warn ) {
+      AliErrorStream() 
+        << "Segmentation for electronic card " 
+       << ecId << " not found" << endl;
+    }  
+    return 0;
+  }  
+   
+  return static_cast<AliMpVSegmentation*>(object);
+}
diff --git a/MUON/mapping/AliMpSegmentation.h b/MUON/mapping/AliMpSegmentation.h
new file mode 100644 (file)
index 0000000..081ed64
--- /dev/null
@@ -0,0 +1,94 @@
+#ifndef ALI_MP_SEGMENTATION_H
+#define ALI_MP_SEGMENTATION_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+// $Id$ 
+// $MpId: AliMpSegmentation.h,v 1.7 2006/05/24 13:58:16 ivana Exp $ 
+
+/// \ingroup management
+/// \class AliMpSegmentation
+/// \brief Singleton container class for mapping segmentations
+///
+/// It provides access to mapping segmentations based on the
+/// AliMpVSegmentation interface.                                        \n
+/// Mapping segmentations for all detection elements
+/// are created at the first call to AliMpSegmentation::Instance().
+/// The class is a singleton, it has all constructors
+/// private, except for the special constructor for Root I/O.
+///
+/// \author Ivana Hrivnacova, IPN Orsay; Laurent Aphecetche, SUBATECH
+
+#ifndef ROOT_TObject
+#  include <TObject.h>
+#endif
+
+#ifndef ALI_MP_STRING_OBJ_MAP_H
+#  include "AliMpStringObjMap.h"
+#endif
+
+#ifndef ALI_MP_EX_MAP_H
+#  include "AliMpExMap.h"
+#endif
+
+class AliMpVSegmentation;
+class AliMpSegmentation;
+
+class TRootIOCtor;
+
+class AliMpSegmentation : public  TObject {
+
+  public:
+    AliMpSegmentation(TRootIOCtor* /*ioCtor*/);
+    virtual ~AliMpSegmentation();
+    
+    // static methods
+    static AliMpSegmentation* Instance();
+
+    // methods
+    const AliMpVSegmentation* GetMpSegmentation(
+                                 Int_t detElemId, Int_t cath, 
+                                Bool_t warn = true) const;
+
+    const AliMpVSegmentation* GetMpSegmentationByElectronics(
+                                 Int_t detElemId, Int_t elCardID, 
+                                Bool_t warn = true) const;
+    
+  private:
+    AliMpSegmentation();
+    AliMpSegmentation(const AliMpSegmentation& rhs);
+    AliMpSegmentation& operator=(const AliMpSegmentation& rhs);
+
+    AliMpVSegmentation* CreateMpSegmentation(
+                              Int_t detElemId, Int_t cath);
+
+    AliMpExMap* FillElCardsMap(Int_t detElemId);
+
+    // static data members
+    static AliMpSegmentation* fgInstance; ///< Singleton instance
+
+    // data members
+    AliMpStringObjMap  fMpSegmentations;///< Map of mapping segmentations to DE names
+    AliMpExMap         fElCardsMap;     ///< Map of el. cards IDs to segmentations
+      
+    
+  ClassDef(AliMpSegmentation,1)  // The factory for building mapping segmentations
+};
+
+#endif //ALI_MP_SEGMENTATION_H
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+