| The Gaudi Framework v32r1 (f65d50dc)

GaudiTuples.h
Go to the documentation of this file.
1 #ifndef GAUDIALG_GAUDITUPLES_H
2 #define GAUDIALG_GAUDITUPLES_H 1
3 // ============================================================================
4 /* @file GaudiTuples.h
5 *
6 * Header file for class : GaudiTuples
7 *
8 * @author Chris Jones Christopher.Rob.Jones@cern.ch
9 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
10 * @date 2005-08-08
11 */
12 // ============================================================================
13 // Include files
14 // ============================================================================
15 #include "boost/algorithm/string/replace.hpp"
16 #include <boost/multi_index/hashed_index.hpp>
17 #include <boost/multi_index/member.hpp>
18 #include <boost/multi_index/ordered_index.hpp>
19 #include <boost/multi_index_container.hpp>
20 // ============================================================================
21 // GaudiKernel
22 // ============================================================================
23 #include "GaudiKernel/ClassID.h"
24 // ============================================================================
25 // GaudiAlg
26 // ============================================================================
27 #include "GaudiAlg/GaudiHistoAlg.h"
28 #include "GaudiAlg/GaudiHistoTool.h"
29 #include "GaudiAlg/Maps.h"
30 #include "GaudiAlg/Tuple.h"
31 #include "GaudiAlg/TupleObj.h"
32 // ============================================================================
41 // ============================================================================
42 template <class PBASE>
43 class GAUDI_API GaudiTuples : public PBASE {
44 public:
45 // ==========================================================================
47 typedef GaudiAlg::HistoID HistoID;
49 typedef Tuples::Tuple Tuple;
51 typedef GaudiAlg::TupleID TupleID;
52 // ==========================================================================
53 public:
54 // ==========================================================================
86 Tuple nTuple( const std::string& title, const CLID& clid = CLID_ColumnWiseTuple ) const;
87
126 Tuple nTuple( const TupleID& ID, const std::string& title, const CLID& clid = CLID_ColumnWiseTuple ) const;
127
158 Tuple evtCol( const std::string& title, const CLID& clid = CLID_ColumnWiseTuple ) const;
159
198 Tuple evtCol( const TupleID& ID, const std::string& title, const CLID& clid = CLID_ColumnWiseTuple ) const;
199 // ==========================================================================
200 public: // trivial accessors
201 // ==========================================================================
203 bool produceNTuples() const { return m_produceNTuples; }
205 bool splitNTupleDir() const { return m_splitNTupleDir; }
207 const std::string& nTupleLUN() const { return m_nTupleLUN; }
209 const std::string& nTupleTopDir() const { return m_nTupleTopDir; }
211 const std::string& nTupleDir() const { return m_nTupleDir; }
213 TupleID::NumericID nTupleOffSet() const { return m_nTupleOffSet; }
215 std::string nTuplePath() const;
217 bool produceEvtCols() const { return m_produceEvtCols; }
219 bool splitEvtColDir() const { return m_splitEvtColDir; }
221 const std::string& evtColLUN() const { return m_evtColLUN; }
223 const std::string& evtColTopDir() const { return m_evtColTopDir; }
225 const std::string& evtColDir() const { return m_evtColDir; }
227 TupleID::NumericID evtColOffSet() const { return m_evtColOffSet; }
229 std::string evtColPath() const;
231 bool tuplesPrint() const { return m_tuplesPrint; }
233 bool evtColsPrint() const { return m_evtColsPrint; }
234 // ==========================================================================
235 public:
236 // ==========================================================================
240 long printTuples() const;
244 long printEvtCols() const;
245 // ==========================================================================
247 bool nTupleExists( const TupleID& ID ) const;
249 bool evtColExists( const TupleID& ID ) const;
250 // ==========================================================================
251 protected:
252 // ==========================================================================
260 virtual std::unique_ptr<Tuples::TupleObj> createNTuple( const std::string& name, NTuple::Tuple* tuple,
261 const CLID& clid ) const;
269 virtual std::unique_ptr<Tuples::TupleObj> createEvtCol( const std::string& name, NTuple::Tuple* tuple,
270 const CLID& clid ) const;
271 // ==========================================================================
272 public:
273 // ==========================================================================
276 template <typename U = PBASE, typename = std::enable_if_t<std::is_base_of_v<GaudiHistoAlg, PBASE>, U>>
277 GaudiTuples( const std::string& name, ISvcLocator* pSvcLocator ) : PBASE( name, pSvcLocator ) {}
280 template <typename U = PBASE, typename = std::enable_if_t<std::is_base_of_v<GaudiHistoTool, PBASE>, U>>
281 GaudiTuples( const std::string& type, const std::string& name, const IInterface* parent )
282 : PBASE( type, name, parent ) {}
283 // ==========================================================================
284 protected:
285 // ==========================================================================
289 StatusCode initialize() override
290 #ifdef __ICC
291 {
292 return i_gtInitialize();
293 }
294 StatusCode i_gtInitialize()
295 #endif
296 ;
300 StatusCode finalize() override
301 #ifdef __ICC
302 {
303 return i_gtFinalize();
304 }
305 StatusCode i_gtFinalize()
306 #endif
307 ;
308 // ==========================================================================
309 private:
310 // ==========================================================================
311 Gaudi::Property<bool> m_produceNTuples{this, "NTupleProduce", true, "general switch to enable/disable N-tuples"};
312 Gaudi::Property<bool> m_tuplesPrint{this, "NTuplePrint", true,
313 [this]( auto& ) {
314 // no action if not yet initialized
315 if ( this->FSMState() >= Gaudi::StateMachine::INITIALIZED &&
316 this->tuplesPrint() )
317 this->printTuples();
318 },
319 "print N-tuple statistics"};
320 Gaudi::Property<bool> m_splitNTupleDir{this, "NTupleSplitDir", false,
321 "split long directory names into short pieces (suitable for HBOOK)"};
322 Gaudi::Property<TupleID::NumericID> m_nTupleOffSet{this, "NTupleOffSet", 0, "offset for numerical N-tuple ID"};
323 Gaudi::Property<std::string> m_nTupleLUN{this, "NTupleLUN", "FILE1", "Logical File Unit for N-tuples"};
324 Gaudi::Property<std::string> m_nTupleTopDir{this, "NTupleTopDir", "", "top-level directory for N-Tuples"};
325 Gaudi::Property<std::string> m_nTupleDir{
326 this, "NTupleDir", boost::algorithm::replace_all_copy( this->name(), ":", "_" ), "subdirectory for N-Tuples"};
327
328 Gaudi::Property<bool> m_produceEvtCols{this, "EvtColsProduce", false,
329 "general switch to enable/disable Event Tag Collections"};
330 Gaudi::Property<bool> m_evtColsPrint{this, "EvtColsPrint", false,
331 [this]( auto& ) {
332 // no action if not yet initialized
333 if ( this->FSMState() >= Gaudi::StateMachine::INITIALIZED &&
334 this->evtColsPrint() )
335 this->printEvtCols();
336 },
337 "print statistics for Event Tag Collections "};
338 Gaudi::Property<bool> m_splitEvtColDir{this, "EvtColSplitDir", false, "split long directory names into short pieces"};
339 Gaudi::Property<TupleID::NumericID> m_evtColOffSet{this, "EvtColOffSet", 0, "offset for numerical N-tuple ID"};
340 Gaudi::Property<std::string> m_evtColLUN{this, "EvtColLUN", "EVTCOL", "Logical File Unit for Event Tag Collections"};
341 Gaudi::Property<std::string> m_evtColTopDir{this, "EvtColTopDir", "",
342 "Top-level directory for Event Tag Collections"};
343 Gaudi::Property<std::string> m_evtColDir{this, "EvtColDir",
344 boost::algorithm::replace_all_copy( this->name(), ":", "_" ),
345 "Subdirectory for Event Tag Collections"};
346 struct nTupleMapItem final {
347 std::string title;
348 TupleID id;
349 std::shared_ptr<Tuples::TupleObj> tuple;
350 };
351 struct title_t {};
352 struct id_t {};
353 struct order_t {};
354 template <typename... Ts>
355 using indexed_by = boost::multi_index::indexed_by<Ts...>;
356 template <typename... Ts>
357 using hashed_unique = boost::multi_index::hashed_unique<Ts...>;
358 template <typename... Ts>
359 using ordered_unique = boost::multi_index::ordered_unique<Ts...>;
360 template <typename Obj, typename Type, Type Obj::*Member>
361 using member = boost::multi_index::member<Obj, Type, Member>;
362 template <typename T>
363 using tag = boost::multi_index::tag<T>;
364 using nTupleMap = boost::multi_index_container<
365 nTupleMapItem, indexed_by<hashed_unique<tag<title_t>, member<nTupleMapItem, std::string, &nTupleMapItem::title>>,
366 hashed_unique<tag<id_t>, member<nTupleMapItem, TupleID, &nTupleMapItem::id>>,
367 ordered_unique<tag<order_t>, member<nTupleMapItem, TupleID, &nTupleMapItem::id>>>>;
368
369 // ==========================================================================
371 mutable nTupleMap m_nTupleMap;
372
373 decltype( auto ) nTupleByID() const { return m_nTupleMap.template get<id_t>(); }
374 decltype( auto ) nTupleByTitle() const { return m_nTupleMap.template get<title_t>(); }
375 decltype( auto ) nTupleOrdered() const { return m_nTupleMap.template get<order_t>(); }
376
377 // ==========================================================================
379 mutable nTupleMap m_evtColMap;
380
381 decltype( auto ) evtColByID() const { return m_evtColMap.template get<id_t>(); }
382 decltype( auto ) evtColByTitle() const { return m_evtColMap.template get<title_t>(); }
383 decltype( auto ) evtColOrdered() const { return m_evtColMap.template get<order_t>(); }
384
385 // ==========================================================================
386 };
387 // ============================================================================
388 // The END
389 // ============================================================================
390 #endif // GAUDIALG_GAUDITUPLES_H
GaudiTuples::title_t
Definition: GaudiTuples.h:351
GaudiTuples::m_evtColMap
nTupleMap m_evtColMap
the actual storage of event collections by title and ID
Definition: GaudiTuples.h:379
GaudiTuples::nTupleMapItem::title
std::string title
Definition: GaudiTuples.h:347
Gaudi::StateMachine::INITIALIZED
Definition: StateMachine.h:15
std::shared_ptr< Tuples::TupleObj >
ClassID.h
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
GaudiTuples::evtColOffSet
TupleID::NumericID evtColOffSet() const
get the value for Event Tag Collection offset (property "EvtColsOffSet")
Definition: GaudiTuples.h:227
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
GaudiTuples
Templated base class providing common 'ntupling' methods.
Definition: GaudiTuples.h:43
TupleObj.h
Header file for class TupleObj.
GaudiTuples::produceEvtCols
bool produceEvtCols() const
get the flag for Event Tag Collection production (property "EvtColsProduce")
Definition: GaudiTuples.h:217
GaudiTuples::evtColDir
const std::string & evtColDir() const
get the Event Tag Collection directory (property "EvtColsDir")
Definition: GaudiTuples.h:225
GaudiTuples::Tuple
Tuples::Tuple Tuple
the actual type of the tuple
Definition: GaudiTuples.h:49
GaudiTuples< GaudiHistoAlg >::indexed_by
boost::multi_index::indexed_by< Ts... > indexed_by
Definition: GaudiTuples.h:355
GaudiHistoTool.h
Header file for class : GaudiHistoTool.
GaudiTuples::order_t
Definition: GaudiTuples.h:353
GaudiAlg::ID::NumericID
int NumericID
type for internal numeric ID
Definition: GaudiHistoID.h:47
GaudiTuples::evtColLUN
const std::string & evtColLUN() const
get the logical unit for Event Tag Collections (property "EvtColsLUN")
Definition: GaudiTuples.h:221
GaudiTuples::produceNTuples
bool produceNTuples() const
get the flag for N-Tuple production (property "NTupleProduce")
Definition: GaudiTuples.h:203
GaudiTuples::splitNTupleDir
bool splitNTupleDir() const
get the flag for N-Tuple path split (property "NTupleSplitDir")
Definition: GaudiTuples.h:205
GaudiTuples::tuplesPrint
bool tuplesPrint() const
print tuples at finalization
Definition: GaudiTuples.h:231
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:281
GaudiTuples::nTupleMapItem
Definition: GaudiTuples.h:346
std::string
STL class.
GaudiTuples::nTupleMapItem::id
TupleID id
Definition: GaudiTuples.h:348
Tuples::Tuple
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: Tuple.h:116
GaudiTuples::nTupleOffSet
TupleID::NumericID nTupleOffSet() const
get the value for N-Tuple offset (property "NTupleOffSet")
Definition: GaudiTuples.h:213
GaudiTuples::TupleID
GaudiAlg::TupleID TupleID
the actual type of N-tuple ID
Definition: GaudiTuples.h:51
GaudiTuples< GaudiHistoAlg >::ordered_unique
boost::multi_index::ordered_unique< Ts... > ordered_unique
Definition: GaudiTuples.h:359
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
IInterface
Definition of the basic interface.
Definition: IInterface.h:244
gaudirun.type
type
Definition: gaudirun.py:142
GaudiTuples::HistoID
GaudiAlg::HistoID HistoID
the actual type for histogram identifier
Definition: GaudiTuples.h:47
Tuples::TupleID
GaudiAlg::ID TupleID
the actual type for N-Tuple identifier (HBOOK-style)
Definition: TupleID.h:22
GaudiTuples::nTupleTopDir
const std::string & nTupleTopDir() const
get the top-level N-Tuple directory (property "NTupleTopDir")
Definition: GaudiTuples.h:209
GaudiTuples< GaudiHistoAlg >::tag
boost::multi_index::tag< T > tag
Definition: GaudiTuples.h:363
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:277
GaudiTuples::m_nTupleMap
nTupleMap m_nTupleMap
the actual storage of ntuples by title and ID
Definition: GaudiTuples.h:371
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
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:367
GaudiTuples::id_t
Definition: GaudiTuples.h:352
NTuple::Tuple
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:375
Maps.h
GaudiTuples::evtColsPrint
bool evtColsPrint() const
print event collections at finalization
Definition: GaudiTuples.h:233
std::unique_ptr
STL class.
GaudiTuples< GaudiHistoAlg >::member
boost::multi_index::member< Obj, Type, Member > member
Definition: GaudiTuples.h:361
GaudiTuples::evtColTopDir
const std::string & evtColTopDir() const
get the top-level Event Tag Collection directory (property "EvtColsTopDir")
Definition: GaudiTuples.h:223
GaudiHistoAlg.h
GaudiTuples::nTupleMapItem::tuple
std::shared_ptr< Tuples::TupleObj > tuple
Definition: GaudiTuples.h:349
GaudiTuples::nTupleLUN
const std::string & nTupleLUN() const
get the logical unit for N-Tuples (property "NTupleLUN")
Definition: GaudiTuples.h:207
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:71
GaudiTuples::splitEvtColDir
bool splitEvtColDir() const
get the flag for Event Tag Collection path split (property "EvtColsSplitDir")
Definition: GaudiTuples.h:219
GaudiPython.TupleUtils.nTuple
def nTuple(dirpath, ID, ID2=None, topdir=None, LUN='FILE1')
Definition: TupleUtils.py:73
GaudiTuples::nTupleDir
const std::string & nTupleDir() const
get the N-Tuple directory (property "NTupleDir")
Definition: GaudiTuples.h:211
GaudiAlg::ID
ID class for Histogram and Ntuples.
Definition: GaudiHistoID.h:43
Tuple.h
Header file for class : Tuple.
GaudiTuples< GaudiHistoAlg >::hashed_unique
boost::multi_index::hashed_unique< Ts... > hashed_unique
Definition: GaudiTuples.h:357