File indexing completed on 2023-03-17 11:24:01
0001 #include <iostream>
0002 #include <algorithm>
0003 #include <map>
0004 #include <utility>
0005
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007
0008 #include "SimDataFormats/GeneratorProducts/interface/GenLumiInfoProduct.h"
0009
0010 using namespace edm;
0011 using namespace std;
0012
0013 const bool operator<(const GenLumiInfoProduct::ProcessInfo& lhs, const GenLumiInfoProduct::ProcessInfo& rhs) {
0014 return (lhs.process() < rhs.process());
0015 }
0016
0017 const bool operator!=(const GenLumiInfoProduct::ProcessInfo& lhs, const GenLumiInfoProduct::ProcessInfo& rhs) {
0018 bool condition = (lhs.process() != rhs.process()) || (lhs.lheXSec() != rhs.lheXSec());
0019 return condition;
0020 }
0021
0022 const bool operator==(const GenLumiInfoProduct::ProcessInfo& lhs, const GenLumiInfoProduct::ProcessInfo& rhs) {
0023 bool condition =
0024 (lhs.process() == rhs.process() && lhs.lheXSec() == rhs.lheXSec() && lhs.nPassPos() == rhs.nPassPos() &&
0025 lhs.nPassNeg() == rhs.nPassNeg() && lhs.nTotalPos() == rhs.nTotalPos() && lhs.nTotalNeg() == rhs.nTotalNeg() &&
0026 lhs.tried() == rhs.tried() && lhs.selected() == rhs.selected() && lhs.killed() == rhs.killed() &&
0027 lhs.accepted() == rhs.accepted() && lhs.acceptedBr() == rhs.acceptedBr());
0028 return condition;
0029 }
0030
0031 const bool operator!=(const GenLumiInfoProduct& lhs, const GenLumiInfoProduct& rhs) {
0032 std::vector<GenLumiInfoProduct::ProcessInfo> lhsVector = lhs.getProcessInfos();
0033 std::vector<GenLumiInfoProduct::ProcessInfo> rhsVector = rhs.getProcessInfos();
0034 std::sort(lhsVector.begin(), lhsVector.end());
0035 std::sort(rhsVector.begin(), rhsVector.end());
0036 unsigned int lhssize = lhsVector.size();
0037 unsigned int rhssize = rhsVector.size();
0038 bool condition = (lhs.getHEPIDWTUP() != rhs.getHEPIDWTUP()) || (lhssize != rhssize);
0039 bool fail = false;
0040 if (!condition) {
0041 for (unsigned int i = 0; i < lhssize; i++) {
0042 if (lhsVector[i] != rhsVector[i]) {
0043 fail = true;
0044 break;
0045 }
0046 }
0047 }
0048 return (condition || fail);
0049 }
0050
0051 const bool operator==(const GenLumiInfoProduct& lhs, const GenLumiInfoProduct& rhs) {
0052 std::vector<GenLumiInfoProduct::ProcessInfo> lhsVector = lhs.getProcessInfos();
0053 std::vector<GenLumiInfoProduct::ProcessInfo> rhsVector = rhs.getProcessInfos();
0054 std::sort(lhsVector.begin(), lhsVector.end());
0055 std::sort(rhsVector.begin(), rhsVector.end());
0056 unsigned int lhssize = lhsVector.size();
0057 unsigned int rhssize = rhsVector.size();
0058
0059 bool condition = (lhs.getHEPIDWTUP() == rhs.getHEPIDWTUP()) && (lhssize == rhssize);
0060 unsigned int passCounts = 0;
0061 if (condition) {
0062 for (unsigned int i = 0; i < lhssize; i++) {
0063 if (lhsVector[i] == rhsVector[i])
0064 passCounts++;
0065 }
0066 }
0067 return (condition && (passCounts == lhssize));
0068 }
0069
0070 GenLumiInfoProduct::GenLumiInfoProduct() : hepidwtup_(-1) { internalProcesses_.clear(); }
0071
0072 GenLumiInfoProduct::GenLumiInfoProduct(const int id) : hepidwtup_(id) { internalProcesses_.clear(); }
0073
0074 GenLumiInfoProduct::GenLumiInfoProduct(GenLumiInfoProduct const& other)
0075 : hepidwtup_(other.hepidwtup_), internalProcesses_(other.internalProcesses_) {}
0076
0077 GenLumiInfoProduct::~GenLumiInfoProduct() {}
0078
0079 bool GenLumiInfoProduct::mergeProduct(GenLumiInfoProduct const& other) {
0080 std::map<int, ProcessInfo> processes;
0081
0082 for (unsigned int i = 0; i < getProcessInfos().size(); i++) {
0083 int id = getProcessInfos()[i].process();
0084 ProcessInfo& x = processes[id];
0085 x = getProcessInfos()[i];
0086 }
0087
0088
0089
0090 for (unsigned int i = 0; i < other.getProcessInfos().size(); i++) {
0091 int id = other.getProcessInfos()[i].process();
0092 ProcessInfo& x = processes[id];
0093 if (x.lheXSec().value() > 0)
0094 x.addOthers(other.getProcessInfos()[i]);
0095 else
0096 x = other.getProcessInfos()[i];
0097 }
0098
0099 internalProcesses_.resize(processes.size());
0100 unsigned int i = 0;
0101 for (std::map<int, ProcessInfo>::const_iterator iter = processes.begin(); iter != processes.end(); ++iter, i++)
0102 internalProcesses_[i] = iter->second;
0103 return true;
0104 }
0105
0106 void GenLumiInfoProduct::swap(GenLumiInfoProduct& other) {
0107 std::swap(hepidwtup_, other.hepidwtup_);
0108 internalProcesses_.swap(other.internalProcesses_);
0109 }
0110
0111 bool GenLumiInfoProduct::isProductEqual(GenLumiInfoProduct const& other) const { return ((*this) == other); }