CMS 3D CMS Logo

EcalTPGFineGrainTowerEEHandler.cc
Go to the documentation of this file.
10 
11 #include <iostream>
12 
14  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalTPGFineGrainTowerEEHandler")) {
15  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "EcalTPGFineGrainTowerEE Source handler constructor.";
16  m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
17  m_lastRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("lastRun").c_str()));
18  m_sid = ps.getParameter<std::string>("OnlineDBSID");
19  m_user = ps.getParameter<std::string>("OnlineDBUser");
20  m_pass = ps.getParameter<std::string>("OnlineDBPassword");
21  m_locationsource = ps.getParameter<std::string>("LocationSource");
22  m_location = ps.getParameter<std::string>("Location");
23  m_gentag = ps.getParameter<std::string>("GenTag");
24  m_runtype = ps.getParameter<std::string>("RunType");
25 
26  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << m_sid << "/" << m_user << "/" << m_location << "/" << m_gentag;
27 }
28 
30 
32  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "Started GetNewObjects!!!";
33 
34  //check whats already inside of database
35  if (tagInfo().size) {
36  //check whats already inside of database
37  std::cout << "got offlineInfo = " << std::endl;
38  std::cout << "tag name = " << tagInfo().name << std::endl;
39  std::cout << "size = " << tagInfo().size << std::endl;
40  } else {
41  std::cout << " First object for this tag " << std::endl;
42  }
43 
44  unsigned int max_since = 0;
45  max_since = static_cast<unsigned int>(tagInfo().lastInterval.since);
46  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "max_since : " << max_since;
47  Ref fgrTTEE_db = lastPayload();
48 
49  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "retrieved last payload ";
50 
51  // here we retrieve all the runs after the last from online DB
52  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "Retrieving run list from ONLINE DB ... ";
53 
54  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "Making connection...";
55  econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
56  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "Done.";
57 
58  if (!econn) {
59  std::cout << " connection parameters " << m_sid << "/" << m_user << std::endl;
60  // cerr << e.what() << std::endl;
61  throw cms::Exception("OMDS not available");
62  }
63 
65  my_locdef.setLocation(m_location);
66 
68  my_rundef.setRunType(m_runtype);
69 
70  RunTag my_runtag;
71  my_runtag.setLocationDef(my_locdef);
72  my_runtag.setRunTypeDef(my_rundef);
73  my_runtag.setGeneralTag(m_gentag);
74 
75  readFromFile("last_tpg_fgrTTEE_settings.txt");
76 
77  unsigned int min_run = m_i_run_number + 1;
78 
79  if (m_firstRun < m_i_run_number) {
80  min_run = m_i_run_number + 1;
81  } else {
82  min_run = m_firstRun;
83  }
84  if (min_run < max_since) {
85  min_run = max_since + 1; // we have to add 1 to the last transferred one
86  }
87 
88  std::cout << "m_i_run_number" << m_i_run_number << "m_firstRun " << m_firstRun << "max_since " << max_since
89  << std::endl;
90 
91  unsigned int max_run = m_lastRun;
92  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "min_run= " << min_run << " max_run= " << max_run;
93 
94  RunList my_list;
95  my_list = econn->fetchGlobalRunListByLocation(my_runtag, min_run, max_run, my_locdef);
96  // my_list=econn->fetchRunListByLocation(my_runtag,min_run,max_run,my_locdef);
97 
98  std::vector<RunIOV> run_vec = my_list.getRuns();
99  size_t num_runs = run_vec.size();
100 
101  std::cout << "number of runs is : " << num_runs << std::endl;
102 
103  unsigned int irun;
104  if (num_runs > 0) {
105  // going to query the ecal logic id
106  std::vector<EcalLogicID> my_TTEcalLogicId_EE;
107  my_TTEcalLogicId_EE = econn->getEcalLogicIDSetOrdered(
108  "EE_trigger_tower", 1, 200, 1, 70, EcalLogicID::NULLID, EcalLogicID::NULLID, "EE_offline_towerid", 12);
109  std::cout << " GOT the logic ID for the EE trigger towers " << std::endl;
110 
111  for (size_t kr = 0; kr < run_vec.size(); kr++) {
112  irun = static_cast<unsigned int>(run_vec[kr].getRunNumber());
113 
114  std::cout << " **************** " << std::endl;
115  std::cout << " **************** " << std::endl;
116  std::cout << " run= " << irun << std::endl;
117 
118  // retrieve the data
119  std::map<EcalLogicID, RunTPGConfigDat> dataset;
120  econn->fetchDataSet(&dataset, &run_vec[kr]);
121 
122  std::string the_config_tag = "";
123  int the_config_version = 0;
124 
125  std::map<EcalLogicID, RunTPGConfigDat>::const_iterator it;
126 
127  int nr = 0;
128  for (it = dataset.begin(); it != dataset.end(); it++) {
129  ++nr;
130  EcalLogicID ecalid = it->first;
131  RunTPGConfigDat dat = it->second;
132  the_config_tag = dat.getConfigTag();
133  the_config_version = dat.getVersion();
134  }
135 
136  // it is all the same for all SM... get the last one
137 
138  std::cout << " run= " << irun << " tag " << the_config_tag << " version=" << the_config_version << std::endl;
139 
140  // here we should check if it is the same as previous run.
141 
142  if ((the_config_tag != m_i_tag || the_config_version != m_i_version) && nr > 0) {
143  std::cout << "the tag is different from last transferred run ... retrieving last config set from DB"
144  << std::endl;
145 
146  FEConfigMainInfo fe_main_info;
147  fe_main_info.setConfigTag(the_config_tag);
148  fe_main_info.setVersion(the_config_version);
149 
150  try {
151  std::cout << " before fetch config set" << std::endl;
152  econn->fetchConfigSet(&fe_main_info);
153  std::cout << " after fetch config set" << std::endl;
154 
155  // now get TPGFineGrainTowerEE
156  int fgrId = fe_main_info.getFgrId();
157 
158  if (fgrId != m_i_fgrTTEE) {
159  FEConfigFgrInfo fe_fgr_info;
160  fe_fgr_info.setId(fgrId);
161  econn->fetchConfigSet(&fe_fgr_info);
162  std::map<EcalLogicID, FEConfigFgrEETowerDat> dataset_TpgFineGrainEE;
163  econn->fetchDataSet(&dataset_TpgFineGrainEE, &fe_fgr_info);
165 
166  typedef std::map<EcalLogicID, FEConfigFgrEETowerDat>::const_iterator CIfefgr;
167  EcalLogicID ecid_xt;
168  FEConfigFgrEETowerDat rd_fgr;
169  int itowers = 0;
170 
171  for (CIfefgr p = dataset_TpgFineGrainEE.begin(); p != dataset_TpgFineGrainEE.end(); p++) {
172  ecid_xt = p->first;
173  rd_fgr = p->second;
174 
175  std::string ecid_name = ecid_xt.getName();
176 
177  if (ecid_name == "EE_trigger_tower") {
178  int tccid = ecid_xt.getID1();
179  // TT number
180  int towerid = ecid_xt.getID2();
181 
182  bool set_the_tower = false;
183  int towid;
184  for (size_t itower = 0; itower < my_TTEcalLogicId_EE.size(); itower++) {
185  if (!set_the_tower) {
186  if (my_TTEcalLogicId_EE[itower].getID1() == tccid &&
187  my_TTEcalLogicId_EE[itower].getID2() == towerid) {
188  towid = my_TTEcalLogicId_EE[itower].getLogicID();
189  set_the_tower = true;
190  break;
191  }
192  }
193  }
194 
195  if (set_the_tower) {
196  fgrMap->setValue(towid, rd_fgr.getLUTValue());
197 
198  } else {
199  std::cout << " these may be the additional towers TCC/TT " << tccid << "/" << towerid << std::endl;
200  }
201 
202  ++itowers;
203  }
204  }
205 
206  Time_t snc = (Time_t)irun;
207 
208  m_to_transfer.push_back(std::make_pair((EcalTPGFineGrainTowerEE *)fgrMap, snc));
209 
210  m_i_run_number = irun;
211  m_i_tag = the_config_tag;
212  m_i_version = the_config_version;
213  m_i_fgrTTEE = fgrId;
214 
215  writeFile("last_tpg_fgrTTEE_settings.txt");
216 
217  } else {
218  m_i_run_number = irun;
219  m_i_tag = the_config_tag;
220  m_i_version = the_config_version;
221 
222  writeFile("last_tpg_fgrTTEE_settings.txt");
223 
224  std::cout << " even if the tag/version is not the same, the fgrTTEE id is the same -> no transfer needed "
225  << std::endl;
226  }
227 
228  } catch (std::exception &e) {
229  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" << the_config_tag << " version=" << the_config_version
230  << std::endl;
231  std::cout << e.what() << std::endl;
232  m_i_run_number = irun;
233  }
234  std::cout << " **************** " << std::endl;
235 
236  } else if (nr == 0) {
237  m_i_run_number = irun;
238  std::cout << " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed " << std::endl;
239  std::cout << " **************** " << std::endl;
240  } else {
241  m_i_run_number = irun;
242  m_i_tag = the_config_tag;
243  m_i_version = the_config_version;
244  std::cout << " the tag/version is the same -> no transfer needed " << std::endl;
245  std::cout << " **************** " << std::endl;
246  writeFile("last_tpg_fgrTTEE_settings.txt");
247  }
248  }
249  }
250 
251  delete econn;
252  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "Ecal - > end of getNewObjects -----------";
253 }
254 
256  //-------------------------------------------------------------
257 
258  m_i_tag = "";
259  m_i_version = 0;
260  m_i_run_number = 0;
261  m_i_fgrTTEE = 0;
262 
263  FILE *inpFile; // input file
264  inpFile = fopen(inputFile, "r");
265  if (!inpFile) {
266  edm::LogError("EcalTPGFineGrainTowerEEHandler") << "*** Can not open file: " << inputFile;
267  return;
268  }
269 
270  char line[256];
271 
272  std::ostringstream str;
273 
274  fgets(line, 255, inpFile);
275  m_i_tag = to_string(line);
276  str << "gen tag " << m_i_tag << std::endl; // should I use this?
277 
278  fgets(line, 255, inpFile);
279  m_i_version = atoi(line);
280  str << "version= " << m_i_version << std::endl;
281 
282  fgets(line, 255, inpFile);
283  m_i_run_number = atoi(line);
284  str << "run_number= " << m_i_run_number << std::endl;
285 
286  fgets(line, 255, inpFile);
287  m_i_fgrTTEE = atoi(line);
288  str << "fgrTTEE_config= " << m_i_fgrTTEE << std::endl;
289 
290  fclose(inpFile); // close inp. file
291 }
292 
294  //-------------------------------------------------------------
295 
296  std::ofstream myfile;
297  myfile.open(inputFile);
298  myfile << m_i_tag << std::endl;
299  myfile << m_i_version << std::endl;
300  myfile << m_i_run_number << std::endl;
301  myfile << m_i_fgrTTEE << std::endl;
302 
303  myfile.close();
304 }
EcalCondDBInterface
Definition: EcalCondDBInterface.h:37
l1tpf_impl::readFromFile
void readFromFile(CaloCluster &c, FILE *file)
Definition: DiscretePFInputsIO.h:22
cond::time::Time_t
cond::Time_t Time_t
Definition: Time.h:18
MessageLogger.h
FEConfigFgrEETowerDat::getLUTValue
int getLUTValue() const
Definition: FEConfigFgrEETowerDat.h:21
RunList
Definition: RunList.h:16
RunTag
Definition: RunTag.h:13
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EcalLogicID::getName
std::string getName() const
Definition: EcalLogicID.cc:26
FEConfigMainInfo
Definition: FEConfigMainInfo.h:14
test_db_connect.econn
econn
Definition: test_db_connect.py:10
popcon::PopConSourceHandler< EcalTPGFineGrainTowerEE >::Time_t
cond::Time_t Time_t
Definition: PopConSourceHandler.h:34
LocationDef
Definition: LocationDef.h:12
DeadROCCounter.getRunNumber
def getRunNumber(filename)
Definition: DeadROCCounter.py:7
RunTPGConfigDat.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
EcalLogicID::getID1
int getID1() const
Definition: EcalLogicID.cc:30
FEConfigMainInfo::setVersion
void setVersion(int id)
Definition: FEConfigMainInfo.h:78
FEConfigMainInfo::getFgrId
int getFgrId() const
Definition: FEConfigMainInfo.h:43
popcon::EcalTPGFineGrainTowerEEHandler::m_firstRun
unsigned int m_firstRun
Definition: EcalTPGFineGrainTowerEEHandler.h:69
EcalLogicID::getID2
int getID2() const
Definition: EcalLogicID.cc:32
popcon::EcalTPGFineGrainTowerEEHandler::getNewObjects
void getNewObjects() override
Definition: EcalTPGFineGrainTowerEEHandler.cc:31
EcalTPGFineGrainTowerEE
Definition: EcalTPGFineGrainTowerEE.h:9
FEConfigMainInfo.h
RunTag::setGeneralTag
void setGeneralTag(std::string tag)
Definition: RunTag.cc:24
test_db_connect.my_rundef
my_rundef
Definition: test_db_connect.py:13
FEConfigFgrInfo::setId
void setId(int id)
Definition: FEConfigFgrInfo.h:24
popcon::EcalTPGFineGrainTowerEEHandler::m_pass
std::string m_pass
Definition: EcalTPGFineGrainTowerEEHandler.h:77
EcalMappingRcd.h
str
#define str(s)
Definition: TestProcessor.cc:52
EcalLogicID
Definition: EcalLogicID.h:7
RunTPGConfigDat
Definition: RunTPGConfigDat.h:11
popcon::EcalTPGFineGrainTowerEEHandler::writeFile
void writeFile(const char *inputFile)
Definition: EcalTPGFineGrainTowerEEHandler.cc:293
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
RunTypeDef
Definition: RunTypeDef.h:12
popcon::EcalTPGFineGrainTowerEEHandler::m_gentag
std::string m_gentag
Definition: EcalTPGFineGrainTowerEEHandler.h:74
test_db_connect.my_locdef
my_locdef
Definition: test_db_connect.py:11
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
FEConfigFgrInfo
Definition: FEConfigFgrInfo.h:11
edm::ParameterSet
Definition: ParameterSet.h:47
EgHLTOffHistBins_cfi.nr
nr
Definition: EgHLTOffHistBins_cfi.py:4
FEConfigFgrInfo.h
EcalElectronicsMapping.h
dtResolutionTest_cfi.inputFile
inputFile
Definition: dtResolutionTest_cfi.py:14
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
FEConfigFgrEETowerDat
Definition: FEConfigFgrEETowerDat.h:11
EcalTPGFineGrainTowerEE::setValue
void setValue(const uint32_t &id, const uint32_t &lut)
Definition: EcalTPGFineGrainTowerEE.cc:7
EcalLogicID.h
EcalLogicID::NULLID
static const int NULLID
Definition: EcalLogicID.h:35
popcon::EcalTPGFineGrainTowerEEHandler::EcalTPGFineGrainTowerEEHandler
EcalTPGFineGrainTowerEEHandler(edm::ParameterSet const &)
Definition: EcalTPGFineGrainTowerEEHandler.cc:13
std
Definition: JetResolutionObject.h:76
writedatasetfile.dataset
dataset
Definition: writedatasetfile.py:19
RunTPGConfigDat::getVersion
int getVersion() const
Definition: RunTPGConfigDat.h:22
RunTag::setLocationDef
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:33
popcon::EcalTPGFineGrainTowerEEHandler::~EcalTPGFineGrainTowerEEHandler
~EcalTPGFineGrainTowerEEHandler() override
Definition: EcalTPGFineGrainTowerEEHandler.cc:29
popcon::EcalTPGFineGrainTowerEEHandler::m_lastRun
unsigned int m_lastRun
Definition: EcalTPGFineGrainTowerEEHandler.h:70
popcon::EcalTPGFineGrainTowerEEHandler::readFromFile
void readFromFile(const char *inputFile)
Definition: EcalTPGFineGrainTowerEEHandler.cc:255
reco::JetExtendedAssociation::Ref
edm::Ref< Container > Ref
Definition: JetExtendedAssociation.h:32
Exception
Definition: hltDiff.cc:245
popcon::EcalTPGFineGrainTowerEEHandler::m_location
std::string m_location
Definition: EcalTPGFineGrainTowerEEHandler.h:73
RunList::getRuns
std::vector< RunIOV > getRuns()
Definition: RunList.cc:25
RunTPGConfigDat::getConfigTag
std::string getConfigTag() const
Definition: RunTPGConfigDat.h:20
EcalTPGFineGrainTowerEEHandler.h
ParameterSetfwd.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
popcon::EcalTPGFineGrainTowerEEHandler::m_runtype
std::string m_runtype
Definition: EcalTPGFineGrainTowerEEHandler.h:81
dumpRecoGeometry_cfg.tagInfo
tagInfo
Definition: dumpRecoGeometry_cfg.py:194
dataset
Definition: dataset.py:1
RunTag::setRunTypeDef
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:42
IODConfig::setConfigTag
void setConfigTag(std::string x)
Definition: IODConfig.h:29
popcon::EcalTPGFineGrainTowerEEHandler::m_sid
std::string m_sid
Definition: EcalTPGFineGrainTowerEEHandler.h:75
mps_splice.line
line
Definition: mps_splice.py:76
popcon::EcalTPGFineGrainTowerEEHandler::m_locationsource
std::string m_locationsource
Definition: EcalTPGFineGrainTowerEEHandler.h:78
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
popcon::EcalTPGFineGrainTowerEEHandler::m_user
std::string m_user
Definition: EcalTPGFineGrainTowerEEHandler.h:76