1 #ifndef FWCore_Framework_InputProcessBlockCacheImpl_h 2 #define FWCore_Framework_InputProcessBlockCacheImpl_h 26 #include <type_traits> 41 template <
typename M,
typename V1,
typename... Vs>
44 : countTypeInParameterPack<M, Vs...>();
57 static_assert(
sizeof...(
Types) > 0,
58 "CacheType used with registerProcessBlockCacheFiller does not match any template parameters of " 59 "InputProcessBlockCache");
70 template <
typename CacheType>
73 std::function<std::shared_ptr<CacheType>(
ProcessBlock const&, std::shared_ptr<CacheType>
const&)>
func_;
76 template <
typename... CacheTypes>
83 template <std::
size_t I>
87 template <std::
size_t I>
98 std::get<I>(cacheHandles) =
CacheHandle(std::get<I>(caches_.at(
index).cacheTuple_).
get());
100 fillTuple<I + 1>(cacheHandles,
event);
104 std::tuple<CacheHandle<CacheTypes>...> cacheHandles;
107 if (!processNames_.empty()) {
108 fillTuple<0>(cacheHandles,
event);
117 for (
auto const& tokenInfo : tokenInfos_) {
118 if (!tokenInfo.token_.isUninitialized()) {
129 template <std::
size_t N>
132 template <std::
size_t ICacheType,
typename DataType,
typename Func>
134 registerProcessBlockCacheFiller<ICacheType, CacheTypeT<ICacheType>,
DataType, Func>(
token,
135 std::forward<Func>(
func));
138 template <
typename CacheType,
typename DataType,
typename Func>
140 static_assert(countTypeInParameterPack<CacheType, CacheTypes...>() == 1u,
141 "If registerProcessBlockCacheFiller is called with a type template parameter\n" 142 "then that type must appear exactly once in the template parameters of InputProcessBlockCache");
147 registerProcessBlockCacheFiller<I, CacheType, DataType, Func>(
token, std::forward<Func>(
func));
158 if (!tokenInfos_.empty()) {
159 processNames_.resize(
sizeof...(CacheTypes));
171 template <std::
size_t I>
176 template <std::
size_t I>
178 CacheTuple
const& previousCacheTuple,
179 CacheTuple& cacheTuple) {
181 auto const& previousSharedPtr = std::get<I>(previousCacheTuple.cacheTuple_);
182 std::get<I>(cacheTuple.cacheTuple_) = std::get<I>(functors_).func_(pb, previousSharedPtr);
184 fillCache<I + 1>(pb, previousCacheTuple, cacheTuple);
187 void accessInputProcessBlock(ProcessBlock
const& pb) {
188 if (
sizeof...(CacheTypes) > 0 && !processNames_.empty()) {
189 CacheTuple cacheTuple;
190 if (caches_.empty()) {
191 CacheTuple firstCacheTuple;
192 fillCache<0>(pb, firstCacheTuple, cacheTuple);
194 CacheTuple
const& previousCacheTuple = caches_.back();
195 fillCache<0>(pb, previousCacheTuple, cacheTuple);
197 caches_.push_back(
std::move(cacheTuple));
201 void clearCaches() { caches_.clear(); }
202 auto cacheSize()
const {
return caches_.size(); }
205 template <std::
size_t ICacheType,
typename CacheType,
typename DataType,
typename Func>
207 static_assert(ICacheType <
sizeof...(CacheTypes),
"ICacheType out of range");
208 processNames_.resize(
sizeof...(CacheTypes));
209 tokenInfos_.resize(
sizeof...(CacheTypes));
210 if (!tokenInfos_[ICacheType].token_.isUninitialized()) {
212 <<
"registerProcessBlockCacheFiller should only be called once per cache type";
217 std::get<ICacheType>(functors_).func_ = std::forward<Func>(
func);
223 std::vector<CacheTuple> caches_;
226 std::tuple<CacheFiller<CacheTypes>...> functors_;
227 std::vector<std::string> processNames_;
228 std::vector<TokenInfo> tokenInfos_;
std::string const & processName() const
std::function< std::shared_ptr< CacheType >ProcessBlock const &, std::shared_ptr< CacheType > const &)> func_
constexpr std::size_t indexInputProcessBlockCache()
static constexpr unsigned int invalidCacheIndex()
const std::complex< double > I
unsigned int eventProcessBlockIndex(Event const &event, std::string const &processName)
std::string selectProcess(ProductRegistry const &, ProductLabels const &, TypeID const &) const
constexpr std::size_t countTypeInParameterPack()
void labelsForToken(EDGetToken iToken, Labels &oLabels) const