CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CalibTracker/SiPixelESProducers/src/SiPixelDetInfoFileReader.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // Package:    SiPixelESProducers
00003 // Class:      SiPixelDetInfoFileReader
00004 // Original Author:  V.Chiochia
00005 //         Created:  Mon May 20 10:04:31 CET 2007
00006 // $Id: SiPixelDetInfoFileReader.cc,v 1.1 2007/08/08 16:22:30 chiochia Exp $
00007 
00008 #include "CalibTracker/SiPixelESProducers/interface/SiPixelDetInfoFileReader.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 
00017 SiPixelDetInfoFileReader::SiPixelDetInfoFileReader(std::string filePath) {
00018 
00019 //   if(filePath==std::string("")){
00020 //     filePath = edm::FileInPath(std::string("CalibTracker/SiPixelCommon/data/SiPixelDetInfo.dat") ).fullPath();
00021 //   }
00022 
00023   detData_.clear();
00024   detIds_.clear();
00025 
00026   inputFile_.open(filePath.c_str());
00027 
00028   if (inputFile_.is_open()){
00029 
00030     for(;;) {
00031 
00032       uint32_t detid;
00033       int ncols;
00034       int nrows;
00035 
00036       inputFile_ >> detid >> ncols  >> nrows ;
00037 
00038       if (!(inputFile_.eof() || inputFile_.fail())){
00039 
00040         detIds_.push_back(detid);
00041 
00042         //inputFile_ >> numberOfAPVs;
00043         //inputFile_ >> stripLength;
00044         
00045         //       edm::LogInfo("SiPixelDetInfoFileReader::SiPixelDetInfoFileReader") << detid <<" " <<numberOfAPVs <<" " <<stripLength << " "<< thickness<< endl;
00046         
00047         std::map<uint32_t, std::pair<int, int> >::const_iterator it = detData_.find(detid);
00048         
00049         if( it==detData_.end() ){
00050           
00051           detData_[detid]=pair<int, int>(ncols,nrows);
00052           
00053         }
00054         else{     
00055           edm::LogError("SiPixelDetInfoFileReader::SiPixelDetInfoFileReader") <<"DetId " << detid << " already found on file. Ignoring new data"<<endl;
00056           detIds_.pop_back();
00057           continue;
00058         }
00059       }
00060       else if (inputFile_.eof()){
00061         
00062         edm::LogInfo("SiPixelDetInfoFileReader::SiPixelDetInfoFileReader - END of file reached")<<endl;
00063         break;
00064         
00065       }
00066       else if (inputFile_.fail()) {
00067         
00068         edm::LogError("SiPixelDetInfoFileReader::SiPixelDetInfoFileReader - ERROR while reading file")<<endl;     
00069         break;
00070       }
00071     }
00072     
00073     inputFile_.close();
00074     
00075   }  
00076   else {
00077     
00078     edm::LogError("SiPixelDetInfoFileReader::SiPixelDetInfoFileReader - Unable to open file")<<endl;
00079     return;
00080     
00081   }
00082   
00083 
00084 //   int i=0;
00085 //   for(std::map<uint32_t, std::pair<unsigned short, double> >::iterator it =detData_.begin(); it!=detData_.end(); it++ ) {
00086 //     std::cout<< it->first << " " << (it->second).first << " " << (it->second).second<<endl;
00087 //     i++;
00088 //   }
00089 //   std::cout<<i;
00090 
00091 
00092 }
00093 //
00094 // Destructor
00095 //
00096 SiPixelDetInfoFileReader::~SiPixelDetInfoFileReader(){
00097 
00098    edm::LogInfo("SiPixelDetInfoFileReader::~SiPixelDetInfoFileReader");
00099 }
00100 //
00101 // get DetId's
00102 //
00103 const std::vector<uint32_t> & SiPixelDetInfoFileReader::getAllDetIds() const{
00104 
00105   return detIds_;
00106 
00107 }
00108 //
00109 // get method
00110 //
00111 const std::pair<int, int> & SiPixelDetInfoFileReader::getDetUnitDimensions(uint32_t detId) const{
00112 
00113   std::map<uint32_t, std::pair<int, int> >::const_iterator it = detData_.find(detId);
00114 
00115   if(it!=detData_.end()){
00116     
00117     return (*it).second; 
00118 
00119   }
00120   else{
00121 
00122     static std::pair< int, int> defaultValue(0,0);
00123     edm::LogWarning("SiPixelDetInfoFileReader::getDetUnitDimensions - Unable to find requested detid. Returning invalid data ")<<endl; 
00124     return defaultValue;
00125 
00126   }
00127 
00128 }
00129