CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <assert.h>
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 {
29  std::string mthn = "[PixelMaskAllPixels::PixelMaskAllPixels()]\t\t " ;
30  //std::cout << __LINE__ << "]\t" << mthn << "Table Size in const: " << tableMat.size() << std::endl;
31 
32  std::vector< std::string > ins = tableMat[0];
33  std::map<std::string , int > colM;
34  std::vector<std::string > colNames;
35 
36 /*
37  EXTENSION_TABLE_NAME: ROC_MASKS (VIEW: CONF_KEY_ROC_MASKS_V)
38 
39  CONFIG_KEY NOT NULL VARCHAR2(80)
40  KEY_TYPE NOT NULL VARCHAR2(80)
41  KEY_ALIAS NOT NULL VARCHAR2(80)
42  VERSION VARCHAR2(40)
43  KIND_OF_COND NOT NULL VARCHAR2(40)
44  ROC_NAME NOT NULL VARCHAR2(200)
45  KILL_MASK NOT NULL VARCHAR2(4000) colNames.push_back("CONFIG_KEY_ID" );
46 */
47  colNames.push_back("CONFIG_KEY" );
48  colNames.push_back("KEY_TYPE" );
49  colNames.push_back("KEY_ALIAS" );
50  colNames.push_back("VERSION" );
51  colNames.push_back("KIND_OF_COND");
52  colNames.push_back("ROC_NAME" );
53  colNames.push_back("KILL_MASK" );
54 
55  for(unsigned int c = 0 ; c < ins.size() ; c++)
56  {
57  for(unsigned int n=0; n<colNames.size(); n++)
58  {
59  if(tableMat[0][c] == colNames[n])
60  {
61  colM[colNames[n]] = c;
62  break;
63  }
64  }
65  }//end for
66  for(unsigned int n=0; n<colNames.size(); n++)
67  {
68  if(colM.find(colNames[n]) == colM.end())
69  {
70  std::cerr << mthn << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
71  assert(0);
72  }
73  }
74  maskbits_.clear() ;
75  for(unsigned int r = 1 ; r < tableMat.size() ; r++){ //Goes to every row of the Matrix
76  std::string currentRocName = tableMat[r][colM["ROC_NAME"]] ;
77  PixelROCName rocid(currentRocName);
79  tmp.read(rocid,base64_decode(tableMat[r][colM["KILL_MASK"]])) ; // decode back from specially base64-encoded data for XML
80  maskbits_.push_back(tmp);
81  } //end for r
82 }
83 
84 //================================================================================================================
85 // modified by MR on 18-04-2008 10:02:00
87 
88 //================================================================================================================
90 {
91  maskbits_.push_back(bits);
92 }
93 
94 //================================================================================================================
96  PixelMaskBase("","",""){
97 
98  std::string mthn = "[PixelMaskAllPixels::PixelMaskAllPixels()]\t\t " ;
99 
100  if (filename[filename.size()-1]=='t'){
101 
102 
103  std::ifstream in(filename.c_str());
104 
105  if (!in.good()){
106  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
107  throw std::runtime_error("Failed to open file "+filename);
108  }
109 
111  in >> tag;
112 
113  maskbits_.clear();
114 
115  while (!in.eof()) {
116 
117  PixelROCName rocid(in);
118 
120 
121  tmp.read(rocid,in);
122 
123  maskbits_.push_back(tmp);
124 
125  in >> tag;
126 
127  }
128 
129  in.close();
130 
131  }
132  else{
133 
134  std::ifstream in(filename.c_str(),std::ios::binary);
135 
136  char nchar;
137 
138  in.read(&nchar,1);
139 
140  //in >> nchar;
141 
142  std::string s1;
143 
144  //wrote these lines of code without ref. needs to be fixed
145  for(int i=0;i< nchar; i++){
146  char c;
147  in >>c;
148  s1.push_back(c);
149  }
150 
151  //std::cout << __LINE__ << "]\t" << mthn << "READ ROC name: " << s1 << std::endl;
152 
153  maskbits_.clear();
154 
155 
156  while (!in.eof()){
157 
158  //std::cout << __LINE__ << "]\t" << mthn << "read s1: " << s1 << std::endl;
159 
160  PixelROCName rocid(s1);
161 
162  //std::cout << __LINE__ << "]\t" << mthn << "read rocid: " << rocid << std::endl;
163 
165 
166  tmp.readBinary(rocid, in);
167 
168  maskbits_.push_back(tmp);
169 
170 
171  in.read(&nchar,1);
172 
173  s1.clear();
174 
175  if (in.eof()) continue;
176 
177  //std::cout << __LINE__ << "]\t" << mthn << "Will read: " << (int)nchar << " characters." <<std::endl;
178 
179  //wrote these lines of code without ref. needs to be fixed
180  for(int i=0;i< nchar; i++){
181  char c;
182  in >>c;
183  //std::cout << " " <<c;
184  s1.push_back(c);
185  }
186  //std::cout << std::endl;
187 
188 
189  }
190 
191  in.close();
192 
193 
194 
195  }
196 
197 
198  //std::cout << __LINE__ << "]\t" << mthn << "Read maskbits for " << maskbits_.size() << " ROCs" << std::endl;
199 
200  }
201 
202 //================================================================================================================
204 
205  return maskbits_[ROCId];
206 
207 }
208 
209 //================================================================================================================
211 
212  for(unsigned int i=0;i<maskbits_.size();i++){
213  if (maskbits_[i].name()==name) return &(maskbits_[i]);
214  }
215 
216  return 0;
217 
218 }
219 
220 //================================================================================================================
222 
223 
224  std::ofstream out(filename.c_str(),std::ios::binary);
225 
226  for(unsigned int i=0;i<maskbits_.size();i++){
227  maskbits_[i].writeBinary(out);
228  }
229 
230 
231 }
232 
233 //================================================================================================================
235 
236  if (dir!="") dir+="/";
237  PixelModuleName module(maskbits_[0].name().rocname());
238  std::string filename=dir+"ROC_Masks_module_"+module.modulename()+".dat";
239 
240  std::ofstream out(filename.c_str());
241 
242  for(unsigned int i=0;i<maskbits_.size();i++){
243  maskbits_[i].writeASCII(out);
244  }
245 
246 
247 }
248 
249 //=============================================================================================
251  int version,
252  std::string path,
253  std::ofstream *outstream,
254  std::ofstream *out1stream,
255  std::ofstream *out2stream) const
256 {
257  std::string mthn = "[PixelMaskAllPixels::writeXMLHeader()]\t\t\t " ;
258  std::stringstream maskFullPath ;
259 
260  maskFullPath << path << "/Pixel_RocMasks_" << PixelTimeFormatter::getmSecTime() << ".xml";
261  std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl ;
262 
263  outstream->open(maskFullPath.str().c_str()) ;
264 
265  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl ;
266  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl ;
267  *outstream << "" << std::endl ;
268  *outstream << " <HEADER>" << std::endl ;
269  *outstream << " <TYPE>" << std::endl ;
270  *outstream << " <EXTENSION_TABLE_NAME>ROC_MASKS</EXTENSION_TABLE_NAME>" << std::endl ;
271  *outstream << " <NAME>ROC Mask Bits</NAME>" << std::endl ;
272  *outstream << " </TYPE>" << std::endl ;
273  *outstream << " <RUN>" << std::endl ;
274  *outstream << " <RUN_TYPE>ROC Mask Bits</RUN_TYPE>" << std::endl ;
275  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl ;
276  *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
277  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl ;
278  *outstream << " </RUN>" << std::endl ;
279  *outstream << " </HEADER>" << std::endl ;
280  *outstream << "" << std::endl ;
281  *outstream << " <DATA_SET>" << std::endl ;
282  *outstream << "" << std::endl ;
283  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl ;
284  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl ;
285  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl ;
286  *outstream << "" << std::endl ;
287  *outstream << " <PART>" << std::endl ;
288  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl ;
289  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl ;
290  *outstream << " </PART>" << std::endl ;
291  *outstream << " " << std::endl ;
292 
293 }
294 //=============================================================================================
295 void PixelMaskAllPixels::writeXML( std::ofstream *outstream,
296  std::ofstream *out1stream,
297  std::ofstream *out2stream) const
298 {
299  std::string mthn = "[PixelMaskAllPixels::writeXML()]\t\t\t " ;
300 
301  for(unsigned int i=0;i<maskbits_.size();i++){
302  maskbits_[i].writeXML(outstream);
303  }
304 }
305 //=============================================================================================
306 void PixelMaskAllPixels::writeXMLTrailer(std::ofstream *outstream,
307  std::ofstream *out1stream,
308  std::ofstream *out2stream ) const
309 {
310  std::string mthn = "[PixelMaskAllPixels::writeXMLTrailer()]\t\t\t " ;
311 
312  *outstream << " " << std::endl ;
313  *outstream << " </DATA_SET>" << std::endl ;
314  *outstream << "</ROOT>" << std::endl ;
315 
316  outstream->close() ;
317  std::cout << __LINE__ << "]\t" << mthn << "Data written " << std::endl ;
318 
319 }
320 
virtual void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) const
int i
Definition: DBlmapReader.cc:9
int read(const PixelROCName &rocid, std::string in)
#define base64_decode(in, inlen, out, outlen)
Definition: base64.h:57
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
assert(m_qm.get())
static std::string getmSecTime(void)
This class implements..
const PixelROCMaskBits & getMaskBits(int ROCId) const
static std::string getTime(void)
void writeXML(pos::PixelConfigKey key, int version, std::string path) const
std::string getComment() const
This class provides utility methods to manipulate ASCII formatted timestamps.
tuple ins
Definition: cuy.py:312
std::string getAuthor() const
void writeBinary(std::string filename) const
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
This is the documentation about PixelMaskBase...
Definition: PixelMaskBase.h:36
This class implements..
std::string modulename() const
std::vector< PixelROCMaskBits > maskbits_
This class implements..
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
This class implements..
This class implements..
Definition: PixelROCName.h:23
tuple filename
Definition: lut2db_cfg.py:20
virtual void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) const
tuple cout
Definition: gather_cfg.py:145
dbl *** dir
Definition: mlp_gen.cc:35
void writeASCII(std::string dir) const
void addROCMaskBits(const PixelROCMaskBits &)
int readBinary(const PixelROCName &rocid, std::ifstream &in)