diff --git a/CondFormats/PhysicsToolsObjects/interface/MVAComputer.h b/CondFormats/PhysicsToolsObjects/interface/MVAComputer.h index 9a2ecd5555989..8d656cd816dab 100644 --- a/CondFormats/PhysicsToolsObjects/interface/MVAComputer.h +++ b/CondFormats/PhysicsToolsObjects/interface/MVAComputer.h @@ -14,6 +14,7 @@ #include "CondFormats/Serialization/interface/Serializable.h" +#include #include #include #include @@ -54,6 +55,9 @@ class VarProcessor { virtual ~VarProcessor() {} virtual std::string getInstanceName() const; +#ifndef __GCCXML__ + virtual std::unique_ptr clone() const; +#endif COND_SERIALIZABLE; }; @@ -73,17 +77,27 @@ class Variable { class ProcOptional : public VarProcessor { public: +#ifndef __GCCXML__ + virtual std::unique_ptr clone() const; +#endif std::vector neutralPos; COND_SERIALIZABLE; }; class ProcCount : public VarProcessor { + public: +#ifndef __GCCXML__ + virtual std::unique_ptr clone() const; +#endif COND_SERIALIZABLE; }; class ProcClassed : public VarProcessor { public: +#ifndef __GCCXML__ + virtual std::unique_ptr clone() const; +#endif unsigned int nClasses; COND_SERIALIZABLE; @@ -91,6 +105,9 @@ class ProcClassed : public VarProcessor { class ProcSplitter : public VarProcessor { public: +#ifndef __GCCXML__ + virtual std::unique_ptr clone() const; +#endif unsigned int nFirst; COND_SERIALIZABLE; @@ -98,6 +115,9 @@ class ProcSplitter : public VarProcessor { class ProcForeach : public VarProcessor { public: +#ifndef __GCCXML__ + virtual std::unique_ptr clone() const; +#endif unsigned int nProcs; COND_SERIALIZABLE; @@ -105,6 +125,9 @@ class ProcForeach : public VarProcessor { class ProcSort : public VarProcessor { public: +#ifndef __GCCXML__ + virtual std::unique_ptr clone() const; +#endif unsigned int sortByIndex; bool descending; @@ -113,6 +136,9 @@ class ProcSort : public VarProcessor { class ProcCategory : public VarProcessor { public: +#ifndef __GCCXML__ + virtual std::unique_ptr clone() const; +#endif typedef std::vector BinLimits; std::vector variableBinLimits; @@ -123,6 +149,9 @@ class ProcCategory : public VarProcessor { class ProcNormalize : public VarProcessor { public: +#ifndef __GCCXML__ + virtual std::unique_ptr clone() const; +#endif std::vector distr; int categoryIdx; @@ -131,6 +160,9 @@ class ProcNormalize : public VarProcessor { class ProcLikelihood : public VarProcessor { public: +#ifndef __GCCXML__ + virtual std::unique_ptr clone() const; +#endif class SigBkg { public: HistogramF background; @@ -153,6 +185,9 @@ class ProcLikelihood : public VarProcessor { class ProcLinear : public VarProcessor { public: +#ifndef __GCCXML__ + virtual std::unique_ptr clone() const; +#endif std::vector coeffs; double offset; @@ -161,6 +196,9 @@ class ProcLinear : public VarProcessor { class ProcMultiply : public VarProcessor { public: +#ifndef __GCCXML__ + virtual std::unique_ptr clone() const; +#endif typedef std::vector Config; unsigned int in; @@ -171,6 +209,9 @@ class ProcMultiply : public VarProcessor { class ProcMatrix : public VarProcessor { public: +#ifndef __GCCXML__ + virtual std::unique_ptr clone() const; +#endif Matrix matrix; COND_SERIALIZABLE; @@ -178,6 +219,9 @@ class ProcMatrix : public VarProcessor { class ProcExternal : public VarProcessor { public: +#ifndef __GCCXML__ + virtual std::unique_ptr clone() const; +#endif virtual std::string getInstanceName() const; std::string method; @@ -188,6 +232,9 @@ class ProcExternal : public VarProcessor { class ProcMLP : public VarProcessor { public: +#ifndef __GCCXML__ + virtual std::unique_ptr clone() const; +#endif typedef std::pair > Neuron; typedef std::pair, bool> Layer; diff --git a/CondFormats/PhysicsToolsObjects/src/MVAComputer.cc b/CondFormats/PhysicsToolsObjects/src/MVAComputer.cc index c55f8972647b8..c1bafc528bfd1 100644 --- a/CondFormats/PhysicsToolsObjects/src/MVAComputer.cc +++ b/CondFormats/PhysicsToolsObjects/src/MVAComputer.cc @@ -9,16 +9,10 @@ // the discriminator computer calibration object. POOL doesn't support // polymorph pointers, so this is implemented using multiple containers // for each possible sub-class and an index array from which the -// array of pointers can be reconstructed. In order to avoid having -// to handle each sub-class container by hand here, the generated -// reflex dictionary is used to find and read/write the std::vector<...> -// containers for the individual classes in the private data members. -// So changes can be solely done in the header files and does not leave -// a trail elsewhere. +// array of pointers can be reconstructed. // // Author: Christophe Saout // Created: Sat Apr 24 15:18 CEST 2007 -// $Id: MVAComputer.cc,v 1.10 2010/01/26 19:40:03 saout Exp $ // #include #include @@ -53,6 +47,81 @@ std::string VarProcessor::getInstanceName() const return type.substr(sizeof prefix - 1); } +std::unique_ptr +VarProcessor::clone() const { + return(std::unique_ptr(new VarProcessor(*this))); +} + +std::unique_ptr +ProcOptional::clone() const { + return(std::unique_ptr(new ProcOptional(*this))); +} + +std::unique_ptr +ProcCount::clone() const { + return(std::unique_ptr(new ProcCount(*this))); +} + +std::unique_ptr +ProcClassed::clone() const { + return(std::unique_ptr(new ProcClassed(*this))); +} + +std::unique_ptr +ProcSplitter::clone() const { + return(std::unique_ptr(new ProcSplitter(*this))); +} + +std::unique_ptr +ProcForeach::clone() const { + return(std::unique_ptr(new ProcForeach(*this))); +} + +std::unique_ptr +ProcSort::clone() const { + return(std::unique_ptr(new ProcSort(*this))); +} + +std::unique_ptr +ProcCategory::clone() const { + return(std::unique_ptr(new ProcCategory(*this))); +} + +std::unique_ptr +ProcNormalize::clone() const { + return(std::unique_ptr(new ProcNormalize(*this))); +} + +std::unique_ptr +ProcLikelihood::clone() const { + return(std::unique_ptr(new ProcLikelihood(*this))); +} + +std::unique_ptr +ProcLinear::clone() const { + return(std::unique_ptr(new ProcLinear(*this))); +} + +std::unique_ptr +ProcMultiply::clone() const { + return(std::unique_ptr(new ProcMultiply(*this))); +} + +std::unique_ptr +ProcMatrix::clone() const { + return(std::unique_ptr(new ProcMatrix(*this))); +} + +std::unique_ptr +ProcExternal::clone() const { + return(std::unique_ptr(new ProcExternal(*this))); +} + +std::unique_ptr +ProcMLP::clone() const { + return(std::unique_ptr(new ProcMLP(*this))); +} + std::string ProcExternal::getInstanceName() const { return method; @@ -118,42 +187,7 @@ std::vector MVAComputer::getProcessors() const void MVAComputer::addProcessor(const VarProcessor *proc) { cacheId = getNextMVAComputerCacheId(); - - ROOT::Reflex::Type baseType = ROOT::Reflex::GetType(); - ROOT::Reflex::Type type = - ROOT::Reflex::Type::ByTypeInfo(typeid(*proc)); - ROOT::Reflex::Type refType(type, - ROOT::Reflex::CONST & ROOT::Reflex::REFERENCE); - if (!type.Name().size()) - throw cms::Exception("MVAComputerCalibration") - << "Calibration class " << typeid(*proc).name() - << " not registered with ROOT::Reflex." - << std::endl; - - ROOT::Reflex::Object obj = - ROOT::Reflex::Object(baseType, const_cast( - static_cast(proc))).CastObject(type); - - // find and call copy constructor - for(ROOT::Reflex::Member_Iterator iter = type.FunctionMember_Begin(); - iter != type.FunctionMember_End(); iter++) { - const ROOT::Reflex::Type &ctor = iter->TypeOf(); - if (!iter->IsConstructor() || - ctor.FunctionParameterSize() != 1 || - ctor.FunctionParameterAt(0).Id() != refType.Id()) - continue; - - ROOT::Reflex::Object copy = type.Construct(ctor, - ROOT::Reflex::Tools::MakeVector(obj.Address())); - - processors.push_back(static_cast(copy.Address())); - return; - } - - throw cms::Exception("MVAComputerCalibration") - << "Calibration class " << typeid(*proc).name() - << " has no copy ctor registered with ROOT::Reflex." - << std::endl; + processors.push_back(proc->clone().release()); } static MVAComputerContainer::CacheId getNextMVAComputerContainerCacheId()