/home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/io/include/RAT/DSReader.hh Source File

Ratpac-two: /home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/io/include/RAT/DSReader.hh Source File
Ratpac-two
DSReader.hh
1 #ifndef __RAT_DSReader___
2 #define __RAT_DSReader___
3 
4 #include <TChain.h>
5 #include <TObject.h>
6 #include <TTree.h>
7 
8 #include <RAT/DB.hh>
9 #include <RAT/DS/Root.hh>
10 #include <RAT/DS/Run.hh>
11 #include <string>
12 
13 namespace RAT {
14 
15 // Convenience class for ROOT scripts
16 class DSReader : public TObject {
17  public:
18  DSReader(const std::string &filename);
19  virtual ~DSReader();
20 
21  // Reconstruct the global RAT::DB from the snapshot embedded in this file by
22  // the outroot processor (the "ratdb" object). This restores the exact set of
23  // tables used to build the geometry during production -- no $RATSHARE or geo
24  // file needed. It is called automatically by the constructor so the DB is
25  // ready before event looping begins, but is exposed so it can be re-run.
26  // Returns the singleton DB instance.
27  RAT::DB *LoadDB();
28 
29  // Construct and close the Geant4 detector geometry from the DB loaded by
30  // LoadDB(), mirroring `rat`'s /run/initialize. This wraps RAT's G4 machinery
31  // (DetectorConstruction, RunManager, PhysicsList) so no Geant4 types leak
32  // into ROOT. Call once, after construction, before using the geometry (e.g.
33  // the light-path calculator). Requires the libRATPAC library to be loaded.
34  void BuildGeometry();
35 
36  void Add(const std::string &filename);
37  void SetBranchStatus(const std::string &bname, bool status = 1) { T.SetBranchStatus(bname.c_str(), status); };
38 
39  TTree *GetT() { return &T; };
40  TTree *GetRunT() { return &runT; };
41  virtual DS::Root *GetDS() { return fDS; };
42  Long64_t GetEntryCount() { return fTotalEntries; };
43 
44  virtual bool HasNextEntry() { return next < fTotalEntries; };
45  virtual size_t GetRunCount() { return fTotalRuns; };
46 
47  // FIXME: return types for all functions below should be const, but we don't
48  // have enough downstream const accessors to make this work yet.
49 
50  // Load event. Returns ds (which will now point to specified event)
51  virtual DS::Root &GetEntry(Long64_t num) {
52  next = num + 1;
53  T.GetEntry(num);
54  return *fDS;
55  };
56 
57  virtual DS::Root &NextEntry();
58  virtual DS::Run &GetRun() { return GetRunByRunID(fDS->GetRunID()); };
59  virtual DS::Run &GetRunByRunID(int runID);
60  virtual DS::Run &GetRunByIndex(size_t index);
61  ClassDef(DSReader, 1);
62 
63  protected:
64  TChain T;
65  TChain runT;
66  DS::Root *fDS;
67  DS::Run *fRun;
68  size_t next;
69  size_t fTotalEntries;
70  size_t fTotalRuns;
71 };
72 
73 } // namespace RAT
74 
75 #endif
Definition: DB.hh:127
Definition: DSReader.hh:16
Definition: Root.hh:37
virtual int GetRunID() const
Definition: Root.hh:43
Definition: Run.hh:22
Definition: CCCrossSecMessenger.hh:29