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/ISession.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 
45 // end OMDS stuff
46 
50 
52 
53 
54 //
55 // class declaration
56 //
57 
59 public:
62 
63  typedef boost::shared_ptr<RunInfo> ReturnType;
64 
66 private:
67  // ----------member data ---------------------------
71 
72 };
73 
74 //
75 // constants, enums and typedefs
76 //
77 
78 //
79 // static data member definitions
80 //
81 
82 //
83 // constructors and destructor
84 //
86  connectionString(iConfig.getParameter<std::string>("connectionString")),
87  authpath(iConfig.getParameter<std::string>("authpath")),
88  tableToRead(iConfig.getParameter<std::string>("tableToRead"))
89 {
90  //the following line is needed to tell the framework what
91  // data is being produced
92  setWhatProduced(this,"OmdsFedVector");
93 
94  //now do what ever other initialization is needed
95 }
96 
97 
99 {
100 
101  // do anything here that needs to be done at desctruction time
102  // (e.g. close files, deallocate resources etc.)
103 
104 }
105 
106 
107 //
108 // member functions
109 //
110 
111 // ------------ method called to produce the data ------------
114 {
115  // std::cout << "ENTERING L1RCTOmdsFedVectorProducer::produce()" << std::endl;
116 
117  using namespace edm::es;
118  boost::shared_ptr<RunInfo> pRunInfo ;
119 
120  // std::cout << "GETTING FED VECTOR FROM OMDS" << std::endl;
121 
122  // GETTING ALREADY-EXISTING RUNINFO OUT OF ES TO FIND OUT RUN NUMBER
124  iRecord.get(sum);
125  const RunInfo* summary=sum.product();
126  int runNumber = summary->m_run;
127 
128  // CREATING NEW RUNINFO WHICH WILL GET NEW FED VECTOR AND BE RETURNED
129  pRunInfo = boost::shared_ptr<RunInfo>( new RunInfo() );
130 
131 
132  // DO THE DATABASE STUFF
133 
134  //make connection object
135  cond::DbConnection connection;
136 
137  //set in configuration object authentication path
139  connection.configure();
140 
141  //create session object from connection
142  cond::DbSession session = connection.createSession();
143 
144  session.open(connectionString,true);
145 
146  session.transaction().start(true); // (true=readOnly)
147 
148  coral::ISchema& schema = session.schema("CMS_RUNINFO");
149 
150  //condition
151  coral::AttributeList conditionData;
152  conditionData.extend<int>( "n_run" );
153  conditionData[0].data<int>() = runNumber;
154 
155  std::string columnToRead_val = "VALUE";
156 
157  std::string tableToRead_fed = "RUNSESSION_STRING";
158  coral::IQuery* queryV = schema.newQuery();
159  queryV->addToTableList(tableToRead);
160  queryV->addToTableList(tableToRead_fed);
161  queryV->addToOutputList(tableToRead_fed + "." + columnToRead_val, columnToRead_val);
162  //queryV->addToOutputList(tableToRead + "." + columnToRead, columnToRead);
163  //condition
164  std::string condition = tableToRead + ".RUNNUMBER=:n_run AND " + tableToRead + ".NAME='CMS.LVL0:FED_ENABLE_MASK' AND RUNSESSION_PARAMETER.ID = RUNSESSION_STRING.RUNSESSION_PARAMETER_ID";
165  //std::string condition = tableToRead + ".runnumber=:n_run AND " + tableToRead + ".name='CMS.LVL0:FED_ENABLE_MASK'";
166  queryV->setCondition(condition, conditionData);
167  coral::ICursor& cursorV = queryV->execute();
168  std::string fed;
169  if ( cursorV.next() ) {
170  //cursorV.currentRow().toOutputStream(std::cout) << std::endl;
171  const coral::AttributeList& row = cursorV.currentRow();
172  fed = row[columnToRead_val].data<std::string>();
173  }
174  else {
175  fed="null";
176  }
177  //std::cout << "string fed emask == " << fed << std::endl;
178  delete queryV;
179 
180  std::replace(fed.begin(), fed.end(), '%', ' ');
181  std::stringstream stream(fed);
182  for(;;)
183  {
184  std::string word;
185  if ( !(stream >> word) ){break;}
186  std::replace(word.begin(), word.end(), '&', ' ');
187  std::stringstream ss(word);
188  int fedNumber;
189  int val;
190  ss >> fedNumber >> val;
191  //std::cout << "fed:: " << fed << "--> val:: " << val << std::endl;
192  //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....)
193  if( (val & 0001) == 1 && (val != 5) && (val != 7) )
194  pRunInfo->m_fed_in.push_back(fedNumber);
195  }
196  // std::cout << "feds in run:--> ";
197  // std::copy(pRunInfo->m_fed_in.begin(), pRunInfo->m_fed_in.end(), std::ostream_iterator<int>(std::cout, ", "));
198  // std::cout << std::endl;
199  /*
200  for (size_t i =0; i<pRunInfo->m_fed_in.size() ; ++i)
201  {
202  std::cout << "fed in run:--> " << pRunInfo->m_fed_in[i] << std::endl;
203  }
204  */
205 
206  return pRunInfo ;
207 }
208 
209 //define this as a plug-in
boost::shared_ptr< RunInfo > ReturnType
L1RCTOmdsFedVectorProducer(const edm::ParameterSet &)
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:83
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
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void setAuthenticationPath(const std::string &p)
ReturnType produce(const RunInfoRcd &)