]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpDDLStore.cxx
Applying ManuMask in motif position test
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDDLStore.cxx
CommitLineData
f0c62051 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16// $Id$
17// $MpId: AliMpDDLStore.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
18// Category: management
19//
20// Class AliMpDDLStore
21// --------------------
22// The top container class for DDLs, det elements and bus patched
23// It provides acces to DDL, det element and bus patches objects
24// via various characteristics.
25// Authors: Ivana Hrivnacova, IPN Orsay
26// Christian Finck, SUBATECH Nantes
27
28#include "AliMpDDLStore.h"
29#include "AliMpDEStore.h"
30#include "AliMpDDL.h"
31#include "AliMpFiles.h"
32#include "AliMpHelper.h"
33#include "AliMpDEManager.h"
34#include "AliMpDetElement.h"
35#include "AliMpBusPatch.h"
36
37#include "AliLog.h"
38
39#include <Riostream.h>
40
41/// \cond CLASSIMP
42ClassImp(AliMpDDLStore)
43/// \endcond
44
45AliMpDDLStore* AliMpDDLStore::fgInstance = 0;
46const Int_t AliMpDDLStore::fgkNofDDLs = 20;
47
48//
49// static methods
50//
51
52//______________________________________________________________________________
53AliMpDDLStore* AliMpDDLStore::Instance()
54{
55/// Create the DDL store if it does not yet exist
56/// and return its instance
57
58 if ( ! fgInstance )
59 fgInstance = new AliMpDDLStore();
60
61 return fgInstance;
62}
63
64//
65// ctors, dtor
66//
67
68//______________________________________________________________________________
69AliMpDDLStore::AliMpDDLStore()
70: TObject(),
71 fDDLs(fgkNofDDLs),
72 fDetElements(AliMpDEStore::Instance()),
73 fBusPatches(true)
74{
75/// Standard constructor
76
77 AliDebug(1,"");
78 fDDLs.SetOwner(true);
79 fBusPatches.SetOwner(true);
80 fBusPatches.SetSize(900);
81
82 // Create all detection elements
83 ReadDDLs();
84}
85
86//______________________________________________________________________________
87AliMpDDLStore::AliMpDDLStore(TRootIOCtor* /*ioCtor*/)
88: TObject(),
89 fDDLs(),
90 fDetElements(0),
91 fBusPatches()
92{
93/// Constructor for IO
94
95 AliDebug(1,"");
96
97 fgInstance = this;
98}
99
100
101//______________________________________________________________________________
102AliMpDDLStore::~AliMpDDLStore()
103{
104/// Destructor
105
106 AliDebug(1,"");
107
108 delete fDetElements;
109
110 // DDL objects are deleted with fDDLs
111 // Bus patches objects are deleted with fBusPatches
112
113 fgInstance = 0;
114}
115
116//
117// private methods
118//
119
120//______________________________________________________________________________
121Bool_t AliMpDDLStore::ReadDDLs()
122{
123/// Read ddl <-> bus patch file
124
125 TString infile = AliMpFiles::BusPatchFilePath();
126
127 ifstream in(infile, ios::in);
128 if (!in) {
129 AliErrorStream() << "Data file " << infile << " not found.";
130 return false;
131 }
132
133 char line[80];
134
135 while ( in.getline(line,80) ) {
136
137 if ( line[0] == '#' ) continue;
138
139 TString tmp(AliMpHelper::Normalize(line));
140
141 Int_t blankPos = tmp.First(' ');
142 Int_t blankPos1 = tmp.Last(' ');
143
144 TString sDE(tmp(0, blankPos));
145
146 Int_t idDE = atoi(sDE.Data());
147
148 TString sDDL(tmp(blankPos1 + 1, tmp.Length()-blankPos1));
149
150 Int_t iDDL = atoi(sDDL.Data());
151
152 // always working local DDL number... for the moment.
153
154 // not really needed remove for stand alone purpose (Ch.F)
155 // if (iDDL >= AliDAQ::DdlIDOffset("MUONTRK"))
156 // iDDL -= AliDAQ::DdlIDOffset("MUONTRK");
157
158
159 TString busPatch(tmp(blankPos + 1,blankPos1-blankPos-1));
160 AliDebugStream(3)
161 << "idDE " << idDE << " buspatch " << busPatch.Data() << " iDDL " << iDDL
162 << endl;
163
164 if ( iDDL < 0 || iDDL >= fgkNofDDLs ) {
165 AliErrorStream() << "DDL id "<< iDDL << " outside limits." << endl;
166 return false;
167 }
168
169 if ( ! AliMpDEManager::IsValidDetElemId(idDE, false) ) {
170 AliErrorStream() << "DetElemId "<< idDE << " not valid." << endl;
171 return false;
172 }
173
174
175 AliMpDDL* ddl = GetDDL(iDDL, false);
176 if ( !ddl) {
177 ddl = new AliMpDDL(iDDL);
178 fDDLs.AddAt(ddl, iDDL);
179 }
180 ddl->AddDE(idDE);
181
182
183 TArrayI busPatchList;
184 // decoding range of buspatch
185 AliMpHelper::DecodeName(busPatch,';',busPatchList);
186
187 // Update DE
188 AliMpDetElement* de = AliMpDEManager::GetDetElement(idDE);
189 de->SetDdlId(iDDL);
190 // filling buspatch -> idDE
191 for (Int_t i = 0; i < busPatchList.GetSize(); i++) {
192 fBusPatches.Add(busPatchList[i],
193 new AliMpBusPatch(busPatchList[i], idDE, iDDL));
194 de->AddBusPatch(busPatchList[i]);
195 }
196 }
197
198 // Fill bus patch Ids array in DDLs now
199 for ( Int_t i=0; i<fDDLs.GetEntriesFast(); i++ ) {
200 AliMpDDL* ddl = (AliMpDDL*) fDDLs.At(i);
201 ddl->FillBusPatchIds();
202 }
203
204 in.close();
205 return true;
206}
207
208//
209// public methods
210//
211
212
213//______________________________________________________________________________
214AliMpDDL* AliMpDDLStore::GetDDL(Int_t ddlId, Bool_t warn) const
215{
216/// Return DDL for given ddlId
217
218 AliMpDDL* ddl
219 = (AliMpDDL*)fDDLs.At(ddlId);
220
221 if ( ! ddl && warn ) {
222 AliErrorStream()
223 << "DDL with Id = " << ddlId << " not defined." << endl;
224 }
225
226 return ddl;
227}
228
229//______________________________________________________________________________
230AliMpDetElement* AliMpDDLStore::GetDetElement(Int_t detElemId, Bool_t warn) const
231{
232/// Return detection element with given detElemId
233
234 return fDetElements->GetDetElement(detElemId, warn);
235}
236
237//______________________________________________________________________________
238AliMpBusPatch* AliMpDDLStore::GetBusPatch(Int_t busPatchId, Bool_t warn) const
239{
240/// Return bus patch with given Id
241
242 AliMpBusPatch* busPatch
243 = (AliMpBusPatch*) fBusPatches.GetValue(busPatchId);
244
245 if ( ! busPatch && warn ) {
246 AliErrorStream()
247 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
248 }
249
250 return busPatch;
251}
252
253//______________________________________________________________________________
254Int_t AliMpDDLStore::GetDEfromBus(Int_t busPatchId) const
255{
256/// Return detection element Id for given busPatchId
257
258 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
259
260 if ( ! busPatch ) {
261 AliErrorStream()
262 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
263 return 0;
264 }
265
266 return busPatch->GetDEId();
267}
268
269//______________________________________________________________________________
270Int_t AliMpDDLStore::GetDDLfromBus(Int_t busPatchId) const
271{
272/// Return DDL Id for given busPatchId
273
274 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
275
276 if ( ! busPatch ) {
277 AliErrorStream()
278 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
279 return 0;
280 }
281
282 return busPatch->GetDdlId();
283}
284
285//______________________________________________________________________________
286AliMpIntPair AliMpDDLStore::GetDetElemIdManu(Int_t manuSerial) const
287{
288/// Return the detElemId and manuId for given serial manu number
289
290 return fDetElements->GetDetElemIdManu(manuSerial);
291}