Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <memory>
00023 #include "boost/shared_ptr.hpp"
00024
00025
00026 #include "FWCore/Framework/interface/ModuleFactory.h"
00027 #include "FWCore/Framework/interface/ESProducer.h"
00028
00029 #include "FWCore/Framework/interface/ESHandle.h"
00030
00031
00032 #include "RelationalAccess/ISession.h"
00033 #include "RelationalAccess/ITransaction.h"
00034 #include "RelationalAccess/IRelationalDomain.h"
00035 #include "RelationalAccess/ISchema.h"
00036 #include "RelationalAccess/IQuery.h"
00037 #include "RelationalAccess/ICursor.h"
00038 #include "RelationalAccess/IConnection.h"
00039 #include "CoralBase/AttributeList.h"
00040 #include "CoralBase/Attribute.h"
00041 #include "CoralKernel/Context.h"
00042
00043 #include "CondCore/DBCommon/interface/DbConnection.h"
00044 #include "CondCore/DBCommon/interface/DbConnectionConfiguration.h"
00045 #include "CondCore/DBCommon/interface/DbTransaction.h"
00046
00047
00048 #include "CondFormats/RunInfo/interface/RunInfo.h"
00049 #include "FWCore/Framework/interface/Run.h"
00050 #include "FWCore/Framework/interface/LuminosityBlock.h"
00051
00052 #include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
00053
00054
00055
00056
00057
00058
00059 class L1RCTOmdsFedVectorProducer : public edm::ESProducer {
00060 public:
00061 L1RCTOmdsFedVectorProducer(const edm::ParameterSet&);
00062 ~L1RCTOmdsFedVectorProducer();
00063
00064 typedef boost::shared_ptr<RunInfo> ReturnType;
00065
00066 ReturnType produce(const RunInfoRcd&);
00067 private:
00068
00069 std::string connectionString;
00070 std::string authpath;
00071 std::string tableToRead;
00072
00073 };
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 L1RCTOmdsFedVectorProducer::L1RCTOmdsFedVectorProducer(const edm::ParameterSet& iConfig) :
00087 connectionString(iConfig.getParameter<std::string>("connectionString")),
00088 authpath(iConfig.getParameter<std::string>("authpath")),
00089 tableToRead(iConfig.getParameter<std::string>("tableToRead"))
00090 {
00091
00092
00093 setWhatProduced(this,"OmdsFedVector");
00094
00095
00096 }
00097
00098
00099 L1RCTOmdsFedVectorProducer::~L1RCTOmdsFedVectorProducer()
00100 {
00101
00102
00103
00104
00105 }
00106
00107
00108
00109
00110
00111
00112
00113 L1RCTOmdsFedVectorProducer::ReturnType
00114 L1RCTOmdsFedVectorProducer::produce(const RunInfoRcd& iRecord)
00115 {
00116
00117
00118 using namespace edm::es;
00119 boost::shared_ptr<RunInfo> pRunInfo ;
00120
00121
00122
00123
00124 edm::ESHandle<RunInfo> sum;
00125 iRecord.get(sum);
00126 const RunInfo* summary=sum.product();
00127 int runNumber = summary->m_run;
00128
00129
00130 pRunInfo = boost::shared_ptr<RunInfo>( new RunInfo() );
00131
00132
00133
00134
00135
00136 cond::DbConnection connection;
00137
00138
00139 connection.configuration().setAuthenticationPath(authpath);
00140 connection.configure();
00141
00142
00143 cond::DbSession session = connection.createSession();
00144
00145 session.open(connectionString,true);
00146
00147 session.transaction().start(true);
00148
00149 coral::ISchema& schema = session.schema("CMS_RUNINFO");
00150
00151
00152 coral::AttributeList conditionData;
00153 conditionData.extend<int>( "n_run" );
00154 conditionData[0].data<int>() = runNumber;
00155
00156 std::string columnToRead_val = "VALUE";
00157
00158 std::string tableToRead_fed = "RUNSESSION_STRING";
00159 coral::IQuery* queryV = schema.newQuery();
00160 queryV->addToTableList(tableToRead);
00161 queryV->addToTableList(tableToRead_fed);
00162 queryV->addToOutputList(tableToRead_fed + "." + columnToRead_val, columnToRead_val);
00163
00164
00165 std::string condition = tableToRead + ".RUNNUMBER=:n_run AND " + tableToRead + ".NAME='CMS.LVL0:FED_ENABLE_MASK' AND RUNSESSION_PARAMETER.ID = RUNSESSION_STRING.RUNSESSION_PARAMETER_ID";
00166
00167 queryV->setCondition(condition, conditionData);
00168 coral::ICursor& cursorV = queryV->execute();
00169 std::string fed;
00170 if ( cursorV.next() ) {
00171
00172 const coral::AttributeList& row = cursorV.currentRow();
00173 fed = row[columnToRead_val].data<std::string>();
00174 }
00175 else {
00176 fed="null";
00177 }
00178
00179 delete queryV;
00180
00181 std::replace(fed.begin(), fed.end(), '%', ' ');
00182 std::stringstream stream(fed);
00183 for(;;)
00184 {
00185 std::string word;
00186 if ( !(stream >> word) ){break;}
00187 std::replace(word.begin(), word.end(), '&', ' ');
00188 std::stringstream ss(word);
00189 int fedNumber;
00190 int val;
00191 ss >> fedNumber >> val;
00192
00193
00194 if( (val & 0001) == 1 && (val != 5) && (val != 7) )
00195 pRunInfo->m_fed_in.push_back(fedNumber);
00196 }
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 return pRunInfo ;
00208 }
00209
00210
00211 DEFINE_FWK_EVENTSETUP_MODULE(L1RCTOmdsFedVectorProducer);