Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "CalibFormats/SiPixelObjects/interface/PixelGlobalDelay25.h"
00008 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
00009
00010 #include <sstream>
00011 #include <fstream>
00012 #include <map>
00013 #include <assert.h>
00014 #include <math.h>
00015 #include <stdexcept>
00016
00017
00018 using namespace pos;
00019 using namespace std;
00020
00021 PixelGlobalDelay25::PixelGlobalDelay25(vector<vector<string> > &tableMat):PixelConfigBase(" "," "," ")
00022 {
00023 std::string mthn = "[PixelGlobalDelay25::PixelGlobalDelay25()]\t\t " ;
00024 vector<string> ins = tableMat[0];
00025 map<string , int > colM;
00026 vector<string> colNames;
00027
00042 colNames.push_back("CONFIG_KEY" ) ;
00043 colNames.push_back("KEY_TYPE" ) ;
00044 colNames.push_back("KEY_ALIAS_ID" ) ;
00045 colNames.push_back("KEY_ALIAS" ) ;
00046 colNames.push_back("VERSION" ) ;
00047 colNames.push_back("KIND_OF_COND" ) ;
00048 colNames.push_back("GLOBALDELAY25") ;
00049 for(unsigned int c = 0 ; c < ins.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 for(unsigned int n=0; n<colNames.size(); n++)
00060 {
00061 if(colM.find(colNames[n]) == colM.end())
00062 {
00063 std::cerr << "[PixelGlobalDelay25::PixelGlobalDelay25()]\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
00064 assert(0);
00065 }
00066 }
00067 sscanf(tableMat[1][colM["GLOBALDELAY25"]].c_str(),"%x",&delay_);
00068 std::cout << __LINE__ << "]\t" << mthn << "[DB] read global delay 0x" << std::hex << delay_ << std::dec << endl;
00069
00070 if (delay_>=50) {
00071 std::cout << __LINE__ << "]\t" << mthn << "global delay is out of range (>= 1 Tclk)." << std::endl;
00072 std::cout << __LINE__ << "]\t" << mthn << "will not apply any global delays." << std::endl;
00073 std::cout << __LINE__ << "]\t" << mthn << "increase the delays in the TPLL if needed." << std::endl;
00074 delay_=0;
00075 }
00076 }
00077
00078
00079 PixelGlobalDelay25::PixelGlobalDelay25(std::string filename):
00080 PixelConfigBase(" "," "," "){
00081
00082 std::string mthn = "[PixelGlobalDelay25::PixelGlobalDelay25()]\t\t\t " ;
00083 std::ifstream in(filename.c_str());
00084
00085 if (!in.good()){
00086 std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
00087 throw std::runtime_error("Failed to open file "+filename);
00088 }
00089 else {
00090 std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
00091 }
00092
00093 in >> std::hex >> delay_ >> std::dec;
00094 std::cout << __LINE__ << "]\t" << mthn << "read global delay 0x" << std::hex << delay_ << std::dec << endl;
00095
00096 in.close();
00097
00098 if (delay_>=50) {
00099 std::cout << __LINE__ << "]\t" << mthn << "global delay is out of range (>= 1 Tclk)." << std::endl;
00100 std::cout << __LINE__ << "]\t" << mthn << "will not apply any global delays." << std::endl;
00101 std::cout << __LINE__ << "]\t" << mthn << "increase the delays in the TPLL if needed." << std::endl;
00102 delay_=0;
00103 }
00104 }
00105
00106
00107 PixelGlobalDelay25::~PixelGlobalDelay25() {}
00108
00109
00110 unsigned int PixelGlobalDelay25::getDelay(unsigned int offset) const{
00111 std::string mthn = "[PixelGlobalDelay25::getDelay()]\t\t\t " ;
00112 unsigned int ret=offset+delay_;
00113 if (ret > 127) {
00114 std::cout << __LINE__ << "]\t" << mthn <<"the required total delay "<<ret<<" is out of range." << endl;
00115 std::cout << __LINE__ << "]\t" << mthn <<"original setting: "<<offset<<", global delay: "<<delay_ << endl;
00116 std::cout << __LINE__ << "]\t" << mthn <<"we will keep the default delay setting..." << endl;
00117
00118 ret=offset;
00119 }
00120
00121 std::cout << __LINE__ << "]\t" << mthn << "getDelay("<<offset<<") returns "<<ret<<endl;
00122 return ret;
00123 }
00124
00125
00126 unsigned int PixelGlobalDelay25::getCyclicDelay(unsigned int offset) const{
00127 std::string mthn = "[PixelGlobalDelay25::getCyclicDelay()]\t\t\t " ;
00128 unsigned int ret=offset+delay_;
00129 if (ret > 120) ret-=50;
00130 std::cout<< __LINE__ << "]\t" << mthn << "getCyclicDelay("<<offset<<") returns "<<ret<<endl;
00131 return ret;
00132 }
00133
00134
00135 unsigned int PixelGlobalDelay25::getTTCrxDelay(unsigned int offset) const{
00136
00137
00138
00139
00140
00141
00142
00143 std::string mthn = "[PixelGlobalDelay25::getTTCrxDelay()]\t\t\t " ;
00144 unsigned int K=(offset/16*16+offset%16*15+30)%240;
00145 K+=(unsigned int)floor((delay_*0.499)/0.1039583 + 0.5);
00146
00147
00148 unsigned int ret;
00149 if (K>239) {
00150 std::cout << __LINE__ << "]\t" << mthn << "the required TTCrx fine delay "<<K<<" is out of range."<<endl;
00151 std::cout << __LINE__ << "]\t" << mthn << "this can happen if the register was initialized to 0"<<endl;
00152 std::cout << __LINE__ << "]\t" << mthn << "(i.e. delay of 3.1 ns) and the required delay is >21.7 ns."<<endl;
00153 std::cout << __LINE__ << "]\t" << mthn << "we will keep the current delay setting..."<<endl;
00154 ret=offset;
00155 }else{
00156 unsigned int n=K%15;
00157 unsigned int m=((K/15)-n+14)%16;
00158 ret=16*n+m;
00159 }
00160
00161 std::cout << __LINE__ << "]\t" << mthn << "getTTCrxDelay("<<offset<<") returns "<<ret<<endl;
00162 return ret;
00163
00164 }
00165
00166
00167 unsigned int PixelGlobalDelay25::getTTCrxDelay() const{
00168
00169
00170
00171
00172
00173
00174
00175 return getTTCrxDelay(14);
00176 }
00177
00178
00179
00180 void PixelGlobalDelay25::writeASCII(std::string dir) const {
00181
00182 std::string mthn = "[PixelGlobalDelay25::writeASCII()]\t\t\t " ;
00183 if (dir!="") dir+="/";
00184 string filename=dir+"globaldelay25.dat";
00185
00186 ofstream out(filename.c_str());
00187 if(!out.good()){
00188 cout << __LINE__ << "]\t" << mthn << "Could not open file:"<<filename<<endl;
00189 assert(0);
00190 }
00191
00192 out << "0x" << hex << delay_ << dec << endl;
00193
00194 out.close();
00195 }
00196
00197
00198 void PixelGlobalDelay25::writeXMLHeader(pos::PixelConfigKey key,
00199 int version,
00200 std::string path,
00201 std::ofstream *outstream,
00202 std::ofstream *out1stream,
00203 std::ofstream *out2stream) const
00204 {
00205 std::stringstream s ; s << __LINE__ << "]\t[[PixelGlobalDelay25::writeXMLHeader()]\t\t\t " ;
00206 std::string mthn = s.str() ;
00207 std::stringstream fullPath ;
00208 fullPath << path << "/Pixel_GlobalDelay25_" << PixelTimeFormatter::getmSecTime() << ".xml" ;
00209 cout << mthn << "Writing to: " << fullPath.str() << endl ;
00210
00211 outstream->open(fullPath.str().c_str()) ;
00212
00213 *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl ;
00214 *outstream << "<ROOT xmlns:xsi='https://www.w3.org/2001/XMLSchema-instance'>" << std::endl ;
00215 *outstream << "" << std::endl ;
00216 *outstream << " <!-- " << mthn << "-->" << std::endl ;
00217 *outstream << "" << std::endl ;
00218 *outstream << " <HEADER>" << std::endl ;
00219 *outstream << " <TYPE>" << std::endl ;
00220 *outstream << " <EXTENSION_TABLE_NAME>PIXEL_GLOBAL_DELAY25</EXTENSION_TABLE_NAME>" << std::endl ;
00221 *outstream << " <NAME>Pixel Global Delay25</NAME>" << std::endl ;
00222 *outstream << " </TYPE>" << std::endl ;
00223 *outstream << " <RUN>" << std::endl ;
00224 *outstream << " <RUN_TYPE>Pixel Global Delay25</RUN_TYPE>" << std::endl ;
00225 *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl ;
00226 *outstream << " <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
00227 *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl ;
00228 *outstream << " </RUN>" << std::endl ;
00229 *outstream << " </HEADER>" << std::endl ;
00230 *outstream << "" << std::endl ;
00231 *outstream << " <DATA_SET>" << std::endl ;
00232 *outstream << " " << std::endl ;
00233 *outstream << " <VERSION>" << version << "</VERSION>" << std::endl ;
00234 *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl ;
00235 *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl ;
00236 *outstream << " " << std::endl ;
00237 *outstream << " <PART>" << std::endl ;
00238 *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl ;
00239 *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl ;
00240 *outstream << " </PART>" << std::endl ;
00241
00242 }
00243
00244
00245 void PixelGlobalDelay25::writeXML( std::ofstream *outstream,
00246 std::ofstream *out1stream,
00247 std::ofstream *out2stream) const
00248 {
00249 std::stringstream s ; s << __LINE__ << "]\t[PixelGlobalDelay25::writeXML()]\t\t\t " ;
00250 std::string mthn = s.str() ;
00251
00252 *outstream << " <DATA>" << std::endl ;
00253 *outstream << " <GLOBALDELAY25>0x" << hex << delay_ << dec << "</GLOBALDELAY25>" << std::endl ;
00254 *outstream << " </DATA>" << std::endl ;
00255 *outstream << " " << std::endl ;
00256 }
00257
00258
00259 void PixelGlobalDelay25::writeXMLTrailer(std::ofstream *outstream,
00260 std::ofstream *out1stream,
00261 std::ofstream *out2stream) const
00262 {
00263 std::stringstream s ; s << __LINE__ << "]\t[PixelGlobalDelay25::writeASCII()]\t\t\t " ;
00264 std::string mthn = s.str() ;
00265
00266 *outstream << " " << std::endl ;
00267 *outstream << " </DATA_SET>" << std::endl ;
00268 *outstream << "</ROOT> " << std::endl ;
00269
00270 outstream->close() ;
00271 }
00272