CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalADCToGeVHandler.cc
Go to the documentation of this file.
5 
6 
7 #include<iostream>
8 
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 }
30 
32 {
33 }
34 
35 
37 {
38 
39  std::cout << "------- Ecal - > getNewObjects\n";
40 
41  std::ostringstream ss;
42  ss<<"ECAL ";
43 
44  unsigned int max_since=0;
45  max_since=static_cast<unsigned int>(tagInfo().lastInterval.first);
46  std::cout << "max_since : " << max_since << std::endl;
47  Ref ped_db = lastPayload();
48 
49  // we parse the last record in the DB and check if it is low or high field
50 
51  std::cout << "retrieved last payload " << std::endl;
52 
53 
54  EcalADCToGeVConstant the_cal ;
55 
56  float adc_eb=ped_db->getEBValue();
57  float adc_ee=ped_db->getEEValue();
58 
59  float the_value_high_eb=0.03894;
60  float the_value_high_ee=0.06285;
61 
62 
63  bool magnet_high=true;
64  if(adc_eb!= the_value_high_eb || adc_ee!= the_value_high_ee ) magnet_high=false;
65 
66 
67  // here we connect to the online DB to check the value of the magnetic field
68 
69  std::cout << "Connecting to ONLINE DB ... " << std::endl;
70  econn = new EcalCondDBInterface( m_sid, m_user, m_pass );
71  std::cout << "Connection done" << std::endl;
72 
73  if (!econn)
74  {
75  std::cout << " Problem with OMDS: connection parameters " <<m_sid <<"/"<<m_user<<"/"<<m_pass<<std::endl;
76  throw cms::Exception("OMDS not available");
77  }
78 
79 
80  std::cout << "Retrieving last run from ONLINE DB ... " << std::endl;
81  std::map<EcalLogicID, RunDat> rundat;
82  RunIOV rp ;
83  run_t runmax=10000000;
84  std::string location_p5="P5_Co";
85  econn->fetchValidDataSet(&rundat , &rp, location_p5 ,runmax);
86 
87  unsigned long long irun=(unsigned long long) rp.getRunNumber();
88 
89  std::cout<< "retrieved run number "<< irun <<std::endl;
90 
91  if(irun>max_since) {
92 
93 
94  // retrieve from last value data record
95  // always call this method at first run
96 
97  std::map<EcalLogicID, RunDCSMagnetDat> dataset;
98 
99  econn->fetchDataSet(&dataset, &rp);
100 
101  if (!dataset.size()) {
102  throw(std::runtime_error("Zero rows read back"));
103  } else {
104  std::cout<< "retrieved magnet current"<<std::endl;
105  }
106 
107 
108  float mag_cur=0;
109 
110  std::map< EcalLogicID, RunDCSMagnetDat >::iterator it;
111  for (it=dataset.begin(); it!=dataset.end(); ++it){
112 
113  RunDCSMagnetDat a_mag = (*it).second;
114  mag_cur= a_mag.getMagnetCurrent();
115 
116  }
117 
118 
119  std::string file_=m_file_highfield;
120  bool something_to_transfer=false;
121  if(mag_cur>7000. && magnet_high ) {
122 
123  std::cout << " the magnet is ON and the constants are for magnet ON " << std::endl;
124 
125  } else if(mag_cur>7000. && !magnet_high ) {
126  something_to_transfer=true;
127  std::cout << " the magnet is ON and the constants are for magnet OFF " << std::endl;
128  std::cout << " I transfer the ON constants "<< std::endl;
129  file_=m_file_highfield;
130 
131  } else if(mag_cur<6000. && magnet_high ) {
132  something_to_transfer=true;
133  std::cout << " the magnet is OFF and the constants are for magnet ON "<< std::endl;
134  std::cout << " I transfer the OFF constants "<< std::endl;
135  file_=m_file_lowfield;
136 
137  } else if( mag_cur<6000. && !magnet_high ){
138 
139  std::cout << " the magnet is OFF and the constants are for magnet OFF "<< std::endl;
140  file_=m_file_lowfield;
141 
142  } else {
143 
144  std::cout << " the magnet is in a strange situation I do nothing ... just be patient "<< std::endl;
145 
146  }
147 
148 
149  if(something_to_transfer){
150 
151  std::cout << "Generating popcon record for run " << irun << "..." << std::flush;
152  std::cout << "going to open file "<<file_ << std::flush;
153 
154 
155  EcalCondHeader header;
157  EcalADCToGeVXMLTranslator::readXML(file_,header,*payload);
158 
159 
160  Time_t snc= (Time_t) irun ;
161 
163  std::make_pair(payload,snc));
164 
165  ss << "Run=" << irun << "_Magnet_changed_"<<std::endl;
166  m_userTextLog = ss.str()+";";
167 
168 
169  } else {
170  std::cout << "Run " << irun << " nothing sent to the DB"<< std::endl;
171 
172  ss<< "Run=" << irun << "_Magnet_NOT_changed_"<<std::endl;
173  m_userTextLog = ss.str()+";";
174  }
175 
176 
177  delete econn;
178  } else {
179  std::cout << "Run " << irun << " nothing sent to the DB"<< std::endl;
180  ss<< "Run=" << irun << "_no_new_runs_"<<std::endl;
181  m_userTextLog = ss.str()+";";
182 
183 
184  }
185 
186 
187 
188  std::cout << "Ecal - > end of getNewObjects -----------\n";
189 
190 }
191 
T getParameter(std::string const &) const
int run_t
Definition: CaliIOV.h:11
static int readXML(const std::string &filename, EcalCondHeader &header, EcalADCToGeVConstant &record)
float getMagnetCurrent() const
tuple dataset
Definition: dataset.py:400
run_t getRunNumber() const
Definition: RunIOV.cc:45
cond::Time_t Time_t
Definition: Time.h:17
EcalADCToGeVHandler(edm::ParameterSet const &)
tuple cout
Definition: gather_cfg.py:121
Definition: RunIOV.h:13