npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
Column.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_COLUMN_HH_
2 #define NPSTAT_COLUMN_HH_
3 
4 /*!
5 // \file Column.hh
6 //
7 // \brief Address ntuple columns by name or by number
8 //
9 // Author: I. Volobouev
10 //
11 // November 2010
12 */
13 
14 #include <string>
15 #include <cassert>
16 
17 namespace npstat {
18  template <typename T>
19  class AbsNtuple;
20 
21  /**
22  // This class serves just one purpose: it allows to address ntuple columns
23  // by either name or number in the same function call. Do not create
24  // stand-alone objects of this class in your application code and do not
25  // include this header directly (it will be included automatically when
26  // you include AbsNtuple.hh). Objects of this class are not meant to be
27  // reused, and doing so can lead to subtle bugs.
28  */
29  class Column
30  {
31  public:
32  /** Constructor from unsigned integer */
33  inline Column(const unsigned long i)
34  : col_(i), name_(0), lastNt_(0), mode_(0) {}
35 
36  /** Constructor from c-string */
37  inline Column(const char* name)
38  : col_(0), name_(name), lastNt_(0), mode_(1) {assert(name);}
39 
40  /** Constructor from std::string */
41  inline Column(const std::string& name)
42  : col_(0), name_(0), st_(name), lastNt_(0), mode_(2) {}
43 
44  /**
45  // Can't call "isValid" after operator(): this will result
46  // in a run-time error
47  */
48  template <typename T>
49  bool isValid(const AbsNtuple<T>& ntuple) const;
50 
51  /**
52  // This will return the column number in the given ntuple
53  // or will throw an exception if the column specification
54  // is invalid
55  */
56  template <typename T>
57  unsigned long operator()(const AbsNtuple<T>& ntuple) const;
58 
59  private:
60  Column();
61 
62  mutable unsigned long col_;
63  const char* name_;
64  std::string st_;
65  mutable const void* lastNt_;
66  unsigned mode_;
67  };
68 }
69 
70 #endif // NPSTAT_COLUMN_HH_
Definition: AbsNtuple.hh:39
Definition: Column.hh:30
Column(const unsigned long i)
Definition: Column.hh:33
bool isValid(const AbsNtuple< T > &ntuple) const
unsigned long operator()(const AbsNtuple< T > &ntuple) const
Column(const char *name)
Definition: Column.hh:37
Column(const std::string &name)
Definition: Column.hh:41
Definition: AbsArrayProjector.hh:14