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