CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PixelPortcardMap.cc
Go to the documentation of this file.
1 //
2 // This class provides the mapping between
3 // portcards and the modules controlled by
4 // the card
5 //
6 //
7 //
8 
11 
12 #include <sstream>
13 #include <cassert>
14 #include <stdexcept>
15 
16 using namespace pos;
17 using namespace std;
18 
19 PixelPortcardMap::PixelPortcardMap(std::vector<std::vector<std::string> > &tableMat) : PixelConfigBase(" ", " ", " ") {
20  std::string mthn = "[PixelPortcardMap::PixelPortcardMap()]\t\t\t ";
21  std::vector<std::string> ins = tableMat[0];
22  std::map<std::string, int> colM;
23  std::vector<std::string> colNames;
24  /*
25  EXTENSION_TABLE_NAME: PIXEL_PORTCARD_MAP (VIEW: CONF_KEY_PORTCARD_MAP_V)
26 
27  CONFIG_KEY NOT NULL VARCHAR2(80)
28  KEY_TYPE NOT NULL VARCHAR2(80)
29  KEY_ALIAS NOT NULL VARCHAR2(80)
30  VERSION VARCHAR2(40)
31  KIND_OF_COND NOT NULL VARCHAR2(40)
32  PORT_CARD NOT NULL VARCHAR2(200)
33  PANEL_NAME NOT NULL VARCHAR2(200)
34  TBM_MODE VARCHAR2(200)
35  AOH_CHAN NOT NULL NUMBER(38)
36 */
37  colNames.push_back("CONFIG_KEY");
38  colNames.push_back("KEY_TYPE");
39  colNames.push_back("KEY_ALIAS");
40  colNames.push_back("VERSION");
41  colNames.push_back("KIND_OF_COND");
42  colNames.push_back("PORT_CARD");
43  colNames.push_back("PANEL_NAME");
44  colNames.push_back("TBM_MODE");
45  colNames.push_back("AOH_CHAN");
46  /*
47  colNames.push_back("CONFIG_KEY_ID" );
48  colNames.push_back("CONFG_KEY" );
49  colNames.push_back("VERSION" );
50  colNames.push_back("KIND_OF_COND" );
51  colNames.push_back("SERIAL_NUMBER" );
52  colNames.push_back("PORT_CARD" );
53  colNames.push_back("PANEL_NAME" );
54  colNames.push_back("TBM_MODE" );
55  colNames.push_back("AOH_CHAN" );
56  */
57  for (unsigned int c = 0; c < ins.size(); c++) {
58  for (unsigned int n = 0; n < colNames.size(); n++) {
59  if (tableMat[0][c] == colNames[n]) {
60  colM[colNames[n]] = c;
61  break;
62  }
63  }
64  } //end for
65  /*
66  for(unsigned int n=0; n<colNames.size(); n++)
67  {
68  if(colM.find(colNames[n]) == colM.end())
69  {
70  std::cerr << __LINE__ << "]\t" << mthn
71  << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
72  assert(0);
73  }
74  }
75  */
76 
77  std::string portcardname;
78  std::string modulename;
79  unsigned int aoh;
80  std::string aohstring;
81  std::string tbmChannel;
82 
83  for (unsigned int r = 1; r < tableMat.size(); r++) { //Goes to every row of the Matrix
84 
85  portcardname = tableMat[r][colM["PORT_CARD"]];
86  modulename = tableMat[r][colM["PANEL_NAME"]];
87  aohstring = tableMat[r][colM["AOH_CHAN"]];
88  tbmChannel = tableMat[r][colM["TBM_MODE"]];
89  // cout << "[PixelPortcardMap::PixelPortcardMap()]\t\t\t "
90  // << "Portcardname: " << portcardname
91  // << "\tmodulename: " << modulename
92  // << "\taohstring: " << aohstring
93  // << "\ttbmChannel:" << tbmChannel
94  // << endl ;
95  //aohname.erase(0,20); // Is going to be change when Umesh put a AOH Channel column in the view.
96  aoh = (((unsigned int)atoi(aohstring.c_str())));
97  //std::cout<<aoh<<std::endl;
98  PixelModuleName module(modulename);
99  if (module.modulename() != modulename) {
100  std::cout << __LINE__ << "]\t" << mthn << "Modulename: " << modulename << std::endl;
101  std::cout << __LINE__ << "]\t" << mthn << "Parsed to : " << module.modulename() << std::endl;
102  assert(0);
103  }
104  if (tbmChannel.empty()) {
105  tbmChannel = "A"; // assert(0); // add TBMChannel to the input, then remove assert
106  }
107  PixelChannel channel(module, tbmChannel);
108  std::pair<std::string, int> portcardAndAOH(portcardname, aoh);
109  map_[channel] = portcardAndAOH;
110  } //end for r
111 
112 } //end constructor
113 //*****************************************************************************
114 
116  std::string mthn = "[PixelPortcardMap::PixelPortcardMap()]\t\t\t ";
117  std::ifstream in(filename.c_str());
118 
119  if (!in.good()) {
120  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
121  throw std::runtime_error("Failed to open file " + filename);
122  } else {
123  std::cout << __LINE__ << "]\t" << mthn << "Reading from: " << filename << std::endl;
124  }
125 
126  std::string dummy;
127 
128  in >> dummy;
129  in >> dummy;
130  in >> dummy;
131  in >> dummy;
132  in >> dummy;
133 
134  do {
135  std::string portcardname;
136  std::string modulename;
137  std::string TBMChannel = "A";
138  std::string aoh_string;
139  unsigned int aoh;
140 
141  in >> portcardname >> modulename >> aoh_string;
142  if (aoh_string == "A" ||
143  aoh_string == "B") // Optionally, the TBM channel may be specified after the module name. Check for this.
144  {
145  TBMChannel = aoh_string;
146  in >> aoh_string;
147  }
148  aoh = atoi(aoh_string.c_str());
149 
150  if (!in.eof()) {
151  PixelModuleName module(modulename);
152  if (module.modulename() != modulename) {
153  std::cout << __LINE__ << "]\t" << mthn << "Modulename: " << modulename << std::endl;
154  std::cout << __LINE__ << "]\t" << mthn << "Parsed to : " << module.modulename() << std::endl;
155  assert(0);
156  }
157 
158  PixelChannel channel(module, TBMChannel);
159  std::pair<std::string, int> portcardAndAOH(portcardname, aoh);
160  map_[channel] = portcardAndAOH;
161  }
162 
163  } while (!in.eof());
164 }
165 
166 /*const std::map<PixelModuleName, int>& PixelPortcardMap::modules(std::string portcard) const{
167 
168  std::map<std::string,std::map<PixelModuleName, int> >::const_iterator theportcard=map_.find(portcard);
169 
170  if (theportcard==map_.end()) {
171  std::cout << "Could not find portcard with name:"<<portcard<<std::endl;
172  }
173 
174  return theportcard->second;
175 
176 }*/
177 
179 
181  std::string mthn = "[PixelPortcardMap::writeASCII()]\t\t\t\t ";
182  if (!dir.empty())
183  dir += "/";
184  string filename = dir + "portcardmap.dat";
185 
186  ofstream out(filename.c_str());
187  if (!out.good()) {
188  cout << __LINE__ << "]\t" << mthn << "Could not open file: " << filename << endl;
189  assert(0);
190  }
191 
192  out << "# Portcard Module AOH channel" << endl;
193  std::map<PixelChannel, std::pair<std::string, int> >::const_iterator i = map_.begin();
194  for (; i != map_.end(); ++i) {
195  out << i->second.first << " " << i->first.module() << " " << i->first.TBMChannel() << " "
196  << i->second.second << endl;
197  }
198  out.close();
199 }
200 
201 const std::set<std::pair<std::string, int> > PixelPortcardMap::PortCardAndAOHs(const PixelModuleName &aModule) const {
202  std::set<std::pair<std::string, int> > returnThis;
203 
204  // Loop over the entire map, searching for elements matching PixelModuleName. Add matching elements to returnThis.
205  for (std::map<PixelChannel, std::pair<std::string, int> >::const_iterator map_itr = map_.begin();
206  map_itr != map_.end();
207  ++map_itr) {
208  if (map_itr->first.modulename() == aModule.modulename()) {
209  returnThis.insert(map_itr->second);
210  }
211  }
212 
213  return returnThis;
214 }
215 
216 // Added by Dario for Debbie (the PixelPortcardMap::portcards is way to slow for the interactive tool)
218  for (std::map<PixelChannel, std::pair<std::string, int> >::const_iterator map_itr = map_.begin();
219  map_itr != map_.end();
220  ++map_itr) {
221  if (map_itr->first.modulename() == moduleName) {
222  portcardName = map_itr->second.first;
223  return true;
224  }
225  }
226  return false;
227 }
228 
229 const std::set<std::string> PixelPortcardMap::portcards(const PixelModuleName &aModule) const {
230  std::set<std::string> returnThis;
231  const std::set<std::pair<std::string, int> > portCardAndAOHs = PortCardAndAOHs(aModule);
232  for (std::set<std::pair<std::string, int> >::const_iterator portCardAndAOHs_itr = portCardAndAOHs.begin();
233  portCardAndAOHs_itr != portCardAndAOHs.end();
234  ++portCardAndAOHs_itr) {
235  returnThis.insert((*portCardAndAOHs_itr).first);
236  }
237  return returnThis;
238 }
239 
240 const std::pair<std::string, int> PixelPortcardMap::PortCardAndAOH(const PixelModuleName &aModule,
241  const PixelTBMChannel &TBMChannel) const {
242  return PortCardAndAOH(PixelChannel(aModule, TBMChannel));
243 }
244 
245 const std::pair<std::string, int> PixelPortcardMap::PortCardAndAOH(const PixelModuleName &aModule,
246  const std::string &TBMChannel) const {
247  return PortCardAndAOH(PixelChannel(aModule, TBMChannel));
248 }
249 
250 const std::pair<std::string, int> PixelPortcardMap::PortCardAndAOH(const PixelChannel &aChannel) const {
251  std::map<PixelChannel, std::pair<std::string, int> >::const_iterator found = map_.find(aChannel);
252  if (found == map_.end()) {
253  std::pair<std::string, int> returnThis("none", 0);
254  return returnThis;
255  } else {
256  return found->second;
257  }
258 }
259 
260 std::set<PixelModuleName> PixelPortcardMap::modules(std::string portCardName) const {
261  std::set<PixelModuleName> returnThis;
262 
263  // Loop over the entire map, searching for elements matching portCardName. Add matching elements to returnThis.
264  for (std::map<PixelChannel, std::pair<std::string, int> >::const_iterator map_itr = map_.begin();
265  map_itr != map_.end();
266  ++map_itr) {
267  if (map_itr->second.first == portCardName) {
268  returnThis.insert(map_itr->first.module());
269  }
270  }
271 
272  return returnThis;
273 }
274 
275 std::set<std::string> PixelPortcardMap::portcards(const PixelDetectorConfig *detconfig) {
276  std::set<std::string> returnThis;
277 
278  if (detconfig != nullptr) {
279  //still done done in an awkward way, but this avoids an
280  //double nested loop that we had in the first implementation
281  const std::vector<PixelModuleName> &moduleList = detconfig->getModuleList();
282  std::set<std::string> moduleNames;
283  for (std::vector<PixelModuleName>::const_iterator it = moduleList.begin(), it_end = moduleList.end(); it != it_end;
284  ++it) {
285  moduleNames.insert(it->modulename());
286  }
287 
288  for (std::map<PixelChannel, std::pair<std::string, int> >::const_iterator map_itr = map_.begin();
289  map_itr != map_.end();
290  ++map_itr) {
291  if (moduleNames.find(map_itr->first.modulename()) != moduleNames.end()) {
292  returnThis.insert(map_itr->second.first);
293  }
294  }
295 
296  } else {
297  for (std::map<PixelChannel, std::pair<std::string, int> >::const_iterator map_itr = map_.begin();
298  map_itr != map_.end();
299  ++map_itr) {
300  returnThis.insert(map_itr->second.first);
301  }
302  }
303 
304  return returnThis;
305 }
306 //=============================================================================================
308  int version,
310  std::ofstream *outstream,
311  std::ofstream *out1stream,
312  std::ofstream *out2stream) const {
313  std::string mthn = "[PixelPortcardMap::writeXMLHeader()]\t\t\t ";
314  std::stringstream fullPath;
315  fullPath << path << "/Pixel_PortCardMap_" << PixelTimeFormatter::getmSecTime() << ".xml";
316  std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << fullPath.str() << std::endl;
317 
318  outstream->open(fullPath.str().c_str());
319 
320  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl;
321  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
322  *outstream << " <HEADER>" << std::endl;
323  *outstream << " <TYPE>" << std::endl;
324  *outstream << " <EXTENSION_TABLE_NAME>PIXEL_PORTCARD_MAP</EXTENSION_TABLE_NAME>" << std::endl;
325  *outstream << " <NAME>Pixel Port Card Map</NAME>" << std::endl;
326  *outstream << " </TYPE>" << std::endl;
327  *outstream << " <RUN>" << std::endl;
328  *outstream << " <RUN_TYPE>Pixel Port Card Map</RUN_TYPE>" << std::endl;
329  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl;
330  *outstream << " <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>"
331  << std::endl;
332  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl;
333  *outstream << " </RUN>" << std::endl;
334  *outstream << " </HEADER>" << std::endl;
335  *outstream << "" << std::endl;
336  *outstream << " <DATA_SET>" << std::endl;
337  *outstream << " <PART>" << std::endl;
338  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl;
339  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl;
340  *outstream << " </PART>" << std::endl;
341  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl;
342  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl;
343  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl;
344 }
345 
346 //=============================================================================================
347 void PixelPortcardMap::writeXML(std::ofstream *outstream, std::ofstream *out1stream, std::ofstream *out2stream) const {
348  std::string mthn = "[PixelPortcardMap::writeXML()]\t\t\t ";
349 
350  std::map<PixelChannel, std::pair<std::string, int> >::const_iterator i = map_.begin();
351  for (; i != map_.end(); ++i) {
352  *outstream << " <DATA>" << std::endl;
353  *outstream << " <PORT_CARD>" << i->second.first << "</PORT_CARD>" << std::endl;
354  *outstream << " <PANEL_NAME>" << i->first.module() << "</PANEL_NAME>" << std::endl;
355  *outstream << " <TBM_MODE>" << i->first.TBMChannel() << "</TBM_MODE>" << std::endl;
356  *outstream << " <AOH_CHAN>" << i->second.second << "</AOH_CHAN>" << std::endl;
357  *outstream << " </DATA>" << std::endl;
358  }
359 }
360 
361 //=============================================================================================
362 void PixelPortcardMap::writeXMLTrailer(std::ofstream *outstream,
363  std::ofstream *out1stream,
364  std::ofstream *out2stream) const {
365  std::string mthn = "[PixelPortcardMap::writeXMLTrailer()]\t\t\t ";
366 
367  *outstream << " </DATA_SET>" << std::endl;
368  *outstream << "</ROOT> " << std::endl;
369 
370  outstream->close();
371 }
This file contains the base class for &quot;pixel configuration data&quot; management.
const edm::EventSetup & c
Simple class to hold either &quot;A&quot; or &quot;B&quot; for the TBM channel.
This class provides the mapping between portcards and the modules controlled by the card...
void writeASCII(std::string dir) const override
void writeXML(pos::PixelConfigKey key, int version, std::string path) const override
PixelPortcardMap(std::string filename)
assert(be >=bs)
static std::string getmSecTime(void)
std::set< PixelModuleName > modules(std::string portCardName) const
static std::string getTime(void)
std::string getComment() const
tuple key
prepare the HTCondor submission files and eventually submit them
This is the documentation about PixelDetectorConfig...
This class provides utility methods to manipulate ASCII formatted timestamps.
tuple ins
Definition: cuy.py:313
std::string getAuthor() const
void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
const std::pair< std::string, int > PortCardAndAOH(const PixelModuleName &aModule, const std::string &TBMChannel) const
const std::vector< PixelModuleName > & getModuleList() const
This class implements..
std::string modulename() const
const std::set< std::pair< std::string, int > > PortCardAndAOHs(const PixelModuleName &aModule) const
This class implements..
const std::set< std::string > portcards(const PixelModuleName &aModule) const
void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:144
bool getName(std::string moduleName, std::string &portcardName)
std::map< PixelChannel, std::pair< std::string, int > > map_
tuple module
Definition: callgraph.py:69