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(Bool_t warn)
60 /// Create the DE store if it does not yet exist
61 /// and return its instance
63 if ( ! fgInstance && warn ) {
64 AliWarningClass("DE Store has not been loaded");
70 //______________________________________________________________________________
71 AliMpDEStore* AliMpDEStore::ReadData(Bool_t warn)
73 /// Load the DE store data from ASCII data files
74 /// and return its instance
78 AliWarningClass("DE Store has been already loaded");
82 AliInfoClass("Reading DE Store from ASCII files.");
84 fgInstance = new AliMpDEStore();
92 //______________________________________________________________________________
93 AliMpDEStore::AliMpDEStore()
97 /// Standard constructor
100 fDetElements.SetOwner(true);
102 // Create all detection elements
106 //______________________________________________________________________________
107 AliMpDEStore::AliMpDEStore(TRootIOCtor* /*ioCtor*/)
111 /// Constructor for IO
119 //______________________________________________________________________________
120 AliMpDEStore::~AliMpDEStore()
126 // Segmentations are deleted with fMpSegmentations
127 // El cards arrays are deleted with fElCardsMap
136 //______________________________________________________________________________
137 Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName)
139 /// Return true if the planeTypeName corresponds to a valid plane type
141 if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ||
142 planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
148 //______________________________________________________________________________
149 AliMp::PlaneType AliMpDEStore::PlaneType(const TString& planeTypeName)
151 /// Return plane type for the given planeTypeName \n
152 /// Fatal error if planeTypeName is wrong
154 if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) )
155 return AliMp::kBendingPlane;
157 if ( planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
158 return AliMp::kNonBendingPlane;
160 // Should never reach this line
161 AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data()));
162 return AliMp::kBendingPlane;
165 //______________________________________________________________________________
166 AliMp::StationType AliMpDEStore::StationType(const TString& stationTypeName)
168 /// Return station type for the given stationTypeName \n
169 /// Fatal error if stationTypeName is wrong
171 if ( stationTypeName == StationTypeName(AliMp::kStation1) )
172 return AliMp::kStation1;
174 if ( stationTypeName == StationTypeName(AliMp::kStation2) )
175 return AliMp::kStation2;
177 if ( stationTypeName == StationTypeName(AliMp::kStation345) )
178 return AliMp::kStation345;
180 if ( stationTypeName == StationTypeName(AliMp::kStationTrigger) )
181 return AliMp::kStationTrigger;
183 // Should never reach this line
184 AliFatalClass(Form("No station type defined for ", stationTypeName.Data()));
185 return AliMp::kStation1;
188 //______________________________________________________________________________
189 Bool_t AliMpDEStore::ReadManuToSerialNbs(AliMpDetElement* detElement,
190 AliMp::StationType stationType)
192 /// Read manu serial numbers for the given detection element
193 static Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane);
195 TString deName = detElement->GetDEName();
197 TString infile = AliMpFiles::ManuToSerialPath(deName, stationType);
198 ifstream in(infile, ios::in);
200 // Change to Error when all files available
201 //if ( !in.is_open() && stationType == AliMp::kStation345 ) {
202 // AliWarningStream() << "File " << infile << " not found." << endl;
208 while ( in.getline(line,80) ) {
210 if ( line[0] == '#' ) continue;
212 TString tmp(AliMpHelper::Normalize(line));
214 TObjArray* stringList = tmp.Tokenize(TString(" "));
216 Int_t manuId = atoi( ((TObjString*)stringList->At(0))->GetName());
217 Int_t manuSerial = atoi( ((TObjString*)stringList->At(2))->GetName());
219 TString sPlane = ((TObjString*)stringList->At(1))->GetString();
221 // filling manuId <> manuSerial
222 if (!sPlane.CompareTo(PlaneTypeName(AliMp::kBendingPlane)))
223 detElement->AddManuSerial(manuId, manuSerial);
225 detElement->AddManuSerial(manuId + manuMask, manuSerial);
234 //______________________________________________________________________________
236 AliMpDEStore::ReadDENames(AliMp::StationType station)
238 /// Read det element names for cath = 0 from the file specified by name
242 TString filePath = AliMpFiles::DENamesFilePath(station);
243 std::ifstream in(filePath);
245 AliErrorClassStream() << "Cannot open file " << filePath << endl;;
249 // Read plane types per cathods
253 TString cathName1, cathName2;
255 while ( ! in.eof() && cathName1.Length() == 0 ) {
256 if ( word[0] == '#' )
257 in.getline(line, 80);
265 Bool_t isCathNameDefined = false;
266 if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
267 isCathNameDefined = true;
272 TString name, name0, name1, name2;
273 AliMp::PlaneType planeForCathode[2];
277 if ( word[0] == '#' )
279 in.getline(line, 80);
283 detElemId = word.Atoi();
286 // warning : important to check non bending first (=nbp),
287 // as bp is contained within nbp...
288 if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
290 planeForCathode[0] = AliMp::kNonBendingPlane;
294 planeForCathode[0] = AliMp::kBendingPlane;
297 if ( !isCathNameDefined )
301 Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator());
302 name0 = name1(0,pos);
304 // Other cathode is other plane...
305 planeForCathode[1] = OtherPlaneType(planeForCathode[0]);
309 name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1;
310 name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2;
311 if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
313 planeForCathode[1] = AliMp::kNonBendingPlane;
317 planeForCathode[1] = AliMp::kBendingPlane;
321 if ( planeForCathode[0]==planeForCathode[1] )
323 AliFatalClass(Form("Got the same cathode type for both planes"
324 " of DetElemId %d",detElemId));
327 AliMpDetElement* detElement
328 = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]);
329 if ( ! fDetElements.GetValue(detElemId) )
331 AliDebugClassStream(3)
332 << "Adding DE name " << detElemId << " " << name << endl;
333 fDetElements.Add(detElemId, detElement);
335 // Read manu serial numbers for this det element
336 ReadManuToSerialNbs(detElement, station);
340 AliWarningClassStream()
341 << "Det element " << detElemId << " " << name << " already defined." << endl;
353 //______________________________________________________________________________
354 void AliMpDEStore::FillDEs()
356 /// Fill DE names from files
358 Bool_t result1 = ReadDENames(AliMp::kStation1);
359 Bool_t result2 = ReadDENames(AliMp::kStation2);
360 Bool_t result3 = ReadDENames(AliMp::kStation345);
361 Bool_t result4 = ReadDENames(AliMp::kStationTrigger);
363 Bool_t result = result1 && result2 && result3 && result4;
365 AliErrorClassStream() << "Error in reading DE names files" << endl;
374 //______________________________________________________________________________
375 AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const
377 /// Return det element for given detElemId
379 AliMpDetElement* detElement
380 = (AliMpDetElement*)fDetElements.GetValue(detElemId);
382 if ( ! detElement && warn ) {
383 AliErrorClassStream()
384 << "Detection element " << detElemId << " not defined." << endl;
390 //______________________________________________________________________________
391 AliMpDetElement* AliMpDEStore::GetDetElement(const TString& deName, Bool_t warn) const
393 /// Return det element for given deName
395 for ( Int_t i = 0; i < fDetElements.GetSize(); i++ ) {
397 AliMpDetElement* detElement
398 = (AliMpDetElement*)fDetElements.GetObject(i);
400 if (deName.CompareTo(detElement->GetDEName()) == 0)
406 AliErrorClassStream()
407 << "Detection element with name" << deName.Data() << " not defined." << endl;
413 //______________________________________________________________________________
414 AliMpIntPair AliMpDEStore::GetDetElemIdManu(Int_t manuSerial) const
416 /// Return the detElemId and manuId for given serial manu number
418 for ( Int_t i = 0; i < fDetElements.GetSize(); i++ ) {
420 AliMpDetElement* detElement
421 = (AliMpDetElement*)fDetElements.GetObject(i);
423 Int_t manuId = detElement->GetManuIdFromSerial(manuSerial);
424 if ( manuId ) return AliMpIntPair(detElement->GetId(), manuId);
427 // manu with this serial number does not exist
428 return AliMpIntPair::Invalid();