CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelFECConfig.cc
Go to the documentation of this file.
1 //
2 // This class stores the information about a FEC.
3 // This include the number, crate, and base address
4 //
5 //
6 
9 #include <fstream>
10 #include <sstream>
11 #include <map>
12 #include <assert.h>
13 #include <stdexcept>
14 
15 using namespace pos;
16 using namespace std;
17 
18 
19 
20 PixelFECConfig::PixelFECConfig(std::vector<std::vector<std::string> >& tableMat ) : PixelConfigBase(" "," "," "){
21 
22  std::map<std::string , int > colM;
23  std::vector<std::string > colNames;
39  colNames.push_back("CONFIG_KEY" );
40  colNames.push_back("KEY_TYPE" );
41  colNames.push_back("KEY_ALIAS" );
42  colNames.push_back("VERSION" );
43  colNames.push_back("KIND_OF_COND" );
44  colNames.push_back("PIXFEC_NAME" );
45  colNames.push_back("CRATE_NUMBER" );
46  colNames.push_back("SLOT_NUMBER" );
47  colNames.push_back("VME_ADDR" );
48 
49  for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
50  {
51  for(unsigned int n=0; n<colNames.size(); n++)
52  {
53  if(tableMat[0][c] == colNames[n]){
54  colM[colNames[n]] = c;
55  break;
56  }
57  }
58  }//end for
59  /*
60  for(unsigned int n=0; n<colNames.size(); n++)
61  {
62  if(colM.find(colNames[n]) == colM.end()){
63  std::cerr << "[PixelFECConfig::PixelFECConfig()]\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
64  assert(0);
65  }
66  }
67  */
68 
69  fecconfig_.clear();
70  for(unsigned int r = 1 ; r < tableMat.size() ; r++) //Goes to every row of the Matrix
71  {
72  unsigned int fecnumber;
73  unsigned int crate;
74  unsigned int vme_base_address;
75 
76 // 01234567890123
77 // BPix_Pxl_FEC_1
78 // string fullFECName = tableMat[r][colM["PIXEL_FEC"]] ;
79 // fullFECName.replace(0,13,"") ;
80  fecnumber = atoi(tableMat[r][colM["PIXFEC_NAME"]].c_str()) ;
81  crate = atoi(tableMat[r][colM["CRATE_NUMBER"]].c_str()) ;
82  string hexVMEAddr = tableMat[r][colM["VME_ADDR"]] ;
83  sscanf(hexVMEAddr.c_str(), "%x", &vme_base_address) ;
85 
86  tmp.setFECParameters(fecnumber , crate , vme_base_address);
87 
88  fecconfig_.push_back(tmp);
89  }
90 
91 }// end contructor
92 
93 //****************************************************************************************
94 
95 
97  PixelConfigBase(" "," "," "){
98 
99  std::string mthn = "[[PixelFECConfig::PixelFECConfig()]\t\t\t " ;
100 
101  std::ifstream in(filename.c_str());
102 
103  if (!in.good()){
104  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
105  throw std::runtime_error("Failed to open file "+filename);
106  }
107  else {
108  std::cout << __LINE__ << "]\t" << mthn <<" Opened: " << filename << std::endl;
109  }
110 
111  std::string dummy;
112 
113  in >> dummy;
114  in >> dummy;
115  in >> dummy;
116  in >> dummy;
117  in >> dummy;
118  in >> dummy;
119 
120  do {
121 
122  unsigned int fecnumber;
123  unsigned int crate;
124  unsigned int vme_base_address;
125 
126  in >> fecnumber >> crate >> std::hex>> vme_base_address >>std::dec ;
127 
128  if (!in.eof() ){
129  //std::cout << __LINE__ << "]\t" << mthn << fecnumber <<" "<< crate << " "
130  // << std::hex << vme_base_address<<std::dec<<std::endl;
131 
133 
134  tmp.setFECParameters(fecnumber , crate , vme_base_address);
135 
136  fecconfig_.push_back(tmp);
137  }
138 
139  }
140  while (!in.eof());
141  in.close();
142 }
143 
144 
145 //std::ostream& operator<<(std::ostream& s, const PixelFECConfig& table){
146 
147  //for (unsigned int i=0;i<table.translationtable_.size();i++){
148  // s << table.translationtable_[i]<<std::endl;
149  // }
150 // return s;
151 
152 //}
153 
154 
155 unsigned int PixelFECConfig::getNFECBoards() const{
156 
157  return fecconfig_.size();
158 
159 }
160 
161 unsigned int PixelFECConfig::getFECNumber(unsigned int i) const{
162 
163  assert(i<fecconfig_.size());
164  return fecconfig_[i].getFECNumber();
165 
166 }
167 
168 
169 unsigned int PixelFECConfig::getCrate(unsigned int i) const{
170 
171  assert(i<fecconfig_.size());
172  return fecconfig_[i].getCrate();
173 
174 }
175 
176 
177 unsigned int PixelFECConfig::getVMEBaseAddress(unsigned int i) const{
178 
179  assert(i<fecconfig_.size());
180  return fecconfig_[i].getVMEBaseAddress();
181 
182 }
183 
184 
185 unsigned int PixelFECConfig::crateFromFECNumber(unsigned int fecnumber) const{
186 
187  std::string mthn = "[PixelFECConfig::crateFromFECNumber()]\t\t\t " ;
188  for(unsigned int i=0;i<fecconfig_.size();i++){
189  if (fecconfig_[i].getFECNumber()==fecnumber) return fecconfig_[i].getCrate();
190  }
191 
192  std::cout << __LINE__ << "]\t" << mthn << "Could not find FEC number: " << fecnumber << std::endl;
193 
194  assert(0);
195 
196  return 0;
197 
198 }
199 
200 unsigned int PixelFECConfig::VMEBaseAddressFromFECNumber(unsigned int fecnumber) const{
201 
202  std::string mthn = "[PixelFECConfig::VMEBaseAddressFromFECNumber()]\t\t " ;
203  for(unsigned int i=0;i<fecconfig_.size();i++){
204  if (fecconfig_[i].getFECNumber()==fecnumber) return fecconfig_[i].getVMEBaseAddress();
205  }
206 
207  std::cout << __LINE__ << "]\t" << mthn << "Could not find FEC number: " << fecnumber << std::endl;
208 
209  assert(0);
210 
211  return 0;
212 
213 }
214 
215 //=============================================================================================
217 
218  if (dir!="") dir+="/";
219  std::string filename=dir+"fecconfig.dat";
220  std::ofstream out(filename.c_str());
221 
222  std::vector< PixelFECParameters >::const_iterator i=fecconfig_.begin();
223 
224  out << "#FEC number crate vme base address" << endl;
225  for(;i!=fecconfig_.end();++i){
226  out << i->getFECNumber()<<" "
227  << i->getCrate()<<" "
228  << "0x"<<hex<<i->getVMEBaseAddress()<<dec<<endl;
229  }
230 
231 }
232 
233 //=============================================================================================
235  int version,
236  std::string path,
237  std::ofstream *outstream,
238  std::ofstream *out1stream,
239  std::ofstream *out2stream) const
240 {
241  std::string mthn = "[PixelFECConfig::writeXMLHeader()]\t\t\t " ;
242  std::stringstream fullPath ;
243  fullPath << path << "/Pixel_PixelFecParameters_" << PixelTimeFormatter::getmSecTime() << ".xml" ;
244  cout << __LINE__ << "]\t" << mthn << "Writing to: " << fullPath.str() << endl ;
245 
246  outstream->open(fullPath.str().c_str()) ;
247 
248  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << endl ;
249  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << endl ;
250  *outstream << " <HEADER>" << endl ;
251  *outstream << " <TYPE>" << endl ;
252  *outstream << " <EXTENSION_TABLE_NAME>PIXEL_FEC_PARAMETERS</EXTENSION_TABLE_NAME>" << endl ;
253  *outstream << " <NAME>Pixel FEC Parameters</NAME>" << endl ;
254  *outstream << " </TYPE>" << endl ;
255  *outstream << " <RUN>" << endl ;
256  *outstream << " <RUN_TYPE>Pixel FEC Parameters</RUN_TYPE>" << endl ;
257  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << endl ;
258  *outstream << " <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << endl ;
259  *outstream << " <LOCATION>CERN P5</LOCATION>" << endl ;
260  *outstream << " </RUN>" << endl ;
261  *outstream << " </HEADER>" << endl ;
262  *outstream << "" << endl ;
263  *outstream << " <DATA_SET>" << endl ;
264  *outstream << " <PART>" << endl ;
265  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << endl ;
266  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << endl ;
267  *outstream << " </PART>" << endl ;
268  *outstream << " <VERSION>" << version << "</VERSION>" << endl ;
269  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << endl ;
270  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << endl ;
271 }
272 
273 //=============================================================================================
274 void PixelFECConfig::writeXML( std::ofstream *outstream,
275  std::ofstream *out1stream,
276  std::ofstream *out2stream) const
277 {
278  std::string mthn = "[PixelFECConfig::writeXML()]\t\t\t " ;
279 
280  std::vector< PixelFECParameters >::const_iterator i=fecconfig_.begin();
281 
282  for(;i!=fecconfig_.end();++i){
283  *outstream << "" << endl ;
284  *outstream << " <DATA>" << endl ;
285  *outstream << " <PIXFEC_NAME>" << i->getFECNumber() << "</PIXFEC_NAME>" << endl ;
286  *outstream << " <CRATE_NUMBER>" << i->getCrate() << "</CRATE_NUMBER>" << endl ;
287  *outstream << " <VME_ADDR>0x" << hex << i->getVMEBaseAddress() << dec << "</VME_ADDR>" << endl ;
288  *outstream << " </DATA>" << endl ;
289  }
290 }
291 
292 //=============================================================================================
293 void PixelFECConfig::writeXMLTrailer(std::ofstream *outstream,
294  std::ofstream *out1stream,
295  std::ofstream *out2stream) const
296 {
297  std::string mthn = "[PixelFECConfig::writeXMLTrailer()]\t\t\t " ;
298 
299  *outstream << "" << endl ;
300  *outstream << " </DATA_SET>" << endl ;
301  *outstream << "</ROOT> " << endl ;
302 
303  outstream->close() ;
304 }
305 
int i
Definition: DBlmapReader.cc:9
virtual void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) const
This file contains the base class for &quot;pixel configuration data&quot; management.
unsigned int getFECNumber(unsigned int i) const
assert(m_qm.get())
unsigned int getVMEBaseAddress(unsigned int i) const
unsigned int getCrate(unsigned int i) const
This class specifies which FEC boards are used and how they are addressed.
static std::string getmSecTime(void)
unsigned int crateFromFECNumber(unsigned int fecnumber) const
This class implements..
void writeASCII(std::string dir="") const
std::vector< PixelFECParameters > fecconfig_
tuple path
else: Piece not in the list, fine.
static std::string getTime(void)
std::string getComment() const
This class provides utility methods to manipulate ASCII formatted timestamps.
PixelFECConfig(std::string filename)
unsigned int VMEBaseAddressFromFECNumber(unsigned int fecnumber) const
void writeXML(pos::PixelConfigKey key, int version, std::string path) const
std::string getAuthor() 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 implements..
tuple out
Definition: dbtoconf.py:99
unsigned int getNFECBoards() const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121
dbl *** dir
Definition: mlp_gen.cc:35
void setFECParameters(unsigned int fecnumber, unsigned int crate, unsigned int vmebaseaddress)