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