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
20 //-----------------------------------------------------------------------------
22 // --------------------
23 // The container class for detection element objects
24 // Authors: Ivana Hrivnacova, IPN Orsay
25 // Laurent Aphecetche, Christian Finck, SUBATECH Nantes
26 //-----------------------------------------------------------------------------
28 #include "AliMpDEStore.h"
29 #include "AliMpDEManager.h"
30 #include "AliMpDetElement.h"
31 #include "AliMpConstants.h"
32 #include "AliMpFiles.h"
33 #include "AliMpHelper.h"
34 #include "AliMpIntPair.h"
35 #include "AliMpConstants.h"
39 #include <Riostream.h>
42 #include <TObjString.h>
43 #include <TObjArray.h>
47 ClassImp(AliMpDEStore)
50 AliMpDEStore* AliMpDEStore::fgInstance = 0;
51 const char AliMpDEStore::fgkCommentPrefix = '#';
57 //______________________________________________________________________________
58 AliMpDEStore* AliMpDEStore::Instance()
60 /// Create the DE store if it does not yet exist
61 /// and return its instance
64 fgInstance = new AliMpDEStore();
73 //______________________________________________________________________________
74 AliMpDEStore::AliMpDEStore()
78 /// Standard constructor
81 fDetElements.SetOwner(true);
83 // Create all detection elements
87 //______________________________________________________________________________
88 AliMpDEStore::AliMpDEStore(TRootIOCtor* /*ioCtor*/)
92 /// Constructor for IO
100 //______________________________________________________________________________
101 AliMpDEStore::~AliMpDEStore()
107 // Segmentations are deleted with fMpSegmentations
108 // El cards arrays are deleted with fElCardsMap
117 //______________________________________________________________________________
118 Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName)
120 /// Return true if the planeTypeName corresponds to a valid plane type
122 if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ||
123 planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
129 //______________________________________________________________________________
130 AliMp::PlaneType AliMpDEStore::PlaneType(const TString& planeTypeName)
132 /// Return plane type for the given planeTypeName \n
133 /// Fatal error if planeTypeName is wrong
135 if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) )
136 return AliMp::kBendingPlane;
138 if ( planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
139 return AliMp::kNonBendingPlane;
141 // Should never reach this line
142 AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data()));
143 return AliMp::kBendingPlane;
146 //______________________________________________________________________________
147 AliMp::StationType AliMpDEStore::StationType(const TString& stationTypeName)
149 /// Return station type for the given stationTypeName \n
150 /// Fatal error if stationTypeName is wrong
152 if ( stationTypeName == StationTypeName(AliMp::kStation1) )
153 return AliMp::kStation1;
155 if ( stationTypeName == StationTypeName(AliMp::kStation2) )
156 return AliMp::kStation2;
158 if ( stationTypeName == StationTypeName(AliMp::kStation345) )
159 return AliMp::kStation345;
161 if ( stationTypeName == StationTypeName(AliMp::kStationTrigger) )
162 return AliMp::kStationTrigger;
164 // Should never reach this line
165 AliFatalClass(Form("No station type defined for ", stationTypeName.Data()));
166 return AliMp::kStation1;
169 //______________________________________________________________________________
170 Bool_t AliMpDEStore::ReadManuToSerialNbs(AliMpDetElement* detElement,
171 AliMp::StationType stationType)
173 /// Read manu serial numbers for the given detection element
174 static Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane);
176 TString deName = detElement->GetDEName();
178 TString infile = AliMpFiles::ManuToSerialPath(deName, stationType);
179 ifstream in(infile, ios::in);
181 // Change to Error when all files available
182 //if ( !in.is_open() && stationType == AliMp::kStation345 ) {
183 // AliWarningStream() << "File " << infile << " not found." << endl;
189 while ( in.getline(line,80) ) {
191 if ( line[0] == '#' ) continue;
193 TString tmp(AliMpHelper::Normalize(line));
195 TObjArray* stringList = tmp.Tokenize(TString(" "));
197 Int_t manuId = atoi( ((TObjString*)stringList->At(0))->GetName());
198 Int_t manuSerial = atoi( ((TObjString*)stringList->At(2))->GetName());
200 TString sPlane = ((TObjString*)stringList->At(1))->GetString();
202 // filling manuId <> manuSerial
203 if (!sPlane.CompareTo(PlaneTypeName(AliMp::kBendingPlane)))
204 detElement->AddManuSerial(manuId, manuSerial);
206 detElement->AddManuSerial(manuId + manuMask, manuSerial);
215 //______________________________________________________________________________
217 AliMpDEStore::ReadDENames(AliMp::StationType station)
219 /// Read det element names for cath = 0 from the file specified by name
223 TString filePath = AliMpFiles::DENamesFilePath(station);
224 std::ifstream in(filePath);
226 AliErrorClassStream() << "Cannot open file " << filePath << endl;;
230 // Read plane types per cathods
234 TString cathName1, cathName2;
236 while ( ! in.eof() && cathName1.Length() == 0 ) {
237 if ( word[0] == '#' )
238 in.getline(line, 80);
246 Bool_t isCathNameDefined = false;
247 if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
248 isCathNameDefined = true;
253 TString name, name0, name1, name2;
254 AliMp::PlaneType planeForCathode[2];
258 if ( word[0] == '#' )
260 in.getline(line, 80);
264 detElemId = word.Atoi();
267 // warning : important to check non bending first (=nbp),
268 // as bp is contained within nbp...
269 if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
271 planeForCathode[0] = AliMp::kNonBendingPlane;
275 planeForCathode[0] = AliMp::kBendingPlane;
278 if ( !isCathNameDefined )
282 Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator());
283 name0 = name1(0,pos);
285 // Other cathode is other plane...
286 planeForCathode[1] = OtherPlaneType(planeForCathode[0]);
290 name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1;
291 name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2;
292 if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
294 planeForCathode[1] = AliMp::kNonBendingPlane;
298 planeForCathode[1] = AliMp::kBendingPlane;
302 if ( planeForCathode[0]==planeForCathode[1] )
304 AliFatalClass(Form("Got the same cathode type for both planes"
305 " of DetElemId %d",detElemId));
308 AliMpDetElement* detElement
309 = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]);
310 if ( ! fDetElements.GetValue(detElemId) )
312 AliDebugClassStream(3)
313 << "Adding DE name " << detElemId << " " << name << endl;
314 fDetElements.Add(detElemId, detElement);
316 // Read manu serial numbers for this det element
317 ReadManuToSerialNbs(detElement, station);
321 AliWarningClassStream()
322 << "Det element " << detElemId << " " << name << " already defined." << endl;
334 //______________________________________________________________________________
335 void AliMpDEStore::FillDEs()
337 /// Fill DE names from files
339 Bool_t result1 = ReadDENames(AliMp::kStation1);
340 Bool_t result2 = ReadDENames(AliMp::kStation2);
341 Bool_t result3 = ReadDENames(AliMp::kStation345);
342 Bool_t result4 = ReadDENames(AliMp::kStationTrigger);
344 Bool_t result = result1 && result2 && result3 && result4;
346 AliErrorClassStream() << "Error in reading DE names files" << endl;
355 //______________________________________________________________________________
356 AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const
358 /// Return det element for given detElemId
360 AliMpDetElement* detElement
361 = (AliMpDetElement*)fDetElements.GetValue(detElemId);
363 if ( ! detElement && warn ) {
364 AliErrorClassStream()
365 << "Detection element " << detElemId << " not defined." << endl;
371 //______________________________________________________________________________
372 AliMpDetElement* AliMpDEStore::GetDetElement(const TString& deName, Bool_t warn) const
374 /// Return det element for given deName
376 for ( Int_t i = 0; i < fDetElements.GetSize(); i++ ) {
378 AliMpDetElement* detElement
379 = (AliMpDetElement*)fDetElements.GetObject(i);
381 if (deName.CompareTo(detElement->GetDEName()) == 0)
387 AliErrorClassStream()
388 << "Detection element with name" << deName.Data() << " not defined." << endl;
394 //______________________________________________________________________________
395 AliMpIntPair AliMpDEStore::GetDetElemIdManu(Int_t manuSerial) const
397 /// Return the detElemId and manuId for given serial manu number
399 for ( Int_t i = 0; i < fDetElements.GetSize(); i++ ) {
401 AliMpDetElement* detElement
402 = (AliMpDetElement*)fDetElements.GetObject(i);
404 Int_t manuId = detElement->GetManuIdFromSerial(manuSerial);
405 if ( manuId ) return AliMpIntPair(detElement->GetId(), manuId);
408 // manu with this serial number does not exist
409 return AliMpIntPair::Invalid();