test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelTrimAllPixels.cc
Go to the documentation of this file.
1 //
2 // This class provide a base class for the
3 // pixel trim data for the pixel FEC configuration
4 // This is a pure interface (abstract class) that
5 // needs to have an implementation.
6 //
7 // Need to figure out what is 'VMEcommand' below!
8 //
9 // All applications should just use this
10 // interface and not care about the specific
11 // implementation.
12 //
13 
14 #include <sstream>
15 #include <iostream>
16 #include <ios>
17 #include <assert.h>
18 #include <stdexcept>
22 
23 using namespace pos;
24 
25 PixelTrimAllPixels::PixelTrimAllPixels( std::vector <std::vector<std::string> >& tableMat):
26  PixelTrimBase("","","")
27 {
28  std::string mthn = "]\t[PixelTrimAllPixels::PixelTrimAllPixels()]\t\t " ;
29  std::stringstream currentRocName;
30  std::map<std::string , int > colM;
31  std::vector<std::string > colNames;
44  colNames.push_back("CONFIG_KEY" );
45  colNames.push_back("KEY_TYPE" );
46  colNames.push_back("KEY_ALIAS" );
47  colNames.push_back("VERSION" );
48  colNames.push_back("KIND_OF_COND");
49  colNames.push_back("ROC_NAME" );
50  colNames.push_back("TRIM_BITS" );
51 
52 
53  for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
54  {
55  for(unsigned int n=0; n<colNames.size(); n++)
56  {
57  if(tableMat[0][c] == colNames[n])
58  {
59  colM[colNames[n]] = c;
60  break;
61  }
62  }
63  }//end for
64  for(unsigned int n=0; n<colNames.size(); n++)
65  {
66  if(colM.find(colNames[n]) == colM.end())
67  {
68  std::cerr << __LINE__ << mthn << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
69  assert(0);
70  }
71  }
72 
73  //unsigned char *bits ; /// supose to be " unsigned char bits[tableMat[1][colM["TRIM_BLOB"]].size()] ; "
74  //char c[2080];
76  trimbits_.clear() ;
77  for(unsigned int r = 1 ; r < tableMat.size() ; r++) //Goes to every row of the Matrix
78  {
79  PixelROCName rocid( tableMat[r][colM["ROC_NAME"]] );
81  tmp.read(rocid, base64_decode(tableMat[r][colM["TRIM_BITS"]])) ;
82  trimbits_.push_back(tmp);
83  }//end for r
84  //std::cout<<trimbits_.size()<<std::endl;
85 } //end contructor with databasa table
86 
87 
89  PixelTrimBase("","",""){
90 
91  if (filename[filename.size()-1]=='t'){
92 
93  std::ifstream in(filename.c_str());
94 
95  if (!in.good()) throw std::runtime_error("Failed to open file "+filename);
96  // std::cout << "filename =" << filename << std::endl;
97 
98  std::string s1;
99  in >> s1;
100 
101  trimbits_.clear();
102 
103 
104  while (in.good()){
105 
106  std::string s2;
107  in>>s2;
108 
109  // std::cout << "PixelTrimAllPixels::PixelTrimAllPixels read s1:"<<s1<< " s2:" << s2 << std::endl;
110 
111  assert( s1 == "ROC:" );
112 
113  PixelROCName rocid(s2);
114 
115  //std::cout << "PixelTrimAllPixels::PixelTrimAllPixels read rocid:"<<rocid<<std::endl;
116 
118 
119  tmp.read(rocid, in);
120 
121  trimbits_.push_back(tmp);
122 
123  in >> s1;
124 
125  }
126 
127  in.close();
128 
129  }
130  else{
131 
132  std::ifstream in(filename.c_str(),std::ios::binary);
133  if (!in.good()) throw std::runtime_error("Failed to open file "+filename);
134 
135  char nchar;
136 
137  in.read(&nchar,1);
138 
139  std::string s1;
140 
141  //wrote these lines of code without ref. needs to be fixed
142  for(int i=0;i< nchar; i++){
143  char c;
144  in >>c;
145  s1.push_back(c);
146  }
147 
148  //std::cout << "READ ROC name:"<<s1<<std::endl;
149 
150  trimbits_.clear();
151 
152 
153  while (!in.eof()){
154 
155  //std::cout << "PixelTrimAllPixels::PixelTrimAllPixels read s1:"<<s1<<std::endl;
156 
157  PixelROCName rocid(s1);
158 
159  //std::cout << "PixelTrimAllPixels::PixelTrimAllPixels read rocid:"<<rocid<<std::endl;
160 
162 
163  tmp.readBinary(rocid, in);
164 
165  trimbits_.push_back(tmp);
166 
167 
168  in.read(&nchar,1);
169 
170  s1.clear();
171 
172  if (in.eof()) continue;
173 
174  //wrote these lines of code without ref. needs to be fixed
175  for(int i=0;i< nchar; i++){
176  char c;
177  in >>c;
178  s1.push_back(c);
179  }
180 
181 
182  }
183 
184  in.close();
185 
186 
187 
188  }
189 
190  //std::cout << "Read trimbits for "<<trimbits_.size()<<" ROCs"<<std::endl;
191 
192  }
193 
194 
195 //std::string PixelTrimAllPixels::getConfigCommand(PixelMaskBase& pixelMask){
196 //
197 // std::string s;
198 // return s;
199 //
200 //}
201 
203 
204  return trimbits_[ROCId];
205 
206 }
207 
209 
210  for(unsigned int i=0;i<trimbits_.size();i++){
211  if (trimbits_[i].name()==name) return &(trimbits_[i]);
212  }
213 
214  return 0;
215 
216 }
217 
218 
219 
222  const PixelMaskBase& pixelMask) const{
223 
224  for(unsigned int i=0;i<trimbits_.size();i++){
225 
226  std::vector<unsigned char> trimAndMasks(4160);
227 
228  const PixelROCMaskBits& maskbits=pixelMask.getMaskBits(i);
229 
230  for (unsigned int col=0;col<52;col++){
231  for (unsigned int row=0;row<80;row++){
232  unsigned char tmp=trimbits_[i].trim(col,row);
233  if (maskbits.mask(col,row)!=0) tmp|=0x80;
234  trimAndMasks[col*80+row]=tmp;
235  }
236  }
237 
238  // the slow way, one pixel at a time
239  //pixelFEC->setMaskAndTrimAll(*(trans->getHdwAddress(trimbits_[i].name())),trimAndMasks);
240  // the fast way, a full roc in column mode (& block xfer)
241  const PixelHdwAddress* theROC = trans->getHdwAddress(trimbits_[i].name());
242  pixelFEC->roctrimload(theROC->mfec(),
243  theROC->mfecchannel(),
244  theROC->hubaddress(),
245  theROC->portaddress(),
246  theROC->rocid(),
247  trimAndMasks);
248  }
249 }
250 
252 
253 
254  std::ofstream out(filename.c_str(),std::ios::binary);
255 
256  for(unsigned int i=0;i<trimbits_.size();i++){
257  trimbits_[i].writeBinary(out);
258  }
259 
260 
261 }
262 
263 
265 
266  if (dir!="") dir+="/";
267  PixelModuleName module(trimbits_[0].name().rocname());
268  std::string filename=dir+"ROC_Trims_module_"+module.modulename()+".dat";
269 
270 
271  std::ofstream out(filename.c_str());
272 
273  for(unsigned int i=0;i<trimbits_.size();i++){
274  trimbits_[i].writeASCII(out);
275  }
276 
277 
278 }
279 //=============================================================================================
281  int version,
282  std::string path,
283  std::ofstream *outstream,
284  std::ofstream *out1stream,
285  std::ofstream *out2stream) const
286 {
287  std::string mthn = "[PixelTrimAllPixels::writeXMLHeader()]\t\t\t " ;
288  std::stringstream maskFullPath ;
289 
290  maskFullPath << path << "/Pixel_RocTrims_" << PixelTimeFormatter::getmSecTime() << ".xml";
291  std::cout << mthn << "Writing to: " << maskFullPath.str() << std::endl ;
292 
293  outstream->open(maskFullPath.str().c_str()) ;
294 
295  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl ;
296  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl ;
297  *outstream << "" << std::endl ;
298  *outstream << " <HEADER>" << std::endl ;
299  *outstream << " <TYPE>" << std::endl ;
300  *outstream << " <EXTENSION_TABLE_NAME>ROC_TRIMS</EXTENSION_TABLE_NAME>" << std::endl ;
301  *outstream << " <NAME>ROC Trim Bits</NAME>" << std::endl ;
302  *outstream << " </TYPE>" << std::endl ;
303  *outstream << " <RUN>" << std::endl ;
304  *outstream << " <RUN_TYPE>ROC Trim Bits</RUN_TYPE>" << std::endl ;
305  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl ;
306  *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
307  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl ;
308  *outstream << " </RUN>" << std::endl ;
309  *outstream << " </HEADER>" << std::endl ;
310  *outstream << "" << std::endl ;
311  *outstream << " <DATA_SET>" << std::endl ;
312  *outstream << "" << std::endl ;
313  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl ;
314  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl ;
315  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl ;
316  *outstream << "" << std::endl ;
317  *outstream << " <PART>" << std::endl ;
318  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl ;
319  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl ;
320  *outstream << " </PART>" << std::endl ;
321  *outstream << "" << std::endl ;
322 
323 }
324 
325 //=============================================================================================
326 void PixelTrimAllPixels::writeXML( std::ofstream *outstream,
327  std::ofstream *out1stream,
328  std::ofstream *out2stream) const
329 {
330  std::string mthn = "[PixelTrimAllPixels::writeXML()]\t\t\t " ;
331 
332  for(unsigned int i=0;i<trimbits_.size();i++){
333  trimbits_[i].writeXML(outstream);
334  }
335 }
336 
337 //=============================================================================================
338 void PixelTrimAllPixels::writeXMLTrailer(std::ofstream *outstream,
339  std::ofstream *out1stream,
340  std::ofstream *out2stream ) const
341 {
342  std::string mthn = "[PixelTrimAllPixels::writeXMLTrailer()]\t\t\t " ;
343 
344  *outstream << " </DATA_SET>" << std::endl ;
345  *outstream << "</ROOT>" << std::endl ;
346 
347  outstream->close() ;
348  std::cout << mthn << "Data written " << std::endl ;
349 
350 }
unsigned int mfec() const
const PixelHdwAddress * getHdwAddress(const PixelROCName &aROC) const
int i
Definition: DBlmapReader.cc:9
int read(PixelROCName rocid, std::string in)
void writeBinary(std::string filename) const
#define base64_decode(in, inlen, out, outlen)
Definition: base64.h:57
unsigned int portaddress() const
void writeASCII(std::string filename) const
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision bits
int readBinary(PixelROCName rocid, std::ifstream &in)
unsigned int rocid() const
unsigned int mfecchannel() const
static std::string getmSecTime(void)
tuple s2
Definition: indexGen.py:106
virtual int roctrimload(int mfec, int fecchannel, int hubaddress, int portaddress, int rocid, const std::vector< unsigned char > &allPixels)=0
void writeXML(pos::PixelConfigKey key, int version, std::string path) const
tuple path
else: Piece not in the list, fine.
virtual const PixelROCMaskBits & getMaskBits(int ROCId) const =0
static std::string getTime(void)
std::string getComment() const
unsigned int hubaddress() const
This class provides utility methods to manipulate ASCII formatted timestamps.
Store mfec, mfecchannel etc.
std::string getAuthor() const
std::vector< PixelROCTrimBits > trimbits_
PixelROCTrimBits getTrimBits(int ROCId) const
This is the documentation about PixelMaskBase...
Definition: PixelMaskBase.h:36
This class implements..
tuple out
Definition: dbtoconf.py:99
This class implements..
virtual void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) const
PixelTrimAllPixels(std::string filename)
std::string modulename() const
This class implements..
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
This class implements..
list key
Definition: combine.py:13
unsigned int mask(unsigned int col, unsigned int row) const
tuple filename
Definition: lut2db_cfg.py:20
virtual void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) const
This class implements..
Definition: PixelTrimBase.h:46
tuple cout
Definition: gather_cfg.py:121
dbl *** dir
Definition: mlp_gen.cc:35
int col
Definition: cuy.py:1008
void generateConfiguration(PixelFECConfigInterface *pixelFEC, PixelNameTranslation *trans, const PixelMaskBase &pixelMask) const