File indexing completed on 2025-08-12 02:28:50
0001 #ifndef DataFormats_L1Scouting_OrbitFlatTable_h
0002 #define DataFormats_L1Scouting_OrbitFlatTable_h
0003
0004
0005
0006
0007
0008 #include "DataFormats/NanoAOD/interface/FlatTable.h"
0009
0010 #include <cstdint>
0011 #include <vector>
0012 #include <string>
0013 #include <type_traits>
0014
0015 namespace l1ScoutingRun3 {
0016
0017 class OrbitFlatTable : public nanoaod::FlatTable {
0018 public:
0019 static constexpr unsigned int NBX = 3564;
0020
0021 OrbitFlatTable() : nanoaod::FlatTable(), bxOffsets_(orbitBufferSize_ + 1, 0) {}
0022
0023 OrbitFlatTable(std::vector<unsigned> bxOffsets,
0024 const std::string &name,
0025 bool singleton = false,
0026 bool extension = false)
0027 : nanoaod::FlatTable(bxOffsets.back(), name, singleton, extension), bxOffsets_(bxOffsets) {
0028 if (bxOffsets.size() != orbitBufferSize_ + 1) {
0029 throw cms::Exception("LogicError") << "Mismatch between bxOffsets.size() " << bxOffsets.size()
0030 << " and orbitBufferSize_ + 1" << (orbitBufferSize_ + 1);
0031 }
0032 }
0033
0034 ~OrbitFlatTable() {}
0035
0036 using FlatTable::nRows;
0037 using FlatTable::size;
0038
0039
0040 unsigned int nRows(unsigned bx) const {
0041 if (bx >= orbitBufferSize_)
0042 throwBadBx(bx);
0043 return bxOffsets_[bx + 1] - bxOffsets_[bx];
0044 };
0045 unsigned int size(unsigned bx) const { return nRows(bx); }
0046
0047
0048 template <typename T>
0049 auto columnData(unsigned int column) const {
0050 return nanoaod::FlatTable::columnData<T>(column);
0051 }
0052
0053
0054 template <typename T>
0055 auto columnData(unsigned int column, unsigned bx) const {
0056 if (bx >= orbitBufferSize_)
0057 throwBadBx(bx);
0058 auto begin = beginData<T>(column);
0059 return std::span(begin + bxOffsets_[bx], begin + bxOffsets_[bx + 1]);
0060 }
0061
0062
0063 template <typename T>
0064 auto columnData(unsigned int column) {
0065 return nanoaod::FlatTable::columnData<T>(column);
0066 }
0067
0068
0069 template <typename T>
0070 auto columnData(unsigned int column, unsigned bx) {
0071 if (bx >= orbitBufferSize_)
0072 throwBadBx(bx);
0073 auto begin = beginData<T>(column);
0074 return std::span(begin + bxOffsets_[bx], begin + bxOffsets_[bx + 1]);
0075 }
0076
0077
0078 template <typename T>
0079 const auto &columValue(unsigned int column, unsigned bx) const {
0080 if (!singleton())
0081 throw cms::Exception("LogicError", "columnValue works only for singleton tables");
0082 if (bx >= orbitBufferSize_ || bxOffsets_[bx + 1] == bxOffsets_[bx])
0083 throwBadBx(bx);
0084 auto begin = beginData<T>(column);
0085 return *(begin + bxOffsets_[bx]);
0086 }
0087
0088 private:
0089 std::vector<unsigned> bxOffsets_;
0090
0091
0092
0093 static constexpr int orbitBufferSize_ = NBX + 1;
0094
0095 [[noreturn]] void throwBadBx(unsigned bx) const {
0096 throw cms::Exception("OrbitFlatTable") << "Trying to access bad bx " << bx;
0097 }
0098 };
0099
0100 }
0101
0102 #endif