00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "CalibFormats/SiPixelObjects/interface/PixelROCMaskBits.h"
00010 #include <iostream>
00011 #include <assert.h>
00012
00013
00014 using namespace pos;
00015
00016 PixelROCMaskBits::PixelROCMaskBits(){
00017 }
00018
00019
00020
00021 void PixelROCMaskBits::setROCMaskBits(PixelROCName& rocid ,std::string bits)
00022 {
00023 try
00024 {
00025 rocid_=rocid;
00026 char cpt[520] ;
00027 bits.copy( cpt , 520);
00028 for(unsigned int i = 0 ; i < bits.size(); i++)
00029 {
00030 bits_[i] = (unsigned char)cpt[i];
00031
00032
00033
00034 }
00035 }
00036 catch(std::bad_cast)
00037 {
00038 std::cout << "Error casting variable." << std::endl;
00039 }
00040 }
00041
00042
00043
00044
00045 int PixelROCMaskBits::read(const PixelROCName& rocid, std::ifstream& in){
00046
00047 rocid_=rocid;
00048
00049 std::string tag;
00050
00051 for (int i=0;i<52;i++){
00052
00053 in >> tag;
00054
00055
00056
00057 std::string data;
00058
00059 in >> data;
00060
00061
00062
00063 unsigned char byte=0;
00064
00065 for(int j=0;j<80;j++){
00066
00067 if (data[j]=='1') byte+=128;
00068
00069 if ((j+1)%8==0) {
00070
00071 bits_[i*10+(j+1)/8-1]=byte;
00072 byte=0;
00073 }
00074 else{
00075 byte/=2;
00076 }
00077
00078
00079 }
00080
00081 }
00082
00083 return 1;
00084
00085 }
00086
00087
00088 int PixelROCMaskBits::read(const PixelROCName& rocid, std::istringstream& in)
00089 {
00090 rocid_=rocid;
00091 std::string tag;
00092 for (int i=0;i<52;i++)
00093 {
00094 in >> tag;
00095
00096 std::string data;
00097 in >> data;
00098
00099 unsigned char byte=0;
00100 for(int j=0;j<80;j++)
00101 {
00102 if (data[j]=='1') byte+=128;
00103 if ((j+1)%8==0)
00104 {
00105
00106 bits_[i*10+(j+1)/8-1]=byte;
00107 byte=0;
00108 }
00109 else
00110 {
00111 byte/=2;
00112 }
00113 }
00114 }
00115 return 1;
00116 }
00117
00118 int PixelROCMaskBits::readBinary(const PixelROCName& rocid, std::ifstream& in){
00119
00120 rocid_=rocid;
00121
00122
00123 in.read((char*)bits_,520);
00124
00125
00126 return 1;
00127 }
00128
00129
00130
00131 void PixelROCMaskBits::writeBinary(std::ofstream& out) const{
00132
00133 out << (char)rocid_.rocname().size();
00134 out.write(rocid_.rocname().c_str(),rocid_.rocname().size());
00135
00136 for(unsigned int i=0;i<520;i++){
00137 out << bits_[i];
00138 }
00139
00140 }
00141
00142
00143 void PixelROCMaskBits::writeASCII(std::ofstream& out) const{
00144
00145 out << "ROC: "<<rocid_.rocname()<<std::endl;
00146
00147 for(unsigned int col=0;col<52;col++){
00148 out << "col";
00149 if (col<10) out << "0";
00150 out <<col<<": ";
00151 for (int row=0;row<80;row++){
00152 out << mask(col,row);
00153 }
00154 out << std::endl;
00155 }
00156
00157 }
00158
00159 unsigned int PixelROCMaskBits::mask(unsigned int col, unsigned int row) const{
00160
00161 unsigned int tmp=bits_[col*10+row/8];
00162
00163
00164 tmp=tmp>>(row%8);
00165
00166
00167
00168 return tmp&0x01;
00169
00170 }
00171
00172 void PixelROCMaskBits::setMask(unsigned int col, unsigned int row, unsigned int mask){
00173
00174 assert(mask==0||mask==1);
00175
00176 unsigned int bit=1<<(row%8);
00177 if (mask) bits_[col*10+row/8]=bits_[col*10+row/8]|bit;
00178 if (!mask) bits_[col*10+row/8]=bits_[col*10+row/8]&(0xff^bit);
00179
00180 }
00181
00182
00183 std::ostream& pos::operator<<(std::ostream& s, const PixelROCMaskBits& mask){
00184
00185 s << "Dumping ROC masks" <<std::endl;
00186
00187 for(int i=0;i<52;i++){
00188 s<<"Col"<<i<<":";
00189 for(int j=0;j<10;j++){
00190 unsigned char bitmask=1;
00191 for(int k=0;k<8;k++){
00192 if(mask.bits_[i*10+j]&bitmask) {
00193 s << "1";
00194 }
00195 else{
00196 s << "0";
00197 }
00198 bitmask*=2;
00199 }
00200 }
00201 s<<std::endl;
00202 }
00203
00204
00205 return s;
00206
00207 }
00208
00209