CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
popcon::EcalTPGPedestalsHandler Class Reference

#include <EcalTPGPedestalsHandler.h>

Inheritance diagram for popcon::EcalTPGPedestalsHandler:
popcon::PopConSourceHandler< EcalTPGPedestals >

Public Member Functions

 EcalTPGPedestalsHandler (edm::ParameterSet const &)
 
void getNewObjects () override
 
std::string id () const override
 
void readFromFile (const char *inputFile)
 
void writeFile (const char *inputFile)
 
 ~EcalTPGPedestalsHandler () override
 
- Public Member Functions inherited from popcon::PopConSourceHandler< EcalTPGPedestals >
void convertFromOld ()
 
SummarydummySummary (typename OldContainer::value_type const &) const
 
void initialize (const cond::persistency::Session &dbSession, cond::TagInfo_t const &tagInfo, cond::LogDBEntry_t const &logDBEntry)
 
Ref lastPayload () const
 
cond::LogDBEntry_t const & logDBEntry () const
 
std::pair< Container const *, std::string const > operator() (const cond::persistency::Session &session, cond::TagInfo_t const &tagInfo, cond::LogDBEntry_t const &logDBEntry) const
 
 PopConSourceHandler ()
 
Container const & returnData ()
 
void sort ()
 
cond::TagInfo_t const & tagInfo () const
 
std::string const & userTextLog () const
 
virtual ~PopConSourceHandler ()
 

Public Attributes

EcalCondDBInterfaceeconn
 

Private Member Functions

std::string to_string (char value[])
 

Private Attributes

unsigned int m_firstRun
 
std::string m_gentag
 
int m_i_ped
 
unsigned int m_i_run_number
 
std::string m_i_tag
 
int m_i_version
 
unsigned int m_lastRun
 
std::string m_location
 
std::string m_locationsource
 
std::string m_name
 
std::string m_pass
 
unsigned int m_runnr
 
std::string m_runtype
 
std::string m_sid
 
std::string m_user
 
const EcalTPGPedestalsmypedestals
 

Additional Inherited Members

- Public Types inherited from popcon::PopConSourceHandler< EcalTPGPedestals >
typedef std::vector< Triplet > Container
 
typedef std::vector< std::pair< EcalTPGPedestals *, cond::Time_t > > OldContainer
 
typedef PopConSourceHandler< EcalTPGPedestalsself
 
typedef cond::Summary Summary
 
typedef cond::Time_t Time_t
 
typedef EcalTPGPedestals value_type
 
- Protected Member Functions inherited from popcon::PopConSourceHandler< EcalTPGPedestals >
int add (value_type *payload, Summary *summary, Time_t time)
 
cond::persistency::SessiondbSession () const
 
- Protected Attributes inherited from popcon::PopConSourceHandler< EcalTPGPedestals >
OldContainer m_to_transfer
 
std::string m_userTextLog
 

Detailed Description

Definition at line 44 of file EcalTPGPedestalsHandler.h.

Constructor & Destructor Documentation

popcon::EcalTPGPedestalsHandler::EcalTPGPedestalsHandler ( edm::ParameterSet const &  )

Definition at line 23 of file EcalTPGPedestalsHandler.cc.

References edm::ParameterSet::getParameter(), m_firstRun, m_gentag, m_lastRun, m_location, m_locationsource, m_pass, m_runtype, m_sid, m_user, and AlCaHLTBitMon_QueryRunRegistry::string.

24  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalTPGPedestalsHandler")) {
25  edm::LogInfo("EcalTPGPedestalsHandler") << "EcalTPGPedestals Source handler constructor";
26  m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
27  m_lastRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("lastRun").c_str()));
28  m_sid = ps.getParameter<std::string>("OnlineDBSID");
29  m_user = ps.getParameter<std::string>("OnlineDBUser");
30  m_pass = ps.getParameter<std::string>("OnlineDBPassword");
31  m_locationsource = ps.getParameter<std::string>("LocationSource");
32  m_location = ps.getParameter<std::string>("Location");
33  m_gentag = ps.getParameter<std::string>("GenTag");
34  m_runtype = ps.getParameter<std::string>("RunType");
35 
36  edm::LogInfo("EcalTPGPedestalsHandler") << m_sid << "/" << m_user << "/" << m_location << "/" << m_gentag;
37 }
popcon::EcalTPGPedestalsHandler::~EcalTPGPedestalsHandler ( )
override

Definition at line 39 of file EcalTPGPedestalsHandler.cc.

39 {}

Member Function Documentation

void popcon::EcalTPGPedestalsHandler::getNewObjects ( )
overridevirtual

Implements popcon::PopConSourceHandler< EcalTPGPedestals >.

Definition at line 41 of file EcalTPGPedestalsHandler.cc.

References gather_cfg::cout, writedatasetfile::dataset, MillePedeFileConverter_cfg::e, econn, cppFunctionSkipper::exception, Exception, EcalCondDBInterface::fetchConfigSet(), EcalCondDBInterface::fetchDataSet(), EcalCondDBInterface::fetchGlobalRunListByLocation(), RunTPGConfigDat::getConfigTag(), EcalLogicID::getID1(), EcalLogicID::getID2(), EcalLogicID::getID3(), EcalLogicID::getName(), FEConfigMainInfo::getPedId(), FEConfigPedDat::getPedMeanG1(), FEConfigPedDat::getPedMeanG12(), FEConfigPedDat::getPedMeanG6(), RunList::getRuns(), RunTPGConfigDat::getVersion(), EcalCondObjectContainer< T >::insert(), createfilelist::int, B2GTnPMonitor_cfi::item, cond::TagInfo_t::lastInterval, m_firstRun, m_gentag, m_i_ped, m_i_run_number, m_i_tag, m_i_version, m_lastRun, m_location, m_pass, m_runtype, m_sid, popcon::PopConSourceHandler< EcalTPGPedestals >::m_to_transfer, m_user, EcalTPGPedestal::mean_x1, EcalTPGPedestal::mean_x12, EcalTPGPedestal::mean_x6, cond::TagInfo_t::name, EgHLTOffHistBins_cfi::nr, AlCaHLTBitMon_ParallelJobs::p, DetId::rawId(), readFromFile(), IODConfig::setConfigTag(), RunTag::setGeneralTag(), FEConfigPedInfo::setId(), LocationDef::setLocation(), RunTag::setLocationDef(), RunTypeDef::setRunType(), RunTag::setRunTypeDef(), FEConfigMainInfo::setVersion(), cond::TagInfo_t::size, findQualityFiles::size, EBDetId::SMCRYSTALMODE, AlCaHLTBitMon_QueryRunRegistry::string, popcon::PopConSourceHandler< EcalTPGPedestals >::tagInfo(), writeFile(), x, EEDetId::XYMODE, y, and z.

41  {
42  edm::LogInfo("EcalTPGPedestalsHandler") << "Started getNewObjects";
43 
44  //check whats already inside of database
45  if (tagInfo().size) {
46  //check whats already inside of database
47  std::cout << "got offlineInfo = " << std::endl;
48  std::cout << "tag name = " << tagInfo().name << std::endl;
49  std::cout << "size = " << tagInfo().size << std::endl;
50  } else {
51  std::cout << " First object for this tag " << std::endl;
52  }
53 
54  unsigned int max_since = 0;
55  max_since = static_cast<unsigned int>(tagInfo().lastInterval.first);
56  edm::LogInfo("EcalTPGPedestalsHandler") << "max_since = " << max_since;
57  edm::LogInfo("EcalTPGPedestalsHandler") << "Retrieved last payload ";
58 
59  // here we retrieve all the runs after the last from online DB
60  edm::LogInfo("EcalTPGPedestalsHandler") << "Retrieving run list from ONLINE DB ... " << std::endl;
61 
62  edm::LogInfo("EcalTPGPedestalsHandler") << "Making connection..." << std::flush;
64  edm::LogInfo("EcalTPGPedestalsHandler") << "Done." << std::endl;
65 
66  if (!econn) {
67  std::cout << " Connection parameters " << m_sid << "/" << m_user << std::endl;
68  throw cms::Exception("OMDS not available");
69  }
70 
71  LocationDef my_locdef;
72  my_locdef.setLocation(m_location);
73 
74  RunTypeDef my_rundef;
75  my_rundef.setRunType(m_runtype);
76 
77  RunTag my_runtag;
78  my_runtag.setLocationDef(my_locdef);
79  my_runtag.setRunTypeDef(my_rundef);
80  my_runtag.setGeneralTag(m_gentag);
81 
82  readFromFile("last_tpg_ped_settings.txt");
83 
84  unsigned int min_run = m_i_run_number + 1;
85 
86  if (m_firstRun < m_i_run_number) {
87  min_run = m_i_run_number + 1;
88  } else {
89  min_run = m_firstRun;
90  }
91  if (min_run < max_since) {
92  min_run = max_since + 1; // we have to add 1 to the last transferred one
93  }
94 
95  std::cout << "m_i_run_number" << m_i_run_number << "m_firstRun " << m_firstRun << "max_since " << max_since
96  << std::endl;
97 
98  unsigned int max_run = m_lastRun;
99  edm::LogInfo("EcalTPGPedestalsHandler") << "min_run= " << min_run << " max_run = " << max_run;
100  RunList my_list;
101  my_list = econn->fetchGlobalRunListByLocation(my_runtag, min_run, max_run, my_locdef);
102  // my_list=econn->fetchRunListByLocation(my_runtag, min_run, max_run, my_locdef);
103 
104  std::vector<RunIOV> run_vec = my_list.getRuns();
105  size_t num_runs = run_vec.size();
106 
107  std::cout << "number of runs is : " << num_runs << std::endl;
108 
109  unsigned int irun = 0;
110 
111  if (num_runs > 0) {
112  for (size_t kr = 0; kr < run_vec.size(); kr++) {
113  irun = static_cast<unsigned int>(run_vec[kr].getRunNumber());
114 
115  std::cout << " **************** " << std::endl;
116  std::cout << " **************** " << std::endl;
117  std::cout << " run= " << irun << std::endl;
118 
119  // retrieve the data :
120  std::map<EcalLogicID, RunTPGConfigDat> dataset;
121  econn->fetchDataSet(&dataset, &run_vec[kr]);
122 
123  std::string the_config_tag = "";
124  int the_config_version = 0;
125 
126  std::map<EcalLogicID, RunTPGConfigDat>::const_iterator it;
127 
128  int nr = 0;
129  for (it = dataset.begin(); it != dataset.end(); it++) {
130  ++nr;
131  //EcalLogicID ecalid = it->first;
132 
133  RunTPGConfigDat dat = it->second;
134  the_config_tag = dat.getConfigTag();
135  the_config_version = dat.getVersion();
136  }
137 
138  // it is all the same for all SM... get the last one
139 
140  std::cout << " run= " << irun << " tag " << the_config_tag << " version=" << the_config_version << std::endl;
141 
142  // here we should check if it is the same as previous run.
143 
144  if ((the_config_tag != m_i_tag || the_config_version != m_i_version) && nr > 0) {
145  std::cout << "the tag is different from last transferred run ... retrieving last config set from DB"
146  << std::endl;
147 
148  FEConfigMainInfo fe_main_info;
149  fe_main_info.setConfigTag(the_config_tag);
150  fe_main_info.setVersion(the_config_version);
151 
152  try {
153  std::cout << " before fetch config set" << std::endl;
154  econn->fetchConfigSet(&fe_main_info);
155  std::cout << " after fetch config set" << std::endl;
156 
157  // now get TPGPedestals
158  int pedId = fe_main_info.getPedId();
159 
160  if (pedId != m_i_ped) {
161  FEConfigPedInfo fe_ped_info;
162  fe_ped_info.setId(pedId);
163  econn->fetchConfigSet(&fe_ped_info);
164  std::map<EcalLogicID, FEConfigPedDat> dataset_TpgPed;
165  econn->fetchDataSet(&dataset_TpgPed, &fe_ped_info);
166 
167  // NB new
169  typedef std::map<EcalLogicID, FEConfigPedDat>::const_iterator CIfeped;
170  EcalLogicID ecid_xt;
171  FEConfigPedDat rd_ped;
172  int icells = 0;
173  for (CIfeped p = dataset_TpgPed.begin(); p != dataset_TpgPed.end(); p++) {
174  ecid_xt = p->first;
175  rd_ped = p->second;
176 
177  std::string ecid_name = ecid_xt.getName();
178 
179  // EB data
180  if (ecid_name == "EB_crystal_number") {
181  if (icells < 10)
182  std::cout << " copy the EB data "
183  << " icells = " << icells << std::endl;
184  int sm_num = ecid_xt.getID1();
185  int xt_num = ecid_xt.getID2();
186 
187  EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
189  item.mean_x1 = (unsigned int)rd_ped.getPedMeanG1();
190  item.mean_x6 = (unsigned int)rd_ped.getPedMeanG6();
191  item.mean_x12 = (unsigned int)rd_ped.getPedMeanG12();
192 
193  peds->insert(std::make_pair(ebdetid.rawId(), item));
194  ++icells;
195  } else if (ecid_name == "EE_crystal_number") {
196  // EE data
197  int z = ecid_xt.getID1();
198  int x = ecid_xt.getID2();
199  int y = ecid_xt.getID3();
200  EEDetId eedetid(x, y, z, EEDetId::XYMODE);
202  item.mean_x1 = (unsigned int)rd_ped.getPedMeanG1();
203  item.mean_x6 = (unsigned int)rd_ped.getPedMeanG6();
204  item.mean_x12 = (unsigned int)rd_ped.getPedMeanG12();
205 
206  peds->insert(std::make_pair(eedetid.rawId(), item));
207  ++icells;
208  }
209  }
210 
211  Time_t snc = (Time_t)irun;
212  m_to_transfer.push_back(std::make_pair((EcalTPGPedestals*)peds, snc));
213 
214  m_i_run_number = irun;
215  m_i_tag = the_config_tag;
216  m_i_version = the_config_version;
217  m_i_ped = pedId;
218 
219  writeFile("last_tpg_ped_settings.txt");
220 
221  } else {
222  m_i_run_number = irun;
223  m_i_tag = the_config_tag;
224  m_i_version = the_config_version;
225 
226  writeFile("last_tpg_ped_settings.txt");
227 
228  std::cout << " even if the tag/version is not the same, the pedestals id is the same -> no transfer needed "
229  << std::endl;
230  }
231 
232  }
233 
234  catch (std::exception& e) {
235  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" << the_config_tag << " version=" << the_config_version
236  << std::endl;
237  std::cout << e.what() << std::endl;
238  m_i_run_number = irun;
239  }
240  std::cout << " **************** " << std::endl;
241 
242  } else if (nr == 0) {
243  m_i_run_number = irun;
244  std::cout << " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed " << std::endl;
245  std::cout << " **************** " << std::endl;
246  } else {
247  m_i_run_number = irun;
248  m_i_tag = the_config_tag;
249  m_i_version = the_config_version;
250  std::cout << " the tag/version is the same -> no transfer needed " << std::endl;
251  std::cout << " **************** " << std::endl;
252  writeFile("last_tpg_ped_settings.txt");
253  }
254  }
255  }
256 
257  delete econn;
258 
259  edm::LogInfo("EcalTPGPedestalsHandler") << "Ecal - > end of getNewObjects -----------";
260 }
size
Write out results.
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:42
std::vector< RunIOV > getRuns()
Definition: RunList.cc:25
RunList fetchGlobalRunListByLocation(const RunTag &tag, int min_run, int max_run, const LocationDef &locDef) noexcept(false)
std::string getConfigTag() const
float getPedMeanG1() const
int getVersion() const
Definition: RunTag.h:13
static const int XYMODE
Definition: EEDetId.h:335
size_t size
Definition: Types.h:76
void fetchConfigSet(ICONF *iconf) noexcept(false)
void setVersion(int id)
void fetchDataSet(std::map< EcalLogicID, DATT > *fillMap, IOVT *iov) noexcept(false)
std::string name
Definition: Types.h:72
int getID2() const
Definition: EcalLogicID.cc:32
void writeFile(const char *inputFile)
cond::ValidityInterval lastInterval
Definition: Types.h:74
std::string getName() const
Definition: EcalLogicID.cc:26
int getID1() const
Definition: EcalLogicID.cc:30
float getPedMeanG12() const
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:33
void insert(std::pair< uint32_t, Item > const &a)
void setRunType(std::string runtype)
Definition: RunTypeDef.cc:21
void readFromFile(const char *inputFile)
float getPedMeanG6() const
int getPedId() const
void setConfigTag(std::string x)
Definition: IODConfig.h:29
void setId(int id)
void setLocation(std::string loc)
Definition: LocationDef.cc:20
int getID3() const
Definition: EcalLogicID.cc:34
void setGeneralTag(std::string tag)
Definition: RunTag.cc:24
static const int SMCRYSTALMODE
Definition: EBDetId.h:159
EcalTPGPedestalsMap EcalTPGPedestals
std::string popcon::EcalTPGPedestalsHandler::id ( ) const
inlineoverridevirtual
void popcon::EcalTPGPedestalsHandler::readFromFile ( const char *  inputFile)

Definition at line 262 of file EcalTPGPedestalsHandler.cc.

References dtResolutionTest_cfi::inputFile, mps_splice::line, m_i_ped, m_i_run_number, m_i_tag, m_i_version, str, and to_string().

Referenced by getNewObjects().

262  {
263  //-------------------------------------------------------------
264 
265  m_i_tag = "";
266  m_i_version = 0;
267  m_i_run_number = 0;
268  m_i_ped = 0;
269 
270  FILE* inpFile; // input file
271  inpFile = fopen(inputFile, "r");
272  if (!inpFile) {
273  edm::LogError("EcalTPGPedestalsHandler") << "*** Can not open file: " << inputFile;
274  return;
275  }
276 
277  char line[256];
278 
279  std::ostringstream str;
280 
281  fgets(line, 255, inpFile);
282  m_i_tag = to_string(line);
283  str << "gen tag " << m_i_tag << std::endl; // should I use this?
284 
285  fgets(line, 255, inpFile);
286  m_i_version = atoi(line);
287  str << "version= " << m_i_version << std::endl;
288 
289  fgets(line, 255, inpFile);
290  m_i_run_number = atoi(line);
291  str << "run_number= " << m_i_run_number << std::endl;
292 
293  fgets(line, 255, inpFile);
294  m_i_ped = atoi(line);
295  str << "ped_config= " << m_i_ped << std::endl;
296 
297  fclose(inpFile); // close inp. file
298 }
std::string to_string(char value[])
#define str(s)
std::string popcon::EcalTPGPedestalsHandler::to_string ( char  value[])
inlineprivate

Definition at line 45 of file EcalTPGPedestalsHandler.h.

References relativeConstraints::value.

Referenced by readFromFile().

45  {
46  std::ostringstream streamOut;
47  streamOut << value;
48  return streamOut.str();
49  }
void popcon::EcalTPGPedestalsHandler::writeFile ( const char *  inputFile)

Definition at line 300 of file EcalTPGPedestalsHandler.cc.

References m_i_ped, m_i_run_number, m_i_tag, and m_i_version.

Referenced by getNewObjects(), and Vispa.Main.TabController.TabController::save().

300  {
301  //-------------------------------------------------------------
302 
303  std::ofstream myfile;
304  myfile.open(inputFile);
305  myfile << m_i_tag << std::endl;
306  myfile << m_i_version << std::endl;
307  myfile << m_i_run_number << std::endl;
308  myfile << m_i_ped << std::endl;
309 
310  myfile.close();
311 }

Member Data Documentation

EcalCondDBInterface* popcon::EcalTPGPedestalsHandler::econn

Definition at line 61 of file EcalTPGPedestalsHandler.h.

Referenced by getNewObjects().

unsigned int popcon::EcalTPGPedestalsHandler::m_firstRun
private

Definition at line 66 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

std::string popcon::EcalTPGPedestalsHandler::m_gentag
private

Definition at line 70 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

int popcon::EcalTPGPedestalsHandler::m_i_ped
private

Definition at line 81 of file EcalTPGPedestalsHandler.h.

Referenced by getNewObjects(), readFromFile(), and writeFile().

unsigned int popcon::EcalTPGPedestalsHandler::m_i_run_number
private

Definition at line 80 of file EcalTPGPedestalsHandler.h.

Referenced by getNewObjects(), readFromFile(), and writeFile().

std::string popcon::EcalTPGPedestalsHandler::m_i_tag
private

Definition at line 78 of file EcalTPGPedestalsHandler.h.

Referenced by getNewObjects(), readFromFile(), and writeFile().

int popcon::EcalTPGPedestalsHandler::m_i_version
private

Definition at line 79 of file EcalTPGPedestalsHandler.h.

Referenced by getNewObjects(), readFromFile(), and writeFile().

unsigned int popcon::EcalTPGPedestalsHandler::m_lastRun
private

Definition at line 67 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

std::string popcon::EcalTPGPedestalsHandler::m_location
private

Definition at line 69 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

std::string popcon::EcalTPGPedestalsHandler::m_locationsource
private

Definition at line 74 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler().

std::string popcon::EcalTPGPedestalsHandler::m_name
private

Definition at line 75 of file EcalTPGPedestalsHandler.h.

std::string popcon::EcalTPGPedestalsHandler::m_pass
private

Definition at line 73 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

unsigned int popcon::EcalTPGPedestalsHandler::m_runnr
private

Definition at line 76 of file EcalTPGPedestalsHandler.h.

std::string popcon::EcalTPGPedestalsHandler::m_runtype
private

Definition at line 77 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

std::string popcon::EcalTPGPedestalsHandler::m_sid
private

Definition at line 71 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

std::string popcon::EcalTPGPedestalsHandler::m_user
private

Definition at line 72 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

const EcalTPGPedestals* popcon::EcalTPGPedestalsHandler::mypedestals
private

Definition at line 64 of file EcalTPGPedestalsHandler.h.