File indexing completed on 2024-04-06 11:59:33
0001
0002
0003
0004
0005
0006
0007 #include "CalibTracker/SiPixelESProducers/interface/SiPixelDetInfoFileReader.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010
0011
0012 using namespace cms;
0013 using namespace std;
0014
0015 SiPixelDetInfoFileReader::SiPixelDetInfoFileReader(std::string filePath) {
0016
0017
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
0037
0038
0039
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
0070
0071
0072
0073
0074
0075 }
0076
0077
0078
0079 SiPixelDetInfoFileReader::~SiPixelDetInfoFileReader() {
0080 edm::LogInfo("SiPixelDetInfoFileReader::~SiPixelDetInfoFileReader");
0081 }
0082
0083
0084
0085 const std::vector<uint32_t>& SiPixelDetInfoFileReader::getAllDetIds() const { return detIds_; }
0086
0087
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 }