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" 88 void fillLSCache(
unsigned int runnum,
unsigned int luminum);
92 std::
string m_connectStr;
93 unsigned int m_cachedrun;
95 unsigned int m_cachesize;
103 produces<LumiSummary, edm::Transition::BeginLuminosityBlock>();
104 produces<LumiDetails, edm::Transition::BeginLuminosityBlock>();
106 m_connectStr=iConfig.getParameter<
std::string>(
"connect");
107 m_cachesize=iConfig.getUntrackedParameter<
unsigned int>(
"ncacheEntries",5);
123 iLBlock.
put(std::make_unique<LumiSummary>());
124 iLBlock.
put(std::make_unique<LumiDetails>());
129 unsigned int currentrun=iLBlock.
run();
133 writeEmptyProductForEntry(iLBlock);
136 if(m_cachedrun!=currentrun){
137 fillLSCache(currentrun,currentls);
139 if(m_lscache.find(currentls)==m_lscache.end()){
141 fillLSCache(currentrun,currentls);
144 if( m_lscache.empty() ){
145 writeEmptyProductForEntry(iLBlock);
148 unsigned int lstowriteout=0;
149 if(m_lscache.find(currentls)==m_lscache.end()){
150 std::vector<unsigned int>
v;
151 for(std::map<unsigned int,ExpressLumiProducer::PerLSData >::iterator it=m_lscache.begin();it!=m_lscache.end();++it){
152 v.push_back(it->first);
154 lstowriteout=v.back();
156 lstowriteout=currentls;
161 writeEmptyProductForEntry(iLBlock);
163 writeProductsForEntry(iLBlock,lstowriteout);
173 coral::AttributeList bindVariables;
174 bindVariables.extend(
"runnumber",
typeid(
unsigned int));
175 bindVariables[
"runnumber"].data<
unsigned int>()=runnumber;
177 coral::AttributeList MyOutput;
178 MyOutput.extend(
"maxavailablels",
typeid(
unsigned int));
179 coral::IQuery* myQuery=schema.newQuery();
180 myQuery->addToTableList(tablename);
181 myQuery->addToOutputList(
"max(LUMISECTION)",
"maxavailablels");
182 myQuery->setCondition(conditionStr,bindVariables);
183 myQuery->defineOutput(MyOutput);
184 coral::ICursor& mycursor=myQuery->execute();
185 while( mycursor.next() ){
186 const coral::AttributeList& row=mycursor.currentRow();
187 if(!row[
"maxavailablels"].isNull()){
188 result=row[
"maxavailablels"].data<
unsigned int>();
204 throw cms::Exception(
"Non existing service lumi::service::DBService");
207 coral::ITypeConverter& tconverter=
session->typeConverter();
211 unsigned int lsmin=1;
212 unsigned int lsmax=currentlsnum;
214 session->transaction().start(
true);
216 unsigned int maxavailableLS=maxavailableLSforRun(schema,
std::string(
"LUMI_SECTIONS"),m_cachedrun);
217 if(maxavailableLS!=0 && maxavailableLS<currentlsnum){
218 lsmax=maxavailableLS;
219 }
else if(maxavailableLS==0){
221 session->transaction().commit();
225 lsmin=(lsmax-m_cachesize)>0 ? (lsmax-m_cachesize+1) : 1;
227 for(
unsigned int n=lsmin;
n<=lsmax;++
n){
229 std::vector<float> mytmp(3564,0.0);
231 std::vector<float> myerrtmp(3564,0.0);
233 std::vector<short> myqtmp(3564,0);
235 m_lscache.insert(std::make_pair(
n,l));
238 coral::AttributeList lumisummaryBindVariables;
239 lumisummaryBindVariables.extend(
"lsmin",
typeid(
unsigned int));
240 lumisummaryBindVariables.extend(
"runnumber",
typeid(
unsigned int));
241 lumisummaryBindVariables[
"runnumber"].data<
unsigned int>()=m_cachedrun;
242 lumisummaryBindVariables[
"lsmin"].data<
unsigned int>()=lsmin;
243 std::string conditionStr(
" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin ");
244 coral::AttributeList lumisummaryOutput;
245 lumisummaryOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
246 lumisummaryOutput.extend(
"INSTLUMI",
typeid(
float));
247 lumisummaryOutput.extend(
"DELIVLUMISECTION",
typeid(
float));
248 lumisummaryOutput.extend(
"LIVELUMISECTION",
typeid(
float));
249 lumisummaryOutput.extend(
"STARTORBIT",
typeid(
unsigned long long));
251 lumisummaryBindVariables.extend(
"lsmax",
typeid(
unsigned int));
252 conditionStr=conditionStr+
"AND LUMISECTION<=:lsmax";
253 lumisummaryBindVariables[
"lsmax"].data<
unsigned int>()=lsmax;
255 coral::IQuery* lumisummaryQuery=schema.newQuery();
256 lumisummaryQuery->addToTableList(
std::string(
"LUMI_SECTIONS"));
257 lumisummaryQuery->addToOutputList(
"LUMISECTION");
258 lumisummaryQuery->addToOutputList(
"INSTLUMI");
259 lumisummaryQuery->addToOutputList(
"DELIVLUMISECTION");
260 lumisummaryQuery->addToOutputList(
"LIVELUMISECTION");
261 lumisummaryQuery->addToOutputList(
"STARTORBIT");
262 lumisummaryQuery->setCondition(conditionStr,lumisummaryBindVariables);
263 lumisummaryQuery->defineOutput(lumisummaryOutput);
264 coral::ICursor& lumisummarycursor=lumisummaryQuery->execute();
265 unsigned int rowcounter=0;
266 while( lumisummarycursor.next() ){
267 const coral::AttributeList& row=lumisummarycursor.currentRow();
268 unsigned int lsnum=row[
"LUMISECTION"].data<
unsigned int>();
270 if(!row[
"INSTLUMI"].isNull()){
271 instlumi=row[
"INSTLUMI"].data<
float>();
274 float intgdellumi=0.0;
275 float intgreclumi=0.0;
276 unsigned long long startorbit=0;
277 if(!row[
"DELIVLUMISECTION"].isNull()){
278 intgdellumi=row[
"DELIVLUMISECTION"].data<
float>()*1000.0;
280 if(!row[
"LIVELUMISECTION"].isNull()){
281 intgreclumi=row[
"LIVELUMISECTION"].data<
float>()*1000.0;
284 deadfrac=1.0-intgreclumi/intgdellumi;
286 if(!row[
"STARTORBIT"].isNull()){
287 startorbit=row[
"STARTORBIT"].data<
unsigned long long>();
289 unsigned long long deadcount=deadfrac*10000.0;
290 unsigned long long bitzerocount=10000.0;
303 delete lumisummaryQuery;
304 if(m_isNullRun)
return;
310 coral::AttributeList lumidetailBindVariables;
311 lumidetailBindVariables.extend(
"lsmin",
typeid(
unsigned int));
312 lumidetailBindVariables.extend(
"runnumber",
typeid(
unsigned int));
313 lumidetailBindVariables[
"runnumber"].data<
unsigned int>()=m_cachedrun;
314 lumidetailBindVariables[
"lsmin"].data<
unsigned int>()=lsmin;
315 std::string detailconditionStr(
" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND BUNCHLUMI>0 ");
316 coral::AttributeList lumidetailOutput;
317 lumidetailOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
318 lumidetailOutput.extend(
"BUNCH",
typeid(
unsigned int));
319 lumidetailOutput.extend(
"BUNCHLUMI",
typeid(
float));
321 lumidetailBindVariables.extend(
"lsmax",
typeid(
unsigned int));
322 detailconditionStr=detailconditionStr+
"AND LUMISECTION<=:lsmax";
323 lumidetailBindVariables[
"lsmax"].data<
unsigned int>()=lsmax;
325 coral::IQuery* lumidetailQuery=schema.newQuery();
326 lumidetailQuery->addToTableList(
std::string(
"BUNCH_LUMI_SECTIONS"));
327 lumidetailQuery->addToOutputList(
"LUMISECTION");
328 lumidetailQuery->addToOutputList(
"BUNCH");
329 lumidetailQuery->addToOutputList(
"BUNCHLUMI");
330 lumidetailQuery->setCondition(detailconditionStr,lumidetailBindVariables);
331 lumidetailQuery->defineOutput(lumidetailOutput);
332 coral::ICursor& lumidetailcursor=lumidetailQuery->execute();
333 while( lumidetailcursor.next() ){
334 const coral::AttributeList& row=lumidetailcursor.currentRow();
335 unsigned int lsnum=row[
"LUMISECTION"].data<
unsigned int>();
336 unsigned int bxidx=row[
"BUNCH"].data<
unsigned int>();
337 float bxlumi=row[
"BUNCHLUMI"].data<
float>();
338 m_lscache[lsnum].bunchlumivalue[bxidx]=bxlumi;
340 delete lumidetailQuery;
341 session->transaction().commit();
343 session->transaction().rollback();
350 auto pIn1 = std::make_unique<LumiSummary>();
351 auto pIn2 = std::make_unique<LumiDetails>();
353 pIn1->setLumiVersion(
"DIP");
354 pIn2->setLumiVersion(
"DIP");
360 pIn1->setLumiVersion(
"DIP");
361 pIn1->setLumiData(lsdata.
lumivalue,0.0,0.0);
364 pIn1->setlsnumber(lsdata.
lsnum);
367 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