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" 89 void fillLSCache(
unsigned int runnum,
unsigned int luminum);
93 std::
string m_connectStr;
94 unsigned int m_cachedrun;
96 unsigned int m_cachesize;
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();
134 writeEmptyProductForEntry(iLBlock);
137 if(m_cachedrun!=currentrun){
138 fillLSCache(currentrun,currentls);
140 if(m_lscache.find(currentls)==m_lscache.end()){
142 fillLSCache(currentrun,currentls);
145 if( m_lscache.empty() ){
146 writeEmptyProductForEntry(iLBlock);
149 unsigned int lstowriteout=0;
150 if(m_lscache.find(currentls)==m_lscache.end()){
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;
162 writeEmptyProductForEntry(iLBlock);
164 writeProductsForEntry(iLBlock,lstowriteout);
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);
217 unsigned int maxavailableLS=maxavailableLSforRun(schema,
std::string(
"LUMI_SECTIONS"),m_cachedrun);
218 if(maxavailableLS!=0 && maxavailableLS<currentlsnum){
219 lsmax=maxavailableLS;
220 }
else if(maxavailableLS==0){
222 session->transaction().commit();
226 lsmin=(lsmax-m_cachesize)>0 ? (lsmax-m_cachesize+1) : 1;
228 for(
unsigned int n=lsmin;
n<=lsmax;++
n){
230 std::vector<float> mytmp(3564,0.0);
232 std::vector<float> myerrtmp(3564,0.0);
234 std::vector<short> myqtmp(3564,0);
236 m_lscache.insert(std::make_pair(
n,l));
239 coral::AttributeList lumisummaryBindVariables;
240 lumisummaryBindVariables.extend(
"lsmin",
typeid(
unsigned int));
241 lumisummaryBindVariables.extend(
"runnumber",
typeid(
unsigned int));
242 lumisummaryBindVariables[
"runnumber"].data<
unsigned int>()=m_cachedrun;
243 lumisummaryBindVariables[
"lsmin"].data<
unsigned int>()=lsmin;
244 std::string conditionStr(
" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin ");
245 coral::AttributeList lumisummaryOutput;
246 lumisummaryOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
247 lumisummaryOutput.extend(
"INSTLUMI",
typeid(
float));
248 lumisummaryOutput.extend(
"DELIVLUMISECTION",
typeid(
float));
249 lumisummaryOutput.extend(
"LIVELUMISECTION",
typeid(
float));
250 lumisummaryOutput.extend(
"STARTORBIT",
typeid(
unsigned long long));
252 lumisummaryBindVariables.extend(
"lsmax",
typeid(
unsigned int));
253 conditionStr=conditionStr+
"AND LUMISECTION<=:lsmax";
254 lumisummaryBindVariables[
"lsmax"].data<
unsigned int>()=lsmax;
256 coral::IQuery* lumisummaryQuery=schema.newQuery();
257 lumisummaryQuery->addToTableList(
std::string(
"LUMI_SECTIONS"));
258 lumisummaryQuery->addToOutputList(
"LUMISECTION");
259 lumisummaryQuery->addToOutputList(
"INSTLUMI");
260 lumisummaryQuery->addToOutputList(
"DELIVLUMISECTION");
261 lumisummaryQuery->addToOutputList(
"LIVELUMISECTION");
262 lumisummaryQuery->addToOutputList(
"STARTORBIT");
263 lumisummaryQuery->setCondition(conditionStr,lumisummaryBindVariables);
264 lumisummaryQuery->defineOutput(lumisummaryOutput);
265 coral::ICursor& lumisummarycursor=lumisummaryQuery->execute();
266 unsigned int rowcounter=0;
267 while( lumisummarycursor.next() ){
268 const coral::AttributeList& row=lumisummarycursor.currentRow();
269 unsigned int lsnum=row[
"LUMISECTION"].data<
unsigned int>();
271 if(!row[
"INSTLUMI"].isNull()){
272 instlumi=row[
"INSTLUMI"].data<
float>();
275 float intgdellumi=0.0;
276 float intgreclumi=0.0;
277 unsigned long long startorbit=0;
278 if(!row[
"DELIVLUMISECTION"].isNull()){
279 intgdellumi=row[
"DELIVLUMISECTION"].data<
float>()*1000.0;
281 if(!row[
"LIVELUMISECTION"].isNull()){
282 intgreclumi=row[
"LIVELUMISECTION"].data<
float>()*1000.0;
285 deadfrac=1.0-intgreclumi/intgdellumi;
287 if(!row[
"STARTORBIT"].isNull()){
288 startorbit=row[
"STARTORBIT"].data<
unsigned long long>();
290 unsigned long long deadcount=deadfrac*10000.0;
291 unsigned long long bitzerocount=10000.0;
304 delete lumisummaryQuery;
305 if(m_isNullRun)
return;
311 coral::AttributeList lumidetailBindVariables;
312 lumidetailBindVariables.extend(
"lsmin",
typeid(
unsigned int));
313 lumidetailBindVariables.extend(
"runnumber",
typeid(
unsigned int));
314 lumidetailBindVariables[
"runnumber"].data<
unsigned int>()=m_cachedrun;
315 lumidetailBindVariables[
"lsmin"].data<
unsigned int>()=lsmin;
316 std::string detailconditionStr(
" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND BUNCHLUMI>0 ");
317 coral::AttributeList lumidetailOutput;
318 lumidetailOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
319 lumidetailOutput.extend(
"BUNCH",
typeid(
unsigned int));
320 lumidetailOutput.extend(
"BUNCHLUMI",
typeid(
float));
322 lumidetailBindVariables.extend(
"lsmax",
typeid(
unsigned int));
323 detailconditionStr=detailconditionStr+
"AND LUMISECTION<=:lsmax";
324 lumidetailBindVariables[
"lsmax"].data<
unsigned int>()=lsmax;
326 coral::IQuery* lumidetailQuery=schema.newQuery();
327 lumidetailQuery->addToTableList(
std::string(
"BUNCH_LUMI_SECTIONS"));
328 lumidetailQuery->addToOutputList(
"LUMISECTION");
329 lumidetailQuery->addToOutputList(
"BUNCH");
330 lumidetailQuery->addToOutputList(
"BUNCHLUMI");
331 lumidetailQuery->setCondition(detailconditionStr,lumidetailBindVariables);
332 lumidetailQuery->defineOutput(lumidetailOutput);
333 coral::ICursor& lumidetailcursor=lumidetailQuery->execute();
334 while( lumidetailcursor.next() ){
335 const coral::AttributeList& row=lumidetailcursor.currentRow();
336 unsigned int lsnum=row[
"LUMISECTION"].data<
unsigned int>();
337 unsigned int bxidx=row[
"BUNCH"].data<
unsigned int>();
338 float bxlumi=row[
"BUNCHLUMI"].data<
float>();
339 m_lscache[lsnum].bunchlumivalue[bxidx]=bxlumi;
341 delete lumidetailQuery;
342 session->transaction().commit();
344 session->transaction().rollback();
351 auto pIn1 = std::make_unique<LumiSummary>();
352 auto pIn2 = std::make_unique<LumiDetails>();
354 pIn1->setLumiVersion(
"DIP");
355 pIn2->setLumiVersion(
"DIP");
361 pIn1->setLumiVersion(
"DIP");
362 pIn1->setLumiData(lsdata.
lumivalue,0.0,0.0);
365 pIn1->setlsnumber(lsdata.
lsnum);
368 pIn2->setLumiVersion(
"DIP");
virtual void beginLuminosityBlockProduce(edm::LuminosityBlock &iLBlock, edm::EventSetup const &iSetup) override final
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 writeProductsForEntry(edm::LuminosityBlock &iLBlock, unsigned int luminum)
virtual void produce(edm::Event &, const edm::EventSetup &) override final
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