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 
std::map< RPCDCCLink, RPCLBLink > map_type
Definition: RPCDCCLinkMap.h:13
cond::persistency::ConnectionPool connection_
void getNewObjects() override
Iov_t lastInterval
Definition: Types.h:73
Time_t since
Definition: Types.h:53
Definition: config.py:1
RPCDCCLinkMapHandler(edm::ParameterSet const &config)
void setParameters(const edm::ParameterSet &connectionPset)
Definition: query.py:1
std::vector< std::pair< RPCDCCLinkMap *, Time_t > > m_to_transfer
Log< level::Info, false > LogInfo
static void parse(std::string const &name, RPCLBLink &lb_link)
std::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)
std::string id() const override