00001
00002
00003
00004
00005
00006
00007 #include "CalibFormats/SiPixelObjects/interface/PixelGlobalDelay25.h"
00008 #include <fstream>
00009 #include <map>
00010 #include <assert.h>
00011 #include <math.h>
00012
00013
00014 using namespace pos;
00015 using namespace std;
00016
00017
00018 PixelGlobalDelay25::PixelGlobalDelay25(std::string filename):
00019 PixelConfigBase(" "," "," "){
00020
00021 std::ifstream in(filename.c_str());
00022
00023 if (!in.good()){
00024 std::cout << "Could not open:"<<filename<<std::endl;
00025 assert(0);
00026 }
00027 else {
00028 std::cout << "Opened:"<<filename<<std::endl;
00029 }
00030
00031 in >> std::hex >> delay_ >> std::dec;
00032 std::cout << "PixelGlobalDelay25:: read global delay 0x" << std::hex << delay_ << std::dec << endl;
00033
00034 in.close();
00035
00036 if (delay_>=50) {
00037 std::cout << "PixelGlobalDelay25:: global delay is out of range (>= 1 Tclk)."<< std::endl;
00038 std::cout << "PixelGlobalDelay25:: will not apply any global delays."<<std::endl;
00039 std::cout << "PixelGlobalDelay25:: increase the delays in the TPLL if needed."<<std::endl;
00040 delay_=0;
00041 }
00042 }
00043
00044
00045 PixelGlobalDelay25::~PixelGlobalDelay25() {}
00046
00047
00048 unsigned int PixelGlobalDelay25::getDelay(unsigned int offset) const{
00049 unsigned int ret=offset+delay_;
00050 if (ret > 127) {
00051 std::cout<<"PixelGlobalDelay25:: the required Delay25 delay "<<ret<<" is out of range."<<endl;
00052 std::cout<<"PixelGlobalDelay25:: this can happen if the operating point is chosen to be"<<endl;
00053 std::cout<<"PixelGlobalDelay25:: over 78; i.e. more than 7 ns delay."<<endl;
00054 std::cout<<"PixelGlobalDelay25:: we will keep the current delay setting..."<<endl;
00055 ret=offset;
00056 }
00057
00058 std::cout<<"PixelGlobalDelay25::getDelay("<<offset<<") returns "<<ret<<endl;
00059 return ret;
00060 }
00061
00062
00063 unsigned int PixelGlobalDelay25::getTTCrxDelay(unsigned int offset) const{
00064
00065
00066
00067
00068
00069
00070
00071 unsigned int K=(offset/16*16+offset%16*15+30)%240;
00072 K+=floor((delay_*0.499)/0.1039583 + 0.5);
00073
00074 unsigned int ret;
00075 if (K>239) {
00076 std::cout<<"PixelGlobalDelay25:: the required TTCrx fine delay "<<K<<" is out of range."<<endl;
00077 std::cout<<"PixelGlobalDelay25:: this can happen if the register was initialized to 0"<<endl;
00078 std::cout<<"PixelGlobalDelay25:: (i.e. delay of 3.1 ns) and the required delay is >21.7 ns."<<endl;
00079 std::cout<<"PixelGlobalDelay25:: we will keep the current delay setting..."<<endl;
00080 ret=offset;
00081 }else{
00082 unsigned int n=K%15;
00083 unsigned int m=((K/15)-n+14)%16;
00084 ret=16*n+m;
00085 }
00086
00087 std::cout<<"PixelGlobalDelay25::getTTCrxDelay("<<offset<<") returns "<<ret<<endl;
00088 return ret;
00089
00090 }
00091
00092
00093 void PixelGlobalDelay25::writeASCII(std::string dir) const {
00094
00095 if (dir!="") dir+="/";
00096 string filename=dir+"globaldelay25.dat";
00097
00098 ofstream out(filename.c_str());
00099 if(!out.good()){
00100 cout << "Could not open file:"<<filename<<endl;
00101 assert(0);
00102 }
00103
00104 out << "0x" << hex << delay_ << dec << endl;
00105
00106 out.close();
00107 }