1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 // $MpId: AliMpDDLStore.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
20 //-----------------------------------------------------------------------------
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
28 //-----------------------------------------------------------------------------
30 #include "AliMpDDLStore.h"
31 #include "AliMpConstants.h"
32 #include "AliMpDEStore.h"
34 #include "AliMpFiles.h"
35 #include "AliMpHelper.h"
36 #include "AliMpDEManager.h"
37 #include "AliMpDetElement.h"
38 #include "AliMpBusPatch.h"
39 #include "AliMpTriggerCrate.h"
40 #include "AliMpLocalBoard.h"
41 #include "AliMpSegmentation.h"
42 #include "AliMpVSegmentation.h"
43 #include "AliMpStringObjMap.h"
46 #include <Riostream.h>
48 #include <TObjArray.h>
50 #include <TObjString.h>
54 ClassImp(AliMpDDLStore)
57 AliMpDDLStore* AliMpDDLStore::fgInstance = 0;
58 const Int_t AliMpDDLStore::fgkNofDDLs = 20;
59 const Int_t AliMpDDLStore::fgkNofTriggerDDLs = 2;
65 //______________________________________________________________________________
66 AliMpDDLStore* AliMpDDLStore::Instance(Bool_t warn)
68 /// Create the DDL store if it does not yet exist
69 /// and return its instance
71 if ( ! fgInstance && warn ) {
72 AliWarningClass("DDL Store has not been loaded");
78 //______________________________________________________________________________
79 AliMpDDLStore* AliMpDDLStore::ReadData(Bool_t warn)
81 /// Load the DDL store from ASCII data files
82 /// and return its instance
86 AliWarningClass("DDL Store has been already loaded");
90 AliInfoClass("Reading DDL Store from ASCII files.");
92 fgInstance = new AliMpDDLStore();
100 //______________________________________________________________________________
101 AliMpDDLStore::AliMpDDLStore()
103 fDDLs(fgkNofDDLs+fgkNofTriggerDDLs), // FIXEME
105 fTriggerCrates(true),
109 fGlobalCrate(new AliMpGlobalCrate())
111 /// Standard constructor
114 fDDLs.SetOwner(true);
115 fBusPatches.SetOwner(true);
116 fBusPatches.SetSize(900);
118 fTriggerCrates.SetOwner(true);
119 fTriggerCrates.SetSize(16);
121 fLocalBoards.SetOwner(true);
122 fLocalBoards.SetSize(242); // included non-identied board
125 // Load segmentation & DE store data
126 if ( ! AliMpSegmentation::Instance(false) )
127 AliMpSegmentation::ReadData(true);
129 // Create all detection elements
137 //______________________________________________________________________________
138 AliMpDDLStore::AliMpDDLStore(TRootIOCtor* /*ioCtor*/)
142 fTriggerCrates(true),
146 /// Constructor for IO
154 //______________________________________________________________________________
155 AliMpDDLStore::~AliMpDDLStore()
161 // DDL objects are deleted with fDDLs
162 // Bus patches objects are deleted with fBusPatches
172 //______________________________________________________________________________
173 Int_t AliMpDDLStore::GetManuListIndex(Int_t detElemId) const
175 /// Return the index of the manu list for given detElemId
177 return AliMpDEManager::GetChamberId(detElemId)*4 + (detElemId % 100);
181 //______________________________________________________________________________
182 Int_t AliMpDDLStore::GetBusPatchIndex(Int_t detElemId, Int_t manuId) const
184 /// Calculate the index of the buspatch from manuId
187 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
188 static Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane) - 1;
190 if( stationType == AliMp::kStation345) {
191 pos = (manuId & manuMask)/100;
193 Int_t idx = GetManuListIndex(detElemId);
195 // using array defined from DetElemIdToBusPatch.dat file
196 for (pos = fManuList12[idx].GetSize()-1; pos >= 0; --pos)
197 if ( manuId >= fManuList12[idx].At(pos))
204 //______________________________________________________________________________
205 Bool_t AliMpDDLStore::ReadGlobalTrigger(AliMpGlobalCrate& crate, const Char_t* globalName)
207 /// Fill trigger global crate object from ascii file
208 /// put the method static to be used by other class w/o initializing object
213 infile = AliMpFiles::GlobalTriggerBoardMapping();
217 ifstream in(infile, ios::in);
220 printf("Local Trigger Board Mapping File %s not found", infile.Data());
227 in.getline(line, 255);
228 TString tmp(AliMpHelper::Normalize(line));
230 if (!tmp.Contains(crate.GetName()))
231 printf("Wrong Global Crate File");
233 in.getline(line, 255);
234 tmp = AliMpHelper::Normalize(line);
236 if (tmp.Contains(crate.GetJtagName())) {
238 in.getline(line, 255);
239 TString tmp(AliMpHelper::Normalize(line));
241 sscanf(tmp.Data(), "%lx", &addr);
242 crate.SetJtagVmeAddr(addr);
243 //AliDebug(1, Form("Jtag Vme Address: 0x%x", addr));
245 // clk div, rx phase, read delay
246 in.getline(line, 255);
247 tmp = AliMpHelper::Normalize(line);
249 AliMpHelper::DecodeName(line, ' ', list);
250 crate.SetJtagClockDiv(list[0]);
251 crate.SetJtagRxPhase(list[1]);
252 crate.SetJtagRdDelay(list[2]);
253 //AliDebug(1, Form("Jtag Clock Div: %d, Rx Phase: %d, Read Delay %d", list[0], list[1], list[2]));
256 in.getline(line, 255);
257 tmp = AliMpHelper::Normalize(line);
258 AliMpHelper::DecodeName(line, ' ', list);
260 for (Int_t i = 0; i < crate.GetJtagNofLines(); ++i)
261 enable |= (list[i] << i);
262 crate.SetEnableJtag(enable);
263 //AliDebug(1, Form("Jtag Enable: 0x%x", enable));
265 for (Int_t i = 0; i < crate.GetJtagNofLines(); ++i) {
266 in.getline(line, 255);
267 for (Int_t j = 0; j < crate.GetJtagNofLines(); ++j) {
268 in.getline(line, 255);
269 tmp = AliMpHelper::Normalize(line);
270 crate.SetJtagCrateName(i*crate.GetJtagNofLines() + j, tmp);
271 //AliDebug(1, Form("Jtag Crate Name: %s", tmp.Data()));
276 in.getline(line, 255);
277 tmp = AliMpHelper::Normalize(line);
278 if (tmp.Contains(crate.GetFirstDarcName())) {
280 in.getline(line, 255);
281 TString tmp(AliMpHelper::Normalize(line));
283 sscanf(tmp.Data(), "%lx", &addr);
284 crate.SetFirstDarcVmeAddr(addr);
285 //AliDebug(1, Form("First Darc Vme Address: 0x%x", addr));
288 in.getline(line, 255);
289 tmp = AliMpHelper::Normalize(line);
290 crate.SetFirstDarcType(tmp.Atoi());
291 //AliDebug(1, Form("First Darc Type: %d", tmp.Atoi()));
294 in.getline(line, 255);
296 tmp = AliMpHelper::Normalize(line);
297 sscanf(tmp.Data(), "%x", &item);
298 crate.SetFirstDarcDisable(item);
299 //AliDebug(1, Form("First Darc Enable: 0x%x", item));
302 in.getline(line, 255);
303 tmp = AliMpHelper::Normalize(line);
304 sscanf(tmp.Data(), "%x", &item);
305 crate.SetFirstDarcL0Delay(item);
306 //AliDebug(1, Form("First Darc L0 Delay: 0x%x", item));
309 in.getline(line, 255);
310 tmp = AliMpHelper::Normalize(line);
311 sscanf(tmp.Data(), "%x", &item);
312 crate.SetFirstDarcL1TimeOut(item);
313 //AliDebug(1, Form("First Darc L1 Time Out: 0x%x", item));
316 in.getline(line, 255);
317 tmp = AliMpHelper::Normalize(line);
318 if (tmp.Contains(crate.GetSecondDarcName())) {
320 in.getline(line, 255);
321 TString tmp(AliMpHelper::Normalize(line));
323 sscanf(tmp.Data(), "%lx", &addr);
324 crate.SetSecondDarcVmeAddr(addr);
325 //AliDebug(1, Form("Second Darc Vme Address: 0x%x", addr));
328 in.getline(line, 255);
329 tmp = AliMpHelper::Normalize(line);
330 crate.SetSecondDarcType(tmp.Atoi());
331 //AliDebug(1, Form("Second Darc Type: %d", tmp.Atoi()));
334 in.getline(line, 255);
336 tmp = AliMpHelper::Normalize(line);
337 sscanf(tmp.Data(), "%x", &item);
338 crate.SetSecondDarcDisable(item);
339 //AliDebug(1, Form("Second Darc Enable: 0x%x", item));
342 in.getline(line, 255);
343 tmp = AliMpHelper::Normalize(line);
344 sscanf(tmp.Data(), "%x", &item);
345 crate.SetSecondDarcL0Delay(item);
346 //AliDebug(1, Form("Second Darc L0 Delay: 0x%x", item));
349 in.getline(line, 255);
350 tmp = AliMpHelper::Normalize(line);
351 sscanf(tmp.Data(), "%x", &item);
352 crate.SetSecondDarcL1TimeOut(item);
353 //AliDebug(1, Form("Second Darc L1 Time Out: 0x%x", item));
356 in.getline(line, 255);
357 tmp = AliMpHelper::Normalize(line);
358 if (tmp.Contains(crate.GetGlobalName())) {
359 in.getline(line, 255);
360 TString tmp(AliMpHelper::Normalize(line));
362 sscanf(tmp.Data(), "%lx", &addr);
363 crate.SetGlobalVmeAddr(addr);
364 //AliDebug(1, Form("Global Vme Address: 0x%x", addr));
366 for (Int_t i = 0; i < crate.GetGlobalNofRegisters(); ++i) {
367 in.getline(line, 255);
368 TString tmp(AliMpHelper::Normalize(line));
370 sscanf(tmp.Data(), "%x", ®);
371 crate.SetGlobalRegister(i, reg);
372 //AliDebug(1, Form("Global Register %d: 0x%x", i, reg));
376 in.getline(line, 255);
377 tmp = AliMpHelper::Normalize(line);
378 if (tmp.Contains(crate.GetFetName())) {
379 in.getline(line, 255);
380 TString tmp(AliMpHelper::Normalize(line));
382 sscanf(tmp.Data(), "%lx", &addr);
383 crate.SetFetVmeAddr(addr);
384 //AliDebug(1, Form("Fet Vme Address: 0x%x", addr));
386 for (Int_t i = 0; i < crate.GetFetNofRegisters(); ++i) {
387 in.getline(line, 255);
388 TString tmp(AliMpHelper::Normalize(line));
390 sscanf(tmp.Data(), "%x", ®);
391 crate.SetFetRegister(i, reg);
392 //AliDebug(1, Form("Fet Register %d: 0x%x", i, reg));
398 //______________________________________________________________________________
399 Bool_t AliMpDDLStore::ReadDDLs()
401 /// Read ddl <-> bus patch file
403 TString infile = AliMpFiles::BusPatchFilePath();
405 ifstream in(infile, ios::in);
407 AliErrorStream() << "Data file " << infile << " not found.";
413 while ( in.getline(line,255) ) {
415 if ( line[0] == '#' )
418 TString tmp(AliMpHelper::Normalize(line));
420 TObjArray* stringList = tmp.Tokenize(TString(" "));
422 TString sDE = ((TObjString*)stringList->At(0))->GetString();
423 Int_t idDE = atoi(sDE.Data());
425 if ( ! AliMpDEManager::IsValidDetElemId(idDE, false) ) {
426 AliErrorStream() << "DetElemId "<< idDE << " not valid." << endl;
430 TString busPatch = ((TObjString*)stringList->At(1))->GetString();
433 TString sDDL = ((TObjString*)stringList->At(2))->GetString();
434 Int_t iDDL = atoi(sDDL.Data());
436 if ( iDDL < 0 || iDDL >= fgkNofDDLs ) {
437 AliErrorStream() << "DDL id "<< iDDL << " outside limits." << endl;
442 << "idDE " << idDE << " buspatch " << busPatch.Data() << " iDDL " << iDDL
445 // reading 1st manu Id for each bus patch (station 1 & 2)
446 if(AliMpDEManager::GetStationType(idDE) != AliMp::kStation345) {
448 TString sManu = ((TObjString*)stringList->At(3))->GetString();
449 AliMpHelper::DecodeName(sManu,',',fManuList12[GetManuListIndex(idDE)]);
451 if(AliMpDEManager::GetStationType(idDE) == AliMp::kStation2) {
452 TString sManuBridge = ((TObjString*)stringList->At(4))->GetString();
453 AliMpHelper::DecodeName(sManuBridge,',',fManuBridge2[GetManuListIndex(idDE)]);
460 AliMpDDL* ddl = GetDDL(iDDL, false);
462 ddl = new AliMpDDL(iDDL);
463 fDDLs.AddAt(ddl, iDDL);
467 TArrayI busPatchList;
468 // decoding range of buspatch
469 AliMpHelper::DecodeName(busPatch,';',busPatchList);
472 AliMpDetElement* de = AliMpDEManager::GetDetElement(idDE);
474 // filling buspatch -> idDE
475 for (Int_t i = 0; i < busPatchList.GetSize(); i++) {
476 fBusPatches.Add(busPatchList[i],
477 new AliMpBusPatch(busPatchList[i], idDE, iDDL));
478 de->AddBusPatch(busPatchList[i]);
482 // Fill bus patch Ids array in DDLs now
483 for ( Int_t i=0; i<fDDLs.GetEntriesFast(); i++ ) {
484 AliMpDDL* ddl = (AliMpDDL*) fDDLs.At(i);
485 ddl->FillBusPatchIds();
491 //______________________________________________________________________________
492 Bool_t AliMpDDLStore::ReadTriggerDDLs()
494 /// create trigger DDL object and Global crate object
496 if (!ReadGlobalTrigger(*fGlobalCrate)) return false;
497 if (!ReadLocalTrigger()) return false;
502 //______________________________________________________________________________
503 Bool_t AliMpDDLStore::ReadLocalTrigger()
505 /// create trigger DDL object ddl<->Crate<->local board
507 ReadGlobalTrigger(*fGlobalCrate);
511 TString infile = AliMpFiles::LocalTriggerBoardMapping();
513 ifstream in(infile, ios::in);
516 AliError(Form("Local Trigger Board Mapping File %s not found", infile.Data()));
520 AliMpLocalBoard* board = 0x0;
521 AliMpTriggerCrate* crate = 0x0;
524 Int_t localBoardId = 0;
526 UShort_t crateId, mask;
527 Int_t mode, coincidence;
534 if (!strlen(line)) break;
535 TString crateName(AliMpHelper::Normalize(line));
538 sscanf(line,"%hx",&crateId);
541 sscanf(line,"%d",&mode);
544 sscanf(line,"%d",&coincidence);
547 sscanf(line,"%hx",&mask);
549 // determine ddl number vs crate side
550 if (crateName.Contains("R"))
551 iDDL = fgkNofDDLs; // starts where tracker ends
553 iDDL = fgkNofDDLs + 1;
555 AliMpDDL* ddl = GetDDL(iDDL, false);
557 ddl = new AliMpDDL(iDDL);
558 fDDLs.AddAt(ddl, iDDL);
560 if (!GetTriggerCrate(crateName.Data(), false)) {
561 crate = new AliMpTriggerCrate(crateName.Data(), crateId, mask, mode, coincidence);
562 crate->SetDdlId(iDDL);
563 fTriggerCrates.Add(crateName.Data(), crate);
566 // add trigger crate number for given ddl if not present
567 if ( !ddl->HasTriggerCrateId(crateId) )
568 ddl->AddTriggerCrate(crateId);
571 Char_t localBoardName[20];
575 for ( Int_t i = 0; i < AliMpConstants::LocalBoardNofChannels(); ++i )
577 if ( (mask >> i ) & 0x1 )
580 sscanf(line,"%02d %s %03d %03x",&slot,localBoardName,&localBoardId,&switches);
581 board = new AliMpLocalBoard(localBoardId, localBoardName, slot);
582 board->SetSwitch(switches);
583 board->SetCrate(crateName);
585 if (localBoardId > AliMpConstants::NofLocalBoards())
586 board->SetNotified(false); // copy cards
588 crate->AddLocalBoard(localBoardId);
591 AliMpDDL* ddl = GetDDL(iDDL, true);
593 // add DE for local board and DDL
595 TString tmp(AliMpHelper::Normalize(line));
596 AliMpHelper::DecodeName(tmp,' ',list);
598 for (Int_t i = 0; i < list.GetSize(); ++i) {
600 if (list[i]) { // skip copy card
601 AliMpDetElement* de = AliMpDEManager::GetDetElement(list[i]);
602 if (de->GetDdlId() == -1)
605 board->AddDE(list[i]);
606 if(!ddl->HasDEId(list[i]))
610 // set copy number and transverse connector
612 tmp = AliMpHelper::Normalize(line);
613 AliMpHelper::DecodeName(tmp,' ',list);
615 board->SetInputXfrom(list[0]);
616 board->SetInputXto(list[1]);
618 board->SetInputYfrom(list[2]);
619 board->SetInputYto(list[3]);
621 board->SetTC(list[4]);
623 // add local board into map
624 fLocalBoards.Add(board->GetId(), board);
632 //______________________________________________________________________________
633 Bool_t AliMpDDLStore::SetManus() {
634 /// Set manus for each bus patch
636 Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane) - 1;
639 for (Int_t iDDL = 0; iDDL < fgkNofDDLs; ++iDDL) {
641 AliDebug(3, Form("DDL # %d\n", iDDL));
643 AliMpDDL* ddl = GetDDL(iDDL);
645 // loop over DE in the given DDL
646 for (Int_t detElemIdx = 0; detElemIdx < ddl->GetNofDEs(); ++detElemIdx) {
648 Int_t detElemId = ddl->GetDEId(detElemIdx);
650 AliMpDetElement* detElement = GetDetElement(detElemId);
652 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
655 // list of manu per DE on both cathode
657 for ( Int_t cath = 0; cath < 2 ; ++cath ) {
658 const AliMpVSegmentation* seg
659 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(cath));
661 AliMp::PlaneType planeType = detElement->GetPlaneType(AliMp::GetCathodType(cath));
664 seg->GetAllElectronicCardIDs(manus);
666 // filling TList manu
667 for ( Int_t im = 0; im < manus.GetSize(); ++im ) {
669 AliMpIntPair* manu = 0x0;
670 if( stationType == AliMp::kStation345)
671 manu = new AliMpIntPair((manus[im] & manuMask), planeType, kTRUE); //remove offset for NB
673 manu = new AliMpIntPair(manus[im], planeType, kTRUE); //keep offset for NB
677 detElement->AddManu(manus[im]);
681 manuList.Sort(); // sort regardless B or NB plane
683 // filling manu to the corresponding buspatch
684 for (Int_t iEntry = 0; iEntry < manuList.GetEntries(); ++iEntry) {
686 AliMpIntPair* manuPtr = (AliMpIntPair*)manuList.At(iEntry);
688 Int_t manuId = manuPtr->GetFirst();
689 Int_t pos = GetBusPatchIndex(detElemId, manuId);
691 if (pos > detElement->GetNofBusPatches()) {
692 AliError(Form("pos greater %d than size %d manuId %d detElemId %d \n",
693 pos, detElement->GetNofBusPatches(), manuId, detElemId));
697 // get buspatch and fill manus
698 Int_t busPatchId = detElement->GetBusPatchId(pos);
699 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
701 if( stationType == AliMp::kStation345) {
703 if (manuPtr->GetSecond())
704 busPatch->AddManu(manuId+manuMask+1); // add offset again after sorted
706 busPatch->AddManu(manuId);
710 busPatch->AddManu(manuId);
717 if (AliDebugLevel() == 3) {
719 // print out for checking
720 for(Int_t pos = 0; pos < detElement->GetNofBusPatches(); ++pos) {
721 Int_t busPatchId = detElement->GetBusPatchId(pos);
722 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
723 printf("BusPatch: %d\n", busPatch->GetId());
724 for (Int_t iEntry = 0; iEntry < busPatch->GetNofManus(); ++iEntry)
725 printf("manu Id: %d\n", busPatch->GetManuId(iEntry));
729 } // detection element loop
735 //______________________________________________________________________________
736 Bool_t AliMpDDLStore::SetPatchModules() {
737 /// Compute the number of manu per PCB for each buspatch
740 Bool_t result = true;
742 for ( it.First(); !it.IsDone(); it.Next() ) {
744 AliMpDetElement* detElement = it.CurrentDE();
746 for (Int_t i = 0; i < detElement->GetNofBusPatches(); ++i) {
747 AliMpBusPatch* busPatch = GetBusPatch(detElement->GetBusPatchId(i));
748 Bool_t newResult = false;
749 Int_t idDE = busPatch->GetDEId();
751 if (AliMpDEManager::GetStationType(idDE) == AliMp::kStation2 )
752 newResult = busPatch->SetNofManusPerModule(fManuBridge2[GetManuListIndex(idDE)].At(i));
754 newResult = busPatch->SetNofManusPerModule();
761 //______________________________________________________________________________
762 Bool_t AliMpDDLStore::SetBusPatchLength() {
763 /// read the buspatch length file and set buspatch length
765 TString infile = AliMpFiles::BusPatchLengthFilePath();
766 ifstream in(infile, ios::in);
768 AliErrorStream() << "Data file " << infile << " not found.";
773 for (Int_t iDDL = 0; iDDL < fgkNofDDLs; ++iDDL ) {
774 AliMpDDL* ddl = GetDDL(iDDL);
776 for (Int_t iBusPatch = 0; iBusPatch < ddl->GetNofBusPatches(); ++iBusPatch) {
779 if (!in.getline(line,255)) {
780 AliWarning(Form("Wrong size in bus patch length file; index %d DDL %d",
784 } while(line[0] == '#');
786 TString tmp(AliMpHelper::Normalize(line));
788 TObjArray* stringList = tmp.Tokenize(TString(" "));
790 TString sLocalBusId = ((TObjString*)stringList->At(0))->GetString();
791 Int_t localBusId = sLocalBusId.Atoi();
793 TString sLength = ((TObjString*)stringList->At(1))->GetString();
794 Float_t length = sLength.Atof();
798 if (localBusId != iBusPatch + 1)
799 AliWarning(Form("Wrong local buspatch id %d instead of %d", iBusPatch+1, localBusId));
801 Int_t busPatchId = ddl->GetBusPatchId(iBusPatch);
802 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
803 busPatch->SetCableLength(length);
811 //________________________________________________________________
812 Int_t AliMpDDLStore::GetLocalBoardId(TString name) const {
813 /// return the first board with a given side and line
815 TExMapIter i = fLocalBoards.GetIterator();
817 while ( i.Next(key, value) ) {
818 AliMpLocalBoard* local = (AliMpLocalBoard*)value;
820 TString tmp(&local->GetName()[4], 2);
821 if (name.Contains(tmp))
822 if (name[0] == local->GetName()[0])
823 return local->GetId();
835 //______________________________________________________________________________
836 AliMpDDL* AliMpDDLStore::GetDDL(Int_t ddlId, Bool_t warn) const {
837 /// Return DDL for given ddlId
840 = (AliMpDDL*)fDDLs.At(ddlId);
842 if ( ! ddl && warn ) {
844 << "DDL with Id = " << ddlId << " not defined." << endl;
850 //______________________________________________________________________________
851 AliMpDetElement* AliMpDDLStore::GetDetElement(Int_t detElemId, Bool_t warn) const {
852 /// Return detection element with given detElemId
854 if ( ! AliMpDEStore::Instance() ) {
855 AliFatal("DE Store has not been loaded.");
859 return AliMpDEStore::Instance()->GetDetElement(detElemId, warn);
862 //______________________________________________________________________________
863 AliMpBusPatch* AliMpDDLStore::GetBusPatch(Int_t busPatchId, Bool_t warn) const {
864 /// Return bus patch with given Id
866 AliMpBusPatch* busPatch
867 = (AliMpBusPatch*) fBusPatches.GetValue(busPatchId);
869 if ( ! busPatch && warn ) {
871 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
877 //______________________________________________________________________________
878 AliMpLocalBoard* AliMpDDLStore::GetLocalBoard(Int_t localBoardId, Bool_t warn) const {
879 /// Return bus patch with given Id
881 AliMpLocalBoard* localBoard
882 = (AliMpLocalBoard*) fLocalBoards.GetValue(localBoardId);
884 if ( ! localBoard && warn ) {
886 << "Local board with Id = " << localBoardId << " not defined." << endl;
892 //______________________________________________________________________________
893 AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(TString name, Bool_t warn) const {
894 /// Return trigger crate with given name
896 AliMpTriggerCrate* crate
897 = (AliMpTriggerCrate*) fTriggerCrates.GetValue(name.Data());
899 if ( ! crate && warn ) {
901 << "Trigger crate with name = " << name.Data() << " not defined." << endl;
907 //______________________________________________________________________________
908 AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(Int_t ddlId, Int_t index, Bool_t warn) const {
909 /// Return trigger crate with given ddl and index crate
911 if (ddlId == 0 || ddlId == 1)
914 AliMpDDL* ddl = GetDDL(ddlId, warn);
918 if ( index >= ddl->GetNofTriggerCrates() ) {
919 AliError(Form("crate id %d greater than array[%d]", index, ddl->GetNofTriggerCrates()));
923 TString name = AliMpTriggerCrate::GenerateName(index, ddlId, fgkNofDDLs);
925 return GetTriggerCrate(name, warn);
928 //______________________________________________________________________________
929 Int_t AliMpDDLStore::GetDEfromBus(Int_t busPatchId) const {
930 /// Return detection element Id for given busPatchId
932 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
936 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
940 return busPatch->GetDEId();
943 //______________________________________________________________________________
944 Int_t AliMpDDLStore::GetDEfromLocalBoard(Int_t localBoardId, Int_t chamberId) const {
945 /// Return detElemId for local board Id and chamber id.
947 AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId);
949 if ( ! localBoard ) {
951 << "Loacl board with Id = " << localBoardId << " not defined." << endl;
955 return localBoard->GetDEIdByChamber(chamberId);
958 //______________________________________________________________________________
959 Int_t AliMpDDLStore::GetDDLfromBus(Int_t busPatchId) const {
960 /// Return DDL Id for given busPatchId
962 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
966 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
970 return busPatch->GetDdlId();
973 //______________________________________________________________________________
974 Int_t AliMpDDLStore::GetBusPatchId(Int_t detElemId, Int_t manuId) const {
975 /// Return bus patch for a given manuId
977 AliMpDetElement* detElement = GetDetElement(detElemId);
978 Int_t pos = GetBusPatchIndex(detElemId, manuId);
980 if ( pos > detElement->GetNofBusPatches() ) {
983 << " greater than the size = " << detElement->GetNofBusPatches()
984 << " for detElemId = " << detElemId
985 << " manuId = " << manuId << endl;
989 return detElement->GetBusPatchId(pos);
992 //______________________________________________________________________________
993 AliMpIntPair AliMpDDLStore::GetDetElemIdManu(Int_t manuSerial) const {
994 /// Return the detElemId and manuId for given serial manu number
996 if ( ! AliMpDEStore::Instance() ) {
997 AliFatal("DE Store has not been loaded.");
998 return AliMpIntPair::Invalid();
1001 return AliMpDEStore::Instance()->GetDetElemIdManu(manuSerial);
1004 //______________________________________________________________________________
1005 void AliMpDDLStore::PrintAllManu() const {
1006 /// Print all manu Ids and their serial numbers sorted by detection element
1007 /// and bus patch. \n
1008 /// As serial manu numbers are filled in a different way than manu Ids this
1009 /// printing allows to check that both ways are consistent
1013 for ( it.First(); ! it.IsDone(); it.Next() ) {
1014 AliMpDetElement* de = it.CurrentDE();
1015 cout << "DE: " << de->GetId() << endl;
1017 // Loop over bus patches in this DE
1018 for ( Int_t i=0; i< de->GetNofBusPatches(); ++i ) {
1020 AliMpBusPatch* busPatch = GetBusPatch(de->GetBusPatchId(i));
1021 cout << " busPatch: " << busPatch->GetId() << endl;
1024 for ( Int_t j=0; j<busPatch->GetNofManus(); ++j ) {
1025 cout << std::setw(6) << busPatch->GetManuId(j) << " ";
1029 cout << " Manu serial: ";
1030 for ( Int_t k=0; k<busPatch->GetNofManus(); ++k ) {
1031 cout << std::setw(6) << de->GetManuSerialFromId(busPatch->GetManuId(k)) << " ";
1038 //________________________________________________________________
1039 Int_t AliMpDDLStore::GetNextDEfromLocalBoard(Int_t localBoardId, Int_t chamberId ) const {
1040 /// return the next detection element in line
1042 AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId);
1044 TString name(localBoard->GetName());
1046 Int_t line = localBoard->GetPosition().GetFirst();
1049 name.Replace(4,1,Form("%d", line));
1052 if ((nextLocalId = GetLocalBoardId(name)))
1053 return GetDEfromLocalBoard(nextLocalId, chamberId);
1060 //________________________________________________________________
1061 Int_t AliMpDDLStore::GetPreviousDEfromLocalBoard(Int_t localBoardId, Int_t chamberId) const {
1062 /// return the previous detection element in line
1064 AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId);
1066 TString name(localBoard->GetName());
1068 Int_t line = localBoard->GetPosition().GetFirst();
1071 name.Replace(4,1,Form("%d", line));
1074 if ((prevLocalId = GetLocalBoardId(name)))
1075 return GetDEfromLocalBoard(prevLocalId, chamberId);