CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelFEDConfig.cc
Go to the documentation of this file.
1 //
2 // This class stores the information about a FED.
3 // This include the number, crate, and base address
4 //
5 //
6 
9 #include <fstream>
10 #include <iostream>
11 #include <map>
12 #include <assert.h>
13 #include <stdexcept>
14 
15 using namespace pos;
16 using namespace std;
17 
18 PixelFEDConfig::PixelFEDConfig(std::vector<std::vector<std::string> >& tableMat ) : PixelConfigBase(" "," "," "){
19 
20  std::string mthn = "[PixelFEDConfig::PixelFEDConfig()]\t\t\t " ;
21 
22  std::vector< std::string > ins = tableMat[0];
23  std::map<std::string , int > colM;
24  std::vector<std::string > colNames;
25 /*
26  EXTENSION_TABLE_NAME: FED_CRATE_CONFIG (VIEW: CONF_KEY_FED_CRATE_CONFIGV)
27 
28  CONFIG_KEY NOT NULL VARCHAR2(80)
29  KEY_TYPE NOT NULL VARCHAR2(80)
30  KEY_ALIAS NOT NULL VARCHAR2(80)
31  VERSION VARCHAR2(40)
32  KIND_OF_COND NOT NULL VARCHAR2(40)
33  PIXEL_FED NOT NULL NUMBER(38)
34  CRATE_NUMBER NOT NULL NUMBER(38)
35  VME_ADDR NOT NULL VARCHAR2(200)
36 */
37 
38  colNames.push_back("CONFIG_KEY" );
39  colNames.push_back("KEY_TYPE" );
40  colNames.push_back("KEY_ALIAS" );
41  colNames.push_back("VERSION" );
42  colNames.push_back("KIND_OF_COND" );
43  colNames.push_back("PIXEL_FED" );
44  colNames.push_back("CRATE_NUMBER" );
45  colNames.push_back("VME_ADDR" );
46 /*
47  colNames.push_back("PIXEL_FED" ); //0
48  colNames.push_back("CRATE_NUMBER" ); //1
49  colNames.push_back("VME_ADDRS_HEX"); //2
50 */
51  for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
52  {
53  for(unsigned int n=0; n<colNames.size(); n++)
54  {
55  if(tableMat[0][c] == colNames[n])
56  {
57  colM[colNames[n]] = c;
58  break;
59  }
60  }
61  }//end for
62  /*
63  for(unsigned int n=0; n<colNames.size(); n++)
64  {
65  if(colM.find(colNames[n]) == colM.end())
66  {
67  std::cerr << __LINE__ << "]\t" << mthn << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
68  assert(0);
69  }
70  }
71  */
72 
73  std::string fedname = "";
74  unsigned int fednum = 0;
75  fedconfig_.clear();
76  bool flag = false;
77  for(unsigned int r = 1 ; r < tableMat.size() ; r++){ //Goes to every row of the Matrix
78 
79  fedname = tableMat[r][colM["PIXEL_FED"]]; //This is not going to work if you change in the database "PxlFed_#" in the FED column.Im removing "PlxFed_" and store the number
80  //becuase the PixelFecConfig class ask for the fec number not the name.
81  // 01234567
82  // PxlFED_XX
83 // fedname.erase(0,7);
84  fednum = (unsigned int)atoi(fedname.c_str()) ;
85 
86  if(fedconfig_.empty())
87  {
89  unsigned int vme_base_address = 0 ;
90  vme_base_address = strtoul(tableMat[r][colM["VME_ADDR"]].c_str(), 0, 16);
91 // string hexVMEAddr = tableMat[r][colM["VME_ADDRS_HEX"]] ;
92 // sscanf(hexVMEAddr.c_str(), "%x", &vme_base_address) ;
93  tmp.setFEDParameters( fednum, (unsigned int)atoi(tableMat[r][colM["CRATE_NUMBER"]].c_str()) ,
94  vme_base_address);
95  fedconfig_.push_back(tmp);
96  }
97  else
98  {
99  for( unsigned int y = 0; y < fedconfig_.size() ; y++)
100  {
101  if (fedconfig_[y].getFEDNumber() == fednum) // This is to check if there are Pixel Feds already in the vector because
102  { // in the view of the database that I'm reading there are many repeated entries (AS FAR AS THESE PARAMS ARE CONCERNED).
103  flag = true; // This ensure that there are no objects in the fedconfig vector with repeated values.
104  break;
105  }
106  else flag = false;
107  }
108 
109  if(flag == false)
110  {
112  tmp.setFEDParameters( fednum, (unsigned int)atoi(tableMat[r][colM["CRATE_NUMBER"]].c_str()) ,
113  (unsigned int)strtoul(tableMat[r][colM["VME_ADDR"]].c_str(), 0, 16));
114  fedconfig_.push_back(tmp);
115  }
116  }//end else
117  }//end for r
118 /*
119  std::cout << __LINE__ << "]\t" << mthn << std::endl;
120 
121  for( unsigned int x = 0 ; x < fedconfig_.size() ; x++)
122  {
123  std::cout<< __LINE__ << "]\t" << mthn << fedconfig_[x] << std::endl;
124  }
125 
126  std::cout<< __LINE__ << "]\t" << mthn << fedconfig_.size() << std::endl;
127 */
128 }//end Constructor
129 
130 
131 
132 //*****************************************************************************************************
133 
134 
135 
136 
138  PixelConfigBase(" "," "," "){
139 
140  std::string mthn = "[PixelFEDConfig::PixelFEDConfig()]\t\t\t " ;
141  std::ifstream in(filename.c_str());
142 
143  if (!in.good()){
144  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename.c_str() << std::endl;
145  throw std::runtime_error("Failed to open file "+filename);
146  }
147  else {
148  std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename.c_str() << std::endl;
149  }
150 
151  std::string dummy;
152 
153  in >> dummy;
154  in >> dummy;
155  in >> dummy;
156  in >> dummy;
157  in >> dummy;
158  in >> dummy;
159 
160  do {
161 
162  unsigned int fednumber;
163  unsigned int crate;
164  unsigned int vme_base_address;
165 
166  in >> fednumber >> crate >> std::hex >> vme_base_address >> std::dec;
167 
168  if (!in.eof() ){
169  // std::cout << __LINE__ << "]\t" << mthn << std::dec << fednumber <<" "<< crate << " 0x"
170  // << std::hex << vme_base_address<<std::dec<<std::endl;
172 
173  tmp.setFEDParameters(fednumber , crate , vme_base_address);
174 
175  fedconfig_.push_back(tmp);
176  }
177 
178  }
179  while (!in.eof());
180  in.close();
181 
182  }
183 
184 //std::ostream& operator<<(std::ostream& s, const PixelFEDConfig& table){
185 
186 //for (unsigned int i=0;i<table.translationtable_.size();i++){
187 // s << table.translationtable_[i]<<std::endl;
188 // }
189 // return s;
190 
191 //}
192 
194 
196 
197  std::string mthn = "[PixelFEDConfig::writeASCII()]\t\t\t\t " ;
198  if (dir!="") dir+="/";
199  string filename=dir+"fedconfig.dat";
200 
201  ofstream out(filename.c_str());
202  if(!out.good()){
203  cout << __LINE__ << "]\t" << mthn << "Could not open file: " << filename << endl;
204  assert(0);
205  }
206 
207  out <<" #FED number crate vme base address" <<endl;
208  for(unsigned int i=0;i<fedconfig_.size();i++){
209  out << fedconfig_[i].getFEDNumber()<<" "
210  << fedconfig_[i].getCrate()<<" "
211  << "0x"<<hex<<fedconfig_[i].getVMEBaseAddress()<<dec<<endl;
212  }
213  out.close();
214 }
215 
216 
217 unsigned int PixelFEDConfig::getNFEDBoards() const{
218 
219  return fedconfig_.size();
220 
221 }
222 
223 unsigned int PixelFEDConfig::getFEDNumber(unsigned int i) const{
224 
225  assert(i<fedconfig_.size());
226  return fedconfig_[i].getFEDNumber();
227 
228 }
229 
230 
231 unsigned int PixelFEDConfig::getCrate(unsigned int i) const{
232 
233  assert(i<fedconfig_.size());
234  return fedconfig_[i].getCrate();
235 
236 }
237 
238 
239 unsigned int PixelFEDConfig::getVMEBaseAddress(unsigned int i) const{
240 
241  assert(i<fedconfig_.size());
242  return fedconfig_[i].getVMEBaseAddress();
243 
244 }
245 
246 
247 unsigned int PixelFEDConfig::crateFromFEDNumber(unsigned int fednumber) const{
248 
249 
250  std::string mthn = "[PixelFEDConfig::crateFromFEDNumber()]\t\t\t " ;
251  for(unsigned int i=0;i<fedconfig_.size();i++){
252  if (fedconfig_[i].getFEDNumber()==fednumber) return fedconfig_[i].getCrate();
253  }
254 
255  std::cout << __LINE__ << "]\t" << mthn << "Could not find FED number: " << fednumber << std::endl;
256 
257  assert(0);
258 
259  return 0;
260 
261 }
262 
263 
264 unsigned int PixelFEDConfig::VMEBaseAddressFromFEDNumber(unsigned int fednumber) const{
265 
266  std::string mthn = "[PixelFEDConfig::VMEBaseAddressFromFEDNumber()]\t\t " ;
267  for(unsigned int i=0;i<fedconfig_.size();i++){
268  if (fedconfig_[i].getFEDNumber()==fednumber) return fedconfig_[i].getVMEBaseAddress();
269  }
270 
271  std::cout << __LINE__ << "]\t" << mthn << "Could not find FED number: " << fednumber << std::endl;
272 
273  assert(0);
274 
275  return 0;
276 
277 }
278 
279 unsigned int PixelFEDConfig::FEDNumberFromCrateAndVMEBaseAddress(unsigned int crate, unsigned int vmebaseaddress) const {
280 
281  std::string mthn = "[PixelFEDConfig::FEDNumberFromCrateAndVMEBaseAddress()]\t " ;
282  for(unsigned int i=0;i<fedconfig_.size();i++){
283  if (fedconfig_[i].getCrate()==crate&&
284  fedconfig_[i].getVMEBaseAddress()==vmebaseaddress) return fedconfig_[i].getFEDNumber();
285  }
286 
287  std::cout << __LINE__ << "]\t" << mthn << "Could not find FED crate and address: "<< crate << ", " << vmebaseaddress << std::endl;
288 
289  assert(0);
290 
291  return 0;
292 
293 }
294 
295 //=============================================================================================
297  int version,
298  std::string path,
299  std::ofstream *outstream,
300  std::ofstream *out1stream,
301  std::ofstream *out2stream) const
302 {
303  std::string mthn = "[PixelFEDConfig::::writeXMLHeader()]\t\t\t " ;
304  std::stringstream fullPath ;
305  fullPath << path << "/Pixel_FedCrateConfig_" << PixelTimeFormatter::getmSecTime() << ".xml" ;
306  cout << __LINE__ << "]\t" << mthn << "Writing to: " << fullPath.str() << endl ;
307 
308  outstream->open(fullPath.str().c_str()) ;
309  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << endl ;
310  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << endl ;
311  *outstream << " <HEADER>" << endl ;
312  *outstream << " <TYPE>" << endl ;
313  *outstream << " <EXTENSION_TABLE_NAME>FED_CRATE_CONFIG</EXTENSION_TABLE_NAME>" << endl ;
314  *outstream << " <NAME>Pixel FED Crate Configuration</NAME>" << endl ;
315  *outstream << " </TYPE>" << endl ;
316  *outstream << " <RUN>" << endl ;
317  *outstream << " <RUN_NAME>Pixel FED Crate Configuration</RUN_NAME>" << endl ;
318  *outstream << " <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << endl ;
319  *outstream << " <LOCATION>CERN P5</LOCATION>" << endl ;
320  *outstream << " </RUN>" << endl ;
321  *outstream << " </HEADER>" << endl ;
322  *outstream << " " << endl ;
323  *outstream << " <DATA_SET>" << endl ;
324  *outstream << " <PART>" << endl ;
325  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << endl ;
326  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << endl ;
327  *outstream << " </PART>" << endl ;
328  *outstream << " <VERSION>" << version << "</VERSION>" << endl ;
329  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << endl ;
330  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << endl ;
331  *outstream << " " << endl ;
332 }
333 
334 //=============================================================================================
335 void PixelFEDConfig::writeXML(std::ofstream *outstream,
336  std::ofstream *out1stream,
337  std::ofstream *out2stream) const
338 {
339  std::string mthn = "[PixelFEDConfig::writeXML()]\t\t\t " ;
340 
341  for(unsigned int i=0;i<fedconfig_.size();i++){
342  *outstream << " <DATA>" << endl ;
343  *outstream << " <PIXEL_FED>" << fedconfig_[i].getFEDNumber() << "</PIXEL_FED>" << endl ;
344  *outstream << " <CRATE_NUMBER>" << fedconfig_[i].getCrate() << "</CRATE_NUMBER>" << endl ;
345  *outstream << " <VME_ADDR>" << "0x" << hex << fedconfig_[i].getVMEBaseAddress() << dec << "</VME_ADDR>" << endl ;
346  *outstream << " </DATA>" << endl ;
347  *outstream << "" << endl ;
348  }
349 
350 }
351 
352 //=============================================================================================
353 void PixelFEDConfig::writeXMLTrailer(std::ofstream *outstream,
354  std::ofstream *out1stream,
355  std::ofstream *out2stream) const
356 {
357  std::string mthn = "[PixelFEDConfig::writeXMLTrailer()]\t\t\t " ;
358 
359  *outstream << " </DATA_SET>" << endl ;
360  *outstream << "</ROOT> " << endl ;
361 
362  outstream->close() ;
363 }
int i
Definition: DBlmapReader.cc:9
void setFEDParameters(unsigned int fednumber, unsigned int crate, unsigned int vmebaseaddress)
unsigned int FEDNumberFromCrateAndVMEBaseAddress(unsigned int crate, unsigned int vmebaseaddress) const
This file contains the base class for &quot;pixel configuration data&quot; management.
unsigned int crateFromFEDNumber(unsigned int fednumber) const
unsigned int VMEBaseAddressFromFEDNumber(unsigned int fednumber) const
assert(m_qm.get())
std::vector< PixelFEDParameters > fedconfig_
void writeXML(pos::PixelConfigKey key, int version, std::string path) const
unsigned int getFEDNumber(unsigned int i) const
static std::string getmSecTime(void)
unsigned int getCrate(unsigned int i) const
tuple path
else: Piece not in the list, fine.
static std::string getTime(void)
This class implements..
std::string getComment() const
virtual void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) const
This class provides utility methods to manipulate ASCII formatted timestamps.
unsigned int getVMEBaseAddress(unsigned int i) const
tuple ins
Definition: cuy.py:312
std::string getAuthor() const
unsigned int getNFEDBoards() const
virtual void writeASCII(std::string dir) const
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
This class implements..
tuple out
Definition: dbtoconf.py:99
virtual void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) const
This class implements..
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
PixelFEDConfig(std::string filename)
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121
dbl *** dir
Definition: mlp_gen.cc:35