Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:14

0001 #ifndef EventFilter_RPCRawToDigi_RPCTwinMuxRecord_icc
0002 #define EventFilter_RPCRawToDigi_RPCTwinMuxRecord_icc
0003 
0004 #include "EventFilter/RPCRawToDigi/interface/RPCTwinMuxRecord.h"
0005 
0006 namespace rpctwinmux {
0007 
0008   inline unsigned int TwinMuxRecord::getType(std::uint64_t const record) {
0009     if ((record & rpc_first_identifier_mask_) == rpc_first_identifier_)
0010       return rpc_first_type_;
0011     if ((record & rpc_second_identifier_mask_) == rpc_second_identifier_)
0012       return rpc_second_type_;
0013     if ((record & error_identifier_mask_) == error_identifier_)
0014       return error_type_;
0015     return unknown_type_;
0016   }
0017 
0018   inline unsigned int TwinMuxRecord::getType() const { return getType(record_); }
0019 
0020   inline void TwinMuxRecord::set(std::uint64_t const record) { record_ = record; }
0021 
0022   inline void TwinMuxRecord::reset() { record_ = 0x0; }
0023 
0024   inline std::uint64_t const& TwinMuxRecord::getRecord() const { return record_; }
0025 
0026   inline void BlockHeader::set(std::uint64_t const record) { record_ = record; }
0027 
0028   inline void BlockHeader::reset() { record_ = 0x0; }
0029 
0030   inline std::uint64_t const& BlockHeader::getRecord() const { return record_; }
0031 
0032   inline unsigned int BlockHeader::getFirmwareVersion() const { return (record_ & ufov_mask_) >> ufov_offset_; }
0033 
0034   inline unsigned int BlockHeader::getNAMC() const { return (record_ & n_amc_mask_) >> n_amc_offset_; }
0035 
0036   inline unsigned int BlockHeader::getOrbitCounter() const {
0037     return (record_ & orbit_counter_mask_) >> orbit_counter_offset_;
0038   }
0039 
0040   inline void BlockHeader::setFirmwareVersion(unsigned int ufov) {
0041     record_ &= ~ufov_mask_;
0042     record_ |= (((std::uint64_t)(ufov) << ufov_offset_) & ufov_mask_);
0043   }
0044 
0045   inline void BlockHeader::setNAMC(unsigned int n_amc) {
0046     record_ &= ~n_amc_mask_;
0047     record_ |= (((std::uint64_t)(n_amc) << n_amc_offset_) & n_amc_mask_);
0048   }
0049 
0050   inline void BlockHeader::setOrbitCounter(unsigned int orbit_counter) {
0051     record_ &= ~orbit_counter_mask_;
0052     record_ |= (((std::uint64_t)(orbit_counter) << orbit_counter_offset_) & orbit_counter_mask_);
0053   }
0054 
0055   inline void BlockTrailer::set(std::uint64_t const record) { record_ = record; }
0056 
0057   inline void BlockTrailer::reset() { record_ = 0x0; }
0058 
0059   inline std::uint64_t const& BlockTrailer::getRecord() const { return record_; }
0060 
0061   inline std::uint32_t BlockTrailer::getCRC() const { return (record_ & crc_mask_) >> crc_offset_; }
0062 
0063   inline unsigned int BlockTrailer::getBlockNumber() const {
0064     return (record_ & block_number_mask_) >> block_number_offset_;
0065   }
0066 
0067   inline unsigned int BlockTrailer::getEventCounter() const {
0068     return (record_ & event_counter_mask_) >> event_counter_offset_;
0069   }
0070 
0071   inline unsigned int BlockTrailer::getBXCounter() const { return (record_ & bx_counter_mask_) >> bx_counter_offset_; }
0072 
0073   inline void BlockTrailer::setCRC(std::uint32_t crc) {
0074     record_ &= ~crc_mask_;
0075     record_ |= (((std::uint64_t)(crc) << crc_offset_) & crc_mask_);
0076   }
0077 
0078   inline void BlockTrailer::setBlockNumber(unsigned int block_number) {
0079     record_ &= ~block_number_mask_;
0080     record_ |= (((std::uint64_t)(block_number) << block_number_offset_) & block_number_mask_);
0081   }
0082 
0083   inline void BlockTrailer::setEventCounter(unsigned int event_counter) {
0084     record_ &= ~event_counter_mask_;
0085     record_ |= (((std::uint64_t)(event_counter) << event_counter_offset_) & event_counter_mask_);
0086   }
0087 
0088   inline void BlockTrailer::setBXCounter(unsigned int bx_counter) {
0089     record_ &= ~bx_counter_mask_;
0090     record_ |= (((std::uint64_t)(bx_counter) << bx_counter_offset_) & bx_counter_mask_);
0091   }
0092 
0093   inline void BlockAMCContent::set(std::uint64_t const record) { record_ = record; }
0094 
0095   inline void BlockAMCContent::reset() { record_ = 0x0; }
0096 
0097   inline std::uint64_t const& BlockAMCContent::getRecord() const { return record_; }
0098 
0099   inline bool BlockAMCContent::isLengthCorrect() const { return ((record_ & length_correct_mask_) ? true : false); }
0100 
0101   inline bool BlockAMCContent::isLastBlock() const { return ((record_ & more_blocks_mask_) ? false : true); }
0102 
0103   inline bool BlockAMCContent::isFirstBlock() const { return ((record_ & segmented_mask_) ? false : true); }
0104 
0105   inline bool BlockAMCContent::isEnabled() const { return ((record_ & enabled_mask_) ? true : false); }
0106 
0107   inline bool BlockAMCContent::isPresent() const { return ((record_ & present_mask_) ? true : false); }
0108 
0109   inline bool BlockAMCContent::isValid() const { return ((record_ & valid_mask_) ? true : false); }
0110 
0111   inline bool BlockAMCContent::isCRCOk() const { return ((record_ & crc_ok_mask_) ? true : false); }
0112 
0113   inline unsigned int BlockAMCContent::getSize() const { return (record_ & size_mask_) >> size_offset_; }
0114 
0115   inline unsigned int BlockAMCContent::getBlockNumber() const {
0116     return (record_ & block_number_mask_) >> block_number_offset_;
0117   }
0118 
0119   inline unsigned int BlockAMCContent::getAMCNumber() const {
0120     return (record_ & amc_number_mask_) >> amc_number_offset_;
0121   }
0122 
0123   inline unsigned int BlockAMCContent::getBoardId() const { return (record_ & board_id_mask_) >> board_id_offset_; }
0124 
0125   inline void BlockAMCContent::setLengthCorrect(bool length_correct) {
0126     if (length_correct)
0127       record_ |= length_correct_mask_;
0128     else
0129       record_ &= ~(length_correct_mask_);
0130   }
0131 
0132   inline void BlockAMCContent::setLastBlock(bool last_block) {
0133     if (!last_block)
0134       record_ |= more_blocks_mask_;
0135     else
0136       record_ &= ~(more_blocks_mask_);
0137   }
0138 
0139   inline void BlockAMCContent::setFirstBlock(bool first_block) {
0140     if (!first_block)
0141       record_ |= segmented_mask_;
0142     else
0143       record_ &= ~(segmented_mask_);
0144   }
0145 
0146   inline void BlockAMCContent::setEnabled(bool enabled) {
0147     if (enabled)
0148       record_ |= enabled_mask_;
0149     else
0150       record_ &= ~(enabled_mask_);
0151   }
0152 
0153   inline void BlockAMCContent::setPresent(bool present) {
0154     if (present)
0155       record_ |= present_mask_;
0156     else
0157       record_ &= ~(present_mask_);
0158   }
0159 
0160   inline void BlockAMCContent::setValid(bool valid) {
0161     if (valid)
0162       record_ |= valid_mask_;
0163     else
0164       record_ &= ~(valid_mask_);
0165   }
0166 
0167   inline void BlockAMCContent::setCRCOk(bool crc_ok) {
0168     if (crc_ok)
0169       record_ |= crc_ok_mask_;
0170     else
0171       record_ &= ~(crc_ok_mask_);
0172   }
0173 
0174   inline void BlockAMCContent::setSize(unsigned int size) {
0175     record_ &= ~size_mask_;
0176     record_ |= (((std::uint64_t)(size) << size_offset_) & size_mask_);
0177   }
0178 
0179   inline void BlockAMCContent::setBlockNumber(unsigned int block_number) {
0180     record_ &= ~block_number_mask_;
0181     record_ |= (((std::uint64_t)(block_number) << block_number_offset_) & block_number_mask_);
0182   }
0183 
0184   inline void BlockAMCContent::setAMCNumber(unsigned int amc_number) {
0185     record_ &= ~amc_number_mask_;
0186     record_ |= (((std::uint64_t)(amc_number) << amc_number_offset_) & amc_number_mask_);
0187   }
0188 
0189   inline void BlockAMCContent::setBoardId(unsigned int board_id) {
0190     record_ &= ~board_id_mask_;
0191     record_ |= (((std::uint64_t)(board_id) << board_id_offset_) & board_id_mask_);
0192   }
0193 
0194   inline void TwinMuxHeader::set(unsigned int nword, std::uint64_t const word) {
0195     if (nword < 2)
0196       record_[nword] = word;
0197   }
0198 
0199   inline void TwinMuxHeader::reset() {
0200     record_[0] = 0x0;
0201     record_[1] = dt_bx_window_mask_ | rpc_bx_window_mask_ | ho_bx_window_mask_;
0202   }
0203 
0204   inline std::uint64_t const* TwinMuxHeader::getRecord() const { return record_; }
0205 
0206   inline unsigned int TwinMuxHeader::getAMCNumber() const {
0207     return (record_[0] & amc_number_mask_) >> amc_number_offset_;
0208   }
0209 
0210   inline unsigned int TwinMuxHeader::getEventCounter() const {
0211     return (record_[0] & event_counter_mask_) >> event_counter_offset_;
0212   }
0213 
0214   inline unsigned int TwinMuxHeader::getBXCounter() const {
0215     return (record_[0] & bx_counter_mask_) >> bx_counter_offset_;
0216   }
0217 
0218   inline unsigned int TwinMuxHeader::getDataLength() const {
0219     return (record_[0] & data_length_mask_) >> data_length_offset_;
0220   }
0221 
0222   inline unsigned int TwinMuxHeader::getOrbitCounter() const {
0223     return (record_[1] & orbit_counter_mask_) >> orbit_counter_offset_;
0224   }
0225 
0226   inline unsigned int TwinMuxHeader::getBoardId() const { return (record_[1] & board_id_mask_) >> board_id_offset_; }
0227 
0228   inline bool TwinMuxHeader::hasDTBXWindow() const { return (record_[1] & dt_bx_window_mask_) != dt_bx_window_mask_; }
0229 
0230   inline unsigned int TwinMuxHeader::getDTBXWindow() const {
0231     return (record_[1] & dt_bx_window_mask_) >> dt_bx_window_offset_;
0232   }
0233 
0234   inline bool TwinMuxHeader::hasRPCBXWindow() const {
0235     return (record_[1] & rpc_bx_window_mask_) != rpc_bx_window_mask_;
0236   }
0237 
0238   inline int TwinMuxHeader::getRPCBXMin() const {
0239     return -1 * int((record_[1] & rpc_bx_window_mask_) >> rpc_bx_window_offset_) / 5;
0240   }
0241 
0242   inline int TwinMuxHeader::getRPCBXMax() const {
0243     return int((record_[1] & rpc_bx_window_mask_) >> rpc_bx_window_offset_) % 5;
0244   }
0245 
0246   inline bool TwinMuxHeader::hasHOBXWindow() const { return (record_[1] & ho_bx_window_mask_) != ho_bx_window_mask_; }
0247 
0248   inline unsigned int TwinMuxHeader::getHOBXWindow() const {
0249     return (record_[1] & ho_bx_window_mask_) >> ho_bx_window_offset_;
0250   }
0251 
0252   inline void TwinMuxHeader::setAMCNumber(unsigned int amc_number) {
0253     record_[0] &= ~amc_number_mask_;
0254     record_[0] |= (((std::uint64_t)(amc_number) << amc_number_offset_) & amc_number_mask_);
0255   }
0256 
0257   inline void TwinMuxHeader::setEventCounter(unsigned int event_counter) {
0258     record_[0] &= ~event_counter_mask_;
0259     record_[0] |= (((std::uint64_t)(event_counter) << event_counter_offset_) & event_counter_mask_);
0260   }
0261 
0262   inline void TwinMuxHeader::setBXCounter(unsigned int bx_counter) {
0263     record_[0] &= ~bx_counter_mask_;
0264     record_[0] |= (((std::uint64_t)(bx_counter) << bx_counter_offset_) & bx_counter_mask_);
0265   }
0266 
0267   inline void TwinMuxHeader::setDataLength(unsigned int data_length) {
0268     record_[0] &= ~data_length_mask_;
0269     record_[0] |= (((std::uint64_t)(data_length) << data_length_offset_) & data_length_mask_);
0270   }
0271 
0272   inline void TwinMuxHeader::setOrbitCounter(unsigned int orbit_counter) {
0273     record_[1] &= ~orbit_counter_mask_;
0274     record_[1] |= (((std::uint64_t)(orbit_counter) << orbit_counter_offset_) & orbit_counter_mask_);
0275   }
0276 
0277   inline void TwinMuxHeader::setBoardId(unsigned int board_id) {
0278     record_[1] &= ~board_id_mask_;
0279     record_[1] |= (((std::uint64_t)(board_id) << board_id_offset_) & board_id_mask_);
0280   }
0281 
0282   inline void TwinMuxHeader::setDTBXWindow(unsigned int bx_window) {
0283     record_[1] &= ~dt_bx_window_mask_;
0284     record_[1] |= (((std::uint64_t)(bx_window) << dt_bx_window_offset_) & dt_bx_window_mask_);
0285   }
0286 
0287   inline void TwinMuxHeader::setRPCBXWindow(int bx_min, int bx_max) {
0288     std::uint64_t bx_window((bx_max - 4) + 5 * (bx_min - 4));
0289     record_[1] &= ~rpc_bx_window_mask_;
0290     record_[1] |= (((std::uint64_t)(bx_window) << rpc_bx_window_offset_) & rpc_bx_window_mask_);
0291   }
0292 
0293   inline void TwinMuxHeader::setHOBXWindow(unsigned int bx_window) {
0294     record_[1] &= ~ho_bx_window_mask_;
0295     record_[1] |= (((std::uint64_t)(bx_window) << ho_bx_window_offset_) & ho_bx_window_mask_);
0296   }
0297 
0298   inline void TwinMuxTrailer::set(std::uint64_t const record) { record_ = record; }
0299 
0300   inline void TwinMuxTrailer::reset() { record_ = 0x0; }
0301 
0302   inline std::uint64_t const& TwinMuxTrailer::getRecord() const { return record_; }
0303 
0304   inline std::uint32_t TwinMuxTrailer::getCRC() const { return (record_ & crc_mask_) >> crc_offset_; }
0305 
0306   inline unsigned int TwinMuxTrailer::getEventCounter() const {
0307     return (record_ & event_counter_mask_) >> event_counter_offset_;
0308   }
0309 
0310   inline unsigned int TwinMuxTrailer::getDataLength() const {
0311     return (record_ & data_length_mask_) >> data_length_offset_;
0312   }
0313 
0314   inline void TwinMuxTrailer::setCRC(std::uint32_t crc) {
0315     record_ &= ~crc_mask_;
0316     record_ |= (((std::uint64_t)(crc) << crc_offset_) & crc_mask_);
0317   }
0318 
0319   inline void TwinMuxTrailer::setEventCounter(unsigned int event_counter) {
0320     record_ &= ~event_counter_mask_;
0321     record_ |= (((std::uint64_t)(event_counter) << event_counter_offset_) & event_counter_mask_);
0322   }
0323 
0324   inline void TwinMuxTrailer::setDataLength(unsigned int data_length) {
0325     record_ &= ~data_length_mask_;
0326     record_ |= (((std::uint64_t)(data_length) << data_length_offset_) & data_length_mask_);
0327   }
0328 
0329   inline void RPCLinkRecord::set(std::uint32_t const record) { record_ = record; }
0330 
0331   inline void RPCLinkRecord::reset() { record_ = da_mask_; }
0332 
0333   inline std::uint32_t const& RPCLinkRecord::getRecord() const { return record_; }
0334 
0335   inline bool RPCLinkRecord::isAcknowledge() const { return ((record_ & da_mask_) ? true : false); }
0336 
0337   inline bool RPCLinkRecord::isError() const { return ((record_ & de_mask_) ? true : false); }
0338 
0339   inline bool RPCLinkRecord::isEOD() const { return ((record_ & eod_mask_) ? true : false); }
0340 
0341   inline unsigned int RPCLinkRecord::getDelay() const { return (record_ & delay_mask_) >> delay_offset_; }
0342 
0343   inline unsigned int RPCLinkRecord::getLinkBoard() const { return (record_ & link_board_mask_) >> link_board_offset_; }
0344 
0345   inline unsigned int RPCLinkRecord::getConnector() const { return (record_ & connector_mask_) >> connector_offset_; }
0346 
0347   inline unsigned int RPCLinkRecord::getPartition() const { return (record_ & partition_mask_) >> partition_offset_; }
0348 
0349   inline std::uint8_t RPCLinkRecord::getPartitionData() const {
0350     return (record_ & partition_data_mask_) >> partition_data_offset_;
0351   }
0352 
0353   inline void RPCLinkRecord::setAcknowledge(bool da) {
0354     if (da)
0355       record_ |= da_mask_;
0356     else
0357       record_ &= ~(da_mask_);
0358   }
0359 
0360   inline void RPCLinkRecord::setError(bool de) {
0361     if (de)
0362       record_ |= de_mask_;
0363     else
0364       record_ &= ~(de_mask_);
0365   }
0366 
0367   inline void RPCLinkRecord::setEOD(bool eod) {
0368     if (eod)
0369       record_ |= eod_mask_;
0370     else
0371       record_ &= ~(eod_mask_);
0372   }
0373 
0374   inline void RPCLinkRecord::setDelay(unsigned int delay) {
0375     record_ &= ~delay_mask_;
0376     record_ |= (((std::uint32_t)(delay) << delay_offset_) & delay_mask_);
0377   }
0378 
0379   inline void RPCLinkRecord::setLinkBoard(unsigned int link_board) {
0380     record_ &= ~link_board_mask_;
0381     record_ |= (((std::uint32_t)(link_board) << link_board_offset_) & link_board_mask_);
0382   }
0383 
0384   inline void RPCLinkRecord::setConnector(unsigned int connector) {
0385     record_ &= ~connector_mask_;
0386     record_ |= (((std::uint32_t)(connector) << connector_offset_) & connector_mask_);
0387   }
0388 
0389   inline void RPCLinkRecord::setPartition(unsigned int partition) {
0390     record_ &= ~partition_mask_;
0391     record_ |= (((std::uint32_t)(partition) << partition_offset_) & partition_mask_);
0392   }
0393 
0394   inline void RPCLinkRecord::setPartitionData(std::uint8_t data) {
0395     record_ &= ~partition_data_mask_;
0396     record_ |= (((std::uint32_t)(data) << partition_data_offset_) & partition_data_mask_);
0397   }
0398 
0399   inline void RPCBXRecord::set(std::uint8_t const record) { record_ = record; }
0400 
0401   inline void RPCBXRecord::reset() { record_ = 0x0; }
0402 
0403   inline std::uint8_t const& RPCBXRecord::getRecord() const { return record_; }
0404 
0405   inline bool RPCBXRecord::isBC0() const { return ((record_ & bc0_mask_) ? true : false); }
0406 
0407   inline unsigned int RPCBXRecord::getBXCounter() const { return (record_ & bcn_mask_) >> bcn_offset_; }
0408 
0409   inline void RPCBXRecord::setBC0(bool bc0) {
0410     if (bc0)
0411       record_ |= bc0_mask_;
0412     else
0413       record_ &= ~(bc0_mask_);
0414   }
0415 
0416   inline void RPCBXRecord::setBXCounter(unsigned int bcn) {
0417     record_ &= ~bcn_mask_;
0418     record_ |= (((std::uint8_t)(bcn) << bcn_offset_) & bcn_mask_);
0419   }
0420 
0421   inline void RPCRecord::set(unsigned int nword, std::uint64_t const word) {
0422     if (nword < 2)
0423       record_[nword] = word;
0424   }
0425 
0426   inline void RPCRecord::reset() {
0427     record_[0] = TwinMuxRecord::rpc_first_identifier_ |
0428                  ((std::uint64_t)RPCLinkRecord::da_mask_ << link_record_offset_[0]) |
0429                  ((std::uint64_t)RPCLinkRecord::da_mask_ << link_record_offset_[1]);
0430     record_[1] = TwinMuxRecord::rpc_second_identifier_ |
0431                  ((std::uint64_t)RPCLinkRecord::da_mask_ << link_record_offset_[2]) |
0432                  ((std::uint64_t)RPCLinkRecord::da_mask_ << link_record_offset_[3]) |
0433                  ((std::uint64_t)RPCLinkRecord::da_mask_ << link_record_offset_[4]);
0434   }
0435 
0436   inline std::uint64_t const* RPCRecord::getRecord() const { return record_; }
0437 
0438   inline int RPCRecord::getBXOffset() const { return -4 + (int)((record_[0] & bx_offset_mask_) >> bx_offset_offset_); }
0439 
0440   inline bool RPCRecord::hasOverflow() const { return ((record_[0] & overflow_mask_) ? true : false); }
0441 
0442   inline RPCBXRecord RPCRecord::getRPCBXRecord(unsigned int link) const {
0443     RPCBXRecord bx_record;
0444     if (link < 5) {
0445       bx_record.set((record_[0] >> bx_record_offset_[link]) & bx_record_mask_);
0446     }
0447     return bx_record;
0448   }
0449 
0450   inline RPCLinkRecord RPCRecord::getRPCLinkRecord(unsigned int link) const {
0451     RPCLinkRecord link_record;
0452     if (link < 5) {
0453       link_record.set((record_[link_record_word_[link]] >> link_record_offset_[link]) & link_record_mask_);
0454     }
0455     return link_record;
0456   }
0457 
0458   inline void RPCRecord::setBXOffset(int bx_offset) {
0459     record_[0] &= ~bx_offset_mask_;
0460     record_[0] |= (((std::uint64_t)(bx_offset + 4) << bx_offset_offset_) & bx_offset_mask_);
0461   }
0462 
0463   inline void RPCRecord::setOverflow(bool overflow) {
0464     if (overflow)
0465       record_[0] |= overflow_mask_;
0466     else
0467       record_[0] &= ~(overflow_mask_);
0468   }
0469 
0470   inline void RPCRecord::setRPCBXRecord(unsigned int link, RPCBXRecord const& bx_record) {
0471     if (link < 5) {
0472       record_[0] &= ~(bx_record_mask_ << bx_record_offset_[link]);
0473       record_[0] |= (((std::uint64_t)bx_record.getRecord() & bx_record_mask_) << bx_record_offset_[link]);
0474     }
0475   }
0476 
0477   inline void RPCRecord::setRPCLinkRecord(unsigned int link, RPCLinkRecord const& link_record) {
0478     if (link < 5) {
0479       record_[link_record_word_[link]] &= ~(link_record_mask_ << link_record_offset_[link]);
0480       record_[link_record_word_[link]] |=
0481           (((std::uint64_t)link_record.getRecord() & link_record_mask_) << link_record_offset_[link]);
0482     }
0483   }
0484 
0485 }  // namespace rpctwinmux
0486 
0487 #endif  // EventFilter_RPCRawToDigi_RPCTwinMuxRecord_icc