// // This file primarly test the functionnality of the HepFileManagers. // // Zoom Histograms #include "TestManager.h" #include "HepTuple/HepHist1D.h" #include "ZMtools/pretendToUse.h" ZM_USING_NAMESPACE( zmht ) #include "ZMutility/iostream" USING( namespace std ) #ifdef USE_ROOT #include "HepTuple/HepRootObj.h" #include "HepTuple/HepRootHist1D.h" #endif void directories() { cout << "Create "; HepFileManager* manager = OPEN_FILE("dir"); if (manager == NULL ) { cerr << "Could not open file\n"; ::exit(-1); } cout << manager->fileName() << endl; string filename (manager->fileName()); if (file_type == HBOOK) { for(size_t i=0; i < filename.length(); i++ ) { filename[i] = toupper(filename[i]); } } cout << "Create the directories and cd to the lower one\n"; manager->mkdir("High"); manager->cd("High"); manager->mkdir("LowAndVeryLongDirectoryName"); manager->cd("LowAndVeryLongDirectoryName"); manager->mkdir("Lower"); manager->cd("Lower"); cout << "We are now at " << manager->pwd() << endl; cout << "cd(//" << filename << ")" << endl; manager->cd("//"+filename); cout << "We are now at " << manager->pwd() << endl; cout << "ls:\n" << manager->ls() << endl; cout << "ls High/LowAndVeryLongDirectoryName :\n" << manager->ls("High/LowAndVeryLongDirectoryName") << endl; cout << "Create a hist1D (High/LowAndVeryLongDirectoryName/dummy)\n"; manager->cd("High/LowAndVeryLongDirectoryName"); HepHist& hep = manager->hist1D("dummy", 10, 0.0, 11.0); cout << "Create a hist1D with an invalid name\n"; HepHist& invalid = manager->hist1D("withaslah/and more",10, 0.0, 11.0); pretendToUse(invalid); cout << "Create more directories\n"; manager->mkdir("Lower2"); cout << "Get a listing\n"; HepFileManager::ItemList l = manager->list("","1"); HepFileManager::ItemList::iterator i = l.begin(); while( i != l.end() ) { cout << "\"" << (*i).dir; cout << "\" has a Histogram 1D named: \"" << (*i).title; cout << "\" with type " << (*i).type << endl; i++; } cout << "cd()" << endl; manager->cd(""); cout << "We are now at " << manager->pwd() << endl; cout << "ls:\n" << manager->ls() << endl; cout << "ls High/LowAndVeryLongDirectoryName :\n" << manager->ls("High/LowAndVeryLongDirectoryName") << endl; cout << "Get a recursive listing of ONLY the directories:\n"; cout << manager->ls("//"+filename,"Dr") << endl; l = manager->list("//"+filename,"Dr"); i = l.begin(); while( i != l.end() ) { cout << "\"" << (*i).dir; cout << "\" has a directory named: \"" << (*i).title; cout << "\" with type " << (*i).type << endl; i++; } l[0]; manager->cd("High/LowAndVeryLongDirectoryName"); cout << "Test cd(xxx/../xxx)" << endl; cout << "Should end up in High/LowAndVeryLongDirectoryName " << endl; manager->cd("Lower2/../../LowAndVeryLongDirectoryName"); cout << "And we are in: " << manager->pwd() << endl; cout << "Testing rm and rmdir" << endl; cout << "Delete the hist1D\n"; hep.release(); manager->rm("dummy"); manager->cd(); cout << "ls:\n" << manager->ls() << endl; cout << "ls High/LowAndVeryLongDirectoryName :\n" << manager->ls("High/LowAndVeryLongDirectoryName") << endl; cout << "ls //"+filename+"/High:\n" << manager->ls("//"+filename+"/High") << endl; cout << "ls -r "+filename+":\n" << manager->ls("//"+filename+"","r") << endl; cout << "rmdir -r //"+filename+"/High" << endl; manager->rmdir("//"+filename+"/High",true); cout << "ls -r //"+filename+":\n" << manager->ls("//"+filename+"","r") << endl; delete manager; } int main(int argc, char** argv) { // This test program explicitly tries to make invalid // histogram and/or ntuple but we still want to run the complete // test! ZMxHepCantMakeHist::setHandler ( ZMexIgnoreAlways() ); ZMxHepCantMakeNtuple::setHandler ( ZMexIgnoreAlways() ); // get comandline arguments PARSE; directories(); return 0; }