Skip to content
Snippets Groups Projects
Commit 131815dc authored by Pierre-Alain Loizeau's avatar Pierre-Alain Loizeau Committed by Pierre-Alain Loizeau
Browse files

In CbmMcbm2018RichPar, add explicit assignment OP constructor + replace map...

In CbmMcbm2018RichPar, add explicit assignment OP constructor + replace map with vector when possible

- Introduce LoadInternalContainers method for setting all memberss derived from other members
- replace fToTshiftMap map with vector as continuous array with always successive keys (faster access)
- add the copy and assignment constructors
- Add a Print method
parent 09d4a6e9
No related branches found
No related tags found
1 merge request!642Fix assignment and perf. improvement in CbmMcbm2018RichPar
Pipeline #14943 passed
......@@ -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)
......@@ -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
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment