]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpDDLStore.cxx
Add the array of crates Id
[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
42d368d0 27#include "AliMpConstants.h"
f0c62051 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"
42d368d0 36#include "AliMpSegmentation.h"
37#include "AliMpVSegmentation.h"
f0c62051 38
39#include "AliLog.h"
40
41#include <Riostream.h>
42d368d0 42#include <TList.h>
f0c62051 43
44/// \cond CLASSIMP
45ClassImp(AliMpDDLStore)
46/// \endcond
47
48AliMpDDLStore* AliMpDDLStore::fgInstance = 0;
49const Int_t AliMpDDLStore::fgkNofDDLs = 20;
50
51//
52// static methods
53//
54
55//______________________________________________________________________________
56AliMpDDLStore* AliMpDDLStore::Instance()
57{
58/// Create the DDL store if it does not yet exist
59/// and return its instance
60
61 if ( ! fgInstance )
62 fgInstance = new AliMpDDLStore();
63
64 return fgInstance;
65}
66
67//
68// ctors, dtor
69//
70
71//______________________________________________________________________________
72AliMpDDLStore::AliMpDDLStore()
73: TObject(),
74 fDDLs(fgkNofDDLs),
75 fDetElements(AliMpDEStore::Instance()),
42d368d0 76 fBusPatches(true),
77 fManuList12()
f0c62051 78{
79/// Standard constructor
80
81 AliDebug(1,"");
82 fDDLs.SetOwner(true);
83 fBusPatches.SetOwner(true);
84 fBusPatches.SetSize(900);
85
86 // Create all detection elements
87 ReadDDLs();
42d368d0 88 SetManus();
dbc1e34c 89 SetPatchModules();
f0c62051 90}
91
92//______________________________________________________________________________
93AliMpDDLStore::AliMpDDLStore(TRootIOCtor* /*ioCtor*/)
94: TObject(),
95 fDDLs(),
96 fDetElements(0),
97 fBusPatches()
98{
99/// Constructor for IO
100
101 AliDebug(1,"");
102
103 fgInstance = this;
104}
105
106
107//______________________________________________________________________________
108AliMpDDLStore::~AliMpDDLStore()
109{
110/// Destructor
111
112 AliDebug(1,"");
113
114 delete fDetElements;
115
116 // DDL objects are deleted with fDDLs
117 // Bus patches objects are deleted with fBusPatches
118
119 fgInstance = 0;
120}
121
122//
123// private methods
124//
125
42d368d0 126//______________________________________________________________________________
127Int_t AliMpDDLStore::GetManuListIndex(Int_t detElemId) const
128{
129/// Return the index of the manu list for given detElemId
130
131 return AliMpDEManager::GetChamberId(detElemId)*4 + (detElemId % 100);
132}
133
134
135//______________________________________________________________________________
136Int_t AliMpDDLStore::GetBusPatchIndex(Int_t detElemId, Int_t manuId) const
137{
138/// Calculate the index of the buspatch from manuId
139
140 Int_t pos = 0;
141 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
142 static Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane) - 1;
143
144 if( stationType == AliMp::kStation345) {
145 pos = (manuId & manuMask)/100;
146 } else {
147 Int_t idx = GetManuListIndex(detElemId);
148
149 // using array defined from DetElemIdToBusPatch.dat file
150 for (pos = fManuList12[idx].GetSize()-1; pos >= 0; --pos)
151 if ( manuId >= fManuList12[idx].At(pos)) break;
152 }
153
154 return pos;
155}
156
157
f0c62051 158//______________________________________________________________________________
159Bool_t AliMpDDLStore::ReadDDLs()
160{
161/// Read ddl <-> bus patch file
162
42d368d0 163
f0c62051 164 TString infile = AliMpFiles::BusPatchFilePath();
165
166 ifstream in(infile, ios::in);
167 if (!in) {
168 AliErrorStream() << "Data file " << infile << " not found.";
169 return false;
170 }
171
42d368d0 172 char line[255];
f0c62051 173
42d368d0 174 while ( in.getline(line,255) ) {
f0c62051 175
176 if ( line[0] == '#' ) continue;
177
178 TString tmp(AliMpHelper::Normalize(line));
179
180 Int_t blankPos = tmp.First(' ');
181 Int_t blankPos1 = tmp.Last(' ');
42d368d0 182 Int_t length = 0;
f0c62051 183
184 TString sDE(tmp(0, blankPos));
185
186 Int_t idDE = atoi(sDE.Data());
187
42d368d0 188 // reading 1st manu Id for each bus patch (station 1 & 2)
189 if(AliMpDEManager::GetStationType(idDE) != AliMp::kStation345) {
f0c62051 190
42d368d0 191 TString sManu(tmp(blankPos1 + 1, tmp.Length()-blankPos1));
192 AliMpHelper::DecodeName(sManu,',',fManuList12[GetManuListIndex(idDE)]);
f0c62051 193
42d368d0 194 TString tmp1(tmp(blankPos + 1, blankPos1 - blankPos));
195 blankPos1 = blankPos + tmp1.First(' ') + 1;
196 length = tmp.Last(' ') - blankPos1;
f0c62051 197
42d368d0 198 } else {
199 length = tmp.Length()-blankPos1;
200 }
f0c62051 201
42d368d0 202 TString sDDL(tmp(blankPos1 + 1, length));
203 Int_t iDDL = atoi(sDDL.Data());
204
f0c62051 205
206 TString busPatch(tmp(blankPos + 1,blankPos1-blankPos-1));
207 AliDebugStream(3)
42d368d0 208 << "idDE " << idDE << " buspatch " << busPatch.Data() << " iDDL " << iDDL
209 << endl;
210
f0c62051 211 if ( iDDL < 0 || iDDL >= fgkNofDDLs ) {
212 AliErrorStream() << "DDL id "<< iDDL << " outside limits." << endl;
213 return false;
214 }
215
216 if ( ! AliMpDEManager::IsValidDetElemId(idDE, false) ) {
217 AliErrorStream() << "DetElemId "<< idDE << " not valid." << endl;
218 return false;
219 }
f0c62051 220
221 AliMpDDL* ddl = GetDDL(iDDL, false);
222 if ( !ddl) {
223 ddl = new AliMpDDL(iDDL);
224 fDDLs.AddAt(ddl, iDDL);
225 }
226 ddl->AddDE(idDE);
227
f0c62051 228 TArrayI busPatchList;
229 // decoding range of buspatch
230 AliMpHelper::DecodeName(busPatch,';',busPatchList);
231
232 // Update DE
233 AliMpDetElement* de = AliMpDEManager::GetDetElement(idDE);
234 de->SetDdlId(iDDL);
235 // filling buspatch -> idDE
236 for (Int_t i = 0; i < busPatchList.GetSize(); i++) {
237 fBusPatches.Add(busPatchList[i],
238 new AliMpBusPatch(busPatchList[i], idDE, iDDL));
239 de->AddBusPatch(busPatchList[i]);
240 }
241 }
242
243 // Fill bus patch Ids array in DDLs now
244 for ( Int_t i=0; i<fDDLs.GetEntriesFast(); i++ ) {
245 AliMpDDL* ddl = (AliMpDDL*) fDDLs.At(i);
246 ddl->FillBusPatchIds();
247 }
248
249 in.close();
250 return true;
251}
42d368d0 252//______________________________________________________________________________
253Bool_t AliMpDDLStore::SetManus()
254{
255/// Set manus for each bus patch
256
257 Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane) - 1;
258
259 // loop over DDL
260 for (Int_t iDDL = 0; iDDL < fgkNofDDLs; ++iDDL) {
261
262 AliDebug(3, Form("DDL # %d\n", iDDL));
263
264 AliMpDDL* ddl = GetDDL(iDDL);
265
266 // loop over DE in the given DDL
267 for (Int_t detElemIdx = 0; detElemIdx < ddl->GetNofDEs(); ++detElemIdx) {
268
269 Int_t detElemId = ddl->GetDEId(detElemIdx);
270
271 AliMpDetElement* detElement = GetDetElement(detElemId);
272
273 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
274
275
276 // list of manu per DE on both cathode
277 TList manuList;
278 for ( Int_t cath = 0; cath < 2 ; ++cath ) {
279 const AliMpVSegmentation* seg
280 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(cath));
281
282 AliMp::PlaneType planeType = detElement->GetPlaneType(AliMp::GetCathodType(cath));
283
284 TArrayI manus;
285 seg->GetAllElectronicCardIDs(manus);
286
287 // filling TList manu
288 for ( Int_t im = 0; im < manus.GetSize(); ++im ) {
289
290 AliMpIntPair* manu = 0x0;
291 if( stationType == AliMp::kStation345)
292 manu = new AliMpIntPair((manus[im] & manuMask), planeType, kTRUE); //remove offset for NB
293 else
294 manu = new AliMpIntPair(manus[im], planeType, kTRUE); //keep offset for NB
295
296 manuList.Add(manu);
297 }
298 }// cathode
299
300 manuList.Sort(); // sort regardless B or NB plane
301
302 // filling manu to the corresponding buspatch
303 for (Int_t iEntry = 0; iEntry < manuList.GetEntries(); ++iEntry) {
304
305 AliMpIntPair* manuPtr = (AliMpIntPair*)manuList.At(iEntry);
306
307 Int_t manuId = manuPtr->GetFirst();
308 Int_t pos = GetBusPatchIndex(detElemId, manuId);
309
310 if (pos > detElement->GetNofBusPatches()) {
311 AliError(Form("pos greater %d than size %d manuId %d detElemId %d \n",
312 pos, detElement->GetNofBusPatches(), manuId, detElemId));
313 return false;
314 }
315
316 // get buspatch and fill manus
317 Int_t busPatchId = detElement->GetBusPatchId(pos);
318 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
319
320 if( stationType == AliMp::kStation345) {
321
322 if (manuPtr->GetSecond())
323 busPatch->AddManu(manuId+manuMask+1); // add offset again after sorted
324 else
325 busPatch->AddManu(manuId);
326
327 } else {
328
329 busPatch->AddManu(manuId);
330
331 }
332 }
333
334 manuList.Delete();
335
336 if (AliDebugLevel() == 3) {
337
338 // print out for checking
339 for(Int_t pos = 0; pos < detElement->GetNofBusPatches(); ++pos) {
340 Int_t busPatchId = detElement->GetBusPatchId(pos);
341 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
342 printf("BusPatch: %d\n", busPatch->GetId());
343 for (Int_t iEntry = 0; iEntry < busPatch->GetNofManus(); ++iEntry)
344 printf("manu Id: %d\n", busPatch->GetManuId(iEntry));
345 }
346 }
347
348 } // detection element loop
349 }// DDL loop
350
351 return true;
352}
f0c62051 353
dbc1e34c 354//______________________________________________________________________________
355Bool_t AliMpDDLStore::SetPatchModules()
356{
357/// Compute the number of manu per PCB for each buspatch
358
359 Bool_t result = true;
360
361 for (Int_t i = 0; i < fBusPatches.GetSize(); ++i) {
362 AliMpBusPatch* busPatch = (AliMpBusPatch*)fBusPatches.GetObject(i);
363 Bool_t newResult = busPatch->SetNofManusPerModule();
364 result = result && newResult;
365
366 if (AliDebugLevel() == 3) {
367 // print out for checking
368 printf("\nbus patch %d\n", busPatch->GetId());
369 for (Int_t i = 0; i < busPatch->GetNofPatchModules(); ++i)
370 printf("manu per %dth pcb %d\n", i, busPatch->GetNofManusPerModule(i));
371 }
372 }
373
374 return result;
375}
376
377
f0c62051 378//
379// public methods
380//
381
382
383//______________________________________________________________________________
384AliMpDDL* AliMpDDLStore::GetDDL(Int_t ddlId, Bool_t warn) const
385{
386/// Return DDL for given ddlId
387
388 AliMpDDL* ddl
389 = (AliMpDDL*)fDDLs.At(ddlId);
390
391 if ( ! ddl && warn ) {
392 AliErrorStream()
393 << "DDL with Id = " << ddlId << " not defined." << endl;
394 }
395
396 return ddl;
397}
398
399//______________________________________________________________________________
400AliMpDetElement* AliMpDDLStore::GetDetElement(Int_t detElemId, Bool_t warn) const
401{
402/// Return detection element with given detElemId
403
404 return fDetElements->GetDetElement(detElemId, warn);
405}
406
407//______________________________________________________________________________
408AliMpBusPatch* AliMpDDLStore::GetBusPatch(Int_t busPatchId, Bool_t warn) const
409{
410/// Return bus patch with given Id
411
412 AliMpBusPatch* busPatch
413 = (AliMpBusPatch*) fBusPatches.GetValue(busPatchId);
414
415 if ( ! busPatch && warn ) {
416 AliErrorStream()
417 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
418 }
419
420 return busPatch;
421}
422
423//______________________________________________________________________________
424Int_t AliMpDDLStore::GetDEfromBus(Int_t busPatchId) const
425{
426/// Return detection element Id for given busPatchId
427
428 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
429
430 if ( ! busPatch ) {
431 AliErrorStream()
432 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
433 return 0;
434 }
435
436 return busPatch->GetDEId();
437}
438
439//______________________________________________________________________________
440Int_t AliMpDDLStore::GetDDLfromBus(Int_t busPatchId) const
441{
442/// Return DDL Id for given busPatchId
443
444 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
445
446 if ( ! busPatch ) {
447 AliErrorStream()
448 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
449 return 0;
450 }
451
452 return busPatch->GetDdlId();
453}
454
42d368d0 455//______________________________________________________________________________
456Int_t AliMpDDLStore::GetBusPatchId(Int_t detElemId, Int_t manuId) const
457{
458/// Return bus patch for a given manuId
459
460 AliMpDetElement* detElement = GetDetElement(detElemId);
461 Int_t pos = GetBusPatchIndex(detElemId, manuId);
462
463 if ( pos > detElement->GetNofBusPatches() ) {
464 AliErrorStream()
465 << "Pos = " << pos
466 << " greater than the size = " << detElement->GetNofBusPatches()
467 << " for detElemId = " << detElemId
468 << " manuId = " << manuId << endl;
469 return -1;
470 }
471
472 return detElement->GetBusPatchId(pos);
473}
474
f0c62051 475//______________________________________________________________________________
476AliMpIntPair AliMpDDLStore::GetDetElemIdManu(Int_t manuSerial) const
477{
478/// Return the detElemId and manuId for given serial manu number
479
480 return fDetElements->GetDetElemIdManu(manuSerial);
481}
92faf71f 482
483//______________________________________________________________________________
484void AliMpDDLStore::PrintAllManu() const
485{
486/// Print all manu Ids and their serial numbers sorted by detection element
487/// and bus patch. \n
488/// As serial manu numbers are filled in a different way than manu Ids this
489/// printing allows to check that both ways are consistent
490
491 // Loop over DE
492 AliMpDEIterator it;
493 for ( it.First(); ! it.IsDone(); it.Next() ) {
494 AliMpDetElement* de = it.CurrentDE();
495 cout << "DE: " << de->GetId() << endl;
496
497 // Loop over bus patches in this DE
498 for ( Int_t i=0; i< de->GetNofBusPatches(); ++i ) {
499
500 AliMpBusPatch* busPatch = GetBusPatch(de->GetBusPatchId(i));
501 cout << " busPatch: " << busPatch->GetId() << endl;
502
503 cout << " Manu : ";
504 for ( Int_t j=0; j<busPatch->GetNofManus(); ++j ) {
505 cout << std::setw(6) << busPatch->GetManuId(j) << " ";
506 }
507 cout << endl;
508
509 cout << " Manu serial: ";
510 for ( Int_t k=0; k<busPatch->GetNofManus(); ++k ) {
511 cout << std::setw(6) << de->GetManuSerialFromId(busPatch->GetManuId(k)) << " ";
512 }
513 cout << endl;
514 }
515 }
516}
517
518