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