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];
68  std::string bits;
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()) {
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 }
pos::PixelTrimAllPixels::writeXMLTrailer
void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
Definition: PixelTrimAllPixels.cc:296
pos::PixelFECConfigInterface
This class implements..
Definition: PixelFECConfigInterface.h:23
mps_fire.i
i
Definition: mps_fire.py:428
pos::PixelROCMaskBits
This class implements..
Definition: PixelROCMaskBits.h:24
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
PixelTimeFormatter.h
This class provides utility methods to manipulate ASCII formatted timestamps.
PixelBase64.h
pos::PixelTrimAllPixels::getTrimBits
PixelROCTrimBits getTrimBits(int ROCId) const override
Definition: PixelTrimAllPixels.cc:179
pos::PixelTrimAllPixels::writeBinary
void writeBinary(std::string filename) const override
Definition: PixelTrimAllPixels.cc:220
pos::PixelMaskBase
This is the documentation about PixelMaskBase...
Definition: PixelMaskBase.h:36
cuy.col
col
Definition: cuy.py:1010
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
pos::PixelTrimAllPixels::generateConfiguration
void generateConfiguration(PixelFECConfigInterface *pixelFEC, PixelNameTranslation *trans, const PixelMaskBase &pixelMask) const override
Definition: PixelTrimAllPixels.cc:190
pos::PixelMaskBase::getMaskBits
virtual const PixelROCMaskBits & getMaskBits(int ROCId) const =0
PixelTrimAllPixels.h
This class implements..
pos::PixelModuleName
This class implements..
Definition: PixelModuleName.h:26
cms::cuda::assert
assert(be >=bs)
indexGen.s2
s2
Definition: indexGen.py:107
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
pos::PixelHdwAddress::hubaddress
unsigned int hubaddress() const
Definition: PixelHdwAddress.h:40
pos::PixelHdwAddress::mfecchannel
unsigned int mfecchannel() const
Definition: PixelHdwAddress.h:39
pos::PixelROCTrimBits
This class implements..
Definition: PixelROCTrimBits.h:23
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::PixelHdwAddress::rocid
unsigned int rocid() const
Definition: PixelHdwAddress.h:42
pos::PixelConfigBase::getAuthor
std::string getAuthor() const
Definition: PixelConfigBase.h:70
pos::PixelTrimBase
This class implements..
Definition: PixelTrimBase.h:45
pos::PixelTimeFormatter::getmSecTime
static std::string getmSecTime(void)
Definition: PixelTimeFormatter.h:93
pos::PixelTrimAllPixels::writeASCII
void writeASCII(std::string filename) const override
Definition: PixelTrimAllPixels.cc:228
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
pos::PixelTrimAllPixels::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: PixelTrimAllPixels.cc:241
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
pos::PixelHdwAddress::portaddress
unsigned int portaddress() const
Definition: PixelHdwAddress.h:41
pos::PixelConfigBase::getComment
std::string getComment() const
Definition: PixelConfigBase.h:71
pos::PixelConfigKey
This class implements..
Definition: PixelConfigKey.h:20
recoMuon::in
Definition: RecoMuonEnumerators.h:6
pos::PixelModuleName::modulename
std::string modulename() const
Definition: PixelModuleName.cc:203
pos::PixelHdwAddress
Store mfec, mfecchannel etc.
Definition: PixelHdwAddress.h:23
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
pos::PixelROCName
This class implements..
Definition: PixelROCName.h:23
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
alignCSCRings.r
r
Definition: alignCSCRings.py:93
pos::PixelTrimAllPixels::writeXML
void writeXML(pos::PixelConfigKey key, int version, std::string path) const override
Definition: PixelTrimAllPixels.h:46
base64_decode
#define base64_decode(in, inlen, out, outlen)
Definition: base64.h:52
pos::PixelROCMaskBits::mask
unsigned int mask(unsigned int col, unsigned int row) const
Definition: PixelROCMaskBits.cc:143
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
pos::PixelTrimAllPixels::trimbits_
std::vector< PixelROCTrimBits > trimbits_
Definition: PixelTrimAllPixels.h:64
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
pos::PixelNameTranslation
This is the documentation about PixelNameTranslation...
Definition: PixelNameTranslation.h:41
crabWrapper.key
key
Definition: crabWrapper.py:19
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
BeamSplash_cfg.version
version
Definition: BeamSplash_cfg.py:45
pos::PixelTrimAllPixels::PixelTrimAllPixels
PixelTrimAllPixels(std::string filename)
Definition: PixelTrimAllPixels.cc:80
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
pos::PixelHdwAddress::mfec
unsigned int mfec() const
Definition: PixelHdwAddress.h:38
pos::PixelFECConfigInterface::roctrimload
virtual int roctrimload(int mfec, int fecchannel, int hubaddress, int portaddress, int rocid, const std::vector< unsigned char > &allPixels)=0