Skip to content

Commit b3f748c

Browse files
committed
update with MessageLogger, from_chars(), etc.
1 parent 520ab39 commit b3f748c

File tree

6 files changed

+36
-21
lines changed

6 files changed

+36
-21
lines changed

CondFormats/HGCalObjects/interface/HGCalMappingParameterSoA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace hgcal {
3535
SOA_COLUMN(bool, valid),
3636
SOA_COLUMN(bool, isHD),
3737
SOA_COLUMN(bool, iscalib),
38-
SOA_COLUMN(int, offset),
38+
SOA_COLUMN(int, caliboffset),
3939
SOA_COLUMN(bool, isSiPM),
4040
SOA_COLUMN(uint16_t, typeidx),
4141
SOA_COLUMN(uint16_t, chip),

Geometry/HGCalMapping/plugins/alpaka/HGCalMappingCellESProducer.cc

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "FWCore/ParameterSet/interface/FileInPath.h"
2+
#include "FWCore/MessageLogger/interface/MessageLogger.h"
23
#include "FWCore/ParameterSet/interface/ParameterSet.h"
34
#include "FWCore/Utilities/interface/ESGetToken.h"
45

@@ -21,6 +22,7 @@
2122
#include <iostream>
2223
#include <fstream>
2324
#include <sstream>
25+
#include <charconv>
2426

2527
namespace ALPAKA_ACCELERATOR_NAMESPACE {
2628

@@ -32,7 +34,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
3234
HGCalMappingCellESProducer(const edm::ParameterSet& iConfig)
3335
: ESProducer(iConfig),
3436
filelist_(iConfig.getParameter<std::vector<std::string> >("filelist")),
35-
offsetfile_(iConfig.getParameter<std::string>("offsetfile")) {
37+
offsetfile_(iConfig.getParameter<edm::FileInPath>("offsetfile")) {
3638
auto cc = setWhatProduced(this);
3739
cellIndexTkn_ = cc.consumes(iConfig.getParameter<edm::ESInputTag>("cellindexer"));
3840
}
@@ -43,14 +45,16 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
4345
desc.add<std::vector<std::string> >("filelist", std::vector<std::string>({}))
4446
->setComment("list of files with the readout cells of each module");
4547
desc.add<edm::ESInputTag>("cellindexer", edm::ESInputTag(""))->setComment("Dense cell index tool");
46-
desc.add<std::string>("offsetfile", std::string({}))
48+
desc.add<edm::FileInPath>(
49+
"offsetfile",
50+
edm::FileInPath("Geometry/HGCalMapping/data/CellMaps/calibration_to_surrounding_offsetMap.txt"))
4751
->setComment("file containing the offsets between calibration and surrounding cells");
4852
descriptions.addWithDefaultLabel(desc);
4953
}
5054

51-
std::map<std::tuple<std::string, int, int>, int> makeOffsetMap(std::string input_offsetfile) {
55+
std::map<std::tuple<std::string, int, int>, int> makeOffsetMap(edm::FileInPath input_offsetfile) {
5256
std::map<std::tuple<std::string, int, int>, int> offsetMap;
53-
auto offsetfile = edm::FileInPath(input_offsetfile).fullPath();
57+
const auto& offsetfile = input_offsetfile.fullPath();
5458
std::ifstream stream_offsetfile(offsetfile);
5559
std::string line;
5660
// Skip the first line (description of column content)
@@ -59,21 +63,27 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
5963
std::istringstream iss(line);
6064
std::string r_typecode_str, r_chip_str, r_half_str, offset_str;
6165
if (!(iss >> r_typecode_str >> r_chip_str >> r_half_str >> offset_str)) {
62-
std::cout << "Error reading offset file" << std::endl;
66+
edm::LogError("HGCalMappingCellESProducer") << "Error reading offset file" << std::endl;
6367
break;
6468
}
65-
try {
66-
int r_chip = std::stoi(r_chip_str);
67-
int r_half = std::stoi(r_half_str);
68-
int offset = std::stoi(offset_str);
69-
offsetMap[std::make_tuple(r_typecode_str, r_chip, r_half)] = offset;
70-
} catch (const std::invalid_argument& e) {
71-
std::cout << "Invalid argument: " << e.what() << std::endl;
72-
break;
73-
} catch (const std::out_of_range& e) {
74-
std::cout << "Out of range: " << e.what() << std::endl;
69+
70+
int r_chip, r_half, offset;
71+
auto parse_entry = [](const std::string& str, int& value) -> bool {
72+
const char* begin = str.data();
73+
const char* end = begin + str.size();
74+
auto result = std::from_chars(begin, end, value);
75+
return result.ec == std::errc();
76+
};
77+
78+
if (!parse_entry(r_chip_str, r_chip) || !parse_entry(r_half_str, r_half) ||
79+
!parse_entry(offset_str, offset)) {
80+
edm::LogError("HGCalMappingCellESProducer")
81+
<< "Error parsing offset file entries (typecode, roc, halfroc, and offset): " << r_typecode_str << ", "
82+
<< r_chip_str << ", " << r_half_str << ", " << offset_str << "\n";
7583
break;
7684
}
85+
86+
offsetMap[std::make_tuple(r_typecode_str, r_chip, r_half)] = offset;
7787
}
7888
return offsetMap;
7989
}
@@ -153,7 +163,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
153163
//calibration cell-to-surrounding cell offset. Can be !=0 only for calibration cells
154164
auto mapKey = std::make_tuple(typecode, chip, half);
155165
int offset = (iscalib && offsetMap.find(mapKey) != offsetMap.end()) ? offsetMap[mapKey] : 0;
156-
cell.offset() = offset;
166+
cell.caliboffset() = offset;
157167

158168
} //end loop over entities
159169
} //end loop over cell types
@@ -164,7 +174,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
164174
private:
165175
edm::ESGetToken<HGCalMappingCellIndexer, HGCalElectronicsMappingRcd> cellIndexTkn_;
166176
const std::vector<std::string> filelist_;
167-
std::string offsetfile_;
177+
edm::FileInPath offsetfile_;
168178
};
169179

170180
} // namespace hgcal

Geometry/HGCalMapping/python/hgcalmapping_cff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def customise_hgcalmapper(process,
2020
process.hgCalMappingCellESProducer = cms.ESProducer('hgcal::HGCalMappingCellESProducer@alpaka',
2121
filelist=cms.vstring(sicells, sipmcells),
2222
cellindexer=cms.ESInputTag(''),
23-
offsetfile=cms.string(offsetfile))
23+
offsetfile=cms.FileInPath(offsetfile))
2424
process.hgCalMappingModuleESProducer = cms.ESProducer('hgcal::HGCalMappingModuleESProducer@alpaka',
2525
filename=cms.FileInPath(modules),
2626
moduleindexer=cms.ESInputTag(''))

Geometry/HGCalMapping/test/testMappingModuleIndexer_cfg.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
info="Path to Si cell mapper. Absolute, or relative to CMSSW src directory")
1010
options.register('sipmcells','Geometry/HGCalMapping/data/CellMaps/channels_sipmontile.hgcal.txt',mytype=VarParsing.varType.string,
1111
info="Path to SiPM-on-tile cell mapper. Absolute, or relative to CMSSW src directory")
12+
options.register('offsetfile','Geometry/HGCalMapping/data/CellMaps/calibration_to_surrounding_offsetMap.txt',mytype=VarParsing.varType.cms.FileInPath,
13+
info="Path to calibration-to-surrounding cell offset file. Absolute, or relative to CMSSW src directory")
14+
1215
options.parseArguments()
1316

1417
process.source = cms.Source('EmptySource')
@@ -22,7 +25,8 @@
2225
process = customise_hgcalmapper(process,
2326
modules=options.modules,
2427
sicells=options.sicells,
25-
sipmcells=options.sipmcells)
28+
sipmcells=options.sipmcells,
29+
offsetfile=options.offsetfile)
2630

2731
#Geometry
2832
process.load('Configuration.Geometry.GeometryExtended2026D99Reco_cff')

RecoLocalCalo/HGCalRecAlgos/plugins/alpaka/HGCalRecHitCalibrationAlgorithms.dev.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
157157

158158
auto cellIndex = index[idx].cellInfoIdx();
159159
bool isCalibCell(maps[cellIndex].iscalib());
160-
int offset = maps[cellIndex].offset();
160+
int offset = maps[cellIndex].caliboffset(); //Calibration-to-surrounding cell offset
161161
bool is_surr_cell((offset != 0) && isAvailable && isCalibCell);
162162

163163
//Effectively operate only on the cell that surrounds the calibration cells

RecoLocalCalo/HGCalRecAlgos/plugins/alpaka/HGCalRecHitProducers.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
177177
deviceConfigParamProvider,
178178
deviceMappingCellParamProvider,
179179
deviceIndexingParamProvider);
180+
180181
#endif
181182

182183
#ifdef EDM_ML_DEBUG

0 commit comments

Comments
 (0)