CMS 3D CMS Logo

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

#include <EcalADCToGeVHandler.h>

Inheritance diagram for popcon::EcalADCToGeVHandler:
popcon::PopConSourceHandler< EcalADCToGeVConstant >

Public Member Functions

 EcalADCToGeVHandler (edm::ParameterSet const &)
 
void getNewObjects () override
 
std::string id () const override
 
 ~EcalADCToGeVHandler () override
 
- Public Member Functions inherited from popcon::PopConSourceHandler< EcalADCToGeVConstant >
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 Attributes

std::string m_file_highfield
 
std::string m_file_lowfield
 
unsigned int m_firstRun
 
std::string m_gentag
 
unsigned int m_lastRun
 
std::string m_location
 
std::string m_locationsource
 
std::string m_name
 
std::string m_pass
 
std::string m_sid
 
std::string m_user
 
const EcalADCToGeVConstantmyintercalib
 

Additional Inherited Members

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

Detailed Description

Definition at line 56 of file EcalADCToGeVHandler.h.

Constructor & Destructor Documentation

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

Definition at line 9 of file EcalADCToGeVHandler.cc.

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

10  : m_name(ps.getUntrackedParameter<std::string>("name","EcalADCToGeVHandler")) {
11 
12  std::cout << "EcalADCToGeV Source handler constructor\n" << std::endl;
13  m_firstRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("firstRun").c_str()));
14  m_lastRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("lastRun").c_str()));
15  m_sid= ps.getParameter<std::string>("OnlineDBSID");
16  m_user= ps.getParameter<std::string>("OnlineDBUser");
17  m_pass= ps.getParameter<std::string>("OnlineDBPassword");
18  m_locationsource= ps.getParameter<std::string>("LocationSource");
19  m_location=ps.getParameter<std::string>("Location");
20  m_gentag=ps.getParameter<std::string>("GenTag");
21  m_file_lowfield= ps.getParameter<std::string>("FileLowField");
22  m_file_highfield= ps.getParameter<std::string>("FileHighField");
23 
24 
25 
26  std::cout << m_sid<<"/"<<m_user<<"/"<<m_location<<"/"<<m_gentag << std::endl;
27 
28 
29 }
popcon::EcalADCToGeVHandler::~EcalADCToGeVHandler ( )
override

Definition at line 31 of file EcalADCToGeVHandler.cc.

31 {}

Member Function Documentation

void popcon::EcalADCToGeVHandler::getNewObjects ( )
overridevirtual

Implements popcon::PopConSourceHandler< EcalADCToGeVConstant >.

Definition at line 34 of file EcalADCToGeVHandler.cc.

References begin, gather_cfg::cout, createfilelist::dataset, econn, end, dedxEstimators_cff::exponent, EcalCondDBInterface::fetchDataSet(), EcalCondDBInterface::fetchValidDataSet(), EcalADCToGeVConstant::getEEValue(), RunDCSMagnetDat::getMagnetCurrent(), RunIOV::getRunNumber(), cond::TagInfo_t::lastInterval, popcon::PopConSourceHandler< EcalADCToGeVConstant >::lastPayload(), geometryCSVtoXML::line, m_file_highfield, m_file_lowfield, m_pass, m_sid, m_user, popcon::PopConSourceHandler< EcalADCToGeVConstant >::m_userTextLog, jets_cff::payload, funct::pow(), lumiCalc2::runmax, EcalADCToGeVConstant::setEBValue(), EcalADCToGeVConstant::setEEValue(), cond::TagInfo_t::size, findQualityFiles::size, AlCaHLTBitMon_QueryRunRegistry::string, popcon::PopConSourceHandler< EcalADCToGeVConstant >::tagInfo(), and heppy_batch::val.

34  {
35  std::cout << "------- Ecal - > getNewObjects\n";
36 
37  std::ostringstream ss;
38  ss<<"ECAL ";
39 
40  unsigned int max_since=0;
41  max_since=static_cast<unsigned int>(tagInfo().lastInterval.first);
42  std::cout << "max_since : " << max_since << std::endl;
43  bool magnet_high = false;
44  bool something_to_transfer = false;
45  if(tagInfo().size) {
46  Ref ped_db = lastPayload();
47 
48  // we parse the last record in the DB and check if it is low or high field
49 
50  std::cout << "retrieved last payload " << std::endl;
51 
52 
53  EcalADCToGeVConstant the_cal ;
54 
55  //unused float adc_eb=ped_db->getEBValue();
56  float adc_ee=ped_db->getEEValue();
57 
58  // float the_value_high_eb=0.03894;
59  // float the_value_high_ee=0.06285;
60  // float the_value_high_eb=0.03894;
61  // float the_value_high_ee=0.06378;
62 
63 
64  // bool magnet_high=true;
65  // if(adc_eb!= the_value_high_eb || adc_ee!= the_value_high_ee ) magnet_high=false;
66 
67 
68  //unused float the_value_low_eb=0.03894;
69  // Run 1 : float the_value_low_ee=0.05678;
70  float the_value_low_ee = 0.0590975;
71  if( adc_ee > the_value_low_ee ) magnet_high = true;
72  } // check if there is already a payload
73  else something_to_transfer = true;
74 
75  // here we connect to the online DB to check the value of the magnetic field
76  std::cout << "Connecting to ONLINE DB ... " << std::endl;
78  std::cout << "Connection done" << std::endl;
79 
80 
81  std::cout << "Retrieving last run from ONLINE DB ... " << std::endl;
82  std::map<EcalLogicID, RunDat> rundat;
83  RunIOV rp ;
84  run_t runmax=10000000;
85  std::string location_p5="P5_Co";
86  econn->fetchValidDataSet(&rundat , &rp, location_p5 ,runmax);
87 
88  unsigned long long irun=(unsigned long long) rp.getRunNumber();
89 
90  std::cout<< "retrieved run number "<< irun <<std::endl;
91 
92  if(irun>max_since) {
93  // retrieve from last value data record
94  // always call this method at first run
95 
96  std::map<EcalLogicID, RunDCSMagnetDat> dataset;
97 
98  econn->fetchDataSet(&dataset, &rp);
99 
100  if (dataset.empty()) {
101  throw(std::runtime_error("Zero rows read back"));
102  } else {
103  std::cout<< "retrieved magnet current"<<std::endl;
104  }
105 
106  float mag_cur=0;
107 
108  std::map< EcalLogicID, RunDCSMagnetDat >::iterator it;
109  for (it=dataset.begin(); it!=dataset.end(); ++it){
110 
111  RunDCSMagnetDat a_mag = (*it).second;
112  mag_cur= a_mag.getMagnetCurrent();
113 
114  }
115 
116 
118  if(tagInfo().size) {
119  if(mag_cur>7000. && magnet_high ) {
120 
121  std::cout << " the magnet is ON and the constants are for magnet ON " << std::endl;
122 
123  } else if(mag_cur>7000. && !magnet_high ) {
124  something_to_transfer=true;
125  std::cout << " the magnet is ON and the constants are for magnet OFF " << std::endl;
126  std::cout << " I transfer the ON constants "<< std::endl;
127  file_=m_file_highfield;
128 
129  } else if(mag_cur<6000. && magnet_high ) {
130  something_to_transfer=true;
131  std::cout << " the magnet is OFF and the constants are for magnet ON "<< std::endl;
132  std::cout << " I transfer the OFF constants "<< std::endl;
133  file_=m_file_lowfield;
134 
135  } else if( mag_cur<6000. && !magnet_high ){
136 
137  std::cout << " the magnet is OFF and the constants are for magnet OFF "<< std::endl;
138  file_=m_file_lowfield;
139 
140  } else {
141 
142  std::cout << " the magnet is in a strange situation I do nothing ... just be patient "<< std::endl;
143 
144  }
145  }
146  else {
147  if(mag_cur>7000.)
148  std::cout <<" first payload, the magnet is ON " << std::endl;
149  else if( mag_cur<6000.) {
150  std::cout <<" first payload, the magnet is OFF " << std::endl;
151  file_=m_file_lowfield;
152  }
153  else
154  std::cout << " the magnet is in a strange situation I do nothing ... just be patient "<< std::endl;
155  }
156 
157  if(something_to_transfer) {
158  std::cout << "Generating popcon record for run " << irun
159  << " going to open file " << file_ << "\n" << std::flush;
161  // EcalCondHeader header; // DBv1
162  // EcalADCToGeVXMLTranslator::readXML(file_,header,*payload); // DBv1
163  // DBv2 poor xml file :-(
164  std::ifstream fxml;
165  fxml.open(file_.c_str());
166  std::string line, bid, bid2;
167  float val;
168  for (int il = 0; il < 4; il++) {
169  std::getline(fxml, line);
170  // std::cout << line << "\n";
171  }
172  for (int iPart = 0; iPart < 2; iPart++) { // EB, EE
173  fxml >> bid;
174  std::size_t begin = bid.find_first_of(">");
175  std::size_t end = bid.find_last_of("<");
176  begin++;
177  std::string str2 = bid.substr(begin, end - begin);
178  std::size_t endmantissa = str2.find("e");
179  std::string mantissa = str2.substr(0, endmantissa);
180  std::size_t string_size = str2.size();
181  std::string exponent = str2.substr(endmantissa + 1, string_size);
182  std::istringstream is(mantissa);
183  is >> val;
184  float mult;
185  std::istringstream ise(exponent);
186  ise >> mult;
187  val = val * pow(10, mult);
188  std::cout << " Partition " << iPart << " ADCToGeV " << val << "\n";
189  if(iPart < 1) payload->setEBValue(val);
190  else payload->setEEValue(val);
191  }
192  // end change for DBv2
193 
194  Time_t snc= (Time_t) irun ;
195  popcon::PopConSourceHandler<EcalADCToGeVConstant>::m_to_transfer.push_back(std::make_pair(payload,snc));
196  ss << "Run=" << irun << "_Magnet_changed_" << std::endl;
197  m_userTextLog = ss.str()+";";
198  } else {
199  std::cout << "Run " << irun << " nothing sent to the DB" << std::endl;
200  ss<< "Run=" << irun << "_Magnet_NOT_changed_" << std::endl;
201  m_userTextLog = ss.str()+";";
202  }
203 
204  delete econn;
205  } // irun > max_since
206  else {
207  std::cout << "Run " << irun << " nothing sent to the DB" << std::endl;
208  ss<< "Run=" << irun << "_no_new_runs_"<<std::endl;
209  m_userTextLog = ss.str()+";";
210  }
211  std::cout << "Ecal - > end of getNewObjects -----------\n";
212 }
size
Write out results.
int run_t
Definition: CaliIOV.h:11
size_t size
Definition: Types.h:77
void fetchDataSet(std::map< EcalLogicID, DATT > *fillMap, IOVT *iov) noexcept(false)
void setEEValue(const float &value)
float getMagnetCurrent() const
cond::ValidityInterval lastInterval
Definition: Types.h:75
#define end
Definition: vmac.h:37
void setEBValue(const float &value)
run_t getRunNumber() const
Definition: RunIOV.cc:45
#define begin
Definition: vmac.h:30
Definition: RunIOV.h:13
EcalCondDBInterface * econn
void fetchValidDataSet(std::map< EcalLogicID, DATT > *fillMap, IOVT *fillIOV, RunTag *tag, run_t run=(unsigned int)-1) noexcept(false)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
std::string popcon::EcalADCToGeVHandler::id ( ) const
inlineoverridevirtual

Member Data Documentation

EcalCondDBInterface* popcon::EcalADCToGeVHandler::econn

Definition at line 66 of file EcalADCToGeVHandler.h.

Referenced by getNewObjects().

std::string popcon::EcalADCToGeVHandler::m_file_highfield
private

Definition at line 84 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler(), and getNewObjects().

std::string popcon::EcalADCToGeVHandler::m_file_lowfield
private

Definition at line 83 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler(), and getNewObjects().

unsigned int popcon::EcalADCToGeVHandler::m_firstRun
private

Definition at line 73 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler().

std::string popcon::EcalADCToGeVHandler::m_gentag
private

Definition at line 77 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler().

unsigned int popcon::EcalADCToGeVHandler::m_lastRun
private

Definition at line 74 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler().

std::string popcon::EcalADCToGeVHandler::m_location
private

Definition at line 76 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler().

std::string popcon::EcalADCToGeVHandler::m_locationsource
private

Definition at line 81 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler().

std::string popcon::EcalADCToGeVHandler::m_name
private

Definition at line 82 of file EcalADCToGeVHandler.h.

std::string popcon::EcalADCToGeVHandler::m_pass
private

Definition at line 80 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler(), and getNewObjects().

std::string popcon::EcalADCToGeVHandler::m_sid
private

Definition at line 78 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler(), and getNewObjects().

std::string popcon::EcalADCToGeVHandler::m_user
private

Definition at line 79 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler(), and getNewObjects().

const EcalADCToGeVConstant* popcon::EcalADCToGeVHandler::myintercalib
private

Definition at line 71 of file EcalADCToGeVHandler.h.