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 //-----------------------------------------------------------------------------
29 #include "AliMpDEStore.h"
30 #include "AliMpDEManager.h"
31 #include "AliMpDetElement.h"
32 #include "AliMpConstants.h"
33 #include "AliMpFiles.h"
34 #include "AliMpHelper.h"
35 #include "AliMpIntPair.h"
36 #include "AliMpConstants.h"
37 #include "AliMpExMapIterator.h"
41 #include <Riostream.h>
44 #include <TObjString.h>
45 #include <TObjArray.h>
49 ClassImp(AliMpDEStore)
52 AliMpDEStore* AliMpDEStore::fgInstance = 0;
53 const char AliMpDEStore::fgkCommentPrefix = '#';
59 //______________________________________________________________________________
60 AliMpDEStore* AliMpDEStore::Instance(Bool_t warn)
62 /// Create the DE store if it does not yet exist
63 /// and return its instance
65 if ( ! fgInstance && warn ) {
66 AliWarningClass("DE Store has not been loaded");
72 //______________________________________________________________________________
73 AliMpDEStore* AliMpDEStore::ReadData(Bool_t warn)
75 /// Load the DE store data from ASCII data files
76 /// and return its instance
80 AliWarningClass("DE Store has been already loaded");
84 AliInfoClass("Reading DE Store from ASCII files.");
86 fgInstance = new AliMpDEStore();
94 //______________________________________________________________________________
95 AliMpDEStore::AliMpDEStore()
99 /// Standard constructor
102 fDetElements.SetOwner(true);
104 // Create all detection elements
108 //______________________________________________________________________________
109 AliMpDEStore::AliMpDEStore(TRootIOCtor* ioCtor)
113 /// Constructor for IO
121 //______________________________________________________________________________
122 AliMpDEStore::~AliMpDEStore()
128 // Segmentations are deleted with fMpSegmentations
129 // El cards arrays are deleted with fElCardsMap
138 //______________________________________________________________________________
139 Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName)
141 /// Return true if the planeTypeName corresponds to a valid plane type
143 if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ||
144 planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
150 //______________________________________________________________________________
151 AliMp::PlaneType AliMpDEStore::PlaneType(const TString& planeTypeName)
153 /// Return plane type for the given planeTypeName \n
154 /// Fatal error if planeTypeName is wrong
156 if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) )
157 return AliMp::kBendingPlane;
159 if ( planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
160 return AliMp::kNonBendingPlane;
162 // Should never reach this line
163 AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data()));
164 return AliMp::kBendingPlane;
167 //______________________________________________________________________________
168 AliMp::StationType AliMpDEStore::StationType(const TString& stationTypeName)
170 /// Return station type for the given stationTypeName \n
171 /// Fatal error if stationTypeName is wrong
173 if ( stationTypeName == StationTypeName(AliMp::kStation1) )
174 return AliMp::kStation1;
176 if ( stationTypeName == StationTypeName(AliMp::kStation2) )
177 return AliMp::kStation2;
179 if ( stationTypeName == StationTypeName(AliMp::kStation345) )
180 return AliMp::kStation345;
182 if ( stationTypeName == StationTypeName(AliMp::kStationTrigger) )
183 return AliMp::kStationTrigger;
185 // Should never reach this line
186 AliFatalClass(Form("No station type defined for ", stationTypeName.Data()));
187 return AliMp::kStation1;
190 //______________________________________________________________________________
191 Bool_t AliMpDEStore::ReadManuToSerialNbs(AliMpDetElement* detElement,
192 AliMp::StationType stationType)
194 /// Read manu serial numbers for the given detection element
195 static Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane);
197 TString deName = detElement->GetDEName();
199 TString infile = AliMpFiles::ManuToSerialPath(deName, stationType);
200 ifstream in(infile, ios::in);
202 // Change to Error when all files available
203 //if ( !in.is_open() && stationType == AliMp::kStation345 ) {
204 // AliWarningStream() << "File " << infile << " not found." << endl;
210 while ( in.getline(line,80) ) {
212 if ( line[0] == '#' ) continue;
214 TString tmp(AliMpHelper::Normalize(line));
216 TObjArray* stringList = tmp.Tokenize(TString(" "));
218 Int_t manuId = atoi( ((TObjString*)stringList->At(0))->GetName());
219 Int_t manuSerial = atoi( ((TObjString*)stringList->At(2))->GetName());
221 TString sPlane = ((TObjString*)stringList->At(1))->GetString();
223 // filling manuId <> manuSerial
224 if (!sPlane.CompareTo(PlaneTypeName(AliMp::kBendingPlane)))
225 detElement->AddManuSerial(manuId, manuSerial);
227 detElement->AddManuSerial(manuId + manuMask, manuSerial);
236 //______________________________________________________________________________
238 AliMpDEStore::ReadDENames(AliMp::StationType station)
240 /// Read det element names for cath = 0 from the file specified by name
244 TString filePath = AliMpFiles::DENamesFilePath(station);
245 std::ifstream in(filePath);
247 AliErrorClassStream() << "Cannot open file " << filePath << endl;;
251 // Read plane types per cathods
255 TString cathName1, cathName2;
257 while ( ! in.eof() && cathName1.Length() == 0 ) {
258 if ( word[0] == '#' )
259 in.getline(line, 80);
267 Bool_t isCathNameDefined = false;
268 if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
269 isCathNameDefined = true;
274 TString name, name0, name1, name2;
275 AliMp::PlaneType planeForCathode[2];
279 if ( word[0] == '#' )
281 in.getline(line, 80);
285 detElemId = word.Atoi();
288 // warning : important to check non bending first (=nbp),
289 // as bp is contained within nbp...
290 if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
292 planeForCathode[0] = AliMp::kNonBendingPlane;
296 planeForCathode[0] = AliMp::kBendingPlane;
299 if ( !isCathNameDefined )
303 Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator());
304 name0 = name1(0,pos);
306 // Other cathode is other plane...
307 planeForCathode[1] = OtherPlaneType(planeForCathode[0]);
311 name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1;
312 name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2;
313 if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
315 planeForCathode[1] = AliMp::kNonBendingPlane;
319 planeForCathode[1] = AliMp::kBendingPlane;
323 if ( planeForCathode[0]==planeForCathode[1] )
325 AliFatalClass(Form("Got the same cathode type for both planes"
326 " of DetElemId %d",detElemId));
329 AliMpDetElement* detElement = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]);
331 if ( ! fDetElements.GetValue(detElemId) )
333 AliDebugClassStream(3)
334 << "Adding DE name " << detElemId << " " << name << endl;
335 fDetElements.Add(detElemId, detElement);
337 // Read manu serial numbers for this det element
338 ReadManuToSerialNbs(detElement, station);
342 AliWarningClassStream()
343 << "Det element " << detElemId << " " << name << " already defined." << endl;
355 //______________________________________________________________________________
356 void AliMpDEStore::FillDEs()
358 /// Fill DE names from files
360 Bool_t result1 = ReadDENames(AliMp::kStation1);
361 Bool_t result2 = ReadDENames(AliMp::kStation2);
362 Bool_t result3 = ReadDENames(AliMp::kStation345);
363 Bool_t result4 = ReadDENames(AliMp::kStationTrigger);
365 Bool_t result = result1 && result2 && result3 && result4;
367 AliErrorClassStream() << "Error in reading DE names files" << endl;
376 //______________________________________________________________________________
377 AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const
379 /// Return det element for given detElemId
381 AliMpDetElement* detElement
382 = (AliMpDetElement*)fDetElements.GetValue(detElemId);
384 if ( ! detElement && warn ) {
385 AliErrorClassStream()
386 << "Detection element " << detElemId << " not defined." << endl;
392 //______________________________________________________________________________
393 AliMpDetElement* AliMpDEStore::GetDetElement(const TString& deName, Bool_t warn) const
395 /// Return det element for given deName
397 TIter next(fDetElements.CreateIterator());
398 AliMpDetElement* detElement;
400 while ( ( detElement = static_cast<AliMpDetElement*>(next()) ) )
403 if (deName.CompareTo(detElement->GetDEName()) == 0)
409 AliErrorClassStream()
410 << "Detection element with name" << deName.Data() << " not defined." << endl;
416 //______________________________________________________________________________
417 AliMpIntPair AliMpDEStore::GetDetElemIdManu(Int_t manuSerial) const
419 /// Return the detElemId and manuId for given serial manu number
421 TIter next(fDetElements.CreateIterator());
422 AliMpDetElement* detElement;
424 while ( ( detElement = static_cast<AliMpDetElement*>(next()) ) )
426 Int_t manuId = detElement->GetManuIdFromSerial(manuSerial);
427 if ( manuId ) return AliMpIntPair(detElement->GetId(), manuId);
430 // manu with this serial number does not exist
431 return AliMpIntPair::Invalid();