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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Tue Mar 24 14:04:05 2009 UTC (15 years, 8 months ago) by pizzolot
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +8 -5 lines
setting of random seed; new distribution for primary generation

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

  ViewVC Help
Powered by ViewVC 1.1.23