/[PAMELA software]/PamCAL/src/PamRootManager.cxx
ViewVC logotype

Contents of /PamCAL/src/PamRootManager.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Mon Nov 12 10:10:21 2007 UTC (17 years ago) by nikolas
Branch: MAIN
CVS Tags: HEAD
More basic files added

1 #include "PamRootManager.h"
2
3 #include <TParticle.h>
4 #include <TObjArray.h>
5
6 ClassImp(PamRootManager)
7
8 PamRootManager* PamRootManager::fgInstance = 0;
9
10 //_____________________________________________________________________________
11 PamRootManager::PamRootManager(const char* projectName, FileMode fileMode)
12 : TObject()
13 {
14 //
15 if (fgInstance) {
16 Fatal("PamRootManager", "Singleton instance already exists.");
17 return;
18 }
19
20 TString fileName(projectName);
21 fileName += ".root";
22
23 TString treeTitle(projectName);
24 treeTitle += " tree";
25
26 switch (fileMode) {
27 case kRead:
28 fFile = new TFile(fileName);
29 fTree = (TTree*) fFile->Get(projectName);
30 break;
31
32 case kWrite:
33 fFile = new TFile(fileName, "recreate");
34 fTree = new TTree(projectName, treeTitle);
35 ;;
36 }
37
38 fgInstance = this;
39 }
40
41 //_____________________________________________________________________________
42 PamRootManager::PamRootManager()
43 : TObject(),
44 fFile(0),
45 fTree(0)
46 {
47 //
48
49 if (fgInstance) {
50 Fatal("PamRootManager", "Singleton instance already exists.");
51 return;
52 }
53
54 fgInstance = this;
55 }
56
57 //_____________________________________________________________________________
58 PamRootManager::~PamRootManager()
59 {
60 //
61 delete fFile;
62 fgInstance = 0;
63 }
64
65 //
66 // static methods
67 //
68
69 //_____________________________________________________________________________
70 PamRootManager* PamRootManager::Instance()
71 {
72 // Returns singleton instance.
73 // ---
74
75 return fgInstance;
76 }
77
78 //
79 // public methods
80 //
81
82 //_____________________________________________________________________________
83 void PamRootManager::Register(const char* name, const char* className,
84 void* objAddress)
85 {
86 // Creates a branch of the given name and associates it with
87 // the given address.
88 // ---
89
90 if (!fTree->GetBranch(name))
91 fTree->Branch(name, className, objAddress, 32000, 99);
92 else
93 fTree->GetBranch(name)->SetAddress(objAddress);
94 }
95
96 //_____________________________________________________________________________
97 void PamRootManager::Fill()
98 {
99 // Fills the tree.
100 // ---
101
102 fTree->Fill();
103 }
104
105 //_____________________________________________________________________________
106 void PamRootManager:: WriteAll()
107 {
108 // Erites the tree in the file.
109 // ---
110
111 fTree->Write();
112 }
113
114 //_____________________________________________________________________________
115 void PamRootManager::ReadEvent(Int_t i)
116 {
117 // Reads the event data for i-th event for all connected branches.
118 // ---
119
120 fTree->GetEntry(i);
121 }

  ViewVC Help
Powered by ViewVC 1.1.23