TrigCodes

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#ifndef DQMOFFLINE_TRIGGER_EGHLTTRIGCODES
#define DQMOFFLINE_TRIGGER_EGHLTTRIGCODES

//author: Sam Harper
//aim: to define the trigger bits we are interested in
//implimentation: likely to be more than 32 (or even 64 bits) so differs from CutCodes in the fact it stores the bit position, not the bit mask

#include <cstring>
#include <string>
#include <iostream>
#include <bitset>
#include <vector>
#include <algorithm>

//unforunately hard coded limit of 64 bits which needs to be checked when setting it up
//if this becomes a problem, will be replaced by boost::dynamic_bitset
//my appologies for the typedef, it was better this way

namespace egHLT {
  class TrigCodes {
  public:
    static const int maxNrBits_ = 128;
    using TrigBitSet = std::bitset<maxNrBits_>;

  private:
    //sorted vector
    std::vector<std::pair<std::string, TrigBitSet> > codeDefs_;

  public:
    static TrigCodes* makeCodes(std::vector<std::string>& filterNames);
    ~TrigCodes() = default;

    TrigCodes& operator=(const TrigCodes&) = delete;
    TrigCodes(const TrigCodes&) = delete;

    TrigBitSet getCode(const char* descript) const;
    TrigBitSet getCode(const std::string& descript) const { return getCode(descript.c_str()); }

  private:
    TrigCodes() = default;

    void getCodeName(TrigBitSet code, std::string& id) const;

    //modifiers
    void setCode(const char* descript, TrigBitSet code);
    void setCode(const char* descript, int bitNr);

    //key comp
    static bool keyComp(const std::pair<std::string, TrigBitSet>& lhs, const std::pair<std::string, TrigBitSet>& rhs);
    void sort() { std::sort(codeDefs_.begin(), codeDefs_.end(), keyComp); }
    size_t size() const { return codeDefs_.size(); }
    void printCodes();
  };
}  // namespace egHLT

#endif