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 std::auto_ptr<LumiSummary> pOut1;
125 std::auto_ptr<LumiDetails> pOut2;
136 unsigned int currentrun=iLBlock.
run();
155 unsigned int lstowriteout=0;
157 std::vector<unsigned int>
v;
158 for(std::map<unsigned int,ExpressLumiProducer::PerLSData >::iterator it=
m_lscache.begin();it!=
m_lscache.end();++it){
159 v.push_back(it->first);
161 lstowriteout=v.back();
163 lstowriteout=currentls;
180 coral::AttributeList bindVariables;
181 bindVariables.extend(
"runnumber",
typeid(
unsigned int));
182 bindVariables[
"runnumber"].data<
unsigned int>()=runnumber;
184 coral::AttributeList MyOutput;
185 MyOutput.extend(
"maxavailablels",
typeid(
unsigned int));
186 coral::IQuery*
myQuery=schema.newQuery();
187 myQuery->addToTableList(tablename);
188 myQuery->addToOutputList(
"max(LUMISECTION)",
"maxavailablels");
189 myQuery->setCondition(conditionStr,bindVariables);
190 myQuery->defineOutput(MyOutput);
191 coral::ICursor& mycursor=myQuery->execute();
192 while( mycursor.next() ){
193 const coral::AttributeList& row=mycursor.currentRow();
194 if(!row[
"maxavailablels"].isNull()){
195 result=row[
"maxavailablels"].data<
unsigned int>();
211 throw cms::Exception(
"Non existing service lumi::service::DBService");
214 coral::ITypeConverter& tconverter=session->typeConverter();
218 unsigned int lsmin=1;
219 unsigned int lsmax=currentlsnum;
221 session->transaction().start(
true);
222 coral::ISchema&
schema=session->nominalSchema();
224 if(maxavailableLS!=0 && maxavailableLS<currentlsnum){
225 lsmax=maxavailableLS;
226 }
else if(maxavailableLS==0){
228 session->transaction().commit();
235 for(
unsigned int n=lsmin;
n<=lsmax;++
n){
237 std::vector<float> mytmp(3564,0.0);
239 std::vector<float> myerrtmp(3564,0.0);
241 std::vector<short> myqtmp(3564,0);
246 coral::AttributeList lumisummaryBindVariables;
247 lumisummaryBindVariables.extend(
"lsmin",
typeid(
unsigned int));
248 lumisummaryBindVariables.extend(
"runnumber",
typeid(
unsigned int));
249 lumisummaryBindVariables[
"runnumber"].data<
unsigned int>()=
m_cachedrun;
250 lumisummaryBindVariables[
"lsmin"].data<
unsigned int>()=lsmin;
251 std::string conditionStr(
" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin ");
252 coral::AttributeList lumisummaryOutput;
253 lumisummaryOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
254 lumisummaryOutput.extend(
"INSTLUMI",
typeid(
float));
255 lumisummaryOutput.extend(
"DELIVLUMISECTION",
typeid(
float));
256 lumisummaryOutput.extend(
"LIVELUMISECTION",
typeid(
float));
257 lumisummaryOutput.extend(
"STARTORBIT",
typeid(
unsigned long long));
259 lumisummaryBindVariables.extend(
"lsmax",
typeid(
unsigned int));
260 conditionStr=conditionStr+
"AND LUMISECTION<=:lsmax";
261 lumisummaryBindVariables[
"lsmax"].data<
unsigned int>()=lsmax;
263 coral::IQuery* lumisummaryQuery=schema.newQuery();
264 lumisummaryQuery->addToTableList(
std::string(
"LUMI_SECTIONS"));
265 lumisummaryQuery->addToOutputList(
"LUMISECTION");
266 lumisummaryQuery->addToOutputList(
"INSTLUMI");
267 lumisummaryQuery->addToOutputList(
"DELIVLUMISECTION");
268 lumisummaryQuery->addToOutputList(
"LIVELUMISECTION");
269 lumisummaryQuery->addToOutputList(
"STARTORBIT");
270 lumisummaryQuery->setCondition(conditionStr,lumisummaryBindVariables);
271 lumisummaryQuery->defineOutput(lumisummaryOutput);
272 coral::ICursor& lumisummarycursor=lumisummaryQuery->execute();
273 unsigned int rowcounter=0;
274 while( lumisummarycursor.next() ){
275 const coral::AttributeList& row=lumisummarycursor.currentRow();
276 unsigned int lsnum=row[
"LUMISECTION"].data<
unsigned int>();
278 if(!row[
"INSTLUMI"].isNull()){
279 instlumi=row[
"INSTLUMI"].data<
float>();
282 float intgdellumi=0.0;
283 float intgreclumi=0.0;
284 unsigned long long startorbit=0;
285 if(!row[
"DELIVLUMISECTION"].isNull()){
286 intgdellumi=row[
"DELIVLUMISECTION"].data<
float>()*1000.0;
288 if(!row[
"LIVELUMISECTION"].isNull()){
289 intgreclumi=row[
"LIVELUMISECTION"].data<
float>()*1000.0;
292 deadfrac=1.0-intgreclumi/intgdellumi;
294 if(!row[
"STARTORBIT"].isNull()){
295 startorbit=row[
"STARTORBIT"].data<
unsigned long long>();
297 unsigned long long deadcount=deadfrac*10000.0;
298 unsigned long long bitzerocount=10000.0;
311 delete lumisummaryQuery;
318 coral::AttributeList lumidetailBindVariables;
319 lumidetailBindVariables.extend(
"lsmin",
typeid(
unsigned int));
320 lumidetailBindVariables.extend(
"runnumber",
typeid(
unsigned int));
321 lumidetailBindVariables[
"runnumber"].data<
unsigned int>()=
m_cachedrun;
322 lumidetailBindVariables[
"lsmin"].data<
unsigned int>()=lsmin;
323 std::string detailconditionStr(
" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND BUNCHLUMI>0 ");
324 coral::AttributeList lumidetailOutput;
325 lumidetailOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
326 lumidetailOutput.extend(
"BUNCH",
typeid(
unsigned int));
327 lumidetailOutput.extend(
"BUNCHLUMI",
typeid(
float));
329 lumidetailBindVariables.extend(
"lsmax",
typeid(
unsigned int));
330 detailconditionStr=detailconditionStr+
"AND LUMISECTION<=:lsmax";
331 lumidetailBindVariables[
"lsmax"].data<
unsigned int>()=lsmax;
333 coral::IQuery* lumidetailQuery=schema.newQuery();
334 lumidetailQuery->addToTableList(
std::string(
"BUNCH_LUMI_SECTIONS"));
335 lumidetailQuery->addToOutputList(
"LUMISECTION");
336 lumidetailQuery->addToOutputList(
"BUNCH");
337 lumidetailQuery->addToOutputList(
"BUNCHLUMI");
338 lumidetailQuery->setCondition(detailconditionStr,lumidetailBindVariables);
339 lumidetailQuery->defineOutput(lumidetailOutput);
340 coral::ICursor& lumidetailcursor=lumidetailQuery->execute();
341 while( lumidetailcursor.next() ){
342 const coral::AttributeList& row=lumidetailcursor.currentRow();
343 unsigned int lsnum=row[
"LUMISECTION"].data<
unsigned int>();
344 unsigned int bxidx=row[
"BUNCH"].data<
unsigned int>();
345 float bxlumi=row[
"BUNCHLUMI"].data<
float>();
346 m_lscache[lsnum].bunchlumivalue[bxidx]=bxlumi;
348 delete lumidetailQuery;
349 session->transaction().commit();
351 session->transaction().rollback();
360 std::auto_ptr<LumiSummary> pOut1;
361 std::auto_ptr<LumiDetails> pOut2;
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
void setLumiVersion(std::string const &lumiVersion)
std::map< unsigned int, PerLSData > m_lscache
void setlsnumber(unsigned int lsnumber)
void setOrbitData(unsigned int startorbit, unsigned int numorbit)
void fill(AlgoType algo, std::vector< float > const &values, std::vector< float > const &errors, std::vector< short > const &qualities)
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)
void setLumiVersion(const std::string &lumiversion)
std::vector< float > bunchlumivalue
void setLumiData(float instlumi, float instlumierr, short lumiquality)
void setBitZeroCount(unsigned long long bitzerocount)
unsigned int bitzerocount
unsigned int maxavailableLSforRun(coral::ISchema &schema, const std::string &tablename, unsigned int runnumber)
void setDeadCount(unsigned long long deadcount)
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)
void put(std::auto_ptr< PROD > product)
Put a new product.