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