CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/CalibTracker/SiStripCommon/src/SiStripDetInfoFileReader.cc

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