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 }
PixelModuleName
Definition: PixelModuleName.h:12
init
int init
Definition: HydjetWrapper.h:64
PixelBarrelName.h
MessageLogger.h
PixelToFEDAssociateFromAscii::send
void send(std::pair< int, std::vector< Bdu > > &, std::pair< int, std::vector< Edu > > &)
initialisation (read input file)
Definition: PixelToFEDAssociateFromAscii.cc:140
Range
PixelRecoRange< float > Range
Definition: PixelTripletHLTGenerator.cc:31
pos
Definition: PixelAliasList.h:18
PixelBarrelName
Definition: PixelBarrelName.h:16
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
PixelToFEDAssociateFromAscii::getBdu
Bdu getBdu(std::string) const
Definition: PixelToFEDAssociateFromAscii.cc:149
alignCSCRings.s
s
Definition: alignCSCRings.py:92
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
PixelEndcapName
Definition: PixelEndcapName.h:16
PixelToFEDAssociateFromAscii::version
std::string version() const override
version
Definition: PixelToFEDAssociateFromAscii.cc:14
PixelToFEDAssociateFromAscii::operator()
int operator()(const PixelModuleName &) const override
FED id for module.
Definition: PixelToFEDAssociateFromAscii.cc:16
str
#define str(s)
Definition: TestProcessor.cc:53
PixelToFEDAssociateFromAscii::readRange
Range readRange(const std::string &) const
Definition: PixelToFEDAssociateFromAscii.cc:192
b
double b
Definition: hdecay.h:118
TRange< int >
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:125
geometryDiff.file
file
Definition: geometryDiff.py:13
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
PixelToFEDAssociateFromAscii::Bdu
Definition: PixelToFEDAssociateFromAscii.h:43
PixelToFEDAssociateFromAscii::Edu
Definition: PixelToFEDAssociateFromAscii.h:51
EcalCalibMonitorClient_cfi.moduleName
moduleName
Definition: EcalCalibMonitorClient_cfi.py:17
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:33
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
std
Definition: JetResolutionObject.h:76
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
Exception
Definition: hltDiff.cc:245
PixelToFEDAssociateFromAscii::PixelToFEDAssociateFromAscii
PixelToFEDAssociateFromAscii(const std::string &fileName)
Definition: PixelToFEDAssociateFromAscii.cc:13
PixelToFEDAssociateFromAscii::init
void init(const std::string &fileName)
initialisatin (read file)
Definition: PixelToFEDAssociateFromAscii.cc:44
personalPlayback.fn
fn
Definition: personalPlayback.py:515
Exception.h
mps_fire.result
result
Definition: mps_fire.py:311
phase1PixelTopology::layerName
constexpr char const * layerName[numberOfLayers]
Definition: phase1PixelTopology.h:37
mps_splice.line
line
Definition: mps_splice.py:76
PixelToFEDAssociateFromAscii::getEdu
Edu getEdu(std::string) const
Definition: PixelToFEDAssociateFromAscii.cc:173
PixelToFEDAssociateFromAscii.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
PixelEndcapName.h