CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTConfigProvider.cc
Go to the documentation of this file.
1 
22 
23 #include <boost/regex.hpp>
24 
26 
27 // an empty dummy config data used when we fail to initialize
29 { static HLTConfigData dummyHLTConfigData;
30  return &dummyHLTConfigData;
31 }
32 
34  processName_(""),
35  inited_(false),
36  changed_(true),
37  hltConfigData_(s_dummyHLTConfigData()),
38  l1GtUtils_(new L1GtUtils())
39 {
40 }
41 
43  const edm::EventSetup& iSetup,
44  const std::string& processName,
45  bool& changed) {
46 
47  using namespace std;
48  using namespace edm;
49 
50  LogInfo("HLTConfigData") << "Called (R) with processName '"
51  << processName
52  << "' for " << iRun.id() << endl;
53 
55 
58 
60  changed=changed_;
61  return inited_;
62 
63 }
64 
65 void HLTConfigProvider::init(const edm::ProcessHistory& iHistory, const std::string& processName) {
66 
67  using namespace std;
68  using namespace edm;
69 
70  const ProcessHistory::const_iterator hb(iHistory.begin());
71  const ProcessHistory::const_iterator he(iHistory.end());
72 
73  ProcessConfiguration processConfiguration;
75 
77  if (processName_=="*") {
78  // auto-discovery of process name
79  for (ProcessHistory::const_iterator hi=hb; hi!=he; ++hi) {
80  if (iHistory.getConfigurationForProcess(hi->processName(),processConfiguration)) {
81  processPSet = edm::pset::Registry::instance()->getMapped(processConfiguration.parameterSetID());
82  if ((processPSet!=0) && (processPSet->exists("hltTriggerSummaryAOD"))) {
83  processName_=hi->processName();
84  }
85  }
86  }
87  LogInfo("HLTConfigData") << "Auto-discovered processName: '"
88  << processName_ << "'"
89  << endl;
90  }
91  if (processName_=="*") {
92  clear();
93  LogError("HLTConfigData") << "Auto-discovery of processName failed!"
94  << endl;
95  return;
96  }
97 
99  unsigned int n(0);
100  for (ProcessHistory::const_iterator hi=hb; hi!=he; ++hi) {
101  if (hi->processName()==processName_) {n++;}
102  }
103  if (n>1) {
104  clear();
105  LogError("HLTConfigProvider") << " ProcessName '"<< processName_
106  << " found " << n
107  << " times in history!" << endl;
108  return;
109  }
110 
112  if (iHistory.getConfigurationForProcess(processName_,processConfiguration)) {
113  if ((hltConfigData_ !=s_dummyHLTConfigData()) && (processConfiguration.parameterSetID() == hltConfigData_->id())) {
114  changed_ = false;
115  inited_ = true;
116  return;
117  } else {
118  getDataFrom(processConfiguration.parameterSetID());
119  }
120  } else {
121  LogError("HLTConfigProvider") << "Falling back to processName-only init!";
122  clear();
124  if (!inited_) {
125  LogError("HLTConfigProvider") << "ProcessName not found in history!";
126  }
127  return;
128  }
129 }
130 
132 {
133  //is it in our registry?
135  const HLTConfigData* d = reg->getMapped(iID);
136  if(0 != d) {
137  changed_ = true;
138  inited_ = true;
139  hltConfigData_ = d;
140  } else {
141  const edm::ParameterSet* processPSet = 0;
142  if ( 0 != (processPSet = edm::pset::Registry::instance()->getMapped(iID))) {
143  if (not processPSet->id().isValid()) {
144  clear();
145  edm::LogError("HLTConfigProvider") << "ProcessPSet found is empty!";
146  changed_ = true;
147  inited_ = false;
149  return;
150  } else {
151  clear();
152  reg->insertMapped( HLTConfigData(processPSet));
153  changed_ = true;
154  inited_ = true;
155  hltConfigData_ = reg->getMapped(processPSet->id());
156  return;
157  }
158  } else {
159  clear();
160  edm::LogError("HLTConfigProvider") << "ProcessPSet not found in regsistry!";
161  changed_ = true;
162  inited_ = false;
164  return;
165  }
166  }
167  return;
168 }
169 
170 void HLTConfigProvider::init(const std::string& processName)
171 {
172  using namespace std;
173  using namespace edm;
174 
175  // Obtain ParameterSetID for requested process (with name
176  // processName) from pset registry
177  string pNames("");
178  string hNames("");
179  const ParameterSet* pset = 0;
180  ParameterSetID psetID;
181  unsigned int nPSets(0);
182  const edm::pset::Registry * registry_(pset::Registry::instance());
183  const edm::pset::Registry::const_iterator rb(registry_->begin());
184  const edm::pset::Registry::const_iterator re(registry_->end());
185  for (edm::pset::Registry::const_iterator i = rb; i != re; ++i) {
186  if (i->second.exists("@process_name")) {
187  const std::string pName(i->second.getParameter<string>("@process_name"));
188  pNames += pName+" ";
189  if ( pName == processName ) {
190  psetID = i->first;
191  nPSets++;
192  if ((hltConfigData_ != s_dummyHLTConfigData()) && (hltConfigData_->id()==psetID)) {
193  hNames += tableName();
194  } else if ( 0 != (pset = registry_->getMapped(psetID))) {
195  if (pset->exists("HLTConfigVersion")) {
196  const ParameterSet& HLTPSet(pset->getParameterSet("HLTConfigVersion"));
197  if (HLTPSet.exists("tableName")) {
198  hNames += HLTPSet.getParameter<string>("tableName")+" ";
199  }
200  }
201  }
202  }
203  }
204  }
205 
206  LogVerbatim("HLTConfigProvider") << "Unordered list of all process names found: "
207  << pNames << "." << endl;
208 
209  LogVerbatim("HLTConfigProvider") << "HLT TableName of each selected process: "
210  << hNames << "." << endl;
211 
212  if (nPSets==0) {
213  clear();
214  LogError("HLTConfigProvider") << " Process name '"
215  << processName
216  << "' not found in registry!" << endl;
217  return;
218  }
219  if (psetID==ParameterSetID()) {
220  clear();
221  LogError("HLTConfigProvider") << " Process name '"
222  << processName
223  << "' found but ParameterSetID invalid!"
224  << endl;
225  return;
226  }
227  if (nPSets>1) {
228  clear();
229  LogError("HLTConfigProvider") << " Process name '"
230  << processName
231  << " found " << nPSets
232  << " times in registry!" << endl;
233  return;
234  }
235 
236  getDataFrom(psetID);
237 
238  return;
239 
240 }
241 
243 {
244  // clear all data members
245 
246  processName_ = "";
247  inited_ = false;
248  changed_ = true;
250  *l1GtUtils_ = L1GtUtils();
251 
252  return;
253 }
254 
255 
257  // return hltPrescaleTable_.set();
258  l1GtUtils_->retrieveL1EventSetup(iSetup);
259  int errorTech(0);
260  const int psfsiTech(l1GtUtils_->prescaleFactorSetIndex(iEvent,L1GtUtils::TechnicalTrigger,errorTech));
261  int errorPhys(0);
262  const int psfsiPhys(l1GtUtils_->prescaleFactorSetIndex(iEvent,L1GtUtils::AlgorithmTrigger,errorPhys));
263  assert(psfsiTech==psfsiPhys);
264  if ( (errorTech==0) && (errorPhys==0) &&
265  (psfsiTech>=0) && (psfsiPhys>=0) && (psfsiTech==psfsiPhys) ) {
266  return psfsiPhys;
267  } else {
269  edm::LogError("HLTConfigData")
270  << " Error in determining HLT prescale set index from L1 data using L1GtUtils: "
271  << " Tech/Phys error = " << errorTech << "/" << errorPhys
272  << " Tech/Phys psfsi = " << psfsiTech << "/" << psfsiPhys;
273  return -1;
274  }
275 }
276 
277 unsigned int HLTConfigProvider::prescaleValue(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) const {
278  const int set(prescaleSet(iEvent,iSetup));
279  if (set<0) {
280  return 1;
281  } else {
282  return prescaleValue(static_cast<unsigned int>(set),trigger);
283  }
284 }
285 
286 std::pair<int,int> HLTConfigProvider::prescaleValues(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) const {
287 
288  // start with setting both L1T and HLT prescale values to 0
289  std::pair<int,int> result(std::pair<int,int>(0,0));
290 
291  // get HLT prescale (possible if HLT prescale set index is correctly found)
292  const int set(prescaleSet(iEvent,iSetup));
293  if (set<0) {
294  result.second = -1;
295  } else {
296  result.second = static_cast<int>(prescaleValue(static_cast<unsigned int>(set),trigger));
297  }
298 
299  // get L1T prescale - works only for those hlt trigger paths with
300  // exactly one L1GT seed module which has exactly one L1T name as seed
301  const unsigned int nL1GTSeedModules(hltL1GTSeeds(trigger).size());
302  if (nL1GTSeedModules==0) {
303  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
304  result.first=1;
305  } else if (nL1GTSeedModules==1) {
306  l1GtUtils_->retrieveL1EventSetup(iSetup);
307  const std::string l1tname(hltL1GTSeeds(trigger).at(0).second);
308  int l1error(0);
309  result.first = l1GtUtils_->prescaleFactor(iEvent,l1tname,l1error);
310  if (l1error!=0) {
311  edm::LogError("HLTConfigData")
312  << " Error in determining L1T prescale for HLT path: '" << trigger
313  << "' with L1T seed: '" << l1tname
314  << "' using L1GtUtils: error code: " << l1error
315  << ". (Note: only a single L1T name, not a bit number, is allowed as seed for a proper determination of the L1T prescale!)";
316  result.first = -1;
317  }
318  } else {
320  std::string dump("'"+hltL1GTSeeds(trigger).at(0).second+"'");
321  for (unsigned int i=1; i!=nL1GTSeedModules; ++i) {
322  dump += " * '"+hltL1GTSeeds(trigger).at(i).second+"'";
323  }
324  edm::LogError("HLTConfigData")
325  << " Error in determining L1T prescale for HLT path: '" << trigger
326  << "' has multiple L1GTSeed modules, " << nL1GTSeedModules
327  << ", with L1 seeds: " << dump
328  << ". (Note: at most one L1GTSeed module is allowed for a proper determination of the L1T prescale!)";
329  result.first = -1;
330  }
331 
332  return result;
333 }
334 
335 const std::vector<std::string> HLTConfigProvider::matched(const std::vector<std::string>& inputs, const std::string& pattern) {
336  std::vector<std::string> matched;
337  const boost::regex regexp(edm::glob2reg(pattern));
338  const unsigned int n(inputs.size());
339  for (unsigned int i=0; i<n; ++i) {
340  const std::string& input(inputs[i]);
341  if (boost::regex_match(input,regexp)) matched.push_back(input);
342  }
343  return matched;
344 }
345 
346 const std::string HLTConfigProvider::removeVersion(const std::string& trigger) {
347  const boost::regex regexp("_v[0-9]+$");
348  return boost::regex_replace(trigger,regexp,"");
349 }
350 
351 const std::vector<std::string> HLTConfigProvider::restoreVersion(const std::vector<std::string>& inputs, const std::string& trigger) {
352  return matched(inputs,trigger+"_v[0-9]+$");
353 }
unsigned int size() const
number of trigger paths in trigger table
collection_type::const_iterator const_iterator
void dump(const std::string &what) const
Dumping config info to cout.
T getParameter(std::string const &) const
const_iterator begin() const
int i
Definition: DBlmapReader.cc:9
RunID const & id() const
Definition: RunBase.h:43
edm::detail::ThreadSafeRegistry< edm::ParameterSetID, HLTConfigData > HLTConfigDataRegistry
static const std::vector< std::string > matched(const std::vector< std::string > &inputs, const std::string &pattern)
regexp processing
void getDataFrom(const edm::ParameterSetID &iID)
ParameterSetID id() const
const std::vector< std::vector< std::pair< bool, std::string > > > & hltL1GTSeeds() const
std::string glob2reg(std::string const &pattern)
Definition: RegexMatch.cc:14
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool getMapped(key_type const &k, value_type &result) const
static const HLTConfigData * s_dummyHLTConfigData()
const std::string & tableName() const
HLT ConfDB table name.
std::string processName_
data members
bool insertMapped(value_type const &v)
static const std::string removeVersion(const std::string &trigger)
const HLTConfigData * hltConfigData_
U second(std::pair< T, U > const &p)
bool getConfigurationForProcess(std::string const &name, ProcessConfiguration &config) const
boost::shared_ptr< L1GtUtils > l1GtUtils_
unsigned int prescaleValue(unsigned int set, const std::string &trigger) const
HLT prescale value in specific prescale set for a specific trigger path.
int iEvent
Definition: GenABIO.cc:243
const edm::ParameterSet & processPSet() const
ParameterSet of process.
collection_type::const_iterator const_iterator
tuple result
Definition: query.py:137
ProcessHistory const & processHistory() const
Definition: Run.cc:100
Hash< ParameterSetType > ParameterSetID
HLTConfigProvider()
c&#39;tor
tuple input
Definition: collect_tpl.py:10
const std::string & processName() const
Accessors (const methods)
int prescaleSet(const edm::Event &iEvent, const edm::EventSetup &iSetup) const
static const std::vector< std::string > restoreVersion(const std::vector< std::string > &inputs, const std::string &trigger)
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
std::pair< int, int > prescaleValues(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger) const
Combined L1T (pair.first) and HLT (pair.second) prescales per HLT path.
const_iterator end() const
bool isValid() const
Definition: Hash.h:136
static ThreadSafeRegistry * instance()
edm::ParameterSetID id() const
technical: id() function needed for use with ThreadSafeRegistry
Definition: Run.h:32
list at
Definition: asciidump.py:428