CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ObjectCounter.h
Go to the documentation of this file.
1 #ifndef UtilAlgos_ObjectCounter_h
2 #define UtilAlgos_ObjectCounter_h
3 
21 #include "FWCore/Framework/interface/TypeID.h"
22 #include <iostream>
23 #include <cmath>
24 
25 template<typename C>
27 public:
29  explicit ObjectCounter( const edm::ParameterSet& );
31  void endJob();
32 
33 private:
35  virtual void analyze( const edm::Event&, const edm::EventSetup&) override;
39  bool verbose_;
41  unsigned long n_, nSum_, n2Sum_;
42 };
43 
44 template<typename C>
46  srcToken_( consumes<C>( edm::InputTag( par.template getParameter<std::string>( "src" ) ) ) ),
47  verbose_( par.template getUntrackedParameter<bool>( "verbose", true ) ),
48  n_( 0 ), nSum_( 0 ), n2Sum_( 0 ) {
49 }
50 
51 template<typename C>
53  double n = 0, n2 = 0, s;
54  if ( n_!= 0 ) {
55  n = double( nSum_ ) / n_;
56  n2 = double ( n2Sum_ ) / n_;
57  }
58  s = sqrt( n2 - n * n );
59  if ( verbose_ ) {
60  edm::TypeID id( typeid( typename C::value_type ) );
61  std::cout << ">>> collection \"" << srcToken_ << "\" contains ("
62  << n << " +/- " << s << ") "
63  << id.friendlyClassName() << " objects" << std::endl;
64  }
65 }
66 
67 template<typename C>
70  evt.getByToken( srcToken_, h );
71  if (!h.isValid()) {
72  std::cerr << ">>> product: " << srcToken_ << " not found" << std::endl;
73  } else {
74  int n = h->size();
75  nSum_ += n;
76  n2Sum_ += ( n * n );
77  }
78  ++ n_;
79 }
80 
81 #endif
82 
ObjectCounter(const edm::ParameterSet &)
constructor from parameter set
Definition: ObjectCounter.h:45
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
unsigned long n_
partial statistics
Definition: ObjectCounter.h:41
bool verbose_
verbosity flag
Definition: ObjectCounter.h:39
edm::EDGetTokenT< C > srcToken_
label of source collection
Definition: ObjectCounter.h:37
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
event processing
Definition: ObjectCounter.h:68
unsigned long nSum_
Definition: ObjectCounter.h:41
T sqrt(T t)
Definition: SSEVec.h:48
void endJob()
end-of-job processing
Definition: ObjectCounter.h:52
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
bool isValid() const
Definition: HandleBase.h:75
Container::value_type value_type
tuple cout
Definition: gather_cfg.py:121
unsigned long n2Sum_
Definition: ObjectCounter.h:41
def template
Definition: svgfig.py:520