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, unsigned iCatalog=0)
 
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, unsigned iCatalog)
 
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

◆ ProtocolRules

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

Definition at line 35 of file FileLocator.h.

◆ Rules

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

Definition at line 34 of file FileLocator.h.

Constructor & Destructor Documentation

◆ FileLocator()

edm::FileLocator::FileLocator ( std::string const &  catUrl,
unsigned  iCatalog = 0 
)
explicit

Definition at line 45 of file FileLocator.cc.

References init().

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

◆ ~FileLocator()

edm::FileLocator::~FileLocator ( )

Definition at line 52 of file FileLocator.cc.

52 {}

Member Function Documentation

◆ applyRules()

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

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

Referenced by convert().

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

◆ convert()

std::string edm::FileLocator::convert ( std::string const &  input,
ProtocolRules const &  rules,
bool  direct 
) const
private

Definition at line 58 of file FileLocator.cc.

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

Referenced by lfn(), and pfn().

58  {
59  std::string out = "";
60 
61  for (size_t pi = 0, pe = m_protocols.size(); pi != pe; ++pi) {
63  if (!out.empty())
64  return out;
65  }
66  return out;
67  }
std::string m_destination
Definition: FileLocator.h:57
static std::string const input
Definition: EdmProvDump.cc:50
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:190

◆ init()

void edm::FileLocator::init ( std::string const &  catUrl,
unsigned  iCatalog 
)
private

Definition at line 92 of file FileLocator.cc.

References findQualityFiles::comma, beamspotdip_dqm_sourceclient-live_cfg::configFile, boostedTaus_cff::doc, Exception, edm::Service< T >::isAvailable(), m_destination, m_directRules, m_filename, m_inverseRules, m_protocols, fileinputsource_cfi::option, parseRule(), submitPVValidationJobs::split(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by FileLocator().

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

◆ lfn()

std::string edm::FileLocator::lfn ( std::string const &  ipfn) const

Definition at line 56 of file FileLocator.cc.

References convert(), and m_inverseRules.

56 { 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:58

◆ parseRule()

void edm::FileLocator::parseRule ( tinyxml2::XMLElement *  ruleNode,
ProtocolRules rules 
)
private

Definition at line 69 of file FileLocator.cc.

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

Referenced by init().

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

◆ pfn()

std::string edm::FileLocator::pfn ( std::string const &  ilfn) const

Definition at line 54 of file FileLocator.cc.

References convert(), and m_directRules.

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

Member Data Documentation

◆ m_destination

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

Definition at line 57 of file FileLocator.h.

Referenced by convert(), and init().

◆ m_directRules

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().

◆ m_filename

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

Definition at line 55 of file FileLocator.h.

Referenced by init().

◆ m_fileType

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

Definition at line 54 of file FileLocator.h.

◆ m_inverseRules

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().

◆ m_protocols

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

Definition at line 56 of file FileLocator.h.

Referenced by convert(), and init().

◆ s_numberOfInstances

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.