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