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& );
37  std::string src_;
39  bool verbose_;
41  unsigned long n_, nSum_, n2Sum_;
42 };
43 
44 template<typename C>
46  src_( 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 \"" << src_ << "\" contains ("
62  << n << " +/- " << s << ") "
63  << id.friendlyClassName() << " objects" << std::endl;
64  }
65 }
66 
67 template<typename C>
70  evt.getByLabel( src_, h );
71  if (!h.isValid()) {
72  std::cerr << ">>> product: " << src_ << " 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
ObjectCounter(const edm::ParameterSet &)
constructor from parameter set
Definition: ObjectCounter.h:45
unsigned long n_
partial statistics
Definition: ObjectCounter.h:41
bool verbose_
verbosity flag
Definition: ObjectCounter.h:39
virtual void analyze(const edm::Event &, const edm::EventSetup &)
event processing
Definition: ObjectCounter.h:68
unsigned long nSum_
Definition: ObjectCounter.h:41
T sqrt(T t)
Definition: SSEVec.h:28
void endJob()
end-of-job processing
Definition: ObjectCounter.h:52
bool isValid() const
Definition: HandleBase.h:76
Container::value_type value_type
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
std::string src_
label of source collection
Definition: ObjectCounter.h:37
tuple cout
Definition: gather_cfg.py:41
unsigned long n2Sum_
Definition: ObjectCounter.h:41
string s
Definition: asciidump.py:422
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
def template
Definition: svgfig.py:520
const double par[8 *NPar][4]