File indexing completed on 2024-04-06 12:22:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "FWCore/Framework/interface/ModuleFactory.h"
0024 #include "FWCore/Framework/interface/ESProducer.h"
0025
0026 #include "FWCore/Framework/interface/ESHandle.h"
0027
0028
0029 #include "RelationalAccess/ISessionProxy.h"
0030 #include "RelationalAccess/ITransaction.h"
0031 #include "RelationalAccess/IRelationalDomain.h"
0032 #include "RelationalAccess/ISchema.h"
0033 #include "RelationalAccess/IQuery.h"
0034 #include "RelationalAccess/ICursor.h"
0035 #include "RelationalAccess/IConnection.h"
0036 #include "CoralBase/AttributeList.h"
0037 #include "CoralBase/Attribute.h"
0038 #include "CoralKernel/Context.h"
0039
0040 #include "CondCore/CondDB/interface/ConnectionPool.h"
0041
0042
0043 #include "CondFormats/RunInfo/interface/RunInfo.h"
0044 #include "FWCore/Framework/interface/Run.h"
0045 #include "FWCore/Framework/interface/LuminosityBlock.h"
0046
0047 #include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
0048
0049
0050
0051
0052
0053 class L1RCTOmdsFedVectorProducer : public edm::ESProducer {
0054 public:
0055 L1RCTOmdsFedVectorProducer(const edm::ParameterSet&);
0056 ~L1RCTOmdsFedVectorProducer() override;
0057
0058 using ReturnType = std::unique_ptr<RunInfo>;
0059
0060 ReturnType produce(const RunInfoRcd&);
0061
0062 private:
0063
0064 std::string connectionString;
0065 std::string authpath;
0066 std::string tableToRead;
0067
0068 edm::ESGetToken<RunInfo, RunInfoRcd> token_;
0069 };
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 L1RCTOmdsFedVectorProducer::L1RCTOmdsFedVectorProducer(const edm::ParameterSet& iConfig)
0083 : connectionString(iConfig.getParameter<std::string>("connectionString")),
0084 authpath(iConfig.getParameter<std::string>("authpath")),
0085 tableToRead(iConfig.getParameter<std::string>("tableToRead")) {
0086
0087
0088 token_ = setWhatProduced(this, "OmdsFedVector").consumes();
0089
0090
0091 }
0092
0093 L1RCTOmdsFedVectorProducer::~L1RCTOmdsFedVectorProducer() {
0094
0095
0096 }
0097
0098
0099
0100
0101
0102
0103 L1RCTOmdsFedVectorProducer::ReturnType L1RCTOmdsFedVectorProducer::produce(const RunInfoRcd& iRecord) {
0104
0105
0106
0107
0108
0109 const RunInfo* summary = &iRecord.get(token_);
0110 int runNumber = summary->m_run;
0111
0112
0113 auto pRunInfo = std::make_unique<RunInfo>();
0114
0115
0116
0117
0118 cond::persistency::ConnectionPool connection;
0119
0120
0121 connection.setAuthenticationPath(authpath);
0122 connection.configure();
0123
0124
0125 cond::persistency::Session session = connection.createSession(connectionString, true);
0126
0127 session.transaction().start(true);
0128
0129 coral::ISchema& schema = session.coralSession().schema("CMS_RUNINFO");
0130
0131
0132 coral::AttributeList conditionData;
0133 conditionData.extend<int>("n_run");
0134 conditionData[0].data<int>() = runNumber;
0135
0136 std::string columnToRead_val = "VALUE";
0137
0138 std::string tableToRead_fed = "RUNSESSION_STRING";
0139 coral::IQuery* queryV = schema.newQuery();
0140 queryV->addToTableList(tableToRead);
0141 queryV->addToTableList(tableToRead_fed);
0142 queryV->addToOutputList(tableToRead_fed + "." + columnToRead_val, columnToRead_val);
0143
0144
0145 std::string condition =
0146 tableToRead + ".RUNNUMBER=:n_run AND " + tableToRead +
0147 ".NAME='CMS.LVL0:FED_ENABLE_MASK' AND RUNSESSION_PARAMETER.ID = RUNSESSION_STRING.RUNSESSION_PARAMETER_ID";
0148
0149 queryV->setCondition(condition, conditionData);
0150 coral::ICursor& cursorV = queryV->execute();
0151 std::string fed;
0152 if (cursorV.next()) {
0153
0154 const coral::AttributeList& row = cursorV.currentRow();
0155 fed = row[columnToRead_val].data<std::string>();
0156 } else {
0157 fed = "null";
0158 }
0159
0160 delete queryV;
0161
0162 std::replace(fed.begin(), fed.end(), '%', ' ');
0163 std::stringstream stream(fed);
0164 for (;;) {
0165 std::string word;
0166 if (!(stream >> word)) {
0167 break;
0168 }
0169 std::replace(word.begin(), word.end(), '&', ' ');
0170 std::stringstream ss(word);
0171 int fedNumber;
0172 int val;
0173 ss >> fedNumber >> val;
0174
0175
0176 if ((val & 0001) == 1 && (val != 5) && (val != 7))
0177 pRunInfo->m_fed_in.push_back(fedNumber);
0178 }
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189 return pRunInfo;
0190 }
0191
0192
0193 DEFINE_FWK_EVENTSETUP_MODULE(L1RCTOmdsFedVectorProducer);