Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:14:47

0001 #include "CalibTracker/SiStripCommon/interface/SiStripFedIdListReader.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include <algorithm>
0004 #include <sstream>
0005 
0006 // -----------------------------------------------------------------------------
0007 //
0008 SiStripFedIdListReader::SiStripFedIdListReader(std::string filePath) {
0009   fedIds_.clear();
0010   inputFile_.open(filePath.c_str());
0011 
0012   if (inputFile_.is_open()) {
0013     for (;;) {
0014       uint32_t fed_id;
0015       inputFile_ >> fed_id;
0016 
0017       if (!(inputFile_.eof() || inputFile_.fail())) {
0018         std::vector<uint16_t>::const_iterator it = find(fedIds_.begin(), fedIds_.end(), fed_id);
0019         if (it == fedIds_.end()) {
0020           fedIds_.push_back(fed_id);
0021         } else {
0022           edm::LogWarning("Unknown") << "[SiStripFedIdListReader::" << __func__ << "]"
0023                                      << " FedId " << fed_id << " has already been found in file!" << std::endl;
0024           continue;
0025         }
0026 
0027       } else if (inputFile_.eof()) {
0028         edm::LogVerbatim("Unknown") << "[SiStripFedIdListReader::" << __func__ << "]"
0029                                     << " End of file reached! Found " << fedIds_.size() << " valid FedIds!"
0030                                     << std::endl;
0031         break;
0032       } else if (inputFile_.fail()) {
0033         edm::LogVerbatim("Unknown") << "[SiStripFedIdListReader::" << __func__ << "]"
0034                                     << " Error while reading file \"" << filePath << "\"!" << std::endl;
0035         break;
0036       }
0037     }
0038 
0039     inputFile_.close();
0040   } else {
0041     edm::LogVerbatim("Unknown") << "[SiStripFedIdListReader::" << __func__ << "]"
0042                                 << " Unable to open file \"" << filePath << "\"!" << std::endl;
0043     return;
0044   }
0045 }
0046 
0047 // -----------------------------------------------------------------------------
0048 //
0049 SiStripFedIdListReader::SiStripFedIdListReader(const SiStripFedIdListReader& copy) {
0050   edm::LogVerbatim("Unknown") << "[SiStripFedIdListReader::" << __func__ << "]";
0051   fedIds_ = copy.fedIds_;
0052 }
0053 
0054 // -----------------------------------------------------------------------------
0055 //
0056 SiStripFedIdListReader& SiStripFedIdListReader::operator=(const SiStripFedIdListReader& copy) {
0057   edm::LogVerbatim("Unknown") << "[SiStripFedIdListReader::" << __func__ << "]";
0058   fedIds_ = copy.fedIds_;
0059   return *this;
0060 }
0061 
0062 // -----------------------------------------------------------------------------
0063 //
0064 SiStripFedIdListReader::~SiStripFedIdListReader() {
0065   edm::LogVerbatim("Unknown") << "[SiStripFedIdListReader::" << __func__ << "]";
0066 }
0067 
0068 // -----------------------------------------------------------------------------
0069 //
0070 std::ostream& operator<<(std::ostream& os, const SiStripFedIdListReader& in) {
0071   std::vector<uint16_t> fed_ids = in.fedIds();
0072   std::stringstream ss;
0073   ss << "[SiStripFedIdListReader::" << __func__ << "]"
0074      << " Found " << fed_ids.size() << " valid FED ids with values: ";
0075   std::vector<uint16_t>::const_iterator iter = fed_ids.begin();
0076   for (; iter != fed_ids.end(); ++iter) {
0077     ss << *iter << " ";
0078   }
0079   os << ss.str();
0080   return os;
0081 }