]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpDDLStore.cxx
Fix for the problem during PbPb run of Nov 2010 (Indra)
[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,
d2d10ee1 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
d2d10ee1 101 if ( dataStreams.GetReadFromFiles() )
102 AliInfoClass("Reading DDL Store from ASCII files.");
40c8e44b 103
d2d10ee1 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 }
a49f20a7 548 delete stringList;
ae649dcb 549 }
550
228fd720 551 delete &in;
552
ae649dcb 553 return kTRUE;
554}
555
556
dbc1e34c 557//______________________________________________________________________________
59754717 558Bool_t AliMpDDLStore::SetPatchModules()
559{
40c8e44b 560 /// Compute the number of manu per PCB for each buspatch
dbc1e34c 561
0f30c458 562 AliMpDEIterator it;
563 Bool_t result = true;
dbc1e34c 564
0f30c458 565 for ( it.First(); !it.IsDone(); it.Next() ) {
dbc1e34c 566
40c8e44b 567 AliMpDetElement* detElement = it.CurrentDE();
568
569 for (Int_t i = 0; i < detElement->GetNofBusPatches(); ++i) {
570 AliMpBusPatch* busPatch = GetBusPatch(detElement->GetBusPatchId(i));
571 Bool_t newResult = false;
572 Int_t idDE = busPatch->GetDEId();
573
4e51cfd2 574 if (AliMpDEManager::GetStation12Type(idDE) == AliMq::kStation2 )
40c8e44b 575 newResult = busPatch->SetNofManusPerModule(fManuBridge2[GetManuListIndex(idDE)].At(i));
576 else
577 newResult = busPatch->SetNofManusPerModule();
578 }
0f30c458 579 }
580
581 return result;
582}
583
584//______________________________________________________________________________
59754717 585Bool_t AliMpDDLStore::ReadBusPatchInfo()
586{
587 /// read the buspatch info file and set buspatch info
0f30c458 588
228fd720 589 istream& in
7d5d0cc5 590 = fkDataStreams.
ab167304 591 CreateDataStream(AliMpFiles::BusPatchInfoFilePath());
228fd720 592
0f30c458 593 char line[255];
594
595 for (Int_t iDDL = 0; iDDL < fgkNofDDLs; ++iDDL ) {
40c8e44b 596 AliMpDDL* ddl = GetDDL(iDDL);
0f30c458 597
40c8e44b 598 for (Int_t iBusPatch = 0; iBusPatch < ddl->GetNofBusPatches(); ++iBusPatch) {
0f30c458 599
40c8e44b 600 do {
601 if (!in.getline(line,255)) {
602 AliWarning(Form("Wrong size in bus patch length file; index %d DDL %d",
603 iBusPatch, iDDL));
604 return false;
605 }
606 } while(line[0] == '#');
d9fc467c 607
40c8e44b 608 TString tmp(AliMpHelper::Normalize(line));
d9fc467c 609
40c8e44b 610 TObjArray* stringList = tmp.Tokenize(TString(" "));
d9fc467c 611
59754717 612 // Crocus label
613 TString crLabel = ((TObjString*)stringList->At(0))->GetString();
614 Int_t pos = crLabel.First('-');
615 tmp = crLabel(pos-2, crLabel.Length()-pos+2);
616 TArrayI list;
617 AliMpHelper::DecodeName(tmp.Data(), '-', list);
618
619 Int_t localDDLId = list[0];
620 Int_t frtId = list[1] - 1; // begin at zero !
621 Int_t localBusId = list[2];
622
623 // Add FRT number for given ddl if not present
624 if ( !ddl->HasFrtId(frtId) )
625 ddl->AddFrt(frtId);
626
627 // BP & translator label
628 TString label = ((TObjString*)stringList->At(1))->GetString();
629 TString transLabel = ((TObjString*)stringList->At(2))->GetString();
630
631 // BP length
632 TString sLength = ((TObjString*)stringList->At(3))->GetString();
633 Float_t length = sLength.Atof();
0f30c458 634
40c8e44b 635 delete stringList;
59754717 636
40c8e44b 637 if (localBusId != iBusPatch + 1)
59754717 638 AliWarning(Form("Wrong local buspatch id %d instead of %d", iBusPatch+1, localBusId));
639
640 if(localDDLId != ddl->GetId()+1)
641 AliWarning(Form("Wrong local DDL id %d instead of %d", ddl->GetId()+1, localDDLId));
40c8e44b 642
643 Int_t busPatchId = ddl->GetBusPatchId(iBusPatch);
644 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
645 busPatch->SetCableLength(length);
59754717 646 busPatch->SetCableLabel(label);
647 busPatch->SetTranslatorLabel(transLabel);
648 busPatch->SetFrtId(frtId);
649
40c8e44b 650 }
0f30c458 651 }
228fd720 652
653 delete &in;
0f30c458 654
655 return true;
dbc1e34c 656}
657
0f30c458 658
61c370dd 659//________________________________________________________________
40c8e44b 660Int_t AliMpDDLStore::GetLocalBoardId(TString name) const {
661 /// return the first board with a given side and line
61c370dd 662
630711ed 663 TIter next(fRegionalTrigger.CreateLocalBoardIterator());
664 AliMpLocalBoard* local;
665
666 while ( ( local = static_cast<AliMpLocalBoard*>(next()) ) )
667 {
40c8e44b 668 TString tmp(&local->GetName()[4], 2);
669 if (name.Contains(tmp))
670 if (name[0] == local->GetName()[0])
671 return local->GetId();
61c370dd 672 }
673
674 return 0;
61c370dd 675}
dbc1e34c 676
f0c62051 677//
678// public methods
679//
680
681
682//______________________________________________________________________________
40c8e44b 683AliMpDDL* AliMpDDLStore::GetDDL(Int_t ddlId, Bool_t warn) const {
684 /// Return DDL for given ddlId
f0c62051 685
40c8e44b 686 AliMpDDL* ddl
f0c62051 687 = (AliMpDDL*)fDDLs.At(ddlId);
40c8e44b 688
689 if ( ! ddl && warn ) {
690 AliErrorStream()
f0c62051 691 << "DDL with Id = " << ddlId << " not defined." << endl;
40c8e44b 692 }
f0c62051 693
40c8e44b 694 return ddl;
695}
f0c62051 696
697//______________________________________________________________________________
40c8e44b 698AliMpDetElement* AliMpDDLStore::GetDetElement(Int_t detElemId, Bool_t warn) const {
699 /// Return detection element with given detElemId
f0c62051 700
40c8e44b 701 if ( ! AliMpDEStore::Instance() ) {
702 AliFatal("DE Store has not been loaded.");
703 return 0;
704 }
24f9bd97 705
40c8e44b 706 return AliMpDEStore::Instance()->GetDetElement(detElemId, warn);
707}
f0c62051 708
709//______________________________________________________________________________
40c8e44b 710AliMpBusPatch* AliMpDDLStore::GetBusPatch(Int_t busPatchId, Bool_t warn) const {
711 /// Return bus patch with given Id
f0c62051 712
40c8e44b 713 AliMpBusPatch* busPatch
f0c62051 714 = (AliMpBusPatch*) fBusPatches.GetValue(busPatchId);
40c8e44b 715
716 if ( ! busPatch && warn ) {
717 AliErrorStream()
f0c62051 718 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
40c8e44b 719 }
f0c62051 720
40c8e44b 721 return busPatch;
722}
f0c62051 723
59754717 724
61c370dd 725//______________________________________________________________________________
40c8e44b 726AliMpLocalBoard* AliMpDDLStore::GetLocalBoard(Int_t localBoardId, Bool_t warn) const {
727 /// Return bus patch with given Id
61c370dd 728
efb566fd 729 return fRegionalTrigger.FindLocalBoard(localBoardId, warn);
40c8e44b 730}
61c370dd 731
732//______________________________________________________________________________
efb566fd 733AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(TString name, Bool_t warn) const {
40c8e44b 734 /// Return trigger crate with given name
61c370dd 735
efb566fd 736 return fRegionalTrigger.FindTriggerCrate(name, warn);
40c8e44b 737}
61c370dd 738
739//______________________________________________________________________________
efb566fd 740AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(Int_t ddlId, Int_t index, Bool_t warn) const {
40c8e44b 741 /// Return trigger crate with given ddl and index crate
61c370dd 742
40c8e44b 743 if (ddlId == 0 || ddlId == 1)
744 ddlId += fgkNofDDLs;
fbd38b34 745
40c8e44b 746 AliMpDDL* ddl = GetDDL(ddlId, warn);
747 if ( ! ddl )
748 return 0;
749
750 if ( index >= ddl->GetNofTriggerCrates() ) {
751 AliError(Form("crate id %d greater than array[%d]", index, ddl->GetNofTriggerCrates()));
752 return 0;
753 }
754
755 TString name = AliMpTriggerCrate::GenerateName(index, ddlId, fgkNofDDLs);
756
757 return GetTriggerCrate(name, warn);
758}
61c370dd 759
f0c62051 760//______________________________________________________________________________
40c8e44b 761Int_t AliMpDDLStore::GetDEfromBus(Int_t busPatchId) const {
762 /// Return detection element Id for given busPatchId
f0c62051 763
40c8e44b 764 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
765
766 if ( ! busPatch ) {
767 AliErrorStream()
f0c62051 768 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
40c8e44b 769 return 0;
770 }
f0c62051 771
40c8e44b 772 return busPatch->GetDEId();
773}
f0c62051 774
61c370dd 775//______________________________________________________________________________
40c8e44b 776Int_t AliMpDDLStore::GetDEfromLocalBoard(Int_t localBoardId, Int_t chamberId) const {
777 /// Return detElemId for local board Id and chamber id.
61c370dd 778
40c8e44b 779 AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId);
780
781 if ( ! localBoard ) {
782 AliErrorStream()
61c370dd 783 << "Loacl board with Id = " << localBoardId << " not defined." << endl;
40c8e44b 784 return 0;
785 }
61c370dd 786
40c8e44b 787 return localBoard->GetDEIdByChamber(chamberId);
61c370dd 788}
789
f0c62051 790//______________________________________________________________________________
40c8e44b 791Int_t AliMpDDLStore::GetDDLfromBus(Int_t busPatchId) const {
792 /// Return DDL Id for given busPatchId
f0c62051 793
40c8e44b 794 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
795
796 if ( ! busPatch ) {
797 AliErrorStream()
f0c62051 798 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
40c8e44b 799 return 0;
800 }
f0c62051 801
40c8e44b 802 return busPatch->GetDdlId();
803}
f0c62051 804
42d368d0 805//______________________________________________________________________________
40c8e44b 806Int_t AliMpDDLStore::GetBusPatchId(Int_t detElemId, Int_t manuId) const {
807 /// Return bus patch for a given manuId
808
809 AliMpDetElement* detElement = GetDetElement(detElemId);
810 Int_t pos = GetBusPatchIndex(detElemId, manuId);
811
a639f7c6 812 if ( pos >= detElement->GetNofBusPatches() )
813 {
40c8e44b 814 AliErrorStream()
815 << "Pos = " << pos
816 << " greater than the size = " << detElement->GetNofBusPatches()
817 << " for detElemId = " << detElemId
818 << " manuId = " << manuId << endl;
819 return -1;
820 }
42d368d0 821
40c8e44b 822 return detElement->GetBusPatchId(pos);
823}
42d368d0 824
59754717 825
826//______________________________________________________________________________
168e9c4d 827Long_t AliMpDDLStore::GetLinkPortId(Int_t busPatchId) const {
59754717 828
168e9c4d 829 /// Get link port and DSP from busPatch id.
830 /// Return -1 if the value is not valid
831 /// (the validity has to be tested in the client code)
59754717 832
833 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
834 Int_t ddlId = busPatch->GetDdlId();
835
836 Int_t localBusPatchId = AliMpBusPatch::GetLocalBusID(busPatchId, ddlId) - 1; // begin at zero
837
838 Int_t pos = (localBusPatchId % AliMpFrtCrocusConstants::GetNofBusPatches());
839
840 return AliMpFrtCrocusConstants::GetLinkPortId(pos);
841
842}
843
92faf71f 844//______________________________________________________________________________
40c8e44b 845void AliMpDDLStore::PrintAllManu() const {
846 /// Print all manu Ids and their serial numbers sorted by detection element
847 /// and bus patch. \n
848 /// As serial manu numbers are filled in a different way than manu Ids this
849 /// printing allows to check that both ways are consistent
850
851 // Loop over DE
852 AliMpDEIterator it;
853 for ( it.First(); ! it.IsDone(); it.Next() ) {
854 AliMpDetElement* de = it.CurrentDE();
855 cout << "DE: " << de->GetId() << endl;
856
857 // Loop over bus patches in this DE
858 for ( Int_t i=0; i< de->GetNofBusPatches(); ++i ) {
859
860 AliMpBusPatch* busPatch = GetBusPatch(de->GetBusPatchId(i));
861 cout << " busPatch: " << busPatch->GetId() << endl;
862
863 cout << " Manu : ";
864 for ( Int_t j=0; j<busPatch->GetNofManus(); ++j ) {
865 cout << std::setw(6) << busPatch->GetManuId(j) << " ";
866 }
867 cout << endl;
868
ab167304 869 if ( AliMpManuStore::Instance(kFALSE) ) {
870 cout << " Manu serial: ";
871 for ( Int_t k=0; k<busPatch->GetNofManus(); ++k ) {
872 cout << std::setw(6)
873 << AliMpManuStore::Instance()
874 ->GetManuSerial(de->GetId(), busPatch->GetManuId(k)) << " ";
875 }
876 cout << endl;
877 }
40c8e44b 878 }
879 }
880}
92faf71f 881
efb566fd 882//______________________________________________________________________________
40c8e44b 883Int_t AliMpDDLStore::GetNextDEfromLocalBoard(Int_t localBoardId, Int_t chamberId ) const {
884 /// return the next detection element in line
61c370dd 885
886 AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId);
887
888 TString name(localBoard->GetName());
889
168e9c4d 890 Int_t line = AliMp::PairFirst(localBoard->GetPosition());
61c370dd 891 ++line;
40c8e44b 892
61c370dd 893 name.Replace(4,1,Form("%d", line));
894
40c8e44b 895 Int_t nextLocalId;
61c370dd 896 if ((nextLocalId = GetLocalBoardId(name)))
40c8e44b 897 return GetDEfromLocalBoard(nextLocalId, chamberId);
61c370dd 898 else
40c8e44b 899 return 0;
61c370dd 900
901 return 0;
902}
903
efb566fd 904//______________________________________________________________________________
40c8e44b 905Int_t AliMpDDLStore::GetPreviousDEfromLocalBoard(Int_t localBoardId, Int_t chamberId) const {
906 /// return the previous detection element in line
61c370dd 907
908 AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId);
909
910 TString name(localBoard->GetName());
911
168e9c4d 912 Int_t line = AliMp::PairFirst(localBoard->GetPosition());
61c370dd 913 --line;
40c8e44b 914
61c370dd 915 name.Replace(4,1,Form("%d", line));
916
917 Int_t prevLocalId;
918 if ((prevLocalId = GetLocalBoardId(name)))
40c8e44b 919 return GetDEfromLocalBoard(prevLocalId, chamberId);
61c370dd 920 else
40c8e44b 921 return 0;
61c370dd 922
923}
efb566fd 924
925//______________________________________________________________________________
926void AliMpDDLStore::SetRegionalTrigger(const AliMpRegionalTrigger& regionalTrigger)
927{
928/// Replace the existing regional trigger with the given one
929
930 fRegionalTrigger = regionalTrigger;
931
92c23b09 932 // Remove the existing trigger DDLsf
efb566fd 933 fDDLs.RemoveAt(fgkNofDDLs+1);
934 fDDLs.RemoveAt(fgkNofDDLs);
935
936 // Set new trigger DDLs from new regional trigger
937 SetTriggerDDLs();
938}
630711ed 939
940
941//______________________________________________________________________________
942TIterator*
943AliMpDDLStore::CreateBusPatchIterator() const
944{
945/// Create the iterator over bus patches
946
947 return fBusPatches.CreateIterator();
948}