5 #include <boost/algorithm/string.hpp>
6 #include <boost/algorithm/string/replace.hpp>
18 std::stringstream
str;
26 if (!matchedString.empty())
27 boost::algorithm::replace_all(
result,
str.str(), matchedString);
35 const char* safe(
const char* iCheck) {
36 if (iCheck ==
nullptr) {
46 init(catUrl, iCatalog);
74 auto const protocol = safe(ruleElement->Attribute(
"protocol"));
75 auto destinationMatchRegexp = ruleElement->Attribute(
"destination-match");
76 if (destinationMatchRegexp ==
nullptr or destinationMatchRegexp[0] == 0) {
77 destinationMatchRegexp =
".*";
80 auto const pathMatchRegexp = safe(ruleElement->Attribute(
"path-match"));
81 auto const result = safe(ruleElement->Attribute(
"result"));
82 auto const chain = safe(ruleElement->Attribute(
"chain"));
86 rule.destinationMatch.assign(destinationMatchRegexp);
98 throw cms::Exception(
"TrivialFileCatalog",
"edm::SiteLocalConfigService is not available");
99 if (iCatalog >= localconfservice->dataCatalogs().size())
100 throw cms::Exception(
"TrivialFileCatalog",
"edm::FileLocator: Request nonexistence data catalog");
101 m_url = localconfservice->dataCatalogs()[iCatalog];
104 if (m_url.find(
"file:") == std::string::npos) {
106 "TrivialFileCatalog::connect: Malformed url for file catalog configuration");
109 m_url = m_url.erase(0, m_url.find(
':') + 1);
111 std::vector<std::string> tokens;
115 if (tokens.size() == 2) {
117 std::vector<std::string> optionTokens;
123 for (
size_t oi = 0, oe = optionTokens.size(); oi != oe; ++oi) {
125 std::vector<std::string> argTokens;
128 if (argTokens.size() != 2) {
130 "TrivialFileCatalog::connect: Malformed url for file catalog configuration");
133 if (argTokens[0] ==
"protocol") {
135 }
else if (argTokens[0] ==
"destination") {
143 "TrivialFileCatalog::connect: protocol was not supplied in the contact string");
146 std::ifstream configFile;
152 if (!configFile.good() || !configFile.is_open()) {
154 "TrivialFileCatalog::connect: Unable to open trivial file catalog " +
m_filename);
159 tinyxml2::XMLDocument
doc;
161 if (loadErr != tinyxml2::XML_SUCCESS) {
163 <<
"tinyxml file load failed with error : " <<
doc.ErrorStr() << std::endl;
176 auto rootElement =
doc.RootElement();
178 for (
auto el = rootElement->FirstChildElement(
"lfn-to-pfn"); el !=
nullptr;
179 el = el->NextSiblingElement(
"lfn-to-pfn")) {
184 for (
auto el = rootElement->FirstChildElement(
"pfn-to-lfn"); el !=
nullptr;
185 el = el->NextSiblingElement(
"pfn-to-lfn")) {
197 ProtocolRules::const_iterator
const rulesIterator = protocolRules.find(protocol);
198 if (rulesIterator == protocolRules.end()) {
202 Rules const&
rules = (*(rulesIterator)).second;
204 std::smatch destinationMatches;
205 std::smatch nameMatches;
208 for (Rules::const_iterator
i =
rules.begin();
i !=
rules.end(); ++
i) {
209 if (!std::regex_match(
destination, destinationMatches,
i->destinationMatch)) {
213 if (!std::regex_match(
name,
i->pathMatch)) {
220 if ((direct ==
true) && (!
chain.empty())) {
227 std::regex_match(
name, nameMatches,
i->pathMatch);
228 name = replaceWithRegexp(nameMatches,
i->result);
230 if ((direct ==
false) && (!
chain.empty())) {