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:
59 
60  typedef std::shared_ptr<RunInfo> ReturnType;
61 
62  ReturnType produce(const RunInfoRcd&);
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  using namespace edm::es;
115  std::shared_ptr<RunInfo> pRunInfo ;
116 
117  // std::cout << "GETTING FED VECTOR FROM OMDS" << std::endl;
118 
119  // GETTING ALREADY-EXISTING RUNINFO OUT OF ES TO FIND OUT RUN NUMBER
121  iRecord.get(sum);
122  const RunInfo* summary=sum.product();
123  int runNumber = summary->m_run;
124 
125  // CREATING NEW RUNINFO WHICH WILL GET NEW FED VECTOR AND BE RETURNED
126  pRunInfo = std::make_shared<RunInfo>();
127 
128 
129  // DO THE DATABASE STUFF
130 
131  //make connection object
133 
134  //set in configuration object authentication path
135  connection.setAuthenticationPath(authpath);
136  connection.configure();
137 
138  //create session object from connection
139  cond::persistency::Session session = connection.createSession(connectionString,true );
140 
141  session.transaction().start(true); // (true=readOnly)
142 
143  coral::ISchema& schema = session.coralSession().schema("CMS_RUNINFO");
144 
145  //condition
146  coral::AttributeList conditionData;
147  conditionData.extend<int>( "n_run" );
148  conditionData[0].data<int>() = runNumber;
149 
150  std::string columnToRead_val = "VALUE";
151 
152  std::string tableToRead_fed = "RUNSESSION_STRING";
153  coral::IQuery* queryV = schema.newQuery();
154  queryV->addToTableList(tableToRead);
155  queryV->addToTableList(tableToRead_fed);
156  queryV->addToOutputList(tableToRead_fed + "." + columnToRead_val, columnToRead_val);
157  //queryV->addToOutputList(tableToRead + "." + columnToRead, columnToRead);
158  //condition
159  std::string condition = tableToRead + ".RUNNUMBER=:n_run AND " + tableToRead + ".NAME='CMS.LVL0:FED_ENABLE_MASK' AND RUNSESSION_PARAMETER.ID = RUNSESSION_STRING.RUNSESSION_PARAMETER_ID";
160  //std::string condition = tableToRead + ".runnumber=:n_run AND " + tableToRead + ".name='CMS.LVL0:FED_ENABLE_MASK'";
161  queryV->setCondition(condition, conditionData);
162  coral::ICursor& cursorV = queryV->execute();
163  std::string fed;
164  if ( cursorV.next() ) {
165  //cursorV.currentRow().toOutputStream(std::cout) << std::endl;
166  const coral::AttributeList& row = cursorV.currentRow();
167  fed = row[columnToRead_val].data<std::string>();
168  }
169  else {
170  fed="null";
171  }
172  //std::cout << "string fed emask == " << fed << std::endl;
173  delete queryV;
174 
175  std::replace(fed.begin(), fed.end(), '%', ' ');
176  std::stringstream stream(fed);
177  for(;;)
178  {
179  std::string word;
180  if ( !(stream >> word) ){break;}
181  std::replace(word.begin(), word.end(), '&', ' ');
182  std::stringstream ss(word);
183  int fedNumber;
184  int val;
185  ss >> fedNumber >> val;
186  //std::cout << "fed:: " << fed << "--> val:: " << val << std::endl;
187  //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....)
188  if( (val & 0001) == 1 && (val != 5) && (val != 7) )
189  pRunInfo->m_fed_in.push_back(fedNumber);
190  }
191  // std::cout << "feds in run:--> ";
192  // std::copy(pRunInfo->m_fed_in.begin(), pRunInfo->m_fed_in.end(), std::ostream_iterator<int>(std::cout, ", "));
193  // std::cout << std::endl;
194  /*
195  for (size_t i =0; i<pRunInfo->m_fed_in.size() ; ++i)
196  {
197  std::cout << "fed in run:--> " << pRunInfo->m_fed_in[i] << std::endl;
198  }
199  */
200 
201  return pRunInfo ;
202 }
203 
204 //define this as a plug-in
L1RCTOmdsFedVectorProducer(const edm::ParameterSet &)
void start(bool readOnly=true)
Definition: Session.cc:22
def replace(string, replacements)
Transaction & transaction()
Definition: Session.cc:66
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
void get(HolderT &iHolder) const
std::shared_ptr< RunInfo > ReturnType
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
coral::ISessionProxy & coralSession()
Definition: Session.cc:228
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