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