test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalTPGFineGrainTowerEEHandler.cc
Go to the documentation of this file.
10 
11 #include<iostream>
12 
14  : m_name(ps.getUntrackedParameter<std::string>("name","EcalTPGFineGrainTowerEEHandler")) {
15 
16  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "EcalTPGFineGrainTowerEE Source handler constructor.";
17  m_firstRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("firstRun").c_str()));
18  m_lastRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("lastRun").c_str()));
19  m_sid= ps.getParameter<std::string>("OnlineDBSID");
20  m_user= ps.getParameter<std::string>("OnlineDBUser");
21  m_pass= ps.getParameter<std::string>("OnlineDBPassword");
22  m_locationsource= ps.getParameter<std::string>("LocationSource");
23  m_location=ps.getParameter<std::string>("Location");
24  m_gentag=ps.getParameter<std::string>("GenTag");
25  m_runtype=ps.getParameter<std::string>("RunType");
26 
27  edm::LogInfo("EcalTPGFineGrainTowerEEHandler")<< m_sid<<"/"<<m_user<<"/"<<m_location<<"/"<<m_gentag;
28 
29 }
30 
32 {
33 }
34 
36 {
37 
38  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "Started GetNewObjects!!!";
39 
40  //check whats already inside of database
41  if (tagInfo().size){
42  //check whats already inside of database
43  std::cout << "got offlineInfo = " << std::endl;
44  std::cout << "tag name = " << tagInfo().name << std::endl;
45  std::cout << "size = " << tagInfo().size << std::endl;
46  } else {
47  std::cout << " First object for this tag " << std::endl;
48  }
49 
50  unsigned int max_since=0;
51  max_since=static_cast<unsigned int>(tagInfo().lastInterval.first);
52  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "max_since : " << max_since;
53  Ref fgrTTEE_db = lastPayload();
54 
55  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "retrieved last payload ";
56 
57  // here we retrieve all the runs after the last from online DB
58  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "Retrieving run list from ONLINE DB ... ";
59 
60  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "Making connection...";
61  econn = new EcalCondDBInterface( m_sid, m_user, m_pass );
62  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "Done.";
63 
64  if (!econn)
65  {
66  std::cout << " connection parameters " <<m_sid <<"/"<<m_user<<std::endl;
67  // cerr << e.what() << std::endl;
68  throw cms::Exception("OMDS not available");
69  }
70 
71 
72  LocationDef my_locdef;
73  my_locdef.setLocation(m_location);
74 
75  RunTypeDef my_rundef;
76  my_rundef.setRunType(m_runtype);
77 
78  RunTag my_runtag;
79  my_runtag.setLocationDef( my_locdef );
80  my_runtag.setRunTypeDef( my_rundef );
81  my_runtag.setGeneralTag(m_gentag);
82 
83  readFromFile("last_tpg_fgrTTEE_settings.txt");
84 
85 
86  unsigned int min_run=m_i_run_number+1;
87 
88  if(m_firstRun<m_i_run_number) {
89  min_run=m_i_run_number+1;
90  } else {
91  min_run=m_firstRun;
92  }
93  if(min_run<max_since) {
94  min_run=max_since+1; // we have to add 1 to the last transferred one
95  }
96 
97  std::cout<<"m_i_run_number"<< m_i_run_number <<"m_firstRun "<<m_firstRun<< "max_since " <<max_since<< std::endl;
98 
99  unsigned int max_run=m_lastRun;
100  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "min_run= " << min_run << " max_run= " << max_run;
101 
102  RunList my_list;
103  my_list=econn->fetchGlobalRunListByLocation(my_runtag, min_run, max_run, my_locdef);
104  // my_list=econn->fetchRunListByLocation(my_runtag,min_run,max_run,my_locdef);
105 
106  std::vector<RunIOV> run_vec= my_list.getRuns();
107  size_t num_runs=run_vec.size();
108 
109  std::cout <<"number of runs is : "<< num_runs<< std::endl;
110 
111  unsigned int irun;
112  if(num_runs>0){
113  // going to query the ecal logic id
114  std::vector<EcalLogicID> my_TTEcalLogicId_EE;
115  my_TTEcalLogicId_EE = econn->getEcalLogicIDSetOrdered( "EE_trigger_tower",
116  1, 200,
117  1, 70,
119  "EE_offline_towerid",12 );
120  std::cout <<" GOT the logic ID for the EE trigger towers "<< std::endl;
121 
122  for(size_t kr=0; kr<run_vec.size(); kr++){
123 
124  irun=static_cast<unsigned int>(run_vec[kr].getRunNumber());
125 
126  std::cout<<" **************** "<<std::endl;
127  std::cout<<" **************** "<<std::endl;
128  std::cout<<" run= "<<irun<<std::endl;
129 
130  // retrieve the data
131  std::map<EcalLogicID, RunTPGConfigDat> dataset;
132  econn->fetchDataSet(&dataset, &run_vec[kr]);
133 
134  std::string the_config_tag="";
135  int the_config_version=0;
136 
137  std::map< EcalLogicID, RunTPGConfigDat>::const_iterator it;
138 
139  int nr=0;
140  for( it=dataset.begin(); it!=dataset.end(); it++ )
141  {
142  ++nr;
143  EcalLogicID ecalid = it->first;
144  RunTPGConfigDat dat = it->second;
145  the_config_tag=dat.getConfigTag();
146  the_config_version=dat.getVersion();
147  }
148 
149  // it is all the same for all SM... get the last one
150 
151  std::cout<<" run= "<<irun<<" tag "<<the_config_tag<<" version="<<the_config_version <<std::endl;
152 
153  // here we should check if it is the same as previous run.
154 
155 
156  if((the_config_tag != m_i_tag || the_config_version != m_i_version ) && nr>0 ) {
157  std::cout<<"the tag is different from last transferred run ... retrieving last config set from DB"<<std::endl;
158 
159  FEConfigMainInfo fe_main_info;
160  fe_main_info.setConfigTag(the_config_tag);
161  fe_main_info.setVersion(the_config_version);
162 
163  try{
164  std::cout << " before fetch config set" << std::endl;
165  econn-> fetchConfigSet(&fe_main_info);
166  std::cout << " after fetch config set" << std::endl;
167 
168  // now get TPGFineGrainTowerEE
169  int fgrId=fe_main_info.getFgrId();
170 
171  if( fgrId != m_i_fgrTTEE ) {
172 
173  FEConfigFgrInfo fe_fgr_info;
174  fe_fgr_info.setId(fgrId);
175  econn-> fetchConfigSet(&fe_fgr_info);
176  std::map<EcalLogicID, FEConfigFgrEETowerDat> dataset_TpgFineGrainEE;
177  econn->fetchDataSet(&dataset_TpgFineGrainEE, &fe_fgr_info);
179 
180  typedef std::map<EcalLogicID, FEConfigFgrEETowerDat>::const_iterator CIfefgr;
181  EcalLogicID ecid_xt;
182  FEConfigFgrEETowerDat rd_fgr;
183  int itowers=0;
184 
185  for (CIfefgr p = dataset_TpgFineGrainEE.begin(); p != dataset_TpgFineGrainEE.end(); p++) {
186  ecid_xt = p->first;
187  rd_fgr = p->second;
188 
189  std::string ecid_name=ecid_xt.getName();
190 
191  if (ecid_name=="EE_trigger_tower") {
192 
193  int tccid=ecid_xt.getID1();
194  // TT number
195  int towerid=ecid_xt.getID2();
196 
197  bool set_the_tower=false;
198  int towid;
199  for (size_t itower=0; itower<my_TTEcalLogicId_EE.size(); itower++) {
200 
201  if(!set_the_tower){
202 
203  if(my_TTEcalLogicId_EE[itower].getID1()==tccid && my_TTEcalLogicId_EE[itower].getID2()==towerid){
204  towid =my_TTEcalLogicId_EE[itower].getLogicID();
205  set_the_tower=true;
206  break;
207  }
208  }
209 
210  }
211 
212  if(set_the_tower){
213  fgrMap->setValue(towid, rd_fgr.getLUTValue());
214 
215  } else {
216  std::cout <<" these may be the additional towers TCC/TT "
217  << tccid<<"/"<<towerid<<std::endl;
218  }
219 
220  ++itowers;
221  }
222  }
223 
224  Time_t snc= (Time_t) irun ;
225 
226  m_to_transfer.push_back(std::make_pair((EcalTPGFineGrainTowerEE *)fgrMap,snc));
227 
228  m_i_run_number=irun;
229  m_i_tag=the_config_tag;
230  m_i_version=the_config_version;
231  m_i_fgrTTEE=fgrId;
232 
233  writeFile("last_tpg_fgrTTEE_settings.txt");
234 
235  } else {
236 
237  m_i_run_number=irun;
238  m_i_tag=the_config_tag;
239  m_i_version=the_config_version;
240 
241  writeFile("last_tpg_fgrTTEE_settings.txt");
242 
243  std::cout<< " even if the tag/version is not the same, the fgrTTEE id is the same -> no transfer needed "<< std::endl;
244 
245  }
246 
247  } catch (std::exception &e) {
248  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" <<the_config_tag
249  <<" version="<<the_config_version<< std::endl;
250  std::cout << e.what() << std::endl;
251  m_i_run_number=irun;
252 
253  }
254  std::cout<<" **************** "<<std::endl;
255 
256  } else if(nr==0) {
257  m_i_run_number=irun;
258  std::cout<< " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed "<< std::endl;
259  std::cout<<" **************** "<<std::endl;
260  } else {
261  m_i_run_number=irun;
262  m_i_tag=the_config_tag;
263  m_i_version=the_config_version;
264  std::cout<< " the tag/version is the same -> no transfer needed "<< std::endl;
265  std::cout<<" **************** "<<std::endl;
266  writeFile("last_tpg_fgrTTEE_settings.txt");
267  }
268 
269  }
270  }
271 
272  delete econn;
273  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "Ecal - > end of getNewObjects -----------";
274 }
275 
276 
278  //-------------------------------------------------------------
279 
280  m_i_tag="";
281  m_i_version=0;
282  m_i_run_number=0;
283  m_i_fgrTTEE=0;
284 
285  FILE *inpFile; // input file
286  inpFile = fopen(inputFile,"r");
287  if(!inpFile) {
288  edm::LogError("EcalTPGFineGrainTowerEEHandler")<<"*** Can not open file: "<<inputFile;
289  return;
290  }
291 
292  char line[256];
293 
294  std::ostringstream str;
295 
296  fgets(line,255,inpFile);
297  m_i_tag=to_string(line);
298  str << "gen tag " << m_i_tag << std::endl ; // should I use this?
299 
300  fgets(line,255,inpFile);
301  m_i_version=atoi(line);
302  str << "version= " << m_i_version << std::endl ;
303 
304  fgets(line,255,inpFile);
305  m_i_run_number=atoi(line);
306  str << "run_number= " << m_i_run_number << std::endl ;
307 
308  fgets(line,255,inpFile);
309  m_i_fgrTTEE=atoi(line);
310  str << "fgrTTEE_config= " << m_i_fgrTTEE << std::endl ;
311 
312 
313  fclose(inpFile); // close inp. file
314 
315 }
316 
318  //-------------------------------------------------------------
319 
320 
321  std::ofstream myfile;
322  myfile.open (inputFile);
323  myfile << m_i_tag <<std::endl;
324  myfile << m_i_version <<std::endl;
325  myfile << m_i_run_number <<std::endl;
326  myfile << m_i_fgrTTEE <<std::endl;
327 
328  myfile.close();
329 
330 }
T getParameter(std::string const &) const
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:70
std::vector< RunIOV > getRuns()
Definition: RunList.cc:35
std::string getConfigTag() const
int getVersion() const
Definition: RunTag.h:13
void setVersion(int id)
int getID2() const
Definition: EcalLogicID.cc:51
std::string getName() const
Definition: EcalLogicID.cc:36
int getID1() const
Definition: EcalLogicID.cc:46
void setValue(const uint32_t &id, const uint32_t &lut)
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:53
void setId(int id)
int getFgrId() const
void setRunType(std::string runtype)
Definition: RunTypeDef.cc:33
tuple dataset
Definition: dataset.py:859
cond::Time_t Time_t
Definition: Time.h:17
void setConfigTag(std::string x)
Definition: IODConfig.h:31
static const int NULLID
Definition: EcalLogicID.h:42
void setLocation(std::string loc)
Definition: LocationDef.cc:33
tuple cout
Definition: gather_cfg.py:145
void setGeneralTag(std::string tag)
Definition: RunTag.cc:36
tuple size
Write out results.