BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtStreamAdapter.hh
Go to the documentation of this file.
1/*******************************************************************************
2 * Project: BaBar detector at the SLAC PEP-II B-factory
3 * Package: EvtGenBase
4 * File: $Id: EvtStreamAdapter.hh,v 1.1.1.2 2007/10/26 05:03:14 pingrg Exp $
5 * Author: Alexei Dvoretskii, dvoretsk@slac.stanford.edu, 2001-2002
6 *
7 * Copyright (C) 2002 Caltech
8 *******************************************************************************/
9
10// Stream adapters are used to convert a stream-like input (for example,
11// a file containing N entries) to an STL like iterator interface. There
12// must be a way to get point from the stream, and also an indicator of the
13// end of the stream.
14
15#ifndef EVT_STREAM_ADAPTER_HH
16#define EVT_STREAM_ADAPTER_HH
17
18template <class Point> class EvtStreamAdapter {
19public:
21 virtual ~EvtStreamAdapter() {}
22 virtual EvtStreamAdapter* clone() const = 0;
23 virtual Point currentValue() = 0;
24 virtual void advance() = 0;
25 virtual bool pastEnd() = 0;
26};
27
28// N points are read from a generated stream.
29
30template <class Point, class Generator>
32public:
33 EvtGenStreamAdapter( Generator gen, int count ) : _gen( gen ), _count( count ) {}
34
36
37 virtual EvtStreamAdapter<Point>* clone() const { return new EvtGenStreamAdapter( *this ); }
38 virtual Point currentValue() { return _gen(); }
39 virtual bool pastEnd() { return ( _count <= 0 ); }
40 virtual void advance() { _count--; }
41
42private:
43 Generator _gen;
44 int _count; // also serves as past the end indicator
45};
46
47// Only points satisfying a predicate are read from the stream.
48
49template <class Point, class Iterator, class Predicate>
51public:
52 EvtPredStreamAdapter( Predicate pred, Iterator it, Iterator end )
53 : _pred( pred ), _it( it ), _end( end ) {}
55
56 virtual EvtStreamAdapter<Point>* clone() const { return new EvtPredStreamAdapter( *this ); }
57 virtual Point currentValue() {
58 Point value;
59 while ( !pastEnd() )
60 {
61
62 value = *_it;
63 if ( _pred( value ) ) break;
64 _it++;
65 }
66 return value;
67 }
68
69 virtual bool pastEnd() { return _it == _end; }
70 virtual void advance() { _it++; }
71
72private:
73 Predicate _pred;
74 Iterator _it;
75 Iterator _end;
76};
77
78#endif
DOUBLE_PRECISION count[3]
EvtGenStreamAdapter(Generator gen, int count)
virtual EvtStreamAdapter< Point > * clone() const
virtual Point currentValue()
virtual Point currentValue()
virtual EvtStreamAdapter< Point > * clone() const
EvtPredStreamAdapter(Predicate pred, Iterator it, Iterator end)
virtual void advance()=0
virtual ~EvtStreamAdapter()
virtual EvtStreamAdapter * clone() const =0
virtual Point currentValue()=0
virtual bool pastEnd()=0