/[PAMELA software]/trieste/pamVMC/src/PamRootManager.cxx
ViewVC logotype

Contents of /trieste/pamVMC/src/PamRootManager.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Wed Mar 4 12:51:20 2009 UTC (15 years, 8 months ago) by pamelats
Branch: pamVMC
CVS Tags: start, v0r00
Changes since 1.1: +0 -0 lines
Test pamVMC

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

  ViewVC Help
Powered by ViewVC 1.1.23