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 {
32  edm::LogInfo("RPCDCCLinkMapHandler") << "Configuring Input Connection";
35 }
36 
38 {}
39 
41 {
42  edm::LogInfo("RPCDCCLinkMapHandler") << "getNewObjects";
43  cond::TagInfo const & tag_info = tagInfo();
44  if (since_run_ < tag_info.lastInterval.first)
45  throw cms::Exception("RPCDCCLinkMapHandler") << "Refuse to create RPCDCCLinkMap for run " << since_run_
46  << ", older than most recent tag" << tag_info.lastInterval.first;
47 
48  edm::LogInfo("RPCDCCLinkMapHandler") << "Opening read-only Input Session";
49  auto input_session = connection_.createCoralSession(connect_, false); // writeCapable
50  edm::LogInfo("RPCDCCLinkMapHandler") << "Started Input Transaction";
51  input_session->transaction().start(true); // readOnly
52 
53  std::unique_ptr<coral::IQuery> query(input_session->schema("CMS_RPC_CONF").newQuery());
54  query->addToTableList("DCCBOARD");
55  query->addToTableList("TRIGGERBOARD");
56  query->addToTableList("BOARDBOARDCONN");
57  query->addToTableList("BOARD");
58 
59  query->addToOutputList("DCCBOARD.FEDNUMBER", "DCC");
60  query->addToOutputList("TRIGGERBOARD.DCCINPUTCHANNELNUM", "DCC_INPUT");
61  query->addToOutputList("BOARDBOARDCONN.COLLECTORBOARDINPUTNUM", "TB_INPUT");
62  query->addToOutputList("BOARD.NAME", "LB_NAME");
63 
64  coral::AttributeList query_condition_data;
65  query->setCondition("TRIGGERBOARD.DCCBOARD_DCCBOARDID=DCCBOARD.DCCBOARDID"
66  " AND BOARDBOARDCONN.BOARD_COLLECTORBOARDID=TRIGGERBOARD.TRIGGERBOARDID"
67  " AND BOARD.BOARDID=BOARDBOARDCONN.BOARD_BOARDID"
68  , query_condition_data);
69 
70  int dcc(0), dcc_input(0), tb_input(0);
71  std::string lb_name("");
72 
73  std::unique_ptr<RPCDCCLinkMap> dcc_link_map_object(new RPCDCCLinkMap());
74  RPCDCCLinkMap::map_type & dcc_link_map
75  = dcc_link_map_object->getMap();
76  RPCLBLink lb_link;
77 
78  edm::LogInfo("RPCDCCLinkMapHandler") << "Execute query";
79  coral::ICursor & cursor(query->execute());
80  while (cursor.next()) {
81  coral::AttributeList const & row(cursor.currentRow());
82 
83  // RPCLBLink
84  lb_name = row["LB_NAME"].data<std::string>();
85  RPCLBLinkNameParser::parse(lb_name, lb_link);
86  if (lb_name != lb_link.getName())
87  edm::LogWarning("RPCDCCLinkMapHandler") << "Mismatch LinkBoard Name: " << lb_name << " vs " << lb_link;
88  lb_link.setLinkBoard().setConnector(); // MLB to link
89 
90  dcc = row["DCC"].data<long long>();
91  dcc_input = row["DCC_INPUT"].data<long long>();
92  tb_input = row["TB_INPUT"].data<long long>();
93 
94  dcc_link_map.insert(std::pair<RPCDCCLink, RPCLBLink>(RPCDCCLink(dcc, dcc_input, tb_input)
95  , lb_link));
96  }
97  cursor.close();
98 
99  input_session->transaction().commit();
100 
101  if (!txt_file_.empty()) {
102  edm::LogInfo("RPCDCCLinkMapHandler") << "Fill txtFile";
103  std::ofstream ofstream(txt_file_);
104  for (auto const & link : dcc_link_map) {
105  ofstream << link.first << ": " << link.second << std::endl;
106  }
107  }
108 
109  edm::LogInfo("RPCDCCLinkMapHandler") << "Add to transfer list";
110  m_to_transfer.push_back(std::make_pair(dcc_link_map_object.release(), since_run_));
111 }
112 
114 {
115  return id_;
116 }
std::map< RPCDCCLink, RPCLBLink > map_type
Definition: RPCDCCLinkMap.h:14
cond::persistency::ConnectionPool connection_
T getParameter(std::string const &) const
void getNewObjects() override
Definition: config.py:1
RPCDCCLinkMapHandler(edm::ParameterSet const &config)
def query(query_str, verbose=False)
Definition: das.py:6
void setParameters(const edm::ParameterSet &connectionPset)
Definition: query.py:1
cond::ValidityInterval lastInterval
Definition: Types.h:76
std::string id() const override
static void parse(std::string const &name, RPCLBLink &lb_link)
std::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)