Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-05-23 23:48:33

0001 #ifndef FWCore_Catalog_FileLocator_h
0002 #define FWCore_Catalog_FileLocator_h
0003 
0004 #include "FWCore/Catalog/interface/SiteLocalConfig.h"
0005 #include <string>
0006 #include <list>
0007 #include <map>
0008 #include <utility>
0009 #include <regex>
0010 #include "tinyxml2.h"
0011 #include <boost/property_tree/ptree.hpp>
0012 
0013 namespace edm {
0014 
0015   class FileLocator {
0016   public:
0017     explicit FileLocator(
0018         edm::CatalogAttributes const& catAttr,
0019         unsigned iCatalog = 0,
0020         //storageDescriptionPath is used to override path provided by SiteLocalConfig. This is used in FileLocator_t.cpp tests
0021         std::string const& storageDescriptionPath = std::string());
0022     explicit FileLocator(std::string const& catUrl, unsigned iCatalog = 0);
0023 
0024     ~FileLocator();
0025 
0026     std::string pfn(std::string const& ilfn, edm::CatalogType catType) const;
0027 
0028   private:
0029     /** For the time being the only allowed configuration item is a
0030      *  prefix to be added to the GUID/LFN.
0031      */
0032     struct Rule {
0033       std::regex pathMatch;
0034       std::regex destinationMatch;
0035       std::string result;
0036       std::string chain;
0037     };
0038 
0039     typedef std::vector<Rule> Rules;
0040     typedef std::map<std::string, Rules> ProtocolRules;
0041 
0042     void init_trivialCatalog(std::string const& catUrl, unsigned iCatalog);
0043 
0044     void parseRuleTrivialCatalog(tinyxml2::XMLElement* ruleNode, ProtocolRules& rules);
0045     //using data-access
0046     void init(edm::CatalogAttributes const& input_dataCatalog,
0047               unsigned iCatalog,
0048               std::string const& storageDescriptionPath);
0049     void parseRule(boost::property_tree::ptree::value_type const& storageRule,
0050                    std::string const& protocol,
0051                    ProtocolRules& rules);
0052 
0053     std::string applyRules(ProtocolRules const& protocolRules,
0054                            std::string const& protocol,
0055                            std::string const& destination,
0056                            bool direct,
0057                            std::string name) const;
0058 
0059     std::string convert(std::string const& input, ProtocolRules const& rules, bool direct) const;
0060 
0061     /** Direct rules are used to do the mapping from LFN to PFN.*/
0062     ProtocolRules m_directRules_trivialCatalog;
0063     /** Inverse rules are used to do the mapping from PFN to LFN*/
0064     ProtocolRules m_inverseRules;
0065     /** Direct rules are used to do the mapping from LFN to PFN taken from storage.json*/
0066     ProtocolRules m_directRules;
0067 
0068     std::string m_fileType;
0069     std::string m_filename;
0070     //TFC allows more than one protocols provided in a catalog, separated by a comma
0071     //In new Rucio storage description, only one protocol is provided in a catalog
0072     //This variable can be simplified in the future
0073     std::vector<std::string> m_protocols;
0074     std::string m_destination;
0075   };
0076 }  // namespace edm
0077 
0078 #endif  //  FWCore_Catalog_FileLocator_h