#include <FileLocator.h>
Classes | |
struct | Rule |
Public Member Functions | |
FileLocator (std::string const &catUrl, bool fallback) | |
std::string | lfn (std::string const &ipfn) const |
std::string | pfn (std::string const &ilfn) const |
~FileLocator () | |
Private Types | |
typedef std::map< std::string, Rules > | ProtocolRules |
typedef std::vector< Rule > | Rules |
Private Member Functions | |
std::string | applyRules (ProtocolRules const &protocolRules, std::string const &protocol, std::string const &destination, bool direct, std::string name) const |
std::string | convert (std::string const &input, ProtocolRules const &rules, bool direct) const |
void | init (std::string const &catUrl, bool fallback) |
void | parseRule (xercesc::DOMNode *ruleNode, ProtocolRules &rules) |
Private Attributes | |
std::string | m_destination |
ProtocolRules | m_directRules |
std::string | m_filename |
std::string | m_fileType |
ProtocolRules | m_inverseRules |
std::vector< std::string > | m_protocols |
Static Private Attributes | |
static int | s_numberOfInstances = 0 |
Definition at line 13 of file FileLocator.h.
typedef std::map<std::string, Rules> edm::FileLocator::ProtocolRules [private] |
Definition at line 36 of file FileLocator.h.
typedef std::vector<Rule> edm::FileLocator::Rules [private] |
Definition at line 35 of file FileLocator.h.
edm::FileLocator::FileLocator | ( | std::string const & | catUrl, |
bool | fallback | ||
) | [explicit] |
Definition at line 55 of file FileLocator.cc.
References _toString(), Exception, init(), and s_numberOfInstances.
: m_destination("any") { try { // << "Xerces-c initialization Number " // << s_numberOfInstances << if (s_numberOfInstances == 0) { XMLPlatformUtils::Initialize(); } } catch (XMLException const& e) { // << "Xerces-c error in initialization \n" // << "Exception message is: \n" // << _toString(e.getMessage()) << throw cms::Exception(std::string("Fatal Error on edm::FileLocator:")+ _toString(e.getMessage())); } ++s_numberOfInstances; init(catUrl, fallback); // std::cout << m_protocols.size() << " protocols" << std::endl; // std::cout << m_directRules[m_protocols[0]].size() << " rules" << std::endl; }
edm::FileLocator::~FileLocator | ( | ) |
Definition at line 79 of file FileLocator.cc.
{}
std::string edm::FileLocator::applyRules | ( | ProtocolRules const & | protocolRules, |
std::string const & | protocol, | ||
std::string const & | destination, | ||
bool | direct, | ||
std::string | name | ||
) | const [private] |
Definition at line 246 of file FileLocator.cc.
References i, mergeVDriftHistosByStation::name, and cmsCodeRulesChecker::rules.
Referenced by convert().
{ // std::cerr << "Calling apply rules with protocol: " << protocol << "\n destination: " << destination << "\n " << " on name " << name << std::endl; ProtocolRules::const_iterator const rulesIterator = protocolRules.find(protocol); if (rulesIterator == protocolRules.end()) { return ""; } Rules const& rules = (*(rulesIterator)).second; boost::smatch destinationMatches; boost::smatch nameMatches; /* Look up for a matching rule*/ for (Rules::const_iterator i = rules.begin(); i != rules.end(); ++i) { if (!boost::regex_match(destination, destinationMatches, i->destinationMatch)) { continue; } if (!boost::regex_match(name, i->pathMatch)) { continue; } // std::cerr << "Rule " << i->pathMatch << "matched! " << std::endl; std::string const chain = i->chain; if ((direct == true) && (chain != "")) { name = applyRules(protocolRules, chain, destination, direct, name); if (name.empty()) { return ""; } } boost::regex_match(name, nameMatches, i->pathMatch); name = replaceWithRegexp(nameMatches, i->result); if ((direct == false) && (chain != "")) { name = applyRules(protocolRules, chain, destination, direct, name); } return name; } return ""; }
std::string edm::FileLocator::convert | ( | std::string const & | input, |
ProtocolRules const & | rules, | ||
bool | direct | ||
) | const [private] |
Definition at line 94 of file FileLocator.cc.
References applyRules(), m_destination, m_protocols, dbtoconf::out, and pi.
Referenced by lfn(), and pfn().
{ std::string out = ""; for (size_t pi = 0, pe = m_protocols.size(); pi != pe; ++pi) { out = applyRules(rules, m_protocols[pi], m_destination, direct, input); if (!out.empty()) return out; } return out; }
void edm::FileLocator::init | ( | std::string const & | catUrl, |
bool | fallback | ||
) | [private] |
Definition at line 138 of file FileLocator.cc.
References _toDOMS(), findQualityFiles::comma, HDQMDatabaseProducer::configFile, asciidump::doc, Exception, i, edm::Service< T >::isAvailable(), m_destination, m_directRules, m_filename, m_inverseRules, m_protocols, loadConditions::options, geometryXMLtoCSV::parser, parseRule(), cmsCodeRulesChecker::rules, edm::split(), and EcalElecEmulTccFlatFileProducerFromTPG_cfg::tokens.
Referenced by FileLocator().
{ std::string m_url = catUrl; if (m_url.empty()) { Service<SiteLocalConfig> localconfservice; if (!localconfservice.isAvailable()) throw cms::Exception("edm::SiteLocalConfigService is not available"); m_url = (fallback ? localconfservice->fallbackDataCatalog() : localconfservice->dataCatalog()); } // std::cout << "Connecting to the catalog " << m_url << std::endl; if (m_url.find("file:") == std::string::npos) { throw cms::Exception("TrivialFileCatalog::connect: Malformed url for file catalog configuration"); } m_url = m_url.erase(0, m_url.find(":") + 1); std::vector<std::string> tokens; boost::algorithm::split(tokens, m_url, boost::is_any_of(std::string("?"))); m_filename = tokens[0]; if (tokens.size() == 2) { std::string const options = tokens[1]; std::vector<std::string> optionTokens; boost::algorithm::split(optionTokens, options, boost::is_any_of(std::string("&"))); std::string const equalSign("="); std::string const comma(","); for (size_t oi = 0, oe = optionTokens.size(); oi != oe; ++oi) { std::string const option = optionTokens[oi]; std::vector<std::string> argTokens; boost::algorithm::split(argTokens, option, boost::is_any_of(equalSign)); if (argTokens.size() != 2) { throw cms::Exception("TrivialFileCatalog::connect: Malformed url for file catalog configuration"); } if (argTokens[0] == "protocol") { boost::algorithm::split(m_protocols, argTokens[1], boost::is_any_of(comma)); } else if (argTokens[0] == "destination") { m_destination = argTokens[1]; } } } if (m_protocols.empty()) { throw cms::Exception("TrivialFileCatalog::connect: protocol was not supplied in the contact string"); } std::ifstream configFile; configFile.open(m_filename.c_str()); // // std::cout << "Using catalog configuration " << m_filename << std::endl; if (!configFile.good() || !configFile.is_open()) { throw cms::Exception("TrivialFileCatalog::connect: Unable to open trivial file catalog " + m_filename); } configFile.close(); XercesDOMParser* parser = new XercesDOMParser; parser->setValidationScheme(XercesDOMParser::Val_Auto); parser->setDoNamespaces(false); parser->parse(m_filename.c_str()); DOMDocument* doc = parser->getDocument(); assert(doc); /* trivialFileCatalog matches the following xml schema FIXME: write a proper DTD <storage-mapping> <lfn-to-pfn protocol="direct" destination-match=".*" path-match="lfn/guid match regular expression" result="/castor/cern.ch/cms/$1"/> <pfn-to-lfn protocol="srm" path-match="lfn/guid match regular expression" result="$1"/> </storage-mapping> */ /*first of all do the lfn-to-pfn bit*/ { DOMNodeList* rules = doc->getElementsByTagName(_toDOMS("lfn-to-pfn")); unsigned int const ruleTagsNum = rules->getLength(); // FIXME: we should probably use a DTD for checking validity for (unsigned int i = 0; i < ruleTagsNum; ++i) { DOMNode* ruleNode = rules->item(i); parseRule(ruleNode, m_directRules); } } /*Then we handle the pfn-to-lfn bit*/ { DOMNodeList* rules = doc->getElementsByTagName(_toDOMS("pfn-to-lfn")); unsigned int ruleTagsNum = rules->getLength(); for (unsigned int i = 0; i < ruleTagsNum; ++i) { DOMNode* ruleNode = rules->item(i); parseRule(ruleNode, m_inverseRules); } } }
std::string edm::FileLocator::lfn | ( | std::string const & | ipfn | ) | const |
Definition at line 89 of file FileLocator.cc.
References convert(), and m_inverseRules.
{ return convert(ipfn, m_inverseRules, false); }
void edm::FileLocator::parseRule | ( | xercesc::DOMNode * | ruleNode, |
ProtocolRules & | rules | ||
) | [private] |
Definition at line 106 of file FileLocator.cc.
References _toDOMS(), _toString(), Exception, edm::FileLocator::Rule::pathMatch, and query::result.
Referenced by init().
{ if (!ruleNode) { throw cms::Exception(std::string("TrivialFileCatalog::connect: Malformed trivial catalog")); } // ruleNode is actually always a DOMElement because it's the result of // a `getElementsByTagName()` in the calling method. DOMElement* ruleElement = static_cast<DOMElement *>(ruleNode); std::string const protocol = _toString(ruleElement->getAttribute(_toDOMS("protocol"))); std::string destinationMatchRegexp = _toString(ruleElement->getAttribute(_toDOMS("destination-match"))); if (destinationMatchRegexp.empty()) { destinationMatchRegexp = ".*"; } std::string const pathMatchRegexp = _toString(ruleElement->getAttribute(_toDOMS("path-match"))); std::string const result = _toString(ruleElement->getAttribute(_toDOMS("result"))); std::string const chain = _toString(ruleElement->getAttribute(_toDOMS("chain"))); Rule rule; rule.pathMatch.assign(pathMatchRegexp); rule.destinationMatch.assign(destinationMatchRegexp); rule.result = result; rule.chain = chain; rules[protocol].push_back(rule); }
std::string edm::FileLocator::pfn | ( | std::string const & | ilfn | ) | const |
Definition at line 84 of file FileLocator.cc.
References convert(), and m_directRules.
{ return convert(ilfn, m_directRules, true); }
std::string edm::FileLocator::m_destination [private] |
Definition at line 59 of file FileLocator.h.
ProtocolRules edm::FileLocator::m_directRules [private] |
Direct rules are used to do the mapping from LFN to PFN.
Definition at line 52 of file FileLocator.h.
std::string edm::FileLocator::m_filename [private] |
Definition at line 57 of file FileLocator.h.
Referenced by init().
std::string edm::FileLocator::m_fileType [private] |
Definition at line 56 of file FileLocator.h.
Inverse rules are used to do the mapping from PFN to LFN
Definition at line 54 of file FileLocator.h.
std::vector<std::string> edm::FileLocator::m_protocols [private] |
Definition at line 58 of file FileLocator.h.
int edm::FileLocator::s_numberOfInstances = 0 [static, private] |
For the time being the only allowed configuration item is a prefix to be added to the GUID/LFN.
Definition at line 26 of file FileLocator.h.
Referenced by FileLocator().