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: AliMpDEStore.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
21 // --------------------
22 // The container class for detection element objects
23 // Authors: Ivana Hrivnacova, IPN Orsay
24 // Laurent Aphecetche, Christian Finck, SUBATECH Nantes
26 #include "AliMpDEStore.h"
27 #include "AliMpDEManager.h"
28 #include "AliMpDetElement.h"
29 #include "AliMpConstants.h"
30 #include "AliMpFiles.h"
31 #include "AliMpHelper.h"
32 #include "AliMpIntPair.h"
33 #include "AliMpConstants.h"
37 #include <Riostream.h>
40 #include <TObjString.h>
44 ClassImp(AliMpDEStore)
47 AliMpDEStore* AliMpDEStore::fgInstance = 0;
48 const char AliMpDEStore::fgkCommentPrefix = '#';
54 //______________________________________________________________________________
55 AliMpDEStore* AliMpDEStore::Instance()
57 /// Create the DE store if it does not yet exist
58 /// and return its instance
61 fgInstance = new AliMpDEStore();
70 //______________________________________________________________________________
71 AliMpDEStore::AliMpDEStore()
75 /// Standard constructor
78 fDetElements.SetOwner(true);
80 // Create all detection elements
84 //______________________________________________________________________________
85 AliMpDEStore::AliMpDEStore(TRootIOCtor* /*ioCtor*/)
89 /// Constructor for IO
97 //______________________________________________________________________________
98 AliMpDEStore::~AliMpDEStore()
104 // Segmentations are deleted with fMpSegmentations
105 // El cards arrays are deleted with fElCardsMap
114 //______________________________________________________________________________
115 Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName)
117 /// Return true if the planeTypeName corresponds to a valid plane type
119 if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ||
120 planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
126 //______________________________________________________________________________
127 AliMp::PlaneType AliMpDEStore::PlaneType(const TString& planeTypeName)
129 /// Return plane type for the given planeTypeName \n
130 /// Fatal error if planeTypeName is wrong
132 if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) )
133 return AliMp::kBendingPlane;
135 if ( planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
136 return AliMp::kNonBendingPlane;
138 // Should never reach this line
139 AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data()));
140 return AliMp::kBendingPlane;
143 //______________________________________________________________________________
144 AliMp::StationType AliMpDEStore::StationType(const TString& stationTypeName)
146 /// Return station type for the given stationTypeName \n
147 /// Fatal error if stationTypeName is wrong
149 if ( stationTypeName == StationTypeName(AliMp::kStation1) )
150 return AliMp::kStation1;
152 if ( stationTypeName == StationTypeName(AliMp::kStation2) )
153 return AliMp::kStation2;
155 if ( stationTypeName == StationTypeName(AliMp::kStation345) )
156 return AliMp::kStation345;
158 if ( stationTypeName == StationTypeName(AliMp::kStationTrigger) )
159 return AliMp::kStationTrigger;
161 // Should never reach this line
162 AliFatalClass(Form("No station type defined for ", stationTypeName.Data()));
163 return AliMp::kStation1;
166 //______________________________________________________________________________
167 Bool_t AliMpDEStore::ReadManuToSerialNbs(AliMpDetElement* detElement,
168 AliMp::StationType stationType)
170 /// Read manu serial numbers for the given detection element
172 TString deName = detElement->GetDEName();
174 TString infile = AliMpFiles::ManuToSerialPath(deName, stationType);
175 ifstream in(infile, ios::in);
177 // Change to Error when all files available
178 //if ( !in.is_open() && stationType == AliMp::kStation345 ) {
179 // AliWarningStream() << "File " << infile << " not found." << endl;
185 while ( in.getline(line,80) ) {
187 if ( line[0] == '#' ) continue;
189 TString tmp(AliMpHelper::Normalize(line));
191 Int_t blankPos = tmp.First(' ');
193 TString sManuId(tmp(0, blankPos));
195 Int_t manuId = atoi(sManuId.Data());
197 TString sManuSerial(tmp(blankPos + 1, tmp.Length()-blankPos));
199 Int_t manuSerial = atoi(sManuSerial.Data());
201 // filling manuId <> manuSerial
202 detElement->AddManuSerial(manuId, manuSerial);
209 //______________________________________________________________________________
211 AliMpDEStore::ReadDENames(AliMp::StationType station)
213 /// Read det element names for cath = 0 from the file specified by name
217 TString filePath = AliMpFiles::DENamesFilePath(station);
218 std::ifstream in(filePath);
220 AliErrorClassStream() << "Cannot open file " << filePath << endl;;
224 // Read plane types per cathods
228 TString cathName1, cathName2;
230 while ( ! in.eof() && cathName1.Length() == 0 ) {
231 if ( word[0] == '#' )
232 in.getline(line, 80);
240 Bool_t isCathNameDefined = false;
241 if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
242 isCathNameDefined = true;
247 TString name, name0, name1, name2;
248 AliMp::PlaneType planeForCathode[2];
252 if ( word[0] == '#' )
254 in.getline(line, 80);
258 detElemId = word.Atoi();
261 // warning : important to check non bending first (=nbp),
262 // as bp is contained within nbp...
263 if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
265 planeForCathode[0] = AliMp::kNonBendingPlane;
269 planeForCathode[0] = AliMp::kBendingPlane;
272 if ( !isCathNameDefined )
276 Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator());
277 name0 = name1(0,pos);
279 // Other cathode is other plane...
280 planeForCathode[1] = OtherPlaneType(planeForCathode[0]);
284 name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1;
285 name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2;
286 if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
288 planeForCathode[1] = AliMp::kNonBendingPlane;
292 planeForCathode[1] = AliMp::kBendingPlane;
296 if ( planeForCathode[0]==planeForCathode[1] )
298 AliFatalClass(Form("Got the same cathode type for both planes"
299 " of DetElemId %d",detElemId));
302 AliMpDetElement* detElement
303 = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]);
304 if ( ! fDetElements.GetValue(detElemId) )
306 AliDebugClassStream(3)
307 << "Adding DE name " << detElemId << " " << name << endl;
308 fDetElements.Add(detElemId, detElement);
310 // Read manu serial numbers for this det element
311 ReadManuToSerialNbs(detElement, station);
315 AliWarningClassStream()
316 << "Det element " << detElemId << " " << name << " already defined." << endl;
328 //______________________________________________________________________________
329 void AliMpDEStore::FillDEs()
331 /// Fill DE names from files
333 Bool_t result1 = ReadDENames(AliMp::kStation1);
334 Bool_t result2 = ReadDENames(AliMp::kStation2);
335 Bool_t result3 = ReadDENames(AliMp::kStation345);
336 Bool_t result4 = ReadDENames(AliMp::kStationTrigger);
338 Bool_t result = result1 && result2 && result3 && result4;
340 AliErrorClassStream() << "Error in reading DE names files" << endl;
349 //______________________________________________________________________________
350 AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const
352 /// Return det element for given detElemId
354 AliMpDetElement* detElement
355 = (AliMpDetElement*)fDetElements.GetValue(detElemId);
357 if ( ! detElement && warn ) {
358 AliErrorClassStream()
359 << "Detection element " << detElemId << " not defined." << endl;
365 //______________________________________________________________________________
366 AliMpIntPair AliMpDEStore::GetDetElemIdManu(Int_t manuSerial) const
368 /// Return the detElemId and manuId for given serial manu number
370 for ( Int_t i = 0; i < fDetElements.GetSize(); i++ ) {
372 AliMpDetElement* detElement
373 = (AliMpDetElement*)fDetElements.GetObject(i);
375 Int_t manuId = detElement->GetManuIdFromSerial(manuSerial);
376 if ( manuId ) return AliMpIntPair(detElement->GetId(), manuId);
379 // manu with this serial number does not exist
380 return AliMpIntPair::Invalid();