00001
00002
00003
00004
00005
00006
00007
00008 #include "MyRoot.hh"
00009
00010 #include <stdlib.h>
00011
00012 MyRoot* MyRoot::fMyRoot = 0;
00013
00014 MyRoot::MyRoot()
00015 :m_file(0)
00016 {
00017 if (fMyRoot){
00018 G4Exception("MyRoot::MyRoot()","Run0031",
00019 FatalException, "MyRoot constructed twice.");
00020 }
00021 fVerbose = 0;
00022 fPrintModulo = 0;
00023 fMyRoot = this;
00024 if ( fVerbose >= 5 ){
00025 printf("MyRoot\n");
00026 }
00027 }
00028
00029 MyRoot::~MyRoot()
00030 {
00031 m_tree->Delete();
00032 if (m_file) delete m_file;
00033 if ( fVerbose >= 5 ){
00034 printf("~MyRoot\n");
00035 }
00036 }
00037
00038 void MyRoot::CreateTree(std::string tree_name, int fCircular){
00039 m_tree = new TTree(tree_name.c_str(),tree_name.c_str());
00040 nbFilled = 0;
00041
00042
00043 if (fCircular){
00044 m_tree->SetCircular(fCircular);
00045 }
00046 if ( fVerbose >= 5 ){
00047 std::cout<<"In MyRoot::CreateTree"<<std::endl;
00048 std::cout<<" New tree booked!!"<<std::endl;
00049 std::cout<<" Name: "<<tree_name<<std::endl;
00050 std::cout<<" Circular: "<<fCircular<<std::endl;
00051 }
00052 }
00053
00054 void MyRoot::OpenFile(std::string file_name)
00055 {
00056 if (m_file) delete m_file;
00057 m_file = new TFile (file_name.c_str(), "RECREATE");
00058 if ( fVerbose >= 5 ){
00059 std::cout<<"In MyRoot::OpenFile"<<std::endl;
00060 std::cout<<" New file open!!"<<std::endl;
00061 std::cout<<" Name: "<<file_name<<std::endl;
00062 }
00063 }
00064
00065 MyRoot* MyRoot::GetMyRoot(){
00066 if ( !fMyRoot ){
00067 fMyRoot = new MyRoot;
00068 }
00069 return fMyRoot;
00070 }
00071
00072 void MyRoot::Fill(){
00073 m_tree->Fill();
00074 nbFilled++;
00075 if ( fVerbose >= 5 ){
00076 if ( fPrintModulo ){
00077 if ( nbFilled%fPrintModulo == 0 ){
00078 std::cout<<"In MyRoot::Fill"<<std::endl;
00079 std::cout<<" m_tree->Fill()"<<std::endl;
00080 std::cout<<" "<<nbFilled<<" times for this tree"<<std::endl;
00081 }
00082 }
00083 }
00084 }
00085
00086 void MyRoot::Save(){
00087 m_tree->AutoSave();
00088 if ( fVerbose >= 5 ){
00089 std::cout<<"In MyRoot::Save"<<std::endl;
00090 std::cout<<" m_tree->AutoSave()"<<std::endl;
00091 }
00092 }
00093
00094 int MyRoot::FlushBaskets(){
00095 if ( fVerbose >= 5 ){
00096 std::cout<<"In MyRoot::FlushBaskets"<<std::endl;
00097 std::cout<<" m_tree->FlushBaskets()"<<std::endl;
00098 }
00099 return (m_tree->FlushBaskets());
00100 }
00101
00102 void MyRoot::Write(){
00103 m_tree->Write();
00104 if ( fVerbose >= 5 ){
00105 std::cout<<"In MyRoot::Write"<<std::endl;
00106 std::cout<<" m_tree->Write()"<<std::endl;
00107 }
00108 }
00109
00110 void MyRoot::Close(){
00111 m_file->Close();
00112 if ( fVerbose >= 5 ){
00113 std::cout<<"In MyRoot::Close"<<std::endl;
00114 std::cout<<" m_file->Close()"<<std::endl;
00115 }
00116 }
00117
00118 void MyRoot::SetBranch(const std::string& name, std::vector<double>* pVecD){
00119 m_tree->Branch(name.c_str(), pVecD);
00120 if ( fVerbose >= 5 ){
00121 std::cout<<"In MyRoot::SetBranch"<<std::endl;
00122 std::cout<<" New branch created!!"<<std::endl;
00123 std::cout<<" Name: "<<name<<std::endl;
00124 std::cout<<" Type: vector<double>"<<std::endl;
00125 }
00126 }
00127
00128 void MyRoot::SetBranch(const std::string& name, std::vector<int>* pVecI){
00129 m_tree->Branch(name.c_str(), pVecI);
00130 if ( fVerbose >= 5 ){
00131 std::cout<<"In MyRoot::SetBranch"<<std::endl;
00132 std::cout<<" New branch created!!"<<std::endl;
00133 std::cout<<" Name: "<<name<<std::endl;
00134 std::cout<<" Type: vector<int>"<<std::endl;
00135 }
00136 }
00137
00138 void MyRoot::SetBranch(const std::string& name, int* pI ){
00139 m_tree->Branch(name.c_str(), pI);
00140 if ( fVerbose >= 5 ){
00141 std::cout<<"In MyRoot::SetBranch"<<std::endl;
00142 std::cout<<" New branch created!!"<<std::endl;
00143 std::cout<<" Name: "<<name<<std::endl;
00144 std::cout<<" Type: int"<<std::endl;
00145 }
00146 }
00147
00148 void MyRoot::SetBranch(const std::string& name, double* pD ){
00149 m_tree->Branch(name.c_str(), pD);
00150 if ( fVerbose >= 5 ){
00151 std::cout<<"In MyRoot::SetBranch"<<std::endl;
00152 std::cout<<" New branch created!!"<<std::endl;
00153 std::cout<<" Name: "<<name<<std::endl;
00154 std::cout<<" Type: double"<<std::endl;
00155 }
00156 }
00157
00158 void MyRoot::SetBranch(const std::string& name, std::vector<std::string>* pVecCa){
00159 m_tree->Branch(name.c_str(), pVecCa);
00160 if ( fVerbose >= 5 ){
00161 std::cout<<"In MyRoot::SetBranch"<<std::endl;
00162 std::cout<<" New branch created!!"<<std::endl;
00163 std::cout<<" Name: "<<name<<std::endl;
00164 std::cout<<" Type: vector<string>"<<std::endl;
00165 }
00166 }