CMS 3D CMS Logo

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