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