// // 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" // Due to a g++ bug we commented out the part of the test // using useMethod.h. The problem is that this part will // not compile with the -g flag but will compile with // -ggdb3 Int4 c; Int4 func () { return c; } void readFunc (Int4 i) { c = i; } class Test { int _a; public: Int4 a() {return _a;}; void seta(Int4 f) { _a = f; }; }; #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("compcwn"); Int4 atInt1 = 55; Int4 atInt2 = 55; // Float8 atDouble = 55.0; Test object; // Float8 arr[10][10]; Float8 arr[100][10]; int dim1 = 10; int dim2 = 10; int i; for ( i = 0; i < dim1 ; i++) { ((double*)arr)[i] = 1.0; } HepFileManager* manager = OPEN_FILE("compcwn"); if (manager == NULL ) { cerr << "Could not open file\n"; ::exit(-1); } cerr << "Start ntuple creation \n"; if (newFile) cerr << "Create new file\n"; HepNtuple& hep = newFile ? manager->ntuple("NTUPLE",1) : manager->retrieveNtuple("NTUPLE",1); hep.setColumnWise(); hep.column("Col1",3.2,7.0); hep.column("Col2",8.2); hep.columnVia("colF",func,(Int4)0); #ifdef USEMETHOD_WORKS hep.columnVia("colM",newUseMethod(&object, object.a)); #endif hep.column("Col3",8.2,99.0); hep.column("Col4",8.2,99.0); hep.columnAt("colAt",&atInt1); hep.columnAt("colAt2",&atInt2); if ( newFile ) { hep.columnArray("colArray",2,(Float8)8).dimension(dim1,dim2); } else { hep.columnDirect("colArray",(Float8)8); } hep.capture(); hep.storeCapturedData(); hep.clearData(); cerr << "Block format is: " << hep.blockFormat(0) << endl; cerr << "loop: \n"; for (i=0; i<50; i++) { cerr << i << ":"; hep.capture("Col1",3.2+i); hep.capture("Col2",8.2+2*i); atInt1 = -3*i; c = i; object.seta(5*i); // cerr << "before loop " << dim1 << "," << dim2 << "\n"; for (int j=0; j < dim1+1; j++) { for (int k=0; k< dim2+1; k++) { arr[j][k] = 8.2/(i+1)*j*k; // cerr << j << "," << k << ":" << arr[j][k] << ";"; } } hep.capture("colArray",&(arr[0][0])); hep.capture(); hep.storeCapturedData(); hep.clearData(); } cerr << endl; // set the readColumn back destinations. cerr << "\nRead and compare loop:" << endl; cerr << "(Comparison failures will be noted -- otherwise silence.)" << endl; Float8 col1; hep.readColumn(1,"Col1",&col1); if ( ! IS_DBL_EQUAL( col1, 3.2) ) { cerr << "first col1 is wrong " << col1 << " instead of " << 3.2 << endl; } hep.readColumn(1,"Col2",&col1); if ( ! IS_DBL_EQUAL( col1, 8.2) ) { cerr << "first col2 is wrong " << col1 << " instead of " << 8.2 << endl; } hep.readColumn(1,"Col3",&col1); if ( ! IS_DBL_EQUAL( col1, 8.2) ) { cerr << "first col3 is wrong " << col1 << " instead of " << 8.2 << endl; } hep.readColumn(1,"Col4",&col1); if ( ! IS_DBL_EQUAL( col1, 8.2) ) { cerr << "first col4 is wrong " << col1 << " instead of " << 8.2 << endl; } Int4 creadColumn; hep.readColumn(1,"colF",&creadColumn); if ( creadColumn != 0 ) { cerr << "first colF is wrong " << creadColumn << " instead of " << 0<