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"
20 #include "CoralBase/Attribute.h"
21 #include "CoralBase/AttributeList.h"
28 int _station(0), _ring(0), _subsector(0), _roll(0);
33 case 2: _station = 1;
break;
35 case 4: _station = 2; _layer -= 2;
break;
36 case 5: _station = 3; _layer = 1;
break;
37 case 6: _station = 4; _layer = 1;
break;
39 _ring = _disk_or_wheel;
42 if (_subsector_string ==
"+"
44 || (_station==4 && (_sector != 4 && _sector != 9 && _sector != 11)))
47 if (_station == 4 && _sector == 4) {
48 if (_subsector_string ==
"-")
50 else if (_subsector_string ==
"+")
52 else if (_subsector_string ==
"++")
59 if (_ring > 1 || _station == 1) {
60 _subsector = (_sector - 1) % 6 + 1;
61 _sector = (_sector - 1) / 6 + 1;
63 _subsector = (_sector - 1) % 3 + 1;
64 _sector = (_sector - 1) / 3 + 1;
68 if (_partition ==
"Backward" || _partition ==
"A")
70 else if (_partition ==
"Central" || _partition ==
"B")
72 else if (_partition ==
"Forward" || _partition ==
"C")
74 else if (_partition ==
"D")
77 throw cms::Exception(
"RPCLBLinkMapHandler") <<
"Unexpected partition name " << _partition;
79 return RPCDetId(_region, _ring, _station, _sector, _layer, _subsector, _roll);
83 : id_(_config.getParameter<std::
string>(
"identifier"))
84 , data_tag_(_config.getParameter<std::
string>(
"dataTag"))
85 , since_run_(_config.getParameter<unsigned long long>(
"sinceRun"))
86 , txt_file_(_config.getUntrackedParameter<std::
string>(
"txtFile",
""))
87 , connect_(_config.getParameter<std::
string>(
"connect"))
89 edm::LogInfo(
"RPCDCCLinkMapHandler") <<
"Configuring Input Connection";
103 <<
", older than most recent tag" << _tag_info.
lastInterval.first;
105 edm::LogInfo(
"RPCDCCLinkMapHandler") <<
"Opening read-only Input Session";
107 edm::LogInfo(
"RPCDCCLinkMapHandler") <<
"Started Input Transaction";
108 _input_session->transaction().start(
true);
110 std::auto_ptr<coral::IQuery> _query(_input_session->schema(
"CMS_RPC_CONF").newQuery());
111 _query->addToTableList(
"BOARD");
112 _query->addToTableList(
"CHAMBERSTRIP");
113 _query->addToTableList(
"CHAMBERLOCATION");
114 _query->addToTableList(
"FEBLOCATION");
115 _query->addToTableList(
"FEBCONNECTOR");
116 coral::IQueryDefinition & _subquery_min_channel(_query->defineSubQuery(
"MIN_CHANNEL"));
117 _query->addToTableList(
"MIN_CHANNEL");
118 coral::IQueryDefinition & _subquery_max_strip(_query->defineSubQuery(
"MAX_STRIP"));
119 _query->addToTableList(
"MAX_STRIP");
121 _query->addToOutputList(
"BOARD.NAME",
"LB_NAME");
122 _query->addToOutputList(
"FEBCONNECTOR.LINKBOARDINPUTNUM",
"CONNECTOR");
123 _query->addToOutputList(
"CHAMBERSTRIP.CHAMBERSTRIPNUMBER",
"FIRST_STRIP");
124 _query->addToOutputList(
"CAST(DECODE(SIGN(MAX_STRIP.STRIP - CHAMBERSTRIP.CHAMBERSTRIPNUMBER), 1, 1, -1) AS INTEGER)",
"SLOPE");
125 _query->addToOutputList(
"MIN_CHANNEL.CHANNELS",
"CHANNELS");
126 _query->addToOutputList(
"CAST(DECODE(CHAMBERLOCATION.BARRELORENDCAP, 'Barrel', 0, DECODE(SIGN(CHAMBERLOCATION.DISKORWHEEL), 1, 1, -1)) AS INTEGER)",
"REGION");
127 _query->addToOutputList(
"CHAMBERLOCATION.DISKORWHEEL",
"DISKORWHEEL");
128 _query->addToOutputList(
"CHAMBERLOCATION.LAYER",
"LAYER");
129 _query->addToOutputList(
"CHAMBERLOCATION.SECTOR",
"SECTOR");
130 _query->addToOutputList(
"CHAMBERLOCATION.SUBSECTOR",
"SUBSECTOR");
131 _query->addToOutputList(
"FEBLOCATION.FEBLOCALETAPARTITION",
"ETAPARTITION");
133 _subquery_min_channel.addToTableList(
"CHAMBERSTRIP");
134 _subquery_min_channel.addToOutputList(
"FC_FEBCONNECTORID");
135 _subquery_min_channel.addToOutputList(
"MIN(CABLECHANNELNUM)",
"CHANNEL");
136 _subquery_min_channel.addToOutputList(
"CAST(SUM(POWER(2, CABLECHANNELNUM-1)) AS INTEGER)",
"CHANNELS");
137 _subquery_min_channel.groupBy(
"FC_FEBCONNECTORID");
138 coral::AttributeList _subquery_min_channel_condition_data;
139 _subquery_min_channel.setCondition(
"CABLECHANNELNUM IS NOT NULL"
140 , _subquery_min_channel_condition_data);
142 _subquery_max_strip.addToTableList(
"CHAMBERSTRIP");
143 coral::IQueryDefinition & _subquery_max_channel(_subquery_max_strip.defineSubQuery(
"MAX_CHANNEL"));
144 _subquery_max_strip.addToTableList(
"MAX_CHANNEL");
145 _subquery_max_strip.addToOutputList(
"CHAMBERSTRIP.FC_FEBCONNECTORID",
"FC_FEBCONNECTORID");
146 _subquery_max_strip.addToOutputList(
"CHAMBERSTRIP.CHAMBERSTRIPNUMBER",
"STRIP");
147 coral::AttributeList _subquery_max_strip_condition_data;
148 _subquery_max_strip.setCondition(
"CHAMBERSTRIP.FC_FEBCONNECTORID=MAX_CHANNEL.FC_FEBCONNECTORID"
149 " AND CHAMBERSTRIP.CABLECHANNELNUM=MAX_CHANNEL.CHANNEL"
150 , _subquery_max_strip_condition_data);
152 _subquery_max_channel.addToTableList(
"CHAMBERSTRIP");
153 _subquery_max_channel.addToOutputList(
"FC_FEBCONNECTORID");
154 _subquery_max_channel.addToOutputList(
"MAX(CABLECHANNELNUM)",
"CHANNEL");
155 _subquery_max_channel.groupBy(
"FC_FEBCONNECTORID");
156 coral::AttributeList _subquery_max_channel_condition_data;
157 _subquery_max_channel.setCondition(
"CABLECHANNELNUM IS NOT NULL"
158 , _subquery_max_channel_condition_data);
160 coral::AttributeList _query_condition_data;
161 _query->setCondition(
"CHAMBERSTRIP.FC_FEBCONNECTORID=MIN_CHANNEL.FC_FEBCONNECTORID"
162 " AND CHAMBERSTRIP.CABLECHANNELNUM=MIN_CHANNEL.CHANNEL"
163 " AND CHAMBERSTRIP.FC_FEBCONNECTORID=MAX_STRIP.FC_FEBCONNECTORID"
164 " AND CHAMBERSTRIP.FC_FEBCONNECTORID=FEBCONNECTOR.FEBCONNECTORID"
165 " AND FEBCONNECTOR.FL_FEBLOCATIONID=FEBLOCATION.FEBLOCATIONID"
166 " AND BOARD.BOARDID=FEBLOCATION.LB_LINKBOARDID"
167 " AND CHAMBERLOCATION.CHAMBERLOCATIONID=FEBLOCATION.CL_CHAMBERLOCATIONID"
168 , _query_condition_data);
171 int _first_strip(0), _slope(1);
172 ::uint16_t _channels(0x0);
176 = _lb_link_map_object->
getMap();
182 coral::ICursor & _cursor(_query->execute());
183 while (_cursor.next()) {
184 coral::AttributeList
const & _row(_cursor.currentRow());
189 if (_lb_name != _lb_link.
getName())
190 edm::LogWarning(
"RPCLBLinkMapHandler") <<
"Mismatch LinkBoard Name: " << _lb_name <<
" vs " << _lb_link;
191 _lb_link.
setConnector(_row[
"CONNECTOR"].data<short>() - 1);
194 if (_row[
"SUBSECTOR"].isNull())
197 _subsector = _row[
"SUBSECTOR"].data<
std::string>();
198 _det_id =
getRPCDetId(_row[
"REGION"].data<long long>()
199 , _row[
"DISKORWHEEL"].data<short>()
200 , _row[
"LAYER"].data<short>()
201 , _row[
"SECTOR"].data<short>()
203 , _row[
"ETAPARTITION"].data<std::string>());
206 _first_strip = _row[
"FIRST_STRIP"].data<
int>();
207 _slope = _row[
"SLOPE"].data<
long long>();
208 _channels = (::uint16_t)(_row[
"CHANNELS"].data<long long>());
210 _lb_link_map.insert(std::pair<RPCLBLink, RPCFebConnector>(_lb_link,
RPCFebConnector(_det_id
217 _input_session->transaction().commit();
222 for (RPCLBLinkMap::map_type::const_iterator _link_connector = _lb_link_map.begin()
223 ; _link_connector != _lb_link_map.end() ; ++_link_connector) {
224 _ofstream << _link_connector->first <<
": " << _link_connector->second << std::endl;
228 edm::LogInfo(
"RPCLBLinkMapHandler") <<
"Add to transfer list";
T getParameter(std::string const &) const
OldContainer m_to_transfer
void setParameters(const edm::ParameterSet &connectionPset)
cond::persistency::ConnectionPool connection_
cond::ValidityInterval lastInterval
Abs< T >::type abs(const T &t)
std::string getName() const
static RPCDetId getRPCDetId(int _region, int _disk_or_wheel, int _layer, int _sector, std::string _subsector_string, std::string _partition)
static void parse(std::string const &_name, RPCLBLink &_lb_link)
std::map< RPCLBLink, RPCFebConnector > map_type
RPCLBLink & setConnector(int _connector=wildcard_)
RPCLBLinkMapHandler(edm::ParameterSet const &_config)
std::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)
cond::TagInfo_t const & tagInfo() const