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)
87 auto const protocol = safe(ruleElement->Attribute(
"protocol"));
88 auto destinationMatchRegexp = ruleElement->Attribute(
"destination-match");
89 if (destinationMatchRegexp ==
nullptr or destinationMatchRegexp[0] == 0) {
90 destinationMatchRegexp =
".*";
93 auto const pathMatchRegexp = safe(ruleElement->Attribute(
"path-match"));
94 auto const result = safe(ruleElement->Attribute(
"result"));
95 auto const chain = safe(ruleElement->Attribute(
"chain"));
99 rule.destinationMatch.assign(destinationMatchRegexp);
108 if (storageRule.second.empty()) {
109 throw cms::Exception(
"RucioFileCatalog",
"edm::FileLocator::parseRule Malformed storage rule");
111 auto const pathMatchRegexp = storageRule.second.get<
std::string>(
"lfn");
113 auto const chain = storageRule.second.get(
"chain",
kEmptyString);
127 throw cms::Exception(
"TrivialFileCatalog",
"edm::SiteLocalConfigService is not available");
128 if (iCatalog >= localconfservice->trivialDataCatalogs().size())
129 throw cms::Exception(
"TrivialFileCatalog",
"edm::FileLocator: Request nonexistence data catalog");
130 url = localconfservice->trivialDataCatalogs()[iCatalog];
133 if (
url.find(
"file:") == std::string::npos) {
135 "TrivialFileCatalog::connect: Malformed url for file catalog configuration");
140 std::vector<std::string> tokens;
144 if (tokens.size() == 2) {
146 std::vector<std::string> optionTokens;
152 for (
size_t oi = 0, oe = optionTokens.size(); oi != oe; ++oi) {
154 std::vector<std::string> argTokens;
157 if (argTokens.size() != 2) {
159 "TrivialFileCatalog::connect: Malformed url for file catalog configuration");
162 if (argTokens[0] ==
"protocol") {
164 }
else if (argTokens[0] ==
"destination") {
172 "TrivialFileCatalog::connect: protocol was not supplied in the contact string");
180 "TrivialFileCatalog::connect: Unable to open trivial file catalog " +
m_filename);
185 tinyxml2::XMLDocument
doc;
187 if (loadErr != tinyxml2::XML_SUCCESS) {
189 <<
"tinyxml file load failed with error : " <<
doc.ErrorStr() << std::endl;
202 auto rootElement =
doc.RootElement();
204 for (
auto el = rootElement->FirstChildElement(
"lfn-to-pfn"); el !=
nullptr;
205 el = el->NextSiblingElement(
"lfn-to-pfn")) {
210 for (
auto el = rootElement->FirstChildElement(
"pfn-to-lfn"); el !=
nullptr;
211 el = el->NextSiblingElement(
"pfn-to-lfn")) {
221 if (input_dataCatalog.
empty()) {
224 ex <<
"edm::SiteLocalConfigService is not available";
225 ex.
addContext(
"Calling edm::FileLocator::init()");
228 if (iCatalog >= localconfservice->dataCatalogs().size()) {
230 ex <<
"Request nonexistence data catalog";
231 ex.
addContext(
"Calling edm::FileLocator::init()");
234 aCatalog = localconfservice->dataCatalogs()[iCatalog];
240 if (!storageDescriptionPath.empty())
241 filename_storage = storageDescriptionPath;
246 boost::property_tree::read_json(filename_storage.string(),
json);
249 ex <<
"Can not open storage.json (" << filename_storage.string()
250 <<
"). Check SITECONFIG_PATH and site-local-config.xml <data-access>";
263 if (found_site ==
json.end()) {
265 ex <<
"Can not find storage site \"" << aCatalog.
storageSite <<
"\" and volume \"" << aCatalog.
volume 266 <<
"\" in storage.json. Check site-local-config.xml <data-access> and storage.json";
271 const pt::ptree& protocols = found_site->second.find(
"protocols")->second;
274 return aCatalog.
protocol == protName;
278 if (found_protocol == protocols.end()) {
280 ex <<
"Can not find protocol \"" << aCatalog.
protocol <<
"\" for the storage site \"" << aCatalog.
storageSite 281 <<
"\" and volume \"" << aCatalog.
volume 282 <<
"\" in storage.json. Check site-local-config.xml <data-access> and storage.json";
297 const pt::ptree&
rules =
protocol.second.find(
"rules")->second;
307 rule.
result = prefixTmp +
"/$1";
319 ProtocolRules::const_iterator
const rulesIterator = protocolRules.find(
protocol);
320 if (rulesIterator == protocolRules.end()) {
324 Rules const&
rules = (*(rulesIterator)).second;
326 std::smatch destinationMatches;
327 std::smatch nameMatches;
330 for (Rules::const_iterator
i =
rules.begin();
i !=
rules.end(); ++
i) {
331 if (!std::regex_match(
destination, destinationMatches,
i->destinationMatch)) {
335 if (!std::regex_match(
name,
i->pathMatch)) {
342 if ((direct ==
true) && (!chain.empty())) {
349 std::regex_match(
name, nameMatches,
i->pathMatch);
350 name = replaceWithRegexp(nameMatches,
i->result);
352 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
std::regex destinationMatch