Skip to content

Commit 7557a79

Browse files
authored
Add protections to avoid mismatches with LUT header (#94)
1 parent 0df8365 commit 7557a79

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/TrackSmearer.cc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,39 @@ namespace delphes
1515
/*****************************************************************/
1616

1717
bool
18-
TrackSmearer::loadTable(int pdg, const char *filename)
18+
TrackSmearer::loadTable(int pdg, const char *filename, bool forceReload)
1919
{
2020
auto ipdg = getIndexPDG(pdg);
21+
if (mLUTHeader[ipdg] && !forceReload) {
22+
std::cout << " --- LUT table for PDG " << pdg << " has been already loaded " << std::endl;
23+
return false;
24+
}
2125
mLUTHeader[ipdg] = new lutHeader_t;
2226

2327
std::ifstream lutFile(filename, std::ifstream::binary);
2428
if (!lutFile.is_open()) {
2529
std::cout << " --- cannot open covariance matrix file for PDG " << pdg << ": " << filename << std::endl;
30+
delete mLUTHeader[ipdg];
31+
mLUTHeader[ipdg] = nullptr;
2632
return false;
2733
}
2834
lutFile.read(reinterpret_cast<char *>(mLUTHeader[ipdg]), sizeof(lutHeader_t));
2935
if (lutFile.gcount() != sizeof(lutHeader_t)) {
3036
std::cout << " --- troubles reading covariance matrix header for PDG " << pdg << ": " << filename << std::endl;
37+
delete mLUTHeader[ipdg];
38+
mLUTHeader[ipdg] = nullptr;
3139
return false;
3240
}
3341
if (mLUTHeader[ipdg]->version != LUTCOVM_VERSION) {
3442
std::cout << " --- LUT header version mismatch: expected/detected = " << LUTCOVM_VERSION << "/" << mLUTHeader[ipdg]->version << std::endl;
43+
delete mLUTHeader[ipdg];
44+
mLUTHeader[ipdg] = nullptr;
45+
return false;
46+
}
47+
if (mLUTHeader[ipdg]->pdg != pdg) {
48+
std::cout << " --- LUT header PDG mismatch: expected/detected = " << pdg << "/" << mLUTHeader[ipdg]->pdg << std::endl;
49+
delete mLUTHeader[ipdg];
50+
mLUTHeader[ipdg] = nullptr;
3551
return false;
3652
}
3753
const int nnch = mLUTHeader[ipdg]->nchmap.nbins;

src/TrackSmearer.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public:
2323
~TrackSmearer() = default;
2424

2525
/** LUT methods **/
26-
bool loadTable(int pdg, const char *filename);
26+
bool loadTable(int pdg, const char *filename, bool forceReload = false);
2727
void useEfficiency(bool val) { mUseEfficiency = val; };
2828
lutHeader_t *getLUTHeader(int pdg) { return mLUTHeader[getIndexPDG(pdg)]; };
2929
lutEntry_t *getLUTEntry(int pdg, float nch, float radius, float eta, float pt);

0 commit comments

Comments
 (0)