4 #include <boost/algorithm/string.hpp> 5 #include <boost/algorithm/string/replace.hpp> 6 #include <boost/property_tree/json_parser.hpp> 14 namespace pt = boost::property_tree;
20 std::stringstream
str;
26 if (!matchedString.empty())
27 boost::algorithm::replace_all(
result,
str.str(), matchedString);
33 constexpr
char const*
const kLFNPrefix =
"/store/";
35 const char* safe(
const char* iCheck) {
36 if (iCheck ==
nullptr) {
44 namespace pt = boost::property_tree;
55 : m_destination(
"any") {
56 init(catAttr, iCatalog, storageDescriptionPath);
70 if (
input.compare(0, 7, kLFNPrefix) != 0)
94 auto const protocol = safe(ruleElement->Attribute(
"protocol"));
95 auto destinationMatchRegexp = ruleElement->Attribute(
"destination-match");
96 if (destinationMatchRegexp ==
nullptr or destinationMatchRegexp[0] == 0) {
97 destinationMatchRegexp =
".*";
100 auto const pathMatchRegexp = safe(ruleElement->Attribute(
"path-match"));
101 auto const result = safe(ruleElement->Attribute(
"result"));
102 auto const chain = safe(ruleElement->Attribute(
"chain"));
106 rule.destinationMatch.assign(destinationMatchRegexp);
115 if (storageRule.second.empty()) {
116 throw cms::Exception(
"RucioFileCatalog",
"edm::FileLocator::parseRule Malformed storage rule");
118 auto const pathMatchRegexp = storageRule.second.get<
std::string>(
"lfn");
122 rule.destinationMatch.assign(
".*");
133 throw cms::Exception(
"TrivialFileCatalog",
"edm::SiteLocalConfigService is not available");
134 if (iCatalog >= localconfservice->trivialDataCatalogs().size())
135 throw cms::Exception(
"TrivialFileCatalog",
"edm::FileLocator: Request nonexistence data catalog");
136 url = localconfservice->trivialDataCatalogs()[iCatalog];
139 if (
url.find(
"file:") == std::string::npos) {
141 "TrivialFileCatalog::connect: Malformed url for file catalog configuration");
146 std::vector<std::string> tokens;
150 if (tokens.size() == 2) {
152 std::vector<std::string> optionTokens;
158 for (
size_t oi = 0, oe = optionTokens.size(); oi != oe; ++oi) {
160 std::vector<std::string> argTokens;
163 if (argTokens.size() != 2) {
165 "TrivialFileCatalog::connect: Malformed url for file catalog configuration");
168 if (argTokens[0] ==
"protocol") {
170 }
else if (argTokens[0] ==
"destination") {
178 "TrivialFileCatalog::connect: protocol was not supplied in the contact string");
186 "TrivialFileCatalog::connect: Unable to open trivial file catalog " +
m_filename);
191 tinyxml2::XMLDocument
doc;
193 if (loadErr != tinyxml2::XML_SUCCESS) {
195 <<
"tinyxml file load failed with error : " <<
doc.ErrorStr() << std::endl;
208 auto rootElement =
doc.RootElement();
210 for (
auto el = rootElement->FirstChildElement(
"lfn-to-pfn"); el !=
nullptr;
211 el = el->NextSiblingElement(
"lfn-to-pfn")) {
216 for (
auto el = rootElement->FirstChildElement(
"pfn-to-lfn"); el !=
nullptr;
217 el = el->NextSiblingElement(
"pfn-to-lfn")) {
227 if (input_dataCatalog.
empty()) {
230 ex <<
"edm::SiteLocalConfigService is not available";
231 ex.
addContext(
"Calling edm::FileLocator::init()");
234 if (iCatalog >= localconfservice->dataCatalogs().size()) {
236 ex <<
"Request nonexistence data catalog";
237 ex.
addContext(
"Calling edm::FileLocator::init()");
240 aCatalog = localconfservice->dataCatalogs()[iCatalog];
246 if (!storageDescriptionPath.empty())
247 filename_storage = storageDescriptionPath;
252 boost::property_tree::read_json(filename_storage.string(),
json);
255 ex <<
"Can not open storage.json (" << filename_storage.string()
256 <<
"). Check SITECONFIG_PATH and site-local-config.xml <data-access>";
269 if (found_site ==
json.end()) {
271 ex <<
"Can not find site and volume " << aCatalog.
site <<
", " << aCatalog.
volume <<
" in " << filename_storage
272 <<
". Check site-local-config.xml <data-access> and storage.json";
277 const pt::ptree& protocols = found_site->second.find(
"protocols")->second;
280 return aCatalog.
protocol == protName;
284 if (found_protocol == protocols.end()) {
286 ex <<
"Can not find protocol " << aCatalog.
protocol 287 <<
" in storage.json. Check site-local-config.xml <data-access> and storage.json";
297 const pt::ptree&
rules = found_protocol->second.find(
"rules")->second;
310 ProtocolRules::const_iterator
const rulesIterator = protocolRules.find(
protocol);
311 if (rulesIterator == protocolRules.end()) {
315 Rules const&
rules = (*(rulesIterator)).second;
317 std::smatch destinationMatches;
318 std::smatch nameMatches;
321 for (Rules::const_iterator
i =
rules.begin();
i !=
rules.end(); ++
i) {
322 if (!std::regex_match(
destination, destinationMatches,
i->destinationMatch)) {
326 if (!std::regex_match(
name,
i->pathMatch)) {
333 if ((direct ==
true) && (!chain.empty())) {
340 std::regex_match(
name, nameMatches,
i->pathMatch);
341 name = replaceWithRegexp(nameMatches,
i->result);
343 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