CMS 3D CMS Logo

ScBMTFRawToDigi.cc
Go to the documentation of this file.
2 
4  using namespace edm;
5  srcInputTag_ = iConfig.getParameter<InputTag>("srcInputTag");
6  sourceIdList_ = iConfig.getParameter<std::vector<int>>("sourceIdList");
7  debug_ = iConfig.getUntrackedParameter<bool>("debug", false);
8 
9  // initialize orbit buffer for BX 1->3564;
10  orbitBuffer_ = std::vector<std::vector<l1ScoutingRun3::BMTFStub>>(3565);
11  for (auto& bxVec : orbitBuffer_) {
12  bxVec.reserve(32);
13  }
14  nStubsOrbit_ = 0;
15 
16  produces<l1ScoutingRun3::BMTFStubOrbitCollection>().setBranchAlias("BMTFStubOrbitCollection");
17  rawToken_ = consumes<SDSRawDataCollection>(srcInputTag_);
18 }
19 
21 
23  using namespace edm;
24 
25  Handle<SDSRawDataCollection> ScoutingRawDataCollection;
26  iEvent.getByToken(rawToken_, ScoutingRawDataCollection);
27 
28  std::unique_ptr<l1ScoutingRun3::BMTFStubOrbitCollection> unpackedStubs(new l1ScoutingRun3::BMTFStubOrbitCollection);
29 
30  for (const auto& sdsId : sourceIdList_) {
31  if ((sdsId < SDSNumbering::BmtfMinSDSID) || (sdsId > SDSNumbering::BmtfMaxSDSID))
32  edm::LogError("ScBMTFRawToDigi::produce")
33  << "Provided a source ID outside the expected range: " << sdsId << ", expected range ["
35  const FEDRawData& sourceRawData = ScoutingRawDataCollection->FEDData(sdsId);
36  size_t orbitSize = sourceRawData.size();
37 
38  if ((sourceRawData.size() == 0) && debug_) {
39  std::cout << "No raw data for BMTF FED " << sdsId << std::endl;
40  }
41 
42  // unpack current orbit and store data into the orbitBufferr
43  unpackOrbit(sourceRawData.data(), orbitSize, sdsId);
44  }
45 
46  // fill orbit collection and clear the Bx buffer vector
47  unpackedStubs->fillAndClear(orbitBuffer_, nStubsOrbit_);
48 
49  // store collection in the event
50  iEvent.put(std::move(unpackedStubs));
51 }
52 
53 void ScBMTFRawToDigi::unpackOrbit(const unsigned char* buf, size_t len, int sdsId) {
54  using namespace l1ScoutingRun3;
55 
56  // reset counters
57  nStubsOrbit_ = 0;
58 
59  size_t pos = 0;
60 
61  while (pos < len) {
62  assert(pos + 4 <= len);
63 
64  bmtf::block* bl = (bmtf::block*)(buf + pos);
65 
66  unsigned bx = bl->bx;
67  unsigned orbit = (bl->orbit) & 0x7FFFFFFF;
68  unsigned sCount = (bl->header) & 0xff;
69 
70  size_t pos_increment = 12 + sCount * 8;
71 
72  assert(pos_increment <= len);
73 
74  pos += 12; // header
75 
76  if (debug_) {
77  std::cout << " BMTF #" << sdsId << " Orbit " << orbit << ", BX -> " << bx << ", nStubs -> " << sCount
78  << std::endl;
79  }
80 
81  // Unpack stubs for the current pair (BX, sector)
82  int32_t phi, phiB, tag, qual, eta, qeta, station, wheel, sector;
83 
84  // map for station and wheel, to find chambers with 2 stubs
85  std::vector<std::vector<bool>> stwh_matrix(4, std::vector<bool>(5, false));
86  for (unsigned int i = 0; i < sCount; i++) {
87  uint64_t stub_raw = *(uint64_t*)(buf + pos);
88  pos += 8;
89 
91  phiB = ((stub_raw >> bmtf::shiftsStubs::phiB) & bmtf::masksStubs::phiB);
94  qeta = ((stub_raw >> bmtf::shiftsStubs::qeta) & bmtf::masksStubs::qeta);
98 
99  if (stwh_matrix[station - 1][wheel + 2] == false) {
100  tag = 1;
101  } else {
102  tag = 0;
103  }
104  stwh_matrix[station - 1][wheel + 2] = true;
105 
106  phi = phi >= 2048 ? phi - 4096 : phi;
107  phiB = phiB >= 512 ? phiB - 1024 : phiB;
108  wheel = wheel >= 4 ? wheel - 8 : wheel;
109 
110  BMTFStub stub(phi, phiB, qual, eta, qeta, station, wheel, sector, tag);
111  orbitBuffer_[bx].push_back(stub);
112  nStubsOrbit_++;
113 
114  if (debug_) {
115  std::cout << "Stub " << i << ", raw: 0x" << std::hex << stub_raw << std::dec << std::endl;
116  std::cout << "\tPhi: " << phi << std::endl;
117  std::cout << "\tPhiB: " << phiB << std::endl;
118  std::cout << "\tQuality: " << qual << std::endl;
119  std::cout << "\tEta: " << eta << std::endl;
120  std::cout << "\tQEta: " << qeta << std::endl;
121  std::cout << "\tStation: " << station << std::endl;
122  std::cout << "\tWheel: " << wheel << std::endl;
123  std::cout << "\tSector: " << sector << std::endl;
124  std::cout << "\tTag: " << tag << std::endl;
125  }
126  }
127 
128  } // end orbit while loop
129 }
130 
133  desc.setUnknown();
134  descriptions.addDefault(desc);
135 }
136 
static constexpr int BmtfMinSDSID
Definition: SDSNumbering.h:20
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const FEDRawData & FEDData(int sourceId) const
~ScBMTFRawToDigi() override
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:48
void unpackOrbit(const unsigned char *buf, size_t len, int sdsId)
Log< level::Error, false > LogError
assert(be >=bs)
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< std::vector< l1ScoutingRun3::BMTFStub > > orbitBuffer_
static constexpr int BmtfMaxSDSID
Definition: SDSNumbering.h:21
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::InputTag srcInputTag_
unsigned long long uint64_t
Definition: Time.h:13
edm::EDGetToken rawToken_
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
std::vector< int > sourceIdList_
ScBMTFRawToDigi(const edm::ParameterSet &)
def move(src, dest)
Definition: eostools.py:511