// // This file test the functionalities of the Block class. // Interectly it also test the functionalities of the ColumnAttribs class. // #include "TestManager.h" #include "HepTuple/HepNtuple.h" #include "HepTuple/Column.h" #include "HepTuple/Block.h" USING( namespace std ) ZM_USING_NAMESPACE( zmht ) int main (int argc, char** argv) { int i; PARSE; Int4 atInt1 = 55; // Test if the data file already exist. bool newFile = is_new("quicktest"); // Setup ntuple HepFileManager* manager = OPEN_FILE("quicktest"); if ( manager == NULL ) { cerr << "Could not open the file\n"; ::exit(-1); } cout << "Start ntuple creation \n"; if (newFile) cout << "Create new file\n"; HepNtuple& hep = newFile ? manager->ntuple("NTUPLE",1) : manager->retrieveNtuple("NTUPLE",1); hep.setColumnWise(); // Create and fill columns hep.columnDirect("Col1",7.7); hep.column("Col2",8.2); hep.columnAt("nothing",&atInt1,9); hep.capture(); hep.storeCapturedData(); hep.clearData(); cerr << "Block format is: " << hep.blockFormat(0) << endl; cerr << "loop: "; for (i=0; i<2; i++) { cerr << i << ","; hep.capture("Col1",3.2+i); hep.capture("Col2",8.2+2*i); hep.capture(); hep.storeCapturedData(); hep.clearData(); } cout << 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); cout << "Col1: " << col1 << endl; if ( col1 != 7.7 ) cerr << "first col1 is wrong " << col1 << endl; hep.readColumn(1,"Col2",&col1); if ( col1 != 8.2 ) cerr << "first col2 is wrong " << col1 << endl; Float8 float1,float2; hep.destinationAt("Col1",&float1); cerr << "Reading Row 1\n"; hep.readRow(1); // the first row is "1" cerr << "Reading Row 2\n"; hep.readRow(2); // the first row is "1" cerr << "Reading Row 3\n"; hep.readRow(3); // the first row is "1" hep.destinationAt("Col2",&float2); cerr << "Reading Row 2 after set col2 \n"; hep.readRow(2); // the first row is "1" cerr << "Reading Row 2 in loop \n"; // now readColumn back and compare !! for (i=0; i<2; i++) { cerr << i << ":"; hep.readRow(i+2); // the first row is "1" if ( float1 != 3.2+i ) { cerr << "Col1 wrong " << float1 << endl; } if ( float2 != 8.2+2*i ) { cerr << "Col2 wrong " << float1 << endl; } } hep.release(); delete manager; cout << "END\n"; return 0; }