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"
50 #include <boost/tokenizer.hpp>
51 #include "boost/filesystem/path.hpp"
52 #include "boost/filesystem/operations.hpp"
85 void fillLSCache(
unsigned int runnum,
unsigned int luminum);
96 ExpressLumiProducer::ExpressLumiProducer::ExpressLumiProducer(
const edm::ParameterSet& iConfig)
97 : m_cachedrun(0), m_isNullRun(
false), m_cachesize(0) {
99 produces<LumiSummary, edm::Transition::BeginLuminosityBlock>();
100 produces<LumiDetails, edm::Transition::BeginLuminosityBlock>();
114 iLBlock.
put(std::make_unique<LumiSummary>());
115 iLBlock.
put(std::make_unique<LumiDetails>());
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();
219 std::vector<float> mytmp(3564, 0.0);
220 l.bunchlumivalue.swap(mytmp);
221 std::vector<float> myerrtmp(3564, 0.0);
222 l.bunchlumierror.swap(myerrtmp);
223 std::vector<short> myqtmp(3564, 0);
224 l.bunchlumiquality.swap(myqtmp);
228 coral::AttributeList lumisummaryBindVariables;
229 lumisummaryBindVariables.extend(
"lsmin",
typeid(
unsigned int));
230 lumisummaryBindVariables.extend(
"runnumber",
typeid(
unsigned int));
231 lumisummaryBindVariables[
"runnumber"].data<
unsigned int>() =
m_cachedrun;
232 lumisummaryBindVariables[
"lsmin"].data<
unsigned int>() =
lsmin;
233 std::string conditionStr(
" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin ");
234 coral::AttributeList lumisummaryOutput;
235 lumisummaryOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
236 lumisummaryOutput.extend(
"INSTLUMI",
typeid(
float));
237 lumisummaryOutput.extend(
"DELIVLUMISECTION",
typeid(
float));
238 lumisummaryOutput.extend(
"LIVELUMISECTION",
typeid(
float));
239 lumisummaryOutput.extend(
"STARTORBIT",
typeid(
unsigned long long));
241 lumisummaryBindVariables.extend(
"lsmax",
typeid(
unsigned int));
242 conditionStr = conditionStr +
"AND LUMISECTION<=:lsmax";
243 lumisummaryBindVariables[
"lsmax"].data<
unsigned int>() =
lsmax;
245 coral::IQuery* lumisummaryQuery = schema.newQuery();
246 lumisummaryQuery->addToTableList(
std::string(
"LUMI_SECTIONS"));
247 lumisummaryQuery->addToOutputList(
"LUMISECTION");
248 lumisummaryQuery->addToOutputList(
"INSTLUMI");
249 lumisummaryQuery->addToOutputList(
"DELIVLUMISECTION");
250 lumisummaryQuery->addToOutputList(
"LIVELUMISECTION");
251 lumisummaryQuery->addToOutputList(
"STARTORBIT");
252 lumisummaryQuery->setCondition(conditionStr, lumisummaryBindVariables);
253 lumisummaryQuery->defineOutput(lumisummaryOutput);
254 coral::ICursor& lumisummarycursor = lumisummaryQuery->execute();
255 unsigned int rowcounter = 0;
256 while (lumisummarycursor.next()) {
257 const coral::AttributeList& row = lumisummarycursor.currentRow();
258 unsigned int lsnum = row[
"LUMISECTION"].data<
unsigned int>();
259 float instlumi = 0.0;
260 if (!row[
"INSTLUMI"].isNull()) {
261 instlumi = row[
"INSTLUMI"].data<
float>();
263 float deadfrac = 1.0;
264 float intgdellumi = 0.0;
265 float intgreclumi = 0.0;
266 unsigned long long startorbit = 0;
267 if (!row[
"DELIVLUMISECTION"].isNull()) {
268 intgdellumi = row[
"DELIVLUMISECTION"].data<
float>() * 1000.0;
270 if (!row[
"LIVELUMISECTION"].isNull()) {
271 intgreclumi = row[
"LIVELUMISECTION"].data<
float>() * 1000.0;
273 if (intgdellumi > 0) {
274 deadfrac = 1.0 - intgreclumi / intgdellumi;
276 if (!row[
"STARTORBIT"].isNull()) {
277 startorbit = row[
"STARTORBIT"].data<
unsigned long long>();
279 unsigned long long deadcount = deadfrac * 10000.0;
280 unsigned long long bitzerocount = 10000.0;
282 lsdata.
lsnum = lsnum;
290 if (rowcounter == 0) {
293 delete lumisummaryQuery;
301 coral::AttributeList lumidetailBindVariables;
302 lumidetailBindVariables.extend(
"lsmin",
typeid(
unsigned int));
303 lumidetailBindVariables.extend(
"runnumber",
typeid(
unsigned int));
304 lumidetailBindVariables[
"runnumber"].data<
unsigned int>() =
m_cachedrun;
305 lumidetailBindVariables[
"lsmin"].data<
unsigned int>() =
lsmin;
306 std::string detailconditionStr(
" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND BUNCHLUMI>0 ");
307 coral::AttributeList lumidetailOutput;
308 lumidetailOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
309 lumidetailOutput.extend(
"BUNCH",
typeid(
unsigned int));
310 lumidetailOutput.extend(
"BUNCHLUMI",
typeid(
float));
312 lumidetailBindVariables.extend(
"lsmax",
typeid(
unsigned int));
313 detailconditionStr = detailconditionStr +
"AND LUMISECTION<=:lsmax";
314 lumidetailBindVariables[
"lsmax"].data<
unsigned int>() =
lsmax;
316 coral::IQuery* lumidetailQuery = schema.newQuery();
317 lumidetailQuery->addToTableList(
std::string(
"BUNCH_LUMI_SECTIONS"));
318 lumidetailQuery->addToOutputList(
"LUMISECTION");
319 lumidetailQuery->addToOutputList(
"BUNCH");
320 lumidetailQuery->addToOutputList(
"BUNCHLUMI");
321 lumidetailQuery->setCondition(detailconditionStr, lumidetailBindVariables);
322 lumidetailQuery->defineOutput(lumidetailOutput);
323 coral::ICursor& lumidetailcursor = lumidetailQuery->execute();
324 while (lumidetailcursor.next()) {
325 const coral::AttributeList& row = lumidetailcursor.currentRow();
326 unsigned int lsnum = row[
"LUMISECTION"].data<
unsigned int>();
327 unsigned int bxidx = row[
"BUNCH"].data<
unsigned int>();
328 float bxlumi = row[
"BUNCHLUMI"].data<
float>();
329 m_lscache[lsnum].bunchlumivalue[bxidx] = bxlumi;
331 delete lumidetailQuery;
332 session->transaction().commit();
334 session->transaction().rollback();
340 auto pIn1 = std::make_unique<LumiSummary>();
341 auto pIn2 = std::make_unique<LumiDetails>();
343 pIn1->setLumiVersion(
"DIP");
344 pIn2->setLumiVersion(
"DIP");
350 pIn1->setLumiVersion(
"DIP");
351 pIn1->setLumiData(lsdata.
lumivalue, 0.0, 0.0);
354 pIn1->setlsnumber(lsdata.
lsnum);
357 pIn2->setLumiVersion(
"DIP");