#include "MyClass.h" #include "TFile.h" #include "TTree.h" #include "TBranch.h" #include "TRandom.h" #include "TF1.h" #include "TH1.h" void MakeTree(); void ReadTree(); int main() { MakeTree(); ReadTree(); return 0; } void MakeTree() { TFile* file = new TFile("testfile.root", "RECREATE"); TTree* tree = new TTree("tree", "Tree"); MyClass* myClass = NULL; tree->Branch("branch", "MyClass", &myClass); for(Int_t outerloop = 0; outerloop < 5000; outerloop++){ Int_t numberOfPoints = gRandom->Integer(500); Int_t** data = new Int_t*[13]; for(Int_t loop = 0; loop < 13; loop++){ data[loop] = new Int_t[numberOfPoints]; } for(Int_t index1 = 0; index1 < 13; index1++){ for(Int_t index2 = 0; index2 < numberOfPoints; index2++){ data[index1][index2] = gRandom->Integer(3000); } } myClass = new MyClass; myClass->FillProfile(numberOfPoints, data); tree->Fill(); for(Int_t deleteloop = 0; deleteloop < 13; deleteloop++){ delete[] data[deleteloop]; } delete[] data; delete myClass; } file->Write(); file->Close(); delete file; } void ReadTree() { TFile* file = new TFile("testfile.root"); TTree* tree = (TTree*)file->Get("tree"); MyClass* myClass = NULL; tree->SetBranchAddress("branch", &(myClass)); TH1F* smoothhistogram = NULL; TF1 func("func", "cos(x)^2", 0, 100); Int_t numberOfEntries = tree->GetEntries(); for(Int_t loop = 0; loop < numberOfEntries; loop++){ tree->GetEntry(loop); smoothhistogram = new TH1F("histogram", "", 50, 0, 50); smoothhistogram->FillRandom("func", 200); cout << "Entering smoothing\n"; smoothhistogram->Smooth(500); cout << "Finished smoothing\n"; delete smoothhistogram; } }