Go to the documentation of this file.00001 #ifndef FWCore_Sources_VectorInputSource_h
00002 #define FWCore_Sources_VectorInputSource_h
00003
00004
00005
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(EventPrincipal& cache, size_t number, T eventOperator);
00026 template<typename T>
00027 size_t loopSequential(EventPrincipal& cache, size_t number, T eventOperator);
00028 template<typename T>
00029 size_t loopRandomWithID(EventPrincipal& cache, LuminosityBlockID const& id, size_t number, T eventOperator);
00030 template<typename T>
00031 size_t loopSequentialWithID(EventPrincipal& cache, LuminosityBlockID const& id, size_t number, T eventOperator);
00032 template<typename T, typename Collection>
00033 size_t loopSpecified(EventPrincipal& cache, Collection const& events, T eventOperator);
00034
00035 void dropUnwantedBranches(std::vector<std::string> const& wantedBranches);
00036
00037 private:
00038
00039 void clearEventPrincipal(EventPrincipal& cache);
00040 virtual EventPrincipal* readOneRandom(EventPrincipal& cache) = 0;
00041 virtual EventPrincipal* readOneRandomWithID(EventPrincipal& cache, LuminosityBlockID const& id) = 0;
00042 virtual EventPrincipal* readOneSequential(EventPrincipal& cache) = 0;
00043 virtual EventPrincipal* readOneSequentialWithID(EventPrincipal& cache, LuminosityBlockID const& id) = 0;
00044 virtual EventPrincipal* readOneSpecified(EventPrincipal& cache, EventID const& event) = 0;
00045
00046 virtual void dropUnwantedBranches_(std::vector<std::string> const& wantedBranches) = 0;
00047 };
00048
00049 template<typename T>
00050 size_t VectorInputSource::loopRandom(EventPrincipal& cache, size_t number, T eventOperator) {
00051 size_t i = 0U;
00052 for(; i < number; ++i) {
00053 clearEventPrincipal(cache);
00054 EventPrincipal* ep = readOneRandom(cache);
00055 if(!ep) break;
00056 eventOperator(*ep);
00057 }
00058 return i;
00059 }
00060
00061 template<typename T>
00062 size_t VectorInputSource::loopSequential(EventPrincipal& cache, size_t number, T eventOperator) {
00063 size_t i = 0U;
00064 for(; i < number; ++i) {
00065 clearEventPrincipal(cache);
00066 EventPrincipal* ep = readOneSequential(cache);
00067 if(!ep) break;
00068 eventOperator(*ep);
00069 }
00070 return i;
00071 }
00072
00073 template<typename T>
00074 size_t VectorInputSource::loopRandomWithID(EventPrincipal& cache, LuminosityBlockID const& id, size_t number, T eventOperator) {
00075 size_t i = 0U;
00076 for(; i < number; ++i) {
00077 clearEventPrincipal(cache);
00078 EventPrincipal* ep = readOneRandomWithID(cache, id);
00079 if(!ep) break;
00080 eventOperator(*ep);
00081 }
00082 return i;
00083 }
00084
00085 template<typename T>
00086 size_t VectorInputSource::loopSequentialWithID(EventPrincipal& cache, LuminosityBlockID const& id, size_t number, T eventOperator) {
00087 size_t i = 0U;
00088 for(; i < number; ++i) {
00089 clearEventPrincipal(cache);
00090 EventPrincipal* ep = readOneSequentialWithID(cache, id);
00091 if(!ep) break;
00092 eventOperator(*ep);
00093 }
00094 return i;
00095 }
00096
00097 template<typename T, typename Collection>
00098 size_t VectorInputSource::loopSpecified(EventPrincipal& cache, Collection const& events, T eventOperator) {
00099 size_t i = 0U;
00100 for(typename Collection::const_iterator it = events.begin(), itEnd = events.end(); it != itEnd; ++it) {
00101 clearEventPrincipal(cache);
00102 EventPrincipal* ep = readOneSpecified(cache, *it);
00103 if(!ep) break;
00104 eventOperator(*ep);
00105 ++i;
00106 }
00107 return i;
00108 }
00109 }
00110 #endif