CMS 3D CMS Logo

PixelMaskAllPixels.cc
Go to the documentation of this file.
1 //
2 // This class provide a base class for the
3 // pixel mask data for the pixel FEC configuration
4 // This is a pure interface (abstract class) that
5 // needs to have an implementation.
6 //
7 // All applications should just use this
8 // interface and not care about the specific
9 // implementation
10 //
11 //
12 #include <sstream>
17 #include <fstream>
18 #include <map>
19 #include <iostream>
20 #include <cassert>
21 #include <stdexcept>
22 
23 using namespace pos;
24 using namespace std;
25 
26 //================================================================================================================
27 PixelMaskAllPixels::PixelMaskAllPixels(std::vector<std::vector<std::string> > &tableMat) : PixelMaskBase("", "", "") {
28  std::string mthn = "[PixelMaskAllPixels::PixelMaskAllPixels()]\t\t ";
29  //std::cout << __LINE__ << "]\t" << mthn << "Table Size in const: " << tableMat.size() << std::endl;
30 
31  std::vector<std::string> ins = tableMat[0];
32  std::map<std::string, int> colM;
33  std::vector<std::string> colNames;
34 
35  /*
36  EXTENSION_TABLE_NAME: ROC_MASKS (VIEW: CONF_KEY_ROC_MASKS_V)
37 
38  CONFIG_KEY NOT NULL VARCHAR2(80)
39  KEY_TYPE NOT NULL VARCHAR2(80)
40  KEY_ALIAS NOT NULL VARCHAR2(80)
41  VERSION VARCHAR2(40)
42  KIND_OF_COND NOT NULL VARCHAR2(40)
43  ROC_NAME NOT NULL VARCHAR2(200)
44  KILL_MASK NOT NULL VARCHAR2(4000) colNames.push_back("CONFIG_KEY_ID" );
45 */
46  colNames.push_back("CONFIG_KEY");
47  colNames.push_back("KEY_TYPE");
48  colNames.push_back("KEY_ALIAS");
49  colNames.push_back("VERSION");
50  colNames.push_back("KIND_OF_COND");
51  colNames.push_back("ROC_NAME");
52  colNames.push_back("KILL_MASK");
53 
54  for (unsigned int c = 0; c < ins.size(); c++) {
55  for (unsigned int n = 0; n < colNames.size(); n++) {
56  if (tableMat[0][c] == colNames[n]) {
57  colM[colNames[n]] = c;
58  break;
59  }
60  }
61  } //end for
62  for (unsigned int n = 0; n < colNames.size(); n++) {
63  if (colM.find(colNames[n]) == colM.end()) {
64  std::cerr << mthn << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
65  assert(0);
66  }
67  }
68  maskbits_.clear();
69  for (unsigned int r = 1; r < tableMat.size(); r++) { //Goes to every row of the Matrix
70  std::string currentRocName = tableMat[r][colM["ROC_NAME"]];
71  PixelROCName rocid(currentRocName);
73  tmp.read(rocid,
74  base64_decode(tableMat[r][colM["KILL_MASK"]])); // decode back from specially base64-encoded data for XML
75  maskbits_.push_back(tmp);
76  } //end for r
77 }
78 
79 //================================================================================================================
80 // modified by MR on 18-04-2008 10:02:00
82 
83 //================================================================================================================
84 void PixelMaskAllPixels::addROCMaskBits(const PixelROCMaskBits &bits) { maskbits_.push_back(bits); }
85 
86 //================================================================================================================
88  std::string mthn = "[PixelMaskAllPixels::PixelMaskAllPixels()]\t\t ";
89 
90  if (filename[filename.size() - 1] == 't') {
91  std::ifstream in(filename.c_str());
92 
93  if (!in.good()) {
94  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
95  throw std::runtime_error("Failed to open file " + filename);
96  }
97 
99  in >> tag;
100 
101  maskbits_.clear();
102 
103  while (!in.eof()) {
104  PixelROCName rocid(in);
105 
107 
108  tmp.read(rocid, in);
109 
110  maskbits_.push_back(tmp);
111 
112  in >> tag;
113  }
114 
115  in.close();
116 
117  } else {
118  std::ifstream in(filename.c_str(), std::ios::binary);
119 
120  char nchar;
121 
122  in.read(&nchar, 1);
123 
124  //in >> nchar;
125 
126  std::string s1;
127 
128  //wrote these lines of code without ref. needs to be fixed
129  for (int i = 0; i < nchar; i++) {
130  char c;
131  in >> c;
132  s1.push_back(c);
133  }
134 
135  //std::cout << __LINE__ << "]\t" << mthn << "READ ROC name: " << s1 << std::endl;
136 
137  maskbits_.clear();
138 
139  while (!in.eof()) {
140  //std::cout << __LINE__ << "]\t" << mthn << "read s1: " << s1 << std::endl;
141 
142  PixelROCName rocid(s1);
143 
144  //std::cout << __LINE__ << "]\t" << mthn << "read rocid: " << rocid << std::endl;
145 
147 
148  tmp.readBinary(rocid, in);
149 
150  maskbits_.push_back(tmp);
151 
152  in.read(&nchar, 1);
153 
154  s1.clear();
155 
156  if (in.eof())
157  continue;
158 
159  //std::cout << __LINE__ << "]\t" << mthn << "Will read: " << (int)nchar << " characters." <<std::endl;
160 
161  //wrote these lines of code without ref. needs to be fixed
162  for (int i = 0; i < nchar; i++) {
163  char c;
164  in >> c;
165  //std::cout << " " <<c;
166  s1.push_back(c);
167  }
168  //std::cout << std::endl;
169  }
170 
171  in.close();
172  }
173 
174  //std::cout << __LINE__ << "]\t" << mthn << "Read maskbits for " << maskbits_.size() << " ROCs" << std::endl;
175 }
176 
177 //================================================================================================================
178 const PixelROCMaskBits &PixelMaskAllPixels::getMaskBits(int ROCId) const { return maskbits_[ROCId]; }
179 
180 //================================================================================================================
182  for (unsigned int i = 0; i < maskbits_.size(); i++) {
183  if (maskbits_[i].name() == name)
184  return &(maskbits_[i]);
185  }
186 
187  return nullptr;
188 }
189 
190 //================================================================================================================
192  std::ofstream out(filename.c_str(), std::ios::binary);
193 
194  for (unsigned int i = 0; i < maskbits_.size(); i++) {
195  maskbits_[i].writeBinary(out);
196  }
197 }
198 
199 //================================================================================================================
201  if (!dir.empty())
202  dir += "/";
203  PixelModuleName module(maskbits_[0].name().rocname());
204  std::string filename = dir + "ROC_Masks_module_" + module.modulename() + ".dat";
205 
206  std::ofstream out(filename.c_str());
207 
208  for (unsigned int i = 0; i < maskbits_.size(); i++) {
209  maskbits_[i].writeASCII(out);
210  }
211 }
212 
213 //=============================================================================================
215  int version,
217  std::ofstream *outstream,
218  std::ofstream *out1stream,
219  std::ofstream *out2stream) const {
220  std::string mthn = "[PixelMaskAllPixels::writeXMLHeader()]\t\t\t ";
221  std::stringstream maskFullPath;
222 
223  maskFullPath << path << "/Pixel_RocMasks_" << PixelTimeFormatter::getmSecTime() << ".xml";
224  std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl;
225 
226  outstream->open(maskFullPath.str().c_str());
227 
228  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl;
229  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
230  *outstream << "" << std::endl;
231  *outstream << " <HEADER>" << std::endl;
232  *outstream << " <TYPE>" << std::endl;
233  *outstream << " <EXTENSION_TABLE_NAME>ROC_MASKS</EXTENSION_TABLE_NAME>" << std::endl;
234  *outstream << " <NAME>ROC Mask Bits</NAME>" << std::endl;
235  *outstream << " </TYPE>" << std::endl;
236  *outstream << " <RUN>" << std::endl;
237  *outstream << " <RUN_TYPE>ROC Mask Bits</RUN_TYPE>" << std::endl;
238  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl;
239  *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl;
240  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl;
241  *outstream << " </RUN>" << std::endl;
242  *outstream << " </HEADER>" << std::endl;
243  *outstream << "" << std::endl;
244  *outstream << " <DATA_SET>" << std::endl;
245  *outstream << "" << std::endl;
246  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl;
247  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl;
248  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl;
249  *outstream << "" << std::endl;
250  *outstream << " <PART>" << std::endl;
251  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl;
252  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl;
253  *outstream << " </PART>" << std::endl;
254  *outstream << " " << std::endl;
255 }
256 //=============================================================================================
257 void PixelMaskAllPixels::writeXML(std::ofstream *outstream,
258  std::ofstream *out1stream,
259  std::ofstream *out2stream) const {
260  std::string mthn = "[PixelMaskAllPixels::writeXML()]\t\t\t ";
261 
262  for (unsigned int i = 0; i < maskbits_.size(); i++) {
263  maskbits_[i].writeXML(outstream);
264  }
265 }
266 //=============================================================================================
267 void PixelMaskAllPixels::writeXMLTrailer(std::ofstream *outstream,
268  std::ofstream *out1stream,
269  std::ofstream *out2stream) const {
270  std::string mthn = "[PixelMaskAllPixels::writeXMLTrailer()]\t\t\t ";
271 
272  *outstream << " " << std::endl;
273  *outstream << " </DATA_SET>" << std::endl;
274  *outstream << "</ROOT>" << std::endl;
275 
276  outstream->close();
277  std::cout << __LINE__ << "]\t" << mthn << "Data written " << std::endl;
278 }
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
pos::PixelMaskAllPixels::writeXMLTrailer
void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
Definition: PixelMaskAllPixels.cc:267
PixelTimeFormatter.h
This class provides utility methods to manipulate ASCII formatted timestamps.
PixelBase64.h
pos::PixelMaskBase
This is the documentation about PixelMaskBase...
Definition: PixelMaskBase.h:36
pos::PixelMaskAllPixels::getMaskBits
const PixelROCMaskBits & getMaskBits(int ROCId) const override
Definition: PixelMaskAllPixels.cc:178
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
pos::PixelMaskAllPixels::writeBinary
void writeBinary(std::string filename) const override
Definition: PixelMaskAllPixels.cc:191
pos::PixelModuleName
This class implements..
Definition: PixelModuleName.h:26
cms::cuda::assert
assert(be >=bs)
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
pos::PixelMaskAllPixels::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: PixelMaskAllPixels.cc:214
pos::PixelTimeFormatter::getTime
static std::string getTime(void)
Definition: PixelTimeFormatter.h:60
pos::PixelConfigBase::getAuthor
std::string getAuthor() const
Definition: PixelConfigBase.h:70
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
pos::PixelMaskAllPixels::maskbits_
std::vector< PixelROCMaskBits > maskbits_
Definition: PixelMaskAllPixels.h:51
pos::PixelTimeFormatter::getmSecTime
static std::string getmSecTime(void)
Definition: PixelTimeFormatter.h:93
PixelModuleName.h
This class implements..
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
pos::PixelMaskAllPixels::addROCMaskBits
void addROCMaskBits(const PixelROCMaskBits &)
Definition: PixelMaskAllPixels.cc:84
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
pos::PixelConfigBase::getComment
std::string getComment() const
Definition: PixelConfigBase.h:71
cuy.ins
ins
Definition: cuy.py:314
pos::PixelMaskAllPixels::writeASCII
void writeASCII(std::string dir) const override
Definition: PixelMaskAllPixels.cc:200
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
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
PixelMaskAllPixels.h
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
std
Definition: JetResolutionObject.h:76
base64_decode
#define base64_decode(in, inlen, out, outlen)
Definition: base64.h:52
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
pos::PixelMaskAllPixels::writeXML
void writeXML(pos::PixelConfigKey key, int version, std::string path) const override
Definition: PixelMaskAllPixels.h:34
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
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::PixelMaskAllPixels::PixelMaskAllPixels
PixelMaskAllPixels()
Definition: PixelMaskAllPixels.cc:81
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23