CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/FWCore/Sources/interface/VectorInputSource.h

Go to the documentation of this file.
00001 #ifndef FWCore_Sources_VectorInputSource_h
00002 #define FWCore_Sources_VectorInputSource_h
00003 
00004 /*----------------------------------------------------------------------
00005 VectorInputSource: Abstract interface for vector input sources.
00006 ----------------------------------------------------------------------*/
00007 
00008 #include "FWCore/Sources/interface/EDInputSource.h"
00009 
00010 #include "boost/shared_ptr.hpp"
00011 
00012 #include <memory>
00013 #include <string>
00014 #include <vector>
00015 
00016 namespace edm {
00017   class EventPrincipal;
00018   struct InputSourceDescription;
00019   class ParameterSet;
00020   class VectorInputSource : public EDInputSource {
00021   public:
00022     explicit VectorInputSource(ParameterSet const& pset, InputSourceDescription const& desc);
00023     virtual ~VectorInputSource();
00024 
00025     template<typename T>
00026     size_t loopRandom(size_t number, T eventOperator);
00027     template<typename T>
00028     size_t loopSequential(size_t number, T eventOperator);
00029     template<typename T, typename Collection>
00030     size_t loopSpecified(Collection const& events, T eventOperator);
00031 
00032     void dropUnwantedBranches(std::vector<std::string> const& wantedBranches);
00033 
00034   private:
00035 
00036     virtual EventPrincipal* readOneRandom() = 0;
00037     virtual EventPrincipal* readOneSequential() = 0;
00038     virtual EventPrincipal* readOneSpecified(EventID const& event) = 0;
00039 
00040     virtual void dropUnwantedBranches_(std::vector<std::string> const& wantedBranches) = 0;
00041   };
00042 
00043   template<typename T>
00044   size_t VectorInputSource::loopRandom(size_t number, T eventOperator) {
00045     size_t i = 0U;
00046     for(; i < number; ++i) {
00047       EventPrincipal* ep = readOneRandom();
00048       if(!ep) break;
00049       eventOperator(*ep);
00050     }
00051     return i;
00052   }
00053 
00054   template<typename T>
00055   size_t VectorInputSource::loopSequential(size_t number, T eventOperator) {
00056     size_t i = 0U;
00057     for(; i < number; ++i) {
00058       EventPrincipal* ep = readOneSequential();
00059       if(!ep) break;
00060       eventOperator(*ep);
00061     }
00062     return i;
00063   }
00064 
00065   template<typename T, typename Collection>
00066   size_t VectorInputSource::loopSpecified(Collection const& events, T eventOperator) {
00067     size_t i = 0U;
00068     for(typename Collection::const_iterator it = events.begin(), itEnd = events.end(); it != itEnd; ++it) {
00069       EventPrincipal* ep = readOneSpecified(*it);
00070       if(!ep) break;
00071       eventOperator(*ep);
00072       ++i;
00073     }
00074     return i;
00075   }
00076 }
00077 #endif