CMS 3D CMS Logo

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 <cassert>
15 #include <cstdio>
16 #include <stdexcept>
17 
18 using namespace std;
19 using namespace pos;
20 
21 PixelMaxVsf::PixelMaxVsf(std::vector<std::vector<std::string> > &tableMat) : PixelConfigBase("", "", "") {
22  std::string mthn = "[PixelMaxVsf::PixelMaxVsf()]\t\t\t\t ";
23  std::map<std::string, int> colM;
24  std::vector<std::string> colNames;
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("ROC_NAME");
44  colNames.push_back("MAXVSF");
45 
46  for (unsigned int c = 0; c < tableMat[0].size(); c++) {
47  for (unsigned int n = 0; n < colNames.size(); n++) {
48  if (tableMat[0][c] == colNames[n]) {
49  colM[colNames[n]] = c;
50  break;
51  }
52  }
53  } //end for
54  for (unsigned int n = 0; n < colNames.size(); n++) {
55  if (colM.find(colNames[n]) == colM.end()) {
56  std::cerr << __LINE__ << "]\t" << mthn << "Couldn't find in the database the column with name " << colNames[n]
57  << std::endl;
58  assert(0);
59  }
60  }
61 
62  rocs_.clear();
63 
64  for (unsigned int r = 1; r < tableMat.size(); r++) //Goes to every row of the Matrix
65  {
66  PixelROCName roc(tableMat[r][colM["ROC_NAME"]]);
67  unsigned int vsf;
68  vsf = atoi(tableMat[r][colM["MAXVSF"]].c_str());
69  rocs_[roc] = vsf;
70  }
71 } //end constructor
72 
73 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
74 
76  std::string mthn = "[PixelMaxVsf::PixelMaxVsf()]\t\t\t\t ";
77 
78  if (filename[filename.size() - 1] == 't') {
79  std::ifstream in(filename.c_str());
80 
81  if (!in.good()) {
82  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
83  throw std::runtime_error("Failed to open file " + filename);
84  } else {
85  std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
86  }
87 
88  if (in.eof()) {
89  std::cout << __LINE__ << "]\t" << mthn << "eof before reading anything!" << std::endl;
90  throw std::runtime_error("File appears to be empty: " + filename);
91  }
92 
93  rocs_.clear();
94 
95  std::string rocname;
96 
97  in >> rocname;
98  while (!in.eof()) {
99  //cout << "Read rocname:"<<rocname<<endl;
100  PixelROCName roc(rocname);
101  unsigned int vsf;
102  in >> vsf;
103  rocs_[roc] = vsf;
104  in >> rocname;
105  }
106  return;
107  } else {
108  assert(0);
109  }
110 }
111 
112 bool PixelMaxVsf::getVsf(PixelROCName roc, unsigned int &Vsf) const {
113  std::map<PixelROCName, unsigned int>::const_iterator itr = rocs_.find(roc);
114 
115  if (itr == rocs_.end()) {
116  return false;
117  }
118 
119  Vsf = itr->second;
120 
121  return true;
122 }
123 
124 void PixelMaxVsf::setVsf(PixelROCName roc, unsigned int Vsf) { rocs_[roc] = Vsf; }
125 
127  std::string mthn = "[PixelMaxVsf::writeASCII()]\t\t\t\t ";
128  if (!dir.empty())
129  dir += "/";
130  std::string filename = dir + "maxvsf.dat";
131 
132  std::ofstream out(filename.c_str(), std::ios_base::out);
133  if (!out) {
134  std::cout << __LINE__ << "]\t" << mthn << "Could not open file " << filename << " for write" << std::endl;
135  exit(1);
136  }
137 
138  std::map<PixelROCName, unsigned int>::const_iterator irocs = rocs_.begin();
139  for (; irocs != rocs_.end(); ++irocs) {
140  out << (irocs->first).rocname() << " " << irocs->second << endl;
141  }
142 
143  out.close();
144 }
145 
146 //=============================================================================================
148  int version,
150  std::ofstream *outstream,
151  std::ofstream *out1stream,
152  std::ofstream *out2stream) const {
153  std::string mthn = "[PixelMaxVsf::writeXMLHeader()]\t\t\t ";
154  std::stringstream maskFullPath;
155 
156  maskFullPath << path << "/Pixel_RocMaxVsf_" << PixelTimeFormatter::getmSecTime() << ".xml";
157  std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl;
158 
159  outstream->open(maskFullPath.str().c_str());
160 
161  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl;
162  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
163  *outstream << "" << std::endl;
164  *outstream << " <HEADER>" << std::endl;
165  *outstream << " <TYPE>" << std::endl;
166  *outstream << " <EXTENSION_TABLE_NAME>ROC_MAXVSF</EXTENSION_TABLE_NAME>" << std::endl;
167  *outstream << " <NAME>ROC MaxVsf Setting</NAME>" << std::endl;
168  *outstream << " </TYPE>" << std::endl;
169  *outstream << " <RUN>" << std::endl;
170  *outstream << " <RUN_TYPE>ROC MaxVsf Settings</RUN_TYPE>" << std::endl;
171  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl;
172  *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl;
173  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl;
174  *outstream << " </RUN>" << std::endl;
175  *outstream << " </HEADER>" << std::endl;
176  *outstream << "" << std::endl;
177  *outstream << " <DATA_SET>" << std::endl;
178  *outstream << "" << std::endl;
179  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl;
180  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl;
181  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl;
182  *outstream << "" << std::endl;
183  *outstream << " <PART>" << std::endl;
184  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl;
185  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl;
186  *outstream << " </PART>" << std::endl;
187 }
188 
189 //=============================================================================================
190 void PixelMaxVsf::writeXML(std::ofstream *outstream, std::ofstream *out1stream, std::ofstream *out2stream) const {
191  std::string mthn = "[PixelMaxVsf::writeXML()]\t\t\t ";
192 
193  std::map<PixelROCName, unsigned int>::const_iterator irocs = rocs_.begin();
194  for (; irocs != rocs_.end(); ++irocs) {
195  *outstream << " <DATA>" << std::endl;
196  *outstream << " <ROC_NAME>" << (irocs->first).rocname() << "</ROC_NAME>" << std::endl;
197  *outstream << " <MAXVSF>" << irocs->second << "</MAXVSF>" << std::endl;
198  *outstream << " </DATA>" << std::endl;
199  *outstream << std::endl;
200  }
201 }
202 
203 //=============================================================================================
204 void PixelMaxVsf::writeXMLTrailer(std::ofstream *outstream,
205  std::ofstream *out1stream,
206  std::ofstream *out2stream) const {
207  std::string mthn = "[PixelMaxVsf::writeXMLTrailer()]\t\t\t ";
208 
209  *outstream << " </DATA_SET>" << std::endl;
210  *outstream << "</ROOT>" << std::endl;
211 
212  outstream->close();
213  std::cout << __LINE__ << "]\t" << mthn << "Data written " << std::endl;
214 }
This file contains the base class for "pixel configuration data" management.
void writeASCII(std::string dir="") const override
Definition: PixelMaxVsf.cc:126
void setVsf(PixelROCName roc, unsigned int Vsf)
Definition: PixelMaxVsf.cc:124
static std::string getmSecTime(void)
static std::string getTime(void)
std::string getComment() const
void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
Definition: PixelMaxVsf.cc:204
PixelMaxVsf(std::vector< std::vector< std::string > > &tableMat)
Definition: PixelMaxVsf.cc:21
This class provides utility methods to manipulate ASCII formatted timestamps.
std::map< PixelROCName, unsigned int > rocs_
Definition: PixelMaxVsf.h:49
std::string getAuthor() const
bool getVsf(PixelROCName roc, unsigned int &Vsf) const
Definition: PixelMaxVsf.cc:112
This class implements..
void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
Definition: PixelMaxVsf.cc:147
This class implements..
Definition: PixelROCName.h:23
This class specifies the maximum Vsf setting that should be used for each ROC.
void writeXML(pos::PixelConfigKey key, int version, std::string path) const override
Definition: PixelMaxVsf.h:32
def exit(msg="")