CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelLowVoltageMap.cc
Go to the documentation of this file.
1 //
2 // Implementation of the detector configuration
3 //
4 //
5 //
6 //
7 
10 #include <fstream>
11 #include <iostream>
12 #include <sstream>
13 #include <ios>
14 #include <assert.h>
15 #include <stdio.h>
16 #include <stdexcept>
17 
18 using namespace std;
19 using namespace pos;
20 
21 
22 PixelLowVoltageMap::PixelLowVoltageMap(std::vector< std::vector < std::string> > &tableMat):PixelConfigBase("","","")
23 {
24  std::string mthn = "[PixelLowVoltageMap::PixelLowVoltageMap()] " ;
25  std::map<std::string , int > colM;
26  std::vector<std::string > colNames;
27 /*
28  EXTENSION_TABLE_NAME: XDAQ_LOW_VOLTAGE_MAP (VIEW: CONF_KEY_XDAQ_LOW_VOLTAGE_V)
29 
30  CONFIG_KEY NOT NULL VARCHAR2(80)
31  KEY_TYPE NOT NULL VARCHAR2(80)
32  KEY_ALIAS NOT NULL VARCHAR2(80)
33  VERSION VARCHAR2(40)
34  KIND_OF_COND NOT NULL VARCHAR2(40)
35  PANEL_NAME NOT NULL VARCHAR2(200)
36  DATAPOINT NOT NULL VARCHAR2(200)
37  LV_DIGITAL NOT NULL VARCHAR2(200)
38  LV_ANALOG NOT NULL VARCHAR2(200)
39 
40 */
41 
42  colNames.push_back("CONFIG_KEY" );
43  colNames.push_back("KEY_TYPE" );
44  colNames.push_back("KEY_ALIAS" );
45  colNames.push_back("VERSION" );
46  colNames.push_back("KIND_OF_COND");
47  colNames.push_back("PANEL_NAME" );
48  colNames.push_back("DATAPOINT" );
49  colNames.push_back("LV_DIGITAL" );
50  colNames.push_back("LV_ANALOG" );
51 /*
52  colNames.push_back("CONFIG_KEY_ID" );
53  colNames.push_back("CONFG_KEY" );
54  colNames.push_back("VERSION" );
55  colNames.push_back("KIND_OF_COND" );
56  colNames.push_back("RUN_TYPE" );
57  colNames.push_back("RUN_NUMBER" );
58  colNames.push_back("PANEL_NAME" );
59  colNames.push_back("DATAPOINT" );
60  colNames.push_back("LV_DIGITAL" );
61  colNames.push_back("LV_ANALOG" );
62 */
63 
64  for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
65  {
66  for(unsigned int n=0; n<colNames.size(); n++)
67  {
68  if(tableMat[0][c] == colNames[n])
69  {
70  colM[colNames[n]] = c;
71  break;
72  }
73  }
74  }//end for
75  for(unsigned int n=0; n<colNames.size(); n++)
76  {
77  if(colM.find(colNames[n]) == colM.end())
78  {
79  std::cerr << mthn << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
80  assert(0);
81  }
82  }
83 
84  std::string modulename ;
85  std::string dpNameBase ;
86  std::string ianaChannel ;
87  std::string idigiChannel ;
88  for(unsigned int r = 1 ; r < tableMat.size() ; r++) //Goes to every row of the Matrix
89  {
90  modulename = tableMat[r][colM["PANEL_NAME"]] ;
91  dpNameBase = tableMat[r][colM["DATAPOINT"]] ;
92  ianaChannel = tableMat[r][colM["LV_ANALOG"]] ;
93  idigiChannel= tableMat[r][colM["LV_DIGITAL"]] ;
94  PixelModuleName module(modulename);
95  pair<string, string> channels(ianaChannel,idigiChannel);
96  pair<string, pair<string,string> > dpName(dpNameBase,channels);
97  dpNameMap_[module]=dpName;
98  }
99 }//end constructor
100 
101 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
102 
104  PixelConfigBase("","",""){
105 
106  std::string mthn = "[PixelLowVoltageMap::PixelLowVoltageMap()]\t\t\t " ;
107 
108  if (filename[filename.size()-1]=='t'){
109 
110  std::ifstream in(filename.c_str());
111 
112  if (!in.good()){
113  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
114  throw std::runtime_error("Failed to open file "+filename);
115  }
116  else {
117  std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
118  }
119 
120  if (in.eof()){
121  std::cout << __LINE__ << "]\t" << mthn << "eof before reading anything!" << std::endl;
122  throw std::runtime_error("Failure when reading file; file seems to be empty: "+filename);
123  }
124 
125 
126  dpNameMap_.clear();
127 
128  std::string modulename;
129  std::string dpNameBase;
130  std::string ianaChannel;
131  std::string idigiChannel;
132 
133  in >> modulename >> dpNameBase >> ianaChannel >> idigiChannel;
134 
135  while (!in.eof()){
136  cout << __LINE__ << "]\t" << mthn << "Read modulename: " << modulename << endl;
137  PixelModuleName module(modulename);
138  pair<string, string> channels(ianaChannel,idigiChannel);
139  pair<string, pair<string,string> > dpName(dpNameBase,channels);
140  dpNameMap_[module]=dpName;
141  in >> modulename >> dpNameBase >> ianaChannel >> idigiChannel;
142  }
143 
144  }
145  else{
146  assert(0);
147  }
148 }
149 
151 
152  std::string mthn = "[PixelLowVoltageMap::dpNameIana()]\t\t\t " ;
153  std::map<PixelModuleName, pair< string, pair<string, string> > >::const_iterator i=
154  dpNameMap_.find(module);
155 
156  if (i==dpNameMap_.end()) {
157  cout << __LINE__ << "]\t" << mthn << "Could not find module: " << module << endl;
158  }
159 
160  return i->second.first+"/"+i->second.second.first;
161 
162 }
163 
165 
166  std::string mthn = "[PixelLowVoltageMap::dpNameIdigi()]\t\t\t " ;
167  std::map<PixelModuleName, pair< string, pair<string, string> > >::const_iterator i=
168  dpNameMap_.find(module);
169 
170  if (i==dpNameMap_.end()) {
171  cout << __LINE__ << "]\t" << mthn << "Could not find module: " << module << endl;
172  }
173 
174  return i->second.first+"/"+i->second.second.second;
175 
176 }
177 
178 
179 void PixelLowVoltageMap::writeASCII(std::string dir) const {
180 
181  std::string mthn = "[PixelLowVoltageMap::writeASCII()]\t\t\t " ;
182  if (dir!="") dir+="/";
183  std::string filename=dir+"lowvoltagemap.dat";
184 
185  std::ofstream out(filename.c_str(), std::ios_base::out) ;
186  if(!out) {
187  std::cout << __LINE__ << "]\t" << mthn << "Could not open file " << filename << " for write" << std::endl ;
188  exit(1);
189  }
190  std::map<PixelModuleName, pair< string, pair<string, string> > >::const_iterator imodule=
191  dpNameMap_.begin();
192 
193  for (;imodule!=dpNameMap_.end();++imodule) {
194  out << imodule->first
195  << " "<< imodule->second.first
196  << " "<< imodule->second.second.first
197  << " "<< imodule->second.second.second
198  <<endl;
199  }
200 
201  out.close();
202 
203 }
204 
205 //=============================================================================================
207  int version,
208  std::string path,
209  std::ofstream *outstream,
210  std::ofstream *out1stream,
211  std::ofstream *out2stream) const
212 {
213  std::string mthn = "[PixelLowVoltageMap::writeXMLHeader()]\t\t\t " ;
214  std::stringstream maskFullPath ;
215 
216  maskFullPath << path << "/XDAQLowVoltageMap_Test_" << PixelTimeFormatter::getmSecTime() << ".xml";
217  std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl ;
218 
219  outstream->open(maskFullPath.str().c_str()) ;
220 
221  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl ;
222  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl ;
223  *outstream << "" << std::endl ;
224  *outstream << " <HEADER>" << std::endl ;
225  *outstream << " <TYPE>" << std::endl ;
226  *outstream << " <EXTENSION_TABLE_NAME>XDAQ_LOW_VOLTAGE_MAP</EXTENSION_TABLE_NAME>" << std::endl ;
227  *outstream << " <NAME>XDAQ Low Voltage Map</NAME>" << std::endl ;
228  *outstream << " </TYPE>" << std::endl ;
229  *outstream << " <RUN>" << std::endl ;
230  *outstream << " <RUN_TYPE>XDAQ Low Voltage Map</RUN_TYPE>" << std::endl ;
231  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl ;
232  *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
233  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl ;
234  *outstream << " </RUN>" << std::endl ;
235  *outstream << " </HEADER>" << std::endl ;
236  *outstream << "" << std::endl ;
237  *outstream << " <DATA_SET>" << std::endl ;
238  *outstream << "" << std::endl ;
239  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl ;
240  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl ;
241  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl ;
242  *outstream << "" << std::endl ;
243  *outstream << " <PART>" << std::endl ;
244  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl ;
245  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl ;
246  *outstream << " </PART>" << std::endl ;
247  *outstream << " " << std::endl ;
248 
249 }
250 
251 //=============================================================================================
252 void PixelLowVoltageMap::writeXML( std::ofstream *outstream,
253  std::ofstream *out1stream,
254  std::ofstream *out2stream) const
255 {
256  std::string mthn = "[PixelLowVoltageMap::writeXML()]\t\t\t " ;
257 
258  std::map<PixelModuleName, pair< string, pair<string, string> > >::const_iterator imodule=dpNameMap_.begin();
259 
260  for (;imodule!=dpNameMap_.end();++imodule) {
261  *outstream << " <DATA>" << std::endl ;
262  *outstream << " <PANEL_NAME>" << imodule->first << "</PANEL_NAME>" << std::endl ;
263  *outstream << " <DATAPOINT>" << imodule->second.first << "</DATAPOINT>" << std::endl ;
264  *outstream << " <LV_DIGITAL>" << imodule->second.second.first << "</LV_DIGITAL>" << std::endl ;
265  *outstream << " <LV_ANALOG>" << imodule->second.second.second << "</LV_ANALOG>" << std::endl ;
266  *outstream << " </DATA>" << std::endl ;
267  *outstream << "" << std::endl ;
268  }
269 }
270 
271 //=============================================================================================
272 void PixelLowVoltageMap::writeXMLTrailer(std::ofstream *outstream,
273  std::ofstream *out1stream,
274  std::ofstream *out2stream ) const
275 {
276  std::string mthn = "[PixelLowVoltageMap::writeXMLTrailer()]\t\t\t " ;
277 
278  *outstream << " </DATA_SET>" << std::endl ;
279  *outstream << "</ROOT>" << std::endl ;
280 
281  outstream->close() ;
282  std::cout << __LINE__ << "]\t" << mthn << "Data written " << std::endl ;
283 
284 }
285 
int i
Definition: DBlmapReader.cc:9
This file contains the base class for &quot;pixel configuration data&quot; management.
virtual void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) const
virtual void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) const
static std::string getmSecTime(void)
std::map< PixelModuleName, std::pair< std::string, std::pair< std::string, std::string > > > dpNameMap_
list path
Definition: scaleCards.py:51
void writeXML(pos::PixelConfigKey key, int version, std::string path) const
This class implements..
static std::string getTime(void)
PixelLowVoltageMap(std::vector< std::vector< std::string > > &tableMat)
std::string getComment() const
This class provides utility methods to manipulate ASCII formatted timestamps.
std::string getAuthor() const
std::string dpNameIana(const PixelModuleName &module) const
This class implements..
tuple out
Definition: dbtoconf.py:99
This class implements..
list key
Definition: combine.py:13
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121
void writeASCII(std::string dir="") const
dbl *** dir
Definition: mlp_gen.cc:35
std::string dpNameIdigi(const PixelModuleName &module) const
Definition: vlib.h:209