00001
00002
00003
00004
00005
00006
00007
00008 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "FWCore/Utilities/interface/Exception.h"
00011
00012 using namespace cms;
00013 using namespace std;
00014
00015 SiStripDetInfoFileReader& SiStripDetInfoFileReader::operator=(const SiStripDetInfoFileReader ©) {
00016 detData_=copy.detData_;
00017 detIds_=copy.detIds_;
00018 return *this;
00019 }
00020
00021 SiStripDetInfoFileReader::SiStripDetInfoFileReader(const SiStripDetInfoFileReader& copy) {
00022 detData_=copy.detData_;
00023 detIds_=copy.detIds_;
00024 }
00025
00026 SiStripDetInfoFileReader::SiStripDetInfoFileReader(std::string filePath) {
00027
00028
00029
00030
00031
00032 detData_.clear();
00033 detIds_.clear();
00034
00035 inputFile_.open(filePath.c_str());
00036
00037 if (inputFile_.is_open()){
00038
00039 for(;;) {
00040
00041 uint32_t detid;
00042 double stripLength;
00043 unsigned short numberOfAPVs;
00044 float thickness;
00045
00046 inputFile_ >> detid >> numberOfAPVs >> stripLength >> thickness;
00047
00048 if (!(inputFile_.eof() || inputFile_.fail())){
00049
00050 detIds_.push_back(detid);
00051
00052
00053
00054
00055
00056
00057 std::map<uint32_t, DetInfo >::const_iterator it = detData_.find(detid);
00058
00059 if(it==detData_.end()){
00060 detData_[detid]=DetInfo(numberOfAPVs, stripLength,thickness);
00061 }
00062 else{
00063
00064 edm::LogError("SiStripDetInfoFileReader::SiStripDetInfoFileReader") <<"DetId " << detid << " already found on file. Ignoring new data"<<endl;
00065
00066 detIds_.pop_back();
00067 continue;
00068 }
00069 }
00070 else if (inputFile_.eof()){
00071
00072 edm::LogInfo("SiStripDetInfoFileReader::SiStripDetInfoFileReader - END of file reached")<<endl;
00073 break;
00074
00075 }
00076 else if (inputFile_.fail()) {
00077
00078 edm::LogError("SiStripDetInfoFileReader::SiStripDetInfoFileReader - ERROR while reading file")<<endl;
00079 break;
00080 }
00081 }
00082
00083 inputFile_.close();
00084
00085 }
00086 else {
00087
00088 edm::LogError("SiStripDetInfoFileReader::SiStripDetInfoFileReader - Unable to open file")<<endl;
00089 return;
00090
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 }
00102
00103
00104 SiStripDetInfoFileReader::~SiStripDetInfoFileReader(){
00105
00106 edm::LogInfo("SiStripDetInfoFileReader::~SiStripDetInfoFileReader");
00107 }
00108
00109
00110 const std::pair<unsigned short, double> SiStripDetInfoFileReader::getNumberOfApvsAndStripLength(uint32_t detId) const{
00111
00112 std::map<uint32_t, DetInfo >::const_iterator it = detData_.find(detId);
00113
00114 if(it!=detData_.end()){
00115
00116 return std::pair<unsigned short, double>(it->second.nApvs,it->second.stripLength);
00117
00118 }
00119 else{
00120
00121 static std::pair<unsigned short, double> defaultValue(0,0);
00122 edm::LogWarning("SiStripDetInfoFileReader::getNumberOfApvsAndStripLength - Unable to find requested detid. Returning invalid data ")<<endl;
00123 return defaultValue;
00124
00125 }
00126
00127 }
00128
00129 const float & SiStripDetInfoFileReader::getThickness(uint32_t detId) const{
00130
00131 std::map<uint32_t, DetInfo >::const_iterator it = detData_.find(detId);
00132
00133 if(it!=detData_.end()){
00134
00135 return it->second.thickness;
00136
00137 }
00138 else{
00139
00140 static float defaultValue=0;
00141 edm::LogWarning("SiStripDetInfoFileReader::getThickness - Unable to find requested detid. Returning invalid data ")<<endl;
00142 return defaultValue;
00143
00144 }
00145
00146 }
00147