CMS 3D CMS Logo

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