00001 #ifndef FWCore_Framework_Principal_h
00002 #define FWCore_Framework_Principal_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <map>
00021 #include <memory>
00022 #include <set>
00023 #include <string>
00024 #include <vector>
00025
00026 #include "boost/iterator/filter_iterator.hpp"
00027 #include "boost/shared_ptr.hpp"
00028 #include "FWCore/Framework/interface/Frameworkfwd.h"
00029 #include "DataFormats/Provenance/interface/ProvenanceFwd.h"
00030 #include "DataFormats/Provenance/interface/ProductTransientIndex.h"
00031 #include "DataFormats/Common/interface/EDProductGetter.h"
00032 #include "DataFormats/Common/interface/BasicHandle.h"
00033 #include "DataFormats/Common/interface/OutputHandle.h"
00034 #include "DataFormats/Common/interface/Wrapper.h"
00035 #include "DataFormats/Provenance/interface/ProcessHistory.h"
00036 #include "FWCore/Framework/interface/Group.h"
00037 #include "FWCore/Utilities/interface/InputTag.h"
00038 #include "DataFormats/Provenance/interface/TransientProductLookupMap.h"
00039
00040 namespace edm {
00041 struct FilledGroupPtr {
00042 bool operator()(boost::shared_ptr<Group> const& iObj) { return bool(iObj);}
00043 };
00044
00045 class Principal : public EDProductGetter {
00046 public:
00047 typedef std::vector<boost::shared_ptr<Group> > GroupCollection;
00048 typedef boost::filter_iterator<FilledGroupPtr, GroupCollection::const_iterator> const_iterator;
00049 typedef ProcessHistory::const_iterator ProcessNameConstIterator;
00050 typedef boost::shared_ptr<Group const> SharedConstGroupPtr;
00051 typedef std::vector<BasicHandle> BasicHandleVec;
00052 typedef GroupCollection::size_type size_type;
00053
00054 typedef boost::shared_ptr<Group> SharedGroupPtr;
00055 typedef std::string ProcessName;
00056
00057 Principal(boost::shared_ptr<ProductRegistry const> reg,
00058 ProcessConfiguration const& pc,
00059 BranchType bt);
00060
00061 virtual ~Principal();
00062
00063 bool adjustToNewProductRegistry(ProductRegistry const& reg);
00064
00065 void adjustIndexesAfterProductRegistryAddition();
00066
00067 void addGroupScheduled(boost::shared_ptr<ConstBranchDescription> bd);
00068
00069 void addGroupSource(boost::shared_ptr<ConstBranchDescription> bd);
00070
00071 void addGroupInput(boost::shared_ptr<ConstBranchDescription> bd);
00072
00073 void addOnDemandGroup(boost::shared_ptr<ConstBranchDescription> bd);
00074
00075 void fillPrincipal(ProcessHistoryID const& hist, boost::shared_ptr<BranchMapper> mapper, boost::shared_ptr<DelayedReader> rtrv);
00076
00077 void clearPrincipal();
00078
00079 EDProductGetter const* prodGetter() const {return this;}
00080
00081 OutputHandle getForOutput(BranchID const& bid, bool getProd) const;
00082
00083 BasicHandle getBySelector(TypeID const& tid,
00084 SelectorBase const& s) const;
00085
00086 BasicHandle getByLabel(TypeID const& tid,
00087 std::string const& label,
00088 std::string const& productInstanceName,
00089 std::string const& processName,
00090 size_t& cachedOffset,
00091 int& fillCount) const;
00092
00093 void getMany(TypeID const& tid,
00094 SelectorBase const&,
00095 BasicHandleVec& results) const;
00096
00097 BasicHandle getByType(TypeID const& tid) const;
00098
00099 void getManyByType(TypeID const& tid,
00100 BasicHandleVec& results) const;
00101
00102
00103
00104
00105
00106
00107
00108 size_t getMatchingSequence(TypeID const& typeID,
00109 SelectorBase const& selector,
00110 BasicHandle& result) const;
00111
00112 ProcessHistory const& processHistory() const {
00113 return *processHistoryPtr_;
00114 }
00115
00116 ProcessHistoryID const& processHistoryID() const {
00117 return processHistoryID_;
00118 }
00119
00120 ProcessConfiguration const& processConfiguration() const {return *processConfiguration_;}
00121
00122 ProductRegistry const& productRegistry() const {return *preg_;}
00123
00124
00125 void recombine(Principal& other, std::vector<BranchID> const& bids);
00126
00127 size_t size() const;
00128
00129
00130 const_iterator begin() const {return boost::make_filter_iterator<FilledGroupPtr>(groups_.begin(), groups_.end());}
00131 const_iterator end() const {return boost::make_filter_iterator<FilledGroupPtr>(groups_.end(), groups_.end());}
00132
00133 Provenance getProvenance(BranchID const& bid) const;
00134
00135 void getAllProvenance(std::vector<Provenance const*>& provenances) const;
00136
00137 BranchType const& branchType() const {return branchType_;}
00138
00139 boost::shared_ptr<BranchMapper> branchMapperPtr() const {return branchMapperPtr_;}
00140
00141 boost::shared_ptr<DelayedReader> store() const {return store_;}
00142
00143 void maybeFlushCache(TypeID const& tid, InputTag const& tag) const;
00144
00145 SharedConstGroupPtr const getGroup(BranchID const& oid,
00146 bool resolveProd,
00147 bool fillOnDemand) const;
00148 protected:
00149 ProcessHistory& processHistoryUpdate() {
00150 return *processHistoryPtr_;
00151 }
00152
00153
00154
00155
00156 void addGroup_(std::auto_ptr<Group> g);
00157 void addGroupOrThrow(std::auto_ptr<Group> g);
00158 Group* getExistingGroup(BranchID const& branchID);
00159 Group* getExistingGroup(Group const& g);
00160
00161 SharedConstGroupPtr const getGroupByIndex(ProductTransientIndex const& oid,
00162 bool resolveProd,
00163 bool fillOnDemand) const;
00164
00165
00166
00167
00168
00169
00170 void resolveProduct(Group const& g, bool fillOnDemand) const {resolveProduct_(g, fillOnDemand);}
00171
00172 void swapBase(Principal&);
00173
00174
00175 void checkUniquenessAndType(std::auto_ptr<EDProduct>& prod, Group const* group) const;
00176
00177 void putOrMerge(std::auto_ptr<EDProduct> prod, Group const* group) const;
00178
00179 void putOrMerge(std::auto_ptr<EDProduct> prod, std::auto_ptr<ProductProvenance> prov, Group* group);
00180
00181 void setProcessHistory(Principal const& principal);
00182
00183 private:
00184 virtual EDProduct const* getIt(ProductID const&) const;
00185
00186 virtual bool unscheduledFill(std::string const& moduleLabel) const = 0;
00187
00188
00189 typedef TransientProductLookupMap TypeLookup;
00190
00191 size_t findGroup(TypeID const& typeID,
00192 TypeLookup const& typeLookup,
00193 SelectorBase const& selector,
00194 BasicHandle& result) const;
00195
00196 bool findGroupByLabel(TypeID const& typeID,
00197 TypeLookup const& typeLookup,
00198 std::string const& moduleLabel,
00199 std::string const& productInstanceName,
00200 std::string const& processName,
00201 size_t& cachedOffset,
00202 int& fillCount,
00203 BasicHandle& result) const;
00204
00205 size_t findGroups(TypeID const& typeID,
00206 TypeLookup const& typeLookup,
00207 SelectorBase const& selector,
00208 BasicHandleVec& results) const;
00209
00210
00211 virtual void resolveProduct_(Group const& g, bool fillOnDemand) const {}
00212
00213 boost::shared_ptr<ProcessHistory> processHistoryPtr_;
00214
00215 ProcessHistoryID processHistoryID_;
00216
00217 ProcessConfiguration const* processConfiguration_;
00218
00219
00220 GroupCollection groups_;
00221
00222
00223
00224 boost::shared_ptr<ProductRegistry const> preg_;
00225
00226
00227
00228 boost::shared_ptr<BranchMapper> branchMapperPtr_;
00229
00230
00231
00232 boost::shared_ptr<DelayedReader> store_;
00233
00234
00235 mutable std::set<EDProduct *> productPtrs_;
00236
00237 BranchType branchType_;
00238 };
00239
00240 template <typename PROD>
00241 inline
00242 boost::shared_ptr<Wrapper<PROD> const>
00243 getProductByTag(Principal const& ep, InputTag const& tag) {
00244 TypeID tid = TypeID(typeid(PROD));
00245 ep.maybeFlushCache(tid, tag);
00246 return boost::dynamic_pointer_cast<Wrapper<PROD> const>(ep.getByLabel(tid, tag.label(), tag.instance(), tag.process(), tag.cachedOffset(), tag.fillCount()).product());
00247 }
00248 }
00249 #endif