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 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 ()
 
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::map< Time_t, std::shared_ptr< EcalADCToGeVConstant > > Container
 
typedef std::unique_ptr< EcalADCToGeVConstantRef
 
typedef PopConSourceHandler< EcalADCToGeVConstantself
 
typedef cond::Time_t Time_t
 
typedef EcalADCToGeVConstant value_type
 
- Protected Member Functions inherited from popcon::PopConSourceHandler< EcalADCToGeVConstant >
cond::persistency::SessiondbSession () const
 
- Protected Attributes inherited from popcon::PopConSourceHandler< EcalADCToGeVConstant >
Container m_iovs
 
std::vector< std::pair< EcalADCToGeVConstant *, Time_t > > m_to_transfer
 
std::string m_userTextLog
 

Detailed Description

Definition at line 48 of file EcalADCToGeVHandler.h.

Constructor & Destructor Documentation

◆ EcalADCToGeVHandler()

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

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

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 }

◆ ~EcalADCToGeVHandler()

popcon::EcalADCToGeVHandler::~EcalADCToGeVHandler ( )
override

Definition at line 25 of file EcalADCToGeVHandler.cc.

25 {}

Member Function Documentation

◆ getNewObjects()

void popcon::EcalADCToGeVHandler::getNewObjects ( )
overridevirtual

Implements popcon::PopConSourceHandler< EcalADCToGeVConstant >.

Definition at line 27 of file EcalADCToGeVHandler.cc.

References gather_cfg::cout, writedatasetfile::dataset, test_db_connect::econn, HLT_2023v12_cff::exponent, EcalADCToGeVConstant::getEEValue(), RunDCSMagnetDat::getMagnetCurrent(), RunIOV::getRunNumber(), mps_splice::line, VarParsing::mult, jetsAK4_Puppi_cff::payload, conifer::pow(), contentValuesCheck::ss, AlCaHLTBitMon_QueryRunRegistry::string, dumpRecoGeometry_cfg::tagInfo, and heppy_batch::val.

27  {
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;
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 
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 }
int run_t
Definition: CaliIOV.h:11
Iov_t lastInterval
Definition: Types.h:73
float getMagnetCurrent() const
Time_t since
Definition: Types.h:53
size_t size
Definition: Types.h:74
constexpr int pow(int x)
Definition: conifer.h:24
run_t getRunNumber() const
Definition: RunIOV.cc:31
void fetchDataSet(std::map< EcalLogicID, DATT > *fillMap, IOVT *iov) noexcept(false)
std::unique_ptr< EcalADCToGeVConstant > Ref
void fetchValidDataSet(std::map< EcalLogicID, DATT > *fillMap, IOVT *fillIOV, RunTag *tag, run_t run=(unsigned int) -1) noexcept(false)
Definition: RunIOV.h:13
EcalCondDBInterface * econn

◆ id()

std::string popcon::EcalADCToGeVHandler::id ( ) const
inlineoverridevirtual

Implements popcon::PopConSourceHandler< EcalADCToGeVConstant >.

Definition at line 55 of file EcalADCToGeVHandler.h.

References m_name.

55 { return m_name; }

Member Data Documentation

◆ econn

EcalCondDBInterface* popcon::EcalADCToGeVHandler::econn

Definition at line 56 of file EcalADCToGeVHandler.h.

◆ m_file_highfield

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

Definition at line 72 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler().

◆ m_file_lowfield

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

Definition at line 71 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler().

◆ m_firstRun

unsigned int popcon::EcalADCToGeVHandler::m_firstRun
private

Definition at line 61 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler().

◆ m_gentag

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

Definition at line 65 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler().

◆ m_lastRun

unsigned int popcon::EcalADCToGeVHandler::m_lastRun
private

Definition at line 62 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler().

◆ m_location

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

Definition at line 64 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler().

◆ m_locationsource

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

Definition at line 69 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler().

◆ m_name

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

Definition at line 70 of file EcalADCToGeVHandler.h.

Referenced by id().

◆ m_pass

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

Definition at line 68 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler().

◆ m_sid

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

Definition at line 66 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler().

◆ m_user

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

Definition at line 67 of file EcalADCToGeVHandler.h.

Referenced by EcalADCToGeVHandler().

◆ myintercalib

const EcalADCToGeVConstant* popcon::EcalADCToGeVHandler::myintercalib
private

Definition at line 59 of file EcalADCToGeVHandler.h.