]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpSegmentation.cxx
Updated serial number for station 345
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSegmentation.cxx
index 12911cfe8aa0ecd216242ceeea5a2d65e58455b4..d948839c3fe9e72ca7cd38b4aed6a8d64089c777 100644 (file)
 // $MpId: AliMpSegmentation.cxx,v 1.7 2006/05/24 13:58:34 ivana Exp $
 // Category: management
 
-// -----------------------
+//-----------------------------------------------------------------------------
 // Class AliMpSegmentation
 // -----------------------
 // Singleton container class for mapping segmentations
 // Authors: Ivana Hrivnacova, IPN Orsay
 //          Laurent Aphecetche, SUBATECH
+//-----------------------------------------------------------------------------
 
 #include "AliMpSegmentation.h"
 
+#include "AliMpDataStreams.h"
 #include "AliMpDetElement.h"
+#include "AliMpDEStore.h"
 #include "AliMpDEManager.h"
 #include "AliMpDEIterator.h"
 #include "AliMpExMap.h"
@@ -40,6 +43,8 @@
 #include "AliMpTriggerReader.h"
 #include "AliMpTriggerSegmentation.h"
 #include "AliMpCathodType.h"
+#include "AliMpSlatMotifMap.h"
+
 
 #include "AliLog.h"
 
@@ -47,6 +52,9 @@
 #include <TMap.h>
 #include <TObjString.h>
 #include <TSystem.h>
+#include <TClass.h>
+
+#include <cassert>
 
 /// \cond CLASSIMP
 ClassImp(AliMpSegmentation)
@@ -59,17 +67,36 @@ AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
 //
 
 //______________________________________________________________________________
-AliMpSegmentation* AliMpSegmentation::Instance()
+AliMpSegmentation* AliMpSegmentation::Instance(Bool_t warn)
 {
-/// Create the sementation if it does not yet exist
-/// and return its instance
+/// Return its instance
 
-  if ( ! fgInstance )
-    fgInstance = new AliMpSegmentation();
+  if ( ! fgInstance && warn ) {
+    AliWarningClass("Segmentation has not been loaded");
+  }  
     
   return fgInstance;
 }    
 
+//______________________________________________________________________________
+AliMpSegmentation* AliMpSegmentation::ReadData(Bool_t warn)
+{
+/// Load the sementation from ASCII data files
+/// and return its instance
+
+  if ( fgInstance ) {
+    if ( warn )
+      AliWarningClass("Segmentation has been already loaded");
+    return fgInstance;
+  }  
+  
+  if ( AliMpDataStreams::Instance()->GetReadFromFiles() )
+    AliInfoClass("Reading segmentation from ASCII files.");
+
+  fgInstance = new AliMpSegmentation();
+  return fgInstance;
+}    
+
 //
 // ctors, dtor
 //
@@ -77,39 +104,48 @@ AliMpSegmentation* AliMpSegmentation::Instance()
 //______________________________________________________________________________
 AliMpSegmentation::AliMpSegmentation()
 : TObject(),
-  fMpSegmentations(true),
-  fElCardsMap(true),
-  fSlatMotifMap()
+  fDetElements(0),
+  fMpSegmentations(),
+  fElCardsMap(),
+  fSlatMotifMap(AliMpSlatMotifMap::Instance())
 {  
-/// Standard constructor
+/// Standard constructor - segmentation is loaded from ASCII data files
 
   AliDebug(1,"");
-  fElCardsMap.SetOwner(true);
+  
+  // Load DE data
+  if ( ! AliMpDEStore::Instance(false) )  
+    AliMpDEStore::ReadData();
+  fDetElements = AliMpDEStore::Instance();  
 
   // Create mapping segmentations for all detection elements
-  for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; cath ++ ) { 
-    AliMpDEIterator it;
-    for ( it.First(); ! it.IsDone(); it.Next() ) {
-      CreateMpSegmentation(it.CurrentDEId(), AliMp::GetCathodType(cath));
-    } 
-  }  
-
-  // Fill el cards map for all detection elements
-  // of tracking chambers
   AliMpDEIterator it;
-  for ( it.First(); ! it.IsDone(); it.Next() ) { 
-    if ( AliMpDEManager::GetStationType(it.CurrentDEId()) != AliMp::kStationTrigger ) {
-      FillElCardsMap(it.CurrentDEId());
+  for ( it.First(); ! it.IsDone(); it.Next() ) 
+  {
+    Int_t n(0);
+    
+    for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; ++cath ) 
+    { 
+      if ( CreateMpSegmentation(it.CurrentDEId(), AliMp::GetCathodType(cath)) ) ++n;
     }
-  }  
+     
+    if ( n == 2 &&  // should always be the case except when we play with the CreateMpSegmentation method...
+        AliMpDEManager::GetStationType(it.CurrentDEId()) != AliMp::kStationTrigger ) // only for tracker
+    {
+        // Fill el cards map for all detection elements
+        // of tracking chambers
+        FillElCardsMap(it.CurrentDEId());
+    }      
+  } 
 }
 
 //______________________________________________________________________________
-AliMpSegmentation::AliMpSegmentation(TRootIOCtor* /*ioCtor*/)
+AliMpSegmentation::AliMpSegmentation(TRootIOCtor* ioCtor)
 : TObject(),
+  fDetElements(0),
   fMpSegmentations(),
-  fElCardsMap(),
-  fSlatMotifMap()
+  fElCardsMap(ioCtor),
+  fSlatMotifMap(0)
 {  
 /// Constructor for IO
 
@@ -125,6 +161,8 @@ AliMpSegmentation::~AliMpSegmentation()
 
   AliDebug(1,"");
 
+  delete fDetElements;
+
   // Segmentations are deleted with fMpSegmentations 
   // El cards arrays are deleted with fElCardsMap
   
@@ -170,19 +208,19 @@ AliMpSegmentation::CreateMpSegmentation(Int_t detElemId, AliMp::CathodType cath)
     mpSegmentation = new AliMpSectorSegmentation(sector, true);
   }
   else if ( stationType == AliMp::kStation345 ) { 
-    AliMpSt345Reader reader(fSlatMotifMap);
+    AliMpSt345Reader reader;
     AliMpSlat* slat = reader.ReadSlat(deTypeName, planeType);
     mpSegmentation =  new AliMpSlatSegmentation(slat, true);
   }
   else if ( stationType == AliMp::kStationTrigger ) {
-    AliMpTriggerReader reader(fSlatMotifMap);
+    AliMpTriggerReader reader;
     AliMpTrigger* trigger = reader.ReadSlat(deTypeName, planeType);
     mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
   }
   else   
     AliErrorStream() << "Unknown station type" << endl;
 
-  fMpSegmentations.Add(deSegName, mpSegmentation); 
+  if ( mpSegmentation ) fMpSegmentations.Add(deSegName, mpSegmentation); 
   
 //  StdoutToAliDebug(3, fSlatMotifMap.Print(););
   
@@ -198,33 +236,27 @@ AliMpSegmentation::FillElCardsMap(Int_t detElemId)
 
   AliDebugStream(2) << "detElemId=" << detElemId << endl;;
   
-  AliMpExMap* mde = new AliMpExMap(true);
+  AliMpExMap* mde = new AliMpExMap;
   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 = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
   {
     seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
     seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
-  }
-  
-  mde->SetSize(ecn[0].GetSize()+ecn[1].GetSize());
-  
-  for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++ cathode )
-  {
     for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
     {
       mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
     }
   }
   
+  assert( mde->GetSize() > 0 );
+  
   return mde;
+  
 }
 
 //