Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v38r0 (2143aa4c)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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;
303  StatusCode finalize() override;
304  // ==========================================================================
305 private:
306  // ==========================================================================
307  Gaudi::Property<bool> m_produceNTuples{ this, "NTupleProduce", true, "general switch to enable/disable N-tuples" };
308  Gaudi::Property<bool> m_tuplesPrint{ this, "NTuplePrint", true,
309  [this]( auto& ) {
310  // no action if not yet initialized
311  if ( this->FSMState() >= Gaudi::StateMachine::INITIALIZED &&
312  this->tuplesPrint() )
313  this->printTuples();
314  },
315  "print N-tuple statistics" };
316  Gaudi::Property<bool> m_splitNTupleDir{ this, "NTupleSplitDir", false,
317  "split long directory names into short pieces (suitable for HBOOK)" };
318  Gaudi::Property<TupleID::NumericID> m_nTupleOffSet{ this, "NTupleOffSet", 0, "offset for numerical N-tuple ID" };
319  Gaudi::Property<std::string> m_nTupleLUN{ this, "NTupleLUN", "FILE1", "Logical File Unit for N-tuples" };
320  Gaudi::Property<std::string> m_nTupleTopDir{ this, "NTupleTopDir", "", "top-level directory for N-Tuples" };
322  this, "NTupleDir", boost::algorithm::replace_all_copy( this->name(), ":", "_" ), "subdirectory for N-Tuples" };
323 
324  Gaudi::Property<bool> m_produceEvtCols{ this, "EvtColsProduce", false,
325  "general switch to enable/disable Event Tag Collections" };
326  Gaudi::Property<bool> m_evtColsPrint{ this, "EvtColsPrint", false,
327  [this]( auto& ) {
328  // no action if not yet initialized
329  if ( this->FSMState() >= Gaudi::StateMachine::INITIALIZED &&
330  this->evtColsPrint() )
331  this->printEvtCols();
332  },
333  "print statistics for Event Tag Collections " };
334  Gaudi::Property<bool> m_splitEvtColDir{ this, "EvtColSplitDir", false,
335  "split long directory names into short pieces" };
336  Gaudi::Property<TupleID::NumericID> m_evtColOffSet{ this, "EvtColOffSet", 0, "offset for numerical N-tuple ID" };
337  Gaudi::Property<std::string> m_evtColLUN{ this, "EvtColLUN", "EVTCOL",
338  "Logical File Unit for Event Tag Collections" };
339  Gaudi::Property<std::string> m_evtColTopDir{ this, "EvtColTopDir", "",
340  "Top-level directory for Event Tag Collections" };
341  Gaudi::Property<std::string> m_evtColDir{ this, "EvtColDir",
342  boost::algorithm::replace_all_copy( this->name(), ":", "_" ),
343  "Subdirectory for Event Tag Collections" };
344  struct nTupleMapItem final {
348  };
349  struct title_t {};
350  struct id_t {};
351  struct order_t {};
352  template <typename... Ts>
353  using indexed_by = boost::multi_index::indexed_by<Ts...>;
354  template <typename... Ts>
355  using hashed_unique = boost::multi_index::hashed_unique<Ts...>;
356  template <typename... Ts>
357  using ordered_unique = boost::multi_index::ordered_unique<Ts...>;
358  template <typename Obj, typename Type, Type Obj::*Member>
359  using member = boost::multi_index::member<Obj, Type, Member>;
360  template <typename T>
361  using tag = boost::multi_index::tag<T>;
362  using nTupleMap = boost::multi_index_container<
366 
367  // ==========================================================================
370 
371  decltype( auto ) nTupleByID() const { return m_nTupleMap.template get<id_t>(); }
372  decltype( auto ) nTupleByTitle() const { return m_nTupleMap.template get<title_t>(); }
373  decltype( auto ) nTupleOrdered() const { return m_nTupleMap.template get<order_t>(); }
374 
375  // ==========================================================================
378 
379  decltype( auto ) evtColByID() const { return m_evtColMap.template get<id_t>(); }
380  decltype( auto ) evtColByTitle() const { return m_evtColMap.template get<title_t>(); }
381  decltype( auto ) evtColOrdered() const { return m_evtColMap.template get<order_t>(); }
382 
383  // ==========================================================================
384 };
385 // ============================================================================
386 // The END
387 // ============================================================================
388 #endif // GAUDIALG_GAUDITUPLES_H
GaudiTuples::nTupleLUN
const std::string & nTupleLUN() const
get the logical unit for N-Tuples (property "NTupleLUN")
Definition: GaudiTuples.h:217
GaudiAlg.TupleUtils.nTuple
def nTuple(dirpath, ID, ID2=None, topdir=None, LUN="FILE1")
Definition: TupleUtils.py:84
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:351
GaudiAlg::ID
Definition: GaudiHistoID.h:53
bug_34121.name
name
Definition: bug_34121.py:20
GaudiTuples::nTupleMapItem
Definition: GaudiTuples.h:344
GaudiTuples< GaudiHistoAlg >::ordered_unique
boost::multi_index::ordered_unique< Ts... > ordered_unique
Definition: GaudiTuples.h:357
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:353
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:369
GaudiTuples::nTupleMapItem::tuple
std::shared_ptr< Tuples::TupleObj > tuple
Definition: GaudiTuples.h:347
GaudiHistoAlg.h
GaudiTuples::produceEvtCols
bool produceEvtCols() const
get the flag for Event Tag Collection production (property "EvtColsProduce")
Definition: GaudiTuples.h:227
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:355
GaudiTuples::nTupleMapItem::title
std::string title
Definition: GaudiTuples.h:345
GaudiTuples< GaudiHistoAlg >::tag
boost::multi_index::tag< T > tag
Definition: GaudiTuples.h:361
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:365
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:377
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:350
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:359
gaudirun.type
type
Definition: gaudirun.py:160
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:349
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:346