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>
59 #include "boost/filesystem/path.hpp"
60 #include "boost/filesystem/operations.hpp"
63 : m_connectStr(
""), m_summarycachedrun(0), m_detailcachedrun(0), m_cachesize(0) {
66 findingRecord<DIPLuminosityRcd>();
74 if (currentls == 0 || currentls == 4294967295) {
75 return std::make_shared<const DIPLumiSummary>();
85 return std::make_shared<const DIPLumiSummary>();
88 std::vector<unsigned int>
v;
92 v.push_back(it->first);
99 return std::make_shared<const DIPLumiSummary>();
106 if (currentls == 0 || currentls == 4294967295) {
107 return std::make_shared<const DIPLumiDetail>();
117 return std::make_shared<const DIPLumiDetail>();
120 std::vector<unsigned int>
v;
121 for (
std::map<
unsigned int, std::shared_ptr<const DIPLumiDetail> >::iterator it =
m_detailcache.begin();
124 v.push_back(it->first);
131 return std::make_shared<const DIPLumiDetail>();
158 throw cms::Exception(
"Non existing service lumi::service::DBService");
161 coral::ITypeConverter& tconverter = session->typeConverter();
165 unsigned int lsmin = 1;
166 unsigned int lsmax = currentlsnum;
168 session->transaction().start(
true);
169 coral::ISchema& schema = session->nominalSchema();
171 if (maxavailableLS != 0 && maxavailableLS < currentlsnum) {
172 lsmax = maxavailableLS;
173 }
else if (maxavailableLS == 0) {
175 session->transaction().commit();
182 coral::AttributeList lumisummaryBindVariables;
183 lumisummaryBindVariables.extend(
"lsmin",
typeid(
unsigned int));
184 lumisummaryBindVariables.extend(
"lsmax",
typeid(
unsigned int));
185 lumisummaryBindVariables.extend(
"runnumber",
typeid(
unsigned int));
187 lumisummaryBindVariables[
"lsmin"].data<
unsigned int>() =
lsmin;
188 lumisummaryBindVariables[
"lsmax"].data<
unsigned int>() =
lsmax;
189 std::string conditionStr(
"RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND LUMISECTION<=:lsmax");
190 coral::AttributeList lumisummaryOutput;
191 lumisummaryOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
192 lumisummaryOutput.extend(
"INSTLUMI",
typeid(
float));
193 lumisummaryOutput.extend(
"DELIVLUMISECTION",
typeid(
float));
194 lumisummaryOutput.extend(
"LIVELUMISECTION",
typeid(
float));
195 lumisummaryOutput.extend(
"CMS_ACTIVE",
typeid(
unsigned short));
196 coral::IQuery* lumisummaryQuery = schema.newQuery();
197 lumisummaryQuery->addToTableList(
std::string(
"LUMI_SECTIONS"));
198 lumisummaryQuery->addToOutputList(
"LUMISECTION");
199 lumisummaryQuery->addToOutputList(
"INSTLUMI");
200 lumisummaryQuery->addToOutputList(
"DELIVLUMISECTION");
201 lumisummaryQuery->addToOutputList(
"LIVELUMISECTION");
202 lumisummaryQuery->addToOutputList(
"CMS_ACTIVE");
203 lumisummaryQuery->setCondition(conditionStr, lumisummaryBindVariables);
204 lumisummaryQuery->defineOutput(lumisummaryOutput);
205 coral::ICursor& lumisummarycursor = lumisummaryQuery->execute();
206 while (lumisummarycursor.next()) {
207 const coral::AttributeList& row = lumisummarycursor.currentRow();
208 unsigned int lsnum = row[
"LUMISECTION"].data<
unsigned int>();
209 float instlumi = 0.0;
210 if (!row[
"INSTLUMI"].isNull()) {
211 instlumi = row[
"INSTLUMI"].data<
float>();
213 float intgdellumi = 0.0;
214 if (!row[
"DELIVLUMISECTION"].isNull()) {
215 intgdellumi = row[
"DELIVLUMISECTION"].data<
float>() * 1000.0;
217 float intgreclumi = 0.0;
218 if (!row[
"LIVELUMISECTION"].isNull()) {
219 intgreclumi = row[
"LIVELUMISECTION"].data<
float>() * 1000.0;
221 unsigned short cmsalive = 0;
222 if (!row[
"CMS_ACTIVE"].isNull()) {
223 cmsalive = row[
"CMS_ACTIVE"].data<
unsigned short>();
225 auto tmpls = std::make_unique<DIPLumiSummary>(instlumi, intgdellumi, intgreclumi, cmsalive);
228 std::shared_ptr<const DIPLumiSummary> const_tmpls =
std::move(tmpls);
231 delete lumisummaryQuery;
232 session->transaction().commit();
234 session->transaction().rollback();
245 coral::AttributeList bindVariables;
246 bindVariables.extend(
"runnumber",
typeid(
unsigned int));
247 bindVariables[
"runnumber"].data<
unsigned int>() =
runnumber;
249 coral::AttributeList MyOutput;
250 MyOutput.extend(
"maxavailablels",
typeid(
unsigned int));
251 coral::IQuery*
myQuery = schema.newQuery();
252 myQuery->addToTableList(tablename);
253 myQuery->addToOutputList(
"max(LUMISECTION)",
"maxavailablels");
254 myQuery->setCondition(conditionStr, bindVariables);
255 myQuery->defineOutput(MyOutput);
256 coral::ICursor& mycursor =
myQuery->execute();
257 while (mycursor.next()) {
258 const coral::AttributeList& row = mycursor.currentRow();
259 if (!row[
"maxavailablels"].isNull()) {
260 result = row[
"maxavailablels"].data<
unsigned int>();
269 std::map<unsigned int, std::unique_ptr<DIPLumiDetail> > detailcache;
277 throw cms::Exception(
"Non existing service lumi::service::DBService");
280 coral::ITypeConverter& tconverter = session->typeConverter();
283 unsigned int lsmin = 1;
284 unsigned int lsmax = currentlsnum;
286 session->transaction().start(
true);
287 coral::ISchema& schema = session->nominalSchema();
289 if (maxavailableLS != 0 && maxavailableLS < currentlsnum) {
290 lsmax = maxavailableLS;
291 }
else if (maxavailableLS == 0) {
293 session->transaction().commit();
299 coral::AttributeList lumidetailBindVariables;
300 lumidetailBindVariables.extend(
"lsmin",
typeid(
unsigned int));
301 lumidetailBindVariables.extend(
"lsmax",
typeid(
unsigned int));
302 lumidetailBindVariables.extend(
"runnumber",
typeid(
unsigned int));
304 lumidetailBindVariables[
"lsmin"].data<
unsigned int>() =
lsmin;
305 lumidetailBindVariables[
"lsmax"].data<
unsigned int>() =
lsmax;
306 std::string conditionStr(
"RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND LUMISECTION<=:lsmax AND BUNCHLUMI>0 ");
307 coral::AttributeList lumidetailOutput;
308 lumidetailOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
309 lumidetailOutput.extend(
"BUNCH",
typeid(
unsigned int));
310 lumidetailOutput.extend(
"BUNCHLUMI",
typeid(
float));
311 coral::IQuery* lumidetailQuery = schema.newQuery();
312 lumidetailQuery->addToTableList(
std::string(
"BUNCH_LUMI_SECTIONS"));
313 lumidetailQuery->addToOutputList(
"LUMISECTION");
314 lumidetailQuery->addToOutputList(
"BUNCH");
315 lumidetailQuery->addToOutputList(
"BUNCHLUMI");
316 lumidetailQuery->setCondition(conditionStr, lumidetailBindVariables);
317 lumidetailQuery->defineOutput(lumidetailOutput);
318 coral::ICursor& lumidetailcursor = lumidetailQuery->execute();
319 while (lumidetailcursor.next()) {
320 const coral::AttributeList& row = lumidetailcursor.currentRow();
321 unsigned int lsnum = row[
"LUMISECTION"].data<
unsigned int>();
322 if (detailcache.find(lsnum) == detailcache.end()) {
323 detailcache.insert(std::make_pair(lsnum, std::make_unique<DIPLumiDetail>()));
326 if (!row[
"BUNCH"].isNull()) {
327 unsigned int bxidx = row[
"BUNCH"].data<
unsigned int>();
329 if (!row[
"BUNCHLUMI"].isNull()) {
330 bxlumi = row[
"BUNCHLUMI"].data<
float>();
332 detailcache[lsnum]->fillbxdata(bxidx, bxlumi);
335 for (
auto&
item : detailcache) {
338 delete lumidetailQuery;
339 session->transaction().commit();
341 session->transaction().rollback();