CMS 3D CMS Logo

ObjectCounter< C > Class Template Reference

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

#include <PhysicsTools/UtilAlgos/interface/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.9

Id
ObjectCounter.h,v 1.9 2007/12/31 18:43:14 ratnik Exp

Definition at line 26 of file ObjectCounter.h.


Constructor & Destructor Documentation

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

constructor from parameter set

Definition at line 45 of file ObjectCounter.h.

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


Member Function Documentation

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

event processing

Implements edm::EDAnalyzer.

Definition at line 68 of file ObjectCounter.h.

References TestMuL1L2Filter_cff::cerr, lat::endl(), edm::Event::getByLabel(), h, edm::Handle< T >::isValid(), n, ObjectCounter< C >::n2Sum_, ObjectCounter< C >::n_, ObjectCounter< C >::nSum_, and ObjectCounter< C >::src_.

00068                                                                           {
00069   edm::Handle<C> h;
00070   evt.getByLabel( src_, h );
00071   if (!h.isValid()) {
00072     std::cerr << ">>> product: " << src_ << " not found" << std::endl;
00073   } else {
00074     int n = h->size();
00075     nSum_ += n;
00076     n2Sum_ += ( n * n );
00077   }
00078   ++ n_;
00079 }

template<typename C>
void ObjectCounter< C >::endJob ( void   )  [inline, virtual]

end-of-job processing

Reimplemented from edm::EDAnalyzer.

Definition at line 52 of file ObjectCounter.h.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), id, n, ObjectCounter< C >::n2Sum_, ObjectCounter< C >::n_, ObjectCounter< C >::nSum_, s, funct::sqrt(), ObjectCounter< C >::src_, and ObjectCounter< C >::verbose_.

00052                               {
00053   double n = 0, n2 = 0, s;
00054   if ( n_!= 0 ) {
00055     n = double( nSum_ ) / n_;
00056     n2 = double ( n2Sum_ ) / n_;
00057   }
00058   s = sqrt( n2 - n * n );
00059   if ( verbose_ ) {
00060     edm::TypeID id( typeid( typename C::value_type ) );
00061     std::cout << ">>> collection \"" << src_ << "\" contains (" 
00062               << n << " +/- " << s << ") "  
00063               << id.friendlyClassName() << " objects" << std::endl;
00064   }
00065 }


Member Data Documentation

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

Definition at line 41 of file ObjectCounter.h.

Referenced by ObjectCounter< C >::analyze(), and ObjectCounter< C >::endJob().

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

partial statistics

Definition at line 41 of file ObjectCounter.h.

Referenced by ObjectCounter< C >::analyze(), and ObjectCounter< C >::endJob().

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

Definition at line 41 of file ObjectCounter.h.

Referenced by ObjectCounter< C >::analyze(), and ObjectCounter< C >::endJob().

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

label of source collection

Definition at line 37 of file ObjectCounter.h.

Referenced by ObjectCounter< C >::analyze(), and ObjectCounter< C >::endJob().

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

verbosity flag

Definition at line 39 of file ObjectCounter.h.

Referenced by ObjectCounter< C >::endJob().


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:29:08 2009 for CMSSW by  doxygen 1.5.4