Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:29

0001 //
0002 // This class provide an implementation for
0003 // pixel trim data where all pixels have the
0004 // same settings.
0005 //
0006 //
0007 // All applications should just use this
0008 // interface and not care about the specific
0009 // implementation
0010 //
0011 
0012 #include <iostream>
0013 #include <ios>
0014 #include "CalibFormats/SiPixelObjects/interface/PixelTrimCommon.h"
0015 #include "CalibFormats/SiPixelObjects/interface/PixelROCName.h"
0016 
0017 using namespace pos;
0018 
0019 PixelTrimCommon::PixelTrimCommon(std::string filename) : PixelTrimBase("", "", "") {
0020   if (filename[filename.size() - 1] == 't') {
0021     std::ifstream in(filename.c_str());
0022 
0023     std::string s1;
0024     in >> s1;
0025 
0026     trimbits_.clear();
0027 
0028     while (!in.eof()) {
0029       //std::cout << "PixelTrimCommon::PixelTrimCommon read s1:"<<s1<<std::endl;
0030 
0031       PixelROCName rocid(in);
0032 
0033       //std::cout << "PixelTrimCommon::PixelTrimCommon read rocid:"<<rocid<<std::endl;
0034 
0035       unsigned int trimbits;
0036 
0037       in >> trimbits;
0038 
0039       trimbits_.push_back(trimbits);
0040 
0041       in >> s1;
0042     }
0043 
0044     in.close();
0045 
0046   } else {
0047     std::ifstream in(filename.c_str(), std::ios::binary);
0048 
0049     char nchar;
0050 
0051     in.read(&nchar, 1);
0052 
0053     std::string s1;
0054 
0055     //wrote these lines of code without ref. needs to be fixed
0056     for (int i = 0; i < nchar; i++) {
0057       char c;
0058       in >> c;
0059       s1.push_back(c);
0060     }
0061 
0062     //std::cout << "READ ROC name:"<<s1<<std::endl;
0063 
0064     trimbits_.clear();
0065 
0066     while (!in.eof()) {
0067       //std::cout << "PixelTrimCommon::PixelTrimCommon read s1:"<<s1<<std::endl;
0068 
0069       PixelROCName rocid(s1);
0070 
0071       //std::cout << "PixelTrimCommon::PixelTrimCommon read rocid:"<<rocid<<std::endl;
0072 
0073       unsigned int trimbits;
0074 
0075       in >> trimbits;
0076 
0077       trimbits_.push_back(trimbits);
0078 
0079       in.read(&nchar, 1);
0080 
0081       s1.clear();
0082 
0083       if (in.eof())
0084         continue;
0085 
0086       //wrote these lines of code without ref. needs to be fixed
0087       for (int i = 0; i < nchar; i++) {
0088         char c;
0089         in >> c;
0090         s1.push_back(c);
0091       }
0092     }
0093 
0094     in.close();
0095   }
0096 
0097   //std::cout << "Read trimbits for "<<trimbits_.size()<<" ROCs"<<std::endl;
0098 }
0099 
0100 //std::string PixelTrimCommon::getConfigCommand(PixelMaskBase& pixelMask){
0101 //
0102 //  std::string s;
0103 //  return s;
0104 //
0105 //}
0106 
0107 //PixelROCTrimBits PixelTrimCommon::getTrimBits(int ROCId) const {
0108 //
0109 //  return trimbits_[ROCId];
0110 //
0111 //}
0112 
0113 void PixelTrimCommon::generateConfiguration(PixelFECConfigInterface* pixelFEC,
0114                                             PixelNameTranslation* trans,
0115                                             const PixelMaskBase& pixelMask) const {
0116   for (unsigned int i = 0; i < trimbits_.size(); i++) {
0117     std::vector<unsigned char> trimAndMasks(4160);
0118 
0119     const PixelROCMaskBits& maskbits = pixelMask.getMaskBits(i);
0120 
0121     for (unsigned int col = 0; col < 52; col++) {
0122       for (unsigned int row = 0; row < 80; row++) {
0123         unsigned char tmp = trimbits_[i];
0124         if (maskbits.mask(col, row) != 0)
0125           tmp |= 0x80;
0126         trimAndMasks[col * 80 + row] = tmp;
0127       }
0128     }
0129 
0130     pixelFEC->setMaskAndTrimAll(*(trans->getHdwAddress(rocname_[i])), trimAndMasks);
0131   }
0132 }
0133 
0134 void PixelTrimCommon::writeBinary(std::string filename) const {
0135   std::ofstream out(filename.c_str(), std::ios::binary);
0136 
0137   for (unsigned int i = 0; i < trimbits_.size(); i++) {
0138     assert(0);
0139     //trimbits_[i].writeBinary(out);
0140   }
0141 }
0142 
0143 void PixelTrimCommon::writeASCII(std::string filename) const {
0144   std::ofstream out(filename.c_str());
0145 
0146   for (unsigned int i = 0; i < trimbits_.size(); i++) {
0147     assert(0);
0148     //trimbits_[i].writeASCII(out);
0149   }
0150 }