CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PixelGlobalDelay25.cc
Go to the documentation of this file.
1 //
2 // This class stores the information about the global delay25 delay settings
3 // For the time being, the affected delay25 channels are SDA, SCL, and TRG
4 // (as implemented in PixelTKFECSupervisor)
5 //
6 
9 
10 #include <sstream>
11 #include <fstream>
12 #include <map>
13 #include <cassert>
14 #include <cmath>
15 #include <stdexcept>
16 
17 using namespace pos;
18 using namespace std;
19 
20 PixelGlobalDelay25::PixelGlobalDelay25(vector<vector<string> > &tableMat) : PixelConfigBase(" ", " ", " ") {
21  std::string mthn = "[PixelGlobalDelay25::PixelGlobalDelay25()]\t\t ";
22  vector<string> ins = tableMat[0];
23  map<string, int> colM;
24  vector<string> colNames;
25 
40  colNames.push_back("CONFIG_KEY");
41  colNames.push_back("KEY_TYPE");
42  colNames.push_back("KEY_ALIAS_ID");
43  colNames.push_back("KEY_ALIAS");
44  colNames.push_back("VERSION");
45  colNames.push_back("KIND_OF_COND");
46  colNames.push_back("GLOBALDELAY25");
47  for (unsigned int c = 0; c < ins.size(); c++) {
48  for (unsigned int n = 0; n < colNames.size(); n++) {
49  if (tableMat[0][c] == colNames[n]) {
50  colM[colNames[n]] = c;
51  break;
52  }
53  }
54  } //end for
55  for (unsigned int n = 0; n < colNames.size(); n++) {
56  if (colM.find(colNames[n]) == colM.end()) {
57  std::cerr << "[PixelGlobalDelay25::PixelGlobalDelay25()]\tCouldn't find in the database the column with name "
58  << colNames[n] << std::endl;
59  assert(0);
60  }
61  }
62  sscanf(tableMat[1][colM["GLOBALDELAY25"]].c_str(), "%x", &delay_);
63  std::cout << __LINE__ << "]\t" << mthn << "[DB] read global delay 0x" << std::hex << delay_ << std::dec << endl;
64 
65  if (delay_ >= 50) {
66  std::cout << __LINE__ << "]\t" << mthn << "global delay is out of range (>= 1 Tclk)." << std::endl;
67  std::cout << __LINE__ << "]\t" << mthn << "will not apply any global delays." << std::endl;
68  std::cout << __LINE__ << "]\t" << mthn << "increase the delays in the TPLL if needed." << std::endl;
69  delay_ = 0;
70  }
71 }
72 
74  std::string mthn = "[PixelGlobalDelay25::PixelGlobalDelay25()]\t\t\t ";
75  std::ifstream in(filename.c_str());
76 
77  if (!in.good()) {
78  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
79  throw std::runtime_error("Failed to open file " + filename);
80  } else {
81  std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
82  }
83 
84  in >> std::hex >> delay_ >> std::dec;
85  std::cout << __LINE__ << "]\t" << mthn << "read global delay 0x" << std::hex << delay_ << std::dec << endl;
86 
87  in.close();
88 
89  if (delay_ >= 50) {
90  std::cout << __LINE__ << "]\t" << mthn << "global delay is out of range (>= 1 Tclk)." << std::endl;
91  std::cout << __LINE__ << "]\t" << mthn << "will not apply any global delays." << std::endl;
92  std::cout << __LINE__ << "]\t" << mthn << "increase the delays in the TPLL if needed." << std::endl;
93  delay_ = 0;
94  }
95 }
96 
98 
99 unsigned int PixelGlobalDelay25::getDelay(unsigned int offset) const {
100  std::string mthn = "[PixelGlobalDelay25::getDelay()]\t\t\t ";
101  unsigned int ret = offset + delay_;
102  if (ret > 127) {
103  std::cout << __LINE__ << "]\t" << mthn << "the required total delay " << ret << " is out of range." << endl;
104  std::cout << __LINE__ << "]\t" << mthn << "original setting: " << offset << ", global delay: " << delay_ << endl;
105  std::cout << __LINE__ << "]\t" << mthn << "we will keep the default delay setting..." << endl;
106 
107  ret = offset;
108  }
109 
110  std::cout << __LINE__ << "]\t" << mthn << "getDelay(" << offset << ") returns " << ret << endl;
111  return ret;
112 }
113 
114 unsigned int PixelGlobalDelay25::getCyclicDelay(unsigned int offset) const {
115  std::string mthn = "[PixelGlobalDelay25::getCyclicDelay()]\t\t\t ";
116  unsigned int ret = offset + delay_;
117  if (ret > 120)
118  ret -= 50;
119  std::cout << __LINE__ << "]\t" << mthn << "getCyclicDelay(" << offset << ") returns " << ret << endl;
120  return ret;
121 }
122 
123 unsigned int PixelGlobalDelay25::getTTCrxDelay(unsigned int offset) const {
124  // Computes the TTCrx delay settting required to compensate for the global Delay25 shift.
125  //
126  // 'offset' is the current register setting in the TTCrx register
127  //
128  // The unit of delay_ is 0.499 ns (Delay25 granularity) that needs to be converted
129  // to the units of the TTCrx delay generator 103.96 ps
130 
131  std::string mthn = "[PixelGlobalDelay25::getTTCrxDelay()]\t\t\t ";
132  unsigned int K = (offset / 16 * 16 + offset % 16 * 15 + 30) % 240;
133  K += (unsigned int)floor((delay_ * 0.499) / 0.1039583 + 0.5); // add max 235
134 
135  unsigned int ret;
136  if (K > 239) {
137  std::cout << __LINE__ << "]\t" << mthn << "the required TTCrx fine delay " << K << " is out of range." << endl;
138  std::cout << __LINE__ << "]\t" << mthn << "this can happen if the register was initialized to 0" << endl;
139  std::cout << __LINE__ << "]\t" << mthn << "(i.e. delay of 3.1 ns) and the required delay is >21.7 ns." << endl;
140  std::cout << __LINE__ << "]\t" << mthn << "we will keep the current delay setting..." << endl;
141  ret = offset;
142  } else {
143  unsigned int n = K % 15;
144  unsigned int m = ((K / 15) - n + 14) % 16;
145  ret = 16 * n + m;
146  }
147 
148  std::cout << __LINE__ << "]\t" << mthn << "getTTCrxDelay(" << offset << ") returns " << ret << endl;
149  return ret;
150  //return offset;
151 }
152 
153 unsigned int PixelGlobalDelay25::getTTCrxDelay() const {
154  // Computes the TTCrx delay settting required to compensate for the global Delay25 shift.
155  //
156  // Assumes that the current register setting in the TTCrx is 0 ns (14)
157  //
158  // The unit of delay_ is 0.499 ns (Delay25 granularity) that needs to be converted
159  // to the units of the TTCrx delay generator 103.96 ps
160 
161  return getTTCrxDelay(14);
162 }
163 
165  std::string mthn = "[PixelGlobalDelay25::writeASCII()]\t\t\t ";
166  if (!dir.empty())
167  dir += "/";
168  string filename = dir + "globaldelay25.dat";
169 
170  ofstream out(filename.c_str());
171  if (!out.good()) {
172  cout << __LINE__ << "]\t" << mthn << "Could not open file:" << filename << endl;
173  assert(0);
174  }
175 
176  out << "0x" << hex << delay_ << dec << endl;
177 
178  out.close();
179 }
180 
181 //=============================================================================================
183  int version,
185  std::ofstream *outstream,
186  std::ofstream *out1stream,
187  std::ofstream *out2stream) const {
188  std::stringstream s;
189  s << __LINE__ << "]\t[[PixelGlobalDelay25::writeXMLHeader()]\t\t\t ";
190  std::string mthn = s.str();
191  std::stringstream fullPath;
192  fullPath << path << "/Pixel_GlobalDelay25_" << PixelTimeFormatter::getmSecTime() << ".xml";
193  cout << mthn << "Writing to: " << fullPath.str() << endl;
194 
195  outstream->open(fullPath.str().c_str());
196 
197  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl;
198  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
199  *outstream << "" << std::endl;
200  *outstream << " <!-- " << mthn << "-->" << std::endl;
201  *outstream << "" << std::endl;
202  *outstream << " <HEADER>" << std::endl;
203  *outstream << " <TYPE>" << std::endl;
204  *outstream << " <EXTENSION_TABLE_NAME>PIXEL_GLOBAL_DELAY25</EXTENSION_TABLE_NAME>" << std::endl;
205  *outstream << " <NAME>Pixel Global Delay25</NAME>" << std::endl;
206  *outstream << " </TYPE>" << std::endl;
207  *outstream << " <RUN>" << std::endl;
208  *outstream << " <RUN_TYPE>Pixel Global Delay25</RUN_TYPE>" << std::endl;
209  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl;
210  *outstream << " <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>"
211  << std::endl;
212  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl;
213  *outstream << " </RUN>" << std::endl;
214  *outstream << " </HEADER>" << std::endl;
215  *outstream << "" << std::endl;
216  *outstream << " <DATA_SET>" << std::endl;
217  *outstream << " " << std::endl;
218  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl;
219  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl;
220  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl;
221  *outstream << " " << std::endl;
222  *outstream << " <PART>" << std::endl;
223  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl;
224  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl;
225  *outstream << " </PART>" << std::endl;
226 }
227 
228 //=============================================================================================
229 void PixelGlobalDelay25::writeXML(std::ofstream *outstream,
230  std::ofstream *out1stream,
231  std::ofstream *out2stream) const {
232  std::stringstream s;
233  s << __LINE__ << "]\t[PixelGlobalDelay25::writeXML()]\t\t\t ";
234  std::string mthn = s.str();
235 
236  *outstream << " <DATA>" << std::endl;
237  *outstream << " <GLOBALDELAY25>0x" << hex << delay_ << dec << "</GLOBALDELAY25>" << std::endl;
238  *outstream << " </DATA>" << std::endl;
239  *outstream << " " << std::endl;
240 }
241 
242 //=============================================================================================
243 void PixelGlobalDelay25::writeXMLTrailer(std::ofstream *outstream,
244  std::ofstream *out1stream,
245  std::ofstream *out2stream) const {
246  std::stringstream s;
247  s << __LINE__ << "]\t[PixelGlobalDelay25::writeASCII()]\t\t\t ";
248  std::string mthn = s.str();
249 
250  *outstream << " " << std::endl;
251  *outstream << " </DATA_SET>" << std::endl;
252  *outstream << "</ROOT> " << std::endl;
253 
254  outstream->close();
255 }
void writeXML(std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
tuple ret
prodAgent to be discontinued
This file contains the base class for &quot;pixel configuration data&quot; management.
const edm::EventSetup & c
unsigned int getCyclicDelay(unsigned int offset=0) const
assert(be >=bs)
static std::string getmSecTime(void)
static std::string getTime(void)
PixelGlobalDelay25(std::string filename)
std::string getComment() const
tuple key
prepare the HTCondor submission files and eventually submit them
This class provides utility methods to manipulate ASCII formatted timestamps.
tuple ins
Definition: cuy.py:313
std::string getAuthor() const
void writeASCII(std::string dir) const override
This class implements..
unsigned int getDelay(unsigned int offset=0) const
tuple filename
Definition: lut2db_cfg.py:20
void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
tuple cout
Definition: gather_cfg.py:144
unsigned int getTTCrxDelay() const
void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
This class specifies which delay25 channels are delayed over the entire pixel detector and by how muc...