test
CMS 3D CMS Logo

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