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 }
pos::PixelFECConfigInterface::disableexttrigger
virtual int disableexttrigger(const int mfec, const int bitstate)=0
pos::PixelROCName::rocname
std::string rocname() const
Definition: PixelROCName.cc:235
EcalCondDBWriter_cfi.physics
physics
Definition: EcalCondDBWriter_cfi.py:51
pos::PixelTBMSettings::writeXMLTrailer
void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
Definition: PixelTBMSettings.cc:373
pos::PixelFECConfigInterface
This class implements..
Definition: PixelFECConfigInterface.h:23
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
PixelTimeFormatter.h
This class provides utility methods to manipulate ASCII formatted timestamps.
pos::PixelTBMSettings::getMode
bool getMode(void) const
Definition: PixelTBMSettings.h:67
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
pos::PixelTBMSettings::analogOutputBias_
unsigned char analogOutputBias_
Definition: PixelTBMSettings.h:81
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
pos::PixelModuleName
This class implements..
Definition: PixelModuleName.h:26
cms::cuda::assert
assert(be >=bs)
pos::PixelTBMSettings::generateConfiguration
void generateConfiguration(PixelFECConfigInterface *pixelFEC, PixelNameTranslation *trans, bool physics=false, bool doResets=true) const
Definition: PixelTBMSettings.cc:239
pos::PixelConfigBase
This file contains the base class for "pixel configuration data" management.
Definition: PixelConfigBase.h:32
pos::PixelTBMSettings::getAnalogOutputBias
unsigned char getAnalogOutputBias() const
Definition: PixelTBMSettings.h:60
pos::PixelTBMSettings::writeASCII
void writeASCII(std::string dir) const override
Definition: PixelTBMSettings.cc:217
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
pos::PixelHdwAddress::hubaddress
unsigned int hubaddress() const
Definition: PixelHdwAddress.h:40
pos::PixelTBMSettings
This is the documentation about PixelTBMSettings...
Definition: PixelTBMSettings.h:27
pos::PixelHdwAddress::mfecchannel
unsigned int mfecchannel() const
Definition: PixelHdwAddress.h:39
pos::PixelTBMSettings::writeBinary
void writeBinary(std::string filename) const
Definition: PixelTBMSettings.cc:205
pos::PixelTBMSettings::analogOutputGain_
unsigned char analogOutputGain_
Definition: PixelTBMSettings.h:82
pos::PixelNameTranslation::getHdwAddress
const PixelHdwAddress * getHdwAddress(const PixelROCName &aROC) const
Definition: PixelNameTranslation.cc:449
pos::PixelTimeFormatter::getTime
static std::string getTime(void)
Definition: PixelTimeFormatter.h:60
pos::PixelFECConfigInterface::injectrstroc
virtual int injectrstroc(const int mfec, const int bitstate)=0
pos::PixelTBMSettings::getROCName
const PixelROCName & getROCName() const
Definition: PixelTBMSettings.h:69
pos::PixelTBMSettings::getAnalogInputBias
unsigned char getAnalogInputBias() const
Definition: PixelTBMSettings.h:57
alignCSCRings.s
s
Definition: alignCSCRings.py:92
pos::PixelTBMSettings::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: PixelTBMSettings.cc:313
pos::PixelTBMSettings::setTBMGenericValue
void setTBMGenericValue(std::string, int)
Definition: PixelTBMSettings.cc:189
pos::PixelConfigBase::getAuthor
std::string getAuthor() const
Definition: PixelConfigBase.h:70
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
pos::PixelTimeFormatter::getmSecTime
static std::string getmSecTime(void)
Definition: PixelTimeFormatter.h:93
pos::PixelFECConfigInterface::tbmcmd
virtual int tbmcmd(int mfec, int fecchannel, int tbmchannel, int hubaddress, int portaddress, int offset, int databyte, int direction)=0
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
pos::PixelFECConfigInterface::injecttrigger
virtual int injecttrigger(const int mfec, const int bitstate)=0
pos::PixelFECConfigInterface::callatencycount
virtual int callatencycount(const int mfec, const int latency)=0
pos::PixelTBMSettings::writeXML
void writeXML(pos::PixelConfigKey key, int version, std::string path) const override
Definition: PixelTBMSettings.h:45
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
pos::PixelTBMSettings::rocid_
PixelROCName rocid_
Definition: PixelTBMSettings.h:77
pos::PixelConfigBase::getComment
std::string getComment() const
Definition: PixelConfigBase.h:71
pos::PixelTBMSettings::PixelTBMSettings
PixelTBMSettings()
Definition: PixelTBMSettings.h:32
cuy.ins
ins
Definition: cuy.py:314
pos::PixelConfigKey
This class implements..
Definition: PixelConfigKey.h:20
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
recoMuon::in
Definition: RecoMuonEnumerators.h:6
pos::PixelFECConfigInterface::enablecallatency
virtual int enablecallatency(const int mfec, const int bitstate)=0
createfilelist.int
int
Definition: createfilelist.py:10
pos::operator<<
std::ostream & operator<<(std::ostream &s, const PixelCalibConfiguration &calib)
Definition: PixelCalibConfiguration.cc:1325
value
Definition: value.py:1
pos::PixelHdwAddress
Store mfec, mfecchannel etc.
Definition: PixelHdwAddress.h:23
pos::PixelROCName
This class implements..
Definition: PixelROCName.h:23
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
module
Definition: vlib.h:198
pos::PixelTBMSettings::analogInputBias_
unsigned char analogInputBias_
Definition: PixelTBMSettings.h:80
pos::PixelTBMSettings::singlemode_
bool singlemode_
Definition: PixelTBMSettings.h:83
pos::PixelFECConfigInterface::injectrsttbm
virtual int injectrsttbm(const int mfec, const int bitstate)=0
PixelTBMSettings.h
This class implements..
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
pos::PixelTBMSettings::getAnalogOutputGain
unsigned char getAnalogOutputGain() const
Definition: PixelTBMSettings.h:63
pos::PixelNameTranslation
This is the documentation about PixelNameTranslation...
Definition: PixelNameTranslation.h:41
crabWrapper.key
key
Definition: crabWrapper.py:19
BeamSplash_cfg.version
version
Definition: BeamSplash_cfg.py:45
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
pos::PixelHdwAddress::mfec
unsigned int mfec() const
Definition: PixelHdwAddress.h:38