CARMA C++
TypedAverageAccumulatorT.h
Go to the documentation of this file.
1 /*
2  * TypedAverageAccumulatorT.h - Template file for accumulating monitor point
3  * values of a spoecific type.
4  */
5 
6 #ifndef CARMA_MONITOR_TYPED_AVERAGE_ACCUMULATORT_H
7 #define CARMA_MONITOR_TYPED_AVERAGE_ACCUMULATORT_H
8 
18 #include <vector>
19 
20 #include "carma/corba/corba.h"
21 #include "carma/dbms/dbFFIO.h"
22 #include "carma/monitor/monitorframe.h"
25 
26 
27 namespace carma {
28 namespace monitor {
29 
30 
34  public:
35  virtual ~AverageAccumulatorBase( );
36 
37  protected:
38  explicit AverageAccumulatorBase( );
39 
40  void setMonSys( const MonitorSystem & monSys,
42 
43  private:
44  virtual void
45  setSeq( const ::std::vector< MonitorPoint * > & mpVec ) = 0;
46 };
47 
48 
55 template < typename T, typename U >
57  public:
65  const MonitorSystem & monSys,
67 
68 
74 
75 
83  void accumulate( );
84 
85 
93  void resetAccumulator( );
94 
95 
96  void dumpInstAveragesToDBFile( long frameCount,
97  FILE * file ) const;
98 
99 
100  void dumpInstAveragesToDBFile( long frameCount,
101  carma::dbms::dbFFIO & file ) const;
102 
103 
104  void dumpLongAveragesToDBFile( const char * frameCountText,
105  FILE * file ) const;
106 
107 
108  private:
109  void setSeq( const ::std::vector< MonitorPoint * > & mpVec );
110 
111  typedef ::std::vector< MonitorPointAccumulatorT< T, U > > AccumVec;
112 
113  typedef typename AccumVec::iterator IteratorType;
114  typedef typename AccumVec::const_iterator ConstIteratorType;
115 
116  // vector of MonitorPointAccumulators, ordered by tagID.
117  AccumVec seq_;
118 }; // template TypedAverageAccumulatorT
119 
120 
121 } // end namespace carma::monitor
122 } // end namespace carma
123 
124 
125 inline
126 carma::monitor::AverageAccumulatorBase::AverageAccumulatorBase( )
127 {
128 }
129 
130 
131 inline
132 carma::monitor::AverageAccumulatorBase::~AverageAccumulatorBase( )
133 {
134 }
135 
136 
137 template < typename T, typename U >
139  const MonitorSystem & monitorSystem,
140  const MonitorComponent::ARCHIVE_PRIORITY priority ) :
142 seq_()
143 {
144  // Notice that I have this call in the derived class c'tor because it
145  // uses the virtual setSeq method internally and hence I don't call
146  // it until that method and anything it uses is constructed.
147  setMonSys( monitorSystem, priority );
148 }
149 
150 
151 template < typename T, typename U >
153 {
154 }
155 
156 
157 template < typename T, typename U >
158 void
160  const ::std::vector< MonitorPoint * > & mpVec )
161 {
162  const ::std::vector< MonitorPoint * >::const_iterator iEnd = mpVec.end();
163 
164  ::std::vector< MonitorPoint * >::const_iterator i = mpVec.begin();
165 
166  ::size_t count = 0;
167 
168  for ( ; i != iEnd; ++i ) {
169  if ( dynamic_cast< T * >( *i ) != 0 )
170  ++count;
171  }
172 
173  seq_.reserve( count );
174 
175  i = mpVec.begin();
176 
177  for ( ; i != iEnd; ++i ) {
178  T * const typedPoint = dynamic_cast< T * >( *i );
179 
180  if ( typedPoint != 0 ) {
181  seq_.push_back( MonitorPointAccumulatorT< T, U >( *typedPoint ) );
182  }
183  }
184 }
185 
186 
187 template < typename T, typename U >
188 void
190 {
191  IteratorType i = seq_.begin();
192  const IteratorType iEnd = seq_.end();
193 
194  for ( ; i != iEnd; ++i )
195  i->accumulateAverage();
196 }
197 
198 
199 template < typename T, typename U >
200 void
202 {
203  IteratorType i = seq_.begin();
204  const IteratorType iEnd = seq_.end();
205 
206  for ( ; i != iEnd; ++i )
207  i->resetAccumulator();
208 }
209 
210 
211 template < typename T, typename U >
212 void
214  const long frameCount,
215  FILE * file ) const
216 {
217  ConstIteratorType i = seq_.begin();
218  const ConstIteratorType iEnd = seq_.end();
219 
220  for ( ; i != iEnd; ++i )
221  i->dumpInstAveragesToFile( frameCount, file );
222 }
223 
224 template < typename T, typename U >
225 void
227  const long frameCount,
228  carma::dbms::dbFFIO & file ) const
229 {
230  ConstIteratorType i = seq_.begin();
231  const ConstIteratorType iEnd = seq_.end();
232 
233  for ( ; i != iEnd; ++i )
234  i->dumpInstAveragesToFile( frameCount, file );
235 }
236 
237 
238 template < typename T, typename U >
239 void
241  const char * const frameCountText,
242  FILE * file ) const
243 {
244  ConstIteratorType i = seq_.begin();
245  const ConstIteratorType iEnd = seq_.end();
246 
247  for ( ; i != iEnd; ++i )
248  i->dumpLongAveragesToFile( frameCountText, file );
249 }
250 
251 
252 #endif
ARCHIVE_PRIORITY
Archiving priority.
The monitor system base class.
~TypedAverageAccumulatorT()
Destructor - destroys all strcutures built up during construction.
void resetAccumulator()
Resets values in all typed accumulators so that a new average computation can begin.
void accumulate()
Accumulates values for each monitor point accumulator in this typed average accumulator.
Class(es) to read &amp; write dbms flat file information in ASCII or binary.
Monitor system base class.
Definition: MonitorSystem.h:81
TypedAverageAccumulatorT(const MonitorSystem &monSys, MonitorComponent::ARCHIVE_PRIORITY priority)
Constructor Binds itself to monitor system monSys.
Common base class for TypedAverageAccumulatorT&lt; T, U &gt; classes.