/** * 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 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 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 LoadRKH::confidence(Kernel::FileDescriptor &descriptor) const { if (!descriptor.isAscii()) return 0; auto &file = descriptor.data(); std::string fileline(""); // Header looks something like this where the text inside [] could be anything // LOQ Thu 28-OCT-2004 12:23 [W 26 INST_DIRECT_BEAM] // -- First line -- std::getline(file, fileline); // LOQ or SANS2D (case insensitive) if (boost::ifind_first(fileline, "loq").empty() && boost::ifind_first(fileline, "sans2d").empty()) return 0; // Next should be date time string static const char *MONTHS[12] = {"-JAN-", "-FEB-", "-MAR-", "-APR-", "-MAY-", "-JUN-", "-JUL-", "-AUG-", "-SEP-", "-OCT-", "-NOV-", "-DEC-"}; bool foundMonth(false); for (auto &month : MONTHS) { if (!boost::ifind_first(fileline, month).empty()) { foundMonth = true; break; } } if (!foundMonth) return 0; // there are no constraints on the second line std::getline(file, fileline); // read 3rd line - should contain sequence "0 0 0 1" std::getline(file, fileline); if (fileline.find("0 0 0 1") == std::string::npos) return 0; // read 4th line - should contain sequence ""0 0 0 0" std::getline(file, fileline); if (fileline.find("0 0 0 0") == std::string::npos) return 0; // read 5th line - should contain sequence "3 (F12.5,2E16.6)" std::getline(file, fileline); if (fileline.find("3 (F12.5,2E16.6)") == std::string::npos) return 0; return 20; // Better than LoadAscii }
/** * 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; }
/** 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 LoadEventPreNexus2::confidence(Kernel::FileDescriptor &descriptor) const { if (descriptor.extension().rfind("dat") == std::string::npos) return 0; // If this looks like a binary file where the exact file length is a // multiple // of the DasEvent struct then we're probably okay. if (descriptor.isAscii()) return 0; const size_t objSize = sizeof(DasEvent); auto &handle = descriptor.data(); // get the size of the file in bytes and reset the handle back to the // beginning handle.seekg(0, std::ios::end); const size_t filesize = static_cast<size_t>(handle.tellg()); handle.seekg(0, std::ios::beg); if (filesize % objSize == 0) return 80; else return 0; }