CMS 3D CMS Logo

PixelToFEDAssociateFromAscii.cc
Go to the documentation of this file.
2 
6 
7 #include <ostream>
8 #include <fstream>
10 
11 using namespace std;
12 
14 std::string PixelToFEDAssociateFromAscii::version() const { return theVersion; }
15 
17  return id.isBarrel() ? operator()(dynamic_cast<const PixelBarrelName&>(id)) :
18  operator()(dynamic_cast<const PixelEndcapName&>(id));
19 }
20 
22  for (BarrelConnections::const_iterator ibc = theBarrel.begin(); ibc != theBarrel.end(); ibc++) {
23  for (vector<Bdu>::const_iterator ibd = (*ibc).second.begin(); ibd != (*ibc).second.end(); ibd++) {
24  if (ibd->b == id.shell() && ibd->l.inside(id.layerName()) && ibd->z.inside(id.moduleName()) &&
25  ibd->f.inside(id.ladderName()))
26  return (*ibc).first;
27  }
28  }
29  edm::LogError("** PixelToFEDAssociateFromAscii WARNING, name: ") << id.name() << " not associated to FED";
30  return -1;
31 }
32 
34  for (EndcapConnections::const_iterator iec = theEndcap.begin(); iec != theEndcap.end(); iec++) {
35  for (vector<Edu>::const_iterator ied = (*iec).second.begin(); ied != (*iec).second.end(); ied++) {
36  if (ied->e == id.halfCylinder() && ied->d.inside(id.diskName()) && ied->b.inside(id.bladeName()))
37  return iec->first;
38  }
39  }
40  edm::LogError("** PixelToFEDAssociateFromAscii WARNING, name: ") << id.name() << " not associated to FED";
41  return -1;
42 }
43 
44 void PixelToFEDAssociateFromAscii::init(const string& cfg_name) {
45  LogDebug("init, input file:") << cfg_name.c_str();
46 
47  std::ifstream file(cfg_name.c_str());
48  if (!file) {
49  edm::LogError(" ** PixelToFEDAssociateFromAscii,init ** ") << " cant open data file: " << cfg_name;
50  return;
51  } else {
52  edm::LogInfo("PixelToFEDAssociateFromAscii, read data from: ") << cfg_name;
53  }
54 
55  string line;
56  pair<int, vector<Bdu> > barCon;
57  pair<int, vector<Edu> > endCon;
58 
59  try {
60  while (getline(file, line)) {
61  //
62  // treat # lines
63  //
64  string::size_type pos = line.find('#');
65  if (pos != string::npos)
66  line = line.erase(pos);
67 
68  string::size_type posF = line.find("FED:");
69  string::size_type posB = line.find("S:");
70  string::size_type posE = line.find("E:");
71 
72  LogDebug("line read") << line;
73 
74  //
75  // treat version lines, reset date
76  //
77  if (line.compare(0, 3, "VER") == 0) {
78  edm::LogInfo("version: ") << line;
79  theVersion = line;
80  send(barCon, endCon);
81  theBarrel.clear();
82  theEndcap.clear();
83  }
84 
85  //
86  // fed id line
87  //
88  else if (posF != string::npos) {
89  line = line.substr(posF + 4);
90  int id = atoi(line.c_str());
91  send(barCon, endCon);
92  barCon.first = id;
93  endCon.first = id;
94  }
95 
96  //
97  // barrel connections
98  //
99  else if (posB != string::npos) {
100  line = line.substr(posB + 2);
101  barCon.second.push_back(getBdu(line));
102  }
103 
104  //
105  // endcap connections
106  //
107  else if (posE != string::npos) {
108  line = line.substr(posE + 2);
109  endCon.second.push_back(getEdu(line));
110  }
111  }
112  send(barCon, endCon);
113  } catch (exception& err) {
114  edm::LogError("**PixelToFEDAssociateFromAscii** exception") << err.what();
115  theBarrel.clear();
116  theEndcap.clear();
117  }
118 
119  //
120  // for debug
121  //
122  std::ostringstream str;
123  str << " **PixelToFEDAssociateFromAscii ** BARREL FED CONNECTIONS: " << endl;
124  for (BarrelConnections::const_iterator ibc = theBarrel.begin(); ibc != theBarrel.end(); ibc++) {
125  str << "FED: " << ibc->first << endl;
126  for (vector<Bdu>::const_iterator ibd = (*ibc).second.begin(); ibd != (*ibc).second.end(); ibd++) {
127  str << "b: " << ibd->b << " l: " << ibd->l << " z: " << ibd->z << " f: " << ibd->f << endl;
128  }
129  }
130  str << " **PixelToFEDAssociateFromAscii ** ENDCAP FED CONNECTIONS: " << endl;
131  for (EndcapConnections::const_iterator iec = theEndcap.begin(); iec != theEndcap.end(); iec++) {
132  str << "FED: " << iec->first << endl;
133  for (vector<Edu>::const_iterator ied = (*iec).second.begin(); ied != (*iec).second.end(); ied++) {
134  str << " e: " << ied->e << " d: " << ied->d << " b: " << ied->b << endl;
135  }
136  }
137  edm::LogInfo("PixelToFEDAssociateFromAscii") << str.str();
138 }
139 
140 void PixelToFEDAssociateFromAscii::send(pair<int, vector<Bdu> >& b, pair<int, vector<Edu> >& e) {
141  if (!b.second.empty())
142  theBarrel.push_back(b);
143  if (!e.second.empty())
144  theEndcap.push_back(e);
145  b.second.clear();
146  e.second.clear();
147 }
148 
150  Bdu result;
152 
153  result.b = readRange(line).first;
154 
155  pos = line.find("L:");
156  if (pos != string::npos)
157  line = line.substr(pos + 2);
158  result.l = readRange(line);
159 
160  pos = line.find("Z:");
161  if (pos != string::npos)
162  line = line.substr(pos + 2);
163  result.z = readRange(line);
164 
165  pos = line.find("F:");
166  if (pos != string::npos)
167  line = line.substr(pos + 2);
168  result.f = readRange(line);
169 
170  return result;
171 }
172 
174  Edu result;
176 
177  result.e = readRange(line).first;
178 
179  pos = line.find("D:");
180  if (pos != string::npos)
181  line = line.substr(pos + 2);
182  result.d = readRange(line);
183 
184  pos = line.find("B:");
185  if (pos != string::npos)
186  line = line.substr(pos + 2);
187  result.b = readRange(line);
188 
189  return result;
190 }
191 
193  bool first = true;
194  int num1 = -1;
195  int num2 = -1;
196  const char* line = l.c_str();
197  while (line) {
198  char* evp = nullptr;
199  int num = strtol(line, &evp, 10);
200  {
201  stringstream s;
202  s << "raad from line: ";
203  s << num;
204  LogDebug(s.str());
205  }
206  if (evp != line) {
207  line = evp + 1;
208  if (first) {
209  num1 = num;
210  first = false;
211  }
212  num2 = num;
213  } else
214  line = nullptr;
215  }
216  if (first) {
217  string s = "** PixelToFEDAssociateFromAscii, read data, cant intrpret: ";
218  edm::LogInfo(s) << endl << l << endl << "=====> send exception " << endl;
219  s += l;
220  throw cms::Exception(s);
221  }
222  return Range(num1, num2);
223 }
PixelRecoRange< float > Range
int init
Definition: HydjetWrapper.h:66
Log< level::Error, false > LogError
uint16_t size_type
PixelToFEDAssociateFromAscii(const std::string &fileName)
void init(const std::string &fileName)
initialisatin (read file)
Log< level::Info, false > LogInfo
void send(std::pair< int, std::vector< Bdu > > &, std::pair< int, std::vector< Edu > > &)
initialisation (read input file)
double b
Definition: hdecay.h:120
int operator()(const PixelModuleName &) const override
FED id for module.
#define str(s)
std::string version() const override
version
#define LogDebug(id)
Range readRange(const std::string &) const