Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:54

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     static int s_numberOfInstances;
0033 
0034     struct Rule {
0035       std::regex pathMatch;
0036       std::regex destinationMatch;
0037       std::string result;
0038       std::string chain;
0039     };
0040 
0041     typedef std::vector<Rule> Rules;
0042     typedef std::map<std::string, Rules> ProtocolRules;
0043 
0044     void init_trivialCatalog(std::string const& catUrl, unsigned iCatalog);
0045 
0046     void parseRuleTrivialCatalog(tinyxml2::XMLElement* ruleNode, ProtocolRules& rules);
0047     //using data-access
0048     void init(edm::CatalogAttributes const& input_dataCatalog,
0049               unsigned iCatalog,
0050               std::string const& storageDescriptionPath);
0051     void parseRule(boost::property_tree::ptree::value_type const& storageRule,
0052                    std::string const& protocol,
0053                    ProtocolRules& rules);
0054 
0055     std::string applyRules(ProtocolRules const& protocolRules,
0056                            std::string const& protocol,
0057                            std::string const& destination,
0058                            bool direct,
0059                            std::string name) const;
0060 
0061     std::string convert(std::string const& input, ProtocolRules const& rules, bool direct) const;
0062 
0063     /** Direct rules are used to do the mapping from LFN to PFN.*/
0064     ProtocolRules m_directRules_trivialCatalog;
0065     /** Inverse rules are used to do the mapping from PFN to LFN*/
0066     ProtocolRules m_inverseRules;
0067     /** Direct rules are used to do the mapping from LFN to PFN taken from storage.json*/
0068     ProtocolRules m_directRules;
0069 
0070     std::string m_fileType;
0071     std::string m_filename;
0072     //TFC allows more than one protocols provided in a catalog, separated by a comma
0073     //In new Rucio storage description, only one protocol is provided in a catalog
0074     //This variable can be simplified in the future
0075     std::vector<std::string> m_protocols;
0076     std::string m_destination;
0077   };
0078 }  // namespace edm
0079 
0080 #endif  //  FWCore_Catalog_FileLocator_h