00001 #include "DQMOffline/Trigger/interface/HLTTauDQMAutomation.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include <boost/regex.hpp>
00004
00005 HLTTauDQMAutomation::HLTTauDQMAutomation( ) {
00006 }
00007
00008 HLTTauDQMAutomation::HLTTauDQMAutomation( std::string hltProcessName, double L1MatchDr, double HLTMatchDr ) {
00009 hltProcessName_ = hltProcessName;
00010 L1MatchDr_ = L1MatchDr;
00011 HLTMatchDr_ = HLTMatchDr;
00012 }
00013
00014 HLTTauDQMAutomation::~HLTTauDQMAutomation() {
00015 }
00016
00017 void HLTTauDQMAutomation::AutoCompleteConfig( std::vector<edm::ParameterSet>& config, HLTConfigProvider const& HLTCP ) {
00018
00019 boost::regex reTau(".*Tau.*");
00020 std::map<std::string,HLTTauDQMFilter> filters;
00021 if ( HLTCP.inited() ) {
00022 const std::vector<std::string>& triggerNames = HLTCP.triggerNames();
00023 for ( std::vector<std::string>::const_iterator ipath = triggerNames.begin(); ipath != triggerNames.end(); ++ipath ) {
00024 if ( boost::regex_match(*ipath, reTau) && HLTCP.prescaleValue(0,*ipath) > 0 ) {
00025 HLTTauDQMFilter tmp(*ipath, HLTCP.prescaleValue(0,*ipath), hltProcessName_, L1MatchDr_, HLTMatchDr_);
00026 selectHLTTauDQMFilter(filters, tmp);
00027 }
00028 }
00029 }
00030
00031
00032 boost::regex reMuTau("Mu(.+?)Tau");
00033 boost::smatch what;
00034 std::map<std::string,HLTTauDQMFilter> pfTauFilters;
00035 for ( std::map<std::string,HLTTauDQMFilter>::const_iterator ipath = filters.begin(); ipath != filters.end(); ++ipath ) {
00036 std::string::const_iterator start = ipath->first.begin();
00037 std::string::const_iterator end = ipath->first.end();
00038 if ( boost::regex_match(start, end, what, reMuTau) ) {
00039 HLTTauDQMFilter tmp(ipath->second.name(), what[1]+"PFTau", HLTCP.prescaleValue(0,ipath->second.name()), hltProcessName_, L1MatchDr_, HLTMatchDr_, 1, 0, 0);
00040 selectHLTTauDQMFilter(pfTauFilters, tmp);
00041 }
00042 }
00043 filters.insert(pfTauFilters.begin(),pfTauFilters.end());
00044
00045
00046 std::vector<edm::ParameterSet>::iterator lpsum = config.end();
00047 std::vector<std::map<std::string,HLTTauDQMFilter>::iterator> selectedFilters;
00048 for ( std::vector<edm::ParameterSet>::iterator iconfig = config.begin(); iconfig != config.end(); ++iconfig ) {
00049 std::string configtype;
00050 try {
00051 configtype = iconfig->getUntrackedParameter<std::string>("ConfigType");
00052 } catch ( cms::Exception &e ) {
00053 edm::LogWarning("HLTTauDQMAutomation") << e.what() << std::endl;
00054 continue;
00055 }
00056 if (configtype == "Path") {
00057 try {
00058 if ( iconfig->getUntrackedParameter<std::vector<edm::ParameterSet> >("Filters",std::vector<edm::ParameterSet>()).size() == 0 ) {
00059 std::string triggerName = iconfig->getUntrackedParameter<std::string>("DQMFolder");
00060 std::map<std::string,HLTTauDQMFilter>::iterator iter = findFilter(filters,triggerName);
00061 if ( iter != filters.end() ) {
00062 iconfig->addUntrackedParameter<std::string>("DQMFolder", iter->first);
00063 iconfig->addUntrackedParameter<std::vector<edm::ParameterSet> >("Filters", iter->second.getPSets(HLTCP) );
00064 iconfig->addUntrackedParameter<edm::ParameterSet >("Reference", iter->second.getRefPSet());
00065 selectedFilters.push_back(iter);
00066 }
00067 }
00068 } catch ( cms::Exception &e ) {
00069 edm::LogWarning("HLTTauDQMAutomation") << e.what() << std::endl;
00070 continue;
00071 }
00072 }
00073 else if (configtype == "LitePath") {
00074 try {
00075 if ( iconfig->getUntrackedParameter<std::vector<edm::ParameterSet> >("Filters",std::vector<edm::ParameterSet>()).size() == 0 ) {
00076 std::string triggerName = iconfig->getUntrackedParameter<std::string>("DQMFolder");
00077 if ( triggerName != "Summary" ) {
00078 std::map<std::string,HLTTauDQMFilter>::iterator iter = findFilter(filters,triggerName);
00079 if ( iter != filters.end() ) {
00080 iconfig->addUntrackedParameter<std::string>("DQMFolder", iter->first);
00081 iconfig->addUntrackedParameter<std::vector<edm::ParameterSet> >("Filters", iter->second.getPSets(HLTCP) );
00082 selectedFilters.push_back(iter);
00083 }
00084 } else {
00085 lpsum = iconfig;
00086 }
00087 }
00088 } catch ( cms::Exception &e ) {
00089 edm::LogWarning("HLTTauDQMAutomation") << e.what() << std::endl;
00090 continue;
00091 }
00092 }
00093 }
00094
00095
00096 if ( lpsum != config.end() ) {
00097 std::vector<edm::ParameterSet> filterSet;
00098 for ( std::vector<std::map<std::string,HLTTauDQMFilter>::iterator>::iterator ifilter = selectedFilters.begin(); ifilter != selectedFilters.end(); ++ifilter ) {
00099 if ( !((*ifilter)->second.getSummaryPSet(HLTCP).empty()) ) {
00100 filterSet.push_back((*ifilter)->second.getSummaryPSet(HLTCP));
00101 }
00102 }
00103 lpsum->addUntrackedParameter<std::vector<edm::ParameterSet> >("Filters", filterSet );
00104 }
00105 }
00106
00107 void HLTTauDQMAutomation::AutoCompleteMatching( edm::ParameterSet& config, HLTConfigProvider const& HLTCP, std::string moduleType ) {
00108
00109 boost::regex reTau(".*Tau.*");
00110 std::map<std::string,HLTTauDQMFilter> filters;
00111 if ( HLTCP.inited() ) {
00112 const std::vector<std::string>& triggerNames = HLTCP.triggerNames();
00113 for ( std::vector<std::string>::const_iterator ipath = triggerNames.begin(); ipath != triggerNames.end(); ++ipath ) {
00114 if ( boost::regex_match(*ipath, reTau) && HLTCP.prescaleValue(0,*ipath) > 0 ) {
00115 HLTTauDQMFilter tmp(*ipath, HLTCP.prescaleValue(0,*ipath), hltProcessName_, L1MatchDr_, HLTMatchDr_);
00116 selectHLTTauDQMFilter(filters, tmp);
00117 }
00118 }
00119 }
00120
00121
00122 if ( config.getUntrackedParameter<bool>("doMatching") ) {
00123 std::vector<edm::ParameterSet> matchingFilters = config.getUntrackedParameter<std::vector<edm::ParameterSet> >("matchFilters");
00124 for ( std::vector<edm::ParameterSet>::iterator imatch = matchingFilters.begin(); imatch != matchingFilters.end(); ++imatch ) {
00125 std::string autoFilterName = imatch->getUntrackedParameter<std::string>("AutomaticFilterName","");
00126 if ( autoFilterName != "" ) {
00127 try {
00128 std::map<std::string,HLTTauDQMFilter>::iterator iter = findFilter(filters,autoFilterName);
00129 if ( iter != filters.end() ) {
00130 std::map<int,std::string> modules = iter->second.interestingModules(HLTCP);
00131 boost::regex exprEle(moduleType);
00132 std::string selectedModule = "";
00133 for ( std::map<int,std::string>::const_iterator imodule = modules.begin(); imodule != modules.end(); ++imodule ) {
00134 const std::string& mType = HLTCP.moduleType(imodule->second);
00135 std::string::const_iterator start = mType.begin();
00136 std::string::const_iterator end = mType.end();
00137 if ( boost::regex_match(start, end, exprEle) ) {
00138 selectedModule = imodule->second;
00139 break;
00140 }
00141 }
00142
00143 imatch->addUntrackedParameter<edm::InputTag>("FilterName", edm::InputTag(selectedModule,"",hltProcessName_) );
00144 } else {
00145 imatch->addUntrackedParameter<edm::InputTag>("FilterName", edm::InputTag("","",hltProcessName_) );
00146 }
00147 } catch ( cms::Exception &e ) {
00148 edm::LogWarning("HLTTauDQMAutomation") << e.what() << std::endl;
00149 continue;
00150 }
00151 }
00152 }
00153 config.addUntrackedParameter<std::vector<edm::ParameterSet> >("matchFilters", matchingFilters );
00154 }
00155 }
00156
00157 bool HLTTauDQMAutomation::selectHLTTauDQMFilter(std::map<std::string,HLTTauDQMFilter>& container, HLTTauDQMFilter const& filter) {
00158 bool inserted = false;
00159 std::map<std::string,HLTTauDQMFilter>::iterator iter = container.find(filter.type());
00160 if ( iter == container.end() ) {
00161 container.insert(std::make_pair(filter.type(), filter));
00162 inserted = true;
00163 } else {
00164 iter->second = iter->second.select(filter,inserted);
00165 }
00166 return inserted;
00167 }
00168
00169 std::map<std::string,HLTTauDQMFilter>::iterator HLTTauDQMAutomation::findFilter(std::map<std::string,HLTTauDQMFilter>& container, std::string const& triggerName) {
00170 boost::regex re("[a-zA-Z_]+");
00171 std::map<std::string,HLTTauDQMFilter>::iterator iter;
00172 if ( boost::regex_match(triggerName, re) ) {
00173 iter = container.find(triggerName);
00174 return iter;
00175 } else {
00176 boost::regex tmpRe(triggerName);
00177 for ( iter = container.begin(); iter != container.end(); ++iter ) {
00178 if ( boost::regex_match(iter->first, tmpRe) ) {
00179 return iter;
00180 }
00181 }
00182 }
00183 return container.end();
00184 }