CMS 3D CMS Logo

PixelROCMaskBits.cc
Go to the documentation of this file.
1 //
2 // This class provide the data structure for the
3 // ROC DAC parameters
4 //
5 // At this point I do not see a reason to make an
6 // abstract layer for this code.
7 //
8 
11 #include <iostream>
12 #include <cassert>
13 #include <typeinfo>
14 
15 using namespace pos;
16 
17 //=====================================================================/
19 
20 /**********************Start Modification******************************/
22  std::string mthn = "[PixelROCMaskBits::setROCMaskBits()]\t\t\t ";
23  rocid_ = rocid;
24  char cpt[520];
25  bits.copy(cpt, 520);
26  for (unsigned int i = 0; i < bits.size(); i++) {
27  bits_[i] = static_cast<unsigned char>(cpt[i]);
28  // std::cout<< "bits_[" << i << "]\t" << bits_[i] <<std::endl;
29  // std::cout<<rocid_<<std::endl;
30  // std::cout.flags(std::ios::hex)
31  }
32 }
33 /**********************End Modification******************************/
34 
35 // Added by Dario: handles the base_64-decoded strings from aDB read
37  rocid_ = rocid;
38  for (int i = 0; i < (int)sizeof(bits_); i++) {
39  bits_[i] = in.at(i);
40  }
41  return 1;
42 }
43 
44 //=====================================================================/
45 int PixelROCMaskBits::read(const PixelROCName& rocid, std::ifstream& in) {
46  rocid_ = rocid;
47 
49 
50  for (int i = 0; i < 52; i++) {
51  in >> tag;
52 
53  //std::cout << "Now reading col:"<<tag<<std::endl;
54 
56 
57  in >> data;
58 
59  //std::cout <<"data.size()" <<data.size()<<std::endl;
60 
61  unsigned char byte = 0;
62 
63  for (int j = 0; j < 80; j++) {
64  if (data[j] == '1')
65  byte += 128;
66 
67  if ((j + 1) % 8 == 0) {
68  //std::cout << "Writing byte:"<<(int)byte<<std::endl;
69  bits_[i * 10 + (j + 1) / 8 - 1] = byte;
70  byte = 0;
71  } else {
72  byte /= 2;
73  }
74  }
75  }
76 
77  return 1;
78 }
79 
80 //=====================================================================/
81 // modified by MR on 23-06-2008 11:57:58
82 int PixelROCMaskBits::read(const PixelROCName& rocid, std::istringstream& in) {
83  rocid_ = rocid;
85  for (int i = 0; i < 52; i++) {
86  in >> tag;
87  //std::cout << "Now reading col:"<<tag<<std::endl;
89  in >> data;
90  //std::cout <<"data.size()" <<data.size()<<std::endl;
91  unsigned char byte = 0;
92  for (int j = 0; j < 80; j++) {
93  if (data[j] == '1')
94  byte += 128;
95  if ((j + 1) % 8 == 0) {
96  //std::cout << "Writing byte:"<<(int)byte<<std::endl;
97  bits_[i * 10 + (j + 1) / 8 - 1] = byte;
98  byte = 0;
99  } else {
100  byte /= 2;
101  }
102  }
103  }
104  return 1;
105 }
106 
107 //=====================================================================/
108 int PixelROCMaskBits::readBinary(const PixelROCName& rocid, std::ifstream& in) {
109  rocid_ = rocid;
110 
111  in.read((char*)bits_, 520);
112 
113  return 1;
114 }
115 
116 //=====================================================================/
117 void PixelROCMaskBits::writeBinary(std::ofstream& out) const {
118  out << (char)rocid_.rocname().size();
119  out.write(rocid_.rocname().c_str(), rocid_.rocname().size());
120 
121  for (unsigned int i = 0; i < 520; i++) {
122  out << bits_[i];
123  }
124 }
125 
126 //=====================================================================/
127 void PixelROCMaskBits::writeASCII(std::ofstream& out) const {
128  out << "ROC: " << rocid_.rocname() << std::endl;
129 
130  for (unsigned int col = 0; col < 52; col++) {
131  out << "col";
132  if (col < 10)
133  out << "0";
134  out << col << ": ";
135  for (int row = 0; row < 80; row++) {
136  out << mask(col, row);
137  }
138  out << std::endl;
139  }
140 }
141 
142 //=====================================================================/
143 unsigned int PixelROCMaskBits::mask(unsigned int col, unsigned int row) const {
144  unsigned int tmp = bits_[col * 10 + row / 8];
145  // std::cout << "c = " << col << "\tr = " << row << "\tbits_[" << (col*10+row/8) << "]=" << bits_[col*10+row/8] << std::endl ;
146  // std::cout << "[PixelROCMaskBits::mask()] tmp iniziale " << tmp << std::endl ;
147  tmp = tmp >> (row % 8);
148  // std::cout << "[PixelROCMaskBits::mask()] tmp finale " << tmp << std::endl ;
149  // unsigned int res = tmp&0x01 ;
150  // std::cout << "[PixelROCMaskBits::mask()] return value " << res << std::endl ;
151  return tmp & 0x01;
152 }
153 
154 //=====================================================================/
155 void PixelROCMaskBits::setMask(unsigned int col, unsigned int row, unsigned int mask) {
156  assert(mask == 0 || mask == 1);
157 
158  unsigned int bit = 1 << (row % 8);
159  if (mask)
160  bits_[col * 10 + row / 8] = bits_[col * 10 + row / 8] | bit;
161  if (!mask)
162  bits_[col * 10 + row / 8] = bits_[col * 10 + row / 8] & (0xff ^ bit);
163 }
164 
165 //=====================================================================/
166 std::ostream& pos::operator<<(std::ostream& s, const PixelROCMaskBits& mask) {
167  s << "Dumping ROC masks" << std::endl;
168 
169  for (int i = 0; i < 52; i++) {
170  s << "Col" << i << ":";
171  for (int j = 0; j < 10; j++) {
172  unsigned char bitmask = 1;
173  for (int k = 0; k < 8; k++) {
174  if (mask.bits_[i * 10 + j] & bitmask) {
175  s << "1";
176  } else {
177  s << "0";
178  }
179  bitmask *= 2;
180  }
181  }
182  s << std::endl;
183  }
184 
185  return s;
186 }
187 
188 //=============================================================================================
189 void PixelROCMaskBits::writeXML(std::ofstream* out) const {
190  std::string mthn = "[PixelROCMaskBits::writeXML()]\t\t\t\t";
191 
192  std::string encoded = base64_encode(bits_, sizeof(bits_));
193 
194  *out << " <DATA>" << std::endl;
195  *out << " <ROC_NAME>" << rocid_.rocname() << "</ROC_NAME>" << std::endl;
196  *out << " <KILL_MASK>" << encoded << "</KILL_MASK>" << std::endl;
197  *out << " </DATA>" << std::endl;
198  *out << " " << std::endl;
199 }
void setROCMaskBits(PixelROCName &rocid, std::string bits)
int read(const PixelROCName &rocid, std::string in)
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
std::string rocname() const
std::ostream & operator<<(std::ostream &s, const PixelCalibConfiguration &calib)
std::string base64_encode(unsigned char const *, unsigned int len)
Definition: PixelBase64.cc:38
void writeASCII(std::ofstream &out) const
void setMask(unsigned int col, unsigned int row, unsigned int mask)
This class implements..
This class implements..
This class implements..
Definition: PixelROCName.h:23
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
unsigned char bits_[520]
unsigned int mask(unsigned int col, unsigned int row) const
col
Definition: cuy.py:1010
void writeXML(std::ofstream *out) const
tmp
align.sh
Definition: createJobs.py:716
void writeBinary(std::ofstream &out) const
int readBinary(const PixelROCName &rocid, std::ifstream &in)