Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:37

0001 #include "DataFormats/L1TrackTrigger/interface/TTDTC.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 
0004 #include <numeric>
0005 
0006 using namespace std;
0007 using namespace edm;
0008 using namespace tt;
0009 
0010 TTDTC::TTDTC(int numRegions, int numOverlappingRegions, int numDTCsPerRegion)
0011     : numRegions_(numRegions),
0012       numOverlappingRegions_(numOverlappingRegions),
0013       numDTCsPerRegion_(numDTCsPerRegion),
0014       numDTCsPerTFP_(numOverlappingRegions * numDTCsPerRegion),
0015       regions_(numRegions_),
0016       channels_(numDTCsPerTFP_),
0017       streams_(numRegions_ * numDTCsPerTFP_) {
0018   iota(regions_.begin(), regions_.end(), 0);
0019   iota(channels_.begin(), channels_.end(), 0);
0020 }
0021 
0022 // write one specific stream of TTStubRefs using DTC identifier (region[0-8], board[0-23], channel[0-1])
0023 // dtcRegions aka detector regions are defined by tk layout
0024 void TTDTC::setStream(int dtcRegion, int dtcBoard, int dtcChannel, const StreamStub& stream) {
0025   // check arguments
0026   const bool oorRegion = dtcRegion >= numRegions_ || dtcRegion < 0;
0027   const bool oorBoard = dtcBoard >= numDTCsPerRegion_ || dtcBoard < 0;
0028   const bool oorChannel = dtcChannel >= numOverlappingRegions_ || dtcChannel < 0;
0029   if (oorRegion || oorBoard || oorChannel) {
0030     cms::Exception exception("out_of_range");
0031     exception.addContext("TTDTC::setStream");
0032     if (oorRegion)
0033       exception << "Requested Detector Region "
0034                 << "(" << dtcRegion << ") is out of range 0 to " << numRegions_ - 1 << ".";
0035     if (oorBoard)
0036       exception << "Requested DTC Board "
0037                 << "(" << dtcBoard << ") is out of range 0 to " << numDTCsPerRegion_ - 1 << ".";
0038     if (oorChannel)
0039       exception << "Requested DTC Channel "
0040                 << "(" << dtcChannel << ") is out of range 0 to " << numOverlappingRegions_ - 1 << ".";
0041     throw exception;
0042   }
0043   streams_[index(dtcRegion, dtcBoard, dtcChannel)] = stream;
0044 }
0045 
0046 // read one specific stream of TTStubRefs using TFP identifier (region[0-8], channel[0-47])
0047 // tfpRegions aka processing regions are rotated by -0.5 region width w.r.t detector regions
0048 const StreamStub& TTDTC::stream(int tfpRegion, int tfpChannel) const {
0049   // check arguments
0050   const bool oorRegion = tfpRegion >= numRegions_ || tfpRegion < 0;
0051   const bool oorChannel = tfpChannel >= numDTCsPerTFP_ || tfpChannel < 0;
0052   if (oorRegion || oorChannel) {
0053     cms::Exception exception("out_of_range");
0054     exception.addContext("TTDTC::stream");
0055     if (oorRegion)
0056       exception << "Requested Processing Region "
0057                 << "(" << tfpRegion << ") is out of range 0 to " << numRegions_ - 1 << ".";
0058     if (oorChannel)
0059       exception << "Requested TFP Channel "
0060                 << "(" << tfpChannel << ") is out of range 0 to " << numDTCsPerTFP_ - 1 << ".";
0061     throw exception;
0062   }
0063   return streams_.at(index(tfpRegion, tfpChannel));
0064 }
0065 
0066 // total number of frames
0067 int TTDTC::size() const {
0068   auto all = [](int sum, const StreamStub& stream) { return sum + stream.size(); };
0069   return accumulate(streams_.begin(), streams_.end(), 0, all);
0070 }
0071 
0072 // total number of stubs
0073 int TTDTC::nStubs() const {
0074   auto stubs = [](int sum, const FrameStub& frame) { return sum + frame.first.isNonnull(); };
0075   int n(0);
0076   for (const StreamStub& stream : streams_)
0077     n += accumulate(stream.begin(), stream.end(), 0, stubs);
0078   return n;
0079 }
0080 
0081 // total number of gaps
0082 int TTDTC::nGaps() const {
0083   auto gaps = [](int sum, const FrameStub& frame) { return sum + frame.first.isNull(); };
0084   int n(0);
0085   for (const StreamStub& stream : streams_)
0086     n += accumulate(stream.begin(), stream.end(), 0, gaps);
0087   return n;
0088 }
0089 
0090 // converts DTC identifier (region[0-8], board[0-23], channel[0-1]) into streams_ index [0-431]
0091 int TTDTC::index(int dtcRegion, int dtcBoard, int dtcChannel) const {
0092   return (dtcRegion * numDTCsPerRegion_ + dtcBoard) * numOverlappingRegions_ + dtcChannel;
0093 }
0094 
0095 // converts TFP identifier (region[0-8], channel[0-47]) into streams_ index [0-431]
0096 int TTDTC::index(int tfpRegion, int tfpChannel) const {
0097   const int dtcChannel = numOverlappingRegions_ - (tfpChannel / numDTCsPerRegion_) - 1;
0098   const int dtcBoard = tfpChannel % numDTCsPerRegion_;
0099   const int dtcRegion = tfpRegion - dtcChannel >= 0 ? tfpRegion - dtcChannel : tfpRegion - dtcChannel + numRegions_;
0100   return index(dtcRegion, dtcBoard, dtcChannel);
0101 }