Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Bin lookup in the JetCorrectorParameters class" #18036

Merged
merged 1 commit into from Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CondCore/JetMETPlugins/src/plugins.cc
Expand Up @@ -19,7 +19,7 @@
#include "CondFormats/DataRecord/interface/JetResolutionRcd.h"
#include "CondFormats/DataRecord/interface/JetResolutionScaleFactorRcd.h"

REGISTER_PLUGIN_INIT(JetCorrectionsRecord, JetCorrectorParametersCollection, JetCorrectorParametersInitializeTransients);
REGISTER_PLUGIN(JetCorrectionsRecord, JetCorrectorParametersCollection);
REGISTER_PLUGIN(METCorrectionsRecord, METCorrectorParametersCollection);
REGISTER_PLUGIN(MEtXYcorrectRecord, MEtXYcorrectParametersCollection);

Expand Down
69 changes: 19 additions & 50 deletions CondFormats/JetMETObjects/interface/JetCorrectorParameters.h
Expand Up @@ -8,20 +8,14 @@
#define JetCorrectorParameters_h

#include "CondFormats/Serialization/interface/Serializable.h"
#include "CondFormats/JetMETObjects/interface/Utilities.h"

#include <string>
#include <vector>
#include <tuple>
#include <algorithm>
#include <functional>
#include <iostream>
#include <memory>
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

class JetCorrectorParametersHelper;

class JetCorrectorParameters
{
//---------------- JetCorrectorParameters class ----------------
Expand Down Expand Up @@ -54,8 +48,8 @@ class JetCorrectorParameters
std::vector<std::string> mParVar;
std::vector<std::string> mBinVar;

COND_SERIALIZABLE;
};
COND_SERIALIZABLE;
};
//---------------- Record class --------------------------------
//-- Each Record holds the properties of a bin -----------------
class Record
Expand All @@ -66,30 +60,22 @@ class JetCorrectorParameters
Record(unsigned fNvar, const std::vector<float>& fXMin, const std::vector<float>& fXMax, const std::vector<float>& fParameters) : mNvar(fNvar),mMin(fXMin),mMax(fXMax),mParameters(fParameters) {}
Record(const std::string& fLine, unsigned fNvar);
//-------- Member functions ----------
unsigned nVar() const {return mNvar; }
float xMin(unsigned fVar) const {return mMin[fVar]; }
float xMax(unsigned fVar) const {return mMax[fVar]; }
float xMiddle(unsigned fVar) const {return 0.5*(xMin(fVar)+xMax(fVar));}
float parameter(unsigned fIndex) const {return mParameters[fIndex]; }
std::vector<float> parameters() const {return mParameters; }
unsigned nParameters() const {return mParameters.size(); }
bool operator< (const Record& other) const
{
if (xMin(0) < other.xMin(0)) return true;
if (xMin(0) > other.xMin(0)) return false;
if (xMin(1) < other.xMin(1)) return true;
if (xMin(1) > other.xMin(1)) return false;
return (xMin(2) < other.xMin(2));
}
int operator< (const Record& other) const {return xMin(0) < other.xMin(0); }
private:
//-------- Member variables ----------
unsigned mNvar;
std::vector<float> mMin;
std::vector<float> mMax;
std::vector<float> mParameters;

COND_SERIALIZABLE;
};
COND_SERIALIZABLE;
};

//-------- Constructors --------------
JetCorrectorParameters() { valid_ = false;}
Expand All @@ -98,33 +84,28 @@ class JetCorrectorParameters
const std::vector<JetCorrectorParameters::Record>& fRecords)
: mDefinitions(fDefinitions),mRecords(fRecords) { valid_ = true;}
//-------- Member functions ----------
const Record& record(unsigned fBin) const {return mRecords[fBin]; }
const Definitions& definitions() const {return mDefinitions; }
unsigned size() const {return mRecords.size();}
unsigned size(unsigned fVar) const;
int binIndex(const std::vector<float>& fX) const;
int binIndexN(const std::vector<float>& fX) const;
int neighbourBin(unsigned fIndex, unsigned fVar, bool fNext) const;
std::vector<float> binCenters(unsigned fVar) const;
void printScreen() const;
void printFile(const std::string& fFileName) const;
const Record& record(unsigned fBin) const {return mRecords[fBin]; }
const Definitions& definitions() const {return mDefinitions; }
unsigned size() const {return mRecords.size();}
unsigned size(unsigned fVar) const;
int binIndex(const std::vector<float>& fX) const;
int neighbourBin(unsigned fIndex, unsigned fVar, bool fNext) const;
std::vector<float> binCenters(unsigned fVar) const;
void printScreen() const;
void printFile(const std::string& fFileName) const;
bool isValid() const { return valid_; }
void init();

static const int MAX_SIZE_DIMENSIONALITY = 3 COND_TRANSIENT;

private:
//-------- Member variables ----------
JetCorrectorParameters::Definitions mDefinitions;
std::vector<JetCorrectorParameters::Record> mRecords;
bool valid_; /// is this a valid set?

std::shared_ptr<JetCorrectorParametersHelper> helper COND_TRANSIENT;
JetCorrectorParameters::Definitions mDefinitions;
std::vector<JetCorrectorParameters::Record> mRecords;
bool valid_; /// is this a valid set?

COND_SERIALIZABLE;
};



class JetCorrectorParametersCollection {
//---------------- JetCorrectorParametersCollection class ----------------
//-- Adds several JetCorrectorParameters together by algorithm type ---
Expand Down Expand Up @@ -233,22 +214,10 @@ class JetCorrectorParametersCollection {
collection_type correctionsL5_;
collection_type correctionsL7_;

collection_type& getCorrections() {return corrections_;}
collection_type& getCorrectionsL5() {return correctionsL5_;}
collection_type& getCorrectionsL7() {return correctionsL7_;}

friend struct JetCorrectorParametersInitializeTransients;

COND_SERIALIZABLE;

};

struct JetCorrectorParametersInitializeTransients {
void operator()(JetCorrectorParametersCollection& jcpc) {
for (auto & ptype : jcpc.getCorrections()) {ptype.second.init();}
for (auto & ptype : jcpc.getCorrectionsL5()) {ptype.second.init();}
for (auto & ptype : jcpc.getCorrectionsL7()) {ptype.second.init();}
}
};


#endif
51 changes: 0 additions & 51 deletions CondFormats/JetMETObjects/interface/JetCorrectorParametersHelper.h

This file was deleted.

181 changes: 0 additions & 181 deletions CondFormats/JetMETObjects/interface/Utilities.h
Expand Up @@ -11,120 +11,7 @@
#include <sstream>
#include <string>
#include <vector>
#include <tuple>
#include <cmath>
#include <utility>

namespace std
{
//These functions print a tuple using a provided std::ostream
template<typename Type, unsigned N, unsigned Last>
struct tuple_printer {

static void print(std::ostream& out, const Type& value) {
out << std::get<N>(value) << ", ";
tuple_printer<Type, N + 1, Last>::print(out, value);
}
};
template<typename Type, unsigned N>
struct tuple_printer<Type, N, N> {

static void print(std::ostream& out, const Type& value) {
out << std::get<N>(value);
}

};
template<typename... Types>
std::ostream& operator<<(std::ostream& out, const std::tuple<Types...>& value) {
out << "(";
tuple_printer<std::tuple<Types...>, 0, sizeof...(Types) - 1>::print(out, value);
out << ")";
return out;
}
//----------------------------------------------------------------------
//Returns a list of type indices
template <size_t... n>
struct ct_integers_list {
template <size_t m>
struct push_back
{
typedef ct_integers_list<n..., m> type;
};
};
template <size_t max>
struct ct_iota_1
{
typedef typename ct_iota_1<max-1>::type::template push_back<max>::type type;
};
template <>
struct ct_iota_1<0>
{
typedef ct_integers_list<> type;
};
//----------------------------------------------------------------------
//Return a tuple which is a subset of the original tuple
//This function pops an entry off the font of the tuple
template <size_t... indices, typename Tuple>
auto tuple_subset(const Tuple& tpl, ct_integers_list<indices...>)
-> decltype(std::make_tuple(std::get<indices>(tpl)...))
{
return std::make_tuple(std::get<indices>(tpl)...);
// this means:
// make_tuple(get<indices[0]>(tpl), get<indices[1]>(tpl), ...)
}
template <typename Head, typename... Tail>
std::tuple<Tail...> tuple_tail(const std::tuple<Head, Tail...>& tpl)
{
return tuple_subset(tpl, typename ct_iota_1<sizeof...(Tail)>::type());
// this means:
// tuple_subset<1, 2, 3, ..., sizeof...(Tail)-1>(tpl, ..)
}
//----------------------------------------------------------------------
//Recursive hashing function for tuples
template<typename Head, typename... ndims> struct hash_specialization
{
typedef std::tuple<Head,ndims...> argument_type;
typedef std::size_t result_type;
result_type operator()(const argument_type& t) const
{
const uint32_t& b = reinterpret_cast<const uint32_t&>(std::get<0>(t));
//const uint32_t& more = (*this)(tuple_tail(t));
const uint32_t& more = hash_specialization<ndims...>()(tuple_tail(t));
return b^more;
}
};
//Base case
template<> struct hash_specialization<float>
{
typedef std::tuple<float> argument_type;
typedef std::size_t result_type;
result_type operator()(const argument_type& t) const
{
const uint32_t& b = reinterpret_cast<const uint32_t&>(std::get<0>(t));
const result_type& result = reinterpret_cast<const result_type&>(b);
return result;
}
};
//Overloaded verions of std::hash for tuples
template<typename Head, typename... ndims> struct hash<std::tuple<Head, ndims...> >
{
typedef std::tuple<Head,ndims...> argument_type;
typedef std::size_t result_type;
result_type operator()(const argument_type& t) const
{
return hash_specialization<Head,ndims...>()(t);
}
};
template<> struct hash<std::tuple<> >
{
typedef std::tuple<> argument_type;
typedef std::size_t result_type;
result_type operator()(const argument_type& t) const
{
return -1;
}
};
}

namespace
{
Expand Down Expand Up @@ -242,73 +129,5 @@ namespace
float r = a[0]+fZ*(a[1]+fZ*a[2]);
return r;
}
//------------------------------------------------------------------------
//Generates a std::tuple type based on a stored type and the number of
// objects in the tuple.
//Note: All of the objects will be of the same type
template<typename /*LEFT_TUPLE*/, typename /*RIGHT_TUPLE*/>
struct join_tuples
{
};
template<typename... LEFT, typename... RIGHT>
struct join_tuples<std::tuple<LEFT...>, std::tuple<RIGHT...>>
{
typedef std::tuple<LEFT..., RIGHT...> type;
};
template<typename T, unsigned N>
struct generate_tuple_type
{
typedef typename generate_tuple_type<T, N/2>::type left;
typedef typename generate_tuple_type<T, N/2 + N%2>::type right;
typedef typename join_tuples<left, right>::type type;
};
template<typename T>
struct generate_tuple_type<T, 1>
{
typedef std::tuple<T> type;
};
template<typename T>
struct generate_tuple_type<T, 0>
{
typedef std::tuple<> type;
};
//------------------------------------------------------------------------
//C++11 implementation of make_index_sequence, which is a C++14 function
// using aliases for cleaner syntax
template<class T> using Invoke = typename T::type;

template<unsigned...> struct seq{ using type = seq; };

template<class S1, class S2> struct concat;

template<unsigned... I1, unsigned... I2>
struct concat<seq<I1...>, seq<I2...>>
: seq<I1..., (sizeof...(I1)+I2)...>{};

template<class S1, class S2>
using Concat = Invoke<concat<S1, S2>>;

template<unsigned N> struct gen_seq;
template<unsigned N> using GenSeq = Invoke<gen_seq<N>>;

template<unsigned N>
struct gen_seq : Concat<GenSeq<N/2>, GenSeq<N - N/2>>{};

template<> struct gen_seq<0> : seq<>{};
template<> struct gen_seq<1> : seq<0>{};
//------------------------------------------------------------------------
//Generates a tuple based on a given function (i.e. lambda expression)
template <typename F, unsigned... Is>
auto gen_tuple_impl(F func, seq<Is...> )
-> decltype(std::make_tuple(func(Is)...))
{
return std::make_tuple(func(Is)...);
}
template <unsigned N, typename F>
auto gen_tuple(F func)
-> decltype(gen_tuple_impl(func, GenSeq<N>() ))
{
return gen_tuple_impl(func, GenSeq<N>() );
}
}
#endif