#include "PamRootManager.h" #include #include #include #include #include #include ClassImp(PamRootManager) using namespace std; PamRootManager* PamRootManager::fgInstance = 0; PamRootManager::PamRootManager(const char* projectName, FileMode fileMode) : TObject() { if (fgInstance) { Fatal("PamRootManager", "Singleton instance already exists."); return; } TString fileName = projectName; // TString fileName = TString(gSystem->Getenv("PWD"))+"/"+projectName; fileName += ".root"; cout<<"OUTPUT ROOTFILE: "<Get(projectName); break; case kWrite: fFile = new TFile(fileName, "recreate"); fTree = new TTree("hits", "PamVMC hits collections"); ;; } fgInstance = this; } PamRootManager::PamRootManager() : TObject(), fFile(0), fTree(0) { if (fgInstance) { Fatal("PamRootManager", "Singleton instance already exists."); return; } fgInstance = this; } PamRootManager::~PamRootManager() { fFile->cd(); delete fFile; //delete fDirectory; fgInstance = 0; } PamRootManager* PamRootManager::Instance() { // Returns singleton instance. return fgInstance; } void PamRootManager::Register(const char* name, const char* className, void* objAddress) { // Creates a branch of the given name and associates it with // the given address. if (!fTree->GetBranch(name)) fTree->Branch(name, className, objAddress, 32000, 99); else fTree->GetBranch(name)->SetAddress(objAddress); } void PamRootManager::Fill() { // Fills the tree. //TString tmp = gDirectory->GetName(); fFile->cd(); fTree->Fill(); //gDirectory->cd(tmp); } void PamRootManager:: WriteAll() { // Erites the tree in the file. //TString tmp = gDirectory->GetName(); fFile->cd(); std::cout<<"TREE NAME: "<GetName()<GetName()<Write(); //gDirectory->cd(tmp); std::cout<<"TREE WRITTEN "<GetName()<GetEntry(i); }