CMS 3D CMS Logo

TTDTC.cc
Go to the documentation of this file.
3 
4 #include <numeric>
5 
6 using namespace std;
7 using namespace edm;
8 using namespace tt;
9 
10 TTDTC::TTDTC(int numRegions, int numOverlappingRegions, int numDTCsPerRegion)
11  : numRegions_(numRegions),
12  numOverlappingRegions_(numOverlappingRegions),
13  numDTCsPerRegion_(numDTCsPerRegion),
14  numDTCsPerTFP_(numOverlappingRegions * numDTCsPerRegion),
15  regions_(numRegions_),
16  channels_(numDTCsPerTFP_),
17  streams_(numRegions_ * numDTCsPerTFP_) {
18  iota(regions_.begin(), regions_.end(), 0);
19  iota(channels_.begin(), channels_.end(), 0);
20 }
21 
22 // write one specific stream of TTStubRefs using DTC identifier (region[0-8], board[0-23], channel[0-1])
23 // dtcRegions aka detector regions are defined by tk layout
24 void TTDTC::setStream(int dtcRegion, int dtcBoard, int dtcChannel, const StreamStub& stream) {
25  // check arguments
26  const bool oorRegion = dtcRegion >= numRegions_ || dtcRegion < 0;
27  const bool oorBoard = dtcBoard >= numDTCsPerRegion_ || dtcBoard < 0;
28  const bool oorChannel = dtcChannel >= numOverlappingRegions_ || dtcChannel < 0;
29  if (oorRegion || oorBoard || oorChannel) {
30  cms::Exception exception("out_of_range");
31  exception.addContext("TTDTC::setStream");
32  if (oorRegion)
33  exception << "Requested Detector Region "
34  << "(" << dtcRegion << ") is out of range 0 to " << numRegions_ - 1 << ".";
35  if (oorBoard)
36  exception << "Requested DTC Board "
37  << "(" << dtcBoard << ") is out of range 0 to " << numDTCsPerRegion_ - 1 << ".";
38  if (oorChannel)
39  exception << "Requested DTC Channel "
40  << "(" << dtcChannel << ") is out of range 0 to " << numOverlappingRegions_ - 1 << ".";
41  throw exception;
42  }
43  streams_[index(dtcRegion, dtcBoard, dtcChannel)] = stream;
44 }
45 
46 // read one specific stream of TTStubRefs using TFP identifier (region[0-8], channel[0-47])
47 // tfpRegions aka processing regions are rotated by -0.5 region width w.r.t detector regions
48 const StreamStub& TTDTC::stream(int tfpRegion, int tfpChannel) const {
49  // check arguments
50  const bool oorRegion = tfpRegion >= numRegions_ || tfpRegion < 0;
51  const bool oorChannel = tfpChannel >= numDTCsPerTFP_ || tfpChannel < 0;
52  if (oorRegion || oorChannel) {
53  cms::Exception exception("out_of_range");
54  exception.addContext("TTDTC::stream");
55  if (oorRegion)
56  exception << "Requested Processing Region "
57  << "(" << tfpRegion << ") is out of range 0 to " << numRegions_ - 1 << ".";
58  if (oorChannel)
59  exception << "Requested TFP Channel "
60  << "(" << tfpChannel << ") is out of range 0 to " << numDTCsPerTFP_ - 1 << ".";
61  throw exception;
62  }
63  return streams_.at(index(tfpRegion, tfpChannel));
64 }
65 
66 // total number of frames
67 int TTDTC::size() const {
68  auto all = [](int sum, const StreamStub& stream) { return sum + stream.size(); };
69  return accumulate(streams_.begin(), streams_.end(), 0, all);
70 }
71 
72 // total number of stubs
73 int TTDTC::nStubs() const {
74  auto stubs = [](int sum, const FrameStub& frame) { return sum + frame.first.isNonnull(); };
75  int n(0);
76  for (const StreamStub& stream : streams_)
77  n += accumulate(stream.begin(), stream.end(), 0, stubs);
78  return n;
79 }
80 
81 // total number of gaps
82 int TTDTC::nGaps() const {
83  auto gaps = [](int sum, const FrameStub& frame) { return sum + frame.first.isNull(); };
84  int n(0);
85  for (const StreamStub& stream : streams_)
86  n += accumulate(stream.begin(), stream.end(), 0, gaps);
87  return n;
88 }
89 
90 // converts DTC identifier (region[0-8], board[0-23], channel[0-1]) into streams_ index [0-431]
91 int TTDTC::index(int dtcRegion, int dtcBoard, int dtcChannel) const {
92  return (dtcRegion * numDTCsPerRegion_ + dtcBoard) * numOverlappingRegions_ + dtcChannel;
93 }
94 
95 // converts TFP identifier (region[0-8], channel[0-47]) into streams_ index [0-431]
96 int TTDTC::index(int tfpRegion, int tfpChannel) const {
97  const int dtcChannel = numOverlappingRegions_ - (tfpChannel / numDTCsPerRegion_) - 1;
98  const int dtcBoard = tfpChannel % numDTCsPerRegion_;
99  const int dtcRegion = tfpRegion - dtcChannel >= 0 ? tfpRegion - dtcChannel : tfpRegion - dtcChannel + numRegions_;
100  return index(dtcRegion, dtcBoard, dtcChannel);
101 }
void setStream(int dtcRegion, int dtcBoard, int dtcChannel, const tt::StreamStub &stream)
Definition: TTDTC.cc:24
int nGaps() const
Definition: TTDTC.cc:82
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
std::vector< int > regions_
Definition: TTDTC.h:54
std::pair< TTStubRef, Frame > FrameStub
Definition: TTTypes.h:60
std::vector< FrameStub > StreamStub
Definition: TTTypes.h:63
std::vector< int > channels_
Definition: TTDTC.h:56
int numOverlappingRegions_
Definition: TTDTC.h:48
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
int numDTCsPerRegion_
Definition: TTDTC.h:50
Definition: TTTypes.h:54
int numRegions_
Definition: TTDTC.h:46
tt::StreamsStub streams_
Definition: TTDTC.h:58
HLT enums.
int index(int dtcRegion, int dtcBoard, int dtcChannel) const
Definition: TTDTC.cc:91
TTDTC()
Definition: TTDTC.h:19
int size() const
Definition: TTDTC.cc:67
const tt::StreamStub & stream(int tfpRegion, int tfpChannel) const
Definition: TTDTC.cc:48
int numDTCsPerTFP_
Definition: TTDTC.h:52
int nStubs() const
Definition: TTDTC.cc:73