#include "HepTuple/HepFileManager.h" #include "HepTuple/HepHBookFileManager.h" #include "HepTuple/HepHist1D.h" #include #include USING( namespace std ) void makeDirectory(HepFileManager* fileMan, const std::string& dir) { std::string oldDir = fileMan->pwd(); cout << " Initial directory for " << (string) fileMan->fileName() << ": " << oldDir << endl; cout << " Attempting to make directory " << dir << " in " \ << fileMan->fileName() << " ... " << endl; fileMan->mkdir(dir); cout << "done." << endl; } std::string changeDirectory(HepFileManager* fileMan, const std::string& dir) { std::string tmp = fileMan->pwd(); fileMan->cd(dir); cout << "Changed HepTuple directory from " << tmp << " to " << fileMan->pwd() << endl;; return tmp; } int main (void) { // minimal test case to expose HepTuple bug changing directories with // multiple filemanagers std::string fileA = "testA.rz"; std::string fileB = "testB.rz"; std::string dirA = "efficiency"; std::string dirB = "purity"; HepFileManager* manA = new HepHBookFileManager(fileA); // Create a directory in the first file, cd to it and make a histogram makeDirectory(manA,dirA); std::string oldDirA = changeDirectory(manA,dirA); cout << "Making a histogram in this directory ... "; HepHist1D& junkA = manA->hist1D("junk",50,0.0,50.0); cout << "done" << endl; cout << "Changing directory back to " << oldDirA << endl; changeDirectory(manA,oldDirA); // Create a directory in the second file, cd to it and make a histogram HepFileManager* manB = new HepHBookFileManager(fileB); makeDirectory(manB,dirB); std::string oldDirB = changeDirectory(manB,dirB); cout << "Making a histogram in this directory (" << manB->pwd() << ") ... "; HepHist1D& junkB = manB->hist1D("junk",50,0.0,50.0); cout << "done" << endl; cout << "Changing directory back to " << oldDirB << endl; changeDirectory(manB,oldDirB); // Now go back to the first file and fill our histogram: cout << "Accumulate histogram for manager " << manA->fileName() << endl; junkA.accumulate(25.0); // Now go back to the second file and fill our histogram: cout << "Accumulate histogram for manager " << manB->fileName() << endl; junkB.accumulate(50.0); // finish oldDirA = changeDirectory(manA,dirA); manA->writeDirectory(); // not absolutely needed since you delete next: changeDirectory(manA,oldDirA); delete manA; oldDirB = changeDirectory(manB,dirB); manB->writeDirectory(); // not absolutely needed since you delete next: changeDirectory(manB,oldDirB); delete manB; return 0; }