CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <assert.h>
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) 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  pixelFEC->injectrsttbm(mfec, 1);
268  pixelFEC->injectrstroc(mfec,1);
269  pixelFEC->enablecallatency(mfec,0);
270  pixelFEC->disableexttrigger(mfec,0);
271  pixelFEC->injecttrigger(mfec,0);
272  pixelFEC->callatencycount(mfec,79);
273 
274  //pixelFEC->synccontrolregister(mfec);
275 
276  //Reset TBM and reset ROC
277  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 2, 0x14, 0);
278  //setting speed to 40MHz
279  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 0, 1, 0);
280  // setting the mode, we should always stay in the CAL mode
281  // since the EventNumberClear Mode does not work correctly
282  //if (physics) { // comment out, stau always in the CAL mode, d.k. 27/09/09
283  //pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 1, 0x80, 0);
284  //} else {
285  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 1, 0xc0, 0);
286  //}
287  //Enable token and analog output
288  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 4, 0x0, 0);
289 
290  //Analog input bias
291  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 5,
292  analogInputBias_, 0);
293  //Analog output bias
294  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 6,
295  analogOutputBias_, 0);
296  //Analog output gain
297  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannel, hubaddress, 4, 7,
298  analogOutputGain_, 0);
299 
300 
301  //setting speed to 40MHz
302  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannelB, hubaddress, 4, 0, 1, 0);
303  //pre-calibration, stay always in this mode
304  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannelB, hubaddress, 4, 1, 0xc0, 0);
305  //Reset TBM and reset ROC
306  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannelB, hubaddress, 4, 2, 0x14, 0);
307  //Enable token and analog output
308  if (singlemode_){
309  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannelB, hubaddress, 4, 4, 0x3, 0);
310  }
311  else{
312  pixelFEC->tbmcmd(mfec, mfecchannel, tbmchannelB, hubaddress, 4, 4, 0x0, 0);
313  }
314 }
315 
316 
317 std::ostream& pos::operator<<(std::ostream& s, const PixelTBMSettings& tbm){
318 
319  s << "Module :"<<tbm.rocid_.rocname() <<std::endl;
320  s << "analogInputBias :"<<tbm.analogInputBias_<<std::endl;
321  s << "analogOutputBias:"<<tbm.analogOutputBias_<<std::endl;
322  s << "analogOutputGain:"<<tbm.analogOutputGain_<<std::endl;
323  if (tbm.singlemode_){
324  s << "mode :Singlemode"<<std::endl;
325  }
326  else{
327  s << "mode :Dualmode"<<std::endl;
328  }
329 
330  return s;
331 
332 }
333 //=============================================================================================
335  int version,
336  std::string path,
337  std::ofstream *outstream,
338  std::ofstream *out1stream,
339  std::ofstream *out2stream) const
340 {
341  std::string mthn = "]\t[PixelTBMSettings::writeXMLHeader()]\t\t\t " ;
342  std::stringstream fullPath ;
343  fullPath << path << "/Pixel_TbmParameters_" << PixelTimeFormatter::getmSecTime() << ".xml" ;
344  std::cout << __LINE__ << mthn << "Writing to: " << fullPath.str() << std::endl ;
345 
346  outstream->open(fullPath.str().c_str()) ;
347 
348  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl ;
349  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl ;
350  *outstream << " <HEADER>" << std::endl ;
351  *outstream << " <TYPE>" << std::endl ;
352  *outstream << " <EXTENSION_TABLE_NAME>PIXEL_TBM_PARAMETERS</EXTENSION_TABLE_NAME>" << std::endl ;
353  *outstream << " <NAME>Pixel TBM Parameters</NAME>" << std::endl ;
354  *outstream << " </TYPE>" << std::endl ;
355  *outstream << " <RUN>" << std::endl ;
356  *outstream << " <RUN_TYPE>Pixel TBM Parameters</RUN_TYPE>" << std::endl ;
357  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl ;
358  *outstream << " <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
359  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl ;
360  *outstream << " </RUN>" << std::endl ;
361  *outstream << " </HEADER>" << std::endl ;
362  *outstream << "" << std::endl ;
363  *outstream << " <DATA_SET>" << std::endl ;
364  *outstream << " <PART>" << std::endl ;
365  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl ;
366  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl ;
367  *outstream << " </PART>" << std::endl ;
368  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl ;
369  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl ;
370  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl ;
371  *outstream << " " << std::endl ;
372 }
373 
374 //=============================================================================================
375 void PixelTBMSettings::writeXML(std::ofstream *outstream,
376  std::ofstream *out1stream,
377  std::ofstream *out2stream) const
378 {
379  std::string mthn = "]\t[PixelTBMSettings::writeXML()]\t\t\t " ;
380 
382 
383  *outstream << " <DATA>" << std::endl ;
384  *outstream << " <MODULE_NAME>" << rocid_.rocname() << "</MODULE_NAME>" << std::endl ;
385  *outstream << " <ANLG_INBIAS_VAL>" <<(int)analogInputBias_ << "</ANLG_INBIAS_VAL>" << std::endl ;
386  *outstream << " <ANLG_OUTBIAS_VAL>" <<(int)analogOutputBias_ << "</ANLG_OUTBIAS_VAL>" << std::endl ;
387  *outstream << " <ANLG_OUTGAIN_VAL>" <<(int)analogOutputGain_ << "</ANLG_OUTGAIN_VAL>" << std::endl ;
388  if (singlemode_) {
389  *outstream << " <TBM_MODE>SingleMode</TBM_MODE>" << std::endl ;
390  }
391  else{
392  *outstream << " <TBM_MODE>DualMode</TBM_MODE>" << std::endl ;
393  }
394  *outstream << " </DATA>" << std::endl ;
395 }
396 
397 //=============================================================================================
398 void PixelTBMSettings::writeXMLTrailer(std::ofstream *outstream,
399  std::ofstream *out1stream,
400  std::ofstream *out2stream) const
401 {
402  std::string mthn = "]\t[PixelTBMSettings::writeXMLTrailer()]\t\t\t " ;
403 
404  *outstream << " " << std::endl ;
405  *outstream << " </DATA_SET>" << std::endl ;
406  *outstream << "</ROOT> " << std::endl ;
407 
408  outstream->close() ;
409 }
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
int i
Definition: DBlmapReader.cc:9
void writeASCII(std::string dir) const
This file contains the base class for &quot;pixel configuration data&quot; management.
unsigned char analogOutputBias_
void generateConfiguration(PixelFECConfigInterface *pixelFEC, PixelNameTranslation *trans, bool physics=false) const
virtual int enablecallatency(const int mfec, const int bitstate)=0
unsigned char analogOutputGain_
void writeXML(pos::PixelConfigKey key, int version, std::string path) const
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
unsigned int mfecchannel() const
virtual void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) 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.
tuple ins
Definition: cuy.py:312
virtual int injectrstroc(const int mfec, const int bitstate)=0
std::string getAuthor() const
This class implements..
tuple out
Definition: dbtoconf.py:99
unsigned char analogInputBias_
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
list key
Definition: combine.py:13
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121
virtual int callatencycount(const int mfec, const int latency)=0
dbl *** dir
Definition: mlp_gen.cc:35
virtual void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) const
Definition: vlib.h:208
virtual int injectrsttbm(const int mfec, const int bitstate)=0
This is the documentation about PixelTBMSettings...