CMS 3D CMS Logo

L1RCTOmdsFedVectorProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1RCTOmdsFedVectorProducer
4 // Class: L1RCTOmdsFedVectorProducer
5 //
13 //
14 // Original Author: Jessica Lynn Leonard,32 4-C20,+41227674522,
15 // Created: Fri Sep 9 11:19:20 CEST 2011
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
27 
28 // OMDS stuff
29 #include "RelationalAccess/ISessionProxy.h"
30 #include "RelationalAccess/ITransaction.h"
31 #include "RelationalAccess/IRelationalDomain.h"
32 #include "RelationalAccess/ISchema.h"
33 #include "RelationalAccess/IQuery.h"
34 #include "RelationalAccess/ICursor.h"
35 #include "RelationalAccess/IConnection.h"
36 #include "CoralBase/AttributeList.h"
37 #include "CoralBase/Attribute.h"
38 #include "CoralKernel/Context.h"
39 
41 // end OMDS stuff
42 
46 
48 
49 //
50 // class declaration
51 //
52 
54 public:
56  ~L1RCTOmdsFedVectorProducer() override;
57 
58  using ReturnType = std::unique_ptr<RunInfo>;
59 
61 
62 private:
63  // ----------member data ---------------------------
67 
69 };
70 
71 //
72 // constants, enums and typedefs
73 //
74 
75 //
76 // static data member definitions
77 //
78 
79 //
80 // constructors and destructor
81 //
83  : connectionString(iConfig.getParameter<std::string>("connectionString")),
84  authpath(iConfig.getParameter<std::string>("authpath")),
85  tableToRead(iConfig.getParameter<std::string>("tableToRead")) {
86  //the following line is needed to tell the framework what
87  // data is being produced
88  token_ = setWhatProduced(this, "OmdsFedVector").consumes();
89 
90  //now do what ever other initialization is needed
91 }
92 
94  // do anything here that needs to be done at desctruction time
95  // (e.g. close files, deallocate resources etc.)
96 }
97 
98 //
99 // member functions
100 //
101 
102 // ------------ method called to produce the data ------------
104  // std::cout << "ENTERING L1RCTOmdsFedVectorProducer::produce()" << std::endl;
105 
106  // std::cout << "GETTING FED VECTOR FROM OMDS" << std::endl;
107 
108  // GETTING ALREADY-EXISTING RUNINFO OUT OF ES TO FIND OUT RUN NUMBER
109  const RunInfo* summary = &iRecord.get(token_);
110  int runNumber = summary->m_run;
111 
112  // CREATING NEW RUNINFO WHICH WILL GET NEW FED VECTOR AND BE RETURNED
113  auto pRunInfo = std::make_unique<RunInfo>();
114 
115  // DO THE DATABASE STUFF
116 
117  //make connection object
119 
120  //set in configuration object authentication path
121  connection.setAuthenticationPath(authpath);
122  connection.configure();
123 
124  //create session object from connection
125  cond::persistency::Session session = connection.createSession(connectionString, true);
126 
127  session.transaction().start(true); // (true=readOnly)
128 
129  coral::ISchema& schema = session.coralSession().schema("CMS_RUNINFO");
130 
131  //condition
132  coral::AttributeList conditionData;
133  conditionData.extend<int>("n_run");
134  conditionData[0].data<int>() = runNumber;
135 
136  std::string columnToRead_val = "VALUE";
137 
138  std::string tableToRead_fed = "RUNSESSION_STRING";
139  coral::IQuery* queryV = schema.newQuery();
140  queryV->addToTableList(tableToRead);
141  queryV->addToTableList(tableToRead_fed);
142  queryV->addToOutputList(tableToRead_fed + "." + columnToRead_val, columnToRead_val);
143  //queryV->addToOutputList(tableToRead + "." + columnToRead, columnToRead);
144  //condition
145  std::string condition =
146  tableToRead + ".RUNNUMBER=:n_run AND " + tableToRead +
147  ".NAME='CMS.LVL0:FED_ENABLE_MASK' AND RUNSESSION_PARAMETER.ID = RUNSESSION_STRING.RUNSESSION_PARAMETER_ID";
148  //std::string condition = tableToRead + ".runnumber=:n_run AND " + tableToRead + ".name='CMS.LVL0:FED_ENABLE_MASK'";
149  queryV->setCondition(condition, conditionData);
150  coral::ICursor& cursorV = queryV->execute();
151  std::string fed;
152  if (cursorV.next()) {
153  //cursorV.currentRow().toOutputStream(std::cout) << std::endl;
154  const coral::AttributeList& row = cursorV.currentRow();
155  fed = row[columnToRead_val].data<std::string>();
156  } else {
157  fed = "null";
158  }
159  //std::cout << "string fed emask == " << fed << std::endl;
160  delete queryV;
161 
162  std::replace(fed.begin(), fed.end(), '%', ' ');
163  std::stringstream stream(fed);
164  for (;;) {
166  if (!(stream >> word)) {
167  break;
168  }
169  std::replace(word.begin(), word.end(), '&', ' ');
170  std::stringstream ss(word);
171  int fedNumber;
172  int val;
173  ss >> fedNumber >> val;
174  //std::cout << "fed:: " << fed << "--> val:: " << val << std::endl;
175  //val bit 0 represents the status of the SLINK, but 5 and 7 means the SLINK/TTS is ON but NA or BROKEN (see mail of alex....)
176  if ((val & 0001) == 1 && (val != 5) && (val != 7))
177  pRunInfo->m_fed_in.push_back(fedNumber);
178  }
179  // std::cout << "feds in run:--> ";
180  // std::copy(pRunInfo->m_fed_in.begin(), pRunInfo->m_fed_in.end(), std::ostream_iterator<int>(std::cout, ", "));
181  // std::cout << std::endl;
182  /*
183  for (size_t i =0; i<pRunInfo->m_fed_in.size() ; ++i)
184  {
185  std::cout << "fed in run:--> " << pRunInfo->m_fed_in[i] << std::endl;
186  }
187  */
188 
189  return pRunInfo;
190 }
191 
192 //define this as a plug-in
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
L1RCTOmdsFedVectorProducer(const edm::ParameterSet &)
std::unique_ptr< RunInfo > ReturnType
void start(bool readOnly=true)
Definition: Session.cc:18
def replace(string, replacements)
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
Transaction & transaction()
Definition: Session.cc:52
uint64_t word
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:61
coral::ISessionProxy & coralSession()
Definition: Session.cc:218
ReturnType produce(const RunInfoRcd &)
edm::ESGetToken< RunInfo, RunInfoRcd > token_
void setAuthenticationPath(const std::string &p)