Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "CalibFormats/SiPixelObjects/interface/PixelFECConfig.h"
00008 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
00009 #include <fstream>
00010 #include <sstream>
00011 #include <map>
00012 #include <assert.h>
00013 #include <stdexcept>
00014
00015 using namespace pos;
00016 using namespace std;
00017
00018
00019
00020 PixelFECConfig::PixelFECConfig(std::vector<std::vector<std::string> >& tableMat ) : PixelConfigBase(" "," "," "){
00021
00022 std::map<std::string , int > colM;
00023 std::vector<std::string > colNames;
00039 colNames.push_back("CONFIG_KEY" );
00040 colNames.push_back("KEY_TYPE" );
00041 colNames.push_back("KEY_ALIAS" );
00042 colNames.push_back("VERSION" );
00043 colNames.push_back("KIND_OF_COND" );
00044 colNames.push_back("PIXFEC_NAME" );
00045 colNames.push_back("CRATE_NUMBER" );
00046 colNames.push_back("SLOT_NUMBER" );
00047 colNames.push_back("VME_ADDR" );
00048
00049 for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
00050 {
00051 for(unsigned int n=0; n<colNames.size(); n++)
00052 {
00053 if(tableMat[0][c] == colNames[n]){
00054 colM[colNames[n]] = c;
00055 break;
00056 }
00057 }
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 fecconfig_.clear();
00070 for(unsigned int r = 1 ; r < tableMat.size() ; r++)
00071 {
00072 unsigned int fecnumber;
00073 unsigned int crate;
00074 unsigned int vme_base_address;
00075
00076
00077
00078
00079
00080 fecnumber = atoi(tableMat[r][colM["PIXFEC_NAME"]].c_str()) ;
00081 crate = atoi(tableMat[r][colM["CRATE_NUMBER"]].c_str()) ;
00082 string hexVMEAddr = tableMat[r][colM["VME_ADDR"]] ;
00083 sscanf(hexVMEAddr.c_str(), "%x", &vme_base_address) ;
00084 PixelFECParameters tmp;
00085
00086 tmp.setFECParameters(fecnumber , crate , vme_base_address);
00087
00088 fecconfig_.push_back(tmp);
00089 }
00090
00091 }
00092
00093
00094
00095
00096 PixelFECConfig::PixelFECConfig(std::string filename):
00097 PixelConfigBase(" "," "," "){
00098
00099 std::string mthn = "[[PixelFECConfig::PixelFECConfig()]\t\t\t " ;
00100
00101 std::ifstream in(filename.c_str());
00102
00103 if (!in.good()){
00104 std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
00105 throw std::runtime_error("Failed to open file "+filename);
00106 }
00107 else {
00108 std::cout << __LINE__ << "]\t" << mthn <<" Opened: " << filename << std::endl;
00109 }
00110
00111 std::string dummy;
00112
00113 in >> dummy;
00114 in >> dummy;
00115 in >> dummy;
00116 in >> dummy;
00117 in >> dummy;
00118 in >> dummy;
00119
00120 do {
00121
00122 unsigned int fecnumber;
00123 unsigned int crate;
00124 unsigned int vme_base_address;
00125
00126 in >> fecnumber >> crate >> std::hex>> vme_base_address >>std::dec ;
00127
00128 if (!in.eof() ){
00129
00130
00131
00132 PixelFECParameters tmp;
00133
00134 tmp.setFECParameters(fecnumber , crate , vme_base_address);
00135
00136 fecconfig_.push_back(tmp);
00137 }
00138
00139 }
00140 while (!in.eof());
00141 in.close();
00142 }
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 unsigned int PixelFECConfig::getNFECBoards() const{
00156
00157 return fecconfig_.size();
00158
00159 }
00160
00161 unsigned int PixelFECConfig::getFECNumber(unsigned int i) const{
00162
00163 assert(i<fecconfig_.size());
00164 return fecconfig_[i].getFECNumber();
00165
00166 }
00167
00168
00169 unsigned int PixelFECConfig::getCrate(unsigned int i) const{
00170
00171 assert(i<fecconfig_.size());
00172 return fecconfig_[i].getCrate();
00173
00174 }
00175
00176
00177 unsigned int PixelFECConfig::getVMEBaseAddress(unsigned int i) const{
00178
00179 assert(i<fecconfig_.size());
00180 return fecconfig_[i].getVMEBaseAddress();
00181
00182 }
00183
00184
00185 unsigned int PixelFECConfig::crateFromFECNumber(unsigned int fecnumber) const{
00186
00187 std::string mthn = "[PixelFECConfig::crateFromFECNumber()]\t\t\t " ;
00188 for(unsigned int i=0;i<fecconfig_.size();i++){
00189 if (fecconfig_[i].getFECNumber()==fecnumber) return fecconfig_[i].getCrate();
00190 }
00191
00192 std::cout << __LINE__ << "]\t" << mthn << "Could not find FEC number: " << fecnumber << std::endl;
00193
00194 assert(0);
00195
00196 return 0;
00197
00198 }
00199
00200 unsigned int PixelFECConfig::VMEBaseAddressFromFECNumber(unsigned int fecnumber) const{
00201
00202 std::string mthn = "[PixelFECConfig::VMEBaseAddressFromFECNumber()]\t\t " ;
00203 for(unsigned int i=0;i<fecconfig_.size();i++){
00204 if (fecconfig_[i].getFECNumber()==fecnumber) return fecconfig_[i].getVMEBaseAddress();
00205 }
00206
00207 std::cout << __LINE__ << "]\t" << mthn << "Could not find FEC number: " << fecnumber << std::endl;
00208
00209 assert(0);
00210
00211 return 0;
00212
00213 }
00214
00215
00216 void PixelFECConfig::writeASCII(std::string dir) const {
00217
00218 if (dir!="") dir+="/";
00219 std::string filename=dir+"fecconfig.dat";
00220 std::ofstream out(filename.c_str());
00221
00222 std::vector< PixelFECParameters >::const_iterator i=fecconfig_.begin();
00223
00224 out << "#FEC number crate vme base address" << endl;
00225 for(;i!=fecconfig_.end();++i){
00226 out << i->getFECNumber()<<" "
00227 << i->getCrate()<<" "
00228 << "0x"<<hex<<i->getVMEBaseAddress()<<dec<<endl;
00229 }
00230
00231 }
00232
00233
00234 void PixelFECConfig::writeXMLHeader(pos::PixelConfigKey key,
00235 int version,
00236 std::string path,
00237 std::ofstream *outstream,
00238 std::ofstream *out1stream,
00239 std::ofstream *out2stream) const
00240 {
00241 std::string mthn = "[PixelFECConfig::writeXMLHeader()]\t\t\t " ;
00242 std::stringstream fullPath ;
00243 fullPath << path << "/Pixel_PixelFecParameters_" << PixelTimeFormatter::getmSecTime() << ".xml" ;
00244 cout << __LINE__ << "]\t" << mthn << "Writing to: " << fullPath.str() << endl ;
00245
00246 outstream->open(fullPath.str().c_str()) ;
00247
00248 *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << endl ;
00249 *outstream << "<ROOT xmlns:xsi='https://www.w3.org/2001/XMLSchema-instance'>" << endl ;
00250 *outstream << " <HEADER>" << endl ;
00251 *outstream << " <TYPE>" << endl ;
00252 *outstream << " <EXTENSION_TABLE_NAME>PIXEL_FEC_PARAMETERS</EXTENSION_TABLE_NAME>" << endl ;
00253 *outstream << " <NAME>Pixel FEC Parameters</NAME>" << endl ;
00254 *outstream << " </TYPE>" << endl ;
00255 *outstream << " <RUN>" << endl ;
00256 *outstream << " <RUN_TYPE>Pixel FEC Parameters</RUN_TYPE>" << endl ;
00257 *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << endl ;
00258 *outstream << " <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << endl ;
00259 *outstream << " <LOCATION>CERN P5</LOCATION>" << endl ;
00260 *outstream << " </RUN>" << endl ;
00261 *outstream << " </HEADER>" << endl ;
00262 *outstream << "" << endl ;
00263 *outstream << " <DATA_SET>" << endl ;
00264 *outstream << " <PART>" << endl ;
00265 *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << endl ;
00266 *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << endl ;
00267 *outstream << " </PART>" << endl ;
00268 *outstream << " <VERSION>" << version << "</VERSION>" << endl ;
00269 *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << endl ;
00270 *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << endl ;
00271 }
00272
00273
00274 void PixelFECConfig::writeXML( std::ofstream *outstream,
00275 std::ofstream *out1stream,
00276 std::ofstream *out2stream) const
00277 {
00278 std::string mthn = "[PixelFECConfig::writeXML()]\t\t\t " ;
00279
00280 std::vector< PixelFECParameters >::const_iterator i=fecconfig_.begin();
00281
00282 for(;i!=fecconfig_.end();++i){
00283 *outstream << "" << endl ;
00284 *outstream << " <DATA>" << endl ;
00285 *outstream << " <PIXFEC_NAME>" << i->getFECNumber() << "</PIXFEC_NAME>" << endl ;
00286 *outstream << " <CRATE_NUMBER>" << i->getCrate() << "</CRATE_NUMBER>" << endl ;
00287 *outstream << " <VME_ADDR>0x" << hex << i->getVMEBaseAddress() << dec << "</VME_ADDR>" << endl ;
00288 *outstream << " </DATA>" << endl ;
00289 }
00290 }
00291
00292
00293 void PixelFECConfig::writeXMLTrailer(std::ofstream *outstream,
00294 std::ofstream *out1stream,
00295 std::ofstream *out2stream) const
00296 {
00297 std::string mthn = "[PixelFECConfig::writeXMLTrailer()]\t\t\t " ;
00298
00299 *outstream << "" << endl ;
00300 *outstream << " </DATA_SET>" << endl ;
00301 *outstream << "</ROOT> " << endl ;
00302
00303 outstream->close() ;
00304 }
00305