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