BOSS 7.0.5
BESIII Offline Software System
Loading...
Searching...
No Matches
Calibration/facilities/facilities-00-00-04/facilities/FIFO.h
Go to the documentation of this file.
1// $Id: FIFO.h,v 1.1.1.1 2005/10/17 06:11:40 maqm Exp $
2#ifndef FIFO_h
3#define FIFO_h 1
4
5#ifdef _MSC_VER
6# pragma warning(disable: 4786)
7#endif
8
9#include <vector>
10#include <cassert>
11
12//## Class: FIFO; Parameterized Class
13// Implements the FIFO class. This is not a readout
14// component, but a standard First-In-First-Out storage
15// class.
16
17using std::vector;
18
19template <class _T>
20class FIFO : private vector<_T> //## Inherits: _T
21{
22 public:
23 FIFO (unsigned int depth = 0)
24 : vector<_T>(), m_depth(depth)
25 {
26 if (depth > 0) reserve ( depth );
27
28 // if the depth of the fifo is fixed, then reserve enough space to contain it entirely
29 // FIFO operates in two modes: one for a fixed depth,
30 // and another for a non-fixed depth (unlimited)
31 }
32
33 FIFO (const FIFO& f)
34 : vector<_T>(f), m_depth(f.m_depth)
35 {
36 }
37
38
39 // Push x into the FIFO. Returns true if x was successfully
40 // stored, false if not (FIFO was full).
41 bool push (const _T& x)
42 {
43 if ((m_depth != 0) && (size() >= m_depth)) return false;
44
45 push_back( x );
46
47 return true;
48 }
49
50 // Returns the current front of the FIFO buffer, if it
51 // exists. Caller must perform range checking to see that
52 // the FIFO is not empty prior to this call.
54 {
55 assert(size()>0);
56 _T value (*begin());
57 erase(begin());
58
59 // limited depth mode
60
61 return value;
62 }
63
64 _T& front () { return vector<_T>::front(); }
65 _T& back () { return vector<_T>::back(); }
66
67 const _T& front () const { return vector<_T>::front(); }
68 const _T& back () const { return vector<_T>::back(); }
69
70 bool empty () const { return (size() == 0); }
71
72 // Get the maximum size of this FIFO.
73 unsigned int maxSize () const
74 {
75 return m_depth;
76 }
77
78 // Return the current size of the FIFO buffer.
79 unsigned int size () const
80 {
81 return vector<_T>::size();
82 }
83
84 void clear ()
85 {
86 vector<_T>::clear();
87 }
88
89 // Writes the contents of the FIFO to the output stream.
90 void printOn (std::ostream& out = cout)
91 {
92 short i = 1;
93 for (vector<_T>::reverse_iterator it = rbegin(); it != rend(); ++it) {
94 out << (*it)();
95 if ((i % 8) == 0) out << "\n";
96 else out << "\t";
97 i++;
98 }
99 }
100
101 bool full () const { return size() == m_depth; }
102
103 bool avail () const { return size() < m_depth; }
104
105 private:
106
107 // maximum depth for the fifo
108 unsigned int m_depth;
109};
110
111#endif
#define _T(str)
Double_t x[10]
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")