CMS 3D CMS Logo

PixelLTCConfig.cc
Go to the documentation of this file.
1 //
2 // This class reads the LTC configuration file
3 //
4 //
5 //
6 
9 #include <sstream>
10 #include <cassert>
11 #include <stdexcept>
12 
13 using namespace pos;
14 using namespace std;
15 
16 PixelLTCConfig::PixelLTCConfig(vector< vector<string> > &tableMat):PixelConfigBase(" ", " ", " ")
17 {
18  std::string mthn = "[PixelLTCConfig::PixelLTCConfig()]\t\t\t " ;
19  std::map<std::string , int > colM;
20  std::vector<std::string > colNames;
33  colNames.push_back("CONFIG_KEY" );
34  colNames.push_back("KEY_TYPE" );
35  colNames.push_back("KEY_ALIAS" );
36  colNames.push_back("VERSION" );
37  colNames.push_back("KIND_OF_COND" );
38  colNames.push_back("LTC_OBJ_DATA_FILE");
39  colNames.push_back("LTC_OBJ_DATA_CLOB");
40 
41  for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
42  {
43  for(unsigned int n=0; n<colNames.size(); n++)
44  {
45  if(tableMat[0][c] == colNames[n])
46  {
47  colM[colNames[n]] = c;
48  break;
49  }
50  }
51  }//end for
52  for(unsigned int n=0; n<colNames.size(); n++)
53  {
54  if(colM.find(colNames[n]) == colM.end())
55  {
56  std::cerr << __LINE__ << "]\t" << mthn << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
57  assert(0);
58  }
59  }
60  ltcConfigStream_ << tableMat[1][colM["LTC_OBJ_DATA_CLOB"]] ;
61 // cout << "[PixelTTCciConfig::PixelTTCciConfig()]\tRead: "<< endl<< ttcConfigStream_.str() << endl ;
62 }
63 
65  PixelConfigBase(" "," "," "){
66 
67  std::string mthn = "[PixelLTCConfig::PixelLTCConfig()]\t\t\t " ;
68  std::ifstream in(filename.c_str());
69 
70  if (!in.good()){
71  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
72  throw std::runtime_error("Failed to open file "+filename);
73  }
74  else {
75  std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
76  }
77 
78  //ltcConfigPath_ = filename;
79  string line;
80  while (!in.eof()) {
81  getline (in,line);
82  ltcConfigStream_ << line << endl;
83  }
84 
85 }
86 
88 
89  if (dir!="") dir+="/";
90  std::string filename=dir+"LTCConfiguration.txt";
91  std::ofstream out(filename.c_str());
92 
93  //std::ifstream in(ltcConfigPath_.c_str());
94  //assert(in.good());
95 
96  string configstr = ltcConfigStream_.str();
97 
98  out << configstr << endl;
99 
100  out.close();
101 
102 }
103 
104 //=============================================================================================
106  int version,
107  std::string path,
108  std::ofstream *outstream,
109  std::ofstream *out1stream,
110  std::ofstream *out2stream) const
111 {
112  std::string mthn = "[PixelLTCConfig::writeXMLHeader()]\t\t\t " ;
113  std::stringstream maskFullPath ;
114 
115  writeASCII(path) ;
116 
117  maskFullPath << path << "/Pixel_LtcParameters_" << PixelTimeFormatter::getmSecTime() << ".xml";
118  std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl ;
119 
120  outstream->open(maskFullPath.str().c_str()) ;
121 
122  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl ;
123  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl ;
124  *outstream << "" << std::endl ;
125  *outstream << " <HEADER>" << std::endl ;
126  *outstream << " <TYPE>" << std::endl ;
127  *outstream << " <EXTENSION_TABLE_NAME>PIXEL_LTC_PARAMETERS</EXTENSION_TABLE_NAME>" << std::endl ;
128  *outstream << " <NAME>LTC Configuration Parameters</NAME>" << std::endl ;
129  *outstream << " </TYPE>" << std::endl ;
130  *outstream << " <RUN>" << std::endl ;
131  *outstream << " <RUN_TYPE>LTC Configuration Parameters</RUN_TYPE>" << std::endl ;
132  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl ;
133  *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
134  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl ;
135  *outstream << " </RUN>" << std::endl ;
136  *outstream << " </HEADER>" << std::endl ;
137  *outstream << "" << std::endl ;
138  *outstream << " <DATA_SET>" << std::endl ;
139  *outstream << "" << std::endl ;
140  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl ;
141  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl ;
142  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl ;
143  *outstream << "" << std::endl ;
144  *outstream << " <PART>" << std::endl ;
145  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl ;
146  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl ;
147  *outstream << " </PART>" << std::endl ;
148 
149 }
150 
151 //=============================================================================================
152 void PixelLTCConfig::writeXML( std::ofstream *outstream,
153  std::ofstream *out1stream,
154  std::ofstream *out2stream) const
155 {
156  std::string mthn = "[PixelLTCConfig::writeXML()]\t\t\t " ;
157 
158  *outstream << " <DATA>" << std::endl ;
159  *outstream << " <LTC_OBJ_DATA_FILE>./LTCConfiguration.txt</LTC_OBJ_DATA_FILE>" << std::endl ;
160  *outstream << " </DATA>" << std::endl ;
161 }
162 
163 //=============================================================================================
164 void PixelLTCConfig::writeXMLTrailer(std::ofstream *outstream,
165  std::ofstream *out1stream,
166  std::ofstream *out2stream ) const
167 {
168  std::string mthn = "[PixelLTCConfig::writeXMLTrailer()]\t\t\t " ;
169 
170  *outstream << " </DATA_SET>" << std::endl ;
171  *outstream << "</ROOT>" << std::endl ;
172 
173  outstream->close() ;
174  std::cout << __LINE__ << "]\t" << mthn << "Data written " << std::endl ;
175 
176 }
177 
178 
179 
This file contains the base class for "pixel configuration data" management.
std::stringstream ltcConfigStream_
PixelLTCConfig(std::vector< std::vector< std::string > > &tableMat)
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)
void writeXML(pos::PixelConfigKey key, int version, std::string path) const
static std::string getTime(void)
std::string getComment() const
This class provides utility methods to manipulate ASCII formatted timestamps.
std::string getAuthor() const
virtual void writeASCII(std::string dir) const
This class implements..
dbl *** dir
Definition: mlp_gen.cc:35