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