CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

ObjectCounter< C > Class Template Reference

#include <ObjectCounter.h>

Inheritance diagram for ObjectCounter< C >:
edm::EDAnalyzer

List of all members.

Public Member Functions

void endJob ()
 end-of-job processing
 ObjectCounter (const edm::ParameterSet &)
 constructor from parameter set

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 event processing

Private Attributes

unsigned long n2Sum_
unsigned long n_
 partial statistics
unsigned long nSum_
std::string src_
 label of source collection
bool verbose_
 verbosity flag

Detailed Description

template<typename C>
class ObjectCounter< C >

Counts the number of objects in a collection and prints a summary report at the end of a job.

Template parameters:

Author:
Luca Lista, INFN
Version:
Revision:
1.1
Id:
ObjectCounter.h,v 1.1 2009/03/03 13:07:27 llista Exp

Definition at line 26 of file ObjectCounter.h.


Constructor & Destructor Documentation

template<typename C >
ObjectCounter< C >::ObjectCounter ( const edm::ParameterSet par) [explicit]

constructor from parameter set

Definition at line 45 of file ObjectCounter.h.

                                                            : 
  src_( par.template getParameter<std::string>( "src" ) ), 
  verbose_( par.template getUntrackedParameter<bool>( "verbose", true ) ),
  n_( 0 ), nSum_( 0 ), n2Sum_( 0 ) {
}

Member Function Documentation

template<typename C >
void ObjectCounter< C >::analyze ( const edm::Event evt,
const edm::EventSetup  
) [private, virtual]

event processing

Implements edm::EDAnalyzer.

Definition at line 68 of file ObjectCounter.h.

References dtNoiseDBValidation_cfg::cerr, edm::Event::getByLabel(), h, edm::HandleBase::isValid(), and n.

                                                                          {
  edm::Handle<C> h;
  evt.getByLabel( src_, h );
  if (!h.isValid()) {
    std::cerr << ">>> product: " << src_ << " not found" << std::endl;
  } else {
    int n = h->size();
    nSum_ += n;
    n2Sum_ += ( n * n );
  }
  ++ n_;
}
template<typename C >
void ObjectCounter< C >::endJob ( void  ) [virtual]

end-of-job processing

Reimplemented from edm::EDAnalyzer.

Definition at line 52 of file ObjectCounter.h.

References gather_cfg::cout, errorMatrix2Lands_multiChannel::id, n, alignCSCRings::s, and mathSSE::sqrt().

                              {
  double n = 0, n2 = 0, s;
  if ( n_!= 0 ) {
    n = double( nSum_ ) / n_;
    n2 = double ( n2Sum_ ) / n_;
  }
  s = sqrt( n2 - n * n );
  if ( verbose_ ) {
    edm::TypeID id( typeid( typename C::value_type ) );
    std::cout << ">>> collection \"" << src_ << "\" contains (" 
              << n << " +/- " << s << ") "  
              << id.friendlyClassName() << " objects" << std::endl;
  }
}

Member Data Documentation

template<typename C >
unsigned long ObjectCounter< C >::n2Sum_ [private]

Definition at line 41 of file ObjectCounter.h.

template<typename C >
unsigned long ObjectCounter< C >::n_ [private]

partial statistics

Definition at line 41 of file ObjectCounter.h.

template<typename C >
unsigned long ObjectCounter< C >::nSum_ [private]

Definition at line 41 of file ObjectCounter.h.

template<typename C >
std::string ObjectCounter< C >::src_ [private]

label of source collection

Definition at line 37 of file ObjectCounter.h.

template<typename C >
bool ObjectCounter< C >::verbose_ [private]

verbosity flag

Definition at line 39 of file ObjectCounter.h.