diff --git a/core/detectors/rich/CbmMcbm2018RichPar.cxx b/core/detectors/rich/CbmMcbm2018RichPar.cxx index 8c818c7749528eb9e983bfac819131a092f344f4..fa528d54dc52cf4a98ca8f42a729e32fcdd92a90 100644 --- a/core/detectors/rich/CbmMcbm2018RichPar.cxx +++ b/core/detectors/rich/CbmMcbm2018RichPar.cxx @@ -43,34 +43,45 @@ Bool_t CbmMcbm2018RichPar::getParams(FairParamList* l) if (!l->fill("TRBaddresses", &fTRBaddresses)) return kFALSE; if (!l->fill("ToTshifts", &fToTshifts)) return kFALSE; + LoadInternalContainers(); + + return kTRUE; +} + +void CbmMcbm2018RichPar::LoadInternalContainers() +{ // Create a map from the list imported from the par file Int_t siz = fTRBaddresses.GetSize(); for (Int_t i = 0; i < siz; i++) { fTRBaddrMap.insert(std::pair<Int_t, Int_t>(fTRBaddresses[i], i)); + LOG(debug) << "Inserting in RICH TRB map: 0x" << std::hex << std::setw(4) << fTRBaddresses[i] << std::dec << " " + << i; } - // Create a map from the lists imported from the par file + // Create a vector from the lists imported from the par file + // Continuous indices => no need for map with deep calls for (Int_t i = 0; i < siz; i++) { for (Int_t ch = 0; ch <= 32; ch++) { - fToTshiftMap.insert(std::pair<Int_t, Double_t>(i * 33 + ch, fToTshifts[i * 33 + ch])); + fToTshiftMap.push_back(fToTshifts[i * 33 + ch]); } } - - return kTRUE; } Int_t CbmMcbm2018RichPar::GetAddressIdx(Int_t addr) const { - //TODO catch exception only for map - try { - Int_t idx = fTRBaddrMap.at(addr); - return idx; - } - catch (...) { + auto it = fTRBaddrMap.find(addr); + if (fTRBaddrMap.end() == it) { LOG(warning) << "CbmMcbm2018RichPar::GetAddressIdx => Unknown TRB address 0x" << std::hex << std::setw(4) << addr - << ", probably corrupted data!"; + << std::dec << ", probably corrupted data!"; + LOG(warning) << "Nb available TRB addresses: " << GetNaddresses(); + + Print(); + return -1; } + else { + return it->second; + } } Int_t CbmMcbm2018RichPar::GetAddress(Int_t ind) const @@ -79,4 +90,31 @@ Int_t CbmMcbm2018RichPar::GetAddress(Int_t ind) const return fTRBaddresses[ind]; } +Double_t CbmMcbm2018RichPar::GetToTshift2(Int_t tdcIdx, Int_t ch) const +{ + if (-1 == tdcIdx) { + LOG(fatal) << "CbmMcbm2018RichPar::GetToTshift2 => Invalid TDC index, " + << "check your data or your parameters!"; + } + return fToTshiftMap[tdcIdx * 33 + ch]; +} + +void CbmMcbm2018RichPar::Print() const +{ + LOG(info) << "Nb available TRB addresses: " << GetNaddresses(); + + TString sPrintout = ""; + for (Int_t iTrb = 0; iTrb < GetNaddresses(); ++iTrb) { + if (0 == iTrb % 8) sPrintout += "\n"; + sPrintout += Form(" 0x%04x", GetAddress(iTrb)); + } // for( Int_t iTrb = 0; iTrb < GetNaddresses; ++iTrb) + LOG(info) << "Available TRB addresses: " << sPrintout; + + sPrintout = ""; + for (auto it = fTRBaddrMap.begin(); it != fTRBaddrMap.end(); ++it) { + sPrintout += Form(" 0x%04x", it->first); + } // for( UInt_t i = 0; i < uNrOfChannels; ++i) + LOG(info) << "TRB addresses in map: " << std::endl << sPrintout; +} + ClassImp(CbmMcbm2018RichPar) diff --git a/core/detectors/rich/CbmMcbm2018RichPar.h b/core/detectors/rich/CbmMcbm2018RichPar.h index 4d2210045307fce753727924a8db767c8d5a3f99..b22d191a163135d2934ebe3a911d1cba43be28a4 100644 --- a/core/detectors/rich/CbmMcbm2018RichPar.h +++ b/core/detectors/rich/CbmMcbm2018RichPar.h @@ -9,6 +9,7 @@ // STD #include <map> +#include <vector> // ROOT #include <TArrayD.h> @@ -19,12 +20,23 @@ public: CbmMcbm2018RichPar(const char* name = "CbmMcbm2018RichPar", const char* title = "RICH unpacker parameters", const char* context = "Default"); + /// Explicit copy assignment operator due to vector and map members! + CbmMcbm2018RichPar& operator=(const CbmMcbm2018RichPar& other) + { + fTRBaddresses = other.fTRBaddresses; + fToTshifts = other.fToTshifts; + LoadInternalContainers(); + return *this; + } + virtual ~CbmMcbm2018RichPar(); virtual void putParams(FairParamList*); virtual Bool_t getParams(FairParamList*); + void LoadInternalContainers(); + public: Int_t GetNaddresses(void) const { return fTRBaddresses.GetSize(); } @@ -46,7 +58,9 @@ public: * First argument is TDC index (i.e. 0,1,2,...) * TODO: test! */ - Double_t GetToTshift2(Int_t tdcIdx, Int_t ch) const { return fToTshiftMap.at(tdcIdx * 33 + ch); } + Double_t GetToTshift2(Int_t tdcIdx, Int_t ch) const; + + void Print() const; private: // Stored in the par file /** @@ -72,11 +86,11 @@ private: // Recalculated std::map<Int_t, Int_t> fTRBaddrMap; //! /** - * key - unique channel ID, value - ToT shift + * index - unique channel ID, value - ToT shift */ - std::map<Int_t, Double_t> fToTshiftMap; //! + std::vector<Double_t> fToTshiftMap; //! - ClassDef(CbmMcbm2018RichPar, 1); + ClassDef(CbmMcbm2018RichPar, 2); }; #endif // CbmMcbm2018RichPar_H diff --git a/reco/detectors/rich/unpack/CbmRichUnpackAlgo.cxx b/reco/detectors/rich/unpack/CbmRichUnpackAlgo.cxx index c1da269a7c5352256240ea396778939139f35928..2a997dc41180b756d2688d2354208f963476e94f 100644 --- a/reco/detectors/rich/unpack/CbmRichUnpackAlgo.cxx +++ b/reco/detectors/rich/unpack/CbmRichUnpackAlgo.cxx @@ -69,8 +69,9 @@ Bool_t CbmRichUnpackAlgo::initParSet(CbmMcbm2018RichPar* parset) { LOG(debug) << fName << "::initParSetAsic - "; fUnpackPar = *parset; + fUnpackPar.Print(); - LOG(info) << fName << "::initParSetRichMcbm2018 - Successfully initialized Spadic hardware address map"; + LOG(info) << fName << "::initParSetRichMcbm2018 - Successfully initialized RICH unpacking parameters"; return kTRUE; } @@ -416,7 +417,7 @@ void CbmRichUnpackAlgo::writeOutputDigi(Int_t fpgaID, Int_t channel, Double_t ti // Sorting of Digis (Now done in general part) /* Double_t lastTime = 0.; - + if (fOutputVec.size() < 1) { fOutputVec.emplace_back(pixelUID, finalTime, tot - ToTcorr); } else { lastTime = fOutputVec[fOutputVec.size() - 1].GetTime();