// // This file test the functionalities of the Block class. // Interectly it also test the functionalities of the ColumnAttribs class. // // test harness #include "TestManager.h" #include "HepTuple/HepHBookNtuple.h" #include "HepTuple/HepNtuple.h" #include "HepTuple/Column.h" #include "HepTuple/Block.h" ZM_USING_NAMESPACE( zmht ) #include "ZMutility/iostream" class TH1F; #ifdef USE_ROOT #include "TH1.h" #endif #include #ifndef DBL_EPSILON #define DBL_EPSILON 2.2204460492503131E-16 #endif #define IS_DBL_EQUAL(a,b) ( a == b \ || ( fabs( (a) - (b) ) < 100*DBL_EPSILON \ || ( fabs( (a) - (b) ) / (b) ) < 100*DBL_EPSILON ) ) #include "ZMutility/fstream" USING( namespace std ) int main (int argc, char** argv) { PARSE; bool newFile = is_new("roottest"); HepFileManager* manager = OPEN_FILE("roottest"); if (manager == NULL ) { cerr << "Could not open file\n"; ::exit(-1); } cerr << "Start creation ntuple \n"; if (newFile) cerr << "Create new file\n"; HepNtuple& hep = newFile ? manager->ntuple("RootTuple",1) : manager->retrieveNtuple("RootTuple",1); hep.setColumnWise(); TH1F * histogram = 0; TH1F * def_histo = 0; #ifdef USE_ROOT if (file_type == Root) { // ROOT is only initialized in this case histogram = new TH1F("h_t","h_t",50,0,50); histogram->Fill(0); def_histo = new TH1F("h_t","h_t",50,0,50); } #endif hep.column("Histo",histogram,def_histo); hep.column("value",9,3); hep.capture(); hep.storeCapturedData(); hep.clearData(); cerr << hep.blockFormat(0) << endl; cerr << "loop: \n"; hep.columnAt("Histo",(void**)&histogram); int i; for (i=0; i<50; i++) { cerr << i << ":"; #ifdef USE_ROOT if (file_type == Root) { delete histogram; histogram = new TH1F("h_t","h_t",50,0,50); histogram->Fill(i); } #endif hep.capture(); hep.storeCapturedData(); hep.clearData(); } cerr << endl; // set the readColumn back destinations. hep.readColumn(1,"Histo",(void**)&histogram); #ifdef USE_ROOT if (file_type == Root) { histogram->Print(); } #endif hep.destinationAt("Histo",(void**)&histogram); // now readColumn back and compare !! for (i=0; i<50; i++) { cerr << i << ":"; hep.readRow(i+2); // the first row is "1" #ifdef USE_ROOT if (file_type == Root) { histogram->Print(); } #endif } hep.release(); delete manager; cerr << "\nEND\n"; return 0; }