Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:59

0001 #ifndef FWCore_Framework_stream_callAbilities_h
0002 #define FWCore_Framework_stream_callAbilities_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Framework
0006 // Class  :     callAbilities
0007 //
0008 /**\class callAbilities callAbilities.h "FWCore/Framework/interface/stream/callAbilities.h"
0009 
0010  Description: [one line class summary]
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Sat, 03 Aug 2013 16:28:35 GMT
0019 //
0020 
0021 // system include files
0022 #include <memory>
0023 #include <type_traits>
0024 
0025 // user include files
0026 #include "DataFormats/Provenance/interface/ProvenanceFwd.h"
0027 #include "FWCore/Common/interface/FWCoreCommonFwd.h"
0028 #include "FWCore/Framework/interface/stream/dummy_helpers.h"
0029 
0030 // forward declarations
0031 namespace edm {
0032   class EDConsumerBase;
0033   class Run;
0034   class EventSetup;
0035   class LuminosityBlock;
0036   class ProcessBlock;
0037   namespace stream {
0038     //********************************
0039     // CallGlobal
0040     //********************************
0041     namespace callGlobalDetail {
0042       template <typename, typename = std::void_t<>>
0043       struct has_globalBeginJob : std::false_type {};
0044 
0045       template <typename T>
0046       struct has_globalBeginJob<T, std::void_t<decltype(T::globalBeginJob(nullptr))>> : std::true_type {};
0047     }  // namespace callGlobalDetail
0048     template <typename T, bool>
0049     struct CallGlobalImpl {
0050       template <typename B>
0051       static void set(B* iProd, typename T::GlobalCache const* iCache) {
0052         static_cast<T*>(iProd)->setGlobalCache(iCache);
0053       }
0054       static void beginJob(typename T::GlobalCache* iCache) {
0055         if constexpr (callGlobalDetail::has_globalBeginJob<T>::value) {
0056           T::globalBeginJob(iCache);
0057         }
0058       }
0059       static void endJob(typename T::GlobalCache* iCache) { T::globalEndJob(iCache); }
0060     };
0061     template <typename T>
0062     struct CallGlobalImpl<T, false> {
0063       static void set(void* iProd, void const* iCache) {}
0064       static void beginJob(void* iCache) {}
0065       static void endJob(void* iCache) {}
0066     };
0067 
0068     template <typename T>
0069     using CallGlobal = CallGlobalImpl<T, T::HasAbility::kGlobalCache>;
0070 
0071     //********************************
0072     // CallInputProcessBlock
0073     //********************************
0074     template <typename T, bool, bool>
0075     struct CallInputProcessBlockImpl {
0076       static void set(T* iProd,
0077                       typename impl::choose_unique_ptr<typename T::InputProcessBlockCache>::type const* iCaches,
0078                       unsigned int iStreamModule) {
0079         iProd->setProcessBlockCache(iCaches->get());
0080         if (iStreamModule == 0 && iProd->cacheFillersRegistered()) {
0081           (*iCaches)->moveProcessBlockCacheFiller(iProd->tokenInfos(), iProd->cacheFillers());
0082         }
0083         iProd->clearRegistration();
0084       }
0085 
0086       static void selectInputProcessBlocks(
0087           typename impl::choose_unique_ptr<typename T::InputProcessBlockCache>::type& iCaches,
0088           ProductRegistry const& productRegistry,
0089           ProcessBlockHelperBase const& processBlockHelperBase,
0090           EDConsumerBase const& edConsumerBase) {
0091         iCaches->selectInputProcessBlocks(productRegistry, processBlockHelperBase, edConsumerBase);
0092       }
0093 
0094       static void accessInputProcessBlock(
0095           edm::ProcessBlock const& processBlock,
0096           typename T::GlobalCache* iGC,
0097           typename impl::choose_unique_ptr<typename T::InputProcessBlockCache>::type& iCaches) {
0098         iCaches->accessInputProcessBlock(processBlock);
0099         T::accessInputProcessBlock(processBlock, iGC);
0100       }
0101 
0102       static void clearCaches(typename impl::choose_unique_ptr<typename T::InputProcessBlockCache>::type& iCaches) {
0103         iCaches->clearCaches();
0104       }
0105     };
0106 
0107     template <typename T>
0108     struct CallInputProcessBlockImpl<T, true, false> {
0109       static void set(T* iProd,
0110                       typename impl::choose_unique_ptr<typename T::InputProcessBlockCache>::type const* iCaches,
0111                       unsigned int iStreamModule) {
0112         iProd->setProcessBlockCache(iCaches->get());
0113         if (iStreamModule == 0 && iProd->cacheFillersRegistered()) {
0114           (*iCaches)->moveProcessBlockCacheFiller(iProd->tokenInfos(), iProd->cacheFillers());
0115         }
0116         iProd->clearRegistration();
0117       }
0118 
0119       static void selectInputProcessBlocks(
0120           typename impl::choose_unique_ptr<typename T::InputProcessBlockCache>::type& iCaches,
0121           ProductRegistry const& productRegistry,
0122           ProcessBlockHelperBase const& processBlockHelperBase,
0123           EDConsumerBase const& edConsumerBase) {
0124         iCaches->selectInputProcessBlocks(productRegistry, processBlockHelperBase, edConsumerBase);
0125       }
0126 
0127       static void accessInputProcessBlock(
0128           edm::ProcessBlock const& processBlock,
0129           typename T::GlobalCache*,
0130           typename impl::choose_unique_ptr<typename T::InputProcessBlockCache>::type& iCaches) {
0131         iCaches->accessInputProcessBlock(processBlock);
0132         T::accessInputProcessBlock(processBlock);
0133       }
0134 
0135       static void clearCaches(typename impl::choose_unique_ptr<typename T::InputProcessBlockCache>::type& iCaches) {
0136         iCaches->clearCaches();
0137       }
0138     };
0139 
0140     template <typename T>
0141     struct CallInputProcessBlockImpl<T, false, true> {
0142       static void set(void*, void const*, unsigned int) {}
0143       static void selectInputProcessBlocks(typename impl::choose_unique_ptr<typename T::InputProcessBlockCache>::type&,
0144                                            ProductRegistry const&,
0145                                            ProcessBlockHelperBase const&,
0146                                            EDConsumerBase const&) {}
0147 
0148       static void accessInputProcessBlock(
0149           edm::ProcessBlock const&,
0150           typename T::GlobalCache*,
0151           typename impl::choose_unique_ptr<typename T::InputProcessBlockCache>::type& iCaches) {}
0152 
0153       static void clearCaches(typename impl::choose_unique_ptr<typename T::InputProcessBlockCache>::type&) {}
0154     };
0155 
0156     template <typename T>
0157     struct CallInputProcessBlockImpl<T, false, false> {
0158       static void set(void*, void const*, unsigned int) {}
0159       static void selectInputProcessBlocks(typename impl::choose_unique_ptr<typename T::InputProcessBlockCache>::type&,
0160                                            ProductRegistry const&,
0161                                            ProcessBlockHelperBase const&,
0162                                            EDConsumerBase const&) {}
0163       static void accessInputProcessBlock(
0164           edm::ProcessBlock const&,
0165           typename T::GlobalCache*,
0166           typename impl::choose_unique_ptr<typename T::InputProcessBlockCache>::type& iCaches) {}
0167 
0168       static void clearCaches(typename impl::choose_unique_ptr<typename T::InputProcessBlockCache>::type&) {}
0169     };
0170 
0171     template <typename T>
0172     using CallInputProcessBlock =
0173         CallInputProcessBlockImpl<T, T::HasAbility::kInputProcessBlockCache, T::HasAbility::kGlobalCache>;
0174 
0175     //********************************
0176     // CallGlobalRun
0177     //********************************
0178     template <typename T, bool>
0179     struct CallGlobalRunImpl {
0180       static void beginRun(edm::Run const& iRun,
0181                            edm::EventSetup const& iES,
0182                            typename T::GlobalCache const* iGC,
0183                            std::shared_ptr<typename T::RunCache const>& oCache) {
0184         oCache = T::globalBeginRun(iRun, iES, iGC);
0185       }
0186 
0187       template <typename B>
0188       static void set(B* iProd, typename T::RunCache const* iCache) {
0189         static_cast<T*>(iProd)->setRunCache(iCache);
0190       }
0191 
0192       static void endRun(edm::Run const& iRun, edm::EventSetup const& iES, typename T::RunContext const* iContext) {
0193         T::globalEndRun(iRun, iES, iContext);
0194       }
0195     };
0196 
0197     template <typename T>
0198     struct CallGlobalRunImpl<T, false> {
0199       static void beginRun(edm::Run const&, edm::EventSetup const&, typename T::GlobalCache const*, impl::dummy_ptr) {}
0200       static void set(void* iProd, typename T::RunCache const* iCache) {}
0201       static void endRun(edm::Run const&, edm::EventSetup const&, typename T::RunContext const*) {}
0202     };
0203 
0204     template <typename T>
0205     using CallGlobalRun = CallGlobalRunImpl<T, T::HasAbility::kRunCache>;
0206 
0207     //********************************
0208     // CallGlobalRunSummary
0209     //********************************
0210     template <typename T, bool>
0211     struct CallGlobalRunSummaryImpl {
0212       static void beginRun(edm::Run const& iRun,
0213                            edm::EventSetup const& iES,
0214                            typename T::RunContext const* iRC,
0215                            std::shared_ptr<typename T::RunSummaryCache>& oCache) {
0216         oCache = T::globalBeginRunSummary(iRun, iES, iRC);
0217       }
0218       template <typename B>
0219       static void streamEndRunSummary(B* iProd,
0220                                       edm::Run const& iRun,
0221                                       edm::EventSetup const& iES,
0222                                       typename T::RunSummaryCache* iCache) {
0223         static_cast<T*>(iProd)->endRunSummary(iRun, iES, iCache);
0224       }
0225 
0226       static void globalEndRun(edm::Run const& iRun,
0227                                edm::EventSetup const& iES,
0228                                typename T::RunContext const* iContext,
0229                                typename T::RunSummaryCache* iCache) {
0230         T::globalEndRunSummary(iRun, iES, iContext, iCache);
0231       }
0232     };
0233 
0234     template <typename T>
0235     struct CallGlobalRunSummaryImpl<T, false> {
0236       static void beginRun(edm::Run const&, edm::EventSetup const&, typename T::RunContext const*, impl::dummy_ptr) {}
0237       static void streamEndRunSummary(void* iProd,
0238                                       edm::Run const&,
0239                                       edm::EventSetup const&,
0240                                       typename T::RunSummaryCache const* iCache) {}
0241       static void globalEndRun(edm::Run const&,
0242                                edm::EventSetup const&,
0243                                typename T::RunContext const*,
0244                                typename T::RunSummaryCache*) {}
0245     };
0246 
0247     template <typename T>
0248     using CallGlobalRunSummary = CallGlobalRunSummaryImpl<T, T::HasAbility::kRunSummaryCache>;
0249 
0250     //********************************
0251     // CallGlobalLuminosityBlock
0252     //********************************
0253     template <typename T, bool>
0254     struct CallGlobalLuminosityBlockImpl {
0255       static void beginLuminosityBlock(edm::LuminosityBlock const& Lumi,
0256                                        edm::EventSetup const& iES,
0257                                        typename T::RunContext const* iRC,
0258                                        std::shared_ptr<typename T::LuminosityBlockCache const>& oCache) {
0259         oCache = T::globalBeginLuminosityBlock(Lumi, iES, iRC);
0260       }
0261 
0262       template <typename B>
0263       static void set(B* iProd, typename T::LuminosityBlockCache const* iCache) {
0264         static_cast<T*>(iProd)->setLuminosityBlockCache(iCache);
0265       }
0266 
0267       static void endLuminosityBlock(edm::LuminosityBlock const& Lumi,
0268                                      edm::EventSetup const& iES,
0269                                      typename T::LuminosityBlockContext const* iContext) {
0270         T::globalEndLuminosityBlock(Lumi, iES, iContext);
0271       }
0272     };
0273 
0274     template <typename T>
0275     struct CallGlobalLuminosityBlockImpl<T, false> {
0276       static void beginLuminosityBlock(edm::LuminosityBlock const&,
0277                                        edm::EventSetup const&,
0278                                        typename T::RunContext const*,
0279                                        impl::dummy_ptr) {}
0280       static void set(void* iProd, typename T::LuminosityBlockCache const* iCache) {}
0281       static void endLuminosityBlock(edm::LuminosityBlock const&,
0282                                      edm::EventSetup const&,
0283                                      typename T::LuminosityBlockContext const*) {}
0284     };
0285     template <typename T>
0286     using CallGlobalLuminosityBlock = CallGlobalLuminosityBlockImpl<T, T::HasAbility::kLuminosityBlockCache>;
0287 
0288     //********************************
0289     // CallGlobalLuminosityBlockSummary
0290     //********************************
0291     template <typename T, bool>
0292     struct CallGlobalLuminosityBlockSummaryImpl {
0293       static void beginLuminosityBlock(edm::LuminosityBlock const& Lumi,
0294                                        edm::EventSetup const& iES,
0295                                        typename T::LuminosityBlockContext const* iRC,
0296                                        std::shared_ptr<typename T::LuminosityBlockSummaryCache>& oCache) {
0297         oCache = T::globalBeginLuminosityBlockSummary(Lumi, iES, iRC);
0298       }
0299       template <typename B>
0300       static void streamEndLuminosityBlockSummary(B* iProd,
0301                                                   edm::LuminosityBlock const& iLumi,
0302                                                   edm::EventSetup const& iES,
0303                                                   typename T::LuminosityBlockSummaryCache* iCache) {
0304         static_cast<T*>(iProd)->endLuminosityBlockSummary(iLumi, iES, iCache);
0305       }
0306 
0307       static void globalEndLuminosityBlock(edm::LuminosityBlock const& Lumi,
0308                                            edm::EventSetup const& iES,
0309                                            typename T::LuminosityBlockContext const* iContext,
0310                                            typename T::LuminosityBlockSummaryCache* iCache) {
0311         T::globalEndLuminosityBlockSummary(Lumi, iES, iContext, iCache);
0312       }
0313     };
0314 
0315     template <typename T>
0316     struct CallGlobalLuminosityBlockSummaryImpl<T, false> {
0317       static void beginLuminosityBlock(edm::LuminosityBlock const&,
0318                                        edm::EventSetup const&,
0319                                        typename T::LuminosityBlockContext const*,
0320                                        impl::dummy_ptr) {}
0321       static void streamEndLuminosityBlockSummary(void* iProd,
0322                                                   edm::LuminosityBlock const&,
0323                                                   edm::EventSetup const&,
0324                                                   typename T::LuminosityBlockSummaryCache* iCache) {}
0325       static void globalEndLuminosityBlock(edm::LuminosityBlock const&,
0326                                            edm::EventSetup const&,
0327                                            typename T::LuminosityBlockContext const*,
0328                                            typename T::LuminosityBlockSummaryCache*) {}
0329     };
0330 
0331     template <typename T>
0332     using CallGlobalLuminosityBlockSummary =
0333         CallGlobalLuminosityBlockSummaryImpl<T, T::HasAbility::kLuminosityBlockSummaryCache>;
0334 
0335     //********************************
0336     // CallWatchProcessBlock
0337     //********************************
0338     template <typename T, bool, bool>
0339     struct CallWatchProcessBlockImpl {
0340       static void beginProcessBlock(edm::ProcessBlock const& iProcessBlock, typename T::GlobalCache* iGC) {
0341         T::beginProcessBlock(iProcessBlock, iGC);
0342       }
0343 
0344       static void endProcessBlock(edm::ProcessBlock const& iProcessBlock, typename T::GlobalCache* iGC) {
0345         T::endProcessBlock(iProcessBlock, iGC);
0346       }
0347     };
0348 
0349     template <typename T>
0350     struct CallWatchProcessBlockImpl<T, true, false> {
0351       static void beginProcessBlock(edm::ProcessBlock const& processBlock, typename T::GlobalCache*) {
0352         T::beginProcessBlock(processBlock);
0353       }
0354 
0355       static void endProcessBlock(edm::ProcessBlock const& processBlock, typename T::GlobalCache*) {
0356         T::endProcessBlock(processBlock);
0357       }
0358     };
0359 
0360     template <typename T>
0361     struct CallWatchProcessBlockImpl<T, false, true> {
0362       static void beginProcessBlock(edm::ProcessBlock const&, typename T::GlobalCache*) {}
0363       static void endProcessBlock(edm::ProcessBlock const&, typename T::GlobalCache*) {}
0364     };
0365 
0366     template <typename T>
0367     struct CallWatchProcessBlockImpl<T, false, false> {
0368       static void beginProcessBlock(edm::ProcessBlock const&, typename T::GlobalCache*) {}
0369       static void endProcessBlock(edm::ProcessBlock const&, typename T::GlobalCache*) {}
0370     };
0371 
0372     template <typename T>
0373     using CallWatchProcessBlock =
0374         CallWatchProcessBlockImpl<T, T::HasAbility::kWatchProcessBlock, T::HasAbility::kGlobalCache>;
0375 
0376     //********************************
0377     // CallBeginProcessBlockProduce
0378     //********************************
0379     template <typename T, bool, bool>
0380     struct CallBeginProcessBlockProduceImpl {
0381       static void produce(edm::ProcessBlock& processBlock, typename T::GlobalCache* globalCache) {
0382         T::beginProcessBlockProduce(processBlock, globalCache);
0383       }
0384     };
0385 
0386     template <typename T>
0387     struct CallBeginProcessBlockProduceImpl<T, true, false> {
0388       static void produce(edm::ProcessBlock& processBlock, typename T::GlobalCache*) {
0389         T::beginProcessBlockProduce(processBlock);
0390       }
0391     };
0392 
0393     template <typename T>
0394     struct CallBeginProcessBlockProduceImpl<T, false, true> {
0395       static void produce(edm::ProcessBlock&, typename T::GlobalCache*) {}
0396     };
0397 
0398     template <typename T>
0399     struct CallBeginProcessBlockProduceImpl<T, false, false> {
0400       static void produce(edm::ProcessBlock&, typename T::GlobalCache*) {}
0401     };
0402 
0403     template <typename T>
0404     using CallBeginProcessBlockProduce =
0405         CallBeginProcessBlockProduceImpl<T, T::HasAbility::kBeginProcessBlockProducer, T::HasAbility::kGlobalCache>;
0406 
0407     //********************************
0408     // CallEndProcessBlockProduce
0409     //********************************
0410     template <typename T, bool, bool>
0411     struct CallEndProcessBlockProduceImpl {
0412       static void produce(edm::ProcessBlock& processBlock, typename T::GlobalCache* globalCache) {
0413         T::endProcessBlockProduce(processBlock, globalCache);
0414       }
0415     };
0416 
0417     template <typename T>
0418     struct CallEndProcessBlockProduceImpl<T, true, false> {
0419       static void produce(edm::ProcessBlock& processBlock, typename T::GlobalCache*) {
0420         T::endProcessBlockProduce(processBlock);
0421       }
0422     };
0423 
0424     template <typename T>
0425     struct CallEndProcessBlockProduceImpl<T, false, true> {
0426       static void produce(edm::ProcessBlock&, typename T::GlobalCache*) {}
0427     };
0428 
0429     template <typename T>
0430     struct CallEndProcessBlockProduceImpl<T, false, false> {
0431       static void produce(edm::ProcessBlock&, typename T::GlobalCache*) {}
0432     };
0433 
0434     template <typename T>
0435     using CallEndProcessBlockProduce =
0436         CallEndProcessBlockProduceImpl<T, T::HasAbility::kEndProcessBlockProducer, T::HasAbility::kGlobalCache>;
0437 
0438     //********************************
0439     // CallBeginRunProduce
0440     //********************************
0441     template <typename T, bool>
0442     struct CallBeginRunProduceImpl {
0443       static void produce(edm::Run& iRun, edm::EventSetup const& iES, typename T::RunContext const* iRC) {
0444         T::globalBeginRunProduce(iRun, iES, iRC);
0445       }
0446     };
0447 
0448     template <typename T>
0449     struct CallBeginRunProduceImpl<T, false> {
0450       static void produce(edm::Run& iRun, edm::EventSetup const& iES, typename T::RunContext const* iRC) {}
0451     };
0452 
0453     template <typename T>
0454     using CallBeginRunProduce = CallBeginRunProduceImpl<T, T::HasAbility::kBeginRunProducer>;
0455 
0456     //********************************
0457     // CallEndRunProduce
0458     //********************************
0459     template <typename T, bool bProduce, bool bSummary>
0460     struct CallEndRunProduceImpl {
0461       static void produce(edm::Run&,
0462                           edm::EventSetup const&,
0463                           typename T::RunContext const*,
0464                           typename T::RunSummaryCache const*) {}
0465     };
0466 
0467     template <typename T>
0468     struct CallEndRunProduceImpl<T, true, false> {
0469       static void produce(edm::Run& iRun,
0470                           edm::EventSetup const& iES,
0471                           typename T::RunContext const* iRC,
0472                           typename T::RunSummaryCache const*) {
0473         T::globalEndRunProduce(iRun, iES, iRC);
0474       }
0475     };
0476 
0477     template <typename T>
0478     struct CallEndRunProduceImpl<T, true, true> {
0479       static void produce(edm::Run& iRun,
0480                           edm::EventSetup const& iES,
0481                           typename T::RunContext const* iRC,
0482                           typename T::RunSummaryCache const* iRS) {
0483         T::globalEndRunProduce(iRun, iES, iRC, iRS);
0484       }
0485     };
0486 
0487     template <typename T>
0488     using CallEndRunProduce = CallEndRunProduceImpl<T, T::HasAbility::kEndRunProducer, T::HasAbility::kRunSummaryCache>;
0489 
0490     //********************************
0491     // CallBeginLuminosityBlockProduce
0492     //********************************
0493     template <typename T, bool>
0494     struct CallBeginLuminosityBlockProduceImpl {
0495       static void produce(edm::LuminosityBlock& Lumi,
0496                           edm::EventSetup const& iES,
0497                           typename T::LuminosityBlockContext const* iRC) {
0498         T::globalBeginLuminosityBlockProduce(Lumi, iES, iRC);
0499       }
0500     };
0501 
0502     template <typename T>
0503     struct CallBeginLuminosityBlockProduceImpl<T, false> {
0504       static void produce(edm::LuminosityBlock& Lumi,
0505                           edm::EventSetup const& iES,
0506                           typename T::LuminosityBlockContext const* iRC) {}
0507     };
0508 
0509     template <typename T>
0510     using CallBeginLuminosityBlockProduce =
0511         CallBeginLuminosityBlockProduceImpl<T, T::HasAbility::kBeginLuminosityBlockProducer>;
0512 
0513     //********************************
0514     // CallEndLuminosityBlockProduce
0515     //********************************
0516     template <typename T, bool bProduce, bool bSummary>
0517     struct CallEndLuminosityBlockProduceImpl {
0518       static void produce(edm::LuminosityBlock&,
0519                           edm::EventSetup const&,
0520                           typename T::LuminosityBlockContext const*,
0521                           typename T::LuminosityBlockSummaryCache const*) {}
0522     };
0523 
0524     template <typename T>
0525     struct CallEndLuminosityBlockProduceImpl<T, true, false> {
0526       static void produce(edm::LuminosityBlock& Lumi,
0527                           edm::EventSetup const& iES,
0528                           typename T::LuminosityBlockContext const* iRC,
0529                           typename T::LuminosityBlockSummaryCache const*) {
0530         T::globalEndLuminosityBlockProduce(Lumi, iES, iRC);
0531       }
0532     };
0533 
0534     template <typename T>
0535     struct CallEndLuminosityBlockProduceImpl<T, true, true> {
0536       static void produce(edm::LuminosityBlock& Lumi,
0537                           edm::EventSetup const& iES,
0538                           typename T::LuminosityBlockContext const* iRC,
0539                           typename T::LuminosityBlockSummaryCache const* iRS) {
0540         T::globalEndLuminosityBlockProduce(Lumi, iES, iRC, iRS);
0541       }
0542     };
0543 
0544     template <typename T>
0545     using CallEndLuminosityBlockProduce =
0546         CallEndLuminosityBlockProduceImpl<T,
0547                                           T::HasAbility::kEndLuminosityBlockProducer,
0548                                           T::HasAbility::kLuminosityBlockSummaryCache>;
0549 
0550   }  // namespace stream
0551 }  // namespace edm
0552 
0553 #endif