CMS 3D CMS Logo

EcalADCToGeVHandler.cc
Go to the documentation of this file.
5 
6 #include <iostream>
7 
9  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalADCToGeVHandler")) {
10  std::cout << "EcalADCToGeV Source handler constructor\n" << std::endl;
11  m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
12  m_lastRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("lastRun").c_str()));
13  m_sid = ps.getParameter<std::string>("OnlineDBSID");
14  m_user = ps.getParameter<std::string>("OnlineDBUser");
15  m_pass = ps.getParameter<std::string>("OnlineDBPassword");
16  m_locationsource = ps.getParameter<std::string>("LocationSource");
17  m_location = ps.getParameter<std::string>("Location");
18  m_gentag = ps.getParameter<std::string>("GenTag");
19  m_file_lowfield = ps.getParameter<std::string>("FileLowField");
20  m_file_highfield = ps.getParameter<std::string>("FileHighField");
21 
22  std::cout << m_sid << "/" << m_user << "/" << m_location << "/" << m_gentag << std::endl;
23 }
24 
26 
28  std::cout << "------- Ecal - > getNewObjects\n";
29 
30  std::ostringstream ss;
31  ss << "ECAL ";
32 
33  unsigned int max_since = 0;
34  max_since = static_cast<unsigned int>(tagInfo().lastInterval.since);
35  std::cout << "max_since : " << max_since << std::endl;
36  bool magnet_high = false;
37  bool something_to_transfer = false;
38  if (tagInfo().size) {
39  Ref ped_db = lastPayload();
40 
41  // we parse the last record in the DB and check if it is low or high field
42 
43  std::cout << "retrieved last payload " << std::endl;
44 
45  EcalADCToGeVConstant the_cal;
46 
47  //unused float adc_eb=ped_db->getEBValue();
48  float adc_ee = ped_db->getEEValue();
49 
50  // float the_value_high_eb=0.03894;
51  // float the_value_high_ee=0.06285;
52  // float the_value_high_eb=0.03894;
53  // float the_value_high_ee=0.06378;
54 
55  // bool magnet_high=true;
56  // if(adc_eb!= the_value_high_eb || adc_ee!= the_value_high_ee ) magnet_high=false;
57 
58  //unused float the_value_low_eb=0.03894;
59  // Run 1 : float the_value_low_ee=0.05678;
60  float the_value_low_ee = 0.0590975;
61  if (adc_ee > the_value_low_ee)
62  magnet_high = true;
63  } // check if there is already a payload
64  else
65  something_to_transfer = true;
66 
67  // here we connect to the online DB to check the value of the magnetic field
68  std::cout << "Connecting to ONLINE DB ... " << std::endl;
69  econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
70  std::cout << "Connection done" << std::endl;
71 
72  std::cout << "Retrieving last run from ONLINE DB ... " << std::endl;
73  std::map<EcalLogicID, RunDat> rundat;
74  RunIOV rp;
75  run_t runmax = 10000000;
76  std::string location_p5 = "P5_Co";
77  econn->fetchValidDataSet(&rundat, &rp, location_p5, runmax);
78 
79  unsigned long long irun = (unsigned long long)rp.getRunNumber();
80 
81  std::cout << "retrieved run number " << irun << std::endl;
82 
83  if (irun > max_since) {
84  // retrieve from last value data record
85  // always call this method at first run
86 
87  std::map<EcalLogicID, RunDCSMagnetDat> dataset;
88 
89  econn->fetchDataSet(&dataset, &rp);
90 
91  if (dataset.empty()) {
92  throw(std::runtime_error("Zero rows read back"));
93  } else {
94  std::cout << "retrieved magnet current" << std::endl;
95  }
96 
97  float mag_cur = 0;
98 
99  std::map<EcalLogicID, RunDCSMagnetDat>::iterator it;
100  for (it = dataset.begin(); it != dataset.end(); ++it) {
101  RunDCSMagnetDat a_mag = (*it).second;
102  mag_cur = a_mag.getMagnetCurrent();
103  }
104 
105  std::string file_ = m_file_highfield;
106  if (tagInfo().size) {
107  if (mag_cur > 7000. && magnet_high) {
108  std::cout << " the magnet is ON and the constants are for magnet ON " << std::endl;
109 
110  } else if (mag_cur > 7000. && !magnet_high) {
111  something_to_transfer = true;
112  std::cout << " the magnet is ON and the constants are for magnet OFF " << std::endl;
113  std::cout << " I transfer the ON constants " << std::endl;
114  file_ = m_file_highfield;
115 
116  } else if (mag_cur < 6000. && magnet_high) {
117  something_to_transfer = true;
118  std::cout << " the magnet is OFF and the constants are for magnet ON " << std::endl;
119  std::cout << " I transfer the OFF constants " << std::endl;
120  file_ = m_file_lowfield;
121 
122  } else if (mag_cur < 6000. && !magnet_high) {
123  std::cout << " the magnet is OFF and the constants are for magnet OFF " << std::endl;
124  file_ = m_file_lowfield;
125 
126  } else {
127  std::cout << " the magnet is in a strange situation I do nothing ... just be patient " << std::endl;
128  }
129  } else {
130  if (mag_cur > 7000.)
131  std::cout << " first payload, the magnet is ON " << std::endl;
132  else if (mag_cur < 6000.) {
133  std::cout << " first payload, the magnet is OFF " << std::endl;
134  file_ = m_file_lowfield;
135  } else
136  std::cout << " the magnet is in a strange situation I do nothing ... just be patient " << std::endl;
137  }
138 
139  if (something_to_transfer) {
140  std::cout << "Generating popcon record for run " << irun << " going to open file " << file_ << "\n"
141  << std::flush;
143  // EcalCondHeader header; // DBv1
144  // EcalADCToGeVXMLTranslator::readXML(file_,header,*payload); // DBv1
145  // DBv2 poor xml file :-(
146  std::ifstream fxml;
147  fxml.open(file_.c_str());
148  std::string line, bid, bid2;
149  float val;
150  for (int il = 0; il < 4; il++) {
151  std::getline(fxml, line);
152  // std::cout << line << "\n";
153  }
154  for (int iPart = 0; iPart < 2; iPart++) { // EB, EE
155  fxml >> bid;
156  std::size_t begin = bid.find_first_of('>');
157  std::size_t end = bid.find_last_of('<');
158  begin++;
159  std::string str2 = bid.substr(begin, end - begin);
160  std::size_t endmantissa = str2.find('e');
161  std::string mantissa = str2.substr(0, endmantissa);
162  std::size_t string_size = str2.size();
163  std::string exponent = str2.substr(endmantissa + 1, string_size);
164  std::istringstream is(mantissa);
165  is >> val;
166  float mult;
167  std::istringstream ise(exponent);
168  ise >> mult;
169  val = val * pow(10, mult);
170  std::cout << " Partition " << iPart << " ADCToGeV " << val << "\n";
171  if (iPart < 1)
172  payload->setEBValue(val);
173  else
174  payload->setEEValue(val);
175  }
176  // end change for DBv2
177 
178  Time_t snc = (Time_t)irun;
180  ss << "Run=" << irun << "_Magnet_changed_" << std::endl;
181  m_userTextLog = ss.str() + ";";
182  } else {
183  std::cout << "Run " << irun << " nothing sent to the DB" << std::endl;
184  ss << "Run=" << irun << "_Magnet_NOT_changed_" << std::endl;
185  m_userTextLog = ss.str() + ";";
186  }
187 
188  delete econn;
189  } // irun > max_since
190  else {
191  std::cout << "Run " << irun << " nothing sent to the DB" << std::endl;
192  ss << "Run=" << irun << "_no_new_runs_" << std::endl;
193  m_userTextLog = ss.str() + ";";
194  }
195  std::cout << "Ecal - > end of getNewObjects -----------\n";
196 }
EcalCondDBInterface
Definition: EcalCondDBInterface.h:37
RunIOV
Definition: RunIOV.h:13
popcon::EcalADCToGeVHandler::~EcalADCToGeVHandler
~EcalADCToGeVHandler() override
Definition: EcalADCToGeVHandler.cc:25
cond::time::Time_t
cond::Time_t Time_t
Definition: Time.h:18
popcon::EcalADCToGeVHandler::m_sid
std::string m_sid
Definition: EcalADCToGeVHandler.h:66
run_t
int run_t
Definition: CaliIOV.h:11
popcon::EcalADCToGeVHandler::m_pass
std::string m_pass
Definition: EcalADCToGeVHandler.h:68
EcalIntercalibConstants.h
popcon::EcalADCToGeVHandler::m_location
std::string m_location
Definition: EcalADCToGeVHandler.h:64
gather_cfg.cout
cout
Definition: gather_cfg.py:144
test_db_connect.econn
econn
Definition: test_db_connect.py:10
popcon::PopConSourceHandler< EcalADCToGeVConstant >::Time_t
cond::Time_t Time_t
Definition: PopConSourceHandler.h:34
popcon::EcalADCToGeVHandler::m_gentag
std::string m_gentag
Definition: EcalADCToGeVHandler.h:65
EcalADCToGeVConstant
Definition: EcalADCToGeVConstant.h:13
popcon::EcalADCToGeVHandler::m_locationsource
std::string m_locationsource
Definition: EcalADCToGeVHandler.h:69
popcon::EcalADCToGeVHandler::EcalADCToGeVHandler
EcalADCToGeVHandler(edm::ParameterSet const &)
Definition: EcalADCToGeVHandler.cc:8
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
mps_fire.end
end
Definition: mps_fire.py:242
HLT_FULL_cff.exponent
exponent
Definition: HLT_FULL_cff.py:52851
jets_cff.payload
payload
Definition: jets_cff.py:32
RunIOV::getRunNumber
run_t getRunNumber() const
Definition: RunIOV.cc:31
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
popcon::EcalADCToGeVHandler::m_lastRun
unsigned int m_lastRun
Definition: EcalADCToGeVHandler.h:62
edm::ParameterSet
Definition: ParameterSet.h:47
EcalADCToGeVConstant::getEEValue
float getEEValue() const
Definition: EcalADCToGeVConstant.h:21
RunDCSMagnetDat
Definition: RunDCSMagnetDat.h:15
EcalADCToGeVHandler.h
popcon::PopConSourceHandler
Definition: PopConSourceHandler.h:30
popcon::EcalADCToGeVHandler::m_file_highfield
std::string m_file_highfield
Definition: EcalADCToGeVHandler.h:72
heppy_batch.val
val
Definition: heppy_batch.py:351
std
Definition: JetResolutionObject.h:76
writedatasetfile.dataset
dataset
Definition: writedatasetfile.py:19
popcon::EcalADCToGeVHandler::m_firstRun
unsigned int m_firstRun
Definition: EcalADCToGeVHandler.h:61
popcon::EcalADCToGeVHandler::m_user
std::string m_user
Definition: EcalADCToGeVHandler.h:67
reco::JetExtendedAssociation::Ref
edm::Ref< Container > Ref
Definition: JetExtendedAssociation.h:32
popcon::EcalADCToGeVHandler::m_file_lowfield
std::string m_file_lowfield
Definition: EcalADCToGeVHandler.h:71
ParameterSetfwd.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dumpRecoGeometry_cfg.tagInfo
tagInfo
Definition: dumpRecoGeometry_cfg.py:194
VarParsing.mult
mult
Definition: VarParsing.py:659
dataset
Definition: dataset.py:1
RunDCSMagnetDat::getMagnetCurrent
float getMagnetCurrent() const
Definition: RunDCSMagnetDat.h:27
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
EcalADCToGeVXMLTranslator.h
mps_splice.line
line
Definition: mps_splice.py:76
popcon::EcalADCToGeVHandler::getNewObjects
void getNewObjects() override
Definition: EcalADCToGeVHandler.cc:27
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443