1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 // $MpId: AliMpSegmentation.cxx,v 1.7 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
20 //-----------------------------------------------------------------------------
21 // Class AliMpSegmentation
22 // -----------------------
23 // Singleton container class for mapping segmentations
24 // Authors: Ivana Hrivnacova, IPN Orsay
25 // Laurent Aphecetche, SUBATECH
26 //-----------------------------------------------------------------------------
28 #include "AliMpSegmentation.h"
30 #include "AliMpDetElement.h"
31 #include "AliMpDEManager.h"
32 #include "AliMpDEIterator.h"
33 #include "AliMpExMap.h"
34 #include "AliMpSector.h"
35 #include "AliMpSectorReader.h"
36 #include "AliMpSectorSegmentation.h"
37 #include "AliMpSlat.h"
38 #include "AliMpSlatSegmentation.h"
39 #include "AliMpSt345Reader.h"
40 #include "AliMpTrigger.h"
41 #include "AliMpTriggerReader.h"
42 #include "AliMpTriggerSegmentation.h"
43 #include "AliMpCathodType.h"
46 #include "AliCDBManager.h"
47 #include "AliCDBEntry.h"
49 #include <Riostream.h>
51 #include <TObjString.h>
56 ClassImp(AliMpSegmentation)
59 AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
65 //______________________________________________________________________________
66 AliMpSegmentation* AliMpSegmentation::Instance(Bool_t warn)
68 /// Return its instance
70 if ( ! fgInstance && warn ) {
71 AliWarningClass("Segmentation has not been loaded");
77 //______________________________________________________________________________
78 AliMpSegmentation* AliMpSegmentation::ReadData(Bool_t warn)
80 /// Load the sementation from ASCII data files
81 /// and return its instance
85 AliWarningClass("Segmentation has been already loaded");
89 AliInfoClass("Reading segmentation from ASCII files.");
91 fgInstance = new AliMpSegmentation();
99 //______________________________________________________________________________
100 AliMpSegmentation::AliMpSegmentation()
102 fMpSegmentations(true),
106 /// Standard constructor - segmentation is loaded from ASCII data files
109 fElCardsMap.SetOwner(true);
111 // Create mapping segmentations for all detection elements
112 for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; cath ++ ) {
114 for ( it.First(); ! it.IsDone(); it.Next() ) {
115 CreateMpSegmentation(it.CurrentDEId(), AliMp::GetCathodType(cath));
119 // Fill el cards map for all detection elements
120 // of tracking chambers
122 for ( it.First(); ! it.IsDone(); it.Next() ) {
123 if ( AliMpDEManager::GetStationType(it.CurrentDEId()) != AliMp::kStationTrigger ) {
124 FillElCardsMap(it.CurrentDEId());
129 //______________________________________________________________________________
130 AliMpSegmentation::AliMpSegmentation(TRootIOCtor* /*ioCtor*/)
136 /// Constructor for IO
143 //______________________________________________________________________________
144 AliMpSegmentation::~AliMpSegmentation()
150 // Segmentations are deleted with fMpSegmentations
151 // El cards arrays are deleted with fElCardsMap
160 //______________________________________________________________________________
162 AliMpSegmentation::CreateMpSegmentation(Int_t detElemId, AliMp::CathodType cath)
164 /// Create mapping segmentation for given detElemId and cath
165 /// or return it if it was already built
167 // Check detElemId & cath
168 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0;
170 // If segmentation is already built, just return it
172 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
173 TString deSegName = detElement->GetSegName(cath);
174 TObject* object = fMpSegmentations.Get(deSegName);
175 if ( object ) return (AliMpVSegmentation*)object;
178 << "Creating segmentation for detElemId=" << detElemId
179 << " cath=" << cath << endl;
181 // Read mapping data and create segmentation
183 AliMp::StationType stationType = detElement->GetStationType();
184 AliMp::PlaneType planeType = detElement->GetPlaneType(cath);
185 TString deTypeName = detElement->GetSegType();
187 AliMpVSegmentation* mpSegmentation = 0;
189 if ( stationType == AliMp::kStation1 || stationType == AliMp::kStation2 ) {
190 AliMpSectorReader reader(stationType, planeType);
191 AliMpSector* sector = reader.BuildSector();
192 mpSegmentation = new AliMpSectorSegmentation(sector, true);
194 else if ( stationType == AliMp::kStation345 ) {
195 AliMpSt345Reader reader(fSlatMotifMap);
196 AliMpSlat* slat = reader.ReadSlat(deTypeName, planeType);
197 mpSegmentation = new AliMpSlatSegmentation(slat, true);
199 else if ( stationType == AliMp::kStationTrigger ) {
200 AliMpTriggerReader reader(fSlatMotifMap);
201 AliMpTrigger* trigger = reader.ReadSlat(deTypeName, planeType);
202 mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
205 AliErrorStream() << "Unknown station type" << endl;
207 fMpSegmentations.Add(deSegName, mpSegmentation);
209 // StdoutToAliDebug(3, fSlatMotifMap.Print(););
211 return mpSegmentation;
214 //_____________________________________________________________________________
216 AliMpSegmentation::FillElCardsMap(Int_t detElemId)
218 /// Fill the map of electronic cards IDs to segmentations for
221 AliDebugStream(2) << "detElemId=" << detElemId << endl;;
223 AliMpExMap* mde = new AliMpExMap(true);
224 mde->SetOwner(kFALSE);
225 fElCardsMap.Add(detElemId,mde);
227 const AliMpVSegmentation* seg[2];
230 // Do it in 2 steps to be able to set the AliMpExMap size once for all,
231 // to avoid annoying warning message in case of dynamical resizing.
233 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
235 seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
236 seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
239 mde->SetSize(ecn[0].GetSize()+ecn[1].GetSize());
241 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++ cathode )
243 for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
245 mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
256 //______________________________________________________________________________
257 const AliMpVSegmentation*
258 AliMpSegmentation::GetMpSegmentation(
259 Int_t detElemId, AliMp::CathodType cath, Bool_t warn) const
261 /// Return mapping segmentation for given detElemId and cath
263 // Check detElemId & cath
264 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) {
268 << "Invalid detElemId " << detElemId << endl;
273 // If segmentation is already built, just return it
275 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
276 TString deSegName = detElement->GetSegName(cath);
277 TObject* object = fMpSegmentations.Get(deSegName);
279 // Should never happen
281 << "Segmentation for detElemId/cathod "
282 << detElemId << ", " << cath << " not defined" << endl;
286 return static_cast<AliMpVSegmentation*>(object);
289 //_____________________________________________________________________________
290 const AliMpVSegmentation*
291 AliMpSegmentation::GetMpSegmentationByElectronics(
292 Int_t detElemId, Int_t ecId, Bool_t warn) const
294 /// Return mapping segmentation for given detElemId and electronic card Id
295 /// (motif position Id)
297 AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
300 // Should never happen
302 << "Cannot find the el cards map for detElemId " << detElemId << endl;
306 TObject* object = m->GetValue(ecId);
310 << "Segmentation for electronic card "
311 << ecId << " not found" << endl;
316 return static_cast<AliMpVSegmentation*>(object);