@@ -87,13 +87,13 @@ template <typename ObjType, typename CollectionStringFunctor, typename Precision
8787class FuncCollectionVariable : public CollectionVariable <ObjType> {
8888public:
8989 FuncCollectionVariable (const std::string &aname, const edm::ParameterSet &cfg)
90- : CollectionVariable<ObjType>(aname, cfg),
91- func_ (cfg.getParameter<std::string>(" expr" ), cfg.getUntrackedParameter<bool >(" lazyEval" )),
92- precisionFunc_ (cfg.existsAs<std::string>(" precision" ) ? cfg.getParameter<std::string>(" precision" ) : " 23" ,
93- cfg.getUntrackedParameter<bool >(" lazyEval" )) {}
90+ : CollectionVariable<ObjType>(aname, cfg),
91+ func_ (cfg.getParameter<std::string>(" expr" ), cfg.getUntrackedParameter<bool >(" lazyEval" )),
92+ precisionFunc_ (cfg.existsAs<std::string>(" precision" ) ? cfg.getParameter<std::string>(" precision" ) : " 23" ,
93+ cfg.getUntrackedParameter<bool >(" lazyEval" )) {}
9494 ~FuncCollectionVariable () override {}
95-
96- std::unique_ptr<std::vector<unsigned int >> getCounts (std::vector<const ObjType *> &selobjs) const override {
95+
96+ std::unique_ptr<std::vector<unsigned int >> getCounts (std::vector<const ObjType *> &selobjs) const override {
9797 auto counts = std::make_unique<std::vector<unsigned int >>();
9898 for (auto const &obj : selobjs)
9999 counts->push_back (func_ (*obj).size ());
@@ -119,8 +119,8 @@ class FuncCollectionVariable : public CollectionVariable<ObjType> {
119119 }
120120
121121protected:
122- CollectionStringFunctor func_; // functor to get collection objects
123- PrecisionStringFunctor precisionFunc_; // functor to get output precision
122+ CollectionStringFunctor func_; // functor to get collection objects
123+ PrecisionStringFunctor precisionFunc_; // functor to get output precision
124124};
125125
126126// External variables: i.e. variables that are not member or methods of the object
@@ -538,19 +538,21 @@ class SimpleTypedExternalFlatTableProducer : public SimpleFlatTableProducer<T> {
538538
539539template <typename T>
540540class SimpleCollectionFlatTableProducer : public SimpleFlatTableProducer <T> {
541- public:
541+ public:
542542 SimpleCollectionFlatTableProducer (edm::ParameterSet const ¶ms) : SimpleFlatTableProducer<T>(params) {
543543 if (params.existsAs <edm::ParameterSet>(" collectionVariables" )) {
544544 edm::ParameterSet const &collectionVarsPSet = params.getParameter <edm::ParameterSet>(" collectionVariables" );
545- for (const std::string &coltablename : collectionVarsPSet.getParameterNamesForType <edm::ParameterSet>()) { // tables of variables
545+ for (const std::string &coltablename :
546+ collectionVarsPSet.getParameterNamesForType <edm::ParameterSet>()) { // tables of variables
546547 const auto &coltablePSet = collectionVarsPSet.getParameter <edm::ParameterSet>(coltablename);
547548 CollectionVariableTableInfo coltable;
548- coltable.name = coltablePSet.existsAs <std::string>(" name" ) ? coltablePSet.getParameter <std::string>(" name" ) : coltablename;
549+ coltable.name =
550+ coltablePSet.existsAs <std::string>(" name" ) ? coltablePSet.getParameter <std::string>(" name" ) : coltablename;
549551 coltable.doc = coltablePSet.getParameter <std::string>(" doc" );
550552 coltable.useCount = coltablePSet.getParameter <bool >(" useCount" );
551553 coltable.useOffset = coltablePSet.getParameter <bool >(" useOffset" );
552554 const auto &colvarsPSet = coltablePSet.getParameter <edm::ParameterSet>(" variables" );
553- for (const std::string &colvarname : colvarsPSet.getParameterNamesForType <edm::ParameterSet>()) { // variables
555+ for (const std::string &colvarname : colvarsPSet.getParameterNamesForType <edm::ParameterSet>()) { // variables
554556 const auto &colvarPSet = colvarsPSet.getParameter <edm::ParameterSet>(colvarname);
555557 const std::string &type = colvarPSet.getParameter <std::string>(" type" );
556558 if (type == " int" )
@@ -568,7 +570,8 @@ class SimpleCollectionFlatTableProducer : public SimpleFlatTableProducer<T> {
568570 else if (type == " uint16" )
569571 coltable.colvars .push_back (std::make_unique<UInt16VectorVar>(colvarname, colvarPSet));
570572 else
571- throw cms::Exception (" Configuration" , " unsupported type " + type + " for variable " + colvarname + " in " + coltablename);
573+ throw cms::Exception (" Configuration" ,
574+ " unsupported type " + type + " for variable " + colvarname + " in " + coltablename);
572575 }
573576 this ->coltables .push_back (std::move (coltable));
574577 edm::stream::EDProducer<>::produces<nanoaod::FlatTable>(coltables.back ().name + " Table" );
@@ -581,14 +584,14 @@ class SimpleCollectionFlatTableProducer : public SimpleFlatTableProducer<T> {
581584 static void fillDescriptions (edm::ConfigurationDescriptions &descriptions) {
582585 edm::ParameterSetDescription desc = SimpleFlatTableProducer<T>::baseDescriptions ();
583586 edm::ParameterSetDescription colvariable;
584- colvariable.add <std::string>(" expr" )->setComment (" a function to define the content of the branch in the flat table" );
587+ colvariable.add <std::string>(" expr" )->setComment (
588+ " a function to define the content of the branch in the flat table" );
585589 colvariable.add <std::string>(" doc" )->setComment (" few words of self documentation" );
586590 colvariable.addUntracked <bool >(" lazyEval" , false )
587591 ->setComment (" if true, can use methods of inheriting classes in `expr`. Can cause problems with threading." );
588- colvariable.ifValue (
589- edm::ParameterDescription<std::string>(
590- " type" , " int" , true , edm::Comment (" the c++ type of the branch in the flat table" )),
591- edm::allowedValues<std::string>(" int" , " uint" , " float" , " double" , " uint8" , " int16" , " uint16" ));
592+ colvariable.ifValue (edm::ParameterDescription<std::string>(
593+ " type" , " int" , true , edm::Comment (" the c++ type of the branch in the flat table" )),
594+ edm::allowedValues<std::string>(" int" , " uint" , " float" , " double" , " uint8" , " int16" , " uint16" ));
592595 colvariable.addOptionalNode (
593596 edm::ParameterDescription<int >(
594597 " precision" , true , edm::Comment (" the precision with which to store the value in the flat table" )) xor
@@ -599,10 +602,12 @@ class SimpleCollectionFlatTableProducer : public SimpleFlatTableProducer<T> {
599602 colvariables.setComment (" a parameters set to define all variable to fill the flat table" );
600603 colvariables.addNode (
601604 edm::ParameterWildcard<edm::ParameterSetDescription>(" *" , edm::RequireAtLeastOne, true , colvariable));
602-
605+
603606 edm::ParameterSetDescription coltable;
604- coltable.addOptional <std::string>(" name" )->setComment (" name of the branch in the flat table containing flatten collections of variables" );
605- coltable.add <std::string>(" doc" )->setComment (" few words description of the table containing flatten collections of variables" );
607+ coltable.addOptional <std::string>(" name" )->setComment (
608+ " name of the branch in the flat table containing flatten collections of variables" );
609+ coltable.add <std::string>(" doc" )->setComment (
610+ " few words description of the table containing flatten collections of variables" );
606611 coltable.add <bool >(" useCount" , true )
607612 ->setComment (" whether to use count for the main table to index table with flatten collections of variables" );
608613 coltable.add <bool >(" useOffset" , false )
@@ -674,27 +679,32 @@ class SimpleCollectionFlatTableProducer : public SimpleFlatTableProducer<T> {
674679 out->template addColumn <uint16_t >(" o" + coltable.name , offsets, " offsets for " + coltable.name );
675680 }
676681
677- std::unique_ptr<nanoaod::FlatTable> outcoltable = std::make_unique<nanoaod::FlatTable>(coltablesize, coltable.name , false , false );
682+ std::unique_ptr<nanoaod::FlatTable> outcoltable =
683+ std::make_unique<nanoaod::FlatTable>(coltablesize, coltable.name , false , false );
678684 for (const auto &colvar : coltable.colvars ) {
679685 colvar->fill (selobjs, *outcoltable);
680686 }
681687 outcoltable->setDoc (coltable.doc );
682688 iEvent.put (std::move (outcoltable), coltable.name + " Table" );
683689 }
684-
690+
685691 // put the main table into the event
686692 out->setDoc (this ->doc_ );
687693 iEvent.put (std::move (out));
688694 }
689695
690696protected:
691- typedef FuncCollectionVariable<T, TypedStringObjectMethodCaller<T, std::vector<int32_t >>, StringObjectFunction<T>, int32_t > IntVectorVar;
692- typedef FuncCollectionVariable<T, TypedStringObjectMethodCaller<T, std::vector<uint32_t >>, StringObjectFunction<T>, uint32_t > UIntVectorVar;
693- typedef FuncCollectionVariable<T, TypedStringObjectMethodCaller<T, std::vector<float >>, StringObjectFunction<T>, float > FloatVectorVar;
694- typedef FuncCollectionVariable<T, TypedStringObjectMethodCaller<T, std::vector<double >>, StringObjectFunction<T>, double > DoubleVectorVar;
695- typedef FuncCollectionVariable<T, TypedStringObjectMethodCaller<T, std::vector<uint8_t >>, StringObjectFunction<T>, uint8_t > UInt8VectorVar;
696- typedef FuncCollectionVariable<T, TypedStringObjectMethodCaller<T, std::vector<int16_t >>, StringObjectFunction<T>, int16_t > Int16VectorVar;
697- typedef FuncCollectionVariable<T, TypedStringObjectMethodCaller<T, std::vector<uint16_t >>, StringObjectFunction<T>, uint16_t > UInt16VectorVar;
697+ template <typename R>
698+ using VectorVar =
699+ FuncCollectionVariable<T, TypedStringObjectMethodCaller<T, std::vector<R>>, StringObjectFunction<T>, R>;
700+
701+ using IntVectorVar = VectorVar<int32_t >;
702+ using UIntVectorVar = VectorVar<uint32_t >;
703+ using FloatVectorVar = VectorVar<float >;
704+ using DoubleVectorVar = VectorVar<double >;
705+ using UInt8VectorVar = VectorVar<uint8_t >;
706+ using Int16VectorVar = VectorVar<int16_t >;
707+ using UInt16VectorVar = VectorVar<uint16_t >;
698708
699709 struct CollectionVariableTableInfo {
700710 std::string name;
0 commit comments