// // This file test the possibility of reading arrays columns // elements by elements // // test harness #include "TestManager.h" #include "HepTuple/HepHBookNtuple.h" ZM_USING_NAMESPACE( zmht ) #include USING( namespace std ) const int dim1 = 17; double writeArray[dim1]; double readArray[dim1]; void write(HepFileManager* manager, bool newFile) { HepNtuple& hep = newFile ? manager->ntuple("columnNtuple",2) : manager->retrieveNtuple("columnNtuple",2); if (!newFile) { cout << "Ntuple blockName: " << hep.blockName(0) << endl; cout << "Ntuple format: " << hep.blockFormat(0) << endl; } hep.setColumnWise(); if (newFile) { hep.columnDirect("array",(double)7.12).dimension(dim1); } else { hep.columnDirect("array",(double)7.12); } hep.capture(); hep.storeCapturedData(); hep.clearData(); if ( newFile) { cout << "Ntuple blockName: " << hep.blockName(0) << endl; cout << "Ntuple format: " << hep.blockFormat(0) << endl; } cout << "loop: "; for (int i=0; i<10; i++) { cout << i << "."; for ( int j = 0; j < dim1 ; j++) { writeArray[j] = (i+1)*(j+1) / 8.0; } hep.capture("array",writeArray); hep.storeCapturedData(); hep.clearData(); } cout << endl; hep.release(); } void read(HepFileManager* manager) { int i,j; HepNtuple& hep = manager->retrieveNtuple("columnNtuple",2); for ( j = 0; j < dim1 ; j++) { writeArray[j] = 7.12; } hep.readColumnArray(1,"array",readArray); for ( j = 0; j < dim1 ; j++) { if ( writeArray[j] != readArray[j] ) { cerr << "Error line #0 element #" << j << " " << readArray[j]; cerr << " instead of " << writeArray[j] << endl; }; } cout << "loop: "; for ( i = 0; i<10; i++) { cout << i << "."; for ( j = 0; j < dim1 ; j++) { writeArray[j] = (i+1)*(j+1) / 8.0; } hep.readColumnArray(i+2,"array",readArray); for ( j = 0; j < dim1 ; j++) { if ( writeArray[j] != readArray[j] ) { cerr << "Error line #" << i+1 << " element #" << j << " " << readArray[j]; cerr << " instead of " << writeArray[j] << endl; }; } } cout << endl; double single; double result[12]; result[0] = 7.12; for ( i = 0; i<10; i++) { result[i+1] = (i+1+1)*(i+1) / 8.0; } for ( i = 0; i<11; i++) { cout << i << "."; char colName[256]; sprintf(colName,"array(%d)",i); hep.readColumn(i+1,colName,&single); if ( single != result[i] ) { cerr << "Error line #" << i+1 << " element #" << i << " " << single; cerr << " instead of " << result[i] << endl; }; } cout << endl; hep.release(); } #include "ZMutility/fstream" int main (int argc, char* argv[]) { PARSE; string filename("indices"); bool newFile = is_new(filename); HepFileManager* manager = OPEN_FILE(filename); if (manager == NULL ) { cerr << "Could not open file\n"; ::exit(-1); } write(manager,newFile); read(manager); delete manager; return 0; }