CMS 3D CMS Logo

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 <cassert>
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  std::string mthn = "[PixelFEDConfig::PixelFEDConfig()]\t\t\t ";
20 
21  std::vector<std::string> ins = tableMat[0];
22  std::map<std::string, int> colM;
23  std::vector<std::string> colNames;
24  /*
25  EXTENSION_TABLE_NAME: FED_CRATE_CONFIG (VIEW: CONF_KEY_FED_CRATE_CONFIGV)
26 
27  CONFIG_KEY NOT NULL VARCHAR2(80)
28  KEY_TYPE NOT NULL VARCHAR2(80)
29  KEY_ALIAS NOT NULL VARCHAR2(80)
30  VERSION VARCHAR2(40)
31  KIND_OF_COND NOT NULL VARCHAR2(40)
32  PIXEL_FED NOT NULL NUMBER(38)
33  CRATE_NUMBER NOT NULL NUMBER(38)
34  VME_ADDR NOT NULL VARCHAR2(200)
35 */
36 
37  colNames.push_back("CONFIG_KEY");
38  colNames.push_back("KEY_TYPE");
39  colNames.push_back("KEY_ALIAS");
40  colNames.push_back("VERSION");
41  colNames.push_back("KIND_OF_COND");
42  colNames.push_back("PIXEL_FED");
43  colNames.push_back("CRATE_NUMBER");
44  colNames.push_back("VME_ADDR");
45  /*
46  colNames.push_back("PIXEL_FED" ); //0
47  colNames.push_back("CRATE_NUMBER" ); //1
48  colNames.push_back("VME_ADDRS_HEX"); //2
49 */
50  for (unsigned int c = 0; c < tableMat[0].size(); c++) {
51  for (unsigned int n = 0; n < colNames.size(); n++) {
52  if (tableMat[0][c] == colNames[n]) {
53  colM[colNames[n]] = c;
54  break;
55  }
56  }
57  } //end for
58  /*
59  for(unsigned int n=0; n<colNames.size(); n++)
60  {
61  if(colM.find(colNames[n]) == colM.end())
62  {
63  std::cerr << __LINE__ << "]\t" << mthn << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
64  assert(0);
65  }
66  }
67  */
68 
69  std::string fedname = "";
70  unsigned int fednum = 0;
71  fedconfig_.clear();
72  bool flag = false;
73  for (unsigned int r = 1; r < tableMat.size(); r++) { //Goes to every row of the Matrix
74 
75  fedname = tableMat
76  [r]
77  [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
78  //becuase the PixelFecConfig class ask for the fec number not the name.
79  // 01234567
80  // PxlFED_XX
81  // fedname.erase(0,7);
82  fednum = (unsigned int)atoi(fedname.c_str());
83 
84  if (fedconfig_.empty()) {
86  unsigned int vme_base_address = 0;
87  vme_base_address = strtoul(tableMat[r][colM["VME_ADDR"]].c_str(), nullptr, 16);
88  // string hexVMEAddr = tableMat[r][colM["VME_ADDRS_HEX"]] ;
89  // sscanf(hexVMEAddr.c_str(), "%x", &vme_base_address) ;
90  tmp.setFEDParameters(fednum, (unsigned int)atoi(tableMat[r][colM["CRATE_NUMBER"]].c_str()), vme_base_address);
91  fedconfig_.push_back(tmp);
92  } else {
93  for (unsigned int y = 0; y < fedconfig_.size(); y++) {
94  if (fedconfig_[y].getFEDNumber() ==
95  fednum) // This is to check if there are Pixel Feds already in the vector because
96  { // in the view of the database that I'm reading there are many repeated entries (AS FAR AS THESE PARAMS ARE CONCERNED).
97  flag = true; // This ensure that there are no objects in the fedconfig vector with repeated values.
98  break;
99  } else
100  flag = false;
101  }
102 
103  if (flag == false) {
105  tmp.setFEDParameters(fednum,
106  (unsigned int)atoi(tableMat[r][colM["CRATE_NUMBER"]].c_str()),
107  (unsigned int)strtoul(tableMat[r][colM["VME_ADDR"]].c_str(), nullptr, 16));
108  fedconfig_.push_back(tmp);
109  }
110  } //end else
111  } //end for r
112  /*
113  std::cout << __LINE__ << "]\t" << mthn << std::endl;
114 
115  for( unsigned int x = 0 ; x < fedconfig_.size() ; x++)
116  {
117  std::cout<< __LINE__ << "]\t" << mthn << fedconfig_[x] << std::endl;
118  }
119 
120  std::cout<< __LINE__ << "]\t" << mthn << fedconfig_.size() << std::endl;
121 */
122 } //end Constructor
123 
124 //*****************************************************************************************************
125 
127  std::string mthn = "[PixelFEDConfig::PixelFEDConfig()]\t\t\t ";
128  std::ifstream in(filename.c_str());
129 
130  if (!in.good()) {
131  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename.c_str() << std::endl;
132  throw std::runtime_error("Failed to open file " + filename);
133  } else {
134  std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename.c_str() << std::endl;
135  }
136 
138 
139  in >> dummy;
140  in >> dummy;
141  in >> dummy;
142  in >> dummy;
143  in >> dummy;
144  in >> dummy;
145 
146  do {
147  unsigned int fednumber;
148  unsigned int crate;
149  unsigned int vme_base_address;
150 
151  in >> fednumber >> crate >> std::hex >> vme_base_address >> std::dec;
152 
153  if (!in.eof()) {
154  // std::cout << __LINE__ << "]\t" << mthn << std::dec << fednumber <<" "<< crate << " 0x"
155  // << std::hex << vme_base_address<<std::dec<<std::endl;
157 
158  tmp.setFEDParameters(fednumber, crate, vme_base_address);
159 
160  fedconfig_.push_back(tmp);
161  }
162 
163  } while (!in.eof());
164  in.close();
165 }
166 
167 //std::ostream& operator<<(std::ostream& s, const PixelFEDConfig& table){
168 
169 //for (unsigned int i=0;i<table.translationtable_.size();i++){
170 // s << table.translationtable_[i]<<std::endl;
171 // }
172 // return s;
173 
174 //}
175 
177 
179  std::string mthn = "[PixelFEDConfig::writeASCII()]\t\t\t\t ";
180  if (!dir.empty())
181  dir += "/";
182  string filename = dir + "fedconfig.dat";
183 
184  ofstream out(filename.c_str());
185  if (!out.good()) {
186  cout << __LINE__ << "]\t" << mthn << "Could not open file: " << filename << endl;
187  assert(0);
188  }
189 
190  out << " #FED number crate vme base address" << endl;
191  for (unsigned int i = 0; i < fedconfig_.size(); i++) {
192  out << fedconfig_[i].getFEDNumber() << " " << fedconfig_[i].getCrate() << " "
193  << "0x" << hex << fedconfig_[i].getVMEBaseAddress() << dec << endl;
194  }
195  out.close();
196 }
197 
198 unsigned int PixelFEDConfig::getNFEDBoards() const { return fedconfig_.size(); }
199 
200 unsigned int PixelFEDConfig::getFEDNumber(unsigned int i) const {
201  assert(i < fedconfig_.size());
202  return fedconfig_[i].getFEDNumber();
203 }
204 
205 unsigned int PixelFEDConfig::getCrate(unsigned int i) const {
206  assert(i < fedconfig_.size());
207  return fedconfig_[i].getCrate();
208 }
209 
210 unsigned int PixelFEDConfig::getVMEBaseAddress(unsigned int i) const {
211  assert(i < fedconfig_.size());
212  return fedconfig_[i].getVMEBaseAddress();
213 }
214 
215 unsigned int PixelFEDConfig::crateFromFEDNumber(unsigned int fednumber) const {
216  std::string mthn = "[PixelFEDConfig::crateFromFEDNumber()]\t\t\t ";
217  for (unsigned int i = 0; i < fedconfig_.size(); i++) {
218  if (fedconfig_[i].getFEDNumber() == fednumber)
219  return fedconfig_[i].getCrate();
220  }
221 
222  std::cout << __LINE__ << "]\t" << mthn << "Could not find FED number: " << fednumber << std::endl;
223 
224  assert(0);
225 
226  return 0;
227 }
228 
229 unsigned int PixelFEDConfig::VMEBaseAddressFromFEDNumber(unsigned int fednumber) const {
230  std::string mthn = "[PixelFEDConfig::VMEBaseAddressFromFEDNumber()]\t\t ";
231  for (unsigned int i = 0; i < fedconfig_.size(); i++) {
232  if (fedconfig_[i].getFEDNumber() == fednumber)
233  return fedconfig_[i].getVMEBaseAddress();
234  }
235 
236  std::cout << __LINE__ << "]\t" << mthn << "Could not find FED number: " << fednumber << std::endl;
237 
238  assert(0);
239 
240  return 0;
241 }
242 
244  unsigned int vmebaseaddress) const {
245  std::string mthn = "[PixelFEDConfig::FEDNumberFromCrateAndVMEBaseAddress()]\t ";
246  for (unsigned int i = 0; i < fedconfig_.size(); i++) {
247  if (fedconfig_[i].getCrate() == crate && fedconfig_[i].getVMEBaseAddress() == vmebaseaddress)
248  return fedconfig_[i].getFEDNumber();
249  }
250 
251  std::cout << __LINE__ << "]\t" << mthn << "Could not find FED crate and address: " << crate << ", " << vmebaseaddress
252  << std::endl;
253 
254  assert(0);
255 
256  return 0;
257 }
258 
259 //=============================================================================================
261  int version,
263  std::ofstream *outstream,
264  std::ofstream *out1stream,
265  std::ofstream *out2stream) const {
266  std::string mthn = "[PixelFEDConfig::::writeXMLHeader()]\t\t\t ";
267  std::stringstream fullPath;
268  fullPath << path << "/Pixel_FedCrateConfig_" << PixelTimeFormatter::getmSecTime() << ".xml";
269  cout << __LINE__ << "]\t" << mthn << "Writing to: " << fullPath.str() << endl;
270 
271  outstream->open(fullPath.str().c_str());
272  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << endl;
273  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << endl;
274  *outstream << " <HEADER>" << endl;
275  *outstream << " <TYPE>" << endl;
276  *outstream << " <EXTENSION_TABLE_NAME>FED_CRATE_CONFIG</EXTENSION_TABLE_NAME>" << endl;
277  *outstream << " <NAME>Pixel FED Crate Configuration</NAME>" << endl;
278  *outstream << " </TYPE>" << endl;
279  *outstream << " <RUN>" << endl;
280  *outstream << " <RUN_NAME>Pixel FED Crate Configuration</RUN_NAME>" << endl;
281  *outstream << " <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << endl;
282  *outstream << " <LOCATION>CERN P5</LOCATION>" << endl;
283  *outstream << " </RUN>" << endl;
284  *outstream << " </HEADER>" << endl;
285  *outstream << " " << endl;
286  *outstream << " <DATA_SET>" << endl;
287  *outstream << " <PART>" << endl;
288  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << endl;
289  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << endl;
290  *outstream << " </PART>" << endl;
291  *outstream << " <VERSION>" << version << "</VERSION>" << endl;
292  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << endl;
293  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << endl;
294  *outstream << " " << endl;
295 }
296 
297 //=============================================================================================
298 void PixelFEDConfig::writeXML(std::ofstream *outstream, std::ofstream *out1stream, std::ofstream *out2stream) const {
299  std::string mthn = "[PixelFEDConfig::writeXML()]\t\t\t ";
300 
301  for (unsigned int i = 0; i < fedconfig_.size(); i++) {
302  *outstream << " <DATA>" << endl;
303  *outstream << " <PIXEL_FED>" << fedconfig_[i].getFEDNumber() << "</PIXEL_FED>" << endl;
304  *outstream << " <CRATE_NUMBER>" << fedconfig_[i].getCrate() << "</CRATE_NUMBER>" << endl;
305  *outstream << " <VME_ADDR>"
306  << "0x" << hex << fedconfig_[i].getVMEBaseAddress() << dec << "</VME_ADDR>" << endl;
307  *outstream << " </DATA>" << endl;
308  *outstream << "" << endl;
309  }
310 }
311 
312 //=============================================================================================
313 void PixelFEDConfig::writeXMLTrailer(std::ofstream *outstream,
314  std::ofstream *out1stream,
315  std::ofstream *out2stream) const {
316  std::string mthn = "[PixelFEDConfig::writeXMLTrailer()]\t\t\t ";
317 
318  *outstream << " </DATA_SET>" << endl;
319  *outstream << "</ROOT> " << endl;
320 
321  outstream->close();
322 }
unsigned int VMEBaseAddressFromFEDNumber(unsigned int fednumber) const
unsigned int FEDNumberFromCrateAndVMEBaseAddress(unsigned int crate, unsigned int vmebaseaddress) const
This file contains the base class for "pixel configuration data" management.
std::string getComment() const
void writeXML(pos::PixelConfigKey key, int version, std::string path) const override
assert(be >=bs)
unsigned int getCrate(unsigned int i) const
ins
Definition: cuy.py:313
unsigned int getNFEDBoards() const
static std::string getmSecTime(void)
void writeASCII(std::string dir) const override
unsigned int getVMEBaseAddress(unsigned int i) const
static std::string getTime(void)
This class implements..
This class provides utility methods to manipulate ASCII formatted timestamps.
key
prepare the HTCondor submission files and eventually submit them
~PixelFEDConfig() override
void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
This class implements..
unsigned int getFEDNumber(unsigned int i) const
This class implements..
PixelFEDConfig(std::string filename)
void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
std::string getAuthor() const
std::vector< PixelFEDParameters > fedconfig_
unsigned int crateFromFEDNumber(unsigned int fednumber) const
tmp
align.sh
Definition: createJobs.py:716