00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <sstream>
00015 #include <iostream>
00016 #include <ios>
00017 #include <assert.h>
00018 #include "CalibFormats/SiPixelObjects/interface/PixelTrimAllPixels.h"
00019
00020 using namespace pos;
00021
00022 PixelTrimAllPixels::PixelTrimAllPixels( std::vector <std::vector<std::string> >& tableMat):
00023 PixelTrimBase("","","")
00024 {
00025
00026 std::stringstream currentRocName;
00027 std::map<std::string , int > colM;
00028 std::vector<std::string > colNames;
00047 colNames.push_back("CONFIG_KEY_ID" );
00048 colNames.push_back("CONFG_KEY" );
00049 colNames.push_back("VERSION" );
00050 colNames.push_back("KIND_OF_COND" );
00051 colNames.push_back("ROC_NAME" );
00052 colNames.push_back("HUB_ADDRS" );
00053 colNames.push_back("PORT_NUMBER" );
00054 colNames.push_back("ROC_I2C_ADDR" );
00055 colNames.push_back("GEOM_ROC_NUM" );
00056 colNames.push_back("DATA_FILE" );
00057 colNames.push_back("TRIM_CLOB" );
00058
00059
00060 for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
00061 {
00062 for(unsigned int n=0; n<colNames.size(); n++)
00063 {
00064 if(tableMat[0][c] == colNames[n])
00065 {
00066 colM[colNames[n]] = c;
00067 break;
00068 }
00069 }
00070 }
00071 for(unsigned int n=0; n<colNames.size(); n++)
00072 {
00073 if(colM.find(colNames[n]) == colM.end())
00074 {
00075 std::cerr << "[PixelTrimAllPixels::PixelTrimAllPixels()]\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
00076 assert(0);
00077 }
00078 }
00079
00080
00081
00082 std::string bits;
00083
00084 for(unsigned int r = 1 ; r < tableMat.size() ; r++)
00085 {
00086 PixelROCName rocid( tableMat[r][colM["ROC_NAME"]] );
00087
00088
00089
00090 PixelROCTrimBits tmp;
00091 std::istringstream istring ;
00092 istring.str(tableMat[r][colM["TRIM_CLOB"]]) ;
00093 tmp.read(rocid, istring) ;
00094
00095
00096
00097
00098 trimbits_.push_back(tmp);
00099
00100
00101
00102 }
00103
00104 }
00105
00106
00107 PixelTrimAllPixels::PixelTrimAllPixels(std::string filename):
00108 PixelTrimBase("","",""){
00109
00110 if (filename[filename.size()-1]=='t'){
00111
00112 std::ifstream in(filename.c_str());
00113
00114
00115
00116 std::string s1;
00117 in >> s1;
00118
00119 trimbits_.clear();
00120
00121
00122 while (in.good()){
00123
00124 std::string s2;
00125 in>>s2;
00126
00127
00128
00129 assert( s1 == "ROC:" );
00130
00131 PixelROCName rocid(s2);
00132
00133
00134
00135 PixelROCTrimBits tmp;
00136
00137 tmp.read(rocid, in);
00138
00139 trimbits_.push_back(tmp);
00140
00141 in >> s1;
00142
00143 }
00144
00145 in.close();
00146
00147 }
00148 else{
00149
00150 std::ifstream in(filename.c_str(),std::ios::binary);
00151
00152 char nchar;
00153
00154 in.read(&nchar,1);
00155
00156 std::string s1;
00157
00158
00159 for(int i=0;i< nchar; i++){
00160 char c;
00161 in >>c;
00162 s1.push_back(c);
00163 }
00164
00165
00166
00167 trimbits_.clear();
00168
00169
00170 while (!in.eof()){
00171
00172
00173
00174 PixelROCName rocid(s1);
00175
00176
00177
00178 PixelROCTrimBits tmp;
00179
00180 tmp.readBinary(rocid, in);
00181
00182 trimbits_.push_back(tmp);
00183
00184
00185 in.read(&nchar,1);
00186
00187 s1.clear();
00188
00189 if (in.eof()) continue;
00190
00191
00192 for(int i=0;i< nchar; i++){
00193 char c;
00194 in >>c;
00195 s1.push_back(c);
00196 }
00197
00198
00199 }
00200
00201 in.close();
00202
00203
00204
00205 }
00206
00207
00208
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 PixelROCTrimBits PixelTrimAllPixels::getTrimBits(int ROCId) const {
00220
00221 return trimbits_[ROCId];
00222
00223 }
00224
00225 PixelROCTrimBits* PixelTrimAllPixels::getTrimBits(PixelROCName name){
00226
00227 for(unsigned int i=0;i<trimbits_.size();i++){
00228 if (trimbits_[i].name()==name) return &(trimbits_[i]);
00229 }
00230
00231 return 0;
00232
00233 }
00234
00235
00236
00237 void PixelTrimAllPixels::generateConfiguration(PixelFECConfigInterface* pixelFEC,
00238 PixelNameTranslation* trans,
00239 const PixelMaskBase& pixelMask) const{
00240
00241 for(unsigned int i=0;i<trimbits_.size();i++){
00242
00243 std::vector<unsigned char> trimAndMasks(4160);
00244
00245 const PixelROCMaskBits& maskbits=pixelMask.getMaskBits(i);
00246
00247 for (unsigned int col=0;col<52;col++){
00248 for (unsigned int row=0;row<80;row++){
00249 unsigned char tmp=trimbits_[i].trim(col,row);
00250 if (maskbits.mask(col,row)!=0) tmp|=0x80;
00251 trimAndMasks[col*80+row]=tmp;
00252 }
00253 }
00254
00255
00256
00257
00258 const PixelHdwAddress* theROC = trans->getHdwAddress(trimbits_[i].name());
00259 pixelFEC->roctrimload(theROC->mfec(),
00260 theROC->mfecchannel(),
00261 theROC->hubaddress(),
00262 theROC->portaddress(),
00263 theROC->rocid(),
00264 trimAndMasks);
00265 }
00266 }
00267
00268 void PixelTrimAllPixels::writeBinary(std::string filename) const{
00269
00270
00271 std::ofstream out(filename.c_str(),std::ios::binary);
00272
00273 for(unsigned int i=0;i<trimbits_.size();i++){
00274 trimbits_[i].writeBinary(out);
00275 }
00276
00277
00278 }
00279
00280
00281 void PixelTrimAllPixels::writeASCII(std::string dir) const{
00282
00283 if (dir!="") dir+="/";
00284 PixelModuleName module(trimbits_[0].name().rocname());
00285 std::string filename=dir+"ROC_Trims_module_"+module.modulename()+".dat";
00286
00287
00288 std::ofstream out(filename.c_str());
00289
00290 for(unsigned int i=0;i<trimbits_.size();i++){
00291 trimbits_[i].writeASCII(out);
00292 }
00293
00294
00295 }