test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EMTFBlockCounters.cc
Go to the documentation of this file.
1 #include <memory>
3 
4 #include "EMTFCollections.h"
5 #include "EMTFUnpackerTools.h"
6 #include "EMTFBlockCounters.h"
7 
8 namespace l1t {
9  namespace stage2 {
10  namespace emtf {
11 
13 
14  auto payload = block.payload();
15  int errors = 0;
16 
17  //Check the number of 16-bit words
18  if(payload.size() != 4) { errors += 1; edm::LogError("L1T|EMTF") << "Payload size in 'Block of Counters' is different than expected"; }
19 
20  //Check that each word is 16 bits
21  if(GetHexBits(payload[0], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[0] has more than 16 bits in 'Block of Counters'"; }
22  if(GetHexBits(payload[1], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[1] has more than 16 bits in 'Block of Counters'"; }
23  if(GetHexBits(payload[2], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[2] has more than 16 bits in 'Block of Counters'"; }
24  if(GetHexBits(payload[3], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'Block of Counters'"; }
25 
26  uint16_t BCa = payload[0];
27  uint16_t BCb = payload[1];
28  uint16_t BCc = payload[2];
29  uint16_t BCd = payload[3];
30 
31  //Check Format
32  if(GetHexBits(BCa, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in BCa are incorrect"; }
33  if(GetHexBits(BCb, 15, 15) != 1) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in BCb are incorrect"; }
34  if(GetHexBits(BCc, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in BCc are incorrect"; }
35  if(GetHexBits(BCd, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in BCd are incorrect"; }
36 
37  return errors;
38  }
39 
40 
42 
43  // std::cout << "Inside EMTFBlockCounters.cc: unpack" << std::endl;
44 
45  // Get the payload for this block, made up of 16-bit words (0xffff)
46  // Format defined in MTF7Payload::getBlock() in src/Block.cc
47  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
48  auto payload = block.payload();
49 
50  // Check Format of Payload
51  l1t::emtf::Counters Counters_;
52  for (int err = 0; err < checkFormat(block); err++) Counters_.add_format_error();
53 
54  // Assign payload to 16-bit words
55  uint16_t BCa = payload[0];
56  uint16_t BCb = payload[1];
57  uint16_t BCc = payload[2];
58  uint16_t BCd = payload[3];
59 
60  // res is a pointer to a collection of EMTFDaqOut class objects
61  // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
63  res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
64  int iOut = res->size() - 1;
65 
67  // Unpack the Block of Counters
69  if ( (res->at(iOut)).HasCounters() == true )
70  { (res->at(iOut)).add_format_error(); edm::LogError("L1T|EMTF") << "Why is there already a Counters object?"; goto write; }
71  if (Counters_.Format_Errors() > 0) goto write;
72 
73  Counters_.set_track_counter( GetHexBits(BCa, 0, 14, BCb, 0, 14) );
74  Counters_.set_orbit_counter( GetHexBits(BCc, 0, 14, BCd, 0, 14) );
75  // Counters_.set_rpc_counter( GetHexBits(payload[], , ) );
76  // Counters_.set_dataword(uint64_t bits) { dataword = bits; };
77 
78  write:
79  (res->at(iOut)).set_Counters(Counters_);
80 
81  // Finished with unpacking Counters
82  return true;
83 
84  } // End bool CountersBlockUnpacker::unpack
85 
86  // bool CountersBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
87  // std::cout << "Inside CountersBlockPacker::pack" << std::endl;
88  // return true;
89  // } // End bool CountersBlockPacker::pack
90 
91  } // End namespace emtf
92  } // End namespace stage2
93 } // End namespace l1t
94 
96 // DEFINE_L1T_PACKER(l1t::stage2::CountersBlockPacker);
virtual int checkFormat(const Block &block)
void set_track_counter(int bits)
Definition: Counters.h:26
int Format_Errors() const
Definition: Counters.h:35
std::vector< uint32_t > payload() const
Definition: Block.h:57
void add_format_error()
Definition: Counters.h:29
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:130
void set_orbit_counter(int bits)
Definition: Counters.h:27
virtual bool unpack(const Block &block, UnpackerCollections *coll) override
JetCorrectorParametersCollection coll
Definition: classes.h:10
#define DEFINE_L1T_UNPACKER(type)
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)