The Gaudi Framework  v36r1 (3e2fb5a8)
GaudiTuples.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIALG_GAUDITUPLES_H
12 #define GAUDIALG_GAUDITUPLES_H 1
13 // ============================================================================
14 /* @file GaudiTuples.h
15  *
16  * Header file for class : GaudiTuples
17  *
18  * @author Chris Jones Christopher.Rob.Jones@cern.ch
19  * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
20  * @date 2005-08-08
21  */
22 // ============================================================================
23 // Include files
24 // ============================================================================
25 #include "boost/algorithm/string/replace.hpp"
26 #include <boost/multi_index/hashed_index.hpp>
27 #include <boost/multi_index/member.hpp>
28 #include <boost/multi_index/ordered_index.hpp>
29 #include <boost/multi_index_container.hpp>
30 // ============================================================================
31 // GaudiKernel
32 // ============================================================================
33 #include "GaudiKernel/ClassID.h"
34 // ============================================================================
35 // GaudiAlg
36 // ============================================================================
37 #include "GaudiAlg/GaudiHistoAlg.h"
39 #include "GaudiAlg/Maps.h"
40 #include "GaudiAlg/Tuple.h"
41 #include "GaudiAlg/TupleObj.h"
42 // ============================================================================
51 // ============================================================================
52 template <class PBASE>
53 class GAUDI_API GaudiTuples : public PBASE {
54 public:
55  // ==========================================================================
62  // ==========================================================================
63 public:
64  // ==========================================================================
96  Tuple nTuple( const std::string& title, const CLID& clid = CLID_ColumnWiseTuple ) const;
97 
136  Tuple nTuple( const TupleID& ID, const std::string& title, const CLID& clid = CLID_ColumnWiseTuple ) const;
137 
168  Tuple evtCol( const std::string& title, const CLID& clid = CLID_ColumnWiseTuple ) const;
169 
208  Tuple evtCol( const TupleID& ID, const std::string& title, const CLID& clid = CLID_ColumnWiseTuple ) const;
209  // ==========================================================================
210 public: // trivial accessors
211  // ==========================================================================
213  bool produceNTuples() const { return m_produceNTuples; }
215  bool splitNTupleDir() const { return m_splitNTupleDir; }
217  const std::string& nTupleLUN() const { return m_nTupleLUN; }
219  const std::string& nTupleTopDir() const { return m_nTupleTopDir; }
221  const std::string& nTupleDir() const { return m_nTupleDir; }
223  TupleID::NumericID nTupleOffSet() const { return m_nTupleOffSet; }
225  std::string nTuplePath() const;
227  bool produceEvtCols() const { return m_produceEvtCols; }
229  bool splitEvtColDir() const { return m_splitEvtColDir; }
231  const std::string& evtColLUN() const { return m_evtColLUN; }
233  const std::string& evtColTopDir() const { return m_evtColTopDir; }
235  const std::string& evtColDir() const { return m_evtColDir; }
237  TupleID::NumericID evtColOffSet() const { return m_evtColOffSet; }
239  std::string evtColPath() const;
241  bool tuplesPrint() const { return m_tuplesPrint; }
243  bool evtColsPrint() const { return m_evtColsPrint; }
244  // ==========================================================================
245 public:
246  // ==========================================================================
250  long printTuples() const;
254  long printEvtCols() const;
255  // ==========================================================================
257  bool nTupleExists( const TupleID& ID ) const;
259  bool evtColExists( const TupleID& ID ) const;
260  // ==========================================================================
261 protected:
262  // ==========================================================================
270  virtual std::unique_ptr<Tuples::TupleObj> createNTuple( const std::string& name, NTuple::Tuple* tuple,
271  const CLID& clid ) const;
279  virtual std::unique_ptr<Tuples::TupleObj> createEvtCol( const std::string& name, NTuple::Tuple* tuple,
280  const CLID& clid ) const;
281  // ==========================================================================
282 public:
283  // ==========================================================================
286  template <typename U = PBASE, typename = std::enable_if_t<std::is_base_of_v<GaudiHistoAlg, PBASE>, U>>
287  GaudiTuples( const std::string& name, ISvcLocator* pSvcLocator ) : PBASE( name, pSvcLocator ) {}
290  template <typename U = PBASE, typename = std::enable_if_t<std::is_base_of_v<GaudiHistoTool, PBASE>, U>>
291  GaudiTuples( const std::string& type, const std::string& name, const IInterface* parent )
292  : PBASE( type, name, parent ) {}
293  // ==========================================================================
294 protected:
295  // ==========================================================================
299  StatusCode initialize() override
300 #ifdef __ICC
301  {
302  return i_gtInitialize();
303  }
304  StatusCode i_gtInitialize()
305 #endif
306  ;
310  StatusCode finalize() override
311 #ifdef __ICC
312  {
313  return i_gtFinalize();
314  }
315  StatusCode i_gtFinalize()
316 #endif
317  ;
318  // ==========================================================================
319 private:
320  // ==========================================================================
321  Gaudi::Property<bool> m_produceNTuples{this, "NTupleProduce", true, "general switch to enable/disable N-tuples"};
322  Gaudi::Property<bool> m_tuplesPrint{this, "NTuplePrint", true,
323  [this]( auto& ) {
324  // no action if not yet initialized
325  if ( this->FSMState() >= Gaudi::StateMachine::INITIALIZED &&
326  this->tuplesPrint() )
327  this->printTuples();
328  },
329  "print N-tuple statistics"};
330  Gaudi::Property<bool> m_splitNTupleDir{this, "NTupleSplitDir", false,
331  "split long directory names into short pieces (suitable for HBOOK)"};
332  Gaudi::Property<TupleID::NumericID> m_nTupleOffSet{this, "NTupleOffSet", 0, "offset for numerical N-tuple ID"};
333  Gaudi::Property<std::string> m_nTupleLUN{this, "NTupleLUN", "FILE1", "Logical File Unit for N-tuples"};
334  Gaudi::Property<std::string> m_nTupleTopDir{this, "NTupleTopDir", "", "top-level directory for N-Tuples"};
336  this, "NTupleDir", boost::algorithm::replace_all_copy( this->name(), ":", "_" ), "subdirectory for N-Tuples"};
337 
338  Gaudi::Property<bool> m_produceEvtCols{this, "EvtColsProduce", false,
339  "general switch to enable/disable Event Tag Collections"};
340  Gaudi::Property<bool> m_evtColsPrint{this, "EvtColsPrint", false,
341  [this]( auto& ) {
342  // no action if not yet initialized
343  if ( this->FSMState() >= Gaudi::StateMachine::INITIALIZED &&
344  this->evtColsPrint() )
345  this->printEvtCols();
346  },
347  "print statistics for Event Tag Collections "};
348  Gaudi::Property<bool> m_splitEvtColDir{this, "EvtColSplitDir", false, "split long directory names into short pieces"};
349  Gaudi::Property<TupleID::NumericID> m_evtColOffSet{this, "EvtColOffSet", 0, "offset for numerical N-tuple ID"};
350  Gaudi::Property<std::string> m_evtColLUN{this, "EvtColLUN", "EVTCOL", "Logical File Unit for Event Tag Collections"};
351  Gaudi::Property<std::string> m_evtColTopDir{this, "EvtColTopDir", "",
352  "Top-level directory for Event Tag Collections"};
353  Gaudi::Property<std::string> m_evtColDir{this, "EvtColDir",
354  boost::algorithm::replace_all_copy( this->name(), ":", "_" ),
355  "Subdirectory for Event Tag Collections"};
356  struct nTupleMapItem final {
360  };
361  struct title_t {};
362  struct id_t {};
363  struct order_t {};
364  template <typename... Ts>
365  using indexed_by = boost::multi_index::indexed_by<Ts...>;
366  template <typename... Ts>
367  using hashed_unique = boost::multi_index::hashed_unique<Ts...>;
368  template <typename... Ts>
369  using ordered_unique = boost::multi_index::ordered_unique<Ts...>;
370  template <typename Obj, typename Type, Type Obj::*Member>
371  using member = boost::multi_index::member<Obj, Type, Member>;
372  template <typename T>
373  using tag = boost::multi_index::tag<T>;
374  using nTupleMap = boost::multi_index_container<
378 
379  // ==========================================================================
382 
383  decltype( auto ) nTupleByID() const { return m_nTupleMap.template get<id_t>(); }
384  decltype( auto ) nTupleByTitle() const { return m_nTupleMap.template get<title_t>(); }
385  decltype( auto ) nTupleOrdered() const { return m_nTupleMap.template get<order_t>(); }
386 
387  // ==========================================================================
390 
391  decltype( auto ) evtColByID() const { return m_evtColMap.template get<id_t>(); }
392  decltype( auto ) evtColByTitle() const { return m_evtColMap.template get<title_t>(); }
393  decltype( auto ) evtColOrdered() const { return m_evtColMap.template get<order_t>(); }
394 
395  // ==========================================================================
396 };
397 // ============================================================================
398 // The END
399 // ============================================================================
400 #endif // GAUDIALG_GAUDITUPLES_H
GaudiTuples::nTupleLUN
const std::string & nTupleLUN() const
get the logical unit for N-Tuples (property "NTupleLUN")
Definition: GaudiTuples.h:217
GaudiTuples::GaudiTuples
GaudiTuples(const std::string &type, const std::string &name, const IInterface *parent)
Tool constructor - SFINAE-ed to insure this constructor is only defined if PBASE derives from AlgTool...
Definition: GaudiTuples.h:291
GaudiTuples::nTupleDir
const std::string & nTupleDir() const
get the N-Tuple directory (property "NTupleDir")
Definition: GaudiTuples.h:221
Tuple.h
std::string
STL class.
std::shared_ptr< Tuples::TupleObj >
GaudiTuples::order_t
Definition: GaudiTuples.h:363
GaudiAlg::ID
Definition: GaudiHistoID.h:53
GaudiTuples::nTupleMapItem
Definition: GaudiTuples.h:356
GaudiTuples< GaudiHistoAlg >::ordered_unique
boost::multi_index::ordered_unique< Ts... > ordered_unique
Definition: GaudiTuples.h:369
GaudiTuples::TupleID
GaudiAlg::TupleID TupleID
the actual type of N-tuple ID
Definition: GaudiTuples.h:61
ClassID.h
ISvcLocator
Definition: ISvcLocator.h:46
GaudiHistoTool.h
GaudiTuples< GaudiHistoAlg >::indexed_by
boost::multi_index::indexed_by< Ts... > indexed_by
Definition: GaudiTuples.h:365
GaudiTuples::evtColDir
const std::string & evtColDir() const
get the Event Tag Collection directory (property "EvtColsDir")
Definition: GaudiTuples.h:235
GaudiTuples::GaudiTuples
GaudiTuples(const std::string &name, ISvcLocator *pSvcLocator)
Algorithm constructor - the SFINAE constraint below ensures that this is constructor is only defined ...
Definition: GaudiTuples.h:287
GaudiTuples::m_nTupleMap
nTupleMap m_nTupleMap
the actual storage of ntuples by title and ID
Definition: GaudiTuples.h:381
GaudiTuples::nTupleMapItem::tuple
std::shared_ptr< Tuples::TupleObj > tuple
Definition: GaudiTuples.h:359
GaudiHistoAlg.h
GaudiTuples::produceEvtCols
bool produceEvtCols() const
get the flag for Event Tag Collection production (property "EvtColsProduce")
Definition: GaudiTuples.h:227
TimingHistograms.name
name
Definition: TimingHistograms.py:23
StatusCode
Definition: StatusCode.h:65
GaudiTuples::HistoID
GaudiAlg::HistoID HistoID
the actual type for histogram identifier
Definition: GaudiTuples.h:57
GaudiTuples< GaudiHistoAlg >::hashed_unique
boost::multi_index::hashed_unique< Ts... > hashed_unique
Definition: GaudiTuples.h:367
GaudiTuples::nTupleMapItem::title
std::string title
Definition: GaudiTuples.h:357
GaudiTuples< GaudiHistoAlg >::tag
boost::multi_index::tag< T > tag
Definition: GaudiTuples.h:373
TupleObj.h
GaudiTuples< GaudiHistoAlg >::nTupleMap
boost::multi_index_container< nTupleMapItem, indexed_by< hashed_unique< tag< title_t >, member< nTupleMapItem, std::string, &nTupleMapItem::title > >, hashed_unique< tag< id_t >, member< nTupleMapItem, TupleID, &nTupleMapItem::id > >, ordered_unique< tag< order_t >, member< nTupleMapItem, TupleID, &nTupleMapItem::id > >> > nTupleMap
Definition: GaudiTuples.h:377
Tuples::Tuple
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: Tuple.h:126
GaudiTuples::m_evtColMap
nTupleMap m_evtColMap
the actual storage of event collections by title and ID
Definition: GaudiTuples.h:389
GaudiTuples::produceNTuples
bool produceNTuples() const
get the flag for N-Tuple production (property "NTupleProduce")
Definition: GaudiTuples.h:213
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
GaudiTuples::id_t
Definition: GaudiTuples.h:362
Tuples::TupleID
GaudiAlg::ID TupleID
the actual type for N-Tuple identifier (HBOOK-style)
Definition: TupleID.h:32
GaudiTuples< GaudiHistoAlg >::member
boost::multi_index::member< Obj, Type, Member > member
Definition: GaudiTuples.h:371
GaudiPython.TupleUtils.nTuple
def nTuple(dirpath, ID, ID2=None, topdir=None, LUN='FILE1')
Definition: TupleUtils.py:84
gaudirun.type
type
Definition: gaudirun.py:154
GaudiTuples::nTupleOffSet
TupleID::NumericID nTupleOffSet() const
get the value for N-Tuple offset (property "NTupleOffSet")
Definition: GaudiTuples.h:223
Maps.h
GaudiAlg::ID::NumericID
int NumericID
type for internal numeric ID
Definition: GaudiHistoID.h:57
NTuple::Tuple
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:387
GaudiTuples::evtColLUN
const std::string & evtColLUN() const
get the logical unit for Event Tag Collections (property "EvtColsLUN")
Definition: GaudiTuples.h:231
Gaudi::StateMachine::INITIALIZED
@ INITIALIZED
Definition: StateMachine.h:25
GaudiTuples::evtColsPrint
bool evtColsPrint() const
print event collections at finalization
Definition: GaudiTuples.h:243
IInterface
Definition: IInterface.h:237
GaudiTuples::evtColOffSet
TupleID::NumericID evtColOffSet() const
get the value for Event Tag Collection offset (property "EvtColsOffSet")
Definition: GaudiTuples.h:237
GaudiTuples
Definition: GaudiTuples.h:53
GaudiTuples::splitEvtColDir
bool splitEvtColDir() const
get the flag for Event Tag Collection path split (property "EvtColsSplitDir")
Definition: GaudiTuples.h:229
GaudiTuples::title_t
Definition: GaudiTuples.h:361
GaudiTuples::Tuple
Tuples::Tuple Tuple
the actual type of the tuple
Definition: GaudiTuples.h:59
GaudiTuples::evtColTopDir
const std::string & evtColTopDir() const
get the top-level Event Tag Collection directory (property "EvtColsTopDir")
Definition: GaudiTuples.h:233
std::unique_ptr
STL class.
GaudiTuples::nTupleTopDir
const std::string & nTupleTopDir() const
get the top-level N-Tuple directory (property "NTupleTopDir")
Definition: GaudiTuples.h:219
GaudiTuples::tuplesPrint
bool tuplesPrint() const
print tuples at finalization
Definition: GaudiTuples.h:241
GaudiTuples::splitNTupleDir
bool splitNTupleDir() const
get the flag for N-Tuple path split (property "NTupleSplitDir")
Definition: GaudiTuples.h:215
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
Gaudi::Property< bool >
GaudiTuples::nTupleMapItem::id
TupleID id
Definition: GaudiTuples.h:358