CMS 3D CMS Logo

PixelTBMSettings.cc
Go to the documentation of this file.
1 //
2 // This class provide a base class for the
3 // pixel ROC DAC data for the pixel FEC configuration
4 //
5 //
6 //
7 //
8 
11 #include <fstream>
12 #include <sstream>
13 #include <iostream>
14 #include <ios>
15 #include <cassert>
16 #include <stdexcept>
17 
18 using namespace pos;
19 
20 PixelTBMSettings::PixelTBMSettings(std::vector<std::vector<std::string> > &tableMat) : PixelConfigBase("", "", "") {
21  std::string mthn = "]\t[PixelTBMSettings::PixelTBMSettings()]\t\t\t ";
22  std::vector<std::string> ins = tableMat[0];
23  std::map<std::string, int> colM;
24  std::vector<std::string> colNames;
25 
49  colNames.push_back("CONFIG_KEY");
50  colNames.push_back("KEY_TYPE");
51  colNames.push_back("KEY_ALIAS");
52  colNames.push_back("VERSION");
53  colNames.push_back("KIND_OF_COND");
54  colNames.push_back("TBM_NAME");
55  colNames.push_back("MODULE_NAME");
56  colNames.push_back("HUB_ADDRS");
57  colNames.push_back("TBM_MODE");
58  colNames.push_back("ANLG_INBIAS_ADDR");
59  colNames.push_back("ANLG_INBIAS_VAL");
60  colNames.push_back("ANLG_OUTBIAS_ADDR");
61  colNames.push_back("ANLG_OUTBIAS_VAL");
62  colNames.push_back("ANLG_OUTGAIN_ADDR");
63  colNames.push_back("ANLG_OUTGAIN_VAL");
64 
65  for (unsigned int c = 0; c < ins.size(); c++) {
66  for (unsigned int n = 0; n < colNames.size(); n++) {
67  if (tableMat[0][c] == colNames[n]) {
68  colM[colNames[n]] = c;
69  break;
70  }
71  }
72  } //end for
73  for (unsigned int n = 0; n < colNames.size(); n++) {
74  if (colM.find(colNames[n]) == colM.end()) {
75  std::cerr << __LINE__ << mthn << "Couldn't find in the database the column with name " << colNames[n]
76  << std::endl;
77  assert(0);
78  }
79  }
80 
81  if (tableMat.size() > 1) {
82  //std::cout << __LINE__ << mthn << "Module from DB: " << tableMat[1][colM["MODULE_NAME"]]<< std::endl ;
83  PixelROCName tmp(tableMat[1][colM["MODULE_NAME"]]);
84  rocid_ = tmp;
85  //std::cout << __LINE__ << mthn << "Built ROCNAME: " << rocid_.rocname()<< std::endl ;
86 
87  analogInputBias_ = atoi(tableMat[1][colM["ANLG_INBIAS_VAL"]].c_str());
88  analogOutputBias_ = atoi(tableMat[1][colM["ANLG_OUTBIAS_VAL"]].c_str());
89  analogOutputGain_ = atoi(tableMat[1][colM["ANLG_OUTGAIN_VAL"]].c_str());
90 
91  if (tableMat[1][colM["TBM_MODE"]] == "SingleMode") {
92  singlemode_ = true;
93  } else {
94  singlemode_ = false;
95  }
96  }
97 } //end contructor
98 
99 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
100 
102  std::string mthn = "]\t[PixelTBMSettings::PixelTBMSettings()]\t\t\t ";
103  if (filename[filename.size() - 1] == 't') {
104  std::ifstream in(filename.c_str());
105 
106  if (!in.good()) {
107  std::cout << __LINE__ << mthn << "Could not open:" << filename << std::endl;
108  throw std::runtime_error("Failed to open file " + filename);
109  } else {
110  // std::cout << "Opened:"<<filename<<std::endl;
111  }
112 
114 
116 
117  rocid_ = tmp;
118 
119  unsigned int tmpint;
120 
121  in >> tag;
122  //std::cout << "Tag="<<tag<<std::endl;
123  assert(tag == "AnalogInputBias:");
124  in >> tmpint;
125  analogInputBias_ = tmpint;
126 
127  in >> tag;
128  //std::cout << "Tag="<<tag<<std::endl;
129  assert(tag == "AnalogOutputBias:");
130  in >> tmpint;
131  analogOutputBias_ = tmpint;
132 
133  in >> tag;
134  //std::cout << "Tag="<<tag<<std::endl;
135  assert(tag == "AnalogOutputGain:");
136  in >> tmpint;
137  analogOutputGain_ = tmpint;
138 
139  in >> tag;
140  //std::cout << "Tag="<<tag<<std::endl;
141  assert(tag == "Mode:");
142  in >> tag;
143  assert(tag == "SingleMode" || tag == "DualMode");
144 
145  singlemode_ = true;
146 
147  if (tag == "DualMode")
148  singlemode_ = false;
149 
150  in.close();
151 
152  } else {
153  std::ifstream in(filename.c_str(), std::ios::binary);
154 
155  if (!in.good()) {
156  std::cout << __LINE__ << mthn << "Could not open:" << filename << std::endl;
157  assert(0);
158  } else {
159  std::cout << __LINE__ << mthn << "Opened:" << filename << std::endl;
160  }
161 
162  char nchar;
163  std::string s1;
164 
165  in.read(&nchar, 1);
166 
167  s1.clear();
168 
169  //wrote these lines of code without ref. needs to be fixed
170  for (int i = 0; i < nchar; i++) {
171  char c;
172  in >> c;
173  s1.push_back(c);
174  }
175 
176  PixelROCName tmp(s1);
177 
178  rocid_ = tmp;
179 
180  in >> analogInputBias_;
183  in >> singlemode_;
184 
185  in.close();
186  }
187 }
188 
190  if (what == "analogInputBias") {
191  analogInputBias_ = (unsigned char)value;
192  } else if (what == "analogOutputBias") {
193  analogOutputBias_ = (unsigned char)value;
194  } else if (what == "analogOutputGain") {
195  analogOutputGain_ = (unsigned char)value;
196  } else if (what == "Mode") {
198  } else {
199  std::cout << __LINE__ << "]\t[PixelTBMSettings::setTBMGenericValue()]\t\tFATAL: invalid key/value pair: " << what
200  << "/" << value << std::endl;
201  assert(0);
202  }
203 }
204 
206  std::ofstream out(filename.c_str(), std::ios::binary);
207 
208  out << (char)rocid_.rocname().size();
209  out.write(rocid_.rocname().c_str(), rocid_.rocname().size());
210 
214  out << singlemode_;
215 }
216 
219 
220  if (!dir.empty())
221  dir += "/";
222  std::string filename = dir + "TBM_module_" + module.modulename() + ".dat";
223 
224  std::ofstream out(filename.c_str());
225 
226  out << rocid_.rocname() << std::endl;
227 
228  out << "AnalogInputBias: " << (int)analogInputBias_ << std::endl;
229  out << "AnalogOutputBias: " << (int)analogOutputBias_ << std::endl;
230  out << "AnalogOutputGain: " << (int)analogOutputGain_ << std::endl;
231  out << "Mode: ";
232  if (singlemode_) {
233  out << "SingleMode" << std::endl;
234  } else {
235  out << "DualMode" << std::endl;
236  }
237 }
238 
240  PixelNameTranslation *trans,
241  bool physics,
242  bool doResets) const {
243  PixelHdwAddress theROC = *(trans->getHdwAddress(rocid_));
244 
245  int mfec = theROC.mfec();
246  int mfecchannel = theROC.mfecchannel();
247  int tbmchannel = 14;
248  int tbmchannelB = 15;
249  int hubaddress = theROC.hubaddress();
250 
251  if (doResets) {
252  pixelFEC->injectrsttbm(mfec, 1);
253  pixelFEC->injectrstroc(mfec, 1);
254  }
255  pixelFEC->enablecallatency(mfec, 0);
256  pixelFEC->disableexttrigger(mfec, 0);
257  pixelFEC->injecttrigger(mfec, 0);
258  pixelFEC->callatencycount(mfec, 79);
259 
260  //pixelFEC->synccontrolregister(mfec);
261 
262  //Reset TBM and reset ROC
263  if (doResets)
264  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 2, 0x14, 0);
265  //setting speed to 40MHz
266  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 0, 1, 0);
267  // setting the mode, we should always stay in the CAL mode
268  // since the EventNumberClear Mode does not work correctly
269  //if (physics) { // comment out, stau always in the CAL mode, d.k. 27/09/09
270  //pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 1, 0x80, 0);
271  //} else {
272  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 1, 0xc0, 0);
273  //}
274  //Enable token and analog output
275  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 4, 0x0, 0);
276 
277  //Analog input bias
278  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 5, analogInputBias_, 0);
279  //Analog output bias
280  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 6, analogOutputBias_, 0);
281  //Analog output gain
282  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 7, analogOutputGain_, 0);
283 
284  //setting speed to 40MHz
285  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannelB, hubaddress, 4, 0, 1, 0);
286  //pre-calibration, stay always in this mode
287  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannelB, hubaddress, 4, 1, 0xc0, 0);
288  //Reset TBM and reset ROC
289  if (doResets)
290  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannelB, hubaddress, 4, 2, 0x14, 0);
291  //Enable token and analog output
292  if (singlemode_) {
293  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannelB, hubaddress, 4, 4, 0x3, 0);
294  } else {
295  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannelB, hubaddress, 4, 4, 0x0, 0);
296  }
297 }
298 
299 std::ostream &pos::operator<<(std::ostream &s, const PixelTBMSettings &tbm) {
300  s << "Module :" << tbm.getROCName().rocname() << std::endl;
301  s << "analogInputBias :" << tbm.getAnalogInputBias() << std::endl;
302  s << "analogOutputBias:" << tbm.getAnalogOutputBias() << std::endl;
303  s << "analogOutputGain:" << tbm.getAnalogOutputGain() << std::endl;
304  if (tbm.getMode()) {
305  s << "mode :Singlemode" << std::endl;
306  } else {
307  s << "mode :Dualmode" << std::endl;
308  }
309 
310  return s;
311 }
312 //=============================================================================================
314  int version,
316  std::ofstream *outstream,
317  std::ofstream *out1stream,
318  std::ofstream *out2stream) const {
319  std::string mthn = "]\t[PixelTBMSettings::writeXMLHeader()]\t\t\t ";
320  std::stringstream fullPath;
321  fullPath << path << "/Pixel_TbmParameters_" << PixelTimeFormatter::getmSecTime() << ".xml";
322  std::cout << __LINE__ << mthn << "Writing to: " << fullPath.str() << std::endl;
323 
324  outstream->open(fullPath.str().c_str());
325 
326  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl;
327  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
328  *outstream << " <HEADER>" << std::endl;
329  *outstream << " <TYPE>" << std::endl;
330  *outstream << " <EXTENSION_TABLE_NAME>PIXEL_TBM_PARAMETERS</EXTENSION_TABLE_NAME>" << std::endl;
331  *outstream << " <NAME>Pixel TBM Parameters</NAME>" << std::endl;
332  *outstream << " </TYPE>" << std::endl;
333  *outstream << " <RUN>" << std::endl;
334  *outstream << " <RUN_TYPE>Pixel TBM Parameters</RUN_TYPE>" << std::endl;
335  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl;
336  *outstream << " <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>"
337  << std::endl;
338  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl;
339  *outstream << " </RUN>" << std::endl;
340  *outstream << " </HEADER>" << std::endl;
341  *outstream << "" << std::endl;
342  *outstream << " <DATA_SET>" << std::endl;
343  *outstream << " <PART>" << std::endl;
344  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl;
345  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl;
346  *outstream << " </PART>" << std::endl;
347  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl;
348  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl;
349  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl;
350  *outstream << " " << std::endl;
351 }
352 
353 //=============================================================================================
354 void PixelTBMSettings::writeXML(std::ofstream *outstream, std::ofstream *out1stream, std::ofstream *out2stream) const {
355  std::string mthn = "]\t[PixelTBMSettings::writeXML()]\t\t\t ";
356 
358 
359  *outstream << " <DATA>" << std::endl;
360  *outstream << " <MODULE_NAME>" << rocid_.rocname() << "</MODULE_NAME>" << std::endl;
361  *outstream << " <ANLG_INBIAS_VAL>" << (int)analogInputBias_ << "</ANLG_INBIAS_VAL>" << std::endl;
362  *outstream << " <ANLG_OUTBIAS_VAL>" << (int)analogOutputBias_ << "</ANLG_OUTBIAS_VAL>" << std::endl;
363  *outstream << " <ANLG_OUTGAIN_VAL>" << (int)analogOutputGain_ << "</ANLG_OUTGAIN_VAL>" << std::endl;
364  if (singlemode_) {
365  *outstream << " <TBM_MODE>SingleMode</TBM_MODE>" << std::endl;
366  } else {
367  *outstream << " <TBM_MODE>DualMode</TBM_MODE>" << std::endl;
368  }
369  *outstream << " </DATA>" << std::endl;
370 }
371 
372 //=============================================================================================
373 void PixelTBMSettings::writeXMLTrailer(std::ofstream *outstream,
374  std::ofstream *out1stream,
375  std::ofstream *out2stream) const {
376  std::string mthn = "]\t[PixelTBMSettings::writeXMLTrailer()]\t\t\t ";
377 
378  *outstream << " " << std::endl;
379  *outstream << " </DATA_SET>" << std::endl;
380  *outstream << "</ROOT> " << std::endl;
381 
382  outstream->close();
383 }
virtual int tbmcmd(int mfec, int fecchannel, int tbmchannel, int hubaddress, int portaddress, int offset, int databyte, int direction)=0
unsigned char getAnalogOutputGain() const
void generateConfiguration(PixelFECConfigInterface *pixelFEC, PixelNameTranslation *trans, bool physics=false, bool doResets=true) const
This file contains the base class for "pixel configuration data" management.
unsigned char analogOutputBias_
virtual int enablecallatency(const int mfec, const int bitstate)=0
bool getMode(void) const
unsigned int mfec() const
std::string getComment() const
unsigned char analogOutputGain_
void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
unsigned char getAnalogOutputBias() const
unsigned char getAnalogInputBias() const
std::ostream & operator<<(std::ostream &s, const PixelCalibConfiguration &calib)
This class implements..
assert(be >=bs)
virtual int injecttrigger(const int mfec, const int bitstate)=0
void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
ins
Definition: cuy.py:313
static std::string getmSecTime(void)
void writeBinary(std::string filename) const
void writeASCII(std::string dir) const override
void setTBMGenericValue(std::string, int)
static std::string getTime(void)
virtual int disableexttrigger(const int mfec, const int bitstate)=0
std::string rocname() const
This class provides utility methods to manipulate ASCII formatted timestamps.
Store mfec, mfecchannel etc.
const PixelHdwAddress * getHdwAddress(const PixelROCName &aROC) const
virtual int injectrstroc(const int mfec, const int bitstate)=0
void writeXML(pos::PixelConfigKey key, int version, std::string path) const override
unsigned int mfecchannel() const
Definition: value.py:1
PixelROCName const & getROCName() const
This class implements..
unsigned char analogInputBias_
This is the documentation about PixelNameTranslation...
This class implements..
This class implements..
Definition: PixelROCName.h:23
std::string getAuthor() const
virtual int callatencycount(const int mfec, const int latency)=0
tmp
align.sh
Definition: createJobs.py:716
unsigned int hubaddress() const
virtual int injectrsttbm(const int mfec, const int bitstate)=0
This is the documentation about PixelTBMSettings...