// dataset_files.cxx // Command line interface to extract the physical files in a dataset. // // Syntax is // dataset_files [taskxml] // taskxml = name of input XML description of task (default task.xml) #include #include #include #include "dataset_util/FileStatus.h" #include "dataset_util/DtdRegistry.h" #include "dataset_file/LogicalFile.h" #include "dataset_xml/XmlParser.h" #include "dataset_xml/SimpleXmlDatasetDb.h" #include "dataset_base/Location.h" #include "dataset_base/Dataset.h" #include "dataset_base/DatasetCreator.h" using std::string; using std::cout; using std::endl; using std::ofstream; using dset::LogicalFile; using dset::Location; using dset::Dataset; using dset::DatasetCreator; using dset::SimpleXmlDatasetDb; typedef Location::LogicalFileList LFileList; typedef LogicalFile::Name Name; // So TestDataset can be used. #include "dataset_base/DatasetCreator_t.h" int main(int argc, char* argv[]) { // Read command line. string xmlfile = "dataset.xml"; bool help = false; if ( argc > 1 ) { string arg = argv[1]; if ( arg == "-h" ) { help = true; } else { xmlfile = arg; } } // Broadcast help if requested. if ( help ) { cout << "Usage: " << argv[0] << " [dstxml]" << endl; cout << " Default argument is dataset.xml" << endl; cout << "OUTPUT:" << endl; cout << " dstfiles.dat - holds the list of file names\n"; cout << " All the files in this list" << endl; cout << " dataset.dtd if not already present" << endl; return 0; } // Provide dataset DTD if absent. if ( ! FileStatus("dataset.dtd").exists() ) { DtdRegistry::instance("dataset").write(); } if ( ! FileStatus("dataset.dtd").exists() ) { cout << "Unable to find/generate dataset DTD" << endl; return 1; } // Open dataset. XmlParser xparser; const XmlElement* pele = xparser.parse(xmlfile); if ( pele == 0 ) { cout << "Unable to parse " << xmlfile << endl; return 3; } SimpleXmlDatasetDb ddb; const Dataset* pdst = DatasetCreator::create(*pele, &ddb); delete pele; if ( pdst == 0 ) { cout << "Unable to construct dataset" << endl; DatasetCreator::display(cout); cout << endl; return 4; } if ( ! pdst->is_valid() ) { cout << "Invalid dataset" << endl; return 5; } // Write the list of files. ofstream filelist("dstfiles.dat"); const Location& loc = pdst->location(); const LFileList& lfiles = loc.logical_files(); for ( LFileList::const_iterator ilfile=lfiles.begin(); ilfile!=lfiles.end(); ++ilfile ) { LogicalFile lfile(*ilfile); Name name = lfile.get_readonly(); if ( name == "" ) { cout << "Unable to fetch physical file for" << endl; cout << lfile << endl; } filelist << name << endl; } return 0; }