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" 65 findingRecord<DIPLuminosityRcd>();
75 if(currentls==0||currentls==4294967295){
76 return std::make_shared<const DIPLumiSummary>();
86 return std::make_shared<const DIPLumiSummary>();
89 std::vector<unsigned int>
v;
91 v.push_back(it->first);
98 return std::make_shared<const DIPLumiSummary>();
107 if(currentls==0||currentls==4294967295){
108 return std::make_shared<const DIPLumiDetail>();
118 return std::make_shared<const DIPLumiDetail>();
121 std::vector<unsigned int>
v;
123 v.push_back(it->first);
130 return std::make_shared<const DIPLumiDetail>();
159 throw cms::Exception(
"Non existing service lumi::service::DBService");
162 coral::ITypeConverter& tconverter=
session->typeConverter();
166 unsigned int lsmin=1;
167 unsigned int lsmax=currentlsnum;
169 session->transaction().start(
true);
172 if(maxavailableLS!=0 && maxavailableLS<currentlsnum){
173 lsmax=maxavailableLS;
174 }
else if(maxavailableLS==0){
176 session->transaction().commit();
183 coral::AttributeList lumisummaryBindVariables;
184 lumisummaryBindVariables.extend(
"lsmin",
typeid(
unsigned int));
185 lumisummaryBindVariables.extend(
"lsmax",
typeid(
unsigned int));
186 lumisummaryBindVariables.extend(
"runnumber",
typeid(
unsigned int));
188 lumisummaryBindVariables[
"lsmin"].data<
unsigned int>()=lsmin;
189 lumisummaryBindVariables[
"lsmax"].data<
unsigned int>()=lsmax;
190 std::string conditionStr(
"RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND LUMISECTION<=:lsmax");
191 coral::AttributeList lumisummaryOutput;
192 lumisummaryOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
193 lumisummaryOutput.extend(
"INSTLUMI",
typeid(
float));
194 lumisummaryOutput.extend(
"DELIVLUMISECTION",
typeid(
float));
195 lumisummaryOutput.extend(
"LIVELUMISECTION",
typeid(
float));
196 lumisummaryOutput.extend(
"CMS_ACTIVE",
typeid(
unsigned short));
197 coral::IQuery* lumisummaryQuery=schema.newQuery();
198 lumisummaryQuery->addToTableList(
std::string(
"LUMI_SECTIONS"));
199 lumisummaryQuery->addToOutputList(
"LUMISECTION");
200 lumisummaryQuery->addToOutputList(
"INSTLUMI");
201 lumisummaryQuery->addToOutputList(
"DELIVLUMISECTION");
202 lumisummaryQuery->addToOutputList(
"LIVELUMISECTION");
203 lumisummaryQuery->addToOutputList(
"CMS_ACTIVE");
204 lumisummaryQuery->setCondition(conditionStr,lumisummaryBindVariables);
205 lumisummaryQuery->defineOutput(lumisummaryOutput);
206 coral::ICursor& lumisummarycursor=lumisummaryQuery->execute();
207 while( lumisummarycursor.next() ){
208 const coral::AttributeList& row=lumisummarycursor.currentRow();
209 unsigned int lsnum=row[
"LUMISECTION"].data<
unsigned int>();
211 if(!row[
"INSTLUMI"].isNull()){
212 instlumi=row[
"INSTLUMI"].data<
float>();
214 float intgdellumi=0.0;
215 if(!row[
"DELIVLUMISECTION"].isNull()){
216 intgdellumi=row[
"DELIVLUMISECTION"].data<
float>()*1000.0;
218 float intgreclumi=0.0;
219 if(!row[
"LIVELUMISECTION"].isNull()){
220 intgreclumi=row[
"LIVELUMISECTION"].data<
float>()*1000.0;
222 unsigned short cmsalive=0;
223 if(!row[
"CMS_ACTIVE"].isNull()){
224 cmsalive=row[
"CMS_ACTIVE"].data<
unsigned short>();
226 auto tmpls = std::make_unique<DIPLumiSummary>(instlumi,intgdellumi,intgreclumi,cmsalive);
229 std::shared_ptr<const DIPLumiSummary> const_tmpls =
std::move(tmpls);
232 delete lumisummaryQuery;
233 session->transaction().commit();
235 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>();
270 std::map< unsigned int,std::unique_ptr<DIPLumiDetail> > detailcache;
278 throw cms::Exception(
"Non existing service lumi::service::DBService");
281 coral::ITypeConverter& tconverter=
session->typeConverter();
284 unsigned int lsmin=1;
285 unsigned int lsmax=currentlsnum;
287 session->transaction().start(
true);
290 if(maxavailableLS!=0 &&maxavailableLS<currentlsnum ){
291 lsmax=maxavailableLS;
292 }
else if(maxavailableLS==0){
294 session->transaction().commit();
300 coral::AttributeList lumidetailBindVariables;
301 lumidetailBindVariables.extend(
"lsmin",
typeid(
unsigned int));
302 lumidetailBindVariables.extend(
"lsmax",
typeid(
unsigned int));
303 lumidetailBindVariables.extend(
"runnumber",
typeid(
unsigned int));
305 lumidetailBindVariables[
"lsmin"].data<
unsigned int>()=lsmin;
306 lumidetailBindVariables[
"lsmax"].data<
unsigned int>()=lsmax;
307 std::string conditionStr(
"RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND LUMISECTION<=:lsmax AND BUNCHLUMI>0 ");
308 coral::AttributeList lumidetailOutput;
309 lumidetailOutput.extend(
"LUMISECTION",
typeid(
unsigned int));
310 lumidetailOutput.extend(
"BUNCH",
typeid(
unsigned int));
311 lumidetailOutput.extend(
"BUNCHLUMI",
typeid(
float));
312 coral::IQuery* lumidetailQuery=schema.newQuery();
313 lumidetailQuery->addToTableList(
std::string(
"BUNCH_LUMI_SECTIONS"));
314 lumidetailQuery->addToOutputList(
"LUMISECTION");
315 lumidetailQuery->addToOutputList(
"BUNCH");
316 lumidetailQuery->addToOutputList(
"BUNCHLUMI");
317 lumidetailQuery->setCondition(conditionStr,lumidetailBindVariables);
318 lumidetailQuery->defineOutput(lumidetailOutput);
319 coral::ICursor& lumidetailcursor=lumidetailQuery->execute();
320 while( lumidetailcursor.next() ){
321 const coral::AttributeList& row=lumidetailcursor.currentRow();
322 unsigned int lsnum=row[
"LUMISECTION"].data<
unsigned int>();
323 if(detailcache.find(lsnum)==detailcache.end()){
324 detailcache.insert(std::make_pair(lsnum,std::make_unique<DIPLumiDetail>()));
327 if(!row[
"BUNCH"].isNull()){
328 unsigned int bxidx=row[
"BUNCH"].data<
unsigned int>();
330 if(!row[
"BUNCHLUMI"].isNull()){
331 bxlumi=row[
"BUNCHLUMI"].data<
float>();
333 detailcache[lsnum]->fillbxdata(bxidx,bxlumi);
336 for(
auto & item : detailcache) {
339 delete lumidetailQuery;
340 session->transaction().commit();
342 session->transaction().rollback();
void setFirst(const IOVSyncValue &iTime)
T getParameter(std::string const &) const
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
T getUntrackedParameter(std::string const &, T const &) const
unsigned int m_detailcachedrun
const EventID & eventID() const
std::shared_ptr< const DIPLumiSummary > m_summaryresult
DIPLumiProducer(const edm::ParameterSet &)
ISessionProxyPtr connectReadOnly(const std::string &connectstring)
std::map< unsigned int, std::shared_ptr< const DIPLumiSummary > > m_summarycache
~DIPLumiProducer() override
ReturnDetailType produceDetail(const DIPLuminosityRcd &)
std::shared_ptr< const DIPLumiDetail > ReturnDetailType
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
LuminosityBlockNumber_t luminosityBlockNumber() const
void setLast(const IOVSyncValue &iTime)
unsigned int m_summarycachedrun
std::map< unsigned int, std::shared_ptr< const DIPLumiDetail > > m_detailcache
unsigned int maxavailableLSforRun(coral::ISchema &schema, const std::string &tablename, unsigned int runnumber)
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
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
void fillsummarycache(unsigned int runnumber, unsigned int startlsnum)
ReturnSummaryType produceSummary(const DIPLuminosityRcd &)