CMS 3D CMS Logo

DTC.cc
Go to the documentation of this file.
2 
3 #include <vector>
4 #include <iterator>
5 #include <algorithm>
6 #include <numeric>
7 
8 using namespace std;
9 using namespace edm;
10 using namespace tt;
11 
12 namespace trackerDTC {
13 
14  DTC::DTC(const ParameterSet& iConfig,
15  const Setup* setup,
16  const LayerEncoding* layerEncoding,
17  int dtcId,
18  const std::vector<std::vector<TTStubRef>>& stubsDTC)
19  : setup_(setup),
20  enableTruncation_(iConfig.getParameter<bool>("EnableTruncation")),
21  region_(dtcId / setup->numDTCsPerRegion()),
22  board_(dtcId % setup->numDTCsPerRegion()),
23  modules_(setup->dtcModules(dtcId)),
24  input_(setup->dtcNumRoutingBlocks(), Stubss(setup->dtcNumModulesPerRoutingBlock())),
25  lost_(setup->numOverlappingRegions()) {
26  // count number of stubs on this dtc
27  auto acc = [](int& sum, const vector<TTStubRef>& stubsModule) { return sum += stubsModule.size(); };
28  const int nStubs = accumulate(stubsDTC.begin(), stubsDTC.end(), 0, acc);
29  stubs_.reserve(nStubs);
30  // convert and assign Stubs to DTC routing block channel
31  for (int modId = 0; modId < setup->numModulesPerDTC(); modId++) {
32  const vector<TTStubRef>& ttStubRefs = stubsDTC[modId];
33  if (ttStubRefs.empty())
34  continue;
35  // Module which produced this ttStubRefs
36  SensorModule* module = modules_.at(modId);
37  // DTC routing block id [0-1]
38  const int blockId = modId / setup->dtcNumModulesPerRoutingBlock();
39  // DTC routing blockc channel id [0-35]
40  const int channelId = modId % setup->dtcNumModulesPerRoutingBlock();
41  // convert TTStubs and fill input channel
42  Stubs& stubs = input_[blockId][channelId];
43  for (const TTStubRef& ttStubRef : ttStubRefs) {
44  stubs_.emplace_back(iConfig, setup, layerEncoding, module, ttStubRef);
45  Stub& stub = stubs_.back();
46  if (stub.valid())
47  // passed pt and eta cut
48  stubs.push_back(&stub);
49  }
50  // sort stubs by bend
51  sort(stubs.begin(), stubs.end(), [](Stub* lhs, Stub* rhs) { return abs(lhs->bend()) < abs(rhs->bend()); });
52  // truncate stubs if desired
53  if (!enableTruncation_ || (int)stubs.size() <= setup->numFramesFE())
54  continue;
55  // begin of truncated stubs
56  const auto limit = next(stubs.begin(), setup->numFramesFE());
57  // copy truncated stubs into lost output channel
58  for (int region = 0; region < setup->numOverlappingRegions(); region++)
59  copy_if(
60  limit, stubs.end(), back_inserter(lost_[region]), [region](Stub* stub) { return stub->inRegion(region); });
61  // remove truncated stubs form input channel
62  stubs.erase(limit, stubs.end());
63  }
64  }
65 
66  // board level routing in two steps and products filling
67  void DTC::produce(TTDTC& productAccepted, TTDTC& productLost) {
68  // router step 1: merges stubs of all modules connected to one routing block into one stream
69  Stubs lost;
70  Stubss blockStubs(setup_->dtcNumRoutingBlocks());
71  for (int routingBlock = 0; routingBlock < setup_->dtcNumRoutingBlocks(); routingBlock++)
72  merge(input_[routingBlock], blockStubs[routingBlock], lost);
73  // copy lost stubs during merge into lost output channel
74  for (int region = 0; region < setup_->numOverlappingRegions(); region++) {
75  auto inRegion = [region](Stub* stub) { return stub->inRegion(region); };
76  copy_if(lost.begin(), lost.end(), back_inserter(lost_[region]), inRegion);
77  }
78  // router step 2: merges stubs of all routing blocks and splits stubs into one stream per overlapping region
79  Stubss regionStubs(setup_->numOverlappingRegions());
80  split(blockStubs, regionStubs);
81  // fill products
82  produce(regionStubs, productAccepted);
83  produce(lost_, productLost);
84  }
85 
86  // router step 1: merges stubs of all modules connected to one routing block into one stream
88  // for each input one fifo
89  Stubss stacks(inputs.size());
90  // clock accurate firmware emulation, each while trip describes one clock tick
91  while (!all_of(inputs.begin(), inputs.end(), [](const Stubs& channel) { return channel.empty(); }) or
92  !all_of(stacks.begin(), stacks.end(), [](const Stubs& channel) { return channel.empty(); })) {
93  // fill fifos
94  for (int iInput = 0; iInput < (int)inputs.size(); iInput++) {
95  Stubs& input = inputs[iInput];
96  Stubs& stack = stacks[iInput];
97  if (input.empty())
98  continue;
99  Stub* stub = pop_front(input);
100  if (stub) {
101  if (enableTruncation_ && (int)stack.size() == setup_->dtcDepthMemory() - 1)
102  // kill current first stub when fifo overflows
103  lost.push_back(pop_front(stack));
104  stack.push_back(stub);
105  }
106  }
107  // route stub from a fifo to output if possible
108  bool nothingToRoute(true);
109  for (int iInput = inputs.size() - 1; iInput >= 0; iInput--) {
110  Stubs& stack = stacks[iInput];
111  if (stack.empty())
112  continue;
113  nothingToRoute = false;
114  output.push_back(pop_front(stack));
115  // only one stub can be routed to output per clock tick
116  break;
117  }
118  // each clock tick output will grow by one, if no stub is available then by a gap
119  if (nothingToRoute)
120  output.push_back(nullptr);
121  }
122  // truncate if desired
123  if (enableTruncation_ && (int)output.size() > setup_->numFramesIO()) {
124  const auto limit = next(output.begin(), setup_->numFramesIO());
125  copy_if(limit, output.end(), back_inserter(lost), [](Stub* stub) { return stub; });
126  output.erase(limit, output.end());
127  }
128  // remove all gaps between end and last stub
129  for (auto it = output.end(); it != output.begin();)
130  it = (*--it) ? output.begin() : output.erase(it);
131  }
132 
133  // router step 2: merges stubs of all routing blocks and splits stubs into one stream per overlapping region
135  int region(0);
136  auto regionMask = [&region](Stub* stub) { return stub && stub->inRegion(region) ? stub : nullptr; };
137  for (Stubs& output : outputs) {
138  // copy of masked inputs for each output
139  Stubss streams(inputs.size());
140  int i(0);
141  for (Stubs& input : inputs) {
142  Stubs& stream = streams[i++];
143  transform(input.begin(), input.end(), back_inserter(stream), regionMask);
144  for (auto it = stream.end(); it != stream.begin();)
145  it = (*--it) ? stream.begin() : stream.erase(it);
146  }
148  }
149  }
150 
151  // conversion from Stubss to TTDTC
152  void DTC::produce(const Stubss& stubss, TTDTC& product) {
153  int channel(0);
154  auto toFrame = [&channel](Stub* stub) {
155  return stub ? make_pair(stub->ttStubRef(), stub->frame(channel)) : FrameStub();
156  };
157  for (const Stubs& stubs : stubss) {
159  stream.reserve(stubs.size());
160  transform(stubs.begin(), stubs.end(), back_inserter(stream), toFrame);
161  product.setStream(region_, board_, channel++, stream);
162  }
163  }
164 
165  // pop_front function which additionally returns copy of deleted front
167  Stub* stub = deque.front();
168  deque.pop_front();
169  return stub;
170  }
171 
172 } // namespace trackerDTC
void setStream(int dtcRegion, int dtcBoard, int dtcChannel, const tt::StreamStub &stream)
Definition: TTDTC.cc:24
std::pair< TTStubRef, Frame > FrameStub
Definition: TTTypes.h:60
void produce(TTDTC &accepted, TTDTC &lost)
Definition: DTC.cc:67
Class to process and provide run-time constants used by Track Trigger emulators.
Definition: Setup.h:44
int dtcDepthMemory() const
Definition: Setup.h:357
std::vector< FrameStub > StreamStub
Definition: TTTypes.h:63
void split(Stubss &inputs, Stubss &outputs)
Definition: DTC.cc:134
bool valid() const
Definition: Stub.h:26
std::vector< Stub > stubs_
Definition: DTC.h:56
std::vector< Stubs > Stubss
Definition: DTC.h:22
Stub * pop_front(Stubs &stubs)
Definition: DTC.cc:166
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
bool enableTruncation_
Definition: DTC.h:48
static std::string const input
Definition: EdmProvDump.cc:50
Class to represent an outer tracker Stub.
Definition: Stub.h:18
Definition: TTTypes.h:54
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
Stubss lost_
Definition: DTC.h:60
stack
Definition: svgfig.py:559
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int region_
Definition: DTC.h:50
const tt::Setup * setup_
Definition: DTC.h:46
uint8_t channelId(const VFATFrame &frame)
retrieve this channel identifier
Class to store hardware like structured TTStub Collection used by Track Trigger emulators.
Definition: TTDTC.h:17
Class to encode layer ids used between DTC and TFP in Hybrid.
Definition: LayerEncoding.h:19
Definition: DTC.h:12
HLT enums.
Stubsss input_
Definition: DTC.h:58
int numOverlappingRegions() const
Definition: Setup.h:347
int dtcNumRoutingBlocks() const
Definition: Setup.h:355
Definition: output.py:1
int bend() const
Definition: Stub.h:28
int board_
Definition: DTC.h:52
std::vector< tt::SensorModule * > modules_
Definition: DTC.h:54
void merge(Stubss &inputs, Stubs &output, Stubs &lost)
Definition: DTC.cc:87
int numFramesIO() const
Definition: Setup.h:157
std::deque< Stub * > Stubs
Definition: DTC.h:21
unsigned transform(const HcalDetId &id, unsigned transformCode)