CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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,
Rules
ProtocolRules
 
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 (xercesc::DOMNode *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 = 0
 

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 36 of file FileLocator.h.

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

Definition at line 35 of file FileLocator.h.

Constructor & Destructor Documentation

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

Definition at line 55 of file FileLocator.cc.

References _toString(), alignCSCRings::e, edm::hlt::Exception, init(), s_numberOfInstances, and AlCaHLTBitMon_QueryRunRegistry::string.

56  : m_destination("any") {
57  try {
58  // << "Xerces-c initialization Number "
59  // << s_numberOfInstances <<
60  if (s_numberOfInstances == 0) {
61  XMLPlatformUtils::Initialize();
62  }
63  }
64  catch (XMLException const& e) {
65  // << "Xerces-c error in initialization \n"
66  // << "Exception message is: \n"
67  // << _toString(e.getMessage()) <<
68  throw
69  cms::Exception("TrivialFileCatalog", std::string("Fatal Error on edm::FileLocator:")+ _toString(e.getMessage()));
70  }
72 
73  init(catUrl, fallback);
74 
75  // std::cout << m_protocols.size() << " protocols" << std::endl;
76  // std::cout << m_directRules[m_protocols[0]].size() << " rules" << std::endl;
77  }
static int s_numberOfInstances
Definition: FileLocator.h:26
std::string m_destination
Definition: FileLocator.h:59
std::string _toString(const XMLCh *toTranscode)
void init(std::string const &catUrl, bool fallback)
Definition: FileLocator.cc:138
edm::FileLocator::~FileLocator ( )

Definition at line 79 of file FileLocator.cc.

80  {}

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 246 of file FileLocator.cc.

References i, mergeVDriftHistosByStation::name, cmsCodeRulesChecker::rules, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by convert().

250  {
251 
252  // std::cerr << "Calling apply rules with protocol: " << protocol << "\n destination: " << destination << "\n " << " on name " << name << std::endl;
253 
254  ProtocolRules::const_iterator const rulesIterator = protocolRules.find(protocol);
255  if (rulesIterator == protocolRules.end()) {
256  return "";
257  }
258 
259  Rules const& rules = (*(rulesIterator)).second;
260 
261  boost::smatch destinationMatches;
262  boost::smatch nameMatches;
263 
264  /* Look up for a matching rule*/
265  for (Rules::const_iterator i = rules.begin(); i != rules.end(); ++i) {
266 
267  if (!boost::regex_match(destination, destinationMatches, i->destinationMatch)) {
268  continue;
269  }
270 
271  if (!boost::regex_match(name, i->pathMatch)) {
272  continue;
273  }
274 
275  // std::cerr << "Rule " << i->pathMatch << "matched! " << std::endl;
276 
277  std::string const chain = i->chain;
278  if ((direct == true) && (chain != "")) {
279  name = applyRules(protocolRules, chain, destination, direct, name);
280  if (name.empty()) {
281  return "";
282  }
283  }
284 
285  boost::regex_match(name, nameMatches, i->pathMatch);
286  name = replaceWithRegexp(nameMatches, i->result);
287 
288  if ((direct == false) && (chain != "")) {
289  name = applyRules(protocolRules, chain, destination, direct, name);
290  }
291  return name;
292  }
293  return "";
294  }
int i
Definition: DBlmapReader.cc:9
std::vector< Rule > Rules
Definition: FileLocator.h:35
std::string applyRules(ProtocolRules const &protocolRules, std::string const &protocol, std::string const &destination, bool direct, std::string name) const
Definition: FileLocator.cc:246
std::string edm::FileLocator::convert ( std::string const &  input,
ProtocolRules const &  rules,
bool  direct 
) const
private

Definition at line 94 of file FileLocator.cc.

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

Referenced by lfn(), and pfn().

94  {
95  std::string out = "";
96 
97  for (size_t pi = 0, pe = m_protocols.size(); pi != pe; ++pi) {
98  out = applyRules(rules, m_protocols[pi], m_destination, direct, input);
99  if (!out.empty())
100  return out;
101  }
102  return out;
103  }
std::string m_destination
Definition: FileLocator.h:59
tuple out
Definition: dbtoconf.py:99
std::vector< std::string > m_protocols
Definition: FileLocator.h:58
std::string applyRules(ProtocolRules const &protocolRules, std::string const &protocol, std::string const &destination, bool direct, std::string name) const
Definition: FileLocator.cc:246
double pi
void edm::FileLocator::init ( std::string const &  catUrl,
bool  fallback 
)
private

Definition at line 138 of file FileLocator.cc.

References _toDOMS(), findQualityFiles::comma, HDQMDatabaseProducer::configFile, asciidump::doc, edm::hlt::Exception, i, edm::Service< T >::isAvailable(), m_destination, m_directRules, m_filename, m_inverseRules, m_protocols, AlCaHLTBitMon_ParallelJobs::options, geometryXMLtoCSV::parser, parseRule(), cmsCodeRulesChecker::rules, split, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by FileLocator().

138  {
139  std::string m_url = catUrl;
140 
141  if (m_url.empty()) {
142  Service<SiteLocalConfig> localconfservice;
143  if (!localconfservice.isAvailable())
144  throw cms::Exception("TrivialFileCatalog", "edm::SiteLocalConfigService is not available");
145 
146  m_url = (fallback ? localconfservice->fallbackDataCatalog() : localconfservice->dataCatalog());
147  }
148 
149  // std::cout << "Connecting to the catalog " << m_url << std::endl;
150 
151  if (m_url.find("file:") == std::string::npos) {
152  throw cms::Exception("TrivialFileCatalog", "TrivialFileCatalog::connect: Malformed url for file catalog configuration");
153  }
154 
155  m_url = m_url.erase(0, m_url.find(":") + 1);
156 
157  std::vector<std::string> tokens;
158  boost::algorithm::split(tokens, m_url, boost::is_any_of(std::string("?")));
159  m_filename = tokens[0];
160 
161  if (tokens.size() == 2) {
162  std::string const options = tokens[1];
163  std::vector<std::string> optionTokens;
164  boost::algorithm::split(optionTokens, options, boost::is_any_of(std::string("&")));
165 
166  std::string const equalSign("=");
167  std::string const comma(",");
168 
169  for (size_t oi = 0, oe = optionTokens.size(); oi != oe; ++oi) {
170  std::string const option = optionTokens[oi];
171  std::vector<std::string> argTokens;
172  boost::algorithm::split(argTokens, option, boost::is_any_of(equalSign));
173 
174  if (argTokens.size() != 2) {
175  throw cms::Exception("TrivialFileCatalog", "TrivialFileCatalog::connect: Malformed url for file catalog configuration");
176  }
177 
178  if (argTokens[0] == "protocol") {
179  boost::algorithm::split(m_protocols, argTokens[1], boost::is_any_of(comma));
180  } else if (argTokens[0] == "destination") {
181  m_destination = argTokens[1];
182  }
183  }
184  }
185 
186  if (m_protocols.empty()) {
187  throw cms::Exception("TrivialFileCatalog", "TrivialFileCatalog::connect: protocol was not supplied in the contact string");
188  }
189 
190  std::ifstream configFile;
191  configFile.open(m_filename.c_str());
192 
193  //
194  // std::cout << "Using catalog configuration " << m_filename << std::endl;
195 
196  if (!configFile.good() || !configFile.is_open()) {
197  throw cms::Exception("TrivialFileCatalog", "TrivialFileCatalog::connect: Unable to open trivial file catalog " + m_filename);
198  }
199 
200  configFile.close();
201 
202  XercesDOMParser* parser = new XercesDOMParser;
203  parser->setValidationScheme(XercesDOMParser::Val_Auto);
204  parser->setDoNamespaces(false);
205  parser->parse(m_filename.c_str());
206  DOMDocument* doc = parser->getDocument();
207  assert(doc);
208 
209  /* trivialFileCatalog matches the following xml schema
210  FIXME: write a proper DTD
211  <storage-mapping>
212  <lfn-to-pfn protocol="direct" destination-match=".*"
213  path-match="lfn/guid match regular expression"
214  result="/castor/cern.ch/cms/$1"/>
215  <pfn-to-lfn protocol="srm"
216  path-match="lfn/guid match regular expression"
217  result="$1"/>
218  </storage-mapping>
219  */
220 
221  /*first of all do the lfn-to-pfn bit*/
222  {
223  DOMNodeList* rules = doc->getElementsByTagName(_toDOMS("lfn-to-pfn"));
224  unsigned int const ruleTagsNum = rules->getLength();
225 
226  // FIXME: we should probably use a DTD for checking validity
227 
228  for (unsigned int i = 0; i < ruleTagsNum; ++i) {
229  DOMNode* ruleNode = rules->item(i);
230  parseRule(ruleNode, m_directRules);
231  }
232  }
233  /*Then we handle the pfn-to-lfn bit*/
234  {
235  DOMNodeList* rules = doc->getElementsByTagName(_toDOMS("pfn-to-lfn"));
236  unsigned int ruleTagsNum = rules->getLength();
237 
238  for (unsigned int i = 0; i < ruleTagsNum; ++i) {
239  DOMNode* ruleNode = rules->item(i);
240  parseRule(ruleNode, m_inverseRules);
241  }
242  }
243  }
int i
Definition: DBlmapReader.cc:9
std::string m_destination
Definition: FileLocator.h:59
ProtocolRules m_inverseRules
Definition: FileLocator.h:54
std::string m_filename
Definition: FileLocator.h:57
tuple doc
Definition: asciidump.py:381
ProtocolRules m_directRules
Definition: FileLocator.h:52
void parseRule(xercesc::DOMNode *ruleNode, ProtocolRules &rules)
Definition: FileLocator.cc:106
std::vector< std::string > m_protocols
Definition: FileLocator.h:58
XMLCh * _toDOMS(std::string temp)
double split
Definition: MVATrainer.cc:139
std::string edm::FileLocator::lfn ( std::string const &  ipfn) const

Definition at line 89 of file FileLocator.cc.

References convert(), and m_inverseRules.

89  {
90  return convert(ipfn, m_inverseRules, false);
91  }
ProtocolRules m_inverseRules
Definition: FileLocator.h:54
std::string convert(std::string const &input, ProtocolRules const &rules, bool direct) const
Definition: FileLocator.cc:94
void edm::FileLocator::parseRule ( xercesc::DOMNode *  ruleNode,
ProtocolRules rules 
)
private

Definition at line 106 of file FileLocator.cc.

References _toDOMS(), _toString(), edm::hlt::Exception, edm::FileLocator::Rule::pathMatch, query::result, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by init().

106  {
107  if (!ruleNode) {
108  throw cms::Exception("TrivialFileCatalog", std::string("TrivialFileCatalog::connect: Malformed trivial catalog"));
109  }
110 
111  // ruleNode is actually always a DOMElement because it's the result of
112  // a `getElementsByTagName()` in the calling method.
113  DOMElement* ruleElement = static_cast<DOMElement *>(ruleNode);
114 
115  std::string const protocol = _toString(ruleElement->getAttribute(_toDOMS("protocol")));
116  std::string destinationMatchRegexp = _toString(ruleElement->getAttribute(_toDOMS("destination-match")));
117 
118  if (destinationMatchRegexp.empty()) {
119  destinationMatchRegexp = ".*";
120  }
121 
122  std::string const pathMatchRegexp
123  = _toString(ruleElement->getAttribute(_toDOMS("path-match")));
124  std::string const result
125  = _toString(ruleElement->getAttribute(_toDOMS("result")));
126  std::string const chain
127  = _toString(ruleElement->getAttribute(_toDOMS("chain")));
128 
129  Rule rule;
130  rule.pathMatch.assign(pathMatchRegexp);
131  rule.destinationMatch.assign(destinationMatchRegexp);
132  rule.result = result;
133  rule.chain = chain;
134  rules[protocol].push_back(rule);
135  }
std::string _toString(const XMLCh *toTranscode)
tuple result
Definition: query.py:137
XMLCh * _toDOMS(std::string temp)
std::string edm::FileLocator::pfn ( std::string const &  ilfn) const

Definition at line 84 of file FileLocator.cc.

References convert(), and m_directRules.

84  {
85  return convert(ilfn, m_directRules, true);
86  }
std::string convert(std::string const &input, ProtocolRules const &rules, bool direct) const
Definition: FileLocator.cc:94
ProtocolRules m_directRules
Definition: FileLocator.h:52

Member Data Documentation

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

Definition at line 59 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 52 of file FileLocator.h.

Referenced by init(), and pfn().

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

Definition at line 57 of file FileLocator.h.

Referenced by init().

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

Definition at line 56 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 54 of file FileLocator.h.

Referenced by init(), and lfn().

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

Definition at line 58 of file FileLocator.h.

Referenced by convert(), and init().

int edm::FileLocator::s_numberOfInstances = 0
staticprivate

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

Definition at line 26 of file FileLocator.h.

Referenced by FileLocator().