5 #include <xercesc/parsers/XercesDOMParser.hpp>
6 #include <xercesc/util/PlatformUtils.hpp>
8 #include <boost/algorithm/string.hpp>
9 #include <boost/algorithm/string/replace.hpp>
17 using namespace xercesc;
27 XMLCh* buff = XMLString::transcode(temp.c_str());
32 replaceWithRegexp(boost::smatch
const& matches,
35 std::stringstream str;
38 for (
size_t i = 1;
i < matches.size(); ++
i) {
43 if (!matchedString.empty())
44 boost::algorithm::replace_all(result, str.str(), matchedString);
53 int FileLocator::s_numberOfInstances = 0;
55 FileLocator::FileLocator(
std::string const& catUrl,
bool fallback)
56 : m_destination(
"any") {
61 XMLPlatformUtils::Initialize();
64 catch (XMLException
const&
e) {
73 init(catUrl, fallback);
113 DOMElement* ruleElement =
static_cast<DOMElement *
>(ruleNode);
118 if (destinationMatchRegexp.empty()) {
119 destinationMatchRegexp =
".*";
131 rule.destinationMatch.assign(destinationMatchRegexp);
134 rules[protocol].push_back(rule);
144 throw cms::Exception(
"TrivialFileCatalog",
"edm::SiteLocalConfigService is not available");
146 m_url = (fallback ? localconfservice->fallbackDataCatalog() : localconfservice->dataCatalog());
151 if (m_url.find(
"file:") == std::string::npos) {
152 throw cms::Exception(
"TrivialFileCatalog",
"TrivialFileCatalog::connect: Malformed url for file catalog configuration");
155 m_url = m_url.erase(0, m_url.find(
":") + 1);
157 std::vector<std::string> tokens;
161 if (tokens.size() == 2) {
163 std::vector<std::string> optionTokens;
169 for (
size_t oi = 0, oe = optionTokens.size(); oi != oe; ++oi) {
171 std::vector<std::string> argTokens;
174 if (argTokens.size() != 2) {
175 throw cms::Exception(
"TrivialFileCatalog",
"TrivialFileCatalog::connect: Malformed url for file catalog configuration");
178 if (argTokens[0] ==
"protocol") {
180 }
else if (argTokens[0] ==
"destination") {
187 throw cms::Exception(
"TrivialFileCatalog",
"TrivialFileCatalog::connect: protocol was not supplied in the contact string");
196 if (!configFile.good() || !configFile.is_open()) {
197 throw cms::Exception(
"TrivialFileCatalog",
"TrivialFileCatalog::connect: Unable to open trivial file catalog " +
m_filename);
202 XercesDOMParser*
parser =
new XercesDOMParser;
203 parser->setValidationScheme(XercesDOMParser::Val_Auto);
204 parser->setDoNamespaces(
false);
206 DOMDocument*
doc = parser->getDocument();
223 DOMNodeList*
rules = doc->getElementsByTagName(
_toDOMS(
"lfn-to-pfn"));
224 unsigned int const ruleTagsNum = rules->getLength();
228 for (
unsigned int i = 0;
i < ruleTagsNum; ++
i) {
229 DOMNode* ruleNode = rules->item(
i);
235 DOMNodeList*
rules = doc->getElementsByTagName(
_toDOMS(
"pfn-to-lfn"));
236 unsigned int ruleTagsNum = rules->getLength();
238 for (
unsigned int i = 0;
i < ruleTagsNum; ++
i) {
239 DOMNode* ruleNode = rules->item(
i);
254 ProtocolRules::const_iterator
const rulesIterator = protocolRules.find(protocol);
255 if (rulesIterator == protocolRules.end()) {
259 Rules const&
rules = (*(rulesIterator)).second;
261 boost::smatch destinationMatches;
262 boost::smatch nameMatches;
265 for (Rules::const_iterator
i = rules.begin();
i != rules.end(); ++
i) {
267 if (!boost::regex_match(destination, destinationMatches,
i->destinationMatch)) {
271 if (!boost::regex_match(name,
i->pathMatch)) {
278 if ((direct ==
true) && (chain !=
"")) {
279 name =
applyRules(protocolRules, chain, destination, direct, name);
285 boost::regex_match(name, nameMatches,
i->pathMatch);
286 name = replaceWithRegexp(nameMatches,
i->result);
288 if ((direct ==
false) && (chain !=
"")) {
289 name =
applyRules(protocolRules, chain, destination, direct, name);
std::map< std::string, Rules > ProtocolRules
static int s_numberOfInstances
std::string lfn(std::string const &ipfn) const
std::string m_destination
std::string _toString(const XMLCh *toTranscode)
U second(std::pair< T, U > const &p)
ProtocolRules m_inverseRules
std::string convert(std::string const &input, ProtocolRules const &rules, bool direct) const
std::string pfn(std::string const &ilfn) const
ProtocolRules m_directRules
std::vector< Rule > Rules
void parseRule(xercesc::DOMNode *ruleNode, ProtocolRules &rules)
std::vector< std::vector< double > > tmp
std::vector< std::string > m_protocols
XMLCh * _toDOMS(std::string temp)
std::string applyRules(ProtocolRules const &protocolRules, std::string const &protocol, std::string const &destination, bool direct, std::string name) const
void init(std::string const &catUrl, bool fallback)