Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:33

0001 // -*- C++ -*-
0002 // Package:    SiPixelESProducers
0003 // Class:      SiPixelDetInfoFileReader
0004 // Original Author:  V.Chiochia
0005 //         Created:  Mon May 20 10:04:31 CET 2007
0006 
0007 #include "CalibTracker/SiPixelESProducers/interface/SiPixelDetInfoFileReader.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 //#include "FWCore/ParameterSet/interface/FileInPath.h"
0011 
0012 using namespace cms;
0013 using namespace std;
0014 
0015 SiPixelDetInfoFileReader::SiPixelDetInfoFileReader(std::string filePath) {
0016   //   if(filePath==std::string("")){
0017   //     filePath = edm::FileInPath(std::string("CalibTracker/SiPixelCommon/data/SiPixelDetInfo.dat") ).fullPath();
0018   //   }
0019 
0020   detData_.clear();
0021   detIds_.clear();
0022 
0023   inputFile_.open(filePath.c_str());
0024 
0025   if (inputFile_.is_open()) {
0026     for (;;) {
0027       uint32_t detid;
0028       int ncols;
0029       int nrows;
0030 
0031       inputFile_ >> detid >> ncols >> nrows;
0032 
0033       if (!(inputFile_.eof() || inputFile_.fail())) {
0034         detIds_.push_back(detid);
0035 
0036         //inputFile_ >> numberOfAPVs;
0037         //inputFile_ >> stripLength;
0038 
0039         //       edm::LogInfo("SiPixelDetInfoFileReader::SiPixelDetInfoFileReader") << detid <<" " <<numberOfAPVs <<" " <<stripLength << " "<< thickness<< endl;
0040 
0041         std::map<uint32_t, std::pair<int, int> >::const_iterator it = detData_.find(detid);
0042 
0043         if (it == detData_.end()) {
0044           detData_[detid] = pair<int, int>(ncols, nrows);
0045 
0046         } else {
0047           edm::LogError("SiPixelDetInfoFileReader::SiPixelDetInfoFileReader")
0048               << "DetId " << detid << " already found on file. Ignoring new data" << endl;
0049           detIds_.pop_back();
0050           continue;
0051         }
0052       } else if (inputFile_.eof()) {
0053         edm::LogInfo("SiPixelDetInfoFileReader::SiPixelDetInfoFileReader - END of file reached") << endl;
0054         break;
0055 
0056       } else if (inputFile_.fail()) {
0057         edm::LogError("SiPixelDetInfoFileReader::SiPixelDetInfoFileReader - ERROR while reading file") << endl;
0058         break;
0059       }
0060     }
0061 
0062     inputFile_.close();
0063 
0064   } else {
0065     edm::LogError("SiPixelDetInfoFileReader::SiPixelDetInfoFileReader - Unable to open file") << endl;
0066     return;
0067   }
0068 
0069   //   int i=0;
0070   //   for(std::map<uint32_t, std::pair<unsigned short, double> >::iterator it =detData_.begin(); it!=detData_.end(); it++ ) {
0071   //     std::cout<< it->first << " " << (it->second).first << " " << (it->second).second<<endl;
0072   //     i++;
0073   //   }
0074   //   std::cout<<i;
0075 }
0076 //
0077 // Destructor
0078 //
0079 SiPixelDetInfoFileReader::~SiPixelDetInfoFileReader() {
0080   edm::LogInfo("SiPixelDetInfoFileReader::~SiPixelDetInfoFileReader");
0081 }
0082 //
0083 // get DetId's
0084 //
0085 const std::vector<uint32_t>& SiPixelDetInfoFileReader::getAllDetIds() const { return detIds_; }
0086 //
0087 // get method
0088 //
0089 const std::pair<int, int>& SiPixelDetInfoFileReader::getDetUnitDimensions(uint32_t detId) const {
0090   std::map<uint32_t, std::pair<int, int> >::const_iterator it = detData_.find(detId);
0091 
0092   if (it != detData_.end()) {
0093     return (*it).second;
0094 
0095   } else {
0096     static const std::pair<int, int> defaultValue(0, 0);
0097     edm::LogWarning(
0098         "SiPixelDetInfoFileReader::getDetUnitDimensions - Unable to find requested detid. Returning invalid data ")
0099         << endl;
0100     return defaultValue;
0101   }
0102 }