CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalIntercalibHandler.cc
Go to the documentation of this file.
5 
6 
7 #include<iostream>
8 
10  : m_name(ps.getUntrackedParameter<std::string>("name","EcalIntercalibHandler")) {
11 
12  std::cout << "EcalIntercalib 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  m_value_highfield= ps.getUntrackedParameter< double >("Value_Bon");
24  // m_value_highfield= 0.75585;
25 
26 
27 
28  std::cout << m_sid<<"/"<<m_user<<"/"<<m_location<<"/"<<m_gentag << std::endl;
29 
30 
31 }
32 
34 {
35 }
36 
37 
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  Ref ped_db = lastPayload();
50 
51  // we parse the last record in the DB and check if it is low or high field
52 
53  std::cout << "retrieved last payload " << std::endl;
54 
55 
56  EcalIntercalibConstant the_cal = 0. ; // relies on it being a float.
57  // instead should perhaps
58  // protect the next if when
59  // the EEDetId isn't valid?
60 
61  int iX=50;
62  int iY=5;
63  int iZ=-1;
64 
65 
66  float the_value_high=(float)m_value_highfield;
67  std::cout << "The value for high field at EE x/y/z= 50/5/-1 is " << the_value_high << std::endl;
68 
69  if (EEDetId::validDetId(iX,iY,iZ))
70  {
71  EEDetId eedetidpos(iX,iY,iZ);
72 
73  EcalIntercalibConstants::const_iterator it =ped_db->find(eedetidpos.rawId());
74 
75 
76  the_cal = (*it);
77 
78  }
79 
80  bool magnet_high=true;
81  if(the_cal!= the_value_high) magnet_high=false;
82 
83 
84  // here we connect to the online DB to check the value of the magnetic field
85 
86  std::cout << "Connecting to ONLINE DB ... " << std::endl;
87  econn = new EcalCondDBInterface( m_sid, m_user, m_pass );
88  std::cout << "Connection done" << std::endl;
89 
90  if (!econn)
91  {
92  std::cout << " Problem with OMDS: connection parameters " <<m_sid <<"/"<<m_user<<"/"<<m_pass<<std::endl;
93  throw cms::Exception("OMDS not available");
94  }
95 
96 
97  std::cout << "Retrieving last run from ONLINE DB ... " << std::endl;
98  std::map<EcalLogicID, RunDat> rundat;
99  RunIOV rp ;
100  run_t runmax=10000000;
101  std::string location_p5="P5_Co";
102  econn->fetchValidDataSet(&rundat , &rp, location_p5 ,runmax);
103 
104  unsigned long long irun=(unsigned long long) rp.getRunNumber();
105 
106  std::cout<< "retrieved run number "<< irun <<std::endl;
107 
108  if(irun>max_since) {
109 
110 
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 
136  std::string file_=m_file_highfield;
137  bool something_to_transfer=false;
138  if(mag_cur>7000. && magnet_high ) {
139 
140  std::cout << " the magnet is ON and the constants are for magnet ON " << std::endl;
141 
142  } else if(mag_cur>7000. && !magnet_high ) {
143  something_to_transfer=true;
144  std::cout << " the magnet is ON and the constants are for magnet OFF " << std::endl;
145  std::cout << " I transfer the ON constants "<< std::endl;
146  file_=m_file_highfield;
147 
148  } else if(mag_cur<6000. && magnet_high ) {
149  something_to_transfer=true;
150  std::cout << " the magnet is OFF and the constants are for magnet ON "<< std::endl;
151  std::cout << " I transfer the OFF constants "<< std::endl;
152  file_=m_file_lowfield;
153 
154  } else if( mag_cur<6000. && !magnet_high ){
155 
156  std::cout << " the magnet is OFF and the constants are for magnet OFF "<< std::endl;
157  file_=m_file_lowfield;
158 
159  } else {
160 
161  std::cout << " the magnet is in a strange situation I do nothing ... just be patient "<< std::endl;
162 
163  }
164 
165 
166  if(something_to_transfer){
167 
168  std::cout << "Generating popcon record for run " << irun << "..." << std::flush;
169  std::cout << "going to open file "<<file_ << std::flush;
170 
171 
175 
176 
177  Time_t snc= (Time_t) irun ;
178 
180  std::make_pair(payload,snc));
181 
182  ss << "Run=" << irun << "_Magnet_changed_"<<std::endl;
183  m_userTextLog = ss.str()+";";
184 
185 
186  } else {
187  std::cout << "Run " << irun << " nothing sent to the DB"<< std::endl;
188 
189  ss<< "Run=" << irun << "_Magnet_NOT_changed_"<<std::endl;
190  m_userTextLog = ss.str()+";";
191  }
192 
193 
194  delete econn;
195  } else {
196  std::cout << "Run " << irun << " nothing sent to the DB"<< std::endl;
197  ss<< "Run=" << irun << "_no_new_runs_"<<std::endl;
198  m_userTextLog = ss.str()+";";
199 
200 
201  }
202 
203 
204 
205  std::cout << "Ecal - > end of getNewObjects -----------\n";
206 
207 }
208 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int run_t
Definition: CaliIOV.h:11
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.cc:562
static int readXML(const std::string &filename, EcalCondHeader &header, EcalFloatCondObjectContainer &record)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
float getMagnetCurrent() const
unsigned long long Time_t
Definition: Time.h:16
EcalIntercalibHandler(edm::ParameterSet const &)
std::vector< Item >::const_iterator const_iterator
tuple dataset
Definition: dataset.py:393
run_t getRunNumber() const
Definition: RunIOV.cc:45
EcalIntercalibConstantMap EcalIntercalibConstants
tuple cout
Definition: gather_cfg.py:121
Definition: RunIOV.h:13
float EcalIntercalibConstant