// // 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" #include #ifndef EPSILON #define EPSILON 2.2204460492503131E-6 #endif #define IS_EQUAL(a,b) ( a == b \ || ( ::fabs( (a) - (b) ) < 100*EPSILON \ || ( ::fabs( (a) - (b) ) / (b) ) < 100*EPSILON ) ) #include "ZMutility/fstream" USING( namespace std ) int main (int argc, char** argv) { PARSE; string filename("comprwn"); bool newFile = is_new(filename); int i; float x; HepFileManager* manager = OPEN_FILE(filename); 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.setRowWise(); // Declare the variable names and set default values (for some) hep.column("Col1",(float)3.2,(float)7.0); hep.column("Col2",(float)8.2); hep.column("Col3",(float)8.2,(float)99.0); hep.column("Col4",(float)8.2,(float)99.0); hep.capture(); hep.storeCapturedData(); hep.clearData(); cerr << "Block format descriptor is: " << hep.blockFormat(0) << endl; cerr << "\nWrite loop: \n"; // Pump out some crazy numbers, just to fill the thing for (i=0; i<50; i++) { cerr << i << ":"; x = 3.2+(float)i; hep.capture("Col1",(float)x); x = 8.2f+2.0f*(float)i; hep.capture("Col2",(float)x); hep.capture(); hep.storeCapturedData(); hep.clearData(); } cerr << endl; // set the readColumn back destinations. Float4 col1, col2, col3, col4; hep.readColumn(1,"Col1",&col1); if ( ! IS_EQUAL( col1, (float)3.2) ) { cerr << "First col1 is wrong " << col1 << endl; } hep.readColumn(1,"Col2",&col2); if ( ! IS_EQUAL( col2, (float)8.2) ) { cerr << "First col2 is wrong " << col1 << endl; } hep.readColumn(1,"Col3",&col3); if ( ! IS_EQUAL( col3, (float)8.2) ) { cerr << "First col3 is wrong " << col1 << endl; } hep.readColumn(1,"Col4",&col4); if ( ! IS_EQUAL( col4, (float)8.2) ) { cerr << "First col4 is wrong " << col1 << endl; } Float4 float1,float2,float3,float4; hep.destinationAt("Col1",&float1); hep.destinationAt("Col2",&float2); hep.destinationAt("Col3",&float3); hep.destinationAt("Col4",&float4); // now readColumn back and compare !! // ******************************************************* // Warning! The row numbering starts at 1 -- not zero!!! | // ******************************************************* cerr << "\nRead and compare loop:" << endl; cerr << "(Comparison failures will be noted -- otherwise silence.)" << endl; for (i=0; i<50; i++) { cerr << i << ":"; hep.readRow(i+2); // the first row is "1" x = (float)3.2+(float)i; if ( ! IS_EQUAL( float1 ,3.2+i ) ) { cerr << "Col1 wrong " << float1 - (3.2+i) << endl; } x = (float)8.2+(float)2*i; if ( ! IS_EQUAL( float2 ,8.2+2*i ) ) { cerr << "Col2 wrong " << float2 - ( 8.2+2*i) << endl; } if ( ! IS_EQUAL( float3 ,99.0 ) ) { cerr << "Col3 wrong " << float3 << endl; } if ( ! IS_EQUAL( float4 ,99.0 ) ) { cerr << "Col4 wrong " << float4 << endl; } } hep.release(); delete manager; cerr << "\nEND\n"; return 0; }