#define BOOST_DISABLE_THREADS #define BOOST_NO_MEMBER_TEMPLATES #include using namespace std; #include "TObject.h" #include "TFile.h" class Datum : public TObject { public: int x; ClassDef(Datum,1); }; ostream& operator<< (ostream &s, const Datum &d) { s << "[Datum: " << d.x << "]"; return s; } template class Container : public TObject { public: Container() { t_left = t_right = 0; t = 0; } void printto(ostream &s) const { s << "[Container address:" << this << " "; s << "Datum:"; if (t) s << *t; else s << "[NULL]"; s << endl; s << "Container Left:"; if (t_left) s << *t_left; else s << "[NULL]"; s << "Container Right:"; if (t_right) s << *t_right; else s << "[NULL]"; s << "]" << endl; } void *address() { return this; } T* t; //-> Container *t_left; //-> Container *t_right; //-> ClassDef(Container, 1); }; template ostream& operator<<(ostream &s, const Container &c) { c.printto(s); return s; } #ifdef __CINT__ #pragma link C++ class Container+; #pragma link C++ class Datum+; #endif void createfile() { // we create a network of pointers like this: // // c[0] // / \ // c[1] c[2] // / \ / \ // nul c[3] nul // / \ // nul nul // // and hope to see that it goes to, and comes back from disk, without duplicating // c[3] TFile f("out.test.root","RECREATE"); cout << "about to write" << endl; Container c0, c1, c2, c3; Datum d0, d1, d2, d3; d0.x = 0; d1.x = 1; d2.x = 2; d3.x = 3; c0.t = &d0; c1.t = &d1; c2.t = &d2; c3.t = &d3; c0.t_left = &c1; c0.t_right = &c2; c1.t_left = NULL; c1.t_right = &c3; c2.t_left = &c3; c2.t_right = NULL; c3.t_left = NULL; c3.t_right = NULL; cout << c0 << endl; cout << "about to call Write()" << endl; c0.Write(); cout << "wrote" << endl; f.Close(); cout << "closed. done." << endl; } void readfile() { cout << "Read back in:" << endl; // TFile f_in("out.test.root"); // Container* d = (Container*)f_in.FindObjectAny("Container"); // cout << *d << endl; } void streamtest() { createfile(); cout << "about to try to read them back in:" << endl; readfile(); }