File indexing completed on 2025-01-09 23:33:15
0001 #ifndef CommonTools_Utils_MethodChain_h
0002 #define CommonTools_Utils_MethodChain_h
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "CommonTools/Utils/interface/parser/MethodInvoker.h"
0012 #include "CommonTools/Utils/interface/TypeCode.h"
0013
0014 #include <vector>
0015 #include <oneapi/tbb/concurrent_queue.h>
0016
0017 namespace reco {
0018 namespace parser {
0019
0020
0021 class MethodChainBase {
0022 public:
0023 virtual ~MethodChainBase() {}
0024 virtual edm::ObjectWithDict value(const edm::ObjectWithDict&) const = 0;
0025 };
0026
0027
0028 typedef std::shared_ptr<MethodChainBase> MethodChainPtr;
0029
0030
0031 class MethodChain : public MethodChainBase {
0032 private:
0033 std::vector<MethodInvoker> methods_;
0034 using Objects = std::vector<std::pair<edm::ObjectWithDict, bool>>;
0035 mutable oneapi::tbb::concurrent_queue<Objects> objectsCache_;
0036
0037 private:
0038 [[nodiscard]] Objects initObjects_() const;
0039
0040 Objects borrowObjects() const;
0041 void returnObjects(Objects&&) const;
0042
0043 public:
0044
0045
0046
0047 static bool makeStorage(edm::ObjectWithDict& obj, const edm::TypeWithDict& retType);
0048
0049
0050
0051 static void delStorage(edm::ObjectWithDict&);
0052
0053 public:
0054 MethodChain(const std::vector<MethodInvoker>& methods);
0055 MethodChain(const MethodChain&);
0056 ~MethodChain();
0057 edm::ObjectWithDict value(const edm::ObjectWithDict&) const override;
0058 };
0059
0060
0061
0062 class LazyMethodChain : public MethodChainBase {
0063 private:
0064 std::vector<LazyInvoker> methods_;
0065
0066 public:
0067 LazyMethodChain(const std::vector<LazyInvoker>& methods);
0068 ~LazyMethodChain() override;
0069 edm::ObjectWithDict value(const edm::ObjectWithDict&) const override;
0070 };
0071
0072 }
0073 }
0074
0075 #endif