]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpDDLStore.cxx
Fixing part of the Coding violation
[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 *
354e70ca 12 * about the suitability of this software for any purpose. It is *
f0c62051 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
3d1463c8 19
20//-----------------------------------------------------------------------------
f0c62051 21// Class AliMpDDLStore
22// --------------------
23// The top container class for DDLs, det elements and bus patched
24// It provides acces to DDL, det element and bus patches objects
25// via various characteristics.
26// Authors: Ivana Hrivnacova, IPN Orsay
27// Christian Finck, SUBATECH Nantes
3d1463c8 28//-----------------------------------------------------------------------------
61c370dd 29
f0c62051 30#include "AliMpDDLStore.h"
61c370dd 31#include "AliMpConstants.h"
f0c62051 32#include "AliMpDEStore.h"
33#include "AliMpDDL.h"
34#include "AliMpFiles.h"
35#include "AliMpHelper.h"
36#include "AliMpDEManager.h"
37#include "AliMpDetElement.h"
38#include "AliMpBusPatch.h"
61c370dd 39#include "AliMpTriggerCrate.h"
40#include "AliMpLocalBoard.h"
42d368d0 41#include "AliMpSegmentation.h"
42#include "AliMpVSegmentation.h"
354e70ca 43#include "AliMpStringObjMap.h"
472027a9 44
f0c62051 45#include "AliLog.h"
46
47#include <Riostream.h>
42d368d0 48#include <TList.h>
61c370dd 49#include <TObjArray.h>
50#include <TString.h>
51#include <TObjString.h>
5f377a9a 52#include <TClass.h>
f0c62051 53
54/// \cond CLASSIMP
55ClassImp(AliMpDDLStore)
56/// \endcond
57
58AliMpDDLStore* AliMpDDLStore::fgInstance = 0;
59const Int_t AliMpDDLStore::fgkNofDDLs = 20;
61c370dd 60const Int_t AliMpDDLStore::fgkNofTriggerDDLs = 2;
ae649dcb 61const TString AliMpDDLStore::fgkRevertKeyword = "REVERT";
62const TString AliMpDDLStore::fgkExplicitKeyword = "EXPLICIT";
f0c62051 63
64//
65// static methods
66//
67
68//______________________________________________________________________________
40c8e44b 69AliMpDDLStore* AliMpDDLStore::Instance(Bool_t warn)
f0c62051 70{
40c8e44b 71 /// Create the DDL store if it does not yet exist
72 /// and return its instance
f0c62051 73
40c8e44b 74 if ( ! fgInstance && warn ) {
75 AliWarningClass("DDL Store has not been loaded");
76 }
77
78 return fgInstance;
79}
5f377a9a 80
81//______________________________________________________________________________
40c8e44b 82AliMpDDLStore* AliMpDDLStore::ReadData(Bool_t warn)
5f377a9a 83{
40c8e44b 84 /// Load the DDL store from ASCII data files
85 /// and return its instance
5f377a9a 86
40c8e44b 87 if ( fgInstance ) {
88 if ( warn )
89 AliWarningClass("DDL Store has been already loaded");
90 return fgInstance;
91 }
5f377a9a 92
40c8e44b 93 AliInfoClass("Reading DDL Store from ASCII files.");
94
95 fgInstance = new AliMpDDLStore();
96 return fgInstance;
97}
f0c62051 98
99//
100// ctors, dtor
101//
102
103//______________________________________________________________________________
104AliMpDDLStore::AliMpDDLStore()
40c8e44b 105 : TObject(),
106 fDDLs(fgkNofDDLs+fgkNofTriggerDDLs), // FIXEME
107 fBusPatches(true),
40c8e44b 108 fManuList12(),
109 fManuBridge2(),
efb566fd 110 fGlobalCrate(),
111 fRegionalTrigger()
40c8e44b 112{
113 /// Standard constructor
114
115 AliDebug(1,"");
116 fDDLs.SetOwner(true);
117 fBusPatches.SetOwner(true);
118 fBusPatches.SetSize(900);
119
40c8e44b 120 // Load segmentation & DE store data
121 if ( ! AliMpSegmentation::Instance(false) )
122 AliMpSegmentation::ReadData(true);
123
124 // Create all detection elements
125 ReadDDLs();
efb566fd 126 ReadTrigger();
127 SetTriggerDDLs();
40c8e44b 128 SetManus();
ae649dcb 129 ReadBusPatchSpecial();
40c8e44b 130 SetPatchModules();
131 SetBusPatchLength();
f0c62051 132}
133
134//______________________________________________________________________________
efb566fd 135AliMpDDLStore::AliMpDDLStore(TRootIOCtor* ioCtor)
40c8e44b 136 : TObject(),
137 fDDLs(),
138 fBusPatches(),
efb566fd 139 fGlobalCrate(ioCtor),
140 fRegionalTrigger(ioCtor)
40c8e44b 141{
efb566fd 142 /// Constructor for I0
f0c62051 143
40c8e44b 144 AliDebug(1,"");
f0c62051 145
40c8e44b 146 fgInstance = this;
f0c62051 147}
148
149
150//______________________________________________________________________________
40c8e44b 151AliMpDDLStore::~AliMpDDLStore()
f0c62051 152{
40c8e44b 153 /// Destructor
f0c62051 154
40c8e44b 155 AliDebug(1,"");
f0c62051 156
40c8e44b 157 // DDL objects are deleted with fDDLs
158 // Bus patches objects are deleted with fBusPatches
159
160 fgInstance = 0;
f0c62051 161}
162
163//
164// private methods
165//
166
42d368d0 167//______________________________________________________________________________
40c8e44b 168Int_t AliMpDDLStore::GetManuListIndex(Int_t detElemId) const
42d368d0 169{
40c8e44b 170 /// Return the index of the manu list for given detElemId
171
172 return AliMpDEManager::GetChamberId(detElemId)*4 + (detElemId % 100);
173}
42d368d0 174
42d368d0 175
176//______________________________________________________________________________
40c8e44b 177Int_t AliMpDDLStore::GetBusPatchIndex(Int_t detElemId, Int_t manuId) const
42d368d0 178{
40c8e44b 179 /// Calculate the index of the buspatch from manuId
42d368d0 180
181 Int_t pos = 0;
182 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
183 static Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane) - 1;
184
185 if( stationType == AliMp::kStation345) {
40c8e44b 186 pos = (manuId & manuMask)/100;
42d368d0 187 } else {
40c8e44b 188 Int_t idx = GetManuListIndex(detElemId);
42d368d0 189
40c8e44b 190 // using array defined from DetElemIdToBusPatch.dat file
191 for (pos = fManuList12[idx].GetSize()-1; pos >= 0; --pos)
192 if ( manuId >= fManuList12[idx].At(pos))
193 break;
42d368d0 194 }
195
196 return pos;
197}
198
61c370dd 199//______________________________________________________________________________
40c8e44b 200Bool_t AliMpDDLStore::ReadDDLs()
61c370dd 201{
40c8e44b 202 /// Read ddl <-> bus patch file
354e70ca 203
40c8e44b 204 TString infile = AliMpFiles::BusPatchFilePath();
61c370dd 205
61c370dd 206 ifstream in(infile, ios::in);
61c370dd 207 if (!in) {
40c8e44b 208 AliErrorStream() << "Data file " << infile << " not found.";
209 return false;
61c370dd 210 }
61c370dd 211
212 char line[255];
61c370dd 213
40c8e44b 214 while ( in.getline(line,255) ) {
61c370dd 215
40c8e44b 216 if ( line[0] == '#' )
217 continue;
61c370dd 218
40c8e44b 219 TString tmp(AliMpHelper::Normalize(line));
61c370dd 220
40c8e44b 221 TObjArray* stringList = tmp.Tokenize(TString(" "));
354e70ca 222
40c8e44b 223 TString sDE = ((TObjString*)stringList->At(0))->GetString();
224 Int_t idDE = atoi(sDE.Data());
354e70ca 225
40c8e44b 226 if ( ! AliMpDEManager::IsValidDetElemId(idDE, false) ) {
227 AliErrorStream() << "DetElemId "<< idDE << " not valid." << endl;
228 return false;
229 }
354e70ca 230
40c8e44b 231 TString busPatch = ((TObjString*)stringList->At(1))->GetString();
354e70ca 232
233
40c8e44b 234 TString sDDL = ((TObjString*)stringList->At(2))->GetString();
235 Int_t iDDL = atoi(sDDL.Data());
61c370dd 236
40c8e44b 237 if ( iDDL < 0 || iDDL >= fgkNofDDLs ) {
238 AliErrorStream() << "DDL id "<< iDDL << " outside limits." << endl;
239 return false;
240 }
61c370dd 241
40c8e44b 242 AliDebugStream(3)
243 << "idDE " << idDE << " buspatch " << busPatch.Data() << " iDDL " << iDDL
244 << endl;
61c370dd 245
40c8e44b 246 // reading 1st manu Id for each bus patch (station 1 & 2)
247 if(AliMpDEManager::GetStationType(idDE) != AliMp::kStation345) {
61c370dd 248
40c8e44b 249 TString sManu = ((TObjString*)stringList->At(3))->GetString();
250 AliMpHelper::DecodeName(sManu,',',fManuList12[GetManuListIndex(idDE)]);
61c370dd 251
40c8e44b 252 if(AliMpDEManager::GetStationType(idDE) == AliMp::kStation2) {
253 TString sManuBridge = ((TObjString*)stringList->At(4))->GetString();
254 AliMpHelper::DecodeName(sManuBridge,',',fManuBridge2[GetManuListIndex(idDE)]);
255 }
61c370dd 256
40c8e44b 257 }
61c370dd 258
40c8e44b 259 delete stringList;
61c370dd 260
40c8e44b 261 AliMpDDL* ddl = GetDDL(iDDL, false);
262 if ( !ddl) {
263 ddl = new AliMpDDL(iDDL);
264 fDDLs.AddAt(ddl, iDDL);
265 }
266 ddl->AddDE(idDE);
267
268 TArrayI busPatchList;
269 // decoding range of buspatch
270 AliMpHelper::DecodeName(busPatch,';',busPatchList);
271
272 // Update DE
273 AliMpDetElement* de = AliMpDEManager::GetDetElement(idDE);
274 de->SetDdlId(iDDL);
275 // filling buspatch -> idDE
276 for (Int_t i = 0; i < busPatchList.GetSize(); i++) {
277 fBusPatches.Add(busPatchList[i],
278 new AliMpBusPatch(busPatchList[i], idDE, iDDL));
279 de->AddBusPatch(busPatchList[i]);
280 }
281 }
282
283 // Fill bus patch Ids array in DDLs now
284 for ( Int_t i=0; i<fDDLs.GetEntriesFast(); i++ ) {
285 AliMpDDL* ddl = (AliMpDDL*) fDDLs.At(i);
286 ddl->FillBusPatchIds();
61c370dd 287 }
40c8e44b 288
289 in.close();
290 return true;
291}
efb566fd 292
40c8e44b 293//______________________________________________________________________________
efb566fd 294Bool_t AliMpDDLStore::ReadTrigger()
40c8e44b 295{
296 /// create trigger DDL object and Global crate object
297
efb566fd 298 if ( ! fGlobalCrate.ReadData() ) return false;
40c8e44b 299
efb566fd 300 if ( ! fRegionalTrigger.ReadData() ) return false;
301
40c8e44b 302 return true;
303}
304
305//______________________________________________________________________________
efb566fd 306Bool_t AliMpDDLStore::SetTriggerDDLs()
40c8e44b 307{
efb566fd 308/// Create trigger DDLs and set DDL Ids in the regional trigger
309
40c8e44b 310
efb566fd 311 Int_t iDDL = -1;
354e70ca 312
efb566fd 313 for ( Int_t i=0; i<fRegionalTrigger.GetNofTriggerCrates(); ++i ) {
314
315 AliMpTriggerCrate* crate = fRegionalTrigger.GetTriggerCrateFast(i);
354e70ca 316
efb566fd 317 TString crateName = crate->GetName();
61c370dd 318
efb566fd 319 // determine ddl number vs crate side
320 if (crateName.Contains("R"))
321 iDDL = fgkNofDDLs; // starts where tracker ends
322 else
323 iDDL = fgkNofDDLs + 1;
324
325 // Create DDL if it does not yet exist and set it to the crate
326 AliMpDDL* ddl = (AliMpDDL*)fDDLs.At(iDDL);
327 if ( !ddl) {
efb566fd 328 ddl = new AliMpDDL(iDDL);
329 fDDLs.AddAt(ddl, iDDL);
330 }
331 crate->SetDdlId(iDDL);
40c8e44b 332
472027a9 333
efb566fd 334 // Add trigger crate number for given ddl if not present
335 if ( !ddl->HasTriggerCrateId(crate->GetId()) )
336 ddl->AddTriggerCrate(crate->GetId());
472027a9 337
472027a9 338
efb566fd 339 // Loop over local boards in this crate
340
341 for ( Int_t j=0; j<crate->GetNofLocalBoards(); ++j )
342 {
343 Int_t localBoardId = crate->GetLocalBoardId(j);
344 AliMpLocalBoard* localBoard
345 = fRegionalTrigger.FindLocalBoard(localBoardId);
346 if (!localBoard ) {
347 AliFatalClass("Cannot find local board.");
348 return kFALSE;
349 }
350
351 // Loop over DEs in this localBoard
352
353 for ( Int_t k=0; k<localBoard->GetNofDEs(); ++k )
354 {
472027a9 355
efb566fd 356 Int_t deId = localBoard->GetDEId(k);
357 AliMpDetElement* de = AliMpDEManager::GetDetElement(deId);
358
359 if ( de->GetDdlId() == -1 ) de->SetDdlId(iDDL);
360
361 if ( ! ddl->HasDEId(deId) ) ddl->AddDE(deId);
362 }
40c8e44b 363 }
efb566fd 364 }
365 return kTRUE;
61c370dd 366}
367
42d368d0 368//______________________________________________________________________________
40c8e44b 369Bool_t AliMpDDLStore::SetManus() {
370 /// Set manus for each bus patch
42d368d0 371
372 Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane) - 1;
373
40c8e44b 374 // loop over DDL
42d368d0 375 for (Int_t iDDL = 0; iDDL < fgkNofDDLs; ++iDDL) {
376
40c8e44b 377 AliDebug(3, Form("DDL # %d\n", iDDL));
42d368d0 378
40c8e44b 379 AliMpDDL* ddl = GetDDL(iDDL);
42d368d0 380
40c8e44b 381 // loop over DE in the given DDL
382 for (Int_t detElemIdx = 0; detElemIdx < ddl->GetNofDEs(); ++detElemIdx) {
42d368d0 383
40c8e44b 384 Int_t detElemId = ddl->GetDEId(detElemIdx);
42d368d0 385
40c8e44b 386 AliMpDetElement* detElement = GetDetElement(detElemId);
42d368d0 387
40c8e44b 388 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
42d368d0 389
390
40c8e44b 391 // list of manu per DE on both cathode
392 TList manuList;
393 for ( Int_t cath = 0; cath < 2 ; ++cath ) {
394 const AliMpVSegmentation* seg
395 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(cath));
42d368d0 396
40c8e44b 397 AliMp::PlaneType planeType = detElement->GetPlaneType(AliMp::GetCathodType(cath));
42d368d0 398
40c8e44b 399 TArrayI manus;
400 seg->GetAllElectronicCardIDs(manus);
42d368d0 401
40c8e44b 402 // filling TList manu
403 for ( Int_t im = 0; im < manus.GetSize(); ++im ) {
42d368d0 404
40c8e44b 405 AliMpIntPair* manu = 0x0;
406 if( stationType == AliMp::kStation345)
407 manu = new AliMpIntPair((manus[im] & manuMask), planeType, kTRUE); //remove offset for NB
408 else
409 manu = new AliMpIntPair(manus[im], planeType, kTRUE); //keep offset for NB
42d368d0 410
40c8e44b 411 manuList.Add(manu);
42d368d0 412
40c8e44b 413 detElement->AddManu(manus[im]);
414 }
415 }// cathode
416
417 manuList.Sort(); // sort regardless B or NB plane
42d368d0 418
40c8e44b 419 // filling manu to the corresponding buspatch
420 for (Int_t iEntry = 0; iEntry < manuList.GetEntries(); ++iEntry) {
42d368d0 421
40c8e44b 422 AliMpIntPair* manuPtr = (AliMpIntPair*)manuList.At(iEntry);
42d368d0 423
40c8e44b 424 Int_t manuId = manuPtr->GetFirst();
425 Int_t pos = GetBusPatchIndex(detElemId, manuId);
42d368d0 426
40c8e44b 427 if (pos > detElement->GetNofBusPatches()) {
428 AliError(Form("pos greater %d than size %d manuId %d detElemId %d \n",
429 pos, detElement->GetNofBusPatches(), manuId, detElemId));
430 return false;
431 }
432
433 // get buspatch and fill manus
434 Int_t busPatchId = detElement->GetBusPatchId(pos);
435 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
436
437 if( stationType == AliMp::kStation345) {
438
439 if (manuPtr->GetSecond())
440 busPatch->AddManu(manuId+manuMask+1); // add offset again after sorted
441 else
442 busPatch->AddManu(manuId);
443
444 } else {
445
446 busPatch->AddManu(manuId);
447
448 }
449 }
450
451 manuList.Delete();
452
453 if (AliDebugLevel() == 3) {
454
455 // print out for checking
456 for(Int_t pos = 0; pos < detElement->GetNofBusPatches(); ++pos) {
457 Int_t busPatchId = detElement->GetBusPatchId(pos);
458 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
459 printf("BusPatch: %d\n", busPatch->GetId());
460 for (Int_t iEntry = 0; iEntry < busPatch->GetNofManus(); ++iEntry)
461 printf("manu Id: %d\n", busPatch->GetManuId(iEntry));
462 }
463 }
464
465 } // detection element loop
42d368d0 466 }// DDL loop
467
468 return true;
469}
f0c62051 470
ae649dcb 471//______________________________________________________________________________
472Bool_t AliMpDDLStore::ReadBusPatchSpecial()
473{
474/// Read file with bus patches with a special order of manus
475/// and reset the manus arrays filled via SetManu function
476
477 TString infile = AliMpFiles::BusPatchSpecialFilePath();
478
479 ifstream in(infile, ios::in);
480 if (!in) {
481 AliErrorStream() << "Data file " << infile << " not found.";
482 return false;
483 }
484
485 char line[255];
486
487 while ( in.getline(line,255) ) {
488
489 if ( line[0] == '#' ) continue;
490
491 TString tmp(AliMpHelper::Normalize(line));
492 TObjArray* stringList = tmp.Tokenize(TString(" "));
493
494 TString sKey = ((TObjString*)stringList->At(0))->GetString();
495
496 TString sDDL = ((TObjString*)stringList->At(1))->GetString();
497 TArrayI ddlList;
498 AliMpHelper::DecodeName(sDDL,';',ddlList);
499
500 TString sBusPatch = ((TObjString*)stringList->At(2))->GetString();
501 TArrayI busPatchList;
502 AliMpHelper::DecodeName(sBusPatch,',',busPatchList);
503
504 // Loop over DDL and Bus Patch
505 for (Int_t iDDL = 0; iDDL < ddlList.GetSize(); ++iDDL ) {
506 for (Int_t iBusPatch = 0; iBusPatch < busPatchList.GetSize(); ++iBusPatch) {
507 // Global bus patch ID
508 Int_t busPatchID
509 = AliMpBusPatch::GetGlobalBusID(
510 busPatchList.At(iBusPatch), ddlList.At(iDDL));
511
512 // Get this bus patch
513 AliMpBusPatch* busPatch = GetBusPatch(busPatchID);
514 if ( ! busPatch ) {
515 AliErrorStream() << "Bus patch " << busPatchID << " does not exist." << endl;
516 return kFALSE;
517 }
518
519 if ( sKey == fgkRevertKeyword ) {
520 AliDebugStream(3)
521 << "Reverting readout of bus patch " << busPatchID << endl;
522
523 // Now revert the manus in this bus patch
524 busPatch->RevertReadout();
525 }
526 else if ( sKey == fgkExplicitKeyword ) {
527
528 busPatch->ResetReadout();
529
530 TString sManus = ((TObjString*)stringList->At(3))->GetString();
531 TArrayI manuList;
532 AliMpHelper::DecodeName(sManus,',',manuList);
533
534 AliDebugStream(3)
535 << "Reseting readout of bus patch " << busPatchID
536 << " manus: " << sManus.Data() << endl;
537
538 for (Int_t i = 0; i < manuList.GetSize(); i++) {
539 busPatch->AddManu(manuList.At(i));
540 }
541 }
542 else {
543 AliErrorStream() << "Unrecognized key." << endl;
544 return kFALSE;
545 }
546 }
547 }
548 }
549
550 return kTRUE;
551}
552
553
dbc1e34c 554//______________________________________________________________________________
40c8e44b 555Bool_t AliMpDDLStore::SetPatchModules() {
556 /// Compute the number of manu per PCB for each buspatch
dbc1e34c 557
0f30c458 558 AliMpDEIterator it;
559 Bool_t result = true;
dbc1e34c 560
0f30c458 561 for ( it.First(); !it.IsDone(); it.Next() ) {
dbc1e34c 562
40c8e44b 563 AliMpDetElement* detElement = it.CurrentDE();
564
565 for (Int_t i = 0; i < detElement->GetNofBusPatches(); ++i) {
566 AliMpBusPatch* busPatch = GetBusPatch(detElement->GetBusPatchId(i));
567 Bool_t newResult = false;
568 Int_t idDE = busPatch->GetDEId();
569
570 if (AliMpDEManager::GetStationType(idDE) == AliMp::kStation2 )
571 newResult = busPatch->SetNofManusPerModule(fManuBridge2[GetManuListIndex(idDE)].At(i));
572 else
573 newResult = busPatch->SetNofManusPerModule();
574 }
0f30c458 575 }
576
577 return result;
578}
579
580//______________________________________________________________________________
40c8e44b 581Bool_t AliMpDDLStore::SetBusPatchLength() {
582 /// read the buspatch length file and set buspatch length
0f30c458 583
584 TString infile = AliMpFiles::BusPatchLengthFilePath();
585 ifstream in(infile, ios::in);
586 if (!in) {
40c8e44b 587 AliErrorStream() << "Data file " << infile << " not found.";
588 return false;
589 }
0f30c458 590 char line[255];
591
592 for (Int_t iDDL = 0; iDDL < fgkNofDDLs; ++iDDL ) {
40c8e44b 593 AliMpDDL* ddl = GetDDL(iDDL);
0f30c458 594
40c8e44b 595 for (Int_t iBusPatch = 0; iBusPatch < ddl->GetNofBusPatches(); ++iBusPatch) {
0f30c458 596
40c8e44b 597 do {
598 if (!in.getline(line,255)) {
599 AliWarning(Form("Wrong size in bus patch length file; index %d DDL %d",
600 iBusPatch, iDDL));
601 return false;
602 }
603 } while(line[0] == '#');
d9fc467c 604
40c8e44b 605 TString tmp(AliMpHelper::Normalize(line));
d9fc467c 606
40c8e44b 607 TObjArray* stringList = tmp.Tokenize(TString(" "));
d9fc467c 608
40c8e44b 609 TString sLocalBusId = ((TObjString*)stringList->At(0))->GetString();
610 Int_t localBusId = sLocalBusId.Atoi();
d9fc467c 611
40c8e44b 612 TString sLength = ((TObjString*)stringList->At(1))->GetString();
613 Float_t length = sLength.Atof();
0f30c458 614
40c8e44b 615 delete stringList;
616
617 if (localBusId != iBusPatch + 1)
618 AliWarning(Form("Wrong local buspatch id %d instead of %d", iBusPatch+1, localBusId));
619
620 Int_t busPatchId = ddl->GetBusPatchId(iBusPatch);
621 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
622 busPatch->SetCableLength(length);
623 }
0f30c458 624 }
625
626 return true;
dbc1e34c 627}
628
0f30c458 629
61c370dd 630//________________________________________________________________
40c8e44b 631Int_t AliMpDDLStore::GetLocalBoardId(TString name) const {
632 /// return the first board with a given side and line
61c370dd 633
efb566fd 634
635 TExMapIter i = fRegionalTrigger.GetLocalBoardItr();
61c370dd 636 Long_t key, value;
637 while ( i.Next(key, value) ) {
40c8e44b 638 AliMpLocalBoard* local = (AliMpLocalBoard*)value;
61c370dd 639
40c8e44b 640 TString tmp(&local->GetName()[4], 2);
641 if (name.Contains(tmp))
642 if (name[0] == local->GetName()[0])
643 return local->GetId();
61c370dd 644 }
645
646 return 0;
647
648}
dbc1e34c 649
f0c62051 650//
651// public methods
652//
653
654
655//______________________________________________________________________________
40c8e44b 656AliMpDDL* AliMpDDLStore::GetDDL(Int_t ddlId, Bool_t warn) const {
657 /// Return DDL for given ddlId
f0c62051 658
40c8e44b 659 AliMpDDL* ddl
f0c62051 660 = (AliMpDDL*)fDDLs.At(ddlId);
40c8e44b 661
662 if ( ! ddl && warn ) {
663 AliErrorStream()
f0c62051 664 << "DDL with Id = " << ddlId << " not defined." << endl;
40c8e44b 665 }
f0c62051 666
40c8e44b 667 return ddl;
668}
f0c62051 669
670//______________________________________________________________________________
40c8e44b 671AliMpDetElement* AliMpDDLStore::GetDetElement(Int_t detElemId, Bool_t warn) const {
672 /// Return detection element with given detElemId
f0c62051 673
40c8e44b 674 if ( ! AliMpDEStore::Instance() ) {
675 AliFatal("DE Store has not been loaded.");
676 return 0;
677 }
24f9bd97 678
40c8e44b 679 return AliMpDEStore::Instance()->GetDetElement(detElemId, warn);
680}
f0c62051 681
682//______________________________________________________________________________
40c8e44b 683AliMpBusPatch* AliMpDDLStore::GetBusPatch(Int_t busPatchId, Bool_t warn) const {
684 /// Return bus patch with given Id
f0c62051 685
40c8e44b 686 AliMpBusPatch* busPatch
f0c62051 687 = (AliMpBusPatch*) fBusPatches.GetValue(busPatchId);
40c8e44b 688
689 if ( ! busPatch && warn ) {
690 AliErrorStream()
f0c62051 691 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
40c8e44b 692 }
f0c62051 693
40c8e44b 694 return busPatch;
695}
f0c62051 696
61c370dd 697//______________________________________________________________________________
40c8e44b 698AliMpLocalBoard* AliMpDDLStore::GetLocalBoard(Int_t localBoardId, Bool_t warn) const {
699 /// Return bus patch with given Id
61c370dd 700
efb566fd 701 return fRegionalTrigger.FindLocalBoard(localBoardId, warn);
40c8e44b 702}
61c370dd 703
704//______________________________________________________________________________
efb566fd 705AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(TString name, Bool_t warn) const {
40c8e44b 706 /// Return trigger crate with given name
61c370dd 707
efb566fd 708 return fRegionalTrigger.FindTriggerCrate(name, warn);
40c8e44b 709}
61c370dd 710
711//______________________________________________________________________________
efb566fd 712AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(Int_t ddlId, Int_t index, Bool_t warn) const {
40c8e44b 713 /// Return trigger crate with given ddl and index crate
61c370dd 714
40c8e44b 715 if (ddlId == 0 || ddlId == 1)
716 ddlId += fgkNofDDLs;
fbd38b34 717
40c8e44b 718 AliMpDDL* ddl = GetDDL(ddlId, warn);
719 if ( ! ddl )
720 return 0;
721
722 if ( index >= ddl->GetNofTriggerCrates() ) {
723 AliError(Form("crate id %d greater than array[%d]", index, ddl->GetNofTriggerCrates()));
724 return 0;
725 }
726
727 TString name = AliMpTriggerCrate::GenerateName(index, ddlId, fgkNofDDLs);
728
729 return GetTriggerCrate(name, warn);
730}
61c370dd 731
f0c62051 732//______________________________________________________________________________
40c8e44b 733Int_t AliMpDDLStore::GetDEfromBus(Int_t busPatchId) const {
734 /// Return detection element Id for given busPatchId
f0c62051 735
40c8e44b 736 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
737
738 if ( ! busPatch ) {
739 AliErrorStream()
f0c62051 740 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
40c8e44b 741 return 0;
742 }
f0c62051 743
40c8e44b 744 return busPatch->GetDEId();
745}
f0c62051 746
61c370dd 747//______________________________________________________________________________
40c8e44b 748Int_t AliMpDDLStore::GetDEfromLocalBoard(Int_t localBoardId, Int_t chamberId) const {
749 /// Return detElemId for local board Id and chamber id.
61c370dd 750
40c8e44b 751 AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId);
752
753 if ( ! localBoard ) {
754 AliErrorStream()
61c370dd 755 << "Loacl board with Id = " << localBoardId << " not defined." << endl;
40c8e44b 756 return 0;
757 }
61c370dd 758
40c8e44b 759 return localBoard->GetDEIdByChamber(chamberId);
61c370dd 760}
761
f0c62051 762//______________________________________________________________________________
40c8e44b 763Int_t AliMpDDLStore::GetDDLfromBus(Int_t busPatchId) const {
764 /// Return DDL Id for given busPatchId
f0c62051 765
40c8e44b 766 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
767
768 if ( ! busPatch ) {
769 AliErrorStream()
f0c62051 770 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
40c8e44b 771 return 0;
772 }
f0c62051 773
40c8e44b 774 return busPatch->GetDdlId();
775}
f0c62051 776
42d368d0 777//______________________________________________________________________________
40c8e44b 778Int_t AliMpDDLStore::GetBusPatchId(Int_t detElemId, Int_t manuId) const {
779 /// Return bus patch for a given manuId
780
781 AliMpDetElement* detElement = GetDetElement(detElemId);
782 Int_t pos = GetBusPatchIndex(detElemId, manuId);
783
784 if ( pos > detElement->GetNofBusPatches() ) {
785 AliErrorStream()
786 << "Pos = " << pos
787 << " greater than the size = " << detElement->GetNofBusPatches()
788 << " for detElemId = " << detElemId
789 << " manuId = " << manuId << endl;
790 return -1;
791 }
42d368d0 792
40c8e44b 793 return detElement->GetBusPatchId(pos);
794}
42d368d0 795
f0c62051 796//______________________________________________________________________________
40c8e44b 797AliMpIntPair AliMpDDLStore::GetDetElemIdManu(Int_t manuSerial) const {
798 /// Return the detElemId and manuId for given serial manu number
f0c62051 799
40c8e44b 800 if ( ! AliMpDEStore::Instance() ) {
801 AliFatal("DE Store has not been loaded.");
802 return AliMpIntPair::Invalid();
803 }
24f9bd97 804
40c8e44b 805 return AliMpDEStore::Instance()->GetDetElemIdManu(manuSerial);
806}
92faf71f 807
808//______________________________________________________________________________
40c8e44b 809void AliMpDDLStore::PrintAllManu() const {
810 /// Print all manu Ids and their serial numbers sorted by detection element
811 /// and bus patch. \n
812 /// As serial manu numbers are filled in a different way than manu Ids this
813 /// printing allows to check that both ways are consistent
814
815 // Loop over DE
816 AliMpDEIterator it;
817 for ( it.First(); ! it.IsDone(); it.Next() ) {
818 AliMpDetElement* de = it.CurrentDE();
819 cout << "DE: " << de->GetId() << endl;
820
821 // Loop over bus patches in this DE
822 for ( Int_t i=0; i< de->GetNofBusPatches(); ++i ) {
823
824 AliMpBusPatch* busPatch = GetBusPatch(de->GetBusPatchId(i));
825 cout << " busPatch: " << busPatch->GetId() << endl;
826
827 cout << " Manu : ";
828 for ( Int_t j=0; j<busPatch->GetNofManus(); ++j ) {
829 cout << std::setw(6) << busPatch->GetManuId(j) << " ";
830 }
831 cout << endl;
832
833 cout << " Manu serial: ";
834 for ( Int_t k=0; k<busPatch->GetNofManus(); ++k ) {
835 cout << std::setw(6) << de->GetManuSerialFromId(busPatch->GetManuId(k)) << " ";
836 }
837 cout << endl;
838 }
839 }
840}
92faf71f 841
efb566fd 842//______________________________________________________________________________
40c8e44b 843Int_t AliMpDDLStore::GetNextDEfromLocalBoard(Int_t localBoardId, Int_t chamberId ) const {
844 /// return the next detection element in line
61c370dd 845
846 AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId);
847
848 TString name(localBoard->GetName());
849
850 Int_t line = localBoard->GetPosition().GetFirst();
851 ++line;
40c8e44b 852
61c370dd 853 name.Replace(4,1,Form("%d", line));
854
40c8e44b 855 Int_t nextLocalId;
61c370dd 856 if ((nextLocalId = GetLocalBoardId(name)))
40c8e44b 857 return GetDEfromLocalBoard(nextLocalId, chamberId);
61c370dd 858 else
40c8e44b 859 return 0;
61c370dd 860
861 return 0;
862}
863
efb566fd 864//______________________________________________________________________________
40c8e44b 865Int_t AliMpDDLStore::GetPreviousDEfromLocalBoard(Int_t localBoardId, Int_t chamberId) const {
866 /// return the previous detection element in line
61c370dd 867
868 AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId);
869
870 TString name(localBoard->GetName());
871
872 Int_t line = localBoard->GetPosition().GetFirst();
873 --line;
40c8e44b 874
61c370dd 875 name.Replace(4,1,Form("%d", line));
876
877 Int_t prevLocalId;
878 if ((prevLocalId = GetLocalBoardId(name)))
40c8e44b 879 return GetDEfromLocalBoard(prevLocalId, chamberId);
61c370dd 880 else
40c8e44b 881 return 0;
61c370dd 882
883}
efb566fd 884
885//______________________________________________________________________________
886void AliMpDDLStore::SetRegionalTrigger(const AliMpRegionalTrigger& regionalTrigger)
887{
888/// Replace the existing regional trigger with the given one
889
890 fRegionalTrigger = regionalTrigger;
891
892 // Remove the existing trigger DDLs
893 fDDLs.RemoveAt(fgkNofDDLs+1);
894 fDDLs.RemoveAt(fgkNofDDLs);
895
896 // Set new trigger DDLs from new regional trigger
897 SetTriggerDDLs();
898}