Report problems to ATLAS LXR Team (with time and IP address indicated)

The LXR Cross Referencer

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Architecture: linux ]
Version: head ] [ nightly ] [ GaudiDev ]
  Links to LXR source navigation pages for stable releases [ 12.*.* ]   [ 13.*.* ]   [ 14.*.* ]   [ 15.*.* ] 

001 // $Id: Tuple.h,v 1.9 2008/10/27 19:22:20 marcocle Exp $
002 #ifndef GAUDIALG_TUPLE_H
003 #define GAUDIALG_TUPLE_H 1
004 // ============================================================================
005 // Include files
006 // ============================================================================
007 // STD & STL
008 // ============================================================================
009 #include <string>
010 
011 // ============================================================================
012 /** @file Tuple.h
013  *
014  *  Header file for class : Tuple
015  *
016  *  @date 2002-10-30
017  *  @author Vanya Belyaev Ivan.Belyaev@itep.ru
018  */
019 // ============================================================================
020 
021 // ============================================================================
022 /** @namespace Tuples
023  *
024  *  General namespace for Tuple properties
025  *
026  *  @author Vanya BELYAEV Ivan.Belyaev@itep.ru
027  *  @date   2004-01-23
028  */
029 // ============================================================================
030 
031 #include "GaudiAlg/TupleObj.h"
032 
033 namespace Tuples
034 {
035 
036   template <class ITEM> class TupleItem ;
037 
038   /** @class Tuple Tuple.h GaudiAlg/Tuple.h
039    *
040    *  @brief A simple wrapper class over standard
041    *                        Gaudi NTuple::Tuple facility
042    *
043    *  The main advantages of local ntuples with respect to 'standard'
044    *  Gaudi NTuples ( NTuple::Tuple ) is their "locality".
045    *  For 'standard' ntuples one need
046    * <ol>
047    * <li> Define all ntuple columns/items as
048    *      data members of the algorithm </li>
049    * <li> Book the  <tt>NTuple::Tuple</tt> object using
050    *      <tt>INTupleSvc</tt></li>
051    * <li> Add all defined columns/items to the booked ntuple </li>
052    * <li> Fill ntuple records
053    * </ol>
054    *  Usially the first step is done in the header file (separate file!)
055    *  of the algorithm, the second and the third steps are done in
056    *  <tt>initialize()</tt> method of the algorithm and
057    *  the fourth step is done somewhere in <tt>execute()</tt> method of
058    *  the same algorithm. Such approach requires to keep track of the
059    *  tuple structure through different method and event throught different
060    *  files. And even minor modification of the structure of teh ntuple
061    *  will reqire the modification of at least 2 methods and 2 files.
062    *
063    *  The <tt>Tuples::Tuple</tt> wrapper over standard Gaudi
064    *  <tt>NTuple::Tuple</tt> class solves all abouve listed problems with
065    *  "non-local" nature of Gaudi <tt>NTuple::Tuple</tt> objects.
066    *
067    *  <tt>Tuples::Tuple</tt> object is booked and used 'locally'.
068    *  One does not need to pre-book the ntuple or its columns/items
069    *  somewhere in different compilation units or other methods different
070    *  from the actual point of using the ntuple.
071    *
072    *  The simplest example of usage Tuple object:
073    *
074    *  @code
075    *  Tuple tuple = nTuple( "some more or less uniqe tuple title ");
076    *  for( Loop D0 = loop( "K- pi+", "D0" ) , D0 , ++D0 )
077    *  {
078    *     tuple -> column ( "mass" , M  ( D0 ) / GeV ) ;
079    *     tuple -> column ( "pt"   , PT ( D0 ) / GeV ) ;
080    *     tuple -> column ( "p"    , P  ( D0 ) / GeV ) ;
081    *     tuple -> write  () ;
082    *  }
083    *  @endcode
084    *
085    *  One could fill some Tuple variables in one go
086    *
087    *  @code
088    *  Tuple tuple = nTuple( "some more or less uniqe tuple title ");
089    *  for( Loop D0 = loop( "K- pi+", "D0" ) , D0 , ++D0 )
090    *  {
091    *     tuple -> column ( "mass"      , M  ( D0 ) / GeV ) ;
092    *     tuple -> fill   ( "pt , p "   , PT ( D0 ) / GeV , P(D0) / GeV ) ;
093    *     tuple -> write  () ;
094    *  }
095    *  @endcode
096    *
097    *  Even ALL variables could be filled in one go:
098    *
099    *  @code
100    *  Tuple tuple = nTuple( "some more or less uniqe tuple title ");
101    *  for( Loop D0 = loop( "K- pi+", "D0" ) , D0 , ++D0 )
102    *  {
103    *     tuple -> fill   ( "mass pt , p ", M(D0)/GeV,PT(D0)/GeV,P(D0)/GeV ) ;
104    *     tuple -> write  () ;
105    *  }
106    *  @endcode
107    *
108    *  All these techniques could be easily combined in arbitrary ways
109    *
110    *  @see GaudiTupleAlg
111    *  @see TupleObj
112    *
113    *  @author Vanya BELYAEV Ivan.Belyaev@itep.ru
114    *  @date   2003-02-24
115    */
116   class Tuple
117   {
118   public:
119 
120     /** standard constructor
121      *  @param tuple pointer to "real" tuple object
122      */
123 
124     Tuple ( TupleObj* tuple ) ;
125 
126     /// copy constructor
127     Tuple ( const Tuple&    tuple ) ;
128 
129     /// destructor
130     virtual ~Tuple() ;
131 
132     /** assignment  operator
133      *  Tuples could be assigned in a safe way
134      *  @param tuple tuple to be assigned
135      */
136     Tuple&    operator=( const Tuple&    tuple ) ;
137 
138     /** get the pointer to the underlying object
139      *  @return pointer to underlying TupleObj
140      */
141     TupleObj* operator->  ()  const  { return      tuple () ; }
142 
143     /// check the validity of the tuple object
144     bool      valid       ()  const  { return 0 != tuple () ; }
145 
146   protected:
147 
148     /// Return the underlying tuple object
149     TupleObj*  tuple() const { return m_tuple ; }
150 
151   private:
152 
153     /// default constructor is private
154     Tuple();
155 
156   private:
157 
158     /// The tuple object
159     TupleObj* m_tuple ;
160 
161   };
162 
163   /** @class TupleColumn
164    *
165    *  Helper class which allows to extend the functionality
166    *  of Tuple with possibility to use your own representation
167    *  of complex objects.
168    *
169    *  It allows to extend the functionality of
170    *  Tuples::Tuple and Tuples::TupleObj classes
171    *  for your own needs, according to your own taste
172    *  and without touching the classes at all.
173    *  Neither the extension or the functionality through
174    *  inheritance nor the extension through aggregation
175    *  is used. One use the trick with
176    *  template specialization of streamer operators.
177    *
178    *  Assuming one need to add into private code the
179    *  N-Tuple representation of e.g. MyClass class
180    *
181    *  @code
182    *
183    *  // 0) Class which needs N-Tuple representation
184    *  class MyClass
185    *    {
186    *       ...
187    *      double field1() const ;
188    *      double field2() const ;
189    *      long   field3() const ;
190    *      bool   field4() const ;
191    *    };
192    *
193    *  // 1) define specialization of operator with needed
194    *  //    representation
195    *  template <>
196    *  inline Tuples::Tuple& operator<<
197    *     ( Tuples::Tuple&                     tuple ,
198    *      const Tuples::TupleColumn<MyClass>& item  )
199    *   {
200    *      // no action for invalid tuple
201    *      if( !tuple.valid() ) { return tuple ;}
202    *      tuple->column( item.name() + "field1" , item.value().field1() );
203    *      tuple->column( item.name() + "field2" , item.value().field2() );
204    *      tuple->column( item.name() + "field3" , item.value().field3() );
205    *      tuple->column( item.name() + "field4" , item.value().field4() );
206    *      return tuple ;
207    *   }
208    *
209    * // 3) use the operator to 'stream' objects of type MyClass ito
210    * //  N-Tuple:
211    *
212    *    Tuple tuple = ... ;
213    *    MyClass a  = ...  ;
214    *    tuple << Tuples::make_column( "A" , a ) ;
215    *
216    *    // operators can be chained:
217    *    MyClass a1 = ...  ;
218    *    MyClass a2 = ...  ;
219    *    MyClass a3 = ...  ;
220    *    tuple << Tuples::make_column( "A1" , a1 )
221    *          << Tuples::make_column( "A2" , a2 )
222    *          << Tuples::make_column( "A3" , a3 ) ;
223    *
224    *  @endcode
225    *
226    *  Alternatively one can use function Tuples::Column
227    *
228    *  @code
229    *
230    *    //
231    *    MyClass a1 = ...  ;
232    *    MyClass a2 = ...  ;
233    *    MyClass a3 = ...  ;
234    *    tuple << Tuples::Column( "A1" , a1 )
235    *          << Tuples::Column( "A2" , a2 )
236    *          << Tuples::Column( "A3" , a3 ) ;
237    *
238    *  @endcode
239    *
240    *
241    *  Using this technique one can put 'any' object into NTuple
242    *  and create the own representation. E.g. if the  'standard'
243    *  representation of HepLorentzVector is not suitable one
244    *  can create the alternative representation.
245    *
246    *  Also one can create own representations of complex classes, e.g.
247    *  class MCParticle :
248    *
249    *  @code
250    *
251    *  /// 1 ) define template specialization
252    *  template <>
253    *  inline Tuples::Tuple& operator<<
254    *     ( Tuples::Tuple&                               tuple ,
255    *      const Tuples::TupleColumn<const MCParticle*>& item  )
256    *   {
257    *     if( !tuple.valid() ) { return tuple ;}
258    *     const MCParticle* mcp = item.value() ;
259    *     tuple->column( item.name() + "Mom"   , mcp->momentum()          ) ;
260    *     tuple->column( item.name() + "PID"   , mcp->particleID().pid()  ) ;
261    *     tuple->column( item.name() + "hasVX" , 0 != mcp->originVertex() ) ;
262    *   };
263    *
264    *  /// 2) use the specialization to feed Tuple
265    *
266    *
267    *    Tuple tuple = ... ;
268    *    const MCParticle* mcp = ... ;
269    *    tuple << Tuples::Column( "MCP" , mcp ) ;
270    *
271    *
272    *  @endcode
273    *
274    *
275    *  @author Vanya BELYAEV Ivan.Belyaev@itep.ru
276    */
277   template<class ITEM>
278   class TupleColumn
279   {
280   public:
281     TupleColumn ( const std::string&  name   ,
282                   const ITEM&         value  )
283       : m_name ( name ) , m_value  (  value  ) {};
284   public:
285     /// Return the column name
286     const std::string& name  () const { return m_name  ; }
287     /// Return the column value
288     const ITEM&        value () const { return m_value ; }
289   private:
290     TupleColumn();
291   private:
292     std::string m_name   ; ///< The column name
293     ITEM       m_value  ; ///< The column value
294   };
295 
296   /** @fn make_column
297    *  helper function to create 'on-the-fly' the
298    *  helper object Tuples::TupleColumn
299    */
300   template<class ITEM>
301   inline TupleColumn<ITEM>
302   make_column ( const std::string& name , const ITEM& item )
303   { return TupleColumn<ITEM> ( name , item ) ; }
304 
305   /** @fn make_column
306    *  helper function to create 'on-the-fly' the
307    *  helper object Tuples::TupleColumn
308    */
309   template<class ITEM>
310   inline TupleColumn<const ITEM*>
311   make_column ( const std::string& name , const ITEM* item )
312   { return TupleColumn<const ITEM*>( name , item ) ; }
313 
314   /** @fn make_column
315    *  helper function to create 'on-the-fly' the
316    *  helper object Tuples::TupleColumn
317    */
318   template<class ITEM>
319   inline TupleColumn<ITEM*>
320   make_column ( const std::string& name ,       ITEM* item )
321   { return TupleColumn<ITEM*>      ( name , item ) ; }
322 
323   template<class ITEM>
324   inline TupleColumn<ITEM>
325   Column      ( const std::string& name , const ITEM& item )
326   { return make_column             ( name , item ) ; }
327 
328   template<class ITEM>
329   inline TupleColumn<const ITEM*>
330   Column      ( const std::string& name , const ITEM* item )
331   { return make_column             ( name , item ) ; }
332 
333   template<class ITEM>
334   inline TupleColumn<ITEM*>
335   Column      ( const std::string& name ,       ITEM* item )
336   { return make_column             ( name , item ) ; }
337 
338 } // end of the namespace Tuples
339 
340 // ============================================================================
341 /// helper operator to feed Tuple with the data, see Tuples::TupleColumn
342 // ============================================================================
343 template <class ITEM>
344 inline Tuples::Tuple& operator<<
345   ( Tuples::Tuple&                   tuple ,
346     const Tuples::TupleColumn<ITEM>& item )
347 {
348   if ( !tuple.valid() ) { return tuple  ; } // no action for invalid tuple
349   tuple->column( item.name() , item.value () ) ;
350   return tuple ;
351 }
352 // ============================================================================
353 
354 
355 
356 // ============================================================================
357 // THe END
358 // ============================================================================
359 #endif // GAUDIALG_TUPLE_H
360 // ============================================================================
361 

source navigation ] diff markup ] identifier search ] general search ]

Due to the LXR bug, the updates fail sometimes to remove references to deleted files. The Saturday's full rebuilds fix these problems
This page was automatically generated by the LXR engine. Valid HTML 4.01!