CMS 3D CMS Logo

SiPixelDetInfoFileReader.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Package: SiPixelESProducers
3 // Class: SiPixelDetInfoFileReader
4 // Original Author: V.Chiochia
5 // Created: Mon May 20 10:04:31 CET 2007
6 
10 //#include "FWCore/ParameterSet/interface/FileInPath.h"
11 
12 using namespace cms;
13 using namespace std;
14 
15 
17 
18 // if(filePath==std::string("")){
19 // filePath = edm::FileInPath(std::string("CalibTracker/SiPixelCommon/data/SiPixelDetInfo.dat") ).fullPath();
20 // }
21 
22  detData_.clear();
23  detIds_.clear();
24 
25  inputFile_.open(filePath.c_str());
26 
27  if (inputFile_.is_open()){
28 
29  for(;;) {
30 
31  uint32_t detid;
32  int ncols;
33  int nrows;
34 
35  inputFile_ >> detid >> ncols >> nrows ;
36 
37  if (!(inputFile_.eof() || inputFile_.fail())){
38 
39  detIds_.push_back(detid);
40 
41  //inputFile_ >> numberOfAPVs;
42  //inputFile_ >> stripLength;
43 
44  // edm::LogInfo("SiPixelDetInfoFileReader::SiPixelDetInfoFileReader") << detid <<" " <<numberOfAPVs <<" " <<stripLength << " "<< thickness<< endl;
45 
46  std::map<uint32_t, std::pair<int, int> >::const_iterator it = detData_.find(detid);
47 
48  if( it==detData_.end() ){
49 
50  detData_[detid]=pair<int, int>(ncols,nrows);
51 
52  }
53  else{
54  edm::LogError("SiPixelDetInfoFileReader::SiPixelDetInfoFileReader") <<"DetId " << detid << " already found on file. Ignoring new data"<<endl;
55  detIds_.pop_back();
56  continue;
57  }
58  }
59  else if (inputFile_.eof()){
60 
61  edm::LogInfo("SiPixelDetInfoFileReader::SiPixelDetInfoFileReader - END of file reached")<<endl;
62  break;
63 
64  }
65  else if (inputFile_.fail()) {
66 
67  edm::LogError("SiPixelDetInfoFileReader::SiPixelDetInfoFileReader - ERROR while reading file")<<endl;
68  break;
69  }
70  }
71 
72  inputFile_.close();
73 
74  }
75  else {
76 
77  edm::LogError("SiPixelDetInfoFileReader::SiPixelDetInfoFileReader - Unable to open file")<<endl;
78  return;
79 
80  }
81 
82 
83 // int i=0;
84 // for(std::map<uint32_t, std::pair<unsigned short, double> >::iterator it =detData_.begin(); it!=detData_.end(); it++ ) {
85 // std::cout<< it->first << " " << (it->second).first << " " << (it->second).second<<endl;
86 // i++;
87 // }
88 // std::cout<<i;
89 
90 
91 }
92 //
93 // Destructor
94 //
96 
97  edm::LogInfo("SiPixelDetInfoFileReader::~SiPixelDetInfoFileReader");
98 }
99 //
100 // get DetId's
101 //
102 const std::vector<uint32_t> & SiPixelDetInfoFileReader::getAllDetIds() const{
103 
104  return detIds_;
105 
106 }
107 //
108 // get method
109 //
110 const std::pair<int, int> & SiPixelDetInfoFileReader::getDetUnitDimensions(uint32_t detId) const{
111 
112  std::map<uint32_t, std::pair<int, int> >::const_iterator it = detData_.find(detId);
113 
114  if(it!=detData_.end()){
115 
116  return (*it).second;
117 
118  }
119  else{
120 
121  static const std::pair< int, int> defaultValue(0,0);
122  edm::LogWarning("SiPixelDetInfoFileReader::getDetUnitDimensions - Unable to find requested detid. Returning invalid data ")<<endl;
123  return defaultValue;
124 
125  }
126 
127 }
128 
const std::pair< int, int > & getDetUnitDimensions(uint32_t detId) const
const std::vector< uint32_t > & getAllDetIds() const
SiPixelDetInfoFileReader(std::string filePath)
Namespace of DDCMS conversion namespace.