Skip to content

Commit

Permalink
Merge pull request #6896 from wmtan/RemoveUnnecessaryTypeInfoCalls
Browse files Browse the repository at this point in the history
Remove unnecessary type info calls
  • Loading branch information
ktf committed Dec 27, 2014
2 parents ebde716 + aba1bb9 commit 46a49c5
Show file tree
Hide file tree
Showing 18 changed files with 544 additions and 330 deletions.
32 changes: 15 additions & 17 deletions CommonTools/Utils/src/AnyMethodArgument.h
Expand Up @@ -52,31 +52,29 @@ namespace reco {
class AnyMethodArgumentFixup : public boost::static_visitor<std::pair<AnyMethodArgument, int> > {
private:
edm::TypeWithDict dataType_;
const std::type_info & type_;
template<typename From, typename To>
std::pair<AnyMethodArgument, int> retOk_(const From &f, int cast) const {
return std::pair<AnyMethodArgument,int>(AnyMethodArgument(static_cast<To>(f)), cast);
}

// correct return for each int output type
std::pair<AnyMethodArgument,int> doInt(int t) const {
if (type_ == typeid(int8_t)) { return retOk_<int,int8_t> (t,0); }
if (type_ == typeid(uint8_t)) { return retOk_<int,uint8_t> (t,0); }
if (type_ == typeid(int16_t)) { return retOk_<int,int16_t> (t,0); }
if (type_ == typeid(uint16_t)) { return retOk_<int,uint16_t>(t,0); }
if (type_ == typeid(int32_t)) { return retOk_<int,int32_t> (t,0); }
if (type_ == typeid(uint32_t)) { return retOk_<int,uint32_t>(t,0); }
if (type_ == typeid(int64_t)) { return retOk_<int,int64_t> (t,0); }
if (type_ == typeid(uint64_t)) { return retOk_<int,uint64_t>(t,0); }
if (type_ == typeid(unsigned long)) { return retOk_<int,unsigned long> (t,0); } // harmless if unsigned long matches another type
if (type_ == typeid(double)) { return retOk_<int,double> (t,1); }
if (type_ == typeid(float)) { return retOk_<int,float> (t,1); }
if (dataType_ == typeid(int8_t)) { return retOk_<int,int8_t> (t,0); }
if (dataType_ == typeid(uint8_t)) { return retOk_<int,uint8_t> (t,0); }
if (dataType_ == typeid(int16_t)) { return retOk_<int,int16_t> (t,0); }
if (dataType_ == typeid(uint16_t)) { return retOk_<int,uint16_t>(t,0); }
if (dataType_ == typeid(int32_t)) { return retOk_<int,int32_t> (t,0); }
if (dataType_ == typeid(uint32_t)) { return retOk_<int,uint32_t>(t,0); }
if (dataType_ == typeid(int64_t)) { return retOk_<int,int64_t> (t,0); }
if (dataType_ == typeid(uint64_t)) { return retOk_<int,uint64_t>(t,0); }
if (dataType_ == typeid(unsigned long)) { return retOk_<int,unsigned long> (t,0); } // harmless if unsigned long matches another type
if (dataType_ == typeid(double)) { return retOk_<int,double> (t,1); }
if (dataType_ == typeid(float)) { return retOk_<int,float> (t,1); }
return std::pair<AnyMethodArgument,int>(t,-1);
}
public:
AnyMethodArgumentFixup(const edm::TypeWithDict& type) :
dataType_(type),
type_(type.typeInfo())
dataType_(type)
{
}

Expand All @@ -88,13 +86,12 @@ namespace reco {
template<typename F>
typename boost::enable_if<boost::is_floating_point<F>, std::pair<AnyMethodArgument,int> >::type
operator()(const F &t) const {
if (type_ == typeid(double)) { return retOk_<F,double>(t,0); }
if (type_ == typeid(float)) { return retOk_<F,float> (t,0); }
if (dataType_ == typeid(double)) { return retOk_<F,double>(t,0); }
if (dataType_ == typeid(float)) { return retOk_<F,float> (t,0); }
return std::pair<AnyMethodArgument,int>(t,-1);
}

std::pair<AnyMethodArgument,int> operator()(const std::string &t) const {
if (type_ == typeid(std::string)) { return std::pair<AnyMethodArgument,int>(t,0); }
if (dataType_.isEnum()) {
if (dataType_.dataMemberSize() == 0) {
throw parser::Exception(t.c_str()) << "Enumerator '" << dataType_.name() << "' has no keys.\nPerhaps the dictionary is missing?\n";
Expand All @@ -103,6 +100,7 @@ namespace reco {
// std::cerr << " value is = " << dataType_.stringToEnumValue(t) << std::endl;
return std::pair<AnyMethodArgument,int>(ival,1);
}
if (dataType_ == typeid(std::string)) { return std::pair<AnyMethodArgument,int>(t,0); }
return std::pair<AnyMethodArgument,int>(t,-1);
}

Expand Down
14 changes: 7 additions & 7 deletions CommonTools/Utils/src/MethodArgumentStack.h
@@ -1,21 +1,21 @@
#ifndef CommonTools_Utils_MethodArgumentStack_h
#define CommonTools_Utils_MethodArgumentStack_h

/* \class reco::parser::MethodArgumentStack
*
* Stack of method arguments
*
* \author Giovanni Petrucciani, SNS
*
* \version $Revision: 1.1 $
*
*/

#include "CommonTools/Utils/src/MethodInvoker.h"
#include <vector>

namespace reco {
namespace parser {
typedef std::vector<AnyMethodArgument> MethodArgumentStack;
}
}
namespace parser {
typedef std::vector<AnyMethodArgument> MethodArgumentStack;
} // namespace reco
} // namespace parser

#endif
#endif // CommonTools_Utils_MethodArgumentStack_h

0 comments on commit 46a49c5

Please sign in to comment.