5 #include <boost/algorithm/string.hpp> 6 #include <boost/algorithm/string/replace.hpp> 7 #include <boost/property_tree/json_parser.hpp> 15 namespace pt = boost::property_tree;
21 std::stringstream
str;
27 if (!matchedString.empty())
28 boost::algorithm::replace_all(
result,
str.str(), matchedString);
34 constexpr
char const*
const kLFNPrefix =
"/store/";
36 const char* safe(
const char* iCheck) {
37 if (iCheck ==
nullptr) {
45 namespace pt = boost::property_tree;
56 : m_destination(
"any") {
57 init(catAttr, iCatalog, storageDescriptionPath);
71 if (
input.compare(0, 7, kLFNPrefix) != 0)
95 auto const protocol = safe(ruleElement->Attribute(
"protocol"));
96 auto destinationMatchRegexp = ruleElement->Attribute(
"destination-match");
97 if (destinationMatchRegexp ==
nullptr or destinationMatchRegexp[0] == 0) {
98 destinationMatchRegexp =
".*";
101 auto const pathMatchRegexp = safe(ruleElement->Attribute(
"path-match"));
102 auto const result = safe(ruleElement->Attribute(
"result"));
103 auto const chain = safe(ruleElement->Attribute(
"chain"));
107 rule.destinationMatch.assign(destinationMatchRegexp);
116 if (storageRule.second.empty()) {
117 throw cms::Exception(
"RucioFileCatalog",
"edm::FileLocator::parseRule Malformed storage rule");
119 auto const pathMatchRegexp = storageRule.second.get<
std::string>(
"lfn");
123 rule.destinationMatch.assign(
".*");
134 throw cms::Exception(
"TrivialFileCatalog",
"edm::SiteLocalConfigService is not available");
135 if (iCatalog >= localconfservice->trivialDataCatalogs().size())
136 throw cms::Exception(
"TrivialFileCatalog",
"edm::FileLocator: Request nonexistence data catalog");
137 url = localconfservice->trivialDataCatalogs()[iCatalog];
140 if (
url.find(
"file:") == std::string::npos) {
142 "TrivialFileCatalog::connect: Malformed url for file catalog configuration");
147 std::vector<std::string> tokens;
151 if (tokens.size() == 2) {
153 std::vector<std::string> optionTokens;
159 for (
size_t oi = 0, oe = optionTokens.size(); oi != oe; ++oi) {
161 std::vector<std::string> argTokens;
164 if (argTokens.size() != 2) {
166 "TrivialFileCatalog::connect: Malformed url for file catalog configuration");
169 if (argTokens[0] ==
"protocol") {
171 }
else if (argTokens[0] ==
"destination") {
179 "TrivialFileCatalog::connect: protocol was not supplied in the contact string");
187 "TrivialFileCatalog::connect: Unable to open trivial file catalog " +
m_filename);
192 tinyxml2::XMLDocument
doc;
194 if (loadErr != tinyxml2::XML_SUCCESS) {
196 <<
"tinyxml file load failed with error : " <<
doc.ErrorStr() << std::endl;
209 auto rootElement =
doc.RootElement();
211 for (
auto el = rootElement->FirstChildElement(
"lfn-to-pfn"); el !=
nullptr;
212 el = el->NextSiblingElement(
"lfn-to-pfn")) {
217 for (
auto el = rootElement->FirstChildElement(
"pfn-to-lfn"); el !=
nullptr;
218 el = el->NextSiblingElement(
"pfn-to-lfn")) {
228 if (input_dataCatalog.
empty()) {
231 ex <<
"edm::SiteLocalConfigService is not available";
232 ex.
addContext(
"Calling edm::FileLocator::init()");
235 if (iCatalog >= localconfservice->dataCatalogs().size()) {
237 ex <<
"Request nonexistence data catalog";
238 ex.
addContext(
"Calling edm::FileLocator::init()");
241 aCatalog = localconfservice->dataCatalogs()[iCatalog];
247 if (!storageDescriptionPath.empty())
248 filename_storage = storageDescriptionPath;
253 boost::property_tree::read_json(filename_storage.string(),
json);
256 ex <<
"Can not open storage.json (" << filename_storage.string()
257 <<
"). Check SITECONFIG_PATH and site-local-config.xml <data-access>";
270 if (found_site ==
json.end()) {
272 ex <<
"Can not find storage site \"" << aCatalog.
storageSite <<
"\" and volume \"" << aCatalog.
volume 273 <<
"\" in storage.json. Check site-local-config.xml <data-access> and storage.json";
278 const pt::ptree& protocols = found_site->second.find(
"protocols")->second;
281 return aCatalog.
protocol == protName;
285 if (found_protocol == protocols.end()) {
287 ex <<
"Can not find protocol \"" << aCatalog.
protocol <<
"\" for the storage site \"" << aCatalog.
storageSite 288 <<
"\" and volume \"" << aCatalog.
volume 289 <<
"\" in storage.json. Check site-local-config.xml <data-access> and storage.json";
299 if (found_protocol->second.find(
"rules") == found_protocol->second.not_found()) {
301 ex <<
"protocol must contain either a prefix or rules, " 302 <<
"neither found for protocol \"" << aCatalog.
protocol <<
"\" for the storage site \"" 304 <<
"\" in storage.json. Check site-local-config.xml <data-access> and storage.json";
308 const pt::ptree&
rules = found_protocol->second.find(
"rules")->second;
321 ProtocolRules::const_iterator
const rulesIterator = protocolRules.find(
protocol);
322 if (rulesIterator == protocolRules.end()) {
326 Rules const&
rules = (*(rulesIterator)).second;
328 std::smatch destinationMatches;
329 std::smatch nameMatches;
332 for (Rules::const_iterator
i =
rules.begin();
i !=
rules.end(); ++
i) {
333 if (!std::regex_match(
destination, destinationMatches,
i->destinationMatch)) {
337 if (!std::regex_match(
name,
i->pathMatch)) {
344 if ((direct ==
true) && (!chain.empty())) {
351 std::regex_match(
name, nameMatches,
i->pathMatch);
352 name = replaceWithRegexp(nameMatches,
i->result);
354 if ((direct ==
false) && (!chain.empty())) {
ProtocolRules m_directRules_trivialCatalog
std::map< std::string, Rules > ProtocolRules
FileLocator(edm::CatalogAttributes const &catAttr, unsigned iCatalog=0, std::string const &storageDescriptionPath=std::string())
std::string m_destination
std::string pfn(std::string const &ilfn, edm::CatalogType catType) const
static std::string const input
U second(std::pair< T, U > const &p)
Container::value_type value_type
ProtocolRules m_inverseRules
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::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
def split(sequence, size)
void init_trivialCatalog(std::string const &catUrl, unsigned iCatalog)
void init(edm::CatalogAttributes const &input_dataCatalog, unsigned iCatalog, std::string const &storageDescriptionPath)
void addContext(std::string const &context)
ProtocolRules m_directRules
static const char kEmptyString[1]
std::vector< Rule > Rules
std::vector< std::string > m_protocols
void parseRuleTrivialCatalog(tinyxml2::XMLElement *ruleNode, ProtocolRules &rules)
void parseRule(boost::property_tree::ptree::value_type const &storageRule, std::string const &protocol, ProtocolRules &rules)
std::string convert(std::string const &input, ProtocolRules const &rules, bool direct) const
std::string applyRules(ProtocolRules const &protocolRules, std::string const &protocol, std::string const &destination, bool direct, std::string name) const