test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 #include "boost/shared_ptr.hpp"
23 
24 // user include files
27 
29 
30 // OMDS stuff
31 #include "RelationalAccess/ISessionProxy.h"
32 #include "RelationalAccess/ITransaction.h"
33 #include "RelationalAccess/IRelationalDomain.h"
34 #include "RelationalAccess/ISchema.h"
35 #include "RelationalAccess/IQuery.h"
36 #include "RelationalAccess/ICursor.h"
37 #include "RelationalAccess/IConnection.h"
38 #include "CoralBase/AttributeList.h"
39 #include "CoralBase/Attribute.h"
40 #include "CoralKernel/Context.h"
41 
43 // end OMDS stuff
44 
48 
50 
51 
52 //
53 // class declaration
54 //
55 
57 public:
60 
61  typedef boost::shared_ptr<RunInfo> ReturnType;
62 
64 private:
65  // ----------member data ---------------------------
69 
70 };
71 
72 //
73 // constants, enums and typedefs
74 //
75 
76 //
77 // static data member definitions
78 //
79 
80 //
81 // constructors and destructor
82 //
84  connectionString(iConfig.getParameter<std::string>("connectionString")),
85  authpath(iConfig.getParameter<std::string>("authpath")),
86  tableToRead(iConfig.getParameter<std::string>("tableToRead"))
87 {
88  //the following line is needed to tell the framework what
89  // data is being produced
90  setWhatProduced(this,"OmdsFedVector");
91 
92  //now do what ever other initialization is needed
93 }
94 
95 
97 {
98 
99  // do anything here that needs to be done at desctruction time
100  // (e.g. close files, deallocate resources etc.)
101 
102 }
103 
104 
105 //
106 // member functions
107 //
108 
109 // ------------ method called to produce the data ------------
112 {
113  // std::cout << "ENTERING L1RCTOmdsFedVectorProducer::produce()" << std::endl;
114 
115  using namespace edm::es;
116  boost::shared_ptr<RunInfo> pRunInfo ;
117 
118  // std::cout << "GETTING FED VECTOR FROM OMDS" << std::endl;
119 
120  // GETTING ALREADY-EXISTING RUNINFO OUT OF ES TO FIND OUT RUN NUMBER
122  iRecord.get(sum);
123  const RunInfo* summary=sum.product();
124  int runNumber = summary->m_run;
125 
126  // CREATING NEW RUNINFO WHICH WILL GET NEW FED VECTOR AND BE RETURNED
127  pRunInfo = boost::shared_ptr<RunInfo>( new RunInfo() );
128 
129 
130  // DO THE DATABASE STUFF
131 
132  //make connection object
134 
135  //set in configuration object authentication path
136  connection.setAuthenticationPath(authpath);
137  connection.configure();
138 
139  //create session object from connection
140  cond::persistency::Session session = connection.createSession(connectionString,true );
141 
142  session.transaction().start(true); // (true=readOnly)
143 
144  coral::ISchema& schema = session.coralSession().schema("CMS_RUNINFO");
145 
146  //condition
147  coral::AttributeList conditionData;
148  conditionData.extend<int>( "n_run" );
149  conditionData[0].data<int>() = runNumber;
150 
151  std::string columnToRead_val = "VALUE";
152 
153  std::string tableToRead_fed = "RUNSESSION_STRING";
154  coral::IQuery* queryV = schema.newQuery();
155  queryV->addToTableList(tableToRead);
156  queryV->addToTableList(tableToRead_fed);
157  queryV->addToOutputList(tableToRead_fed + "." + columnToRead_val, columnToRead_val);
158  //queryV->addToOutputList(tableToRead + "." + columnToRead, columnToRead);
159  //condition
160  std::string condition = tableToRead + ".RUNNUMBER=:n_run AND " + tableToRead + ".NAME='CMS.LVL0:FED_ENABLE_MASK' AND RUNSESSION_PARAMETER.ID = RUNSESSION_STRING.RUNSESSION_PARAMETER_ID";
161  //std::string condition = tableToRead + ".runnumber=:n_run AND " + tableToRead + ".name='CMS.LVL0:FED_ENABLE_MASK'";
162  queryV->setCondition(condition, conditionData);
163  coral::ICursor& cursorV = queryV->execute();
164  std::string fed;
165  if ( cursorV.next() ) {
166  //cursorV.currentRow().toOutputStream(std::cout) << std::endl;
167  const coral::AttributeList& row = cursorV.currentRow();
168  fed = row[columnToRead_val].data<std::string>();
169  }
170  else {
171  fed="null";
172  }
173  //std::cout << "string fed emask == " << fed << std::endl;
174  delete queryV;
175 
176  std::replace(fed.begin(), fed.end(), '%', ' ');
177  std::stringstream stream(fed);
178  for(;;)
179  {
180  std::string word;
181  if ( !(stream >> word) ){break;}
182  std::replace(word.begin(), word.end(), '&', ' ');
183  std::stringstream ss(word);
184  int fedNumber;
185  int val;
186  ss >> fedNumber >> val;
187  //std::cout << "fed:: " << fed << "--> val:: " << val << std::endl;
188  //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....)
189  if( (val & 0001) == 1 && (val != 5) && (val != 7) )
190  pRunInfo->m_fed_in.push_back(fedNumber);
191  }
192  // std::cout << "feds in run:--> ";
193  // std::copy(pRunInfo->m_fed_in.begin(), pRunInfo->m_fed_in.end(), std::ostream_iterator<int>(std::cout, ", "));
194  // std::cout << std::endl;
195  /*
196  for (size_t i =0; i<pRunInfo->m_fed_in.size() ; ++i)
197  {
198  std::cout << "fed in run:--> " << pRunInfo->m_fed_in[i] << std::endl;
199  }
200  */
201 
202  return pRunInfo ;
203 }
204 
205 //define this as a plug-in
boost::shared_ptr< RunInfo > ReturnType
L1RCTOmdsFedVectorProducer(const edm::ParameterSet &)
tuple schema
Definition: dataDML.py:2334
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
void get(HolderT &iHolder) const
string authpath
Definition: EcalCondDB.py:77
string connectionString
Definition: autoCondHLT.py:4
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
ReturnType produce(const RunInfoRcd &)
session
Definition: models.py:201
void setAuthenticationPath(const std::string &p)