CMS 3D CMS Logo

PixelTKFECConfig.cc
Go to the documentation of this file.
1 //
2 // This class stores the information about a TKFEC.
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 
19 PixelTKFECConfig::PixelTKFECConfig(std::vector<std::vector<std::string> >& tableMat ) : PixelConfigBase(" "," "," ")
20 {
21  std::map<std::string , int > colM;
22  std::vector<std::string > colNames;
42  colNames.push_back("CONFIG_KEY" );
43  colNames.push_back("KEY_TYPE" );
44  colNames.push_back("KEY_ALIAS" );
45  colNames.push_back("VERSION" );
46  colNames.push_back("KIND_OF_COND");
47  colNames.push_back("TRKFEC_NAME" );
48  colNames.push_back("CRATE_LABEL" );
49  colNames.push_back("CRATE_NUMBER");
50  colNames.push_back("TYPE" );
51  colNames.push_back("SLOT_NUMBER" );
52  colNames.push_back("VME_ADDR" );
53  colNames.push_back("I2CSPEED" );
54 
55  for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
56  {
57  for(unsigned int n=0; n<colNames.size(); n++)
58  {
59  if(tableMat[0][c] == colNames[n])
60  {
61  colM[colNames[n]] = c;
62  break;
63  }
64  }
65  }//end for
66  /*
67  for(unsigned int n=0; n<colNames.size(); n++)
68  {
69  if(colM.find(colNames[n]) == colM.end())
70  {
71  std::cerr << "[PixelTKFECConfig::PixelTKFECConfig()]\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
72  assert(0);
73  }
74  }
75  */
76 
77  for(unsigned int r = 1 ; r < tableMat.size() ; r++) //Goes to every row of the Matrix
78  {
79  std::string TKFECID = tableMat[r][colM["TRKFEC_NAME"]] ;
80  unsigned int crate = atoi(tableMat[r][colM["CRATE_NUMBER"]].c_str()) ;
81  std::string type = "VME" ;
82  unsigned int address = strtoul(tableMat[r][colM["VME_ADDR"]].c_str() , nullptr, 16);
84  tmp.setTKFECParameters(TKFECID , crate , type, address);
85  TKFECconfig_.push_back(tmp);
86  // cout << "[PixelTKFECConfig::PixelTKFECConfig()]\tID: " << TKFECID << " crate: " << crate << " address: " << address << endl;
87  }
88 }// end contructor
89 
90 //****************************************************************************************
91 
92 
94  PixelConfigBase(" "," "," "){
95 
96  std::string mthn ="]\t[PixelTKFECConfig::PixelTKFECConfig()]\t\t\t " ;
97  std::ifstream in(filename.c_str());
98 
99  if (!in.good()){
100  std::cout << __LINE__ << mthn << "Could not open: " << filename << std::endl;
101  throw std::runtime_error("Failed to open file "+filename);
102  }
103  else {
104  std::cout << __LINE__ << mthn << "Opened: " << filename << std::endl;
105  }
106 
108 
109  getline(in, dummy); // skip the column headings
110 
111  do {
112 
113  std::string TKFECID;
114  unsigned int crate;
116  unsigned int address;
117 
118  in >> TKFECID >> std::dec >> crate >> type;
119  if (type=="VME" || type=="PCI")
120  {
121  in >> std::hex>> address >>std::dec ;
122  }
123  else // type not specified, default to "VME"
124  {
125  address = strtoul(type.c_str(), nullptr, 16); // convert string to integer using base 16
126  type = "VME";
127  }
128 
129  if (!in.eof() ){
130  //std::cout << TKFECID <<" "<< crate << " "
131  // << std::hex << vme_base_address<<std::dec<<std::endl;
132 
134 
135  tmp.setTKFECParameters(TKFECID , crate , type, address);
136 
137  TKFECconfig_.push_back(tmp);
138  }
139 
140  }
141  while (!in.eof());
142  in.close();
143 
144 }
145 
147 
149 
150  if (dir!="") dir+="/";
151  string filename=dir+"tkfecconfig.dat";
152 
153  ofstream out(filename.c_str());
154  if(!out.good()){
155  cout << "Could not open file:"<<filename<<endl;
156  assert(0);
157  }
158 
159  out <<"#TKFEC ID crate VME/PCI slot/address" <<endl;
160  for(unsigned int i=0;i<TKFECconfig_.size();i++){
161  out << TKFECconfig_[i].getTKFECID()<<" "
162  << TKFECconfig_[i].getCrate()<<" ";
163  if (TKFECconfig_[i].getType()=="PCI") {
164  out << "PCI ";
165  } else {
166  out << " ";
167  }
168  out << "0x"<<hex<<TKFECconfig_[i].getAddress()<<dec<<endl;
169  }
170  out.close();
171 }
172 
173 
174 //std::ostream& operator<<(std::ostream& s, const PixelTKFECConfig& table){
175 
176  //for (unsigned int i=0;i<table.translationtable_.size();i++){
177  // s << table.translationtable_[i]<<std::endl;
178  // }
179 // return s;
180 
181 //}
182 
183 
185 
186  return TKFECconfig_.size();
187 
188 }
189 
191 
192  assert(i<TKFECconfig_.size());
193  return TKFECconfig_[i].getTKFECID();
194 
195 }
196 
197 
198 unsigned int PixelTKFECConfig::getCrate(unsigned int i) const{
199 
200  assert(i<TKFECconfig_.size());
201  return TKFECconfig_[i].getCrate();
202 
203 }
204 
206 
207  assert(i<TKFECconfig_.size());
208  return TKFECconfig_[i].getType();
209 
210 }
211 
212 unsigned int PixelTKFECConfig::getAddress(unsigned int i) const{
213 
214  assert(i<TKFECconfig_.size());
215  return TKFECconfig_[i].getAddress();
216 
217 }
218 
219 
221 
222  for(unsigned int i=0;i<TKFECconfig_.size();i++){
223  if (TKFECconfig_[i].getTKFECID()==TKFECID) return TKFECconfig_[i].getCrate();
224  }
225 
226  std::cout << "Could not find TKFEC ID:"<<TKFECID<<std::endl;
227 
228  assert(0);
229 
230  return 0;
231 
232 }
233 
235 
236  for(unsigned int i=0;i<TKFECconfig_.size();i++){
237  if (TKFECconfig_[i].getTKFECID()==TKFECID) return TKFECconfig_[i].getType();
238  }
239 
240  std::cout << "Could not find TKFEC ID:"<<TKFECID<<std::endl;
241 
242  assert(0);
243 
244  return nullptr;
245 
246 }
247 
249 
250  for(unsigned int i=0;i<TKFECconfig_.size();i++){
251  if (TKFECconfig_[i].getTKFECID()==TKFECID) return TKFECconfig_[i].getAddress();
252  }
253 
254  std::cout << "Could not find TKFEC ID:"<<TKFECID<<std::endl;
255 
256  assert(0);
257 
258  return 0;
259 
260 }
261 
262 //=============================================================================================
264  int version,
265  std::string path,
266  std::ofstream *outstream,
267  std::ofstream *out1stream,
268  std::ofstream *out2stream) const
269 {
270  std::string mthn = "[PixelTKFECConfig::writeXMLHeader()]\t\t\t " ;
271  std::stringstream maskFullPath ;
272 
273  maskFullPath << path << "/Pixel_TrackerFecParameters_" << PixelTimeFormatter::getmSecTime() << ".xml";
274  std::cout << mthn << "Writing to: " << maskFullPath.str() << std::endl ;
275 
276  outstream->open(maskFullPath.str().c_str()) ;
277 
278  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl ;
279  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl ;
280  *outstream << "" << std::endl ;
281  *outstream << " <HEADER>" << std::endl ;
282  *outstream << " <TYPE>" << std::endl ;
283  *outstream << " <EXTENSION_TABLE_NAME>TRACKER_FEC_PARAMETERS</EXTENSION_TABLE_NAME>" << std::endl ;
284  *outstream << " <NAME>Tracker FEC Parameters</NAME>" << std::endl ;
285  *outstream << " </TYPE>" << std::endl ;
286  *outstream << " <RUN>" << std::endl ;
287  *outstream << " <RUN_TYPE>Tracker FEC Parameters</RUN_TYPE>" << std::endl ;
288  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl ;
289  *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
290  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl ;
291  *outstream << " </RUN>" << std::endl ;
292  *outstream << " </HEADER>" << std::endl ;
293  *outstream << "" << std::endl ;
294  *outstream << " <DATA_SET>" << std::endl ;
295  *outstream << "" << std::endl ;
296  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl ;
297  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl ;
298  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl ;
299  *outstream << "" << std::endl ;
300  *outstream << " <PART>" << std::endl ;
301  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl ;
302  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl ;
303  *outstream << " </PART>" << std::endl ;
304 
305 }
306 
307 //=============================================================================================
308 void PixelTKFECConfig::writeXML( std::ofstream *outstream,
309  std::ofstream *out1stream,
310  std::ofstream *out2stream) const
311 {
312  std::string mthn = "[PixelTKFECConfig::writeXML()]\t\t\t " ;
313 
314  for(unsigned int i=0;i<TKFECconfig_.size();i++){
315  *outstream << " <DATA>" << std::endl ;
316  *outstream << " <TRKFEC_NAME>" << TKFECconfig_[i].getTKFECID() << "</TRKFEC_NAME>" << std::endl ;
317  *outstream << " <CRATE_NUMBER>" << TKFECconfig_[i].getCrate() << "</CRATE_NUMBER>"<< std::endl ;
318  *outstream << " <VME_ADDR>" << "0x" << hex << TKFECconfig_[i].getAddress() << dec << "</VME_ADDR>" << std::endl ;
319  *outstream << " </DATA>" << std::endl ;
320  }
321 }
322 
323 //=============================================================================================
324 void PixelTKFECConfig::writeXMLTrailer(std::ofstream *outstream,
325  std::ofstream *out1stream,
326  std::ofstream *out2stream ) const
327 {
328  std::string mthn = "[PixelTKFECConfig::writeXMLTrailer()]\t\t\t " ;
329 
330  *outstream << " </DATA_SET>" << std::endl ;
331  *outstream << "</ROOT>" << std::endl ;
332 
333  outstream->close() ;
334  std::cout << mthn << "Data written " << std::endl ;
335 
336 }
This class specifies which TKFEC boards are used and how they are addressed.
type
Definition: HCALResponse.h:21
void writeXML(pos::PixelConfigKey key, int version, std::string path) const override
This file contains the base class for "pixel configuration data" management.
unsigned int crateFromTKFECID(std::string TKFECID) const
unsigned int getCrate(unsigned int i) const
void setTKFECParameters(std::string TKFECID, unsigned int crate, std::string type, unsigned int address)
std::string typeFromTKFECID(std::string TKFECID) const
static std::string getmSecTime(void)
unsigned int getNTKFECBoards() const
PixelTKFECConfig(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
static std::string getTime(void)
void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
std::string getComment() const
std::string getTKFECID(unsigned int i) const
This class provides utility methods to manipulate ASCII formatted timestamps.
std::string getAuthor() const
unsigned int addressFromTKFECID(std::string TKFECID) const
This class implements..
This class implements..
std::vector< PixelTKFECParameters > TKFECconfig_
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::string getType(unsigned int i) const
void writeASCII(std::string dir) const override
dbl *** dir
Definition: mlp_gen.cc:35
unsigned int getAddress(unsigned int i) const