CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/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 <memory>
00011 #include <string>
00012 #include <vector>
00013 
00014 namespace edm {
00015   class EventPrincipal;
00016   struct InputSourceDescription;
00017   class LuminosityBlockID;
00018   class ParameterSet;
00019   class VectorInputSource : public EDInputSource {
00020   public:
00021     explicit VectorInputSource(ParameterSet const& pset, InputSourceDescription const& desc);
00022     virtual ~VectorInputSource();
00023 
00024     template<typename T>
00025     size_t loopRandom(size_t number, T eventOperator);
00026     template<typename T>
00027     size_t loopSequential(size_t number, T eventOperator);
00028     template<typename T>
00029     size_t loopRandomWithID(LuminosityBlockID const& id, size_t number, T eventOperator);
00030     template<typename T>
00031     size_t loopSequentialWithID(LuminosityBlockID const& id, size_t number, T eventOperator);
00032     template<typename T, typename Collection>
00033     size_t loopSpecified(Collection const& events, T eventOperator);
00034 
00035     void dropUnwantedBranches(std::vector<std::string> const& wantedBranches);
00036 
00037   private:
00038 
00039     virtual EventPrincipal* readOneRandom() = 0;
00040     virtual EventPrincipal* readOneRandomWithID(LuminosityBlockID const& id) = 0;
00041     virtual EventPrincipal* readOneSequential() = 0;
00042     virtual EventPrincipal* readOneSequentialWithID(LuminosityBlockID const& id) = 0;
00043     virtual EventPrincipal* readOneSpecified(EventID const& event) = 0;
00044 
00045     virtual void dropUnwantedBranches_(std::vector<std::string> const& wantedBranches) = 0;
00046   };
00047 
00048   template<typename T>
00049   size_t VectorInputSource::loopRandom(size_t number, T eventOperator) {
00050     size_t i = 0U;
00051     for(; i < number; ++i) {
00052       EventPrincipal* ep = readOneRandom();
00053       if(!ep) break;
00054       eventOperator(*ep);
00055     }
00056     return i;
00057   }
00058 
00059   template<typename T>
00060   size_t VectorInputSource::loopSequential(size_t number, T eventOperator) {
00061     size_t i = 0U;
00062     for(; i < number; ++i) {
00063       EventPrincipal* ep = readOneSequential();
00064       if(!ep) break;
00065       eventOperator(*ep);
00066     }
00067     return i;
00068   }
00069 
00070   template<typename T>
00071   size_t VectorInputSource::loopRandomWithID(LuminosityBlockID const& id, size_t number, T eventOperator) {
00072     size_t i = 0U;
00073     for(; i < number; ++i) {
00074       EventPrincipal* ep = readOneRandomWithID(id);
00075       if(!ep) break;
00076       eventOperator(*ep);
00077     }
00078     return i;
00079   }
00080 
00081   template<typename T>
00082   size_t VectorInputSource::loopSequentialWithID(LuminosityBlockID const& id, size_t number, T eventOperator) {
00083     size_t i = 0U;
00084     for(; i < number; ++i) {
00085       EventPrincipal* ep = readOneSequentialWithID(id);
00086       if(!ep) break;
00087       eventOperator(*ep);
00088     }
00089     return i;
00090   }
00091 
00092   template<typename T, typename Collection>
00093   size_t VectorInputSource::loopSpecified(Collection const& events, T eventOperator) {
00094     size_t i = 0U;
00095     for(typename Collection::const_iterator it = events.begin(), itEnd = events.end(); it != itEnd; ++it) {
00096       EventPrincipal* ep = readOneSpecified(*it);
00097       if(!ep) break;
00098       eventOperator(*ep);
00099       ++i;
00100     }
00101     return i;
00102   }
00103 }
00104 #endif