CMS 3D CMS Logo

RPCDCCLinkMapHandler.cc
Go to the documentation of this file.
2 
3 #include <fstream>
4 #include <memory>
5 #include <sstream>
6 
10 
12 
13 #include "RelationalAccess/ICursor.h"
14 #include "RelationalAccess/IQuery.h"
15 #include "RelationalAccess/IQueryDefinition.h"
16 #include "RelationalAccess/ISchema.h"
17 #include "RelationalAccess/ISessionProxy.h"
18 #include "RelationalAccess/ITransaction.h"
19 
20 #include "CoralBase/Attribute.h"
21 #include "CoralBase/AttributeList.h"
22 
24 
26  : id_(config.getParameter<std::string>("identifier")),
27  data_tag_(config.getParameter<std::string>("dataTag")),
28  since_run_(config.getParameter<unsigned long long>("sinceRun")),
29  txt_file_(config.getUntrackedParameter<std::string>("txtFile", "")),
30  connect_(config.getParameter<std::string>("connect")) {
31  edm::LogInfo("RPCDCCLinkMapHandler") << "Configuring Input Connection";
32  connection_.setParameters(config.getParameter<edm::ParameterSet>("DBParameters"));
34 }
35 
37 
39  edm::LogInfo("RPCDCCLinkMapHandler") << "getNewObjects";
40  cond::TagInfo_t const& tag_info = tagInfo();
41  if (since_run_ < tag_info.lastInterval.since)
42  throw cms::Exception("RPCDCCLinkMapHandler") << "Refuse to create RPCDCCLinkMap for run " << since_run_
43  << ", older than most recent tag" << tag_info.lastInterval.since;
44 
45  edm::LogInfo("RPCDCCLinkMapHandler") << "Opening read-only Input Session";
46  auto input_session = connection_.createCoralSession(connect_, false); // writeCapable
47  edm::LogInfo("RPCDCCLinkMapHandler") << "Started Input Transaction";
48  input_session->transaction().start(true); // readOnly
49 
50  std::unique_ptr<coral::IQuery> query(input_session->schema("CMS_RPC_CONF").newQuery());
51  query->addToTableList("DCCBOARD");
52  query->addToTableList("TRIGGERBOARD");
53  query->addToTableList("BOARDBOARDCONN");
54  query->addToTableList("BOARD");
55 
56  query->addToOutputList("DCCBOARD.FEDNUMBER", "DCC");
57  query->addToOutputList("TRIGGERBOARD.DCCINPUTCHANNELNUM", "DCC_INPUT");
58  query->addToOutputList("BOARDBOARDCONN.COLLECTORBOARDINPUTNUM", "TB_INPUT");
59  query->addToOutputList("BOARD.NAME", "LB_NAME");
60 
61  coral::AttributeList query_condition_data;
62  query->setCondition(
63  "TRIGGERBOARD.DCCBOARD_DCCBOARDID=DCCBOARD.DCCBOARDID"
64  " AND BOARDBOARDCONN.BOARD_COLLECTORBOARDID=TRIGGERBOARD.TRIGGERBOARDID"
65  " AND BOARD.BOARDID=BOARDBOARDCONN.BOARD_BOARDID",
66  query_condition_data);
67 
68  int dcc(0), dcc_input(0), tb_input(0);
69  std::string lb_name("");
70 
71  std::unique_ptr<RPCDCCLinkMap> dcc_link_map_object(new RPCDCCLinkMap());
72  RPCDCCLinkMap::map_type& dcc_link_map = dcc_link_map_object->getMap();
73  RPCLBLink lb_link;
74 
75  edm::LogInfo("RPCDCCLinkMapHandler") << "Execute query";
76  coral::ICursor& cursor(query->execute());
77  while (cursor.next()) {
78  coral::AttributeList const& row(cursor.currentRow());
79 
80  // RPCLBLink
81  lb_name = row["LB_NAME"].data<std::string>();
82  RPCLBLinkNameParser::parse(lb_name, lb_link);
83  if (lb_name != lb_link.getName())
84  edm::LogWarning("RPCDCCLinkMapHandler") << "Mismatch LinkBoard Name: " << lb_name << " vs " << lb_link;
85  lb_link.setLinkBoard().setConnector(); // MLB to link
86 
87  dcc = row["DCC"].data<long long>();
88  dcc_input = row["DCC_INPUT"].data<long long>();
89  tb_input = row["TB_INPUT"].data<long long>();
90 
91  dcc_link_map.insert(std::pair<RPCDCCLink, RPCLBLink>(RPCDCCLink(dcc, dcc_input, tb_input), lb_link));
92  }
93  cursor.close();
94 
95  input_session->transaction().commit();
96 
97  if (!txt_file_.empty()) {
98  edm::LogInfo("RPCDCCLinkMapHandler") << "Fill txtFile";
99  std::ofstream ofstream(txt_file_);
100  for (auto const& link : dcc_link_map) {
101  ofstream << link.first << ": " << link.second << std::endl;
102  }
103  }
104 
105  edm::LogInfo("RPCDCCLinkMapHandler") << "Add to transfer list";
106  m_to_transfer.push_back(std::make_pair(dcc_link_map_object.release(), since_run_));
107 }
108 
RPCLBLinkNameParser::parse
static void parse(std::string const &name, RPCLBLink &lb_link)
Definition: RPCLBLinkNameParser.cc:7
popcon::PopConSourceHandler< RPCDCCLinkMap >::m_to_transfer
OldContainer m_to_transfer
Definition: PopConSourceHandler.h:162
MessageLogger.h
MainPageGenerator.link
link
Definition: MainPageGenerator.py:271
RPCDCCLinkMapHandler::RPCDCCLinkMapHandler
RPCDCCLinkMapHandler(edm::ParameterSet const &config)
Definition: RPCDCCLinkMapHandler.cc:25
cond::persistency::ConnectionPool::createCoralSession
std::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)
Definition: ConnectionPool.cc:181
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
RPCDCCLinkMapHandler.h
RPCDCCLinkMapHandler::~RPCDCCLinkMapHandler
~RPCDCCLinkMapHandler() override
Definition: RPCDCCLinkMapHandler.cc:36
config
Definition: config.py:1
RPCDCCLinkMapHandler::txt_file_
std::string txt_file_
Definition: RPCDCCLinkMapHandler.h:30
RPCDCCLinkMapHandler::connect_
std::string connect_
Definition: RPCDCCLinkMapHandler.h:32
query
Definition: query.py:1
RPCDCCLinkMapHandler::getNewObjects
void getNewObjects() override
Definition: RPCDCCLinkMapHandler.cc:38
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
popcon::PopConSourceHandler< RPCDCCLinkMap >::tagInfo
cond::TagInfo_t const & tagInfo() const
Definition: PopConSourceHandler.h:78
RPCDCCLinkMapHandler::id_
std::string id_
Definition: RPCDCCLinkMapHandler.h:26
RPCLBLinkNameParser.h
cond::Iov_t::since
Time_t since
Definition: Types.h:53
cond::persistency::ConnectionPool::setParameters
void setParameters(const edm::ParameterSet &connectionPset)
Definition: ConnectionPool.cc:43
cond::persistency::ConnectionPool::configure
void configure()
Definition: ConnectionPool.cc:127
RPCDCCLinkMapHandler::id
std::string id() const override
Definition: RPCDCCLinkMapHandler.cc:109
RPCDCCLinkMap::map_type
std::map< RPCDCCLink, RPCLBLink > map_type
Definition: RPCDCCLinkMap.h:13
cond::TagInfo_t::lastInterval
Iov_t lastInterval
Definition: Types.h:73
std
Definition: JetResolutionObject.h:76
Exception
Definition: hltDiff.cc:246
RPCDCCLinkMap
Definition: RPCDCCLinkMap.h:11
Exception.h
contentValuesFiles.query
query
Definition: contentValuesFiles.py:38
RPCDCCLinkMapHandler::since_run_
cond::Time_t since_run_
Definition: RPCDCCLinkMapHandler.h:28
ParameterSet.h
Types.h
cond::TagInfo_t
Definition: Types.h:69
edm::Log
Definition: MessageLogger.h:70
RPCDCCLinkMapHandler::connection_
cond::persistency::ConnectionPool connection_
Definition: RPCDCCLinkMapHandler.h:33