CMS 3D CMS Logo

CSCTFConfigOnlineProd.cc
Go to the documentation of this file.
2 #include <cstdio>
3 #include <string>
4 
5 std::unique_ptr<L1MuCSCTFConfiguration> CSCTFConfigOnlineProd::newObject(const std::string& objectKey) {
6  edm::LogInfo("L1-O2O: CSCTFConfigOnlineProd") << "Producing "
7  << "L1MuCSCTFConfiguration "
8  << "with key CSCTF_KEY=" << objectKey;
9 
10  std::string csctfreg[12];
11 
12  // loop over the 12 SPs forming the CSCTF crate
13  for (int iSP = 1; iSP < 13; iSP++) {
14  std::string spkey = objectKey + "00";
15  if (iSP < 10)
16  spkey += "0";
17  spkey += std::to_string(iSP);
18 
19  // SELECT Multiple columns FROM TABLE with correct key:
20  std::vector<std::string> columns;
21  columns.push_back("STATIC_CONFIG");
22  columns.push_back("ETA_CONFIG");
23  columns.push_back("FIRMWARE");
24 
25  //SELECT * FROM CMS_CSC_TF.CSCTF_SP_CONF WHERE CSCTF_SP_CONF.SP_KEY = spkey
27  columns, "CMS_CSC_TF", "CSCTF_SP_CONF", "CSCTF_SP_CONF.SP_KEY", m_omdsReader.singleAttribute(spkey));
28 
29  if (results.queryFailed()) // check if query was successful
30  {
31  edm::LogError("L1-O2O") << "Problem with L1CSCTFParameters key.";
32  // return empty configuration
33  return std::make_unique<L1MuCSCTFConfiguration>();
34  }
35 
36  std::string conf_stat, conf_eta, conf_firmware;
37  results.fillVariable("STATIC_CONFIG", conf_stat);
38  results.fillVariable("ETA_CONFIG", conf_eta);
39  results.fillVariable("FIRMWARE", conf_firmware);
40 
41  LogDebug("L1-O2O: CSCTFConfigOnlineProd:") << "conf_stat queried: " << conf_stat << "conf_eta queried:" << conf_eta
42  << "conf_firmware queried:" << conf_firmware;
43 
44  for (size_t pos = conf_stat.find("\\n"); pos != std::string::npos; pos = conf_stat.find("\\n", pos)) {
45  conf_stat[pos] = ' ';
46  conf_stat[pos + 1] = '\n';
47  }
48 
49  for (size_t pos = conf_eta.find("\\n"); pos != std::string::npos; pos = conf_eta.find("\\n", pos)) {
50  conf_eta[pos] = ' ';
51  conf_eta[pos + 1] = '\n';
52  }
53 
54  for (size_t pos = conf_firmware.find("\\n"); pos != std::string::npos; pos = conf_firmware.find("\\n", pos)) {
55  conf_firmware[pos] = ' ';
56  conf_firmware[pos + 1] = '\n';
57  }
58 
59  LogDebug("L1-O2O: CSCTFConfigOnlineProd") << "\nSP KEY: " << spkey << "\n\nSTATIC CONFIGURATION:\n"
60  << conf_stat << "\nDAT_ETA CONFIGURATION:\n"
61  << conf_eta << "\nFIRMWARE VERSIONS:\n"
62  << conf_firmware;
63 
64  // The CSCTF firmware needs a bit more manipulation
65  // The firmware is written in the DBS as SP SP day/month/year, where the real year is 2000+year
66  // For easy handling when retrieving the configuration I prefer to write is as
67  // FIRMWARE SP SP yearmonthday
68  // e.g. SP SP 26/06/09 -> FIRMWARE SP SP 20090626
69 
70  std::string conf_firmware_sp;
71 
72  std::stringstream conf(conf_firmware);
73  while (!conf.eof()) {
74  char buff[1024];
75  conf.getline(buff, 1024);
76  std::stringstream line(buff);
77 
78  std::string register_ = "FIRMWARE";
79  std::string chip_;
80  line >> chip_;
81  std::string muon_;
82  line >> muon_;
83  std::string writeValue_;
84  line >> writeValue_;
85 
86  size_t pos;
87  pos = writeValue_.find('/');
88 
90  day.push_back(writeValue_[pos - 2]);
91  day.push_back(writeValue_[pos - 1]);
92 
93  std::string month;
94  month.push_back(writeValue_[pos + 1]);
95  month.push_back(writeValue_[pos + 2]);
96 
97  std::string year("20");
98  year.push_back(writeValue_[pos + 4]);
99  year.push_back(writeValue_[pos + 5]);
100 
101  //std::cout << "day " << day <<std::endl;
102  //std::cout << "month " << month <<std::endl;
103  //std::cout << "year " << year <<std::endl;
104 
105  std::string date = year + month + day;
106  // std::cout << register_ << " -- "
107  // << chip_ << " -- "
108  // << muon_ << " -- "
109  // << date << " -- "
110  // << std::endl;
111 
112  // for the CSCTF emulator there is no need of the other firmware (CCB and MS)
113  if (chip_ == "SP")
114  conf_firmware_sp += register_ + " " + chip_ + " " + muon_ + " " + date + "\n";
115  }
116 
117  edm::LogInfo("L1-O2O: CSCTFConfigOnlineProd") << "\nSP KEY: " << spkey << "\n\nSTATIC CONFIGURATION:\n"
118  << conf_stat << "\nDAT_ETA CONFIGURATION:\n"
119  << conf_eta << "\nFIRMWARE VERSIONS:\n"
120  << conf_firmware_sp;
121 
122  std::string conf_read = conf_eta + conf_stat + conf_firmware_sp;
123  // write all registers for a given SP
124  csctfreg[iSP - 1] = conf_read;
125  }
126 
127  // return the final object with the configuration for all CSCTF
128  return std::make_unique<L1MuCSCTFConfiguration>(csctfreg);
129 }
#define LogDebug(id)
bool fillVariable(const std::string &columnName, T &outputVariable) const
Definition: OMDSReader.h:274
const QueryResults singleAttribute(const T &data) const
Definition: OMDSReader.h:259
std::unique_ptr< L1MuCSCTFConfiguration > newObject(const std::string &objectKey) override
const QueryResults basicQuery(const std::vector< std::string > &columnNames, const std::string &schemaName, const std::string &tableName, const std::string &conditionLHS="", const QueryResults conditionRHS=QueryResults(), const std::string &conditionRHSName="")
Definition: OMDSReader.cc:75
def day(string)
Definition: getRunInfo.py:11