CMS 3D CMS Logo

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