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 // Code to unpack the "Block of Counters"
2 
4 #include "EMTFCollections.h"
5 #include "EMTFUnpackerTools.h"
6 
7 // This is the "header" - no EMTFBlockCounters.h file is needed
8 namespace l1t {
9  namespace stage2 {
10  namespace emtf {
11 
12  class CountersBlockUnpacker : public Unpacker { // "CountersBlockUnpacker" 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 CountersBlockPacker : public Packer { // "CountersBlockPacker" 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 'Block of Counters' 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 'Block of Counters'"; }
42  if(GetHexBits(payload[1], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[1] has more than 16 bits in 'Block of Counters'"; }
43  if(GetHexBits(payload[2], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[2] has more than 16 bits in 'Block of Counters'"; }
44  if(GetHexBits(payload[3], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'Block of Counters'"; }
45 
46  uint16_t BCa = payload[0];
47  uint16_t BCb = payload[1];
48  uint16_t BCc = payload[2];
49  uint16_t BCd = payload[3];
50 
51  //Check Format
52  if(GetHexBits(BCa, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in BCa are incorrect"; }
53  if(GetHexBits(BCb, 15, 15) != 1) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in BCb are incorrect"; }
54  if(GetHexBits(BCc, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in BCc are incorrect"; }
55  if(GetHexBits(BCd, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in BCd are incorrect"; }
56 
57  return errors;
58  }
59 
60 
62 
63  // Get the payload for this block, made up of 16-bit words (0xffff)
64  // Format defined in MTF7Payload::getBlock() in src/Block.cc
65  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
66  auto payload = block.payload();
67 
68  // Check Format of Payload
69  l1t::emtf::Counters Counters_;
70  for (int err = 0; err < checkFormat(block); err++) Counters_.add_format_error();
71 
72  // Assign payload to 16-bit words
73  uint16_t BCa = payload[0];
74  uint16_t BCb = payload[1];
75  uint16_t BCc = payload[2];
76  uint16_t BCd = payload[3];
77 
78  // res is a pointer to a collection of EMTFOutput class objects
79  // There is one EMTFOutput for each MTF7 (60 deg. sector) in the event
81  res = static_cast<EMTFCollections*>(coll)->getEMTFOutputs();
82  int iOut = res->size() - 1;
83 
85  // Unpack the Block of Counters
87  if ( (res->at(iOut)).HasCounters() == true )
88  { (res->at(iOut)).add_format_error(); edm::LogError("L1T|EMTF") << "Why is there already a Counters object?"; goto write; }
89  if (Counters_.Format_Errors() > 0) goto write;
90 
91  Counters_.set_track_counter( GetHexBits(BCa, 0, 14, BCb, 0, 14) );
92  Counters_.set_orbit_counter( GetHexBits(BCc, 0, 14, BCd, 0, 14) );
93  // Counters_.set_rpc_counter( GetHexBits(payload[], , ) );
94  // Counters_.set_dataword(uint64_t bits) { dataword = bits; };
95 
96  write:
97  (res->at(iOut)).set_Counters(Counters_);
98 
99  // Finished with unpacking Counters
100  return true;
101 
102  } // End bool CountersBlockUnpacker::unpack
103 
104  // bool CountersBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
105  // std::cout << "Inside CountersBlockPacker::pack" << std::endl;
106  // return true;
107  // } // End bool CountersBlockPacker::pack
108 
109  } // End namespace emtf
110  } // End namespace stage2
111 } // End namespace l1t
112 
114 // DEFINE_L1T_PACKER(l1t::stage2::CountersBlockPacker);
virtual int checkFormat(const Block &block)
void set_track_counter(int bits)
Definition: Counters.h:26
std::vector< uint32_t > payload() const
Definition: Block.h:57
#define DEFINE_L1T_UNPACKER(type)
Definition: Unpacker.h:31
void add_format_error()
Definition: Counters.h:29
const int Format_Errors() const
Definition: Counters.h:35
std::vector< EMTFOutput > EMTFOutputCollection
Definition: EMTFOutput.h:104
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
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)