CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripDetInfoFileReader.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Package: SiStripCommon
3 // Class: SiStripDetInfoFileReader
4 // Original Author: G. Bruno
5 // Created: Mon May 20 10:04:31 CET 2007
6 // $Id: SiStripDetInfoFileReader.cc,v 1.6 2009/06/09 18:31:52 elmer Exp $
7 
12 
13 using namespace cms;
14 using namespace std;
15 
17  detData_=copy.detData_;
18  detIds_=copy.detIds_;
19  return *this;
20 }
21 
23  edm::FileInPath fp(pset.getUntrackedParameter<std::string>("filePath","CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"));
24  reader(fp.fullPath());
25 }
26 
28  detData_=copy.detData_;
29  detIds_=copy.detIds_;
30 }
31 
33  reader(filePath);
34 }
35 
36 void SiStripDetInfoFileReader::reader(std::string filePath) {
37 
38 // if(filePath==std::string("")){
39 // filePath = edm::FileInPath(std::string("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat") ).fullPath();
40 // }
41 
42  edm::LogInfo("SiStripDetInfoFileReader") << "filePath " << filePath << std::endl;
43 
44 
45  detData_.clear();
46  detIds_.clear();
47 
48  inputFile_.open(filePath.c_str());
49 
50  if (inputFile_.is_open()){
51 
52  for(;;) {
53 
54  uint32_t detid;
55  double stripLength;
56  unsigned short numberOfAPVs;
57  float thickness;
58 
59  inputFile_ >> detid >> numberOfAPVs >> stripLength >> thickness;
60 
61  if (!(inputFile_.eof() || inputFile_.fail())){
62 
63  detIds_.push_back(detid);
64 
65  // inputFile_ >> numberOfAPVs;
66  // inputFile_ >> stripLength;
67 
68  // edm::LogInfo("SiStripDetInfoFileReader::SiStripDetInfoFileReader") << detid <<" " <<numberOfAPVs <<" " <<stripLength << " "<< thickness<< endl;
69 
70  std::map<uint32_t, DetInfo >::const_iterator it = detData_.find(detid);
71 
72  if(it==detData_.end()){
73  detData_[detid]=DetInfo(numberOfAPVs, stripLength,thickness);
74  }
75  else{
76 
77  edm::LogError("SiStripDetInfoFileReader::SiStripDetInfoFileReader") <<"DetId " << detid << " already found on file. Ignoring new data"<<endl;
78 
79  detIds_.pop_back();
80  continue;
81  }
82  }
83  else if (inputFile_.eof()){
84 
85  edm::LogInfo("SiStripDetInfoFileReader::SiStripDetInfoFileReader - END of file reached")<<endl;
86  break;
87 
88  }
89  else if (inputFile_.fail()) {
90 
91  edm::LogError("SiStripDetInfoFileReader::SiStripDetInfoFileReader - ERROR while reading file")<<endl;
92  break;
93  }
94  }
95 
96  inputFile_.close();
97 
98  }
99  else {
100 
101  edm::LogError("SiStripDetInfoFileReader::SiStripDetInfoFileReader - Unable to open file")<<endl;
102  return;
103 
104  }
105 
106 // int i=0;
107 // for(std::map<uint32_t, std::pair<unsigned short, double> >::iterator it =detData_.begin(); it!=detData_.end(); it++ ) {
108 // std::cout<< it->first << " " << (it->second).first << " " << (it->second).second<<endl;
109 // i++;
110 // }
111 // std::cout<<i;
112 
113 
114 }
115 
116 
118 }
119 
120 
121 const std::pair<unsigned short, double> SiStripDetInfoFileReader::getNumberOfApvsAndStripLength(uint32_t detId) const{
122 
123  std::map<uint32_t, DetInfo >::const_iterator it = detData_.find(detId);
124 
125  if(it!=detData_.end()){
126 
127  return std::pair<unsigned short, double>(it->second.nApvs,it->second.stripLength);
128 
129  }
130  else{
131 
132  static std::pair<unsigned short, double> defaultValue(0,0);
133  edm::LogWarning("SiStripDetInfoFileReader::getNumberOfApvsAndStripLength - Unable to find requested detid. Returning invalid data ")<<endl;
134  return defaultValue;
135 
136  }
137 
138 }
139 
140 const float & SiStripDetInfoFileReader::getThickness(uint32_t detId) const{
141 
142  std::map<uint32_t, DetInfo >::const_iterator it = detData_.find(detId);
143 
144  if(it!=detData_.end()){
145 
146  return it->second.thickness;
147 
148  }
149  else{
150 
151  static float defaultValue=0;
152  edm::LogWarning("SiStripDetInfoFileReader::getThickness - Unable to find requested detid. Returning invalid data ")<<endl;
153  return defaultValue;
154 
155  }
156 
157 }
158 
T getUntrackedParameter(std::string const &, T const &) const
const float & getThickness(uint32_t detId) const
std::map< uint32_t, DetInfo > detData_
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
SiStripDetInfoFileReader & operator=(const SiStripDetInfoFileReader &copy)
std::vector< uint32_t > detIds_
std::string fullPath() const
Definition: FileInPath.cc:171
void reader(std::string filePath)