#include "TTree.h" #include "TFile.h" // Big class with a single instance class Identical { public: Identical() { for (int i = 1; i < 1000; i++) { intArray[i] = 1 + intArray[i - 1]; floatArray[i] = 1 + floatArray[i - 1] * 2; doubleArray[i] = 1 - doubleArray[i - 1] * 2; } } Int_t intArray[1000]; Float_t floatArray[1000]; Double_t doubleArray[1000]; ClassDef(Identical, 1); }; ClassImp(Identical); class Event { public: Identical *identical; Int_t property; ClassDef(Event, 1); }; ClassImp(Event); // Same as Event, but with transient Identical pointer class EventTransient { public: Identical *identical; //! Int_t property; ClassDef(EventTransient, 1); }; ClassImp(EventTransient); void TestIdenticalCompr() { Identical *id = new Identical; // Create a file using auto compression Event *ev = new Event; ev->identical = id; TFile *file = TFile::Open("AutoCompression.root", "RECREATE"); TTree *tree = new TTree("tree", ""); tree->Branch("branch", &ev); for (int i = 0; i < 1000; i++) { ev->property = i; tree->Fill(); } tree->Write(); file->Close(); delete file; delete ev; // Create a file using the EventTransient class EventTransient *evTransient = new EventTransient; evTransient->identical = id; file = TFile::Open("Transient.root", "RECREATE"); tree = new TTree("tree", ""); tree->Branch("branch", &evTransient); TTree *idTree = new TTree("idTree", ""); // tree to store the single identical object idTree->Branch("idBranch", &id); for (int i = 0; i < 1000; i++) { evTransient->property = i; tree->Fill(); } idTree->Fill(); tree->Write(); idTree->Write(); file->Close(); delete file; delete evTransient; delete id; }