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 48 of file EcalTPGPedestalsHandler.h.

Constructor & Destructor Documentation

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

Definition at line 26 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.

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

Definition at line 44 of file EcalTPGPedestalsHandler.cc.

45 {
46 }

Member Function Documentation

void popcon::EcalTPGPedestalsHandler::getNewObjects ( )
overridevirtual

Implements popcon::PopConSourceHandler< EcalTPGPedestals >.

Definition at line 49 of file EcalTPGPedestalsHandler.cc.

References gather_cfg::cout, createfilelist::dataset, MillePedeFileConverter_cfg::e, econn, cppFunctionSkipper::exception, Exception, 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, 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, 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(), and EEDetId::XYMODE.

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

Definition at line 287 of file EcalTPGPedestalsHandler.cc.

References analyzePatCleaning_cfg::inputFile, geometryCSVtoXML::line, m_i_ped, m_i_run_number, m_i_tag, m_i_version, harvestTrackValidationPlots::str, and to_string().

Referenced by getNewObjects().

287  {
288  //-------------------------------------------------------------
289 
290  m_i_tag="";
291  m_i_version=0;
292  m_i_run_number=0;
293  m_i_ped=0;
294 
295  FILE *inpFile; // input file
296  inpFile = fopen(inputFile,"r");
297  if(!inpFile) {
298  edm::LogError("EcalTPGPedestalsHandler")<<"*** Can not open file: "<<inputFile;
299  return;
300  }
301 
302  char line[256];
303 
304  std::ostringstream str;
305 
306  fgets(line,255,inpFile);
307  m_i_tag=to_string(line);
308  str << "gen tag " << m_i_tag << std::endl ; // should I use this?
309 
310  fgets(line,255,inpFile);
311  m_i_version=atoi(line);
312  str << "version= " << m_i_version << std::endl ;
313 
314  fgets(line,255,inpFile);
315  m_i_run_number=atoi(line);
316  str << "run_number= " << m_i_run_number << std::endl ;
317 
318  fgets(line,255,inpFile);
319  m_i_ped=atoi(line);
320  str << "ped_config= " << m_i_ped << std::endl ;
321 
322 
323  fclose(inpFile); // close inp. file
324 
325 }
std::string to_string(char value[])
std::string popcon::EcalTPGPedestalsHandler::to_string ( char  value[])
inlineprivate

Definition at line 51 of file EcalTPGPedestalsHandler.h.

References relativeConstraints::value.

Referenced by readFromFile().

51  {
52  std::ostringstream streamOut;
53  streamOut << value;
54  return streamOut.str();
55  }
void popcon::EcalTPGPedestalsHandler::writeFile ( const char *  inputFile)

Definition at line 327 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().

327  {
328  //-------------------------------------------------------------
329 
330 
331  std::ofstream myfile;
332  myfile.open (inputFile);
333  myfile << m_i_tag <<std::endl;
334  myfile << m_i_version <<std::endl;
335  myfile << m_i_run_number <<std::endl;
336  myfile << m_i_ped <<std::endl;
337 
338  myfile.close();
339 
340 }

Member Data Documentation

EcalCondDBInterface* popcon::EcalTPGPedestalsHandler::econn

Definition at line 69 of file EcalTPGPedestalsHandler.h.

Referenced by getNewObjects().

unsigned int popcon::EcalTPGPedestalsHandler::m_firstRun
private

Definition at line 74 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

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

Definition at line 78 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

int popcon::EcalTPGPedestalsHandler::m_i_ped
private

Definition at line 89 of file EcalTPGPedestalsHandler.h.

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

unsigned int popcon::EcalTPGPedestalsHandler::m_i_run_number
private

Definition at line 88 of file EcalTPGPedestalsHandler.h.

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

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

Definition at line 86 of file EcalTPGPedestalsHandler.h.

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

int popcon::EcalTPGPedestalsHandler::m_i_version
private

Definition at line 87 of file EcalTPGPedestalsHandler.h.

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

unsigned int popcon::EcalTPGPedestalsHandler::m_lastRun
private

Definition at line 75 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

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

Definition at line 77 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

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

Definition at line 82 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler().

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

Definition at line 83 of file EcalTPGPedestalsHandler.h.

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

Definition at line 81 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

unsigned int popcon::EcalTPGPedestalsHandler::m_runnr
private

Definition at line 84 of file EcalTPGPedestalsHandler.h.

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

Definition at line 85 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

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

Definition at line 79 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

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

Definition at line 80 of file EcalTPGPedestalsHandler.h.

Referenced by EcalTPGPedestalsHandler(), and getNewObjects().

const EcalTPGPedestals* popcon::EcalTPGPedestalsHandler::mypedestals
private

Definition at line 72 of file EcalTPGPedestalsHandler.h.