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 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
28 
29 // OMDS stuff
30 #include "RelationalAccess/ISessionProxy.h"
31 #include "RelationalAccess/ITransaction.h"
32 #include "RelationalAccess/IRelationalDomain.h"
33 #include "RelationalAccess/ISchema.h"
34 #include "RelationalAccess/IQuery.h"
35 #include "RelationalAccess/ICursor.h"
36 #include "RelationalAccess/IConnection.h"
37 #include "CoralBase/AttributeList.h"
38 #include "CoralBase/Attribute.h"
39 #include "CoralKernel/Context.h"
40 
42 // end OMDS stuff
43 
47 
49 
50 
51 //
52 // class declaration
53 //
54 
56 public:
58  ~L1RCTOmdsFedVectorProducer() override;
59 
60  using ReturnType = std::unique_ptr<RunInfo>;
61 
63 private:
64  // ----------member data ---------------------------
68 
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 {
87  //the following line is needed to tell the framework what
88  // data is being produced
89  setWhatProduced(this,"OmdsFedVector");
90 
91  //now do what ever other initialization is needed
92 }
93 
94 
96 {
97 
98  // do anything here that needs to be done at desctruction time
99  // (e.g. close files, deallocate resources etc.)
100 
101 }
102 
103 
104 //
105 // member functions
106 //
107 
108 // ------------ method called to produce the data ------------
111 {
112  // std::cout << "ENTERING L1RCTOmdsFedVectorProducer::produce()" << std::endl;
113 
114  // std::cout << "GETTING FED VECTOR FROM OMDS" << std::endl;
115 
116  // GETTING ALREADY-EXISTING RUNINFO OUT OF ES TO FIND OUT RUN NUMBER
118  iRecord.get(sum);
119  const RunInfo* summary=sum.product();
120  int runNumber = summary->m_run;
121 
122  // CREATING NEW RUNINFO WHICH WILL GET NEW FED VECTOR AND BE RETURNED
123  auto pRunInfo = std::make_unique<RunInfo>();
124 
125 
126  // DO THE DATABASE STUFF
127 
128  //make connection object
130 
131  //set in configuration object authentication path
132  connection.setAuthenticationPath(authpath);
133  connection.configure();
134 
135  //create session object from connection
136  cond::persistency::Session session = connection.createSession(connectionString,true );
137 
138  session.transaction().start(true); // (true=readOnly)
139 
140  coral::ISchema& schema = session.coralSession().schema("CMS_RUNINFO");
141 
142  //condition
143  coral::AttributeList conditionData;
144  conditionData.extend<int>( "n_run" );
145  conditionData[0].data<int>() = runNumber;
146 
147  std::string columnToRead_val = "VALUE";
148 
149  std::string tableToRead_fed = "RUNSESSION_STRING";
150  coral::IQuery* queryV = schema.newQuery();
151  queryV->addToTableList(tableToRead);
152  queryV->addToTableList(tableToRead_fed);
153  queryV->addToOutputList(tableToRead_fed + "." + columnToRead_val, columnToRead_val);
154  //queryV->addToOutputList(tableToRead + "." + columnToRead, columnToRead);
155  //condition
156  std::string condition = tableToRead + ".RUNNUMBER=:n_run AND " + tableToRead + ".NAME='CMS.LVL0:FED_ENABLE_MASK' AND RUNSESSION_PARAMETER.ID = RUNSESSION_STRING.RUNSESSION_PARAMETER_ID";
157  //std::string condition = tableToRead + ".runnumber=:n_run AND " + tableToRead + ".name='CMS.LVL0:FED_ENABLE_MASK'";
158  queryV->setCondition(condition, conditionData);
159  coral::ICursor& cursorV = queryV->execute();
160  std::string fed;
161  if ( cursorV.next() ) {
162  //cursorV.currentRow().toOutputStream(std::cout) << std::endl;
163  const coral::AttributeList& row = cursorV.currentRow();
164  fed = row[columnToRead_val].data<std::string>();
165  }
166  else {
167  fed="null";
168  }
169  //std::cout << "string fed emask == " << fed << std::endl;
170  delete queryV;
171 
172  std::replace(fed.begin(), fed.end(), '%', ' ');
173  std::stringstream stream(fed);
174  for(;;)
175  {
176  std::string word;
177  if ( !(stream >> word) ){break;}
178  std::replace(word.begin(), word.end(), '&', ' ');
179  std::stringstream ss(word);
180  int fedNumber;
181  int val;
182  ss >> fedNumber >> val;
183  //std::cout << "fed:: " << fed << "--> val:: " << val << std::endl;
184  //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....)
185  if( (val & 0001) == 1 && (val != 5) && (val != 7) )
186  pRunInfo->m_fed_in.push_back(fedNumber);
187  }
188  // std::cout << "feds in run:--> ";
189  // std::copy(pRunInfo->m_fed_in.begin(), pRunInfo->m_fed_in.end(), std::ostream_iterator<int>(std::cout, ", "));
190  // std::cout << std::endl;
191  /*
192  for (size_t i =0; i<pRunInfo->m_fed_in.size() ; ++i)
193  {
194  std::cout << "fed in run:--> " << pRunInfo->m_fed_in[i] << std::endl;
195  }
196  */
197 
198  return pRunInfo ;
199 }
200 
201 //define this as a plug-in
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:124
L1RCTOmdsFedVectorProducer(const edm::ParameterSet &)
std::unique_ptr< RunInfo > ReturnType
void start(bool readOnly=true)
Definition: Session.cc:22
def replace(string, replacements)
Transaction & transaction()
Definition: Session.cc:66
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
coral::ISessionProxy & coralSession()
Definition: Session.cc:236
ReturnType produce(const RunInfoRcd &)
int m_run
Definition: RunInfo.h:21
void setAuthenticationPath(const std::string &p)
T const * product() const
Definition: ESHandle.h:86