Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:20

0001 #include "CondTools/RPC/interface/RPCDCCLinkMapHandler.h"
0002 
0003 #include <fstream>
0004 #include <memory>
0005 #include <sstream>
0006 
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 
0011 #include "CondCore/CondDB/interface/Types.h"
0012 
0013 #include "RelationalAccess/ICursor.h"
0014 #include "RelationalAccess/IQuery.h"
0015 #include "RelationalAccess/IQueryDefinition.h"
0016 #include "RelationalAccess/ISchema.h"
0017 #include "RelationalAccess/ISessionProxy.h"
0018 #include "RelationalAccess/ITransaction.h"
0019 
0020 #include "CoralBase/Attribute.h"
0021 #include "CoralBase/AttributeList.h"
0022 
0023 #include "CondTools/RPC/interface/RPCLBLinkNameParser.h"
0024 
0025 RPCDCCLinkMapHandler::RPCDCCLinkMapHandler(edm::ParameterSet const& config)
0026     : id_(config.getParameter<std::string>("identifier")),
0027       data_tag_(config.getParameter<std::string>("dataTag")),
0028       since_run_(config.getParameter<unsigned long long>("sinceRun")),
0029       txt_file_(config.getUntrackedParameter<std::string>("txtFile", "")),
0030       connect_(config.getParameter<std::string>("connect")) {
0031   edm::LogInfo("RPCDCCLinkMapHandler") << "Configuring Input Connection";
0032   connection_.setParameters(config.getParameter<edm::ParameterSet>("DBParameters"));
0033   connection_.configure();
0034 }
0035 
0036 RPCDCCLinkMapHandler::~RPCDCCLinkMapHandler() {}
0037 
0038 void RPCDCCLinkMapHandler::getNewObjects() {
0039   edm::LogInfo("RPCDCCLinkMapHandler") << "getNewObjects";
0040   cond::TagInfo_t const& tag_info = tagInfo();
0041   if (since_run_ < tag_info.lastInterval.since)
0042     throw cms::Exception("RPCDCCLinkMapHandler") << "Refuse to create RPCDCCLinkMap for run " << since_run_
0043                                                  << ", older than most recent tag" << tag_info.lastInterval.since;
0044 
0045   edm::LogInfo("RPCDCCLinkMapHandler") << "Opening read-only Input Session";
0046   auto input_session = connection_.createCoralSession(connect_, false);  // writeCapable
0047   edm::LogInfo("RPCDCCLinkMapHandler") << "Started Input Transaction";
0048   input_session->transaction().start(true);  // readOnly
0049 
0050   std::unique_ptr<coral::IQuery> query(input_session->schema("CMS_RPC_CONF").newQuery());
0051   query->addToTableList("DCCBOARD");
0052   query->addToTableList("TRIGGERBOARD");
0053   query->addToTableList("BOARDBOARDCONN");
0054   query->addToTableList("BOARD");
0055 
0056   query->addToOutputList("DCCBOARD.FEDNUMBER", "DCC");
0057   query->addToOutputList("TRIGGERBOARD.DCCINPUTCHANNELNUM", "DCC_INPUT");
0058   query->addToOutputList("BOARDBOARDCONN.COLLECTORBOARDINPUTNUM", "TB_INPUT");
0059   query->addToOutputList("BOARD.NAME", "LB_NAME");
0060 
0061   coral::AttributeList query_condition_data;
0062   query->setCondition(
0063       "TRIGGERBOARD.DCCBOARD_DCCBOARDID=DCCBOARD.DCCBOARDID"
0064       " AND BOARDBOARDCONN.BOARD_COLLECTORBOARDID=TRIGGERBOARD.TRIGGERBOARDID"
0065       " AND BOARD.BOARDID=BOARDBOARDCONN.BOARD_BOARDID",
0066       query_condition_data);
0067 
0068   int dcc(0), dcc_input(0), tb_input(0);
0069   std::string lb_name("");
0070 
0071   std::unique_ptr<RPCDCCLinkMap> dcc_link_map_object(new RPCDCCLinkMap());
0072   RPCDCCLinkMap::map_type& dcc_link_map = dcc_link_map_object->getMap();
0073   RPCLBLink lb_link;
0074 
0075   edm::LogInfo("RPCDCCLinkMapHandler") << "Execute query";
0076   coral::ICursor& cursor(query->execute());
0077   while (cursor.next()) {
0078     coral::AttributeList const& row(cursor.currentRow());
0079 
0080     // RPCLBLink
0081     lb_name = row["LB_NAME"].data<std::string>();
0082     RPCLBLinkNameParser::parse(lb_name, lb_link);
0083     if (lb_name != lb_link.getName())
0084       edm::LogWarning("RPCDCCLinkMapHandler") << "Mismatch LinkBoard Name: " << lb_name << " vs " << lb_link;
0085     lb_link.setLinkBoard().setConnector();  // MLB to link
0086 
0087     dcc = row["DCC"].data<long long>();
0088     dcc_input = row["DCC_INPUT"].data<long long>();
0089     tb_input = row["TB_INPUT"].data<long long>();
0090 
0091     dcc_link_map.insert(std::pair<RPCDCCLink, RPCLBLink>(RPCDCCLink(dcc, dcc_input, tb_input), lb_link));
0092   }
0093   cursor.close();
0094 
0095   input_session->transaction().commit();
0096 
0097   if (!txt_file_.empty()) {
0098     edm::LogInfo("RPCDCCLinkMapHandler") << "Fill txtFile";
0099     std::ofstream ofstream(txt_file_);
0100     for (auto const& link : dcc_link_map) {
0101       ofstream << link.first << ": " << link.second << std::endl;
0102     }
0103   }
0104 
0105   edm::LogInfo("RPCDCCLinkMapHandler") << "Add to transfer list";
0106   m_to_transfer.push_back(std::make_pair(dcc_link_map_object.release(), since_run_));
0107 }
0108 
0109 std::string RPCDCCLinkMapHandler::id() const { return id_; }