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 
11 
12 using namespace cms;
13 using namespace std;
14 
16  detData_=copy.detData_;
17  detIds_=copy.detIds_;
18  return *this;
19 }
20 
22  edm::FileInPath fp(pset.getUntrackedParameter<std::string>("filePath","CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"));
23  reader(fp.fullPath());
24 }
25 
27  detData_=copy.detData_;
28  detIds_=copy.detIds_;
29 }
30 
32  reader(filePath);
33 }
34 
36 
37 // if(filePath==std::string("")){
38 // filePath = edm::FileInPath(std::string("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat") ).fullPath();
39 // }
40 
41  edm::LogInfo("SiStripDetInfoFileReader") << "filePath " << filePath << std::endl;
42 
43 
44  detData_.clear();
45  detIds_.clear();
46 
47  inputFile_.open(filePath.c_str());
48 
49  if (inputFile_.is_open()){
50 
51  for(;;) {
52 
53  uint32_t detid;
54  double stripLength;
55  unsigned short numberOfAPVs;
56  float thickness;
57 
58  inputFile_ >> detid >> numberOfAPVs >> stripLength >> thickness;
59 
60  if (!(inputFile_.eof() || inputFile_.fail())){
61 
62  detIds_.push_back(detid);
63 
64  // inputFile_ >> numberOfAPVs;
65  // inputFile_ >> stripLength;
66 
67  // edm::LogInfo("SiStripDetInfoFileReader::SiStripDetInfoFileReader") << detid <<" " <<numberOfAPVs <<" " <<stripLength << " "<< thickness<< endl;
68 
69  std::map<uint32_t, DetInfo >::const_iterator it = detData_.find(detid);
70 
71  if(it==detData_.end()){
72  detData_[detid]=DetInfo(numberOfAPVs, stripLength,thickness);
73  }
74  else{
75 
76  edm::LogError("SiStripDetInfoFileReader::SiStripDetInfoFileReader") <<"DetId " << detid << " already found on file. Ignoring new data"<<endl;
77 
78  detIds_.pop_back();
79  continue;
80  }
81  }
82  else if (inputFile_.eof()){
83 
84  edm::LogInfo("SiStripDetInfoFileReader::SiStripDetInfoFileReader - END of file reached")<<endl;
85  break;
86 
87  }
88  else if (inputFile_.fail()) {
89 
90  edm::LogError("SiStripDetInfoFileReader::SiStripDetInfoFileReader - ERROR while reading file")<<endl;
91  break;
92  }
93  }
94 
95  inputFile_.close();
96 
97  }
98  else {
99 
100  edm::LogError("SiStripDetInfoFileReader::SiStripDetInfoFileReader - Unable to open file")<<endl;
101  return;
102 
103  }
104 
105 // int i=0;
106 // for(std::map<uint32_t, std::pair<unsigned short, double> >::iterator it =detData_.begin(); it!=detData_.end(); it++ ) {
107 // std::cout<< it->first << " " << (it->second).first << " " << (it->second).second<<endl;
108 // i++;
109 // }
110 // std::cout<<i;
111 
112 
113 }
114 
115 
117 }
118 
119 
120 const std::pair<unsigned short, double> SiStripDetInfoFileReader::getNumberOfApvsAndStripLength(uint32_t detId) const{
121 
122  std::map<uint32_t, DetInfo >::const_iterator it = detData_.find(detId);
123 
124  if(it!=detData_.end()){
125 
126  return std::pair<unsigned short, double>(it->second.nApvs,it->second.stripLength);
127 
128  }
129  else{
130 
131  std::pair<unsigned short, double> defaultValue(0,0.);
132  edm::LogWarning("SiStripDetInfoFileReader::getNumberOfApvsAndStripLength - Unable to find requested detid. Returning invalid data ")<<endl;
133  return defaultValue;
134 
135  }
136 
137 }
138 
139 const float & SiStripDetInfoFileReader::getThickness(uint32_t detId) const{
140 
141  std::map<uint32_t, DetInfo >::const_iterator it = detData_.find(detId);
142 
143  if(it!=detData_.end()){
144 
145  return it->second.thickness;
146 
147  }
148  else{
149 
150  static const float defaultValue=0;
151  edm::LogWarning("SiStripDetInfoFileReader::getThickness - Unable to find requested detid. Returning invalid data ")<<endl;
152  return defaultValue;
153 
154  }
155 
156 }
157 
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:165
void reader(std::string filePath)