CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CalibTracker/SiStripCommon/src/SiStripFedIdListReader.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripCommon/interface/SiStripFedIdListReader.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include <algorithm>
00004 #include <sstream>
00005 
00006 // -----------------------------------------------------------------------------
00007 //
00008 SiStripFedIdListReader::SiStripFedIdListReader( std::string filePath ) {
00009   fedIds_.clear();
00010   inputFile_.open( filePath.c_str() );
00011 
00012   if ( inputFile_.is_open() ) {
00013     
00014     for(;;) {
00015       
00016       uint32_t fed_id; 
00017       inputFile_ >> fed_id;
00018 
00019       if ( !( inputFile_.eof() || inputFile_.fail() ) ) {
00020         
00021         std::vector<uint16_t>::const_iterator it = find( fedIds_.begin(), fedIds_.end(), fed_id );
00022         if( it == fedIds_.end() ) { fedIds_.push_back(fed_id); }
00023         else {
00024           edm::LogWarning("Unknown") 
00025             << "[SiStripFedIdListReader::" << __func__ << "]"
00026             << " FedId " << fed_id << " has already been found in file!" << std::endl;
00027           continue;
00028         }
00029 
00030       } else if ( inputFile_.eof() ) {
00031         edm::LogVerbatim("Unknown") 
00032           << "[SiStripFedIdListReader::" << __func__ << "]"
00033           << " End of file reached! Found " << fedIds_.size() 
00034           << " valid FedIds!" << std::endl;
00035         break;
00036       } else if ( inputFile_.fail() ) {
00037         edm::LogVerbatim("Unknown") 
00038           << "[SiStripFedIdListReader::" << __func__ << "]"
00039           << " Error while reading file \"" << filePath << "\"!" << std::endl;
00040         break;
00041       }
00042     }
00043 
00044     inputFile_.close();
00045   } else {
00046     edm::LogVerbatim("Unknown") 
00047       << "[SiStripFedIdListReader::" << __func__ << "]"
00048       << " Unable to open file \"" << filePath << "\"!" << std::endl;
00049     return;
00050     
00051   }
00052 
00053 }
00054 
00055 // -----------------------------------------------------------------------------
00056 //
00057 SiStripFedIdListReader::SiStripFedIdListReader( const SiStripFedIdListReader& copy ) {
00058   edm::LogVerbatim("Unknown") 
00059     << "[SiStripFedIdListReader::" << __func__ << "]";
00060   fedIds_ = copy.fedIds_;
00061 }
00062 
00063 // -----------------------------------------------------------------------------
00064 //
00065 SiStripFedIdListReader& SiStripFedIdListReader::operator=( const SiStripFedIdListReader& copy ) {
00066   edm::LogVerbatim("Unknown") 
00067     << "[SiStripFedIdListReader::" << __func__ << "]";
00068   fedIds_ = copy.fedIds_;
00069   return *this;  
00070 }
00071 
00072 // -----------------------------------------------------------------------------
00073 //
00074 SiStripFedIdListReader::~SiStripFedIdListReader(){
00075   edm::LogVerbatim("Unknown") 
00076     << "[SiStripFedIdListReader::" << __func__ << "]";
00077 }
00078 
00079 
00080 // -----------------------------------------------------------------------------
00081 //
00082 std::ostream& operator<< ( std::ostream& os, const SiStripFedIdListReader& in ) {
00083   std::vector<uint16_t> fed_ids = in.fedIds();
00084   std::stringstream ss;
00085   ss << "[SiStripFedIdListReader::" << __func__ << "]"
00086      << " Found " << fed_ids.size() << " valid FED ids with values: ";
00087   std::vector<uint16_t>::const_iterator iter = fed_ids.begin();
00088   for ( ; iter != fed_ids.end(); ++iter ) { ss << *iter << " "; }
00089   os << ss.str();
00090   return os;
00091 }
00092