// // 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/HepHist1DArray.h" #include "HepTuple/HepHist2DArray.h" #include "HepTuple/HepHistProfArray.h" #include "HepTuple/HepHist1D.h" #include "HepTuple/HepHist2D.h" #include "HepTuple/HepHistProf.h" ZM_USING_NAMESPACE( zmht ) USING( namespace std ) #include "ZMutility/iostream" #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 ) ) #ifndef FLT_EPSILON #define FLT_EPSILON 2.2204460492503131E-6 #endif #define IS_FLT_EQUAL(a,b) ( a == b \ || ( ::fabs( (a) - (b) ) < 100*FLT_EPSILON \ || ( ::fabs( (a) - (b) ) / (b) ) < 100*FLT_EPSILON ) ) const char objectTypes = 4; bool createHist1DArray ( HepFileManager * man, int size, const string& prefix, int nbins, float min, float max) { #ifdef HEPTRACE cerr << "Still attempting for man=" << man << " and size=" << size << " and prefix=" << prefix << " and nbins=" << nbins << " and min=" << min << " and max=" << max << endl; #endif HepHist1DArray& hists = man->hist1DArray( size, prefix, nbins, min, max); for ( int i = 0; i < size ; ++i ) { int bin = (int) ( nbins * ( (float)i/(float)size ) ); float where = min + ((max-min)/(float)nbins)*bin; // Could add fancy filling for ( int j = 0; j < 10; ++j ) { hists[i].accumulate( where ); } #ifdef HEPTRACE cerr << "In " << hists.title() << i << " We accumulated: " << hists[i].bin( bin+1 ) << " at " << where << " bin #" << bin+1 << endl; #endif } return true; } bool checkHist1DArray ( HepFileManager * man, int size, const string& prefix ) { bool status = true; HepHist1DArray& hists = man->retrieveHist1DArray( size, prefix ); int nbins = hists.nBins(); float min = hists.min(); float max = hists.max(); for ( int i = 0; i < size ; ++i ) { int bin = (int) ( nbins *( (float)i/(float)size ) ); float where = min + ((max-min)/(float)nbins)*bin; #ifdef HEP_TRACE cerr << "hist #" << i << " is : " << hists[i].title() << " " << hists[i].id() << " " << hists[i].dir() << " " << hists[i].nBins() << endl; #endif float val = hists[i].bin( bin+1 ); if ( ! IS_FLT_EQUAL ( 10, val ) ) { cerr << "In " << hists.title() << i << " we found " << val << " at " << where << " bin #" << bin+1 << endl; status = false; } } return status; } bool createHist2DArray ( HepFileManager * man, int size, const string& prefix, int nbinsX, float minX, float maxX, int nbinsY, float minY, float maxY) { HepHist2DArray& hists = man->hist2DArray( size, prefix, nbinsX, minX, maxX, nbinsY, minY, maxY); for ( int i = 0; i < size ; ++i ) { int binx = (int) ( nbinsX *( (float)i/(float)size ) ); int biny = (int) ( nbinsY *( (float)i/(float)size ) ); float whereX = minX + ((maxX-minX)/(float)nbinsX)*binx; float whereY = minY + ((maxY-minY)/(float)nbinsY)*biny; // Could add fancy filling for ( int j = 0; j < 10; ++j ) { hists[i].accumulate( whereX, whereY ); } } return true; } bool checkHist2DArray ( HepFileManager * man, int size, const string& prefix ) { bool status = true; HepHist2DArray& hists = man->retrieveHist2DArray( size, prefix ); int nbinsX = hists.nBinsX(); float minX = hists.minX(); float maxX = hists.maxX(); int nbinsY = hists.nBinsY(); float minY = hists.minY(); float maxY = hists.maxY(); for ( int i = 0; i < size ; ++i ) { int binx = (int) ( nbinsX *( (float)i/(float)size ) ); int biny = (int) ( nbinsY *( (float)i/(float)size ) ); float whereX = minX + ((maxX-minX)/(float)nbinsX)*binx; float whereY = minY + ((maxY-minY)/(float)nbinsY)*biny; float val = hists[i].bin( binx+1, biny+1 ); if ( ! IS_FLT_EQUAL ( 10, val ) ) { cerr << "In " << hists.title() << i << " we found " << val << " at " << whereX << "," << whereY << " bin #" << binx+1 << "," << biny+1 << endl; status = false; } } return status; } bool createHistProfArray ( HepFileManager * man, int size, const string& prefix, int nbinsX, float minX, float maxX, float minY, float maxY) { HepHistProfArray& hists = man->histProfArray( size, prefix, nbinsX, minX, maxX, minY, maxY); for ( int i = 0; i < size ; ++i ) { int binx = (int) ( nbinsX *( (float)i/(float)size ) ); float whereX = minX + ((maxX-minX)/(float)nbinsX)*binx; float whereY = minY + ((maxY-minY)/(float)nbinsX)*binx; // Could add fancy filling for ( int j = 0; j < 10; ++j ) { hists[i].accumulate( whereX, whereY ); } } return true; } bool checkHistProfArray ( HepFileManager * man, int size, const string& prefix ) { bool status = true; HepHistProfArray& hists = man->retrieveHistProfArray( size, prefix ); int nbinsX = hists.nBinsX(); float minX = hists.minX(); float maxX = hists.maxX(); float minY = hists.minY(); float maxY = hists.maxY(); for ( int i = 0; i < size ; ++i ) { int binx = (int) ( nbinsX *( (float)i/(float)size ) ); float whereX = minX + ((maxX-minX)/(float)nbinsX)*binx; float whereY = minY + ((maxY-minY)/(float)nbinsX)*binx; float val = hists[i].bin( binx+1 ); if ( ! IS_FLT_EQUAL ( whereY, val ) ) { cerr << "In " << hists.title() << i << " we found " << val << " at " << whereX << "," << whereY << " bin #" << binx+1 << endl; status = false; } } return status; } bool cloneHist1DArray ( HepFileManager * from , HepFileManager * to, int size, const string & prefix ) { HepHist1DArray & hists = from->retrieveHist1DArray( size, prefix ); hists.makeClone ( to, from->fileName() + "_" + prefix ); return true; } bool cloneHist2DArray ( HepFileManager * from , HepFileManager * to, int size, const string & prefix ) { HepHist2DArray & hists = from->retrieveHist2DArray( size, prefix ); hists.makeClone ( to, from->fileName() + "_" + prefix ); return true; } bool cloneHistProfArray ( HepFileManager * from , HepFileManager * to, int size, const string & prefix ) { HepHistProfArray & hists = from->retrieveHistProfArray( size, prefix ); hists.makeClone ( to, from->fileName() + "_" + prefix ); return true; } int main (int argc, char** argv) { // ZMxHepUnknownHepObj::setHandler ( ZMexIgnoreAlways() ); HepFileManager* files[3] = { 0, 0, 0 }; string managerType[3]; bool unimplemented[3][objectTypes]; int nFiles = 0; int i, j; for ( i = 0; i < 3 ; i++ ) for ( j = 0; j < objectTypes; j++ ) unimplemented[i][j] = false; #ifdef USE_HBOOK files[nFiles] = OPEN_HBOOK_FILE("histarray"); managerType[nFiles] = "hbook"; if ( files[nFiles] != NULL ) nFiles++; #endif #ifdef USE_HISTOSCOPE files[nFiles] = OPEN_HISTO_FILE("histarray"); managerType[nFiles] = "histoscope"; unimplemented[nFiles][2] = true; // no histogram profile if ( files[nFiles] != NULL ) nFiles++; #endif #ifdef USE_ROOT files[nFiles] = OPEN_ROOT_FILE("histarray"); managerType[nFiles] = "root"; unimplemented[nFiles][3] = true; // no ntuple if ( files[nFiles] != NULL ) nFiles++; #endif // build original content for ( i = 0; i < nFiles; i++ ) { if (!unimplemented[i][0]) createHist1DArray( files[i], 10, "array1D_", 10, -5, 5 ); if (!unimplemented[i][1]) createHist2DArray( files[i], 10, "array2D_", 10, -5, 5, 10, -5, 5 ); if (!unimplemented[i][2]) createHistProfArray( files[i], 10, "arrayProf_", 10, -5, 5, -5, 5 ); } for ( i = 0; i < nFiles; ++i ) { for ( j = 0; j < nFiles; ++j ) { if (!unimplemented[i][0] && !unimplemented[j][0]) cloneHist1DArray( files[i], files[j], 10, "array1D_" ); if (!unimplemented[i][1] && !unimplemented[j][1]) cloneHist2DArray( files[i], files[j], 10, "array2D_" ); if (!unimplemented[i][2] && !unimplemented[j][2]) cloneHistProfArray( files[i], files[j], 10, "arrayProf_" ); } } // histarray it to all the managers for ( i = 0; i < nFiles; ++i ) { if (!unimplemented[i][0]) checkHist1DArray( files[i], 10, "array1D_" ); if (!unimplemented[i][1]) checkHist2DArray( files[i], 10, "array2D_" ); if (!unimplemented[i][2]) checkHistProfArray( files[i], 10, "arrayProf_" ); for ( j = 0; j < nFiles; ++j) { if (!unimplemented[i][0] && !unimplemented[j][0]) checkHist1DArray( files[j], 10, files[i]->fileName() + "_" + "array1D_" ); if (!unimplemented[i][1] && !unimplemented[j][1]) checkHist2DArray( files[j], 10, files[i]->fileName() + "_" + "array2D_"); if (!unimplemented[i][2] && !unimplemented[j][2]) checkHistProfArray( files[j], 10, files[i]->fileName() + "_" + "arrayProf_"); } } // List final content for ( i = 0; i < nFiles; i++ ) { cerr << files[i]->ls("","r"); } nFiles = 0; #ifdef USE_HBOOK delete files[nFiles]; files[nFiles] = OPEN_HBOOK_FILE("histarray"); managerType[nFiles] = "hbook"; if ( files[nFiles] != NULL ) nFiles++; #endif #ifdef USE_HISTOSCOPE delete files[nFiles]; files[nFiles] = OPEN_HISTO_FILE("histarray"); managerType[nFiles] = "histoscope"; unimplemented[nFiles][3] = true; // no histogram profile if ( files[nFiles] != NULL ) nFiles++; #endif #ifdef USE_ROOT delete files[nFiles]; files[nFiles] = OPEN_ROOT_FILE("histarray"); managerType[nFiles] = "root"; unimplemented[nFiles][0] = true; // no ntuple if ( files[nFiles] != NULL ) nFiles++; #endif for ( i = 0; i < nFiles; i++ ) { if (!unimplemented[i][0]) checkHist1DArray( files[i], 10, "array1D_" ); if (!unimplemented[i][1]) checkHist2DArray( files[i], 10, "array2D_" ); if (!unimplemented[i][2]) checkHistProfArray( files[i], 10, "arrayProf_" ); } return 0; }