00001
00002
00003
00004
00005
00006
00007 #include "CalibFormats/SiPixelObjects/interface/PixelFECConfig.h"
00008 #include <fstream>
00009 #include <map>
00010 #include <assert.h>
00011
00012 using namespace pos;
00013 using namespace std;
00014
00015
00016
00017 PixelFECConfig::PixelFECConfig(std::vector<std::vector<std::string> >& tableMat ) : PixelConfigBase(" "," "," "){
00018
00019 std::map<std::string , int > colM;
00020 std::vector<std::string > colNames;
00032 colNames.push_back("CONFIG_KEY_ID" );
00033 colNames.push_back("CONFIG_KEY" );
00034 colNames.push_back("VERSION" );
00035 colNames.push_back("KIND_OF_COND" );
00036 colNames.push_back("PIXEL_FEC" );
00037 colNames.push_back("CRATE" );
00038 colNames.push_back("SLOT_NUMBER" );
00039 colNames.push_back("VME_ADDRS_HEX" );
00040
00041
00042 for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
00043 {
00044 for(unsigned int n=0; n<colNames.size(); n++)
00045 {
00046 if(tableMat[0][c] == colNames[n]){
00047 colM[colNames[n]] = c;
00048 break;
00049 }
00050 }
00051 }
00052 for(unsigned int n=0; n<colNames.size(); n++)
00053 {
00054 if(colM.find(colNames[n]) == colM.end()){
00055 std::cerr << "[PixelFECConfig::PixelFECConfig()]\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
00056 assert(0);
00057 }
00058 }
00059
00060 fecconfig_.clear();
00061 for(unsigned int r = 1 ; r < tableMat.size() ; r++)
00062 {
00063 unsigned int fecnumber;
00064 unsigned int crate;
00065 unsigned int vme_base_address;
00066
00067
00068
00069 string fullFECName = tableMat[r][colM["PIXEL_FEC"]] ;
00070 fullFECName.replace(0,13,"") ;
00071 fecnumber = atoi(fullFECName.c_str()) ;
00072 crate = atoi(tableMat[r][colM["CRATE"]].c_str()) ;
00073 string hexVMEAddr = tableMat[r][colM["VME_ADDRS_HEX"]] ;
00074 sscanf(hexVMEAddr.c_str(), "%x", &vme_base_address) ;
00075 PixelFECParameters tmp;
00076
00077 tmp.setFECParameters(fecnumber , crate , vme_base_address);
00078
00079 fecconfig_.push_back(tmp);
00080 }
00081
00082 }
00083
00084
00085
00086
00087 PixelFECConfig::PixelFECConfig(std::string filename):
00088 PixelConfigBase(" "," "," "){
00089
00090 std::ifstream in(filename.c_str());
00091
00092 if (!in.good()){
00093 std::cout << "[PixelFECConfig::PixelFECConfig()]\t\t\t Could not open: "<<filename<<std::endl;
00094 assert(0);
00095 }
00096 else {
00097 std::cout << "[PixelFECConfig::PixelFECConfig()]\t\t\t Opened: "<<filename<<std::endl;
00098 }
00099
00100 std::string dummy;
00101
00102 in >> dummy;
00103 in >> dummy;
00104 in >> dummy;
00105 in >> dummy;
00106 in >> dummy;
00107 in >> dummy;
00108
00109 do {
00110
00111 unsigned int fecnumber;
00112 unsigned int crate;
00113 unsigned int vme_base_address;
00114
00115 in >> fecnumber >> crate >> std::hex>> vme_base_address >>std::dec ;
00116
00117 if (!in.eof() ){
00118
00119
00120
00121 PixelFECParameters tmp;
00122
00123 tmp.setFECParameters(fecnumber , crate , vme_base_address);
00124
00125 fecconfig_.push_back(tmp);
00126 }
00127
00128 }
00129 while (!in.eof());
00130 in.close();
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 unsigned int PixelFECConfig::getNFECBoards() const{
00145
00146 return fecconfig_.size();
00147
00148 }
00149
00150 unsigned int PixelFECConfig::getFECNumber(unsigned int i) const{
00151
00152 assert(i<fecconfig_.size());
00153 return fecconfig_[i].getFECNumber();
00154
00155 }
00156
00157
00158 unsigned int PixelFECConfig::getCrate(unsigned int i) const{
00159
00160 assert(i<fecconfig_.size());
00161 return fecconfig_[i].getCrate();
00162
00163 }
00164
00165
00166 unsigned int PixelFECConfig::getVMEBaseAddress(unsigned int i) const{
00167
00168 assert(i<fecconfig_.size());
00169 return fecconfig_[i].getVMEBaseAddress();
00170
00171 }
00172
00173
00174 unsigned int PixelFECConfig::crateFromFECNumber(unsigned int fecnumber) const{
00175
00176 for(unsigned int i=0;i<fecconfig_.size();i++){
00177 if (fecconfig_[i].getFECNumber()==fecnumber) return fecconfig_[i].getCrate();
00178 }
00179
00180 std::cout << "Could not find FEC number:"<<fecnumber<<std::endl;
00181
00182 assert(0);
00183
00184 return 0;
00185
00186 }
00187
00188 unsigned int PixelFECConfig::VMEBaseAddressFromFECNumber(unsigned int fecnumber) const{
00189
00190 for(unsigned int i=0;i<fecconfig_.size();i++){
00191 if (fecconfig_[i].getFECNumber()==fecnumber) return fecconfig_[i].getVMEBaseAddress();
00192 }
00193
00194 std::cout << "Could not find FEC number:"<<fecnumber<<std::endl;
00195
00196 assert(0);
00197
00198 return 0;
00199
00200 }
00201
00202 void PixelFECConfig::writeASCII(std::string dir) const {
00203
00204 if (dir!="") dir+="/";
00205 std::string filename=dir+"fecconfig.dat";
00206 std::ofstream out(filename.c_str());
00207
00208 std::vector< PixelFECParameters >::const_iterator i=fecconfig_.begin();
00209
00210 out << "#FEC number crate vme base address" << endl;
00211 for(;i!=fecconfig_.end();++i){
00212 out << i->getFECNumber()<<" "
00213 << i->getCrate()<<" "
00214 << "0x"<<hex<<i->getVMEBaseAddress()<<dec<<endl;
00215 }
00216
00217 }