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 "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" 53 #include <boost/tokenizer.hpp> 54 #include <xercesc/dom/DOM.hpp> 55 #include <xercesc/parsers/XercesDOMParser.hpp> 57 #include <xercesc/util/XMLString.hpp> 60 : m_connectStr(
""), m_summarycachedrun(0), m_detailcachedrun(0), m_cachesize(0) {
63 findingRecord<DIPLuminosityRcd>();
71 if (currentls == 0 || currentls == 4294967295) {
72 return std::make_shared<const DIPLumiSummary>();
82 return std::make_shared<const DIPLumiSummary>();
85 std::vector<unsigned int>
v;
89 v.push_back(it->first);
96 return std::make_shared<const DIPLumiSummary>();
103 if (currentls == 0 || currentls == 4294967295) {
104 return std::make_shared<const DIPLumiDetail>();
114 return std::make_shared<const DIPLumiDetail>();
117 std::vector<unsigned int>
v;
118 for (
std::map<
unsigned int, std::shared_ptr<const DIPLumiDetail> >::iterator it =
m_detailcache.begin();
121 v.push_back(it->first);
128 return std::make_shared<const DIPLumiDetail>();
155 throw cms::Exception(
"Non existing service lumi::service::DBService");
158 coral::ITypeConverter& tconverter = session->typeConverter();
162 unsigned int lsmin = 1;
163 unsigned int lsmax = currentlsnum;
165 session->transaction().start(
true);
166 coral::ISchema& schema = session->nominalSchema();
168 if (maxavailableLS != 0 && maxavailableLS < currentlsnum) {
169 lsmax = maxavailableLS;
170 }
else if (maxavailableLS == 0) {
172 session->transaction().commit();
179 coral::AttributeList lumisummaryBindVariables;
180 lumisummaryBindVariables.extend(
"lsmin",
typeid(
unsigned int));
181 lumisummaryBindVariables.extend(
"lsmax",
typeid(
unsigned int));
182 lumisummaryBindVariables.extend(
"runnumber",
typeid(
unsigned int));
184 lumisummaryBindVariables[
"lsmin"].data<
unsigned int>() =
lsmin;
185 lumisummaryBindVariables[
"lsmax"].data<
unsigned int>() =
lsmax;
186 std::string conditionStr(
"RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND LUMISECTION<=:lsmax");
187 coral::AttributeList lumisummaryOutput;
188 lumisummaryOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
189 lumisummaryOutput.extend(
"INSTLUMI",
typeid(
float));
190 lumisummaryOutput.extend(
"DELIVLUMISECTION",
typeid(
float));
191 lumisummaryOutput.extend(
"LIVELUMISECTION",
typeid(
float));
192 lumisummaryOutput.extend(
"CMS_ACTIVE",
typeid(
unsigned short));
193 coral::IQuery* lumisummaryQuery = schema.newQuery();
194 lumisummaryQuery->addToTableList(
std::string(
"LUMI_SECTIONS"));
195 lumisummaryQuery->addToOutputList(
"LUMISECTION");
196 lumisummaryQuery->addToOutputList(
"INSTLUMI");
197 lumisummaryQuery->addToOutputList(
"DELIVLUMISECTION");
198 lumisummaryQuery->addToOutputList(
"LIVELUMISECTION");
199 lumisummaryQuery->addToOutputList(
"CMS_ACTIVE");
200 lumisummaryQuery->setCondition(conditionStr, lumisummaryBindVariables);
201 lumisummaryQuery->defineOutput(lumisummaryOutput);
202 coral::ICursor& lumisummarycursor = lumisummaryQuery->execute();
203 while (lumisummarycursor.next()) {
204 const coral::AttributeList& row = lumisummarycursor.currentRow();
205 unsigned int lsnum = row[
"LUMISECTION"].data<
unsigned int>();
206 float instlumi = 0.0;
207 if (!row[
"INSTLUMI"].isNull()) {
208 instlumi = row[
"INSTLUMI"].data<
float>();
210 float intgdellumi = 0.0;
211 if (!row[
"DELIVLUMISECTION"].isNull()) {
212 intgdellumi = row[
"DELIVLUMISECTION"].data<
float>() * 1000.0;
214 float intgreclumi = 0.0;
215 if (!row[
"LIVELUMISECTION"].isNull()) {
216 intgreclumi = row[
"LIVELUMISECTION"].data<
float>() * 1000.0;
218 unsigned short cmsalive = 0;
219 if (!row[
"CMS_ACTIVE"].isNull()) {
220 cmsalive = row[
"CMS_ACTIVE"].data<
unsigned short>();
222 auto tmpls = std::make_unique<DIPLumiSummary>(instlumi, intgdellumi, intgreclumi, cmsalive);
225 std::shared_ptr<const DIPLumiSummary> const_tmpls =
std::move(tmpls);
228 delete lumisummaryQuery;
229 session->transaction().commit();
231 session->transaction().rollback();
242 coral::AttributeList bindVariables;
243 bindVariables.extend(
"runnumber",
typeid(
unsigned int));
244 bindVariables[
"runnumber"].data<
unsigned int>() =
runnumber;
246 coral::AttributeList MyOutput;
247 MyOutput.extend(
"maxavailablels",
typeid(
unsigned int));
248 coral::IQuery*
myQuery = schema.newQuery();
249 myQuery->addToTableList(tablename);
250 myQuery->addToOutputList(
"max(LUMISECTION)",
"maxavailablels");
251 myQuery->setCondition(conditionStr, bindVariables);
252 myQuery->defineOutput(MyOutput);
253 coral::ICursor& mycursor =
myQuery->execute();
254 while (mycursor.next()) {
255 const coral::AttributeList& row = mycursor.currentRow();
256 if (!row[
"maxavailablels"].isNull()) {
257 result = row[
"maxavailablels"].data<
unsigned int>();
266 std::map<unsigned int, std::unique_ptr<DIPLumiDetail> > detailcache;
274 throw cms::Exception(
"Non existing service lumi::service::DBService");
277 coral::ITypeConverter& tconverter = session->typeConverter();
280 unsigned int lsmin = 1;
281 unsigned int lsmax = currentlsnum;
283 session->transaction().start(
true);
284 coral::ISchema& schema = session->nominalSchema();
286 if (maxavailableLS != 0 && maxavailableLS < currentlsnum) {
287 lsmax = maxavailableLS;
288 }
else if (maxavailableLS == 0) {
290 session->transaction().commit();
296 coral::AttributeList lumidetailBindVariables;
297 lumidetailBindVariables.extend(
"lsmin",
typeid(
unsigned int));
298 lumidetailBindVariables.extend(
"lsmax",
typeid(
unsigned int));
299 lumidetailBindVariables.extend(
"runnumber",
typeid(
unsigned int));
301 lumidetailBindVariables[
"lsmin"].data<
unsigned int>() =
lsmin;
302 lumidetailBindVariables[
"lsmax"].data<
unsigned int>() =
lsmax;
303 std::string conditionStr(
"RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND LUMISECTION<=:lsmax AND BUNCHLUMI>0 ");
304 coral::AttributeList lumidetailOutput;
305 lumidetailOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
306 lumidetailOutput.extend(
"BUNCH",
typeid(
unsigned int));
307 lumidetailOutput.extend(
"BUNCHLUMI",
typeid(
float));
308 coral::IQuery* lumidetailQuery = schema.newQuery();
309 lumidetailQuery->addToTableList(
std::string(
"BUNCH_LUMI_SECTIONS"));
310 lumidetailQuery->addToOutputList(
"LUMISECTION");
311 lumidetailQuery->addToOutputList(
"BUNCH");
312 lumidetailQuery->addToOutputList(
"BUNCHLUMI");
313 lumidetailQuery->setCondition(conditionStr, lumidetailBindVariables);
314 lumidetailQuery->defineOutput(lumidetailOutput);
315 coral::ICursor& lumidetailcursor = lumidetailQuery->execute();
316 while (lumidetailcursor.next()) {
317 const coral::AttributeList& row = lumidetailcursor.currentRow();
318 unsigned int lsnum = row[
"LUMISECTION"].data<
unsigned int>();
319 if (detailcache.find(lsnum) == detailcache.end()) {
320 detailcache.insert(std::make_pair(lsnum, std::make_unique<DIPLumiDetail>()));
323 if (!row[
"BUNCH"].isNull()) {
324 unsigned int bxidx = row[
"BUNCH"].data<
unsigned int>();
326 if (!row[
"BUNCHLUMI"].isNull()) {
327 bxlumi = row[
"BUNCHLUMI"].data<
float>();
329 detailcache[lsnum]->fillbxdata(bxidx, bxlumi);
332 for (
auto&
item : detailcache) {
335 delete lumidetailQuery;
336 session->transaction().commit();
338 session->transaction().rollback();
void setFirst(const IOVSyncValue &iTime)
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
LuminosityBlockNumber_t luminosityBlockNumber() const
T getParameter(std::string const &) const
unsigned int m_detailcachedrun
std::shared_ptr< const DIPLumiSummary > m_summaryresult
DIPLumiProducer(const edm::ParameterSet &)
ISessionProxyPtr connectReadOnly(const std::string &connectstring)
~DIPLumiProducer() override
ReturnDetailType produceDetail(const DIPLuminosityRcd &)
std::shared_ptr< const DIPLumiDetail > ReturnDetailType
T getUntrackedParameter(std::string const &, T const &) const
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
void setLast(const IOVSyncValue &iTime)
unsigned int m_summarycachedrun
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
std::map< unsigned int, std::shared_ptr< const DIPLumiSummary > > m_summarycache
std::map< unsigned int, std::shared_ptr< const DIPLumiDetail > > m_detailcache
unsigned int maxavailableLSforRun(coral::ISchema &schema, const std::string &tablename, unsigned int runnumber)
const EventID & eventID() const
void filldetailcache(unsigned int runnumber, unsigned int startlsnum)
const edm::IOVSyncValue * m_pcurrentTime
std::shared_ptr< const DIPLumiDetail > m_detailresult
std::shared_ptr< const DIPLumiSummary > ReturnSummaryType
void fillsummarycache(unsigned int runnumber, unsigned int startlsnum)
ReturnSummaryType produceSummary(const DIPLuminosityRcd &)