CMS 3D CMS Logo

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 <cassert>
18 #include <stdexcept>
22 
23 using namespace pos;
24 
25 PixelTrimAllPixels::PixelTrimAllPixels(std::vector<std::vector<std::string> > &tableMat) : PixelTrimBase("", "", "") {
26  std::string mthn = "]\t[PixelTrimAllPixels::PixelTrimAllPixels()]\t\t ";
27  std::stringstream currentRocName;
28  std::map<std::string, int> colM;
29  std::vector<std::string> colNames;
42  colNames.push_back("CONFIG_KEY");
43  colNames.push_back("KEY_TYPE");
44  colNames.push_back("KEY_ALIAS");
45  colNames.push_back("VERSION");
46  colNames.push_back("KIND_OF_COND");
47  colNames.push_back("ROC_NAME");
48  colNames.push_back("TRIM_BITS");
49 
50  for (unsigned int c = 0; c < tableMat[0].size(); c++) {
51  for (unsigned int n = 0; n < colNames.size(); n++) {
52  if (tableMat[0][c] == colNames[n]) {
53  colM[colNames[n]] = c;
54  break;
55  }
56  }
57  } //end for
58  for (unsigned int n = 0; n < colNames.size(); n++) {
59  if (colM.find(colNames[n]) == colM.end()) {
60  std::cerr << __LINE__ << mthn << "Couldn't find in the database the column with name " << colNames[n]
61  << std::endl;
62  assert(0);
63  }
64  }
65 
66  //unsigned char *bits ; /// supose to be " unsigned char bits[tableMat[1][colM["TRIM_BLOB"]].size()] ; "
67  //char c[2080];
69  trimbits_.clear();
70  for (unsigned int r = 1; r < tableMat.size(); r++) //Goes to every row of the Matrix
71  {
72  PixelROCName rocid(tableMat[r][colM["ROC_NAME"]]);
74  tmp.read(rocid, base64_decode(tableMat[r][colM["TRIM_BITS"]]));
75  trimbits_.push_back(tmp);
76  } //end for r
77  //std::cout<<trimbits_.size()<<std::endl;
78 } //end contructor with databasa table
79 
81  if (filename[filename.size() - 1] == 't') {
82  std::ifstream in(filename.c_str());
83 
84  if (!in.good())
85  throw std::runtime_error("Failed to open file " + filename);
86  // std::cout << "filename =" << filename << std::endl;
87 
88  std::string s1;
89  in >> s1;
90 
91  trimbits_.clear();
92 
93  while (in.good()) {
94  std::string s2;
95  in >> s2;
96 
97  // std::cout << "PixelTrimAllPixels::PixelTrimAllPixels read s1:"<<s1<< " s2:" << s2 << std::endl;
98 
99  assert(s1 == "ROC:");
100 
101  PixelROCName rocid(s2);
102 
103  //std::cout << "PixelTrimAllPixels::PixelTrimAllPixels read rocid:"<<rocid<<std::endl;
104 
106 
107  tmp.read(rocid, in);
108 
109  trimbits_.push_back(tmp);
110 
111  in >> s1;
112  }
113 
114  in.close();
115 
116  } else {
117  std::ifstream in(filename.c_str(), std::ios::binary);
118  if (!in.good())
119  throw std::runtime_error("Failed to open file " + filename);
120 
121  char nchar;
122 
123  in.read(&nchar, 1);
124 
125  std::string s1;
126 
127  //wrote these lines of code without ref. needs to be fixed
128  for (int i = 0; i < nchar; i++) {
129  char c;
130  in >> c;
131  s1.push_back(c);
132  }
133 
134  //std::cout << "READ ROC name:"<<s1<<std::endl;
135 
136  trimbits_.clear();
137 
138  while (!in.eof()) {
139  //std::cout << "PixelTrimAllPixels::PixelTrimAllPixels read s1:"<<s1<<std::endl;
140 
141  PixelROCName rocid(s1);
142 
143  //std::cout << "PixelTrimAllPixels::PixelTrimAllPixels read rocid:"<<rocid<<std::endl;
144 
146 
147  tmp.readBinary(rocid, in);
148 
149  trimbits_.push_back(tmp);
150 
151  in.read(&nchar, 1);
152 
153  s1.clear();
154 
155  if (in.eof())
156  continue;
157 
158  //wrote these lines of code without ref. needs to be fixed
159  for (int i = 0; i < nchar; i++) {
160  char c;
161  in >> c;
162  s1.push_back(c);
163  }
164  }
165 
166  in.close();
167  }
168 
169  //std::cout << "Read trimbits for "<<trimbits_.size()<<" ROCs"<<std::endl;
170 }
171 
172 //std::string PixelTrimAllPixels::getConfigCommand(PixelMaskBase& pixelMask){
173 //
174 // std::string s;
175 // return s;
176 //
177 //}
178 
179 PixelROCTrimBits PixelTrimAllPixels::getTrimBits(int ROCId) const { return trimbits_[ROCId]; }
180 
182  for (unsigned int i = 0; i < trimbits_.size(); i++) {
183  if (trimbits_[i].name() == name)
184  return &(trimbits_[i]);
185  }
186 
187  return nullptr;
188 }
189 
191  PixelNameTranslation *trans,
192  const PixelMaskBase &pixelMask) const {
193  for (unsigned int i = 0; i < trimbits_.size(); i++) {
194  std::vector<unsigned char> trimAndMasks(4160);
195 
196  const PixelROCMaskBits &maskbits = pixelMask.getMaskBits(i);
197 
198  for (unsigned int col = 0; col < 52; col++) {
199  for (unsigned int row = 0; row < 80; row++) {
200  unsigned char tmp = trimbits_[i].trim(col, row);
201  if (maskbits.mask(col, row) != 0)
202  tmp |= 0x80;
203  trimAndMasks[col * 80 + row] = tmp;
204  }
205  }
206 
207  // the slow way, one pixel at a time
208  //pixelFEC->setMaskAndTrimAll(*(trans->getHdwAddress(trimbits_[i].name())),trimAndMasks);
209  // the fast way, a full roc in column mode (& block xfer)
210  const PixelHdwAddress *theROC = trans->getHdwAddress(trimbits_[i].name());
211  pixelFEC->roctrimload(theROC->mfec(),
212  theROC->mfecchannel(),
213  theROC->hubaddress(),
214  theROC->portaddress(),
215  theROC->rocid(),
216  trimAndMasks);
217  }
218 }
219 
221  std::ofstream out(filename.c_str(), std::ios::binary);
222 
223  for (unsigned int i = 0; i < trimbits_.size(); i++) {
224  trimbits_[i].writeBinary(out);
225  }
226 }
227 
229  if (!dir.empty())
230  dir += "/";
231  PixelModuleName module(trimbits_[0].name().rocname());
232  std::string filename = dir + "ROC_Trims_module_" + module.modulename() + ".dat";
233 
234  std::ofstream out(filename.c_str());
235 
236  for (unsigned int i = 0; i < trimbits_.size(); i++) {
237  trimbits_[i].writeASCII(out);
238  }
239 }
240 //=============================================================================================
242  int version,
244  std::ofstream *outstream,
245  std::ofstream *out1stream,
246  std::ofstream *out2stream) const {
247  std::string mthn = "[PixelTrimAllPixels::writeXMLHeader()]\t\t\t ";
248  std::stringstream maskFullPath;
249 
250  maskFullPath << path << "/Pixel_RocTrims_" << PixelTimeFormatter::getmSecTime() << ".xml";
251  std::cout << mthn << "Writing to: " << maskFullPath.str() << std::endl;
252 
253  outstream->open(maskFullPath.str().c_str());
254 
255  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl;
256  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
257  *outstream << "" << std::endl;
258  *outstream << " <HEADER>" << std::endl;
259  *outstream << " <TYPE>" << std::endl;
260  *outstream << " <EXTENSION_TABLE_NAME>ROC_TRIMS</EXTENSION_TABLE_NAME>" << std::endl;
261  *outstream << " <NAME>ROC Trim Bits</NAME>" << std::endl;
262  *outstream << " </TYPE>" << std::endl;
263  *outstream << " <RUN>" << std::endl;
264  *outstream << " <RUN_TYPE>ROC Trim Bits</RUN_TYPE>" << std::endl;
265  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl;
266  *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl;
267  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl;
268  *outstream << " </RUN>" << std::endl;
269  *outstream << " </HEADER>" << std::endl;
270  *outstream << "" << std::endl;
271  *outstream << " <DATA_SET>" << std::endl;
272  *outstream << "" << std::endl;
273  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl;
274  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl;
275  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl;
276  *outstream << "" << std::endl;
277  *outstream << " <PART>" << std::endl;
278  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl;
279  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl;
280  *outstream << " </PART>" << std::endl;
281  *outstream << "" << std::endl;
282 }
283 
284 //=============================================================================================
285 void PixelTrimAllPixels::writeXML(std::ofstream *outstream,
286  std::ofstream *out1stream,
287  std::ofstream *out2stream) const {
288  std::string mthn = "[PixelTrimAllPixels::writeXML()]\t\t\t ";
289 
290  for (unsigned int i = 0; i < trimbits_.size(); i++) {
291  trimbits_[i].writeXML(outstream);
292  }
293 }
294 
295 //=============================================================================================
296 void PixelTrimAllPixels::writeXMLTrailer(std::ofstream *outstream,
297  std::ofstream *out1stream,
298  std::ofstream *out2stream) const {
299  std::string mthn = "[PixelTrimAllPixels::writeXMLTrailer()]\t\t\t ";
300 
301  *outstream << " </DATA_SET>" << std::endl;
302  *outstream << "</ROOT>" << std::endl;
303 
304  outstream->close();
305  std::cout << mthn << "Data written " << std::endl;
306 }
void writeXML(pos::PixelConfigKey key, int version, std::string path) const override
void writeASCII(std::string filename) const override
unsigned int mfec() const
#define base64_decode(in, inlen, out, outlen)
Definition: base64.h:52
std::string getComment() const
constexpr uint32_t bits
Definition: gpuClustering.h:25
assert(be >=bs)
static std::string getmSecTime(void)
unsigned int portaddress() const
virtual int roctrimload(int mfec, int fecchannel, int hubaddress, int portaddress, int rocid, const std::vector< unsigned char > &allPixels)=0
virtual const PixelROCMaskBits & getMaskBits(int ROCId) const =0
static std::string getTime(void)
This class provides utility methods to manipulate ASCII formatted timestamps.
Store mfec, mfecchannel etc.
const PixelHdwAddress * getHdwAddress(const PixelROCName &aROC) const
unsigned int mfecchannel() const
std::vector< PixelROCTrimBits > trimbits_
unsigned int rocid() const
This is the documentation about PixelMaskBase...
Definition: PixelMaskBase.h:36
This class implements..
This class implements..
void generateConfiguration(PixelFECConfigInterface *pixelFEC, PixelNameTranslation *trans, const PixelMaskBase &pixelMask) const override
PixelTrimAllPixels(std::string filename)
void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
This class implements..
This is the documentation about PixelNameTranslation...
void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
This class implements..
This class implements..
Definition: PixelROCName.h:23
This class implements..
PixelROCTrimBits getTrimBits(int ROCId) const override
col
Definition: cuy.py:1009
std::string getAuthor() const
This class implements..
Definition: PixelTrimBase.h:45
void writeBinary(std::string filename) const override
tmp
align.sh
Definition: createJobs.py:716
unsigned int hubaddress() const
unsigned int mask(unsigned int col, unsigned int row) const