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  // std::cout << "Inside EMTFBlockRPC.cc: unpack" << std::endl;
66 
67  // Get the payload for this block, made up of 16-bit words (0xffff)
68  // Format defined in MTF7Payload::getBlock() in src/Block.cc
69  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
70  auto payload = block.payload();
71 
72  // Check Format of Payload
73  l1t::emtf::RPC RPC_;
74  for (int err = 0; err < checkFormat(block); err++) RPC_.add_format_error();
75 
76  // Assign payload to 16-bit words
77  uint16_t RPCa = payload[0];
78  uint16_t RPCb = payload[1];
79  uint16_t RPCc = payload[2];
80  uint16_t RPCd = payload[3];
81 
82  // res is a pointer to a collection of EMTFDaqOut class objects
83  // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
85  res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
86  int iOut = res->size() - 1;
87  if (RPC_.Format_Errors() > 0) goto write;
88 
90  // Unpack the RPC Data Record
92 
93  RPC_.set_partition_data ( GetHexBits(RPCa, 0, 7) );
94  RPC_.set_partition_num ( GetHexBits(RPCa, 8, 11) );
95  RPC_.set_prt_delay ( GetHexBits(RPCa, 12, 14) );
96 
97  RPC_.set_link_number ( GetHexBits(RPCb, 0, 4) );
98  RPC_.set_lb ( GetHexBits(RPCb, 5, 6) );
99  RPC_.set_eod ( GetHexBits(RPCb, 7, 7) );
100  RPC_.set_bcn ( GetHexBits(RPCb, 8, 14) );
101 
102  RPC_.set_bxn ( GetHexBits(RPCc, 0, 11) );
103  RPC_.set_bc0 ( GetHexBits(RPCc, 14, 14) );
104 
105  RPC_.set_tbin ( GetHexBits(RPCd, 0, 2) );
106 
107  // RPC_.set_dataword ( uint64_t dataword);
108 
109  write:
110 
111  (res->at(iOut)).push_RPC(RPC_);
112 
113  // Finished with unpacking one RPC Data Record
114  return true;
115 
116  } // End bool RPCBlockUnpacker::unpack
117 
118  // bool RPCBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
119  // std::cout << "Inside RPCBlockPacker::pack" << std::endl;
120  // return true;
121  // } // End bool RPCBlockPacker::pack
122 
123  } // End namespace emtf
124  } // End namespace stage2
125 } // End namespace l1t
126 
128 // DEFINE_L1T_PACKER(l1t::stage2::RPCBlockPacker);
void set_link_number(int bits)
Definition: RPC.h:33
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
void set_tbin(int bits)
Definition: RPC.h:35
int Format_Errors() const
Definition: RPC.h:51
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:130
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