Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "CalibFormats/SiPixelObjects/interface/PixelFEDConfig.h"
00008 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
00009 #include <fstream>
00010 #include <iostream>
00011 #include <map>
00012 #include <assert.h>
00013 #include <stdexcept>
00014
00015 using namespace pos;
00016 using namespace std;
00017
00018 PixelFEDConfig::PixelFEDConfig(std::vector<std::vector<std::string> >& tableMat ) : PixelConfigBase(" "," "," "){
00019
00020 std::string mthn = "[PixelFEDConfig::PixelFEDConfig()]\t\t\t " ;
00021
00022 std::vector< std::string > ins = tableMat[0];
00023 std::map<std::string , int > colM;
00024 std::vector<std::string > colNames;
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 colNames.push_back("CONFIG_KEY" );
00039 colNames.push_back("KEY_TYPE" );
00040 colNames.push_back("KEY_ALIAS" );
00041 colNames.push_back("VERSION" );
00042 colNames.push_back("KIND_OF_COND" );
00043 colNames.push_back("PIXEL_FED" );
00044 colNames.push_back("CRATE_NUMBER" );
00045 colNames.push_back("VME_ADDR" );
00046
00047
00048
00049
00050
00051 for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
00052 {
00053 for(unsigned int n=0; n<colNames.size(); n++)
00054 {
00055 if(tableMat[0][c] == colNames[n])
00056 {
00057 colM[colNames[n]] = c;
00058 break;
00059 }
00060 }
00061 }
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 std::string fedname = "";
00074 unsigned int fednum = 0;
00075 fedconfig_.clear();
00076 bool flag = false;
00077 for(unsigned int r = 1 ; r < tableMat.size() ; r++){
00078
00079 fedname = tableMat[r][colM["PIXEL_FED"]];
00080
00081
00082
00083
00084 fednum = (unsigned int)atoi(fedname.c_str()) ;
00085
00086 if(fedconfig_.empty())
00087 {
00088 PixelFEDParameters tmp;
00089 unsigned int vme_base_address = 0 ;
00090 vme_base_address = strtoul(tableMat[r][colM["VME_ADDR"]].c_str(), 0, 16);
00091
00092
00093 tmp.setFEDParameters( fednum, (unsigned int)atoi(tableMat[r][colM["CRATE_NUMBER"]].c_str()) ,
00094 vme_base_address);
00095 fedconfig_.push_back(tmp);
00096 }
00097 else
00098 {
00099 for( unsigned int y = 0; y < fedconfig_.size() ; y++)
00100 {
00101 if (fedconfig_[y].getFEDNumber() == fednum)
00102 {
00103 flag = true;
00104 break;
00105 }
00106 else flag = false;
00107 }
00108
00109 if(flag == false)
00110 {
00111 PixelFEDParameters tmp;
00112 tmp.setFEDParameters( fednum, (unsigned int)atoi(tableMat[r][colM["CRATE_NUMBER"]].c_str()) ,
00113 (unsigned int)strtoul(tableMat[r][colM["VME_ADDR"]].c_str(), 0, 16));
00114 fedconfig_.push_back(tmp);
00115 }
00116 }
00117 }
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137 PixelFEDConfig::PixelFEDConfig(std::string filename):
00138 PixelConfigBase(" "," "," "){
00139
00140 std::string mthn = "[PixelFEDConfig::PixelFEDConfig()]\t\t\t " ;
00141 std::ifstream in(filename.c_str());
00142
00143 if (!in.good()){
00144 std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename.c_str() << std::endl;
00145 throw std::runtime_error("Failed to open file "+filename);
00146 }
00147 else {
00148 std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename.c_str() << std::endl;
00149 }
00150
00151 std::string dummy;
00152
00153 in >> dummy;
00154 in >> dummy;
00155 in >> dummy;
00156 in >> dummy;
00157 in >> dummy;
00158 in >> dummy;
00159
00160 do {
00161
00162 unsigned int fednumber;
00163 unsigned int crate;
00164 unsigned int vme_base_address;
00165
00166 in >> fednumber >> crate >> std::hex >> vme_base_address >> std::dec;
00167
00168 if (!in.eof() ){
00169
00170
00171 PixelFEDParameters tmp;
00172
00173 tmp.setFEDParameters(fednumber , crate , vme_base_address);
00174
00175 fedconfig_.push_back(tmp);
00176 }
00177
00178 }
00179 while (!in.eof());
00180 in.close();
00181
00182 }
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 PixelFEDConfig::~PixelFEDConfig() {}
00194
00195 void PixelFEDConfig::writeASCII(std::string dir) const {
00196
00197 std::string mthn = "[PixelFEDConfig::writeASCII()]\t\t\t\t " ;
00198 if (dir!="") dir+="/";
00199 string filename=dir+"fedconfig.dat";
00200
00201 ofstream out(filename.c_str());
00202 if(!out.good()){
00203 cout << __LINE__ << "]\t" << mthn << "Could not open file: " << filename << endl;
00204 assert(0);
00205 }
00206
00207 out <<" #FED number crate vme base address" <<endl;
00208 for(unsigned int i=0;i<fedconfig_.size();i++){
00209 out << fedconfig_[i].getFEDNumber()<<" "
00210 << fedconfig_[i].getCrate()<<" "
00211 << "0x"<<hex<<fedconfig_[i].getVMEBaseAddress()<<dec<<endl;
00212 }
00213 out.close();
00214 }
00215
00216
00217 unsigned int PixelFEDConfig::getNFEDBoards() const{
00218
00219 return fedconfig_.size();
00220
00221 }
00222
00223 unsigned int PixelFEDConfig::getFEDNumber(unsigned int i) const{
00224
00225 assert(i<fedconfig_.size());
00226 return fedconfig_[i].getFEDNumber();
00227
00228 }
00229
00230
00231 unsigned int PixelFEDConfig::getCrate(unsigned int i) const{
00232
00233 assert(i<fedconfig_.size());
00234 return fedconfig_[i].getCrate();
00235
00236 }
00237
00238
00239 unsigned int PixelFEDConfig::getVMEBaseAddress(unsigned int i) const{
00240
00241 assert(i<fedconfig_.size());
00242 return fedconfig_[i].getVMEBaseAddress();
00243
00244 }
00245
00246
00247 unsigned int PixelFEDConfig::crateFromFEDNumber(unsigned int fednumber) const{
00248
00249
00250 std::string mthn = "[PixelFEDConfig::crateFromFEDNumber()]\t\t\t " ;
00251 for(unsigned int i=0;i<fedconfig_.size();i++){
00252 if (fedconfig_[i].getFEDNumber()==fednumber) return fedconfig_[i].getCrate();
00253 }
00254
00255 std::cout << __LINE__ << "]\t" << mthn << "Could not find FED number: " << fednumber << std::endl;
00256
00257 assert(0);
00258
00259 return 0;
00260
00261 }
00262
00263
00264 unsigned int PixelFEDConfig::VMEBaseAddressFromFEDNumber(unsigned int fednumber) const{
00265
00266 std::string mthn = "[PixelFEDConfig::VMEBaseAddressFromFEDNumber()]\t\t " ;
00267 for(unsigned int i=0;i<fedconfig_.size();i++){
00268 if (fedconfig_[i].getFEDNumber()==fednumber) return fedconfig_[i].getVMEBaseAddress();
00269 }
00270
00271 std::cout << __LINE__ << "]\t" << mthn << "Could not find FED number: " << fednumber << std::endl;
00272
00273 assert(0);
00274
00275 return 0;
00276
00277 }
00278
00279 unsigned int PixelFEDConfig::FEDNumberFromCrateAndVMEBaseAddress(unsigned int crate, unsigned int vmebaseaddress) const {
00280
00281 std::string mthn = "[PixelFEDConfig::FEDNumberFromCrateAndVMEBaseAddress()]\t " ;
00282 for(unsigned int i=0;i<fedconfig_.size();i++){
00283 if (fedconfig_[i].getCrate()==crate&&
00284 fedconfig_[i].getVMEBaseAddress()==vmebaseaddress) return fedconfig_[i].getFEDNumber();
00285 }
00286
00287 std::cout << __LINE__ << "]\t" << mthn << "Could not find FED crate and address: "<< crate << ", " << vmebaseaddress << std::endl;
00288
00289 assert(0);
00290
00291 return 0;
00292
00293 }
00294
00295
00296 void PixelFEDConfig::writeXMLHeader(pos::PixelConfigKey key,
00297 int version,
00298 std::string path,
00299 std::ofstream *outstream,
00300 std::ofstream *out1stream,
00301 std::ofstream *out2stream) const
00302 {
00303 std::string mthn = "[PixelFEDConfig::::writeXMLHeader()]\t\t\t " ;
00304 std::stringstream fullPath ;
00305 fullPath << path << "/Pixel_FedCrateConfig_" << PixelTimeFormatter::getmSecTime() << ".xml" ;
00306 cout << __LINE__ << "]\t" << mthn << "Writing to: " << fullPath.str() << endl ;
00307
00308 outstream->open(fullPath.str().c_str()) ;
00309 *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << endl ;
00310 *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << endl ;
00311 *outstream << " <HEADER>" << endl ;
00312 *outstream << " <TYPE>" << endl ;
00313 *outstream << " <EXTENSION_TABLE_NAME>FED_CRATE_CONFIG</EXTENSION_TABLE_NAME>" << endl ;
00314 *outstream << " <NAME>Pixel FED Crate Configuration</NAME>" << endl ;
00315 *outstream << " </TYPE>" << endl ;
00316 *outstream << " <RUN>" << endl ;
00317 *outstream << " <RUN_NAME>Pixel FED Crate Configuration</RUN_NAME>" << endl ;
00318 *outstream << " <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << endl ;
00319 *outstream << " <LOCATION>CERN P5</LOCATION>" << endl ;
00320 *outstream << " </RUN>" << endl ;
00321 *outstream << " </HEADER>" << endl ;
00322 *outstream << " " << endl ;
00323 *outstream << " <DATA_SET>" << endl ;
00324 *outstream << " <PART>" << endl ;
00325 *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << endl ;
00326 *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << endl ;
00327 *outstream << " </PART>" << endl ;
00328 *outstream << " <VERSION>" << version << "</VERSION>" << endl ;
00329 *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << endl ;
00330 *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << endl ;
00331 *outstream << " " << endl ;
00332 }
00333
00334
00335 void PixelFEDConfig::writeXML(std::ofstream *outstream,
00336 std::ofstream *out1stream,
00337 std::ofstream *out2stream) const
00338 {
00339 std::string mthn = "[PixelFEDConfig::writeXML()]\t\t\t " ;
00340
00341 for(unsigned int i=0;i<fedconfig_.size();i++){
00342 *outstream << " <DATA>" << endl ;
00343 *outstream << " <PIXEL_FED>" << fedconfig_[i].getFEDNumber() << "</PIXEL_FED>" << endl ;
00344 *outstream << " <CRATE_NUMBER>" << fedconfig_[i].getCrate() << "</CRATE_NUMBER>" << endl ;
00345 *outstream << " <VME_ADDR>" << "0x" << hex << fedconfig_[i].getVMEBaseAddress() << dec << "</VME_ADDR>" << endl ;
00346 *outstream << " </DATA>" << endl ;
00347 *outstream << "" << endl ;
00348 }
00349
00350 }
00351
00352
00353 void PixelFEDConfig::writeXMLTrailer(std::ofstream *outstream,
00354 std::ofstream *out1stream,
00355 std::ofstream *out2stream) const
00356 {
00357 std::string mthn = "[PixelFEDConfig::writeXMLTrailer()]\t\t\t " ;
00358
00359 *outstream << " </DATA_SET>" << endl ;
00360 *outstream << "</ROOT> " << endl ;
00361
00362 outstream->close() ;
00363 }