5 #include <boost/algorithm/string.hpp>
6 #include <boost/algorithm/string/replace.hpp>
18 std::stringstream
str;
21 for (
size_t i = 1;
i < matches.size(); ++
i) {
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);
89 rules[protocol].emplace_back(
std::move(rule));
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");
152 if (!configFile.good() || !configFile.is_open()) {
154 "TrivialFileCatalog::connect: Unable to open trivial file catalog " +
m_filename);
159 tinyxml2::XMLDocument doc;
160 auto loadErr = doc.LoadFile(
m_filename.c_str());
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())) {
221 name =
applyRules(protocolRules, chain, destination, direct, name);
227 std::regex_match(name, nameMatches, i->pathMatch);
228 name = replaceWithRegexp(nameMatches, i->result);
230 if ((direct ==
false) && (!chain.empty())) {
231 name =
applyRules(protocolRules, chain, destination, direct, name);
std::map< std::string, Rules > ProtocolRules
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
std::string lfn(std::string const &ipfn) const
std::string m_destination
void init(std::string const &catUrl, unsigned iCatalog)
static std::string const input
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
FileLocator(std::string const &catUrl, unsigned iCatalog=0)
ProtocolRules m_directRules
static const char kEmptyString[1]
std::vector< Rule > Rules
std::vector< std::string > m_protocols
void parseRule(tinyxml2::XMLElement *ruleNode, ProtocolRules &rules)
std::string applyRules(ProtocolRules const &protocolRules, std::string const &protocol, std::string const &destination, bool direct, std::string name) const