Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:51

0001 
0002 #ifndef L1GCTPROCESSOR_H_
0003 #define L1GCTPROCESSOR_H_
0004 
0005 /*!
0006  * \author Jim Brooke
0007  * \date April 2006
0008  */
0009 
0010 /*! \class L1GctProcessor
0011  * \brief ABC for a GCT trigger data processing unit
0012  * 
0013  * A processing unit can be a card, an FPGA, a chunk of firmware. This class
0014  * exists simply to enforce a common interface. 
0015  *
0016  * There should not be any L1GctProcessor* pointers!
0017  * 
0018  */
0019 
0020 #include <vector>
0021 
0022 class L1GctProcessor {
0023 public:
0024   L1GctProcessor() : m_verbose(false), m_bx(0), m_bxStart(0), m_numOfBx(1){};
0025   virtual ~L1GctProcessor(){};
0026 
0027   /// complete reset of processor
0028   inline void reset() {
0029     m_bxStart = 0;
0030     m_numOfBx = 1;
0031     m_bx = 0;
0032     resetPipelines();
0033     resetProcessor();
0034     setupObjects();
0035   }
0036 
0037   /// set the input buffers
0038   virtual void fetchInput() = 0;
0039 
0040   /// process the data and set outputs
0041   virtual void process() = 0;
0042 
0043   /// define the bunch crossing range to process
0044   inline void setBxRange(const int firstBx, const int numberOfBx) {
0045     m_bxStart = firstBx;
0046     m_numOfBx = numberOfBx;
0047     resetPipelines();
0048   }
0049 
0050   /// clear input data buffers and process a new bunch crossing
0051   inline void setNextBx(const int bxnum) {
0052     if ((bxnum - m_bxStart >= 0) && (bxnum - m_bxStart < m_numOfBx)) {
0053       m_bx = bxnum;
0054     } else {
0055       m_bx = 0;
0056     }
0057     resetProcessor();
0058     setupObjects();
0059   }
0060 
0061   /// Method to check the setup for this processor. Returns true by default.
0062   bool setupOk() const { return true; }
0063 
0064   /// control output messages
0065   void setVerbose() { m_verbose = true; }
0066   void setTerse() { m_verbose = false; }
0067 
0068 protected:
0069   /// Separate reset methods for the processor itself and any data stored in pipelines
0070   virtual void resetProcessor() = 0;
0071   virtual void resetPipelines() = 0;
0072 
0073   /// Initialise inputs with null objects for the correct bunch crossing if required
0074   virtual void setupObjects() = 0;
0075 
0076   /// Support for multiple beam crossing operation
0077   inline int bxMin() const { return m_bxStart; }
0078   inline int bxMax() const { return (m_bxStart + m_numOfBx - 1); }
0079   inline int numOfBx() const { return m_numOfBx; }
0080   inline int bxAbs() const { return m_bx; }
0081   inline int bxRel() const { return (m_bx - m_bxStart); }
0082 
0083   template <class T>
0084   struct Pipeline {
0085     std::vector<T> contents;
0086     unsigned entriesPerBx;
0087 
0088     Pipeline() : contents(1), entriesPerBx(1) {}
0089     Pipeline(const unsigned size) : contents(size), entriesPerBx(size) {}
0090 
0091     void resize(const unsigned size) { entriesPerBx = size; }
0092 
0093     void reset(const unsigned nBx) {
0094       contents.clear();
0095       contents.resize(nBx * entriesPerBx);
0096     }
0097 
0098     void store(const T& thisBx, const int bxNum) { contents.at(bxNum) = thisBx; }
0099 
0100     void store(const std::vector<T>& thisBx, const int bxNum) {
0101       unsigned pos = entriesPerBx * bxNum;
0102       for (unsigned i = 0; i < entriesPerBx; i++) {
0103         contents.at(pos++) = thisBx.at(i);
0104       }
0105     }
0106   };
0107 
0108   /// Flag to control output messages
0109   bool m_verbose;
0110 
0111 private:
0112   /// Support for multiple beam crossing operation
0113   int m_bx;
0114   ///
0115   int m_bxStart;
0116   int m_numOfBx;
0117 };
0118 
0119 #endif