CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Protected Attributes
RPCLBLinkMapHandler Class Reference

#include <RPCLBLinkMapHandler.h>

Inheritance diagram for RPCLBLinkMapHandler:
popcon::PopConSourceHandler< RPCLBLinkMap >

Public Member Functions

void getNewObjects () override
 
std::string id () const override
 
 RPCLBLinkMapHandler (edm::ParameterSet const &config)
 
 ~RPCLBLinkMapHandler () override
 
- Public Member Functions inherited from popcon::PopConSourceHandler< RPCLBLinkMap >
void convertFromOld ()
 
SummarydummySummary (typename OldContainer::value_type const &) const
 
void initialize (const cond::persistency::Session &dbSession, cond::TagInfo_t const &tagInfo, cond::LogDBEntry_t const &logDBEntry)
 
Ref lastPayload () const
 
cond::LogDBEntry_t const & logDBEntry () const
 
std::pair< Container const *, std::string const > operator() (const cond::persistency::Session &session, cond::TagInfo_t const &tagInfo, cond::LogDBEntry_t const &logDBEntry) const
 
 PopConSourceHandler ()
 
Container const & returnData ()
 
void sort ()
 
cond::TagInfo_t const & tagInfo () const
 
std::string const & userTextLog () const
 
virtual ~PopConSourceHandler ()
 

Static Public Member Functions

static RPCDetId getRPCDetId (int region, int disk_or_wheel, int layer, int sector, std::string subsector_string, std::string partition)
 

Protected Attributes

std::string connect_
 
cond::persistency::ConnectionPool connection_
 
std::string data_tag_
 
std::string id_
 
cond::Time_t since_run_
 
std::string txt_file_
 
- Protected Attributes inherited from popcon::PopConSourceHandler< RPCLBLinkMap >
OldContainer m_to_transfer
 
std::string m_userTextLog
 

Additional Inherited Members

- Public Types inherited from popcon::PopConSourceHandler< RPCLBLinkMap >
typedef std::vector< Triplet > Container
 
typedef std::vector< std::pair< RPCLBLinkMap *, cond::Time_t > > OldContainer
 
typedef PopConSourceHandler< RPCLBLinkMapself
 
typedef cond::Summary Summary
 
typedef cond::Time_t Time_t
 
typedef RPCLBLinkMap value_type
 
- Protected Member Functions inherited from popcon::PopConSourceHandler< RPCLBLinkMap >
int add (value_type *payload, Summary *summary, Time_t time)
 
cond::persistency::SessiondbSession () const
 

Detailed Description

Definition at line 17 of file RPCLBLinkMapHandler.h.

Constructor & Destructor Documentation

RPCLBLinkMapHandler::RPCLBLinkMapHandler ( edm::ParameterSet const &  config)

Definition at line 83 of file RPCLBLinkMapHandler.cc.

References cond::persistency::ConnectionPool::configure(), connection_, edm::ParameterSet::getParameter(), and cond::persistency::ConnectionPool::setParameters().

84  : id_(config.getParameter<std::string>("identifier"))
85  , data_tag_(config.getParameter<std::string>("dataTag"))
86  , since_run_(config.getParameter<unsigned long long>("sinceRun"))
87  , txt_file_(config.getUntrackedParameter<std::string>("txtFile", ""))
88  , connect_(config.getParameter<std::string>("connect"))
89 {
90  edm::LogInfo("RPCDCCLinkMapHandler") << "Configuring Input Connection";
91  connection_.setParameters(config.getParameter<edm::ParameterSet>("DBParameters"));
93 }
Definition: config.py:1
void setParameters(const edm::ParameterSet &connectionPset)
cond::persistency::ConnectionPool connection_
RPCLBLinkMapHandler::~RPCLBLinkMapHandler ( )
override

Definition at line 95 of file RPCLBLinkMapHandler.cc.

96 {}

Member Function Documentation

void RPCLBLinkMapHandler::getNewObjects ( )
overridevirtual

Implements popcon::PopConSourceHandler< RPCLBLinkMap >.

Definition at line 98 of file RPCLBLinkMapHandler.cc.

References connect_, connection_, cond::persistency::ConnectionPool::createCoralSession(), Exception, RPCLBLink::getName(), getRPCDetId(), cond::TagInfo_t::lastInterval, popcon::PopConSourceHandler< RPCLBLinkMap >::m_to_transfer, RPCLBLinkNameParser::parse(), das::query(), RPCLBLink::setConnector(), since_run_, slope, AlCaHLTBitMon_QueryRunRegistry::string, popcon::PopConSourceHandler< RPCLBLinkMap >::tagInfo(), and txt_file_.

99 {
100  edm::LogInfo("RPCLBLinkMapHandler") << "getNewObjects";
101  cond::TagInfo const & tag_info = tagInfo();
102  if (since_run_ < tag_info.lastInterval.first)
103  throw cms::Exception("RPCLBLinkMapHandler") << "Refuse to create RPCLBLinkMap for run " << since_run_
104  << ", older than most recent tag" << tag_info.lastInterval.first;
105 
106  edm::LogInfo("RPCDCCLinkMapHandler") << "Opening read-only Input Session";
107  auto input_session = connection_.createCoralSession(connect_, false); // writeCapable
108  edm::LogInfo("RPCDCCLinkMapHandler") << "Started Input Transaction";
109  input_session->transaction().start(true); // readOnly
110 
111  std::unique_ptr<coral::IQuery> query(input_session->schema("CMS_RPC_CONF").newQuery());
112  query->addToTableList("BOARD");
113  query->addToTableList("CHAMBERSTRIP");
114  query->addToTableList("CHAMBERLOCATION");
115  query->addToTableList("FEBLOCATION");
116  query->addToTableList("FEBCONNECTOR");
117  coral::IQueryDefinition & subquery_min_channel(query->defineSubQuery("MIN_CHANNEL"));
118  query->addToTableList("MIN_CHANNEL");
119  coral::IQueryDefinition & subquery_max_strip(query->defineSubQuery("MAX_STRIP"));
120  query->addToTableList("MAX_STRIP");
121 
122  query->addToOutputList("BOARD.NAME", "LB_NAME");
123  query->addToOutputList("FEBCONNECTOR.LINKBOARDINPUTNUM", "CONNECTOR");
124  query->addToOutputList("CHAMBERSTRIP.CHAMBERSTRIPNUMBER", "FIRST_STRIP");
125  query->addToOutputList("CAST(DECODE(SIGN(MAX_STRIP.STRIP - CHAMBERSTRIP.CHAMBERSTRIPNUMBER), 1, 1, -1) AS INTEGER)", "SLOPE");
126  query->addToOutputList("MIN_CHANNEL.CHANNELS", "CHANNELS");
127  query->addToOutputList("CAST(DECODE(CHAMBERLOCATION.BARRELORENDCAP, 'Barrel', 0, DECODE(SIGN(CHAMBERLOCATION.DISKORWHEEL), 1, 1, -1)) AS INTEGER)", "REGION");
128  query->addToOutputList("CHAMBERLOCATION.DISKORWHEEL", "DISKORWHEEL");
129  query->addToOutputList("CHAMBERLOCATION.LAYER", "LAYER");
130  query->addToOutputList("CHAMBERLOCATION.SECTOR", "SECTOR");
131  query->addToOutputList("CHAMBERLOCATION.SUBSECTOR", "SUBSECTOR");
132  query->addToOutputList("FEBLOCATION.FEBLOCALETAPARTITION", "ETAPARTITION");
133 
134  subquery_min_channel.addToTableList("CHAMBERSTRIP");
135  subquery_min_channel.addToOutputList("FC_FEBCONNECTORID");
136  subquery_min_channel.addToOutputList("MIN(CABLECHANNELNUM)", "CHANNEL");
137  subquery_min_channel.addToOutputList("CAST(SUM(POWER(2, CABLECHANNELNUM-1)) AS INTEGER)", "CHANNELS");
138  subquery_min_channel.groupBy("FC_FEBCONNECTORID");
139  coral::AttributeList subquery_min_channel_condition_data;
140  subquery_min_channel.setCondition("CABLECHANNELNUM IS NOT NULL"
141  , subquery_min_channel_condition_data);
142 
143  subquery_max_strip.addToTableList("CHAMBERSTRIP");
144  coral::IQueryDefinition & subquery_max_channel(subquery_max_strip.defineSubQuery("MAX_CHANNEL"));
145  subquery_max_strip.addToTableList("MAX_CHANNEL");
146  subquery_max_strip.addToOutputList("CHAMBERSTRIP.FC_FEBCONNECTORID", "FC_FEBCONNECTORID");
147  subquery_max_strip.addToOutputList("CHAMBERSTRIP.CHAMBERSTRIPNUMBER", "STRIP");
148  coral::AttributeList subquery_max_strip_condition_data;
149  subquery_max_strip.setCondition("CHAMBERSTRIP.FC_FEBCONNECTORID=MAX_CHANNEL.FC_FEBCONNECTORID"
150  " AND CHAMBERSTRIP.CABLECHANNELNUM=MAX_CHANNEL.CHANNEL"
151  , subquery_max_strip_condition_data);
152 
153  subquery_max_channel.addToTableList("CHAMBERSTRIP");
154  subquery_max_channel.addToOutputList("FC_FEBCONNECTORID");
155  subquery_max_channel.addToOutputList("MAX(CABLECHANNELNUM)", "CHANNEL");
156  subquery_max_channel.groupBy("FC_FEBCONNECTORID");
157  coral::AttributeList subquery_max_channel_condition_data;
158  subquery_max_channel.setCondition("CABLECHANNELNUM IS NOT NULL"
159  , subquery_max_channel_condition_data);
160 
161  coral::AttributeList query_condition_data;
162  query->setCondition("CHAMBERSTRIP.FC_FEBCONNECTORID=MIN_CHANNEL.FC_FEBCONNECTORID"
163  " AND CHAMBERSTRIP.CABLECHANNELNUM=MIN_CHANNEL.CHANNEL"
164  " AND CHAMBERSTRIP.FC_FEBCONNECTORID=MAX_STRIP.FC_FEBCONNECTORID"
165  " AND CHAMBERSTRIP.FC_FEBCONNECTORID=FEBCONNECTOR.FEBCONNECTORID"
166  " AND FEBCONNECTOR.FL_FEBLOCATIONID=FEBLOCATION.FEBLOCATIONID"
167  " AND BOARD.BOARDID=FEBLOCATION.LB_LINKBOARDID"
168  " AND CHAMBERLOCATION.CHAMBERLOCATIONID=FEBLOCATION.CL_CHAMBERLOCATIONID"
169  , query_condition_data);
170 
171  std::string lb_name("");
172  int first_strip(0), slope(1);
173  std::uint16_t channels(0x0);
174 
175  std::unique_ptr<RPCLBLinkMap> lb_link_map_object(new RPCLBLinkMap());
176  RPCLBLinkMap::map_type & lb_link_map
177  = lb_link_map_object->getMap();
178  RPCLBLink lb_link;
179  RPCDetId det_id;
180  std::string subsector;
181 
182  edm::LogInfo("RPCLBLinkMapHandler") << "Execute query";
183  coral::ICursor & cursor(query->execute());
184  while (cursor.next()) {
185  coral::AttributeList const & row(cursor.currentRow());
186 
187  // RPCLBLink
188  lb_name = row["LB_NAME"].data<std::string>();
189  RPCLBLinkNameParser::parse(lb_name, lb_link);
190  if (lb_name != lb_link.getName())
191  edm::LogWarning("RPCLBLinkMapHandler") << "Mismatch LinkBoard Name: " << lb_name << " vs " << lb_link;
192  lb_link.setConnector(row["CONNECTOR"].data<short>() - 1); // 1-6 to 0-5
193 
194  // RPCDetId
195  if (row["SUBSECTOR"].isNull())
196  subsector = "";
197  else
198  subsector = row["SUBSECTOR"].data<std::string>();
199  det_id = getRPCDetId(row["REGION"].data<long long>()
200  , row["DISKORWHEEL"].data<short>()
201  , row["LAYER"].data<short>()
202  , row["SECTOR"].data<short>()
203  , subsector
204  , row["ETAPARTITION"].data<std::string>());
205 
206  // RPCFebConnector
207  first_strip = row["FIRST_STRIP"].data<int>();
208  slope = row["SLOPE"].data<long long>();
209  channels = (std::uint16_t)(row["CHANNELS"].data<long long>());
210 
211  lb_link_map.insert(std::pair<RPCLBLink, RPCFebConnector>(lb_link, RPCFebConnector(det_id
212  , first_strip
213  , slope
214  , channels)));
215  }
216  cursor.close();
217 
218  input_session->transaction().commit();
219 
220  if (!txt_file_.empty()) {
221  edm::LogInfo("RPCLBLinkMapHandler") << "Fill txtFile";
222  std::ofstream ofstream(txt_file_);
223  for (auto const & link_connector : lb_link_map) {
224  ofstream << link_connector.first << ": " << link_connector.second << std::endl;
225  }
226  }
227 
228  edm::LogInfo("RPCLBLinkMapHandler") << "Add to transfer list";
229  m_to_transfer.push_back(std::make_pair(lb_link_map_object.release(), since_run_));
230 }
static const double slope[3]
static RPCDetId getRPCDetId(int region, int disk_or_wheel, int layer, int sector, std::string subsector_string, std::string partition)
def query(query_str, verbose=False)
Definition: das.py:6
Definition: query.py:1
cond::persistency::ConnectionPool connection_
cond::ValidityInterval lastInterval
Definition: Types.h:75
std::map< RPCLBLink, RPCFebConnector > map_type
Definition: RPCLBLinkMap.h:14
static void parse(std::string const &name, RPCLBLink &lb_link)
std::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)
cond::TagInfo_t const & tagInfo() const
RPCDetId RPCLBLinkMapHandler::getRPCDetId ( int  region,
int  disk_or_wheel,
int  layer,
int  sector,
std::string  subsector_string,
std::string  partition 
)
static

Definition at line 26 of file RPCLBLinkMapHandler.cc.

References funct::abs(), Exception, relativeConstraints::ring, and relativeConstraints::station.

Referenced by getNewObjects().

28 {
29  int station(0), ring(0), subsector(0), roll(0);
30  // region well-defined
31  if (!region) { // barrel
32  switch (layer) {
33  case 1:
34  case 2: station = 1; break;
35  case 3:
36  case 4: station = 2; layer -= 2; break;
37  case 5: station = 3; layer = 1; break;
38  case 6: station = 4; layer = 1; break;
39  }
40  ring = disk_or_wheel;
41  // sector well-defined
42  subsector = 1;
43  if (subsector_string == "+"
44  && (station == 3
45  || (station==4 && (sector != 4 && sector != 9 && sector != 11)))
46  )
47  subsector = 2;
48  if (station == 4 && sector == 4) {
49  if (subsector_string == "-")
50  subsector=2;
51  else if (subsector_string == "+")
52  subsector=3;
53  else if (subsector_string == "++")
54  subsector=4;
55  }
56  } else { // endcap
57  station = std::abs(disk_or_wheel);
58  ring = layer;
59  layer = 1;
60  if (ring > 1 || station == 1) {
61  subsector = (sector - 1) % 6 + 1;
62  sector = (sector - 1) / 6 + 1;
63  } else {
64  subsector = (sector - 1) % 3 + 1;
65  sector = (sector - 1) / 3 + 1;
66  }
67  }
68  // roll
69  if (partition == "Backward" || partition == "A")
70  roll = 1;
71  else if (partition == "Central" || partition == "B")
72  roll = 2;
73  else if (partition == "Forward" || partition == "C")
74  roll = 3;
75  else if (partition == "D")
76  roll = 4;
77  else
78  throw cms::Exception("RPCLBLinkMapHandler") << "Unexpected partition name " << partition;
79 
80  return RPCDetId(region, ring, station, sector, layer, subsector, roll);
81 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::string RPCLBLinkMapHandler::id ( ) const
overridevirtual

Implements popcon::PopConSourceHandler< RPCLBLinkMap >.

Definition at line 232 of file RPCLBLinkMapHandler.cc.

References id_.

233 {
234  return id_;
235 }

Member Data Documentation

std::string RPCLBLinkMapHandler::connect_
protected

Definition at line 38 of file RPCLBLinkMapHandler.h.

Referenced by getNewObjects().

cond::persistency::ConnectionPool RPCLBLinkMapHandler::connection_
protected

Definition at line 39 of file RPCLBLinkMapHandler.h.

Referenced by getNewObjects(), and RPCLBLinkMapHandler().

std::string RPCLBLinkMapHandler::data_tag_
protected

Definition at line 33 of file RPCLBLinkMapHandler.h.

std::string RPCLBLinkMapHandler::id_
protected

Definition at line 32 of file RPCLBLinkMapHandler.h.

Referenced by id().

cond::Time_t RPCLBLinkMapHandler::since_run_
protected

Definition at line 34 of file RPCLBLinkMapHandler.h.

Referenced by getNewObjects().

std::string RPCLBLinkMapHandler::txt_file_
protected

Definition at line 36 of file RPCLBLinkMapHandler.h.

Referenced by getNewObjects().