/home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/ds/include/RAT/DS/RunStore.hh Source File

Ratpac-two: /home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/ds/include/RAT/DS/RunStore.hh Source File
Ratpac-two
RunStore.hh
1 
57 #ifndef __RAT_DS_RunStore__
58 #define __RAT_DS_RunStore__
59 
60 #include <TTree.h>
61 
62 #include <RAT/DS/Run.hh>
63 #include <map>
64 
65 namespace RAT {
66 namespace DS {
67 
68 class RunStore;
69 class Root;
70 
71 class RunRecord {
72  public:
73  RunRecord() : run(0), writtenToDisk(false) {}
74  ~RunRecord() { delete run; }
75  Run *run;
76  bool writtenToDisk;
77 };
78 
79 class RunStore {
81  public:
87  inline static RunStore *Get() {
88  if (!fgStore) {
89  fgStore = new RunStore();
90  }
91  return fgStore;
92  }
93 
102  inline static Run *GetRun(Root *ds) { return Get()->InstanceGetRun(ds); }
103 
112  inline static Run *GetRun(int runID) { return Get()->InstanceGetRun(runID); }
113 
121  inline static Run *GetCurrentRun() { return Get()->InstanceGetRun(currentRunID); }
122 
134  inline static void SetReadTree(TTree *tree) { Get()->InstanceSetReadTree(tree); }
135 
150  inline static void SetWriteTree(TTree *tree) { Get()->InstanceSetWriteTree(tree); }
151 
164  inline static void FlushWriteTree() { Get()->InstanceFlushWriteTree(); }
165 
173  inline static void AddNewRun(Run *run) {
174  currentRunID = run->GetID();
175  Get()->InstanceAddNewRun(run);
176  }
177 
188  inline static void PreloadFromTree(TTree *tree, bool alreadyWrittenToDisk = false) {
189  Get()->InstancePreloadFromTree(tree, alreadyWrittenToDisk);
190  }
191 
192  protected:
193  static RunStore *fgStore;
194  static int currentRunID;
195 
196  public:
198  RunStore();
199  virtual ~RunStore();
200 
201  Run *InstanceGetRun(Root *ds);
202  Run *InstanceGetRun(int runID);
203  void InstanceSetReadTree(TTree *tree);
204  void InstanceSetWriteTree(TTree *tree);
205  void InstanceFlushWriteTree();
206  void InstanceAddNewRun(Run *run);
207  void InstancePreloadFromTree(TTree *tree, bool writtenToDisk = false);
208 
209  ClassDef(RunStore, 2);
210 
211  protected:
212  TTree *fReadTree;
213  Run *fReadRun;
214  TTree *fWriteTree;
215  Run *fWriteRun;
216  std::map<int, RunRecord *> fCache;
217 };
218 
219 } // namespace DS
220 } // namespace RAT
221 
222 #endif
Definition: Root.hh:39
Definition: RunStore.hh:71
Definition: RunStore.hh:79
static Run * GetRun(int runID)
Definition: RunStore.hh:112
static void AddNewRun(Run *run)
Definition: RunStore.hh:173
static void FlushWriteTree()
Definition: RunStore.hh:164
static void SetWriteTree(TTree *tree)
Definition: RunStore.hh:150
RunStore()
Definition: RunStore.cc:11
static void SetReadTree(TTree *tree)
Definition: RunStore.hh:134
static Run * GetCurrentRun()
Definition: RunStore.hh:121
static void PreloadFromTree(TTree *tree, bool alreadyWrittenToDisk=false)
Definition: RunStore.hh:188
static Run * GetRun(Root *ds)
Definition: RunStore.hh:102
static RunStore * Get()
Definition: RunStore.hh:87
Definition: Run.hh:22
virtual Int_t GetID() const
Definition: Run.hh:28
Definition: CCCrossSecMessenger.hh:29