// hepAnonymous.cc -- tests ability to open arbitrary HepTuple-generated // files and determine types. // // Writing this file also tests documentation, as of March 2001. #define DONT_LINK_HISTO #include "HepTuple/HepFileManager.h" #include "HepTuple/hepTupleFileType.h" #include "HepTuple/newManager.h" #include "Exceptions/ZMexHandler.h" #include "HepTuple/HepHist1D.h" #include #include void add_a_histogram (HepFileManager * mgr, const std::string & histname, int x) { std::cout << "Adding histogram " << histname << " to manager for " << mgr->fileName() << " with " << x << " in bin 10 \n"; HepHist1D & h = mgr->hist1D (histname, 20, 0.0, 20.0); h.accumulate ( 9.7, x ); std::cout << "Checking: h.bin(9 - 11) are " << h.bin(9) << " " << h.bin(10) << " " << h.bin(11) << "\n"; } void tellType (const std::string & name) { HepTupleFileFormat f = hepTupleFileType (name); switch (f) { case HEPTUPLE_HBOOK: std::cout << name << " is an HBOOK file\n"; break; case HEPTUPLE_ROOT: std::cout << name << " is a ROOT file\n"; break; case HEPTUPLE_HISTOSCOPE: std::cout << name << " is a HISTOSCOPE file\n"; break; case HEPTUPLE_UNRECOGNIZED: std::cout << name << " is an unrecognized file\n"; break; case HEPTUPLE_CANTOPEN: std::cout << name << " could not be opened \n"; break; default: std::cout << name << " has impossible file type? \n"; } } void lookup ( HepFileManager * m, std::string hname, int x ) { HepHist1D & h = m->retrieveHist1D(hname); //int n = h.bin(10); // Original statement int n = (int)h.bin(10); std::cout << "Bin 10 of histogram " << hname << " has contents " << n << "\n"; if ( n!=x) { std::cout << "THAT IS THE WRONG NUMBER! \n"; } } int main () { //ZMexIgnoreAlways ignore; //ZMxHepBadIO::setHandler (ignore); //ZMxHepCantOpenFile::setHandler (ignore); // First, open up three new files with names A.ht, B.ht and C.ht. // Place a histogram into each. And close the files. std::cerr << "1\n"; #ifndef DONT_LINK_HBOOK HepFileManager *m1 = new HepHBookFileManager ( "A.ht" ); add_a_histogram (m1,"ahist",5); delete m1; #endif std::cerr << "2\n"; #ifndef DONT_LINK_ROOT HepFileManager *m2 = new HepRootFileManager ( "B.ht" ); add_a_histogram (m2,"bhist",7); delete m2; #endif std::cerr << "3\n"; #ifndef DONT_LINK_HISTO HepFileManager *m3 = new HepHistoFileManager ( "C.ht" ); add_a_histogram (m3,"chist",9); delete m3; #endif // Find the types of each file: tellType ( "A.ht" ); tellType ( "B.ht" ); tellType ( "C.ht" ); // Now open up the three files, and look at what is there... #ifndef DONT_LINK_HBOOK HepFileManager * ma = newManager ( "A.ht" ); lookup (ma,"ahist",5); delete ma; #endif #ifndef DONT_LINK_ROOT HepFileManager * mb = newManager ( "B.ht" ); lookup (mb,"bhist",7); delete mb; #endif #ifndef DONT_LINK_HISTO HepFileManager * mc = newManager ( "C.ht" ); lookup (mc,"chist",9); delete mc; #endif return 0; }