Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "CalibFormats/SiPixelObjects/interface/PixelMaxVsf.h"
00009 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
00010 #include <fstream>
00011 #include <iostream>
00012 #include <sstream>
00013 #include <ios>
00014 #include <assert.h>
00015 #include <stdio.h>
00016 #include <stdexcept>
00017
00018 using namespace std;
00019 using namespace pos;
00020
00021
00022 PixelMaxVsf::PixelMaxVsf(std::vector< std::vector< std::string > > &tableMat):PixelConfigBase("","","")
00023 {
00024 std::string mthn = "[PixelMaxVsf::PixelMaxVsf()]\t\t\t\t " ;
00025 std::map<std::string , int > colM;
00026 std::vector<std::string > colNames;
00040 colNames.push_back("CONFIG_KEY" );
00041 colNames.push_back("KEY_TYPE" );
00042 colNames.push_back("KEY_ALIAS" );
00043 colNames.push_back("VERSION" );
00044 colNames.push_back("KIND_OF_COND");
00045 colNames.push_back("ROC_NAME" );
00046 colNames.push_back("MAXVSF" );
00047
00048 for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
00049 {
00050 for(unsigned int n=0; n<colNames.size(); n++)
00051 {
00052 if(tableMat[0][c] == colNames[n])
00053 {
00054 colM[colNames[n]] = c;
00055 break;
00056 }
00057 }
00058 }
00059 for(unsigned int n=0; n<colNames.size(); n++)
00060 {
00061 if(colM.find(colNames[n]) == colM.end())
00062 {
00063 std::cerr << __LINE__ << "]\t" << mthn << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
00064 assert(0);
00065 }
00066 }
00067
00068 rocs_.clear();
00069
00070 for(unsigned int r = 1 ; r < tableMat.size() ; r++)
00071 {
00072 PixelROCName roc(tableMat[r][colM["ROC_NAME"]]);
00073 unsigned int vsf;
00074 vsf = atoi(tableMat[r][colM["MAXVSF"]].c_str());
00075 rocs_[roc]=vsf;
00076 }
00077 }
00078
00079
00080
00081 PixelMaxVsf::PixelMaxVsf(std::string filename):
00082 PixelConfigBase("","",""){
00083
00084 std::string mthn = "[PixelMaxVsf::PixelMaxVsf()]\t\t\t\t " ;
00085
00086 if (filename[filename.size()-1]=='t'){
00087
00088 std::ifstream in(filename.c_str());
00089
00090 if (!in.good()){
00091 std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
00092 throw std::runtime_error("Failed to open file "+filename);
00093 }
00094 else {
00095 std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
00096 }
00097
00098 if (in.eof()){
00099 std::cout << __LINE__ << "]\t" << mthn << "eof before reading anything!" << std::endl;
00100 throw std::runtime_error("File appears to be empty: "+filename);
00101 }
00102
00103
00104 rocs_.clear();
00105
00106 std::string rocname;
00107
00108 in >> rocname;
00109 while (!in.eof()){
00110
00111 PixelROCName roc(rocname);
00112 unsigned int vsf;
00113 in >> vsf;
00114 rocs_[roc]=vsf;
00115 in >> rocname;
00116 }
00117 return;
00118 }
00119 else{
00120 assert(0);
00121 }
00122
00123 }
00124
00125 bool PixelMaxVsf::getVsf(PixelROCName roc, unsigned int& Vsf) const{
00126
00127 std::map<PixelROCName,unsigned int>::const_iterator itr = rocs_.find(roc);
00128
00129 if (itr==rocs_.end()) {
00130 return false;
00131 }
00132
00133 Vsf=itr->second;
00134
00135 return true;
00136
00137 }
00138
00139
00140 void PixelMaxVsf::setVsf(PixelROCName roc, unsigned int Vsf){
00141
00142 rocs_[roc]=Vsf;
00143
00144 }
00145
00146
00147
00148 void PixelMaxVsf::writeASCII(std::string dir) const {
00149
00150 std::string mthn = "[PixelMaxVsf::writeASCII()]\t\t\t\t " ;
00151 if (dir!="") dir+="/";
00152 std::string filename=dir+"maxvsf.dat";
00153
00154 std::ofstream out(filename.c_str(), std::ios_base::out) ;
00155 if(!out) {
00156 std::cout << __LINE__ << "]\t" << mthn << "Could not open file " << filename << " for write" << std::endl ;
00157 exit(1);
00158 }
00159
00160
00161 std::map<PixelROCName, unsigned int>::const_iterator irocs = rocs_.begin();
00162 for(; irocs != rocs_.end() ; irocs++){
00163 out << (irocs->first).rocname() << " " << irocs->second << endl ;
00164 }
00165
00166 out.close();
00167
00168 }
00169
00170
00171 void PixelMaxVsf::writeXMLHeader(pos::PixelConfigKey key,
00172 int version,
00173 std::string path,
00174 std::ofstream *outstream,
00175 std::ofstream *out1stream,
00176 std::ofstream *out2stream) const
00177 {
00178 std::string mthn = "[PixelMaxVsf::writeXMLHeader()]\t\t\t " ;
00179 std::stringstream maskFullPath ;
00180
00181 maskFullPath << path << "/Pixel_RocMaxVsf_" << PixelTimeFormatter::getmSecTime() << ".xml";
00182 std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl ;
00183
00184 outstream->open(maskFullPath.str().c_str()) ;
00185
00186 *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl ;
00187 *outstream << "<ROOT xmlns:xsi='https://www.w3.org/2001/XMLSchema-instance'>" << std::endl ;
00188 *outstream << "" << std::endl ;
00189 *outstream << " <HEADER>" << std::endl ;
00190 *outstream << " <TYPE>" << std::endl ;
00191 *outstream << " <EXTENSION_TABLE_NAME>ROC_MAXVSF</EXTENSION_TABLE_NAME>" << std::endl ;
00192 *outstream << " <NAME>ROC MaxVsf Setting</NAME>" << std::endl ;
00193 *outstream << " </TYPE>" << std::endl ;
00194 *outstream << " <RUN>" << std::endl ;
00195 *outstream << " <RUN_TYPE>ROC MaxVsf Settings</RUN_TYPE>" << std::endl ;
00196 *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl ;
00197 *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
00198 *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl ;
00199 *outstream << " </RUN>" << std::endl ;
00200 *outstream << " </HEADER>" << std::endl ;
00201 *outstream << "" << std::endl ;
00202 *outstream << " <DATA_SET>" << std::endl ;
00203 *outstream << "" << std::endl ;
00204 *outstream << " <VERSION>" << version << "</VERSION>" << std::endl ;
00205 *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl ;
00206 *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl ;
00207 *outstream << "" << std::endl ;
00208 *outstream << " <PART>" << std::endl ;
00209 *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl ;
00210 *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl ;
00211 *outstream << " </PART>" << std::endl ;
00212
00213 }
00214
00215
00216 void PixelMaxVsf::writeXML( std::ofstream *outstream,
00217 std::ofstream *out1stream,
00218 std::ofstream *out2stream) const
00219 {
00220 std::string mthn = "[PixelMaxVsf::writeXML()]\t\t\t " ;
00221
00222 std::map<PixelROCName, unsigned int>::const_iterator irocs = rocs_.begin();
00223 for(; irocs != rocs_.end() ; irocs++){
00224 *outstream << " <DATA>" << std::endl ;
00225 *outstream << " <ROC_NAME>" << (irocs->first).rocname() << "</ROC_NAME>" << std::endl ;
00226 *outstream << " <MAXVSF>" << irocs->second << "</MAXVSF>" << std::endl ;
00227 *outstream << " </DATA>" << std::endl ;
00228 *outstream << std::endl ;
00229 }
00230 }
00231
00232
00233 void PixelMaxVsf::writeXMLTrailer(std::ofstream *outstream,
00234 std::ofstream *out1stream,
00235 std::ofstream *out2stream ) const
00236 {
00237 std::string mthn = "[PixelMaxVsf::writeXMLTrailer()]\t\t\t " ;
00238
00239 *outstream << " </DATA_SET>" << std::endl ;
00240 *outstream << "</ROOT>" << std::endl ;
00241
00242 outstream->close() ;
00243 std::cout << __LINE__ << "]\t" << mthn << "Data written " << std::endl ;
00244
00245 }