00001 #include "CalibFormats/SiPixelObjects/interface/PixelFEDTestDAC.h"
00002 #include <string.h>
00003 #include <cassert>
00004 #include <map>
00005 #include <sstream>
00006
00007 using namespace std;
00008
00009 using namespace pos;
00010
00011 PixelFEDTestDAC::PixelFEDTestDAC(std::vector<std::vector<std::string> > & tableMat ){
00012
00013 const unsigned long int UB=200;
00014 const unsigned long int B=500;
00015 const unsigned long int offset=0;
00016 vector <unsigned int> pulseTrain(256), pixelDCol(1), pixelPxl(2), pixelTBMHeader(3), pixelTBMTrailer(3);
00017 unsigned int DCol, LorR, start=15;
00018 std::string line;
00019 std::string::size_type loc1, loc2, loc3, loc4;
00020 unsigned long int npos=std::string::npos;
00021 int i;
00022
00023 std::map<std::string , int > colM;
00024 std::vector<std::string > colNames;
00038 colNames.push_back("CONFIG_KEY_ID" );
00039 colNames.push_back("CONFG_KEY" );
00040 colNames.push_back("VERSION" );
00041 colNames.push_back("KIND_OF_COND" );
00042 colNames.push_back("RUN_TYPE" );
00043 colNames.push_back("RUN_NUMBER" );
00044 colNames.push_back("CALIB_OBJ_DATA_FILE");
00045 colNames.push_back("CALIB_OBJ_DATA_CLOB");
00046
00047 for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
00048 {
00049 for(unsigned int n=0; n<colNames.size(); n++)
00050 {
00051 if(tableMat[0][c] == colNames[n])
00052 {
00053 colM[colNames[n]] = c;
00054 break;
00055 }
00056 }
00057 }
00058 for(unsigned int n=0; n<colNames.size(); n++)
00059 {
00060 if(colM.find(colNames[n]) == colM.end())
00061 {
00062 std::cerr << "[PixelMaxVsf::PixelMaxVsf()]\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
00063 assert(0);
00064 }
00065 }
00066
00067
00068 std::istringstream fin ;
00069 fin.str(tableMat[1][colM["CALIB_OBJ_DATA_CLOB"]]) ;
00070
00071
00072 for (unsigned int i=0;i<pulseTrain.size();++i)
00073 {
00074 pulseTrain[i]=offset+B;
00075 }
00076
00077 i=start;
00078
00079 getline(fin, line);
00080 mode_=line;
00081 assert(mode_=="EmulatedPhysics"||
00082 mode_=="FEDBaselineWithTestDACs"||
00083 mode_=="FEDAddressLevelWithTestDACs");
00084
00085 while (!fin.eof())
00086 {
00087 getline(fin, line);
00088
00089 if (line.find("TBMHeader")!=npos)
00090 {
00091 loc1=line.find("("); if (loc1==npos) {cout<<"'(' not found after TBMHeader.\n"; break;}
00092 loc2=line.find(")", loc1+1); if (loc2==npos) {cout<<"')' not found after TBMHeader.\n"; break;}
00093 int TBMHeader=atoi(line.substr(loc1+1,loc2-loc1-1).c_str());
00094
00095 pulseTrain[i]=UB;++i;
00096 pulseTrain[i]=UB;++i;
00097 pulseTrain[i]=UB;++i;
00098 pulseTrain[i]=B;++i;
00099
00100 pixelTBMHeader=decimalToBaseX(TBMHeader, 4, 4);
00101
00102 pulseTrain[i]=levelEncoder(pixelTBMHeader[3]);++i;
00103 pulseTrain[i]=levelEncoder(pixelTBMHeader[2]);++i;
00104 pulseTrain[i]=levelEncoder(pixelTBMHeader[1]);++i;
00105 pulseTrain[i]=levelEncoder(pixelTBMHeader[0]);++i;
00106 }
00107 else if (line.find("ROCHeader")!=std::string::npos)
00108 {
00109 loc1=line.find("("); if (loc1==npos) {cout<<"'(' not found after ROCHeader.\n"; break;}
00110 loc2=line.find(")", loc1+1); if (loc2==npos) {cout<<"')' not found after ROCHeader.\n"; break;}
00111 int LastDAC=atoi(line.substr(loc1+1,loc2-loc1-1).c_str());
00112
00113 std::cout<<"--------------"<<std::endl;
00114
00115 pulseTrain[i]=UB;++i;
00116 pulseTrain[i]=B;++i;
00117 pulseTrain[i]=levelEncoder(LastDAC); ++i;
00118 }
00119 else if (line.find("PixelHit")!=std::string::npos) {
00120
00121 loc1=line.find("("); if (loc1==npos) {cout<<"'(' not found after PixelHit.\n"; break;}
00122 loc2=line.find(",", loc1+1); if (loc2==npos) {cout<<"',' not found after the first argument of PixelHit.\n"; break;}
00123 loc3=line.find(",", loc2+1); if (loc3==npos) {cout<<"'.' not found after the second argument of PixelHit.\n"; break;}
00124 loc4=line.find(")", loc3+1); if (loc4==npos) {cout<<"')' not found after the third argument of PixelHit.\n"; break;}
00125 int column=atoi(line.substr(loc1+1, loc2-loc1-1).c_str());
00126 int row=atoi(line.substr(loc2+1, loc3-loc2-1).c_str());
00127 int charge=atoi(line.substr(loc3+1, loc4-loc3-1).c_str());
00128
00129 DCol=int(column/2);
00130 LorR=int(column-DCol*2);
00131 pixelDCol=decimalToBaseX(DCol, 6, 2);
00132 pixelPxl=decimalToBaseX((80-row)*2+LorR, 6, 3);
00133
00134 std::cout<<"Pxl = "<<pixelPxl[2]<<pixelPxl[1]<<pixelPxl[0]<<", DCol= "<<pixelDCol[1]<<pixelDCol[0]<<std::endl;
00135
00136 pulseTrain[i]=levelEncoder(pixelDCol[1]);++i;
00137 pulseTrain[i]=levelEncoder(pixelDCol[0]);++i;
00138 pulseTrain[i]=levelEncoder(pixelPxl[2]);++i;
00139 pulseTrain[i]=levelEncoder(pixelPxl[1]);++i;
00140 pulseTrain[i]=levelEncoder(pixelPxl[0]);++i;
00141 pulseTrain[i]=charge;++i;
00142
00143 }
00144 else if (line.find("TBMTrailer")!=std::string::npos)
00145 {
00146 loc1=line.find("("); if (loc1==npos) {cout<<"'(' not found after TBMTrailer.\n"; break;}
00147 loc2=line.find(")", loc1+1); if (loc2==npos) {cout<<"')' not found after TBMTrailer.\n"; break;}
00148 int TBMTrailer=atoi(line.substr(loc1+1,loc2-loc1-1).c_str());
00149
00150 pulseTrain[i]=UB;++i;
00151 pulseTrain[i]=UB;++i;
00152 pulseTrain[i]=B; ++i;
00153 pulseTrain[i]=B; ++i;
00154
00155 pixelTBMTrailer=decimalToBaseX(TBMTrailer, 4, 4);
00156 pulseTrain[i]=levelEncoder(pixelTBMTrailer[3]);++i;
00157 pulseTrain[i]=levelEncoder(pixelTBMTrailer[2]);++i;
00158 pulseTrain[i]=levelEncoder(pixelTBMTrailer[1]);++i;
00159 pulseTrain[i]=levelEncoder(pixelTBMTrailer[0]);++i;
00160 }
00161 }
00162
00163 dacs_=pulseTrain;
00164 }
00165
00166
00167 PixelFEDTestDAC::PixelFEDTestDAC(std::string filename){
00168
00169 const unsigned long int UB=200;
00170 const unsigned long int B=500;
00171 const unsigned long int offset=0;
00172 vector <unsigned int> pulseTrain(256), pixelDCol(1), pixelPxl(2), pixelTBMHeader(3), pixelTBMTrailer(3);
00173 unsigned int DCol, LorR, start=15;
00174 std::string line;
00175 std::string::size_type loc1, loc2, loc3, loc4;
00176 unsigned long int npos=std::string::npos;
00177 int i;
00178
00179
00180 for (unsigned int i=0;i<pulseTrain.size();++i)
00181 {
00182 pulseTrain[i]=offset+B;
00183 }
00184
00185 ifstream fin(filename.c_str());
00186
00187 i=start;
00188
00189 getline(fin, line);
00190 mode_=line;
00191 assert(mode_=="EmulatedPhysics"||
00192 mode_=="FEDBaselineWithTestDACs"||
00193 mode_=="FEDAddressLevelWithTestDACs");
00194
00195 while (!fin.eof())
00196 {
00197 getline(fin, line);
00198
00199 if (line.find("TBMHeader")!=npos)
00200 {
00201 loc1=line.find("("); if (loc1==npos) {cout<<"'(' not found after TBMHeader.\n"; break;}
00202 loc2=line.find(")", loc1+1); if (loc2==npos) {cout<<"')' not found after TBMHeader.\n"; break;}
00203 int TBMHeader=atoi(line.substr(loc1+1,loc2-loc1-1).c_str());
00204
00205 pulseTrain[i]=UB;++i;
00206 pulseTrain[i]=UB;++i;
00207 pulseTrain[i]=UB;++i;
00208 pulseTrain[i]=B;++i;
00209
00210 pixelTBMHeader=decimalToBaseX(TBMHeader, 4, 4);
00211
00212 pulseTrain[i]=levelEncoder(pixelTBMHeader[3]);++i;
00213 pulseTrain[i]=levelEncoder(pixelTBMHeader[2]);++i;
00214 pulseTrain[i]=levelEncoder(pixelTBMHeader[1]);++i;
00215 pulseTrain[i]=levelEncoder(pixelTBMHeader[0]);++i;
00216 }
00217 else if (line.find("ROCHeader")!=std::string::npos)
00218 {
00219 loc1=line.find("("); if (loc1==npos) {cout<<"'(' not found after ROCHeader.\n"; break;}
00220 loc2=line.find(")", loc1+1); if (loc2==npos) {cout<<"')' not found after ROCHeader.\n"; break;}
00221 int LastDAC=atoi(line.substr(loc1+1,loc2-loc1-1).c_str());
00222
00223 std::cout<<"--------------"<<std::endl;
00224
00225 pulseTrain[i]=UB;++i;
00226 pulseTrain[i]=B;++i;
00227 pulseTrain[i]=levelEncoder(LastDAC); ++i;
00228 }
00229 else if (line.find("PixelHit")!=std::string::npos) {
00230
00231 loc1=line.find("("); if (loc1==npos) {cout<<"'(' not found after PixelHit.\n"; break;}
00232 loc2=line.find(",", loc1+1); if (loc2==npos) {cout<<"',' not found after the first argument of PixelHit.\n"; break;}
00233 loc3=line.find(",", loc2+1); if (loc3==npos) {cout<<"'.' not found after the second argument of PixelHit.\n"; break;}
00234 loc4=line.find(")", loc3+1); if (loc4==npos) {cout<<"')' not found after the third argument of PixelHit.\n"; break;}
00235 int column=atoi(line.substr(loc1+1, loc2-loc1-1).c_str());
00236 int row=atoi(line.substr(loc2+1, loc3-loc2-1).c_str());
00237 int charge=atoi(line.substr(loc3+1, loc4-loc3-1).c_str());
00238
00239 DCol=int(column/2);
00240 LorR=int(column-DCol*2);
00241 pixelDCol=decimalToBaseX(DCol, 6, 2);
00242 pixelPxl=decimalToBaseX((80-row)*2+LorR, 6, 3);
00243
00244 std::cout<<"Pxl = "<<pixelPxl[2]<<pixelPxl[1]<<pixelPxl[0]<<", DCol= "<<pixelDCol[1]<<pixelDCol[0]<<std::endl;
00245
00246 pulseTrain[i]=levelEncoder(pixelDCol[1]);++i;
00247 pulseTrain[i]=levelEncoder(pixelDCol[0]);++i;
00248 pulseTrain[i]=levelEncoder(pixelPxl[2]);++i;
00249 pulseTrain[i]=levelEncoder(pixelPxl[1]);++i;
00250 pulseTrain[i]=levelEncoder(pixelPxl[0]);++i;
00251 pulseTrain[i]=charge;++i;
00252
00253 }
00254 else if (line.find("TBMTrailer")!=std::string::npos)
00255 {
00256 loc1=line.find("("); if (loc1==npos) {cout<<"'(' not found after TBMTrailer.\n"; break;}
00257 loc2=line.find(")", loc1+1); if (loc2==npos) {cout<<"')' not found after TBMTrailer.\n"; break;}
00258 int TBMTrailer=atoi(line.substr(loc1+1,loc2-loc1-1).c_str());
00259
00260 pulseTrain[i]=UB;++i;
00261 pulseTrain[i]=UB;++i;
00262 pulseTrain[i]=B; ++i;
00263 pulseTrain[i]=B; ++i;
00264
00265 pixelTBMTrailer=decimalToBaseX(TBMTrailer, 4, 4);
00266 pulseTrain[i]=levelEncoder(pixelTBMTrailer[3]);++i;
00267 pulseTrain[i]=levelEncoder(pixelTBMTrailer[2]);++i;
00268 pulseTrain[i]=levelEncoder(pixelTBMTrailer[1]);++i;
00269 pulseTrain[i]=levelEncoder(pixelTBMTrailer[0]);++i;
00270 }
00271 }
00272 fin.close();
00273 dacs_=pulseTrain;
00274 }
00275
00276
00277 unsigned int PixelFEDTestDAC::levelEncoder(int level){
00278
00279 unsigned int pulse;
00280
00281 switch (level)
00282 {
00283 case 0: pulse=450; break;
00284 case 1: pulse=500; break;
00285 case 2: pulse=550; break;
00286 case 3: pulse=600; break;
00287 case 4: pulse=650; break;
00288 case 5: pulse=700; break;
00289 default: assert(0); break;
00290 }
00291
00292 return pulse;
00293
00294 }
00295
00296
00297 vector<unsigned int> PixelFEDTestDAC::decimalToBaseX (unsigned int a, unsigned int x, unsigned int length){
00298
00299 vector<unsigned int> ans(100,0);
00300 int i=0;
00301
00302 while (a>0)
00303 {
00304 ans[i]=a%x;
00305
00306 a=a/x;
00307 i+=1;
00308 }
00309
00310 if (length>0) ans.resize(length); else ans.resize(i);
00311
00312 return ans;
00313 }
00314