Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:58

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