File indexing completed on 2025-06-03 00:11:52
0001 #include "DataFormats/L1TrackTrigger/interface/TTDTC.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003
0004 #include <numeric>
0005
0006 TTDTC::TTDTC(int numRegions, int numOverlappingRegions, int numDTCsPerRegion)
0007 : numRegions_(numRegions),
0008 numOverlappingRegions_(numOverlappingRegions),
0009 numDTCsPerRegion_(numDTCsPerRegion),
0010 numDTCsPerTFP_(numOverlappingRegions * numDTCsPerRegion),
0011 regions_(numRegions_),
0012 channels_(numDTCsPerTFP_),
0013 streams_(numRegions_ * numDTCsPerTFP_) {
0014 std::iota(regions_.begin(), regions_.end(), 0);
0015 std::iota(channels_.begin(), channels_.end(), 0);
0016 }
0017
0018
0019
0020 void TTDTC::setStream(int dtcRegion, int dtcBoard, int dtcChannel, const tt::StreamStub& stream) {
0021
0022 const bool oorRegion = dtcRegion >= numRegions_ || dtcRegion < 0;
0023 const bool oorBoard = dtcBoard >= numDTCsPerRegion_ || dtcBoard < 0;
0024 const bool oorChannel = dtcChannel >= numOverlappingRegions_ || dtcChannel < 0;
0025 if (oorRegion || oorBoard || oorChannel) {
0026 cms::Exception exception("out_of_range");
0027 exception.addContext("TTDTC::setStream");
0028 if (oorRegion)
0029 exception << "Requested Detector Region "
0030 << "(" << dtcRegion << ") is out of range 0 to " << numRegions_ - 1 << ".";
0031 if (oorBoard)
0032 exception << "Requested DTC Board "
0033 << "(" << dtcBoard << ") is out of range 0 to " << numDTCsPerRegion_ - 1 << ".";
0034 if (oorChannel)
0035 exception << "Requested DTC Channel "
0036 << "(" << dtcChannel << ") is out of range 0 to " << numOverlappingRegions_ - 1 << ".";
0037 throw exception;
0038 }
0039 streams_[index(dtcRegion, dtcBoard, dtcChannel)] = stream;
0040 }
0041
0042
0043
0044 const tt::StreamStub& TTDTC::stream(int tfpRegion, int tfpChannel) const {
0045
0046 const bool oorRegion = tfpRegion >= numRegions_ || tfpRegion < 0;
0047 const bool oorChannel = tfpChannel >= numDTCsPerTFP_ || tfpChannel < 0;
0048 if (oorRegion || oorChannel) {
0049 cms::Exception exception("out_of_range");
0050 exception.addContext("TTDTC::stream");
0051 if (oorRegion)
0052 exception << "Requested Processing Region "
0053 << "(" << tfpRegion << ") is out of range 0 to " << numRegions_ - 1 << ".";
0054 if (oorChannel)
0055 exception << "Requested TFP Channel "
0056 << "(" << tfpChannel << ") is out of range 0 to " << numDTCsPerTFP_ - 1 << ".";
0057 throw exception;
0058 }
0059 return streams_.at(index(tfpRegion, tfpChannel));
0060 }
0061
0062
0063 int TTDTC::size() const {
0064 auto all = [](int sum, const tt::StreamStub& stream) { return sum + stream.size(); };
0065 return std::accumulate(streams_.begin(), streams_.end(), 0, all);
0066 }
0067
0068
0069 int TTDTC::nStubs() const {
0070 auto stubs = [](int sum, const tt::FrameStub& frame) { return sum + frame.first.isNonnull(); };
0071 int n(0);
0072 for (const tt::StreamStub& stream : streams_)
0073 n += std::accumulate(stream.begin(), stream.end(), 0, stubs);
0074 return n;
0075 }
0076
0077
0078 int TTDTC::nGaps() const {
0079 auto gaps = [](int sum, const tt::FrameStub& frame) { return sum + frame.first.isNull(); };
0080 int n(0);
0081 for (const tt::StreamStub& stream : streams_)
0082 n += std::accumulate(stream.begin(), stream.end(), 0, gaps);
0083 return n;
0084 }
0085
0086
0087 int TTDTC::index(int dtcRegion, int dtcBoard, int dtcChannel) const {
0088 return (dtcRegion * numDTCsPerRegion_ + dtcBoard) * numOverlappingRegions_ + dtcChannel;
0089 }
0090
0091
0092 int TTDTC::index(int tfpRegion, int tfpChannel) const {
0093 const int dtcChannel = numOverlappingRegions_ - (tfpChannel / numDTCsPerRegion_) - 1;
0094 const int dtcBoard = tfpChannel % numDTCsPerRegion_;
0095 const int dtcRegion = tfpRegion - dtcChannel >= 0 ? tfpRegion - dtcChannel : tfpRegion - dtcChannel + numRegions_;
0096 return index(dtcRegion, dtcBoard, dtcChannel);
0097 }