Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CSCCommonTrigger_CSCTriggerContainer_h
0002 #define CSCCommonTrigger_CSCTriggerContainer_h
0003 
0004 /**
0005  * \class CSCTriggerContainer
0006  * \author L. Gray
0007  * 
0008  * A container class to make things more manageable for a Trigger Processor.
0009  * DigiCollections make per-BX processing complicated, this class makes it easier.
0010  * 
0011  * Any class T must have the following functions: // inherit from base class!
0012  * T(const T&)
0013  * operator=
0014  * station()
0015  * sector()
0016  * subsector()
0017  * BX()
0018  */
0019 
0020 #include <vector>
0021 
0022 template <class T>
0023 class CSCTriggerContainer {
0024 public:
0025   CSCTriggerContainer() {}
0026   CSCTriggerContainer(const CSCTriggerContainer& cpy) { _objs = cpy._objs; }
0027   CSCTriggerContainer(const std::vector<T>&);
0028 
0029   CSCTriggerContainer& operator=(const CSCTriggerContainer&);
0030   CSCTriggerContainer& operator=(const std::vector<T>&);
0031 
0032   std::vector<T> get() const;
0033   std::vector<T> get(const unsigned& endcap,
0034                      const unsigned& station,
0035                      const unsigned& tsector,
0036                      const unsigned& tsubsector,
0037                      const unsigned& cscid,
0038                      const int& BX) const;  /// For a specific chamber
0039                                             /// in a station.
0040   std::vector<T> get(const unsigned& endcap,
0041                      const unsigned& station,
0042                      const unsigned& tsector,  /// For a specific station in a sector.
0043                      const unsigned& tsubsector,
0044                      const int& BX) const;
0045   std::vector<T> get(const unsigned& endcap,
0046                      const unsigned& sector,
0047                      const int& BX) const;  /// For objects which span multiple stations.
0048   std::vector<T> get(const unsigned& endcap, const unsigned& sector) const;
0049   std::vector<T> get(const int& BX) const;
0050 
0051   void push_back(const T& data) { _objs.push_back(data); }
0052   void push_many(const std::vector<T>& data) { _objs.insert(_objs.end(), data.begin(), data.end()); }
0053   void push_many(const CSCTriggerContainer<T>& data) {
0054     std::vector<T> vec = data.get();
0055     _objs.insert(_objs.end(), vec.begin(), vec.end());
0056   }
0057   void clear() { _objs.clear(); }
0058 
0059 private:
0060   std::vector<T> _objs;
0061 };
0062 
0063 template <class T>
0064 CSCTriggerContainer<T>::CSCTriggerContainer(const std::vector<T>& parent) {
0065   _objs = parent;
0066 }
0067 
0068 template <class T>
0069 CSCTriggerContainer<T>& CSCTriggerContainer<T>::operator=(const CSCTriggerContainer& rhs) {
0070   if (this != &rhs) {
0071     _objs = rhs._objs;
0072   }
0073   return *this;
0074 }
0075 
0076 template <class T>
0077 CSCTriggerContainer<T>& CSCTriggerContainer<T>::operator=(const std::vector<T>& rhs) {
0078   _objs = rhs;
0079   return *this;
0080 }
0081 
0082 template <class T>
0083 std::vector<T> CSCTriggerContainer<T>::get() const {
0084   return _objs;
0085 }
0086 
0087 template <class T>
0088 std::vector<T> CSCTriggerContainer<T>::get(const unsigned& endcap,
0089                                            const unsigned& station,
0090                                            const unsigned& tsector,
0091                                            const unsigned& tsubsector,
0092                                            const unsigned& cscid,
0093                                            const int& BX) const {
0094   std::vector<T> result;
0095 
0096   for (unsigned i = 0; i < _objs.size(); i++)
0097     if (_objs[i].endcap() == endcap && _objs[i].station() == station && _objs[i].sector() == tsector &&
0098         (station != 1 || _objs[i].subsector() == tsubsector) && _objs[i].cscid() == cscid && _objs[i].BX() == BX)
0099       result.push_back(_objs[i]);
0100 
0101   return result;
0102 }
0103 
0104 template <class T>
0105 std::vector<T> CSCTriggerContainer<T>::get(const unsigned& endcap,
0106                                            const unsigned& station,
0107                                            const unsigned& tsector,
0108                                            const unsigned& tsubsector,
0109                                            const int& BX) const {
0110   std::vector<T> result;
0111 
0112   for (unsigned i = 0; i < _objs.size(); ++i)
0113     if (_objs[i].endcap() == endcap && _objs[i].station() == station && _objs[i].sector() == tsector &&
0114         (station != 1 || _objs[i].subsector() == tsubsector) && _objs[i].BX() == BX)
0115       result.push_back(_objs[i]);
0116 
0117   return result;
0118 }
0119 
0120 template <class T>
0121 std::vector<T> CSCTriggerContainer<T>::get(const unsigned& endcap, const unsigned& sector, const int& BX) const {
0122   std::vector<T> result;
0123 
0124   for (unsigned i = 0; i < _objs.size(); ++i)
0125     if (_objs[i].endcap() == endcap && _objs[i].sector() == sector && _objs[i].BX() == BX)
0126       result.push_back(_objs[i]);
0127 
0128   return result;
0129 }
0130 
0131 template <class T>
0132 std::vector<T> CSCTriggerContainer<T>::get(const unsigned& endcap, const unsigned& sector) const {
0133   std::vector<T> result;
0134 
0135   for (unsigned i = 0; i < _objs.size(); ++i)
0136     if (_objs[i].endcap() == endcap && _objs[i].sector() == sector)
0137       result.push_back(_objs[i]);
0138 
0139   return result;
0140 }
0141 
0142 template <class T>
0143 std::vector<T> CSCTriggerContainer<T>::get(const int& BX) const {
0144   std::vector<T> result;
0145 
0146   for (unsigned i = 0; i < _objs.size(); ++i)
0147     if (_objs[i].BX() == BX)
0148       result.push_back(_objs[i]);
0149 
0150   return result;
0151 }
0152 
0153 #endif