Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:27

0001 #include "CondFormats/PhysicsToolsObjects/interface/PerformancePayloadFromTable.h"
0002 
0003 const int PerformancePayloadFromTable::InvalidPos = -1;
0004 
0005 #include <iostream>
0006 
0007 float PerformancePayloadFromTable::getResult(PerformanceResult::ResultType r, const BinningPointByMap& p) const {
0008   if (!isInPayload(r, p))
0009     return PerformancePayload::InvalidResult;
0010 
0011   // loop on the table rows and search for a match
0012   for (int i = 0; i < pl.nRows(); i++) {
0013     PhysicsPerformancePayload::Row row = pl.getRow(i);
0014 
0015     if (matches(p, row)) {
0016       int pos = resultPos(r);
0017       return row[pos];
0018     }
0019   }
0020   return PerformancePayload::InvalidResult;
0021 }
0022 
0023 bool PerformancePayloadFromTable::matches(const BinningPointByMap& _p, PhysicsPerformancePayload::Row& row) const {
0024   //
0025   // this is the smart function which does not take into account the fields not present
0026   //
0027 
0028   // I can do it via a loop!
0029   BinningPointByMap p = _p;
0030   std::vector<BinningVariables::BinningVariablesType> t = myBinning();
0031 
0032   for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end(); ++it) {
0033     //
0034     // first the binning point map must contain ALL the quantities here
0035     //
0036     //    if (! p.isKeyAvailable(*it) ) return false;
0037     float v = p.value(*it);
0038     if (!(v >= row[minPos(*it)] && v < row[maxPos(*it)]))
0039       return false;
0040   }
0041   return true;
0042 }
0043 
0044 bool PerformancePayloadFromTable::isInPayload(PerformanceResult::ResultType res,
0045                                               const BinningPointByMap& _point) const {
0046   BinningPointByMap point = _point;
0047   // first, let's see if it is available at all
0048   if (resultPos(res) == PerformancePayloadFromTable::InvalidPos)
0049     return false;
0050   // now look whther the binning point contains all the info
0051   std::vector<BinningVariables::BinningVariablesType> t = myBinning();
0052   for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end(); ++it) {
0053     if (!point.isKeyAvailable(*it))
0054       return false;
0055   }
0056   // then, look if there is a matching row
0057   for (int i = 0; i < pl.nRows(); i++) {
0058     PhysicsPerformancePayload::Row row = pl.getRow(i);
0059     if (matches(point, row)) {
0060       return true;
0061     }
0062   }
0063   return false;
0064 }
0065 
0066 #include "FWCore/Utilities/interface/typelookup.h"
0067 TYPELOOKUP_DATA_REG(PerformancePayloadFromTable);