CMS 3D CMS Logo

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