23 : m_name(ps.getUntrackedParameter<
std::
string>(
"name",
"EcalTPGOddWeightIdMapHandler")) {
24 edm::LogInfo(
"EcalTPGOddWeightIdMapHandler") <<
"EcalTPGOddWeightIdMap Source handler constructor";
43 if (m_file_type ==
"txt") {
45 }
else if (m_file_type ==
"xml") {
48 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
"Started GetNewObjects!!!";
58 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
" First object for this tag ";
61 unsigned int max_since = 0;
62 max_since =
static_cast<unsigned int>(
tagInfo().lastInterval.since);
63 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
"max_since : " << max_since;
65 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
"retrieved last payload ";
68 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
"Retrieving run list from ONLINE DB ... ";
71 auto econn = std::make_shared<EcalCondDBInterface>(m_sid, m_user, m_pass);
76 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
" connection parameters " << m_sid <<
"/" << m_user;
91 readFromFile(
"last_tpg_OddweightIdMap_settings.txt");
95 if (m_firstRun < m_i_run_number) {
96 min_run = m_i_run_number + 1;
101 if (min_run < max_since) {
102 min_run = max_since + 1;
105 <<
"m_i_run_number" << m_i_run_number <<
"m_firstRun " << m_firstRun <<
"max_since " << max_since;
107 unsigned int max_run = m_lastRun;
108 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
"min_run= " << min_run <<
"max_run= " << max_run;
111 my_list =
econn->fetchGlobalRunListByLocation(my_runtag, min_run, max_run,
my_locdef);
113 std::vector<RunIOV> run_vec = my_list.
getRuns();
114 size_t num_runs = run_vec.size();
115 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
"number of Mon runs is : " << num_runs;
119 for (
size_t kr = 0; kr < run_vec.size(); kr++) {
120 irun =
static_cast<unsigned int>(run_vec[kr].getRunNumber());
127 std::map<EcalLogicID, RunTPGConfigDat>
dataset;
131 int the_config_version = 0;
133 std::map<EcalLogicID, RunTPGConfigDat>::const_iterator it;
146 <<
" run= " << irun <<
" tag " << the_config_tag <<
" version=" << the_config_version;
150 if ((the_config_tag != m_i_tag || the_config_version != m_i_version) &&
nr > 0) {
152 <<
"the tag is different from last transferred run ... retrieving last config set from DB";
159 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
" before fetch config set";
160 econn->fetchConfigSet(&fe_main_info);
161 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
" after fetch config set";
166 if (weightId != m_i_oddweightIdMap) {
168 fe_odd_weight_info.
setId(weightId);
169 econn->fetchConfigSet(&fe_odd_weight_info);
170 std::map<EcalLogicID, FEConfigOddWeightGroupDat> dataset_TpgWeight;
171 econn->fetchDataSet(&dataset_TpgWeight, &fe_odd_weight_info);
174 typedef std::map<EcalLogicID, FEConfigOddWeightGroupDat>::const_iterator CIfeweight;
179 for (CIfeweight
p = dataset_TpgWeight.begin();
p != dataset_TpgWeight.end();
p++) {
183 unsigned int weight0 =
static_cast<unsigned int>(rd_w.
getWeight4());
184 unsigned int weight1 =
static_cast<unsigned int>(rd_w.
getWeight3());
185 unsigned int weight2 =
static_cast<unsigned int>(rd_w.
getWeight2());
186 unsigned int weight3 =
static_cast<unsigned int>(rd_w.
getWeight1() - 0x80);
187 unsigned int weight4 =
static_cast<unsigned int>(rd_w.
getWeight0());
189 w.setValues(weight0, weight1, weight2, weight3, weight4);
195 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
"found " << igroups <<
"Weight groups";
200 m_i_run_number = irun;
201 m_i_tag = the_config_tag;
202 m_i_version = the_config_version;
203 m_i_oddweightIdMap = weightId;
205 writeFile(
"last_tpg_OddweightIdMap_settings.txt");
208 m_i_run_number = irun;
209 m_i_tag = the_config_tag;
210 m_i_version = the_config_version;
212 writeFile(
"last_tpg_OddweightIdMap_settings.txt");
215 <<
" even if the tag/version is not the same, the weightIdMap id is the same -> no transfer needed ";
219 throw cms::Exception(
"FileReadError") <<
"ERROR: THIS CONFIG DOES NOT EXIST: tag=" << the_config_tag
220 <<
" version=" << the_config_version <<
"\n" 225 }
else if (
nr == 0) {
226 m_i_run_number = irun;
228 <<
" no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed ";
231 m_i_run_number = irun;
232 m_i_tag = the_config_tag;
233 m_i_version = the_config_version;
234 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
" the tag/version is the same -> no transfer needed ";
236 writeFile(
"last_tpg_OddweightIdMap_settings.txt");
242 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
"Ecal - > end of getNewObjects -----------";
245 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
" reading the input file " << m_file_name;
246 std::ifstream fInput;
247 fInput.open(m_file_name);
248 if (!fInput.is_open()) {
249 throw cms::Exception(
"FileReadError") <<
"ERROR : cannot open file " << m_file_name;
251 unsigned int wloc[5];
257 while (!fInput.eof()) {
258 getline(fInput,
line);
260 std::stringstream
ss;
262 ss >> wloc[0] >> wloc[1] >> wloc[2] >> wloc[3] >> wloc[4];
263 w.setValues(wloc[0], wloc[1], wloc[2], wloc[3], wloc[4]);
268 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
"found " << igroups <<
" Weight groups";
273 throw cms::Exception(
"FileReadError") <<
"EcalTPGOddWeightIdMapHandler::readtxtFile error : " <<
e.what();
279 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
" reading the input file " << m_file_name;
281 fxml.open(m_file_name);
282 if (!fxml.is_open()) {
283 throw cms::Exception(
"FileReadError") <<
"ERROR: Cannot open file : " << m_file_name;
286 unsigned int wloc[5];
290 int ngroups, igroups;
291 for (
int i = 0;
i < 5;
i++)
292 std::getline(fxml, dummyLine);
296 std::istringstream sc(stt);
298 edm::LogVerbatim(
"EcalTPGOddWeightIdMapHandler") <<
"found " << ngroups <<
" Weight groups";
299 for (
int i = 0;
i < 2;
i++)
300 std::getline(fxml, dummyLine);
301 for (
int i = 0;
i < ngroups;
i++) {
302 std::getline(fxml, dummyLine);
304 std::size_t
found = bid.find(
"</");
305 stt = bid.substr(7,
found - 7);
306 std::istringstream sg1(stt);
309 throw cms::Exception(
"MismatchError") <<
"ERROR in group " <<
i <<
": " << bid <<
" igroups " << igroups;
311 for (
int i = 0;
i < 2;
i++)
312 std::getline(fxml, dummyLine);
313 for (
int i = 0;
i < 5;
i++) {
315 found = bid.find(
"</");
316 stt = bid.substr(5,
found - 5);
317 std::istringstream
w(stt);
320 w.setValues(wloc[0], wloc[1], wloc[2], wloc[3], wloc[4]);
322 for (
int i = 0;
i < 3;
i++)
323 std::getline(fxml, dummyLine);
330 throw cms::Exception(
"FileReadError") <<
"EcalTPGOddWeightIdMapHandler::readxmlFile error : " <<
e.what();
341 m_i_oddweightIdMap = 0;
352 std::ostringstream
str;
354 fgets(
line, 255, inpFile);
356 str <<
"gen tag " << m_i_tag << std::endl;
358 fgets(
line, 255, inpFile);
359 m_i_version = atoi(
line);
360 str <<
"version= " << m_i_version << std::endl;
362 fgets(
line, 255, inpFile);
363 m_i_run_number = atoi(
line);
364 str <<
"run_number= " << m_i_run_number << std::endl;
366 fgets(
line, 255, inpFile);
367 m_i_oddweightIdMap = atoi(
line);
368 str <<
"weightIdMap_config= " << m_i_oddweightIdMap << std::endl;
376 std::ofstream myfile;
378 myfile << m_i_tag << std::endl;
379 myfile << m_i_version << std::endl;
380 myfile << m_i_run_number << std::endl;
381 myfile << m_i_oddweightIdMap << std::endl;
Log< level::Info, true > LogVerbatim
void setRunTypeDef(const RunTypeDef &runTypeDef)
std::vector< RunIOV > getRuns()
T getParameter(std::string const &) const
EcalTPGOddWeightIdMapHandler(edm::ParameterSet const &)
void readFromFile(const char *inputFile)
Log< level::Error, false > LogError
static std::string to_string(const XMLCh *ch)
~EcalTPGOddWeightIdMapHandler() override
void setLocationDef(const LocationDef &locDef)
void getNewObjects() override
void setValue(const uint32_t &id, const EcalTPGWeights &value)
Log< level::Info, false > LogInfo
void writeFile(const char *inputFile)
std::string m_locationsource
std::string getConfigTag() const
void setConfigTag(std::string x)
void setGeneralTag(std::string tag)
int getWeightGroupId() const