00001 #include "FWCore/ParameterSet/interface/IncludeFileFinder.h"
00002 #include "FWCore/Utilities/interface/EDMException.h"
00003 #include "FWCore/PluginManager/interface/standard.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005
00006 using namespace edmplugin;
00007
00008 namespace edm {
00009 namespace pset {
00010
00011 IncludeFileFinder::IncludeFileFinder()
00012 : thePluginManager(0),
00013 theLibraryMap()
00014 {
00015 if(!edmplugin::PluginManager::isAvailable()) {
00016 edmplugin::PluginManager::configure(edmplugin::standard::config());
00017 }
00018 thePluginManager = edmplugin::PluginManager::get();
00019
00020 typedef edmplugin::PluginManager::CategoryToInfos CatToInfos;
00021 const std::string kCapability("Capability");
00022 const CatToInfos& catToInfos = thePluginManager->categoryToInfos();
00023
00024 for (CatToInfos::const_iterator it = catToInfos.begin(), itEnd=catToInfos.end();
00025 it != itEnd; ++it)
00026 {
00027
00028
00029 if( kCapability == it->first) { continue; }
00030 for (edmplugin::PluginManager::Infos::const_iterator itInfo = it->second.begin(), itInfoEnd = it->second.end();
00031 itInfo != itInfoEnd; ++itInfo)
00032 {
00033 typedef std::map<std::string, std::string>::iterator LibMapItr;
00034
00035 std::string moduleClass = itInfo->name_;
00036 std::pair<LibMapItr,LibMapItr> range = theLibraryMap.equal_range(moduleClass);
00037 if(range.first == range.second) {
00038
00039 std::string libraryName = itInfo->loadable_.leaf();
00040 theLibraryMap.insert(range.first,std::make_pair(moduleClass,libraryName));
00041 }
00042 }
00043 }
00044 }
00045
00046 edm::FileInPath IncludeFileFinder::find(const std::string & moduleClass,
00047 const std::string & moduleLabel)
00048 {
00049 FileInPath result;
00050 std::string libraryName = libraryOf(moduleClass);
00051 std::string name = stripHeader(libraryName);
00052 name = stripTrailer(name);
00053
00054 DomainPackagePair parsings
00055 = twoWordsFrom(name);
00056
00057 for(DomainPackagePair::const_iterator wordPairItr = parsings.begin(), wordPairItrEnd = parsings.end();
00058 wordPairItr != wordPairItrEnd; ++wordPairItr)
00059 {
00060 std::string path = wordPairItr->first + "/" + wordPairItr->second + "/data/"
00061 + moduleLabel + ".cfi";
00062
00063 try
00064 {
00065 result = FileInPath(path);
00066
00067 return result;
00068 }
00069 catch(edm::Exception & e)
00070 {
00071
00072 }
00073 }
00074
00075 throw edm::Exception(errors::Configuration, "IncludeFileFinder")
00076 << "Could not find file " << moduleLabel + ".cfi" << " in "
00077 << name;
00078
00079 return result;
00080 }
00081
00082
00083 std::string IncludeFileFinder::libraryOf(const std::string & moduleClass)
00084 {
00085 std::map<std::string, std::string>::const_iterator mapItr
00086 = theLibraryMap.find(moduleClass);
00087 if(mapItr == theLibraryMap.end())
00088 {
00089 throw edm::Exception(errors::Configuration, "IncludeFileFinder")
00090 << "Cannot find " << moduleClass << " in the Edm Plugin list";
00091 }
00092 return mapItr->second;
00093 }
00094
00095
00096 std::string IncludeFileFinder::stripHeader(const std::string & libraryName)
00097 {
00098
00099
00100
00101 std::string result;
00102 if(libraryName.substr(0, 3) == "lib")
00103 {
00104
00105 result = libraryName.substr(3, libraryName.size());
00106 }
00107 else if(libraryName.substr(0, 6) == "plugin")
00108 {
00109 result = libraryName.substr(6, libraryName.size());
00110 }
00111 else
00112 {
00113 edm::LogError("Configuration")
00114 << "Strange library name in IncludeFileFinder: "
00115 << libraryName << ", doesn't start with 'lib' or 'plugin'";
00116
00117 result = libraryName;
00118 }
00119 return result;
00120 }
00121
00122
00123 std::string IncludeFileFinder::stripTrailer(const std::string & libraryName)
00124 {
00125 std::string result;
00126 unsigned pos = libraryName.find(".", 0);
00127 if(pos == std::string::npos)
00128 {
00129 edm::LogError("Configuration")
00130 << "Strange library name in IncludeFileFinder: "
00131 << libraryName << ", no dots";
00132
00133 result = libraryName;
00134 }
00135 else
00136 {
00137
00138 result = libraryName.substr(0, pos);
00139 }
00140
00141 pos = result.length();
00142
00143 if(result.substr(pos-7, pos) == "Plugins")
00144 {
00145 result = result.substr(0, pos-7);
00146 }
00147 return result;
00148 }
00149
00150
00151 IncludeFileFinder::DomainPackagePair
00152 IncludeFileFinder::twoWordsFrom(const std::string & name)
00153 {
00154 DomainPackagePair result;
00155 for(unsigned i = 1; i < name.size()-1 ; ++i)
00156 {
00157
00158 if(isupper(name[i]))
00159 {
00160 std::string firstWord = name.substr(0, i);
00161 std::string secondWord = name.substr(i, name.size()-i);
00162 result.push_back(std::pair<std::string, std::string>(firstWord, secondWord));
00163 }
00164 }
00165 return result;
00166 }
00167
00168 }
00169 }
00170
00171