Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-05 04:09:21

0001 // -*- C++ -*-
0002 // Package:    SiStripCommon
0003 // Class:      SiStripDetInfoFileReader
0004 // Original Author:  G. Bruno
0005 //         Created:  Mon May 20 10:04:31 CET 2007
0006 
0007 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include <fstream>
0010 
0011 SiStripDetInfo SiStripDetInfoFileReader::read(std::string filePath) {
0012   edm::LogInfo("SiStripDetInfoFileReader") << "filePath " << filePath;
0013 
0014   std::map<uint32_t, DetInfo> detData_;
0015   std::vector<uint32_t> detIds_;
0016 
0017   std::ifstream inputFile;
0018   inputFile.open(filePath.c_str());
0019 
0020   if (inputFile.is_open()) {
0021     for (;;) {
0022       uint32_t detid;
0023       double stripLength;
0024       unsigned short numberOfAPVs;
0025       float thickness;
0026 
0027       inputFile >> detid >> numberOfAPVs >> stripLength >> thickness;
0028 
0029       if (!(inputFile.eof() || inputFile.fail())) {
0030         detIds_.push_back(detid);
0031 
0032         //  inputFile >> numberOfAPVs;
0033         //  inputFile >> stripLength;
0034 
0035         //      edm::LogInfo("SiStripDetInfoFileReader::SiStripDetInfoFileReader") << detid <<" " <<numberOfAPVs <<" " <<stripLength << " "<< thickness<< endl;
0036 
0037         if (detData_.find(detid) == detData_.end()) {
0038           detData_[detid] = DetInfo(numberOfAPVs, stripLength, thickness);
0039         } else {
0040           edm::LogError("SiStripDetInfoFileReader::SiStripDetInfoFileReader")
0041               << "DetId " << detid << " already found on file. Ignoring new data";
0042 
0043           detIds_.pop_back();
0044           continue;
0045         }
0046       } else if (inputFile.eof()) {
0047         edm::LogInfo("SiStripDetInfoFileReader::SiStripDetInfoFileReader - END of file reached");
0048         break;
0049 
0050       } else if (inputFile.fail()) {
0051         edm::LogError("SiStripDetInfoFileReader::SiStripDetInfoFileReader - ERROR while reading file");
0052         break;
0053       }
0054     }
0055     inputFile.close();
0056   } else {
0057     edm::LogError("SiStripDetInfoFileReader::SiStripDetInfoFileReader - Unable to open file");
0058     return SiStripDetInfo();
0059   }
0060 
0061   return SiStripDetInfo(std::move(detData_), std::move(detIds_));
0062 }