24 #include "CoralBase/Exception.h"
25 #include "CoralBase/AttributeList.h"
26 #include "CoralBase/Attribute.h"
27 #include "CoralBase/AttributeSpecification.h"
28 #include "CoralBase/Exception.h"
29 #include "CoralBase/Blob.h"
30 #include "RelationalAccess/ISessionProxy.h"
31 #include "RelationalAccess/ITransaction.h"
32 #include "RelationalAccess/AccessMode.h"
33 #include "RelationalAccess/ITypeConverter.h"
34 #include "RelationalAccess/IQuery.h"
35 #include "RelationalAccess/ICursor.h"
36 #include "RelationalAccess/ISchema.h"
37 #include "RelationalAccess/ITable.h"
52 #include <boost/tokenizer.hpp>
85 void fillLSCache(
unsigned int runnum,
unsigned int luminum);
97 : m_cachedrun(0), m_isNullRun(
false), m_cachesize(0) {
99 produces<LumiSummary, edm::Transition::BeginLuminosityBlock>();
100 produces<LumiDetails, edm::Transition::BeginLuminosityBlock>();
103 m_cachesize =
iConfig.getUntrackedParameter<
unsigned int>(
"ncacheEntries", 5);
114 iLBlock.
put(std::make_unique<LumiSummary>());
115 iLBlock.
put(std::make_unique<LumiDetails>());
118 unsigned int currentrun = iLBlock.
run();
137 unsigned int lstowriteout = 0;
139 std::vector<unsigned int>
v;
140 for (std::map<unsigned int, ExpressLumiProducer::PerLSData>::iterator it =
m_lscache.begin(); it !=
m_lscache.end();
142 v.push_back(it->first);
144 lstowriteout = v.back();
146 lstowriteout = currentls;
150 if (lstowriteout == 0) {
164 coral::AttributeList bindVariables;
165 bindVariables.extend(
"runnumber",
typeid(
unsigned int));
166 bindVariables[
"runnumber"].data<
unsigned int>() = runnumber;
168 coral::AttributeList MyOutput;
169 MyOutput.extend(
"maxavailablels",
typeid(
unsigned int));
170 coral::IQuery*
myQuery = schema.newQuery();
171 myQuery->addToTableList(tablename);
172 myQuery->addToOutputList(
"max(LUMISECTION)",
"maxavailablels");
173 myQuery->setCondition(conditionStr, bindVariables);
174 myQuery->defineOutput(MyOutput);
175 coral::ICursor& mycursor = myQuery->execute();
176 while (mycursor.next()) {
177 const coral::AttributeList& row = mycursor.currentRow();
178 if (!row[
"maxavailablels"].isNull()) {
179 result = row[
"maxavailablels"].data<
unsigned int>();
194 throw cms::Exception(
"Non existing service lumi::service::DBService");
197 coral::ITypeConverter& tconverter =
session->typeConverter();
201 unsigned int lsmin = 1;
202 unsigned int lsmax = currentlsnum;
204 session->transaction().start(
true);
205 coral::ISchema& schema =
session->nominalSchema();
207 if (maxavailableLS != 0 && maxavailableLS < currentlsnum) {
208 lsmax = maxavailableLS;
209 }
else if (maxavailableLS == 0) {
211 session->transaction().commit();
217 for (
unsigned int n = lsmin;
n <=
lsmax; ++
n) {
222 coral::AttributeList lumisummaryBindVariables;
223 lumisummaryBindVariables.extend(
"lsmin",
typeid(
unsigned int));
224 lumisummaryBindVariables.extend(
"runnumber",
typeid(
unsigned int));
225 lumisummaryBindVariables[
"runnumber"].data<
unsigned int>() =
m_cachedrun;
226 lumisummaryBindVariables[
"lsmin"].data<
unsigned int>() = lsmin;
227 std::string conditionStr(
" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin ");
228 coral::AttributeList lumisummaryOutput;
229 lumisummaryOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
230 lumisummaryOutput.extend(
"INSTLUMI",
typeid(
float));
231 lumisummaryOutput.extend(
"DELIVLUMISECTION",
typeid(
float));
232 lumisummaryOutput.extend(
"LIVELUMISECTION",
typeid(
float));
233 lumisummaryOutput.extend(
"STARTORBIT",
typeid(
unsigned long long));
235 lumisummaryBindVariables.extend(
"lsmax",
typeid(
unsigned int));
236 conditionStr = conditionStr +
"AND LUMISECTION<=:lsmax";
237 lumisummaryBindVariables[
"lsmax"].data<
unsigned int>() = lsmax;
239 coral::IQuery* lumisummaryQuery = schema.newQuery();
240 lumisummaryQuery->addToTableList(
std::string(
"LUMI_SECTIONS"));
241 lumisummaryQuery->addToOutputList(
"LUMISECTION");
242 lumisummaryQuery->addToOutputList(
"INSTLUMI");
243 lumisummaryQuery->addToOutputList(
"DELIVLUMISECTION");
244 lumisummaryQuery->addToOutputList(
"LIVELUMISECTION");
245 lumisummaryQuery->addToOutputList(
"STARTORBIT");
246 lumisummaryQuery->setCondition(conditionStr, lumisummaryBindVariables);
247 lumisummaryQuery->defineOutput(lumisummaryOutput);
248 coral::ICursor& lumisummarycursor = lumisummaryQuery->execute();
249 unsigned int rowcounter = 0;
250 while (lumisummarycursor.next()) {
251 const coral::AttributeList& row = lumisummarycursor.currentRow();
252 unsigned int lsnum = row[
"LUMISECTION"].data<
unsigned int>();
253 float instlumi = 0.0;
254 if (!row[
"INSTLUMI"].isNull()) {
255 instlumi = row[
"INSTLUMI"].data<
float>();
257 float deadfrac = 1.0;
258 float intgdellumi = 0.0;
259 float intgreclumi = 0.0;
260 unsigned long long startorbit = 0;
261 if (!row[
"DELIVLUMISECTION"].isNull()) {
262 intgdellumi = row[
"DELIVLUMISECTION"].data<
float>() * 1000.0;
264 if (!row[
"LIVELUMISECTION"].isNull()) {
265 intgreclumi = row[
"LIVELUMISECTION"].data<
float>() * 1000.0;
267 if (intgdellumi > 0) {
268 deadfrac = 1.0 - intgreclumi / intgdellumi;
270 if (!row[
"STARTORBIT"].isNull()) {
271 startorbit = row[
"STARTORBIT"].data<
unsigned long long>();
273 unsigned long long deadcount = deadfrac * 10000.0;
274 unsigned long long bitzerocount = 10000.0;
276 lsdata.
lsnum = lsnum;
284 if (rowcounter == 0) {
287 delete lumisummaryQuery;
295 coral::AttributeList lumidetailBindVariables;
296 lumidetailBindVariables.extend(
"lsmin",
typeid(
unsigned int));
297 lumidetailBindVariables.extend(
"runnumber",
typeid(
unsigned int));
298 lumidetailBindVariables[
"runnumber"].data<
unsigned int>() =
m_cachedrun;
299 lumidetailBindVariables[
"lsmin"].data<
unsigned int>() = lsmin;
300 std::string detailconditionStr(
" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND BUNCHLUMI>0 ");
301 coral::AttributeList lumidetailOutput;
302 lumidetailOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
303 lumidetailOutput.extend(
"BUNCH",
typeid(
unsigned int));
304 lumidetailOutput.extend(
"BUNCHLUMI",
typeid(
float));
306 lumidetailBindVariables.extend(
"lsmax",
typeid(
unsigned int));
307 detailconditionStr = detailconditionStr +
"AND LUMISECTION<=:lsmax";
308 lumidetailBindVariables[
"lsmax"].data<
unsigned int>() = lsmax;
310 coral::IQuery* lumidetailQuery = schema.newQuery();
311 lumidetailQuery->addToTableList(
std::string(
"BUNCH_LUMI_SECTIONS"));
312 lumidetailQuery->addToOutputList(
"LUMISECTION");
313 lumidetailQuery->addToOutputList(
"BUNCH");
314 lumidetailQuery->addToOutputList(
"BUNCHLUMI");
315 lumidetailQuery->setCondition(detailconditionStr, lumidetailBindVariables);
316 lumidetailQuery->defineOutput(lumidetailOutput);
317 coral::ICursor& lumidetailcursor = lumidetailQuery->execute();
318 while (lumidetailcursor.next()) {
319 const coral::AttributeList& row = lumidetailcursor.currentRow();
320 unsigned int lsnum = row[
"LUMISECTION"].data<
unsigned int>();
321 unsigned int bxidx = row[
"BUNCH"].data<
unsigned int>();
322 float bxlumi = row[
"BUNCHLUMI"].data<
float>();
323 m_lscache[lsnum].bunchlumivalue[bxidx] = bxlumi;
325 delete lumidetailQuery;
326 session->transaction().commit();
328 session->transaction().rollback();
334 auto pIn1 = std::make_unique<LumiSummary>();
335 auto pIn2 = std::make_unique<LumiDetails>();
337 pIn1->setLumiVersion(
"DIP");
338 pIn2->setLumiVersion(
"DIP");
344 pIn1->setLumiVersion(
"DIP");
345 pIn1->setLumiData(lsdata.
lumivalue, 0.0, 0.0);
348 pIn1->setlsnumber(lsdata.
lsnum);
351 pIn2->setLumiVersion(
"DIP");
unsigned long long deadcount
#define DEFINE_FWK_MODULE(type)
ISessionProxyPtr connectReadOnly(const std::string &connectstring)
std::vector< short > bunchlumiquality
LuminosityBlockNumber_t luminosityBlock() const
void put(std::unique_ptr< PROD > product)
Put a new product.
void fillLSCache(unsigned int runnum, unsigned int luminum)
void produce(edm::Event &, const edm::EventSetup &) final
void writeProductsForEntry(edm::LuminosityBlock &iLBlock, unsigned int luminum)
void writeEmptyProductForEntry(edm::LuminosityBlock &iLBlock)
void beginLuminosityBlockProduce(edm::LuminosityBlock &iLBlock, edm::EventSetup const &iSetup) final
std::vector< float > bunchlumivalue
unsigned int bitzerocount
unsigned int maxavailableLSforRun(coral::ISchema &schema, const std::string &tablename, unsigned int runnumber)
std::vector< float > bunchlumierror
~ExpressLumiProducer() override
ExpressLumiProducer(const edm::ParameterSet &)
std::map< unsigned int, PerLSData > m_lscache
bool fillLumi(edm::LuminosityBlock &iLBlock)