23 : m_name(ps.getUntrackedParameter<
std::
string>(
"name",
"EcalTPGWeightIdMapHandler")) {
24 edm::LogInfo(
"EcalTPGWeightIdMapHandler") <<
"EcalTPGWeightIdMap Source handler constructor";
43 if (m_file_type ==
"txt") {
45 }
else if (m_file_type ==
"xml") {
48 edm::LogInfo(
"EcalTPGWeightIdMapHandler") <<
"Started GetNewObjects!!!";
60 unsigned int max_since = 0;
61 max_since =
static_cast<unsigned int>(
tagInfo().lastInterval.since);
62 edm::LogInfo(
"EcalTPGWeightIdMapHandler") <<
"max_since : " << max_since;
63 Ref weightIdMap_db = lastPayload();
65 edm::LogInfo(
"EcalTPGWeightIdMapHandler") <<
"retrieved last payload ";
68 edm::LogInfo(
"EcalTPGWeightIdMapHandler") <<
"Retrieving run list from ONLINE DB ... ";
70 edm::LogInfo(
"EcalTPGWeightIdMapHandler") <<
"Making connection...";
75 edm::LogInfo(
" connection parameters ") << m_sid <<
"/" << m_user;
91 readFromFile(
"last_tpg_weightIdMap_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 edm::LogInfo(
"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::LogInfo(
"EcalTPGWeightIdMapHandler") <<
"min_run= " << min_run <<
"max_run= " << max_run;
111 my_list =
econn->fetchGlobalRunListByLocation(my_runtag, min_run, max_run,
my_locdef);
114 std::vector<RunIOV> run_vec = my_list.
getRuns();
115 size_t num_runs = run_vec.size();
116 edm::LogInfo(
"EcalTPGWeightIdMapHandler") <<
"number of Mon runs is : " << num_runs;
120 for (
size_t kr = 0; kr < run_vec.size(); kr++) {
121 irun =
static_cast<unsigned int>(run_vec[kr].getRunNumber());
126 std::map<EcalLogicID, RunTPGConfigDat>
dataset;
130 int the_config_version = 0;
132 std::map<EcalLogicID, RunTPGConfigDat>::const_iterator it;
145 edm::LogInfo(
" run= ") << irun <<
" tag " << the_config_tag <<
" version=" << the_config_version;
149 if ((the_config_tag != m_i_tag || the_config_version != m_i_version) &&
nr > 0) {
150 edm::LogInfo(
"the tag is different from last transferred run ... retrieving last config set from DB");
157 econn->fetchConfigSet(&fe_main_info);
160 int weightId = fe_main_info.
getWeiId();
162 if (weightId != m_i_weightIdMap) {
164 fe_weight_info.
setId(weightId);
165 econn->fetchConfigSet(&fe_weight_info);
166 std::map<EcalLogicID, FEConfigWeightGroupDat> dataset_TpgWeight;
167 econn->fetchDataSet(&dataset_TpgWeight, &fe_weight_info);
168 edm::LogInfo(
"EcalTPGWeightIdMapHandler") <<
"Got object!";
170 typedef std::map<EcalLogicID, FEConfigWeightGroupDat>::const_iterator CIfeweight;
175 for (CIfeweight
p = dataset_TpgWeight.begin();
p != dataset_TpgWeight.end();
p++) {
179 unsigned int weight0 =
static_cast<unsigned int>(rd_w.
getWeight4());
180 unsigned int weight1 =
static_cast<unsigned int>(rd_w.
getWeight3());
181 unsigned int weight2 =
static_cast<unsigned int>(rd_w.
getWeight2());
182 unsigned int weight3 =
static_cast<unsigned int>(rd_w.
getWeight1() - 0x80);
183 unsigned int weight4 =
static_cast<unsigned int>(rd_w.
getWeight0());
185 w.setValues(weight0, weight1, weight2, weight3, weight4);
191 edm::LogInfo(
"EcalTPGWeightIdMapHandler") <<
"found " << igroups <<
"Weight groups";
196 m_i_run_number = irun;
197 m_i_tag = the_config_tag;
198 m_i_version = the_config_version;
199 m_i_weightIdMap = weightId;
201 writeFile(
"last_tpg_weightIdMap_settings.txt");
204 m_i_run_number = irun;
205 m_i_tag = the_config_tag;
206 m_i_version = the_config_version;
208 writeFile(
"last_tpg_weightIdMap_settings.txt");
211 " even if the tag/version is not the same, the weightIdMap id is the same -> no transfer needed ");
216 << the_config_tag <<
" version=" << the_config_version;
218 m_i_run_number = irun;
221 }
else if (
nr == 0) {
222 m_i_run_number = irun;
223 edm::LogInfo(
" no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor, no transfer needed ");
225 m_i_run_number = irun;
226 m_i_tag = the_config_tag;
227 m_i_version = the_config_version;
228 edm::LogInfo(
" the tag/version is the same, no transfer needed ");
229 writeFile(
"last_tpg_weightIdMap_settings.txt");
236 edm::LogInfo(
"EcalTPGWeightIdMapHandler") <<
"Ecal - > end of getNewObjects -----------";
239 edm::LogInfo(
" reading the input file ") << m_file_name;
240 std::ifstream fInput;
241 fInput.open(m_file_name);
242 if (!fInput.is_open()) {
243 edm::LogInfo(
"ERROR : cannot open file ") << m_file_name;
246 unsigned int wloc[5];
251 while (!fInput.eof()) {
252 getline(fInput,
line);
254 std::stringstream
ss;
256 ss >> wloc[0] >> wloc[1] >> wloc[2] >> wloc[3] >> wloc[4];
258 w.setValues(wloc[0], wloc[1], wloc[2], wloc[3], wloc[4]);
263 edm::LogInfo(
"EcalTPGWeightIdMapHandler") <<
"found " << igroups <<
" Weight groups";
268 edm::LogInfo(
"EcalTPGWeightIdMapHandler::readtxtFile error : ") <<
e.what();
273 edm::LogInfo(
" reading the input file ") << m_file_name;
275 fxml.open(m_file_name);
276 if (!fxml.is_open()) {
277 edm::LogInfo(
"ERROR : cannot open file ") << m_file_name;
281 unsigned int wloc[5];
284 int ngroups, igroups = 0;
285 edm::LogInfo(
"EcalTPGWeightIdMapHandler") <<
"found " << igroups <<
"Weight groups";
286 for (
int i = 0;
i < 5;
i++)
287 std::getline(fxml, dummyLine);
291 std::istringstream sc(stt);
293 edm::LogInfo(
"EcalTPGWeightIdMapHandler") <<
"found " << ngroups <<
" Weight groups";
294 for (
int i = 0;
i < 2;
i++)
295 std::getline(fxml, dummyLine);
296 for (
int i = 0;
i < ngroups;
i++) {
297 std::getline(fxml, dummyLine);
300 std::size_t
found = bid.find(
"</");
301 stt = bid.substr(7,
found - 7);
302 std::istringstream sg1(stt);
305 edm::LogInfo(
" group ") <<
i <<
": " << bid <<
" igroups " << igroups;
308 for (
int i = 0;
i < 2;
i++)
309 std::getline(fxml, dummyLine);
310 for (
int i = 0;
i < 5;
i++) {
312 found = bid.find(
"</");
313 stt = bid.substr(5,
found - 5);
314 std::istringstream
w(stt);
317 w.setValues(wloc[0], wloc[1], wloc[2], wloc[3], wloc[4]);
319 for (
int i = 0;
i < 3;
i++)
320 std::getline(fxml, dummyLine);
327 edm::LogInfo(
"EcalTPGWeightIdMapHandler::readxmlFile error : ") <<
e.what();
348 std::ostringstream
str;
350 fgets(
line, 255, inpFile);
352 str <<
"gen tag " << m_i_tag << std::endl;
354 fgets(
line, 255, inpFile);
355 m_i_version = atoi(
line);
356 str <<
"version= " << m_i_version << std::endl;
358 fgets(
line, 255, inpFile);
359 m_i_run_number = atoi(
line);
360 str <<
"run_number= " << m_i_run_number << std::endl;
362 fgets(
line, 255, inpFile);
363 m_i_weightIdMap = atoi(
line);
364 str <<
"weightIdMap_config= " << m_i_weightIdMap << std::endl;
372 std::ofstream myfile;
374 myfile << m_i_tag << std::endl;
375 myfile << m_i_version << std::endl;
376 myfile << m_i_run_number << std::endl;
377 myfile << m_i_weightIdMap << std::endl;
~EcalTPGWeightIdMapHandler() override
void setRunTypeDef(const RunTypeDef &runTypeDef)
std::vector< RunIOV > getRuns()
T getParameter(std::string const &) const
void readFromFile(const char *inputFile)
void getNewObjects() override
void writeFile(const char *inputFile)
Log< level::Error, false > LogError
static std::string to_string(const XMLCh *ch)
void setLocationDef(const LocationDef &locDef)
Log< level::Info, false > LogInfo
void setValue(const uint32_t &id, const EcalTPGWeights &value)
EcalTPGWeightIdMapHandler(edm::ParameterSet const &)
std::string getConfigTag() const
std::unique_ptr< EcalTPGWeightIdMap > Ref
void setConfigTag(std::string x)
void setGeneralTag(std::string tag)
std::string m_locationsource
int getWeightGroupId() const