/** * Return the confidence with with this algorithm can load the file * @param descriptor A descriptor for the file * @returns An integer specifying the confidence level. 0 indicates it will not * be used */ int LoadSpice2D::confidence(Kernel::FileDescriptor &descriptor) const { if (descriptor.extension() != ".xml") return 0; std::istream &is = descriptor.data(); int confidence(0); { // start of inner scope Poco::XML::InputSource src(is); // Set up the DOM parser and parse xml file DOMParser pParser; Poco::AutoPtr<Document> pDoc; try { pDoc = pParser.parse(&src); } catch (Poco::Exception &e) { throw Kernel::Exception::FileError("Unable to parse File (" + descriptor.filename() + ")", e.displayText()); } catch (...) { throw Kernel::Exception::FileError("Unable to parse File:", descriptor.filename()); } // Get pointer to root element Element *pRootElem = pDoc->documentElement(); if (pRootElem) { if (pRootElem->tagName() == "SPICErack") { confidence = 80; } } } // end of inner scope return confidence; }
/** * Return the confidence value that this algorithm can load the file * @param descriptor A descriptor for the file * @returns An integer specifying the confidence level. 0 indicates it will not * be used */ int LoadBBY::confidence(Kernel::FileDescriptor &descriptor) const { if (descriptor.extension() != ".tar") return 0; ANSTO::Tar::File file(descriptor.filename()); if (!file.good()) return 0; size_t hdfFiles = 0; size_t binFiles = 0; const std::vector<std::string> &subFiles = file.files(); for (const auto &subFile : subFiles) { auto len = subFile.length(); if ((len > 4) && (subFile.find_first_of("\\/", 0, 2) == std::string::npos)) { if ((subFile.rfind(".hdf") == len - 4) && (subFile.compare(0, 3, "BBY") == 0)) hdfFiles++; else if (subFile.rfind(".bin") == len - 4) binFiles++; } } return (hdfFiles == 1) && (binFiles == 1) ? 50 : 0; }
/** * Return the confidence with with this algorithm can load the file * @param descriptor A descriptor for the file * @returns An integer specifying the confidence level. 0 indicates it will not be used */ int LoadPreNexus::confidence(Kernel::FileDescriptor & descriptor) const { const std::string & filename = descriptor.filename(); if(filename.compare(filename.size()-12,12,"_runinfo.xml") == 0) return 80; else return 0; }
/** * Return the confidence with with this algorithm can load the file * @param descriptor A descriptor for the file * @returns An integer specifying the confidence level. 0 indicates it will not be used */ int LoadAscii::confidence(Kernel::FileDescriptor & descriptor) const { const std::string & filePath = descriptor.filename(); const size_t filenameLength = filePath.size(); // Avoid some known file types that have different loaders int confidence(0); if( filePath.compare(filenameLength - 12,12,"_runinfo.xml") == 0 || filePath.compare(filenameLength - 6,6,".peaks") == 0 || filePath.compare(filenameLength - 10,10,".integrate") == 0 ) { confidence = 0; } else if(descriptor.isAscii()) { confidence = 9; // Low so that others may try but not stopping version 2 } return confidence; }