Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#include "CondFormats/PhysicsToolsObjects/interface/PerformancePayloadFromTable.h"

const int PerformancePayloadFromTable::InvalidPos = -1;

#include <iostream>

float PerformancePayloadFromTable::getResult(PerformanceResult::ResultType r, const BinningPointByMap& p) const {
  if (!isInPayload(r, p))
    return PerformancePayload::InvalidResult;

  // loop on the table rows and search for a match
  for (int i = 0; i < pl.nRows(); i++) {
    PhysicsPerformancePayload::Row row = pl.getRow(i);

    if (matches(p, row)) {
      int pos = resultPos(r);
      return row[pos];
    }
  }
  return PerformancePayload::InvalidResult;
}

bool PerformancePayloadFromTable::matches(const BinningPointByMap& _p, PhysicsPerformancePayload::Row& row) const {
  //
  // this is the smart function which does not take into account the fields not present
  //

  // I can do it via a loop!
  BinningPointByMap p = _p;
  std::vector<BinningVariables::BinningVariablesType> t = myBinning();

  for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end(); ++it) {
    //
    // first the binning point map must contain ALL the quantities here
    //
    //    if (! p.isKeyAvailable(*it) ) return false;
    float v = p.value(*it);
    if (!(v >= row[minPos(*it)] && v < row[maxPos(*it)]))
      return false;
  }
  return true;
}

bool PerformancePayloadFromTable::isInPayload(PerformanceResult::ResultType res,
                                              const BinningPointByMap& _point) const {
  BinningPointByMap point = _point;
  // first, let's see if it is available at all
  if (resultPos(res) == PerformancePayloadFromTable::InvalidPos)
    return false;
  // now look whther the binning point contains all the info
  std::vector<BinningVariables::BinningVariablesType> t = myBinning();
  for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end(); ++it) {
    if (!point.isKeyAvailable(*it))
      return false;
  }
  // then, look if there is a matching row
  for (int i = 0; i < pl.nRows(); i++) {
    PhysicsPerformancePayload::Row row = pl.getRow(i);
    if (matches(point, row)) {
      return true;
    }
  }
  return false;
}

#include "FWCore/Utilities/interface/typelookup.h"
TYPELOOKUP_DATA_REG(PerformancePayloadFromTable);