// // This file primarly test the array indexing capability // of HepNtuples // // test harness #include "TestManager.h" #include "HepTuple/HepHBookNtuple.h" ZM_USING_NAMESPACE( zmht ) #include "ZMutility/iostream" USING( namespace std ) void indexWrite(HepNtuple& tuple); void indexRead(HepNtuple& tuple); int main (int argc, char** argv) { PARSE; HepFileManager* manager = OPEN_FILE("index"); if (manager == NULL ) { cerr << "Could not open file\n"; ::exit(-1); } HepNtuple& hep = manager->ntuple("indexed",1); hep.setColumnWise(); indexWrite(hep); indexRead(hep); hep.release(); delete manager; return 0; } void indexWrite(HepNtuple& tuple) { // create default value and value holders. // Int4 indexDefault = 0; // Int4 intDefault = 99; Int4 indexVal = 0; Int4 intVal[10]; // Construct the HepNtuple. tuple.columnAt("index",&indexVal).span(0,10); tuple.columnAt("array",(Int4*)&intVal).dimension(10).index("index"); // Capture for (indexVal = 2; indexVal < 7 ; indexVal++ ) { int j; for ( j = 0; j < indexVal; j++ ) { intVal[j] = indexVal*(j+1); } for ( j = indexVal; j < 10; j++ ) { intVal[j] = 77; } tuple.captureThenStore(); tuple.clearData(); } } void indexRead(HepNtuple& tuple) { Int4 indexVal = 0; Int4 intVal[10]; // Set where to grab the information. // we assume that the ntuple is has described in indexWrite tuple.destinationAt("index",&indexVal); tuple.destinationAt("array",(Int4*)&intVal); for (int indexTarget = 2; indexTarget < 7 ; indexTarget++ ) { tuple.readRow(indexTarget-1); if (indexVal != indexTarget) { cerr << "Error: index Value not read correctly (" << indexVal; cerr << " vs " << indexTarget << ")\n"; } for ( int j = 0; j < indexVal; j++ ) { if ( intVal[j] == indexVal*(j+1) ) { } else { cerr << "Error: at " << j << " found " << intVal[j]; cerr << " instead of " << indexVal*(j+1) << endl; } } } }