CMS 3D CMS Logo

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