CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EMTFBlockRPC.cc
Go to the documentation of this file.
1 // Code to unpack the "RPC Data Record"
2 
4 #include "EMTFCollections.h"
5 #include "EMTFUnpackerTools.h"
6 
7 // This is the "header" - no EMTFBlockRPC.h file is needed
8 namespace l1t {
9  namespace stage2 {
10  namespace emtf {
11 
12  class RPCBlockUnpacker : public Unpacker { // "RPCBlockUnpacker" inherits from "Unpacker"
13  public:
14  virtual int checkFormat(const Block& block);
15  // virtual bool checkFormat() override; // Return "false" if block format does not match expected format
16  virtual bool unpack(const Block& block, UnpackerCollections *coll) override; // Apparently it's always good to use override in C++
17  // virtual bool packBlock(const Block& block, UnpackerCollections *coll) override;
18  };
19 
20  // class RPCBlockPacker : public Packer { // "RPCBlockPacker" inherits from "Packer"
21  // public:
22  // virtual bool unpack(const Block& block, UnpackerCollections *coll) override; // Apparently it's always good to use override in C++
23  // };
24 
25  }
26  }
27 }
28 
29 namespace l1t {
30  namespace stage2 {
31  namespace emtf {
32 
34 
35  auto payload = block.payload();
36  int errors = 0;
37 
38  //Check the number of 16-bit words
39  if(payload.size() != 4) { errors += 1; edm::LogError("L1T|EMTF") << "Payload size in 'RPC Data Record' is different than expected"; }
40 
41  //Check that each word is 16 bits
42  if(GetHexBits(payload[0], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[0] has more than 16 bits in 'RPC Data Record'"; }
43  if(GetHexBits(payload[1], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[1] has more than 16 bits in 'RPC Data Record'"; }
44  if(GetHexBits(payload[2], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[2] has more than 16 bits in 'RPC Data Record'"; }
45  if(GetHexBits(payload[3], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'RPC Data Record'"; }
46 
47  uint16_t RPCa = payload[0];
48  uint16_t RPCb = payload[1];
49  uint16_t RPCc = payload[2];
50  uint16_t RPCd = payload[3];
51 
52  //Check Format
53  if(GetHexBits(RPCa, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in RPCa are incorrect"; }
54  if(GetHexBits(RPCb, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in RPCb are incorrect"; }
55  if(GetHexBits(RPCc, 12, 13) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in RPCc are incorrect"; }
56  if(GetHexBits(RPCc, 15, 15) != 1) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in RPCc are incorrect"; }
57  if(GetHexBits(RPCd, 3, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in RPCd are incorrect"; }
58 
59  return errors;
60 
61  }
62 
64 
65  // Get the payload for this block, made up of 16-bit words (0xffff)
66  // Format defined in MTF7Payload::getBlock() in src/Block.cc
67  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
68  auto payload = block.payload();
69 
70  // Check Format of Payload
71  l1t::emtf::RPC RPC_;
72  for (int err = 0; err < checkFormat(block); err++) RPC_.add_format_error();
73 
74  // Assign payload to 16-bit words
75  uint16_t RPCa = payload[0];
76  uint16_t RPCb = payload[1];
77  uint16_t RPCc = payload[2];
78  uint16_t RPCd = payload[3];
79 
80  // res is a pointer to a collection of EMTFOutput class objects
81  // There is one EMTFOutput for each MTF7 (60 deg. sector) in the event
83  res = static_cast<EMTFCollections*>(coll)->getEMTFOutputs();
84  int iOut = res->size() - 1;
85  if (RPC_.Format_Errors() > 0) goto write;
86 
88  // Unpack the RPC Data Record
90 
91  RPC_.set_partition_data ( GetHexBits(RPCa, 0, 7) );
92  RPC_.set_partition_num ( GetHexBits(RPCa, 8, 11) );
93  RPC_.set_prt_delay ( GetHexBits(RPCa, 12, 14) );
94 
95  RPC_.set_link_number ( GetHexBits(RPCb, 0, 4) );
96  RPC_.set_lb ( GetHexBits(RPCb, 5, 6) );
97  RPC_.set_eod ( GetHexBits(RPCb, 7, 7) );
98  RPC_.set_bcn ( GetHexBits(RPCb, 8, 14) );
99 
100  RPC_.set_bxn ( GetHexBits(RPCc, 0, 11) );
101  RPC_.set_bc0 ( GetHexBits(RPCc, 14, 14) );
102 
103  RPC_.set_tbin ( GetHexBits(RPCd, 0, 2) );
104 
105  // RPC_.set_dataword ( uint64_t dataword);
106 
107  write:
108 
109  (res->at(iOut)).push_RPC(RPC_);
110 
111  // Finished with unpacking one RPC Data Record
112  return true;
113 
114  } // End bool RPCBlockUnpacker::unpack
115 
116  // bool RPCBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
117  // std::cout << "Inside RPCBlockPacker::pack" << std::endl;
118  // return true;
119  // } // End bool RPCBlockPacker::pack
120 
121  } // End namespace emtf
122  } // End namespace stage2
123 } // End namespace l1t
124 
126 // DEFINE_L1T_PACKER(l1t::stage2::RPCBlockPacker);
void set_link_number(int bits)
Definition: RPC.h:33
const int Format_Errors() const
Definition: RPC.h:51
void set_partition_data(int bits)
Definition: RPC.h:30
void set_bcn(int bits)
Definition: RPC.h:31
void add_format_error()
Definition: RPC.h:38
void set_prt_delay(int bits)
Definition: RPC.h:28
void set_bxn(int bits)
Definition: RPC.h:34
virtual bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: EMTFBlockRPC.cc:63
std::vector< uint32_t > payload() const
Definition: Block.h:57
#define DEFINE_L1T_UNPACKER(type)
Definition: Unpacker.h:31
void set_eod(int bits)
Definition: RPC.h:36
void set_partition_num(int bits)
Definition: RPC.h:29
std::vector< EMTFOutput > EMTFOutputCollection
Definition: EMTFOutput.h:104
void set_tbin(int bits)
Definition: RPC.h:35
void set_bc0(int bits)
Definition: RPC.h:37
void set_lb(int bits)
Definition: RPC.h:32
JetCorrectorParametersCollection coll
Definition: classes.h:10
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)
virtual int checkFormat(const Block &block)
Definition: EMTFBlockRPC.cc:33