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