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/foreach.hpp>
51 #include <boost/tokenizer.hpp>
52 #include "boost/filesystem/path.hpp"
53 #include "boost/filesystem/operations.hpp"
104 produces<LumiSummary, edm::InLumi>();
105 produces<LumiDetails, edm::InLumi>();
107 m_connectStr=iConfig.getParameter<
std::string>(
"connect");
108 m_cachesize=iConfig.getUntrackedParameter<
unsigned int>(
"ncacheEntries",5);
124 iLBlock.
put(std::make_unique<LumiSummary>());
125 iLBlock.
put(std::make_unique<LumiDetails>());
130 unsigned int currentrun=iLBlock.
run();
149 unsigned int lstowriteout=0;
151 std::vector<unsigned int>
v;
152 for(std::map<unsigned int,ExpressLumiProducer::PerLSData >::iterator it=
m_lscache.begin();it!=
m_lscache.end();++it){
153 v.push_back(it->first);
155 lstowriteout=v.back();
157 lstowriteout=currentls;
174 coral::AttributeList bindVariables;
175 bindVariables.extend(
"runnumber",
typeid(
unsigned int));
176 bindVariables[
"runnumber"].data<
unsigned int>()=runnumber;
178 coral::AttributeList MyOutput;
179 MyOutput.extend(
"maxavailablels",
typeid(
unsigned int));
180 coral::IQuery*
myQuery=schema.newQuery();
181 myQuery->addToTableList(tablename);
182 myQuery->addToOutputList(
"max(LUMISECTION)",
"maxavailablels");
183 myQuery->setCondition(conditionStr,bindVariables);
184 myQuery->defineOutput(MyOutput);
185 coral::ICursor& mycursor=myQuery->execute();
186 while( mycursor.next() ){
187 const coral::AttributeList& row=mycursor.currentRow();
188 if(!row[
"maxavailablels"].isNull()){
189 result=row[
"maxavailablels"].data<
unsigned int>();
205 throw cms::Exception(
"Non existing service lumi::service::DBService");
208 coral::ITypeConverter& tconverter=session->typeConverter();
212 unsigned int lsmin=1;
213 unsigned int lsmax=currentlsnum;
215 session->transaction().start(
true);
216 coral::ISchema&
schema=session->nominalSchema();
218 if(maxavailableLS!=0 && maxavailableLS<currentlsnum){
219 lsmax=maxavailableLS;
220 }
else if(maxavailableLS==0){
222 session->transaction().commit();
229 for(
unsigned int n=lsmin;
n<=lsmax;++
n){
231 std::vector<float> mytmp(3564,0.0);
233 std::vector<float> myerrtmp(3564,0.0);
235 std::vector<short> myqtmp(3564,0);
240 coral::AttributeList lumisummaryBindVariables;
241 lumisummaryBindVariables.extend(
"lsmin",
typeid(
unsigned int));
242 lumisummaryBindVariables.extend(
"runnumber",
typeid(
unsigned int));
243 lumisummaryBindVariables[
"runnumber"].data<
unsigned int>()=
m_cachedrun;
244 lumisummaryBindVariables[
"lsmin"].data<
unsigned int>()=lsmin;
245 std::string conditionStr(
" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin ");
246 coral::AttributeList lumisummaryOutput;
247 lumisummaryOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
248 lumisummaryOutput.extend(
"INSTLUMI",
typeid(
float));
249 lumisummaryOutput.extend(
"DELIVLUMISECTION",
typeid(
float));
250 lumisummaryOutput.extend(
"LIVELUMISECTION",
typeid(
float));
251 lumisummaryOutput.extend(
"STARTORBIT",
typeid(
unsigned long long));
253 lumisummaryBindVariables.extend(
"lsmax",
typeid(
unsigned int));
254 conditionStr=conditionStr+
"AND LUMISECTION<=:lsmax";
255 lumisummaryBindVariables[
"lsmax"].data<
unsigned int>()=lsmax;
257 coral::IQuery* lumisummaryQuery=schema.newQuery();
258 lumisummaryQuery->addToTableList(
std::string(
"LUMI_SECTIONS"));
259 lumisummaryQuery->addToOutputList(
"LUMISECTION");
260 lumisummaryQuery->addToOutputList(
"INSTLUMI");
261 lumisummaryQuery->addToOutputList(
"DELIVLUMISECTION");
262 lumisummaryQuery->addToOutputList(
"LIVELUMISECTION");
263 lumisummaryQuery->addToOutputList(
"STARTORBIT");
264 lumisummaryQuery->setCondition(conditionStr,lumisummaryBindVariables);
265 lumisummaryQuery->defineOutput(lumisummaryOutput);
266 coral::ICursor& lumisummarycursor=lumisummaryQuery->execute();
267 unsigned int rowcounter=0;
268 while( lumisummarycursor.next() ){
269 const coral::AttributeList& row=lumisummarycursor.currentRow();
270 unsigned int lsnum=row[
"LUMISECTION"].data<
unsigned int>();
272 if(!row[
"INSTLUMI"].isNull()){
273 instlumi=row[
"INSTLUMI"].data<
float>();
276 float intgdellumi=0.0;
277 float intgreclumi=0.0;
278 unsigned long long startorbit=0;
279 if(!row[
"DELIVLUMISECTION"].isNull()){
280 intgdellumi=row[
"DELIVLUMISECTION"].data<
float>()*1000.0;
282 if(!row[
"LIVELUMISECTION"].isNull()){
283 intgreclumi=row[
"LIVELUMISECTION"].data<
float>()*1000.0;
286 deadfrac=1.0-intgreclumi/intgdellumi;
288 if(!row[
"STARTORBIT"].isNull()){
289 startorbit=row[
"STARTORBIT"].data<
unsigned long long>();
291 unsigned long long deadcount=deadfrac*10000.0;
292 unsigned long long bitzerocount=10000.0;
305 delete lumisummaryQuery;
312 coral::AttributeList lumidetailBindVariables;
313 lumidetailBindVariables.extend(
"lsmin",
typeid(
unsigned int));
314 lumidetailBindVariables.extend(
"runnumber",
typeid(
unsigned int));
315 lumidetailBindVariables[
"runnumber"].data<
unsigned int>()=
m_cachedrun;
316 lumidetailBindVariables[
"lsmin"].data<
unsigned int>()=lsmin;
317 std::string detailconditionStr(
" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND BUNCHLUMI>0 ");
318 coral::AttributeList lumidetailOutput;
319 lumidetailOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
320 lumidetailOutput.extend(
"BUNCH",
typeid(
unsigned int));
321 lumidetailOutput.extend(
"BUNCHLUMI",
typeid(
float));
323 lumidetailBindVariables.extend(
"lsmax",
typeid(
unsigned int));
324 detailconditionStr=detailconditionStr+
"AND LUMISECTION<=:lsmax";
325 lumidetailBindVariables[
"lsmax"].data<
unsigned int>()=lsmax;
327 coral::IQuery* lumidetailQuery=schema.newQuery();
328 lumidetailQuery->addToTableList(
std::string(
"BUNCH_LUMI_SECTIONS"));
329 lumidetailQuery->addToOutputList(
"LUMISECTION");
330 lumidetailQuery->addToOutputList(
"BUNCH");
331 lumidetailQuery->addToOutputList(
"BUNCHLUMI");
332 lumidetailQuery->setCondition(detailconditionStr,lumidetailBindVariables);
333 lumidetailQuery->defineOutput(lumidetailOutput);
334 coral::ICursor& lumidetailcursor=lumidetailQuery->execute();
335 while( lumidetailcursor.next() ){
336 const coral::AttributeList& row=lumidetailcursor.currentRow();
337 unsigned int lsnum=row[
"LUMISECTION"].data<
unsigned int>();
338 unsigned int bxidx=row[
"BUNCH"].data<
unsigned int>();
339 float bxlumi=row[
"BUNCHLUMI"].data<
float>();
340 m_lscache[lsnum].bunchlumivalue[bxidx]=bxlumi;
342 delete lumidetailQuery;
343 session->transaction().commit();
345 session->transaction().rollback();
354 auto pIn1 = std::make_unique<LumiSummary>();
355 auto pIn2 = std::make_unique<LumiDetails>();
357 pIn1->setLumiVersion(
"DIP");
358 pIn2->setLumiVersion(
"DIP");
364 pIn1->setLumiVersion(
"DIP");
365 pIn1->setLumiData(lsdata.
lumivalue,0.0,0.0);
368 pIn1->setlsnumber(lsdata.
lsnum);
371 pIn2->setLumiVersion(
"DIP");
virtual void produce(edm::Event &, const edm::EventSetup &) overridefinal
unsigned long long deadcount
#define DEFINE_FWK_MODULE(type)
virtual void beginLuminosityBlockProduce(edm::LuminosityBlock &iLBlock, edm::EventSetup const &iSetup) overridefinal
std::vector< short > bunchlumiquality
LuminosityBlockNumber_t luminosityBlock() const
std::map< unsigned int, PerLSData > m_lscache
void put(std::unique_ptr< PROD > product)
Put a new product.
void fillLSCache(unsigned int runnum, unsigned int luminum)
void writeProductsForEntry(edm::LuminosityBlock &iLBlock, unsigned int luminum)
void disconnect(coral::ISessionProxy *session)
void writeEmptyProductForEntry(edm::LuminosityBlock &iLBlock)
std::vector< float > bunchlumivalue
unsigned int bitzerocount
unsigned int maxavailableLSforRun(coral::ISchema &schema, const std::string &tablename, unsigned int runnumber)
std::vector< float > bunchlumierror
coral::ISessionProxy * connectReadOnly(const std::string &connectstring)
ExpressLumiProducer(const edm::ParameterSet &)
volatile std::atomic< bool > shutdown_flag false
bool fillLumi(edm::LuminosityBlock &iLBlock)