CMS 3D CMS Logo

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

#include <EcalIntercalibHandler.h>

Inheritance diagram for popcon::EcalIntercalibHandler:
popcon::PopConSourceHandler< EcalIntercalibConstants >

Public Member Functions

 EcalIntercalibHandler (edm::ParameterSet const &)
 
void getNewObjects ()
 
std::string id () const
 
void readXML (const std::string &filename, EcalFloatCondObjectContainer &record)
 
 ~EcalIntercalibHandler ()
 
- Public Member Functions inherited from popcon::PopConSourceHandler< EcalIntercalibConstants >
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
 
double m_value_highfield
 
const EcalIntercalibConstantsmyintercalib
 

Additional Inherited Members

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

Detailed Description

Definition at line 56 of file EcalIntercalibHandler.h.

Constructor & Destructor Documentation

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

Definition at line 10 of file EcalIntercalibHandler.cc.

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

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

Definition at line 33 of file EcalIntercalibHandler.cc.

34 {
35 }

Member Function Documentation

void popcon::EcalIntercalibHandler::getNewObjects ( )
virtual

Implements popcon::PopConSourceHandler< EcalIntercalibConstants >.

Definition at line 38 of file EcalIntercalibHandler.cc.

References gather_cfg::cout, createfilelist::dataset, econn, Exception, EcalCondDBInterface::fetchDataSet(), EcalCondDBInterface::fetchValidDataSet(), objects.autophobj::float, RunDCSMagnetDat::getMagnetCurrent(), RunIOV::getRunNumber(), cond::TagInfo_t::lastInterval, popcon::PopConSourceHandler< EcalIntercalibConstants >::lastPayload(), m_file_highfield, m_file_lowfield, m_pass, m_sid, m_user, popcon::PopConSourceHandler< EcalIntercalibConstants >::m_userTextLog, m_value_highfield, jetCorrFactors_cfi::payload, DetId::rawId(), readXML(), lumiCalc2::runmax, cond::TagInfo_t::size, findQualityFiles::size, AlCaHLTBitMon_QueryRunRegistry::string, popcon::PopConSourceHandler< EcalIntercalibConstants >::tagInfo(), and EEDetId::validDetId().

39 {
40 
41  std::cout << "------- Ecal - > getNewObjects\n";
42 
43  std::ostringstream ss;
44  ss<<"ECAL ";
45 
46  unsigned int max_since=0;
47  max_since=static_cast<unsigned int>(tagInfo().lastInterval.first);
48  std::cout << "max_since : " << max_since << std::endl;
49  bool something_to_transfer = false;
50  bool magnet_high = true;
51  if(tagInfo().size) {
52  Ref ped_db = lastPayload();
53 
54  // we parse the last record in the DB and check if it is low or high field
55 
56  std::cout << "retrieved last payload " << std::endl;
57 
58 
59  EcalIntercalibConstant the_cal = 0. ; // relies on it being a float.
60  // instead should perhaps
61  // protect the next if when
62  // the EEDetId isn't valid?
63 
64  int iX=50;
65  int iY=5;
66  int iZ=-1;
67 
68 
69  float the_value_high=(float)m_value_highfield;
70  std::cout << "The value for high field at EE x/y/z= 50/5/-1 is " << the_value_high << std::endl;
71 
72  if (EEDetId::validDetId(iX,iY,iZ))
73  {
74  EEDetId eedetidpos(iX,iY,iZ);
75 
76  EcalIntercalibConstants::const_iterator it =ped_db->find(eedetidpos.rawId());
77 
78 
79  the_cal = (*it);
80 
81  }
82 
83  if(the_cal!= the_value_high) magnet_high=false;
84  } // check if there is already a payload
85  else something_to_transfer = true;
86 
87  // here we connect to the online DB to check the value of the magnetic field
88  std::cout << "Connecting to ONLINE DB ... " << std::endl;
90  std::cout << "Connection done" << std::endl;
91 
92  if (!econn)
93  {
94  std::cout << " Problem with OMDS: connection parameters " <<m_sid <<"/"<<m_user<<"/"<<m_pass<<std::endl;
95  throw cms::Exception("OMDS not available");
96  }
97 
98 
99  std::cout << "Retrieving last run from ONLINE DB ... " << std::endl;
100  std::map<EcalLogicID, RunDat> rundat;
101  RunIOV rp ;
102  run_t runmax=10000000;
103  std::string location_p5="P5_Co";
104  econn->fetchValidDataSet(&rundat , &rp, location_p5 ,runmax);
105 
106  unsigned long long irun=(unsigned long long) rp.getRunNumber();
107 
108  std::cout<< "retrieved run number "<< irun <<std::endl;
109 
110  if(irun>max_since) {
111  // retrieve from last value data record
112  // always call this method at first run
113 
114  std::map<EcalLogicID, RunDCSMagnetDat> dataset;
115 
116  econn->fetchDataSet(&dataset, &rp);
117 
118  if (!dataset.size()) {
119  throw(std::runtime_error("Zero rows read back"));
120  } else {
121  std::cout<< "retrieved magnet current"<<std::endl;
122  }
123 
124 
125  float mag_cur=0;
126 
127  std::map< EcalLogicID, RunDCSMagnetDat >::iterator it;
128  for (it=dataset.begin(); it!=dataset.end(); ++it){
129 
130  RunDCSMagnetDat a_mag = (*it).second;
131  mag_cur= a_mag.getMagnetCurrent();
132 
133  }
134 
135 
137  if(tagInfo().size) {
138 
139  if(mag_cur>7000. && magnet_high ) {
140 
141  std::cout << " the magnet is ON and the constants are for magnet ON " << std::endl;
142 
143  } else if(mag_cur>7000. && !magnet_high ) {
144  something_to_transfer=true;
145  std::cout << " the magnet is ON and the constants are for magnet OFF " << std::endl;
146  std::cout << " I transfer the ON constants "<< std::endl;
147  file_=m_file_highfield;
148 
149  } else if(mag_cur<6000. && magnet_high ) {
150  something_to_transfer=true;
151  std::cout << " the magnet is OFF and the constants are for magnet ON "<< std::endl;
152  std::cout << " I transfer the OFF constants "<< std::endl;
153  file_=m_file_lowfield;
154 
155  } else if( mag_cur<6000. && !magnet_high ){
156 
157  std::cout << " the magnet is OFF and the constants are for magnet OFF "<< std::endl;
158  file_=m_file_lowfield;
159 
160  } else {
161 
162  std::cout << " the magnet is in a strange situation I do nothing ... just be patient "<< std::endl;
163 
164  }
165  }
166  else {
167  if(mag_cur>7000.)
168  std::cout <<" first payload, the magnet is ON " << std::endl;
169  else if( mag_cur<6000.) {
170  std::cout <<" first payload, the magnet is OFF " << std::endl;
171  file_=m_file_lowfield;
172  }
173  else
174  std::cout << " the magnet is in a strange situation I do nothing ... just be patient "<< std::endl;
175  }
176 
177  if(something_to_transfer){
178 
179  std::cout << "Generating popcon record for run " << irun << "..." << std::flush;
180  std::cout << "going to open file "<<file_ << std::flush;
181 
182 
183  // EcalCondHeader header;
185  // EcalFloatCondObjectContainerXMLTranslator::readXML(file_,header,*payload); // DBv1
186  readXML(file_,*payload); //DBv2
187 
188  Time_t snc= (Time_t) irun ;
189 
191  std::make_pair(payload,snc));
192  ss << "Run=" << irun << "_Magnet_changed_"<<std::endl;
193  m_userTextLog = ss.str()+";";
194 
195  } else {
196  std::cout << "Run " << irun << " nothing sent to the DB"<< std::endl;
197  ss<< "Run=" << irun << "_Magnet_NOT_changed_"<<std::endl;
198  m_userTextLog = ss.str()+";";
199  }
200 
201  delete econn;
202  } // irun > max_since
203  else {
204  std::cout << "Run " << irun << " nothing sent to the DB"<< std::endl;
205  ss<< "Run=" << irun << "_no_new_runs_"<<std::endl;
206  m_userTextLog = ss.str()+";";
207  }
208  std::cout << "Ecal - > end of getNewObjects -----------\n";
209 }
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)
float getMagnetCurrent() const
cond::ValidityInterval lastInterval
Definition: Types.h:75
payload
payload postfix for testing
void readXML(const std::string &filename, EcalFloatCondObjectContainer &record)
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
std::vector< Item >::const_iterator const_iterator
run_t getRunNumber() const
Definition: RunIOV.cc:45
EcalIntercalibConstantMap EcalIntercalibConstants
Definition: RunIOV.h:13
void fetchValidDataSet(std::map< EcalLogicID, DATT > *fillMap, IOVT *fillIOV, RunTag *tag, run_t run=(unsigned int)-1) noexcept(false)
float EcalIntercalibConstant
std::string popcon::EcalIntercalibHandler::id ( ) const
inlinevirtual
void popcon::EcalIntercalibHandler::readXML ( const std::string &  filename,
EcalFloatCondObjectContainer record 
)

Definition at line 211 of file EcalIntercalibHandler.cc.

References gather_cfg::cout, cmsRelvalreport::exit, runEdmFileComparison::found, mps_fire::i, kEBChannels, kEEChannels, AlCaHLTBitMon_QueryRunRegistry::string, EBDetId::unhashIndex(), EEDetId::unhashIndex(), and heppy_batch::val.

Referenced by getNewObjects().

212  {
213  std::string dummyLine, bid;
214  std::ifstream fxml;
215  fxml.open(file_);
216  if(!fxml.is_open()) {
217  std::cout << "ERROR : cannot open file " << file_ << std::endl;
218  exit (1);
219  }
220  // header
221  for( int i=0; i< 6; i++) {
222  getline(fxml, dummyLine); // skip first lines
223  // std::cout << dummyLine << std::endl;
224  }
225  fxml >> bid;
226  // std::cout << bid << std::endl;
227  std::string stt = bid.substr(7,5);
228  std::istringstream iEB(stt);
229  int nEB;
230  iEB >> nEB;
231  if(nEB != kEBChannels) {
232  std::cout << " strange number of EB channels " << nEB << std::endl;
233  exit(-1);
234  }
235  fxml >> bid; // <item_version>0</item_version>
236  for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
237  EBDetId myEBDetId = EBDetId::unhashIndex(iChannel);
238  fxml >> bid;
239  std::size_t found = bid.find("</");
240  stt = bid.substr(6, found - 6);
241  float val = std::stof(stt);
242  record[myEBDetId] = val;
243  }
244  for( int i=0; i< 5; i++) {
245  getline(fxml, dummyLine); // skip first lines
246  // std::cout << dummyLine << std::endl;
247  }
248  fxml >> bid;
249  // cout << bid << endl;
250  stt = bid.substr(7,5);
251  std::istringstream iEE(stt);
252  int nEE;
253  iEE >> nEE;
254  if(nEE != kEEChannels) {
255  std::cout << " strange number of EE channels " << nEE << std::endl;
256  exit(-1);
257  }
258  fxml >> bid; // <item_version>0</item_version>
259  // now endcaps
260  for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
261  EEDetId myEEDetId = EEDetId::unhashIndex(iChannel);
262  fxml >> bid;
263  std::size_t found = bid.find("</");
264  stt = bid.substr(6, found - 6);
265  float val = std::stof(stt);
266  record[myEEDetId] = val;
267  }
268 }
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:99
const Int_t kEEChannels
const Int_t kEBChannels
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114

Member Data Documentation

EcalCondDBInterface* popcon::EcalIntercalibHandler::econn

Definition at line 67 of file EcalIntercalibHandler.h.

Referenced by getNewObjects().

std::string popcon::EcalIntercalibHandler::m_file_highfield
private

Definition at line 85 of file EcalIntercalibHandler.h.

Referenced by EcalIntercalibHandler(), and getNewObjects().

std::string popcon::EcalIntercalibHandler::m_file_lowfield
private

Definition at line 84 of file EcalIntercalibHandler.h.

Referenced by EcalIntercalibHandler(), and getNewObjects().

unsigned int popcon::EcalIntercalibHandler::m_firstRun
private

Definition at line 74 of file EcalIntercalibHandler.h.

Referenced by EcalIntercalibHandler().

std::string popcon::EcalIntercalibHandler::m_gentag
private

Definition at line 78 of file EcalIntercalibHandler.h.

Referenced by EcalIntercalibHandler().

unsigned int popcon::EcalIntercalibHandler::m_lastRun
private

Definition at line 75 of file EcalIntercalibHandler.h.

Referenced by EcalIntercalibHandler().

std::string popcon::EcalIntercalibHandler::m_location
private

Definition at line 77 of file EcalIntercalibHandler.h.

Referenced by EcalIntercalibHandler().

std::string popcon::EcalIntercalibHandler::m_locationsource
private

Definition at line 82 of file EcalIntercalibHandler.h.

Referenced by EcalIntercalibHandler().

std::string popcon::EcalIntercalibHandler::m_name
private

Definition at line 83 of file EcalIntercalibHandler.h.

std::string popcon::EcalIntercalibHandler::m_pass
private

Definition at line 81 of file EcalIntercalibHandler.h.

Referenced by EcalIntercalibHandler(), and getNewObjects().

std::string popcon::EcalIntercalibHandler::m_sid
private

Definition at line 79 of file EcalIntercalibHandler.h.

Referenced by EcalIntercalibHandler(), and getNewObjects().

std::string popcon::EcalIntercalibHandler::m_user
private

Definition at line 80 of file EcalIntercalibHandler.h.

Referenced by EcalIntercalibHandler(), and getNewObjects().

double popcon::EcalIntercalibHandler::m_value_highfield
private

Definition at line 86 of file EcalIntercalibHandler.h.

Referenced by EcalIntercalibHandler(), and getNewObjects().

const EcalIntercalibConstants* popcon::EcalIntercalibHandler::myintercalib
private

Definition at line 72 of file EcalIntercalibHandler.h.