Nymph  v1.5.2
Flow-Based Data Processing Framework
KTCut.hh
Go to the documentation of this file.
1 /*
2  * KTCut.hh
3  *
4  * Created on: Sept 19, 2014
5  * Author: nsoblath
6  */
7 
8 #ifndef KTCUT_HH_
9 #define KTCUT_HH_
10 
11 #include "KTConfigurable.hh"
12 #include "KTCutResult.hh"
13 #include "KTData.hh"
15 #include "KTLogger.hh"
16 #include "KTMemberVariable.hh"
17 
18 #include "factory.hh"
19 #include "typename.hh"
20 
21 namespace Nymph
22 {
23  KTLOGGER(cutlog_h, "KTCut.h");
24 
108  //************************************
109  // KTCut -- base class for all cuts
110  //************************************
111 
112  class KTCut : public KTConfigurable
113  {
114  public:
115  KTCut(const std::string& name = "default-cut-name");
116  virtual ~KTCut();
117 
118  virtual bool Apply(KTDataPtr) = 0;
119  };
120 
121 
122  //*****************************************************************
123  // KTCutOneArg -- base class for cuts operating on one data type
124  //*****************************************************************
125 
126  template< class XDataType >
127  class KTCutOneArg : public KTCut
128  {
129  public:
130  KTCutOneArg(const std::string& name = "default-cut-name");
131  virtual ~KTCutOneArg();
132 
133  virtual bool Apply(KTData& data, XDataType& dataType) = 0;
134 
135  virtual bool Apply(KTDataPtr dataPtr);
136  };
137 
138 
139  //*******************************************************************
140  // KTCutTwoArgs -- base class for cuts operating on two data types
141  //*******************************************************************
142 
143  template< class XDataType1, class XDataType2 >
144  class KTCutTwoArgs : public KTCut
145  {
146  public:
147  KTCutTwoArgs(const std::string& name = "default-cut-name");
148  virtual ~KTCutTwoArgs();
149 
150  virtual bool Apply(KTData& data, XDataType1& dataType1, XDataType2& dataType2) = 0;
151 
152  virtual bool Apply(KTDataPtr dataPtr);
153  };
154 
155 
156  //*******************
157  // Implementations
158  //*******************
159 
160  template< class XDataType >
161  KTCutOneArg< XDataType >::KTCutOneArg(const std::string& name) :
162  KTCut(name)
163  {
164  }
165 
166  template< class XDataType >
168  {}
169 
170  template< class XDataType >
172  {
173  if (! dataPtr->Has< XDataType >())
174  {
175  KTERROR(cutlog_h, "Data type <" << scarab::type(XDataType()) << "> was not present");
176  return false;
177  }
178  return Apply(dataPtr->Of< KTData >(), dataPtr->Of< XDataType >());
179  }
180 
181 
182  template< class XDataType1, class XDataType2 >
184  KTCut(name)
185  {
186  }
187 
188  template< class XDataType1, class XDataType2 >
190  {}
191 
192  template< class XDataType1, class XDataType2 >
194  {
195  if (! dataPtr->Has< XDataType1 >())
196  {
197  KTERROR(cutlog_h, "Data type <" << scarab::type(XDataType1()) << "> was not present");
198  return false;
199  }
200  if (! dataPtr->Has< XDataType2 >())
201  {
202  KTERROR(cutlog_h, "Data type <" << scarab::type(XDataType2()) << "> was not present");
203  return false;
204  }
205  return Apply(dataPtr->Of< KTData >(), dataPtr->Of< XDataType1 >(), dataPtr->Of< XDataType2 >());
206  }
207 
208 /* Playing around: wouldn't it be cool if this could be done with variadic tmeplates?
209  * Unfortunately we'll need to be able to iterate over the types in the template pack in the Apply(KTDataPtr) function.
210  *
211  template< class ... DataTypes >
212  class KTCutOnData : public KTCut
213  {
214  public:
215  KTCutOnData(const std::string& name = "default-cut-name");
216  virtual ~KTCutOnData();
217 
218  virtual bool Apply(DataTypes ...) = 0;
219 
220  virtual bool Apply(KTDataPtr dataPtr);
221  };
222 
223  template< class ... DataTypes >
224  KTCutOnData< DataTypes... >::KTCutOnData(const std::string& name) :
225  KTCut(name)
226  {
227  }
228 
229  template< class ... DataTypes >
230  KTCutOnData< DataTypes... >::~KTCutOnData()
231  {}
232 
233  template< class ... DataTypes >
234  bool KTCutOnData< DataTypes... >::Apply(KTDataPtr dataPtr)
235  {
236 
237  }
238 */
239 
240  // this macro enforces the existence of cut_class::Result and cut_class::Result::sName at compile time
241 #define KT_REGISTER_CUT(cut_class) \
242  static ::scarab::registrar< ::Nymph::KTCut, cut_class, const std::string& > sCut##cut_class##Registrar( cut_class::Result::sName ); \
243  static ::Nymph::KTExtensibleStructRegistrar< ::Nymph::KTCutResultCore, cut_class::Result > sCut##cut_class##ResultRegistrar( cut_class::Result::sName );
244 
245 } /* namespace Nymph */
246 
247 #endif /* KTCUT_HH_ */
Base class for a cut that gets applied to data objects.
Definition: KTCut.hh:112
virtual bool Apply(KTDataPtr)=0
XStructType & Of(void)
Returns a reference to the object of type XStructType; creates that object if it doesn&#39;t exist...
virtual bool Apply(KTData &data, XDataType1 &dataType1, XDataType2 &dataType2)=0
KTLOGGER(applog, "KTApplication")
KTCutOneArg(const std::string &name="default-cut-name")
Definition: KTCut.hh:161
KTCut(const std::string &name="default-cut-name")
Definition: KTCut.cc:12
virtual ~KTCut()
Definition: KTCut.cc:17
boost::shared_ptr< KTData > KTDataPtr
Definition: KTData.hh:67
#define KTERROR(...)
Definition: KTLogger.hh:347
virtual ~KTCutTwoArgs()
Definition: KTCut.hh:189
Contains the logger class and macros, based on Kasper&#39;s KLogger class.