CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
edm::FileLocator Class Reference

#include <FileLocator.h>

Classes

struct  Rule
 

Public Member Functions

 FileLocator (std::string const &catUrl, bool fallback)
 
std::string lfn (std::string const &ipfn) const
 
std::string pfn (std::string const &ilfn) const
 
 ~FileLocator ()
 

Private Types

typedef std::map< std::string, RulesProtocolRules
 
typedef std::vector< RuleRules
 

Private Member Functions

std::string applyRules (ProtocolRules const &protocolRules, std::string const &protocol, std::string const &destination, bool direct, std::string name) const
 
std::string convert (std::string const &input, ProtocolRules const &rules, bool direct) const
 
void init (std::string const &catUrl, bool fallback)
 
void parseRule (tinyxml2::XMLElement *ruleNode, ProtocolRules &rules)
 

Private Attributes

std::string m_destination
 
ProtocolRules m_directRules
 
std::string m_filename
 
std::string m_fileType
 
ProtocolRules m_inverseRules
 
std::vector< std::string > m_protocols
 

Static Private Attributes

static int s_numberOfInstances
 

Detailed Description

Definition at line 13 of file FileLocator.h.

Member Typedef Documentation

typedef std::map<std::string, Rules> edm::FileLocator::ProtocolRules
private

Definition at line 35 of file FileLocator.h.

typedef std::vector<Rule> edm::FileLocator::Rules
private

Definition at line 34 of file FileLocator.h.

Constructor & Destructor Documentation

edm::FileLocator::FileLocator ( std::string const &  catUrl,
bool  fallback 
)
explicit

Definition at line 46 of file FileLocator.cc.

References init().

46  : m_destination("any") {
47  init(catUrl, fallback);
48 
49  // std::cout << m_protocols.size() << " protocols" << std::endl;
50  // std::cout << m_directRules[m_protocols[0]].size() << " rules" << std::endl;
51  }
std::string m_destination
Definition: FileLocator.h:57
void init(std::string const &catUrl, bool fallback)
Definition: FileLocator.cc:93
edm::FileLocator::~FileLocator ( )

Definition at line 53 of file FileLocator.cc.

53 {}

Member Function Documentation

std::string edm::FileLocator::applyRules ( ProtocolRules const &  protocolRules,
std::string const &  protocol,
std::string const &  destination,
bool  direct,
std::string  name 
) const
private

Definition at line 194 of file FileLocator.cc.

References mps_fire::i, Skims_PA_cff::name, cmsCodeRulesChecker::rules, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by convert().

198  {
199  // std::cerr << "Calling apply rules with protocol: " << protocol << "\n destination: " << destination << "\n " << " on name " << name << std::endl;
200 
201  ProtocolRules::const_iterator const rulesIterator = protocolRules.find(protocol);
202  if (rulesIterator == protocolRules.end()) {
203  return "";
204  }
205 
206  Rules const& rules = (*(rulesIterator)).second;
207 
208  std::smatch destinationMatches;
209  std::smatch nameMatches;
210 
211  /* Look up for a matching rule*/
212  for (Rules::const_iterator i = rules.begin(); i != rules.end(); ++i) {
213  if (!std::regex_match(destination, destinationMatches, i->destinationMatch)) {
214  continue;
215  }
216 
217  if (!std::regex_match(name, i->pathMatch)) {
218  continue;
219  }
220 
221  // std::cerr << "Rule " << i->pathMatch << "matched! " << std::endl;
222 
223  std::string const chain = i->chain;
224  if ((direct == true) && (!chain.empty())) {
225  name = applyRules(protocolRules, chain, destination, direct, name);
226  if (name.empty()) {
227  return "";
228  }
229  }
230 
231  std::regex_match(name, nameMatches, i->pathMatch);
232  name = replaceWithRegexp(nameMatches, i->result);
233 
234  if ((direct == false) && (!chain.empty())) {
235  name = applyRules(protocolRules, chain, destination, direct, name);
236  }
237  return name;
238  }
239  return "";
240  }
Definition: chain.py:1
std::vector< Rule > Rules
Definition: FileLocator.h:34
std::string applyRules(ProtocolRules const &protocolRules, std::string const &protocol, std::string const &destination, bool direct, std::string name) const
Definition: FileLocator.cc:194
std::string edm::FileLocator::convert ( std::string const &  input,
ProtocolRules const &  rules,
bool  direct 
) const
private

Definition at line 59 of file FileLocator.cc.

References applyRules(), m_destination, m_protocols, MillePedeFileConverter_cfg::out, pi, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by lfn(), and pfn().

59  {
60  std::string out = "";
61 
62  for (size_t pi = 0, pe = m_protocols.size(); pi != pe; ++pi) {
63  out = applyRules(rules, m_protocols[pi], m_destination, direct, input);
64  if (!out.empty())
65  return out;
66  }
67  return out;
68  }
std::string m_destination
Definition: FileLocator.h:57
static std::string const input
Definition: EdmProvDump.cc:48
const Double_t pi
std::vector< std::string > m_protocols
Definition: FileLocator.h:56
std::string applyRules(ProtocolRules const &protocolRules, std::string const &protocol, std::string const &destination, bool direct, std::string name) const
Definition: FileLocator.cc:194
void edm::FileLocator::init ( std::string const &  catUrl,
bool  fallback 
)
private

Definition at line 93 of file FileLocator.cc.

References findQualityFiles::comma, common_cff::doc, Exception, edm::Service< T >::isAvailable(), m_destination, m_directRules, m_filename, m_inverseRules, m_protocols, fileinputsource_cfi::option, parseRule(), cms::dd::split(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by FileLocator().

93  {
94  std::string m_url = catUrl;
95 
96  if (m_url.empty()) {
97  Service<SiteLocalConfig> localconfservice;
98  if (!localconfservice.isAvailable())
99  throw cms::Exception("TrivialFileCatalog", "edm::SiteLocalConfigService is not available");
100 
101  m_url = (fallback ? localconfservice->fallbackDataCatalog() : localconfservice->dataCatalog());
102  }
103 
104  // std::cout << "Connecting to the catalog " << m_url << std::endl;
105 
106  if (m_url.find("file:") == std::string::npos) {
107  throw cms::Exception("TrivialFileCatalog",
108  "TrivialFileCatalog::connect: Malformed url for file catalog configuration");
109  }
110 
111  m_url = m_url.erase(0, m_url.find(":") + 1);
112 
113  std::vector<std::string> tokens;
114  boost::algorithm::split(tokens, m_url, boost::is_any_of(std::string("?")));
115  m_filename = tokens[0];
116 
117  if (tokens.size() == 2) {
118  std::string const options = tokens[1];
119  std::vector<std::string> optionTokens;
120  boost::algorithm::split(optionTokens, options, boost::is_any_of(std::string("&")));
121 
122  std::string const equalSign("=");
123  std::string const comma(",");
124 
125  for (size_t oi = 0, oe = optionTokens.size(); oi != oe; ++oi) {
126  std::string const option = optionTokens[oi];
127  std::vector<std::string> argTokens;
128  boost::algorithm::split(argTokens, option, boost::is_any_of(equalSign));
129 
130  if (argTokens.size() != 2) {
131  throw cms::Exception("TrivialFileCatalog",
132  "TrivialFileCatalog::connect: Malformed url for file catalog configuration");
133  }
134 
135  if (argTokens[0] == "protocol") {
136  boost::algorithm::split(m_protocols, argTokens[1], boost::is_any_of(comma));
137  } else if (argTokens[0] == "destination") {
138  m_destination = argTokens[1];
139  }
140  }
141  }
142 
143  if (m_protocols.empty()) {
144  throw cms::Exception("TrivialFileCatalog",
145  "TrivialFileCatalog::connect: protocol was not supplied in the contact string");
146  }
147 
148  std::ifstream configFile;
149  configFile.open(m_filename.c_str());
150 
151  //
152  // std::cout << "Using catalog configuration " << m_filename << std::endl;
153 
154  if (!configFile.good() || !configFile.is_open()) {
155  throw cms::Exception("TrivialFileCatalog",
156  "TrivialFileCatalog::connect: Unable to open trivial file catalog " + m_filename);
157  }
158 
159  configFile.close();
160 
161  tinyxml2::XMLDocument doc;
162  auto loadErr = doc.LoadFile(m_filename.c_str());
163  if (loadErr != tinyxml2::XML_SUCCESS) {
164  throw cms::Exception("TrivialFileCatalog")
165  << "tinyxml file load failed with error : " << doc.ErrorStr() << std::endl;
166  }
167 
168  /* trivialFileCatalog matches the following xml schema
169  FIXME: write a proper DTD
170  <storage-mapping>
171  <lfn-to-pfn protocol="direct" destination-match=".*"
172  path-match="lfn/guid match regular expression"
173  result="/castor/cern.ch/cms/$1"/>
174  <pfn-to-lfn protocol="srm"
175  path-match="lfn/guid match regular expression"
176  result="$1"/>
177  </storage-mapping>
178  */
179 
180  auto rootElement = doc.RootElement();
181  /*first of all do the lfn-to-pfn bit*/
182  for (auto el = rootElement->FirstChildElement("lfn-to-pfn"); el != nullptr;
183  el = el->NextSiblingElement("lfn-to-pfn")) {
185  }
186 
187  /*Then we handle the pfn-to-lfn bit*/
188  for (auto el = rootElement->FirstChildElement("pfn-to-lfn"); el != nullptr;
189  el = el->NextSiblingElement("pfn-to-lfn")) {
191  }
192  }
std::vector< std::string_view > split(std::string_view, const char *)
std::string m_destination
Definition: FileLocator.h:57
ProtocolRules m_inverseRules
Definition: FileLocator.h:52
std::string m_filename
Definition: FileLocator.h:55
ProtocolRules m_directRules
Definition: FileLocator.h:50
std::vector< std::string > m_protocols
Definition: FileLocator.h:56
void parseRule(tinyxml2::XMLElement *ruleNode, ProtocolRules &rules)
Definition: FileLocator.cc:70
std::string edm::FileLocator::lfn ( std::string const &  ipfn) const

Definition at line 57 of file FileLocator.cc.

References convert(), and m_inverseRules.

57 { return convert(ipfn, m_inverseRules, false); }
ProtocolRules m_inverseRules
Definition: FileLocator.h:52
std::string convert(std::string const &input, ProtocolRules const &rules, bool direct) const
Definition: FileLocator.cc:59
void edm::FileLocator::parseRule ( tinyxml2::XMLElement *  ruleNode,
ProtocolRules rules 
)
private

Definition at line 70 of file FileLocator.cc.

References Exception, eostools::move(), or, edm::FileLocator::Rule::pathMatch, mps_fire::result, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by init().

70  {
71  if (!ruleElement) {
72  throw cms::Exception("TrivialFileCatalog", std::string("TrivialFileCatalog::connect: Malformed trivial catalog"));
73  }
74 
75  auto const protocol = safe(ruleElement->Attribute("protocol"));
76  auto destinationMatchRegexp = ruleElement->Attribute("destination-match");
77  if (destinationMatchRegexp == nullptr or destinationMatchRegexp[0] == 0) {
78  destinationMatchRegexp = ".*";
79  }
80 
81  auto const pathMatchRegexp = safe(ruleElement->Attribute("path-match"));
82  auto const result = safe(ruleElement->Attribute("result"));
83  auto const chain = safe(ruleElement->Attribute("chain"));
84 
85  Rule rule;
86  rule.pathMatch.assign(pathMatchRegexp);
87  rule.destinationMatch.assign(destinationMatchRegexp);
88  rule.result = result;
89  rule.chain = chain;
90  rules[protocol].emplace_back(std::move(rule));
91  }
Definition: chain.py:1
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
Definition: Activities.doc:12
def move(src, dest)
Definition: eostools.py:511
std::string edm::FileLocator::pfn ( std::string const &  ilfn) const

Definition at line 55 of file FileLocator.cc.

References convert(), and m_directRules.

55 { return convert(ilfn, m_directRules, true); }
std::string convert(std::string const &input, ProtocolRules const &rules, bool direct) const
Definition: FileLocator.cc:59
ProtocolRules m_directRules
Definition: FileLocator.h:50

Member Data Documentation

std::string edm::FileLocator::m_destination
private

Definition at line 57 of file FileLocator.h.

Referenced by convert(), and init().

ProtocolRules edm::FileLocator::m_directRules
private

Direct rules are used to do the mapping from LFN to PFN.

Definition at line 50 of file FileLocator.h.

Referenced by init(), and pfn().

std::string edm::FileLocator::m_filename
private

Definition at line 55 of file FileLocator.h.

Referenced by init().

std::string edm::FileLocator::m_fileType
private

Definition at line 54 of file FileLocator.h.

ProtocolRules edm::FileLocator::m_inverseRules
private

Inverse rules are used to do the mapping from PFN to LFN

Definition at line 52 of file FileLocator.h.

Referenced by init(), and lfn().

std::vector<std::string> edm::FileLocator::m_protocols
private

Definition at line 56 of file FileLocator.h.

Referenced by convert(), and init().

int edm::FileLocator::s_numberOfInstances
staticprivate

For the time being the only allowed configuration item is a prefix to be added to the GUID/LFN.

Definition at line 25 of file FileLocator.h.