npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
NtupleReference.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_NTUPLEREFERENCE_HH_
2 #define NPSTAT_NTUPLEREFERENCE_HH_
3 
4 /*!
5 // \file NtupleReference.hh
6 //
7 // \brief Special reference class for ArchivedNtuple objects
8 //
9 // Author: I. Volobouev
10 //
11 // November 2010
12 */
13 
14 #include "geners/CPP11_auto_ptr.hh"
15 #include "geners/CPP11_shared_ptr.hh"
16 #include "geners/AbsReference.hh"
17 #include "geners/ClassId.hh"
18 
19 namespace npstat {
20  /**
21  // Reference for finding objects of class ArchivedNtuple in the binary
22  // archives. Interface is similar to the standard utility class Reference
23  // in Reference.hh, but there is no "restore" method. "restore" would not
24  // make sense here as we can not put the complete archive onto the heap.
25  */
26  template <typename Ntuple>
27  class NtupleReference : public gs::AbsReference
28  {
29  public:
30  /** Find item by its unique id in the archive */
31  inline NtupleReference(gs::AbsArchive& ar,
32  const unsigned long long itemId)
33  : gs::AbsReference(ar, gs::ClassId::makeId<Ntuple>(),
34  "npstat::NtupleHeader", itemId) {}
35 
36  /** Find (possibly more than one) item by its name and category */
37  inline NtupleReference(gs::AbsArchive& ar,
38  const char* name, const char* category)
39  : gs::AbsReference(ar, gs::ClassId::makeId<Ntuple>(),
40  "npstat::NtupleHeader", name, category) {}
41 
42  /** Search for items of ArchivedNtuple type */
43  inline NtupleReference(gs::AbsArchive& ar,
44  const gs::SearchSpecifier& namePattern,
45  const gs::SearchSpecifier& categPattern)
46  : gs::AbsReference(ar, gs::ClassId::makeId<Ntuple>(),
47  "npstat::NtupleHeader",
48  namePattern, categPattern) {}
49 
50  inline virtual ~NtupleReference() {}
51 
52  /** Retrieve ArchivedNtuple header record and build the ntuple */
53  inline CPP11_auto_ptr<Ntuple> get(const unsigned long index) const
54  {return CPP11_auto_ptr<Ntuple>(getPtr(index));}
55 
56  /** Retrieve ArchivedNtuple header record and build the ntuple */
57  inline CPP11_shared_ptr<Ntuple> getShared(
58  const unsigned long index) const
59  {return CPP11_shared_ptr<Ntuple>(getPtr(index));}
60 
61  private:
62  inline Ntuple* getPtr(const unsigned long number) const
63  {
64  Ntuple* readout = 0;
65  const unsigned long long itemId = id(number);
66  if (itemId)
67  readout = Ntuple::read(archive(),
68  this->positionInputStream(itemId),
69  itemId);
70  return readout;
71  }
72  };
73 }
74 
75 #endif // NPSTAT_NTUPLEREFERENCE_HH_
Definition: NtupleReference.hh:28
NtupleReference(gs::AbsArchive &ar, const gs::SearchSpecifier &namePattern, const gs::SearchSpecifier &categPattern)
Definition: NtupleReference.hh:43
CPP11_shared_ptr< Ntuple > getShared(const unsigned long index) const
Definition: NtupleReference.hh:57
NtupleReference(gs::AbsArchive &ar, const char *name, const char *category)
Definition: NtupleReference.hh:37
NtupleReference(gs::AbsArchive &ar, const unsigned long long itemId)
Definition: NtupleReference.hh:31
CPP11_auto_ptr< Ntuple > get(const unsigned long index) const
Definition: NtupleReference.hh:53
Definition: AbsArrayProjector.hh:14