21 #include <unordered_map>
58 s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](
int ch) {
return !std::isspace(ch); }));
63 s.erase(std::find_if(s.rbegin(), s.rend(), [](
int ch) {
return !std::isspace(ch); }).
base(), s.end());
101 desc.
setComment(
"Stores a TrackerDetToDTCELinkCablingMap object into the database from a CSV file.");
103 desc.
add<
int>(
"verbosity", 0);
104 desc.
add<
unsigned>(
"csvFormat_ncolumns", 15);
105 desc.
add<
unsigned>(
"csvFormat_idetid", 0);
106 desc.
add<
unsigned>(
"csvFormat_idtcid", 0);
107 desc.
add<
unsigned>(
"csvFormat_igbtlinkid", 0);
108 desc.
add<
unsigned>(
"csvFormat_ielinkid", 0);
109 desc.
add<
long long unsigned int>(
"iovBeginTime", 1);
111 desc.
add<std::vector<std::string>>(
"modulesToDTCCablingCSVFileNames", std::vector<std::string>());
112 descriptions.
add(
"DTCCablingMapProducer", desc);
116 : verbosity_(iConfig.getParameter<int>(
"verbosity")),
117 csvFormat_ncolumns_(iConfig.getParameter<unsigned>(
"csvFormat_ncolumns")),
118 csvFormat_idetid_(iConfig.getParameter<unsigned>(
"csvFormat_idetid")),
119 csvFormat_idtcid_(iConfig.getParameter<unsigned>(
"csvFormat_idtcid")),
120 csvFormat_igbtlinkid_(iConfig.getParameter<unsigned>(
"csvFormat_igbtlinkid")),
121 csvFormat_ielinkid_(iConfig.getParameter<unsigned>(
"csvFormat_ielinkid")),
122 iovBeginTime_(iConfig.getParameter<long long unsigned int>(
"iovBeginTime")),
124 record_(iConfig.getParameter<std::
string>(
"record")) {
128 if (dummy_fill_mode_param ==
"DUMMY_FILL_DISABLED")
130 else if (dummy_fill_mode_param ==
"DUMMY_FILL_ELINK_ID")
132 else if (dummy_fill_mode_param ==
"DUMMY_FILL_ELINK_ID_AND_GBT_ID")
136 <<
"Parameter dummy_fill_mode with invalid value: " << dummy_fill_mode_param;
145 std::vector<std::string>
const& modulesToDTCCablingCSVFileNames) {
148 for (
std::string const& csvFileName : modulesToDTCCablingCSVFileNames) {
152 csvFile.open(csvFilePath.
fullPath().c_str());
154 if (csvFile.is_open()) {
157 unsigned lineNumber = 0;
159 while (std::getline(csvFile, csvLine)) {
161 edm::LogInfo(
"CSVParser") <<
"Reading CSV file line: " << ++lineNumber <<
": \"" << csvLine <<
"\"" << endl;
164 istringstream csvStream(csvLine);
165 vector<string> csvColumn;
168 while (std::getline(csvStream, csvElement,
',')) {
170 csvColumn.push_back(csvElement);
174 ostringstream splitted_line_info;
176 splitted_line_info <<
"-- split line is: [";
178 for (
string const&
s : csvColumn)
179 splitted_line_info <<
"\"" <<
s <<
"\", ";
181 splitted_line_info <<
"]" << endl;
190 edm::LogInfo(
"CSVParser") <<
"-- skipping legend line" << endl;
201 edm::LogError(
"CSVParser") <<
"-- malformed DetId string in CSV file: \"" << csvLine <<
"\"" << endl;
206 unsigned const dtc_id = strtoul(csvColumn.at(
csvFormat_idtcid_).c_str(),
nullptr, 10);
227 goto gbtlink_and_elinkid_generator_end;
230 gbtlink_and_elinkid_generator_end:
235 DTCELinkId dtcELinkId(dtc_id, gbt_id, elink_id);
238 edm::LogInfo(
"CSVParser") <<
"-- DetId = " << detIdRaw <<
" (dtc_id, gbt_id, elink_id) = (" << dtc_id <<
","
239 << gbt_id <<
"," << elink_id <<
")" << endl;
244 <<
"Reading CSV file: CRITICAL ERROR, duplicate dtcELinkId entry about (dtc_id, gbt_id, elink_id) = ("
245 << dtc_id <<
"," << gbt_id <<
"," << elink_id <<
")";
251 edm::LogInfo(
"CSVParser") <<
"Reading CSV file: Skipped a short line: \"" << csvLine <<
"\"" << endl;
256 throw cms::Exception(
"CSVFileNotFound") <<
"Unable to open input CSV file" << csvFilePath << endl;
271 if (poolDbService.isAvailable()) {
274 throw cms::Exception(
"PoolDBServiceNotFound") <<
"A running PoolDBService instance is required.";
bool compare(const P &i, const P &j)
DTCCablingMapProducer(const edm::ParameterSet &)
static constexpr const unsigned int gbt_id_minvalue
unsigned csvFormat_idetid_
#define DEFINE_FWK_MODULE(type)
static void trim(std::string &s)
Log< level::Error, false > LogError
unsigned csvFormat_idtcid_
unsigned csvFormat_ncolumns_
static void ltrim(std::string &s)
unsigned csvFormat_igbtlinkid_
void setComment(std::string const &value)
unsigned long long Time_t
unsigned csvFormat_ielinkid_
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static constexpr const unsigned int elink_id_minvalue
static void rtrim(std::string &s)
Log< level::Info, false > LogInfo
void analyze(const edm::Event &, const edm::EventSetup &) override
T getParameter(std::string const &) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
cond::Time_t iovBeginTime_
std::string fullPath() const
~DTCCablingMapProducer() override
static constexpr const unsigned int elink_id_maxvalue
std::unique_ptr< TrackerDetToDTCELinkCablingMap > pCablingMap_
static constexpr const unsigned int gbt_id_maxvalue
virtual void LoadModulesToDTCCablingMapFromCSV(std::vector< std::string > const &)