CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelMaxVsf.cc
Go to the documentation of this file.
1 //
2 // Implementation of the max Vsf
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 PixelMaxVsf::PixelMaxVsf(std::vector< std::vector< std::string > > &tableMat):PixelConfigBase("","","")
23 {
24  std::string mthn = "[PixelMaxVsf::PixelMaxVsf()]\t\t\t\t " ;
25  std::map<std::string , int > colM;
26  std::vector<std::string > colNames;
40  colNames.push_back("CONFIG_KEY" );
41  colNames.push_back("KEY_TYPE" );
42  colNames.push_back("KEY_ALIAS" );
43  colNames.push_back("VERSION" );
44  colNames.push_back("KIND_OF_COND");
45  colNames.push_back("ROC_NAME" );
46  colNames.push_back("MAXVSF" );
47 
48  for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
49  {
50  for(unsigned int n=0; n<colNames.size(); n++)
51  {
52  if(tableMat[0][c] == colNames[n])
53  {
54  colM[colNames[n]] = c;
55  break;
56  }
57  }
58  }//end for
59  for(unsigned int n=0; n<colNames.size(); n++)
60  {
61  if(colM.find(colNames[n]) == colM.end())
62  {
63  std::cerr << __LINE__ << "]\t" << mthn << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
64  assert(0);
65  }
66  }
67 
68  rocs_.clear();
69 
70  for(unsigned int r = 1 ; r < tableMat.size() ; r++) //Goes to every row of the Matrix
71  {
72  PixelROCName roc(tableMat[r][colM["ROC_NAME"]]);
73  unsigned int vsf;
74  vsf = atoi(tableMat[r][colM["MAXVSF"]].c_str());
75  rocs_[roc]=vsf;
76  }
77 }//end constructor
78 
79 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
80 
82  PixelConfigBase("","",""){
83 
84  std::string mthn = "[PixelMaxVsf::PixelMaxVsf()]\t\t\t\t " ;
85 
86  if (filename[filename.size()-1]=='t'){
87 
88  std::ifstream in(filename.c_str());
89 
90  if (!in.good()){
91  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
92  throw std::runtime_error("Failed to open file "+filename);
93  }
94  else {
95  std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
96  }
97 
98  if (in.eof()){
99  std::cout << __LINE__ << "]\t" << mthn << "eof before reading anything!" << std::endl;
100  throw std::runtime_error("File appears to be empty: "+filename);
101  }
102 
103 
104  rocs_.clear();
105 
106  std::string rocname;
107 
108  in >> rocname;
109  while (!in.eof()){
110  //cout << "Read rocname:"<<rocname<<endl;
111  PixelROCName roc(rocname);
112  unsigned int vsf;
113  in >> vsf;
114  rocs_[roc]=vsf;
115  in >> rocname;
116  }
117  return;
118  }
119  else{
120  assert(0);
121  }
122 
123 }
124 
125 bool PixelMaxVsf::getVsf(PixelROCName roc, unsigned int& Vsf) const{
126 
127  std::map<PixelROCName,unsigned int>::const_iterator itr = rocs_.find(roc);
128 
129  if (itr==rocs_.end()) {
130  return false;
131  }
132 
133  Vsf=itr->second;
134 
135  return true;
136 
137 }
138 
139 
140 void PixelMaxVsf::setVsf(PixelROCName roc, unsigned int Vsf){
141 
142  rocs_[roc]=Vsf;
143 
144 }
145 
146 
147 
149 
150  std::string mthn = "[PixelMaxVsf::writeASCII()]\t\t\t\t " ;
151  if (dir!="") dir+="/";
152  std::string filename=dir+"maxvsf.dat";
153 
154  std::ofstream out(filename.c_str(), std::ios_base::out) ;
155  if(!out) {
156  std::cout << __LINE__ << "]\t" << mthn << "Could not open file " << filename << " for write" << std::endl ;
157  exit(1);
158  }
159 
160 
161  std::map<PixelROCName, unsigned int>::const_iterator irocs = rocs_.begin();
162  for(; irocs != rocs_.end() ; ++irocs){
163  out << (irocs->first).rocname() << " " << irocs->second << endl ;
164  }
165 
166  out.close();
167 
168 }
169 
170 //=============================================================================================
172  int version,
173  std::string path,
174  std::ofstream *outstream,
175  std::ofstream *out1stream,
176  std::ofstream *out2stream) const
177 {
178  std::string mthn = "[PixelMaxVsf::writeXMLHeader()]\t\t\t " ;
179  std::stringstream maskFullPath ;
180 
181  maskFullPath << path << "/Pixel_RocMaxVsf_" << PixelTimeFormatter::getmSecTime() << ".xml";
182  std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl ;
183 
184  outstream->open(maskFullPath.str().c_str()) ;
185 
186  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl ;
187  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl ;
188  *outstream << "" << std::endl ;
189  *outstream << " <HEADER>" << std::endl ;
190  *outstream << " <TYPE>" << std::endl ;
191  *outstream << " <EXTENSION_TABLE_NAME>ROC_MAXVSF</EXTENSION_TABLE_NAME>" << std::endl ;
192  *outstream << " <NAME>ROC MaxVsf Setting</NAME>" << std::endl ;
193  *outstream << " </TYPE>" << std::endl ;
194  *outstream << " <RUN>" << std::endl ;
195  *outstream << " <RUN_TYPE>ROC MaxVsf Settings</RUN_TYPE>" << std::endl ;
196  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl ;
197  *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
198  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl ;
199  *outstream << " </RUN>" << std::endl ;
200  *outstream << " </HEADER>" << std::endl ;
201  *outstream << "" << std::endl ;
202  *outstream << " <DATA_SET>" << std::endl ;
203  *outstream << "" << std::endl ;
204  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl ;
205  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl ;
206  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl ;
207  *outstream << "" << std::endl ;
208  *outstream << " <PART>" << std::endl ;
209  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl ;
210  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl ;
211  *outstream << " </PART>" << std::endl ;
212 
213 }
214 
215 //=============================================================================================
216 void PixelMaxVsf::writeXML( std::ofstream *outstream,
217  std::ofstream *out1stream,
218  std::ofstream *out2stream) const
219 {
220  std::string mthn = "[PixelMaxVsf::writeXML()]\t\t\t " ;
221 
222  std::map<PixelROCName, unsigned int>::const_iterator irocs = rocs_.begin();
223  for(; irocs != rocs_.end() ; ++irocs){
224  *outstream << " <DATA>" << std::endl ;
225  *outstream << " <ROC_NAME>" << (irocs->first).rocname() << "</ROC_NAME>" << std::endl ;
226  *outstream << " <MAXVSF>" << irocs->second << "</MAXVSF>" << std::endl ;
227  *outstream << " </DATA>" << std::endl ;
228  *outstream << std::endl ;
229  }
230 }
231 
232 //=============================================================================================
233 void PixelMaxVsf::writeXMLTrailer(std::ofstream *outstream,
234  std::ofstream *out1stream,
235  std::ofstream *out2stream ) const
236 {
237  std::string mthn = "[PixelMaxVsf::writeXMLTrailer()]\t\t\t " ;
238 
239  *outstream << " </DATA_SET>" << std::endl ;
240  *outstream << "</ROOT>" << std::endl ;
241 
242  outstream->close() ;
243  std::cout << __LINE__ << "]\t" << mthn << "Data written " << std::endl ;
244 
245 }
This file contains the base class for &quot;pixel configuration data&quot; management.
assert(m_qm.get())
void setVsf(PixelROCName roc, unsigned int Vsf)
Definition: PixelMaxVsf.cc:140
static std::string getmSecTime(void)
virtual void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) const
Definition: PixelMaxVsf.cc:233
static std::string getTime(void)
std::string getComment() const
PixelMaxVsf(std::vector< std::vector< std::string > > &tableMat)
Definition: PixelMaxVsf.cc:22
This class provides utility methods to manipulate ASCII formatted timestamps.
std::map< PixelROCName, unsigned int > rocs_
Definition: PixelMaxVsf.h:56
std::string getAuthor() const
bool getVsf(PixelROCName roc, unsigned int &Vsf) const
Definition: PixelMaxVsf.cc:125
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
This class implements..
tuple out
Definition: dbtoconf.py:99
This class implements..
Definition: PixelROCName.h:23
This class specifies the maximum Vsf setting that should be used for each ROC.
virtual void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) const
Definition: PixelMaxVsf.cc:171
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121
dbl *** dir
Definition: mlp_gen.cc:35
void writeXML(pos::PixelConfigKey key, int version, std::string path) const
Definition: PixelMaxVsf.h:34
void writeASCII(std::string dir="") const
Definition: PixelMaxVsf.cc:148