![]() |
|
|||
File indexing completed on 2023-03-17 11:03:46
0001 #ifndef FWCore_SOA_Column_h 0002 #define FWCore_SOA_Column_h 0003 // -*- C++ -*- 0004 // 0005 // Package: FWCore/SOA 0006 // Class : Column 0007 // 0008 /**\class Column Column.h "Column.h" 0009 0010 Description: Column describes a column in a Table 0011 0012 Usage: 0013 Class instances inheriting from the Column class are not intended to be used. 0014 Instead, the specific Column type is used as a template argument 0015 to a edm::soa::Table<> to describe a column in the table. 0016 0017 A column is defined by a name and a C++ type. 0018 0019 Classes inheriting from Column must declare a 'constexpr const char' array named 'kLabel'. 0020 \code 0021 namespace edm { 0022 namespace soa { 0023 struct Eta : public Column<double,Eta> { 0024 static constexpr const char * const kLabel = "eta"; 0025 }; 0026 } 0027 } 0028 \endcode 0029 Alternatively, one can use the macro SOA_DECLARE_COLUMN 0030 \code 0031 namespace edm { 0032 namespace soa { 0033 0034 SOA_DECLARE_COLUMN(Eta,double, "eta"); 0035 0036 } 0037 } 0038 0039 \endcode 0040 0041 */ 0042 // 0043 // Original Author: Chris Jones 0044 // Created: Thu, 24 Aug 2017 16:17:56 GMT 0045 // 0046 0047 // system include files 0048 0049 // user include files 0050 0051 // forward declarations 0052 namespace edm { 0053 namespace soa { 0054 0055 /**Helper class used to fill a column of a table 0056 in a 'non standard' way 0057 */ 0058 template <typename COL, typename F> 0059 struct ColumnFillerHolder { 0060 using Column_type = COL; 0061 F m_f; 0062 }; 0063 0064 template <typename T, typename INHERIT> 0065 struct Column { 0066 using type = T; 0067 0068 static constexpr const char* const& label() { return INHERIT::kLabel; } 0069 0070 template <typename F> 0071 static ColumnFillerHolder<INHERIT, F> filler(F&& iF) { 0072 return {iF}; 0073 } 0074 0075 Column(const Column&) = delete; // stop default 0076 0077 const Column& operator=(const Column&) = delete; // stop default 0078 0079 private: 0080 Column() = default; 0081 }; 0082 0083 } // namespace soa 0084 } // namespace edm 0085 0086 #define SOA_DECLARE_COLUMN(_ClassName_, _Type_, _String_) \ 0087 struct _ClassName_ : public edm::soa::Column<_Type_, _ClassName_> { \ 0088 static constexpr const char* const kLabel = _String_; \ 0089 } 0090 0091 /* 0092 * SOA_DECLARE_DEFAULT macro to define a default way to retrieve the column 0093 * values from an arbitrary class, i.e. a templated value_for_column function. 0094 * A call to the macro should be placed in edm::soa namespace. 0095 * 0096 * This templated value_for_column function has the advantage that 0097 * value_for_column does not have to be redefined for multiple classes with a 0098 * similar interface, but it has one caveat: if a different value_for_column 0099 * function needs to be defined for a given class, it needs to be defined also 0100 * for all derived classes, otherwise the templated value_for_column function 0101 * will still be used for the derived classes. 0102 * 0103 * If this becomes a real problem, the SOA_DECLARE_DEFAULT can be changed to 0104 * define a value_for_column_default() function, and all callers of 0105 * value_for_column() check the existence of a value_for_column_default() 0106 * overload first. 0107 * 0108 * For now, it is encouraged to adapt the interface of the class to the generic 0109 * value_for_column function generated by this macro, rather than implementing 0110 * value_for_column overloads for each class. 0111 */ 0112 #define SOA_DECLARE_DEFAULT(_ClassName_, _Expression_) \ 0113 template <class Object> \ 0114 _ClassName_::type value_for_column(Object const& x, _ClassName_*) { \ 0115 return x._Expression_; \ 0116 } 0117 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.2.1 LXR engine. The LXR team |
![]() ![]() |