25 #include "CoralBase/Exception.h"
26 #include "CoralBase/AttributeList.h"
27 #include "CoralBase/Attribute.h"
28 #include "CoralBase/AttributeSpecification.h"
29 #include "CoralBase/Exception.h"
30 #include "CoralBase/Blob.h"
31 #include "RelationalAccess/ISessionProxy.h"
32 #include "RelationalAccess/ITransaction.h"
33 #include "RelationalAccess/AccessMode.h"
34 #include "RelationalAccess/ITypeConverter.h"
35 #include "RelationalAccess/IQuery.h"
36 #include "RelationalAccess/ICursor.h"
37 #include "RelationalAccess/ISchema.h"
38 #include "RelationalAccess/ITable.h"
51 #include <boost/foreach.hpp>
52 #include <boost/tokenizer.hpp>
53 #include "boost/filesystem/path.hpp"
54 #include "boost/filesystem/operations.hpp"
105 produces<LumiSummary, edm::InLumi>();
106 produces<LumiDetails, edm::InLumi>();
108 m_connectStr=iConfig.getParameter<
std::string>(
"connect");
109 m_cachesize=iConfig.getUntrackedParameter<
unsigned int>(
"ncacheEntries",5);
125 std::auto_ptr<LumiSummary> pOut1;
126 std::auto_ptr<LumiDetails> pOut2;
137 unsigned int currentrun=iLBlock.
run();
156 unsigned int lstowriteout=0;
158 std::vector<unsigned int>
v;
159 for(std::map<unsigned int,ExpressLumiProducer::PerLSData >::iterator it=
m_lscache.begin();it!=
m_lscache.end();++it){
160 v.push_back(it->first);
162 lstowriteout=v.back();
164 lstowriteout=currentls;
181 coral::AttributeList bindVariables;
182 bindVariables.extend(
"runnumber",
typeid(
unsigned int));
183 bindVariables[
"runnumber"].data<
unsigned int>()=runnumber;
185 coral::AttributeList MyOutput;
186 MyOutput.extend(
"maxavailablels",
typeid(
unsigned int));
187 coral::IQuery*
myQuery=schema.newQuery();
188 myQuery->addToTableList(tablename);
189 myQuery->addToOutputList(
"max(LUMISECTION)",
"maxavailablels");
190 myQuery->setCondition(conditionStr,bindVariables);
191 myQuery->defineOutput(MyOutput);
192 coral::ICursor& mycursor=myQuery->execute();
193 while( mycursor.next() ){
194 const coral::AttributeList& row=mycursor.currentRow();
195 if(!row[
"maxavailablels"].isNull()){
196 result=row[
"maxavailablels"].data<
unsigned int>();
212 throw cms::Exception(
"Non existing service lumi::service::DBService");
215 coral::ITypeConverter& tconverter=session->typeConverter();
219 unsigned int lsmin=1;
220 unsigned int lsmax=currentlsnum;
222 session->transaction().start(
true);
223 coral::ISchema&
schema=session->nominalSchema();
225 if(maxavailableLS!=0 && maxavailableLS<currentlsnum){
226 lsmax=maxavailableLS;
227 }
else if(maxavailableLS==0){
229 session->transaction().commit();
236 for(
unsigned int n=lsmin;
n<=lsmax;++
n){
238 std::vector<float> mytmp(3564,0.0);
240 std::vector<float> myerrtmp(3564,0.0);
242 std::vector<short> myqtmp(3564,0);
247 coral::AttributeList lumisummaryBindVariables;
248 lumisummaryBindVariables.extend(
"lsmin",
typeid(
unsigned int));
249 lumisummaryBindVariables.extend(
"runnumber",
typeid(
unsigned int));
250 lumisummaryBindVariables[
"runnumber"].data<
unsigned int>()=
m_cachedrun;
251 lumisummaryBindVariables[
"lsmin"].data<
unsigned int>()=lsmin;
252 std::string conditionStr(
" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin ");
253 coral::AttributeList lumisummaryOutput;
254 lumisummaryOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
255 lumisummaryOutput.extend(
"INSTLUMI",
typeid(
float));
256 lumisummaryOutput.extend(
"DELIVLUMISECTION",
typeid(
float));
257 lumisummaryOutput.extend(
"LIVELUMISECTION",
typeid(
float));
258 lumisummaryOutput.extend(
"STARTORBIT",
typeid(
unsigned long long));
260 lumisummaryBindVariables.extend(
"lsmax",
typeid(
unsigned int));
261 conditionStr=conditionStr+
"AND LUMISECTION<=:lsmax";
262 lumisummaryBindVariables[
"lsmax"].data<
unsigned int>()=lsmax;
264 coral::IQuery* lumisummaryQuery=schema.newQuery();
265 lumisummaryQuery->addToTableList(
std::string(
"LUMI_SECTIONS"));
266 lumisummaryQuery->addToOutputList(
"LUMISECTION");
267 lumisummaryQuery->addToOutputList(
"INSTLUMI");
268 lumisummaryQuery->addToOutputList(
"DELIVLUMISECTION");
269 lumisummaryQuery->addToOutputList(
"LIVELUMISECTION");
270 lumisummaryQuery->addToOutputList(
"STARTORBIT");
271 lumisummaryQuery->setCondition(conditionStr,lumisummaryBindVariables);
272 lumisummaryQuery->defineOutput(lumisummaryOutput);
273 coral::ICursor& lumisummarycursor=lumisummaryQuery->execute();
274 unsigned int rowcounter=0;
275 while( lumisummarycursor.next() ){
276 const coral::AttributeList& row=lumisummarycursor.currentRow();
277 unsigned int lsnum=row[
"LUMISECTION"].data<
unsigned int>();
279 if(!row[
"INSTLUMI"].isNull()){
280 instlumi=row[
"INSTLUMI"].data<
float>();
283 float intgdellumi=0.0;
284 float intgreclumi=0.0;
285 unsigned long long startorbit=0;
286 if(!row[
"DELIVLUMISECTION"].isNull()){
287 intgdellumi=row[
"DELIVLUMISECTION"].data<
float>()*1000.0;
289 if(!row[
"LIVELUMISECTION"].isNull()){
290 intgreclumi=row[
"LIVELUMISECTION"].data<
float>()*1000.0;
293 deadfrac=1.0-intgreclumi/intgdellumi;
295 if(!row[
"STARTORBIT"].isNull()){
296 startorbit=row[
"STARTORBIT"].data<
unsigned long long>();
298 unsigned long long deadcount=deadfrac*10000.0;
299 unsigned long long bitzerocount=10000.0;
312 delete lumisummaryQuery;
319 coral::AttributeList lumidetailBindVariables;
320 lumidetailBindVariables.extend(
"lsmin",
typeid(
unsigned int));
321 lumidetailBindVariables.extend(
"runnumber",
typeid(
unsigned int));
322 lumidetailBindVariables[
"runnumber"].data<
unsigned int>()=
m_cachedrun;
323 lumidetailBindVariables[
"lsmin"].data<
unsigned int>()=lsmin;
324 std::string detailconditionStr(
" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND BUNCHLUMI>0 ");
325 coral::AttributeList lumidetailOutput;
326 lumidetailOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
327 lumidetailOutput.extend(
"BUNCH",
typeid(
unsigned int));
328 lumidetailOutput.extend(
"BUNCHLUMI",
typeid(
float));
330 lumidetailBindVariables.extend(
"lsmax",
typeid(
unsigned int));
331 detailconditionStr=detailconditionStr+
"AND LUMISECTION<=:lsmax";
332 lumidetailBindVariables[
"lsmax"].data<
unsigned int>()=lsmax;
334 coral::IQuery* lumidetailQuery=schema.newQuery();
335 lumidetailQuery->addToTableList(
std::string(
"BUNCH_LUMI_SECTIONS"));
336 lumidetailQuery->addToOutputList(
"LUMISECTION");
337 lumidetailQuery->addToOutputList(
"BUNCH");
338 lumidetailQuery->addToOutputList(
"BUNCHLUMI");
339 lumidetailQuery->setCondition(detailconditionStr,lumidetailBindVariables);
340 lumidetailQuery->defineOutput(lumidetailOutput);
341 coral::ICursor& lumidetailcursor=lumidetailQuery->execute();
342 while( lumidetailcursor.next() ){
343 const coral::AttributeList& row=lumidetailcursor.currentRow();
344 unsigned int lsnum=row[
"LUMISECTION"].data<
unsigned int>();
345 unsigned int bxidx=row[
"BUNCH"].data<
unsigned int>();
346 float bxlumi=row[
"BUNCHLUMI"].data<
float>();
347 m_lscache[lsnum].bunchlumivalue[bxidx]=bxlumi;
349 delete lumidetailQuery;
350 session->transaction().commit();
352 session->transaction().rollback();
361 std::auto_ptr<LumiSummary> pOut1;
362 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 &)
bool fillLumi(edm::LuminosityBlock &iLBlock)
void put(std::auto_ptr< PROD > product)
Put a new product.