The Gaudi Framework  v38r1p1 (ae26267b)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GaudiTuples< PBASE > Class Template Reference

#include <GaudiAlg/GaudiTuples.h>

Inheritance diagram for GaudiTuples< PBASE >:
Collaboration diagram for GaudiTuples< PBASE >:

Classes

struct  id_t
 
struct  nTupleMapItem
 
struct  order_t
 
struct  title_t
 

Public Types

typedef GaudiAlg::HistoID HistoID
 the actual type for histogram identifier More...
 
typedef Tuples::Tuple Tuple
 the actual type of the tuple More...
 
typedef GaudiAlg::TupleID TupleID
 the actual type of N-tuple ID More...
 

Public Member Functions

Tuple nTuple (const std::string &title, const CLID &clid=CLID_ColumnWiseTuple) const
 Access an N-Tuple object (book on-demand) with unique identifier. More...
 
Tuple nTuple (const TupleID &ID, const std::string &title, const CLID &clid=CLID_ColumnWiseTuple) const
 Access an N-Tuple object (book on-demand) with forced identifier. More...
 
Tuple evtCol (const std::string &title, const CLID &clid=CLID_ColumnWiseTuple) const
 Access an Event Tag Collection object (book on-demand) with unique identifier. More...
 
Tuple evtCol (const TupleID &ID, const std::string &title, const CLID &clid=CLID_ColumnWiseTuple) const
 Access an Event Tag Collection object (book on-demand) with forced identifier. More...
 
bool produceNTuples () const
 get the flag for N-Tuple production (property "NTupleProduce") More...
 
bool splitNTupleDir () const
 get the flag for N-Tuple path split (property "NTupleSplitDir") More...
 
const std::stringnTupleLUN () const
 get the logical unit for N-Tuples (property "NTupleLUN") More...
 
const std::stringnTupleTopDir () const
 get the top-level N-Tuple directory (property "NTupleTopDir") More...
 
const std::stringnTupleDir () const
 get the N-Tuple directory (property "NTupleDir") More...
 
TupleID::NumericID nTupleOffSet () const
 get the value for N-Tuple offset (property "NTupleOffSet") More...
 
std::string nTuplePath () const
 get the constructed N-Tuple path More...
 
bool produceEvtCols () const
 get the flag for Event Tag Collection production (property "EvtColsProduce") More...
 
bool splitEvtColDir () const
 get the flag for Event Tag Collection path split (property "EvtColsSplitDir") More...
 
const std::stringevtColLUN () const
 get the logical unit for Event Tag Collections (property "EvtColsLUN") More...
 
const std::stringevtColTopDir () const
 get the top-level Event Tag Collection directory (property "EvtColsTopDir") More...
 
const std::stringevtColDir () const
 get the Event Tag Collection directory (property "EvtColsDir") More...
 
TupleID::NumericID evtColOffSet () const
 get the value for Event Tag Collection offset (property "EvtColsOffSet") More...
 
std::string evtColPath () const
 get the constructed Event Tag Collection path More...
 
bool tuplesPrint () const
 print tuples at finalization More...
 
bool evtColsPrint () const
 print event collections at finalization More...
 
long printTuples () const
 perform the actual printout of N-tuples More...
 
long printEvtCols () const
 perform the actual printout of Event Tag Collections More...
 
bool nTupleExists (const TupleID &ID) const
 check the existence AND validity of the N-Tuple with the given ID More...
 
bool evtColExists (const TupleID &ID) const
 check the existence AND validity of the Event Tag Collection with the given ID More...
 
template<typename U = PBASE, typename = std::enable_if_t<std::is_base_of_v<GaudiHistoAlg, PBASE>, U>>
 GaudiTuples (const std::string &name, ISvcLocator *pSvcLocator)
 Algorithm constructor - the SFINAE constraint below ensures that this is constructor is only defined if PBASE derives from GaudiHistoAlg. More...
 
template<typename U = PBASE, typename = std::enable_if_t<std::is_base_of_v<GaudiHistoTool, PBASE>, U>>
 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. More...
 

Protected Member Functions

virtual std::unique_ptr< Tuples::TupleObjcreateNTuple (const std::string &name, NTuple::Tuple *tuple, const CLID &clid) const
 create TupleObj More...
 
virtual std::unique_ptr< Tuples::TupleObjcreateEvtCol (const std::string &name, NTuple::Tuple *tuple, const CLID &clid) const
 create TupleObj for event tag collection More...
 
StatusCode initialize () override
 standard initialization method More...
 
StatusCode finalize () override
 standard finalization method More...
 

Private Types

template<typename... Ts>
using indexed_by = boost::multi_index::indexed_by< Ts... >
 
template<typename... Ts>
using hashed_unique = boost::multi_index::hashed_unique< Ts... >
 
template<typename... Ts>
using ordered_unique = boost::multi_index::ordered_unique< Ts... >
 
template<typename Obj , typename Type , Type Obj::* Member>
using member = boost::multi_index::member< Obj, Type, Member >
 
template<typename T >
using tag = boost::multi_index::tag< T >
 
using 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 > >> >
 

Private Attributes

Gaudi::Property< bool > m_produceNTuples { this, "NTupleProduce", true, "general switch to enable/disable N-tuples" }
 
Gaudi::Property< bool > m_tuplesPrint
 
Gaudi::Property< bool > m_splitNTupleDir
 
Gaudi::Property< TupleID::NumericIDm_nTupleOffSet { this, "NTupleOffSet", 0, "offset for numerical N-tuple ID" }
 
Gaudi::Property< std::stringm_nTupleLUN { this, "NTupleLUN", "FILE1", "Logical File Unit for N-tuples" }
 
Gaudi::Property< std::stringm_nTupleTopDir { this, "NTupleTopDir", "", "top-level directory for N-Tuples" }
 
Gaudi::Property< std::stringm_nTupleDir
 
Gaudi::Property< bool > m_produceEvtCols
 
Gaudi::Property< bool > m_evtColsPrint
 
Gaudi::Property< bool > m_splitEvtColDir
 
Gaudi::Property< TupleID::NumericIDm_evtColOffSet { this, "EvtColOffSet", 0, "offset for numerical N-tuple ID" }
 
Gaudi::Property< std::stringm_evtColLUN
 
Gaudi::Property< std::stringm_evtColTopDir
 
Gaudi::Property< std::stringm_evtColDir
 
nTupleMap m_nTupleMap
 the actual storage of ntuples by title and ID More...
 
nTupleMap m_evtColMap
 the actual storage of event collections by title and ID More...
 

Detailed Description

template<class PBASE>
class GaudiTuples< PBASE >

Templated base class providing common 'ntupling' methods

Author
Chris Jones Chris.nosp@m.toph.nosp@m.er.Ro.nosp@m.b.Jo.nosp@m.nes@c.nosp@m.ern..nosp@m.ch
Vanya BELYAEV Ivan..nosp@m.Bely.nosp@m.aev@i.nosp@m.tep..nosp@m.ru
Date
2005-08-08

Definition at line 53 of file GaudiTuples.h.

Member Typedef Documentation

◆ hashed_unique

template<class PBASE >
template<typename... Ts>
using GaudiTuples< PBASE >::hashed_unique = boost::multi_index::hashed_unique<Ts...>
private

Definition at line 355 of file GaudiTuples.h.

◆ HistoID

template<class PBASE >
typedef GaudiAlg::HistoID GaudiTuples< PBASE >::HistoID

the actual type for histogram identifier

Definition at line 57 of file GaudiTuples.h.

◆ indexed_by

template<class PBASE >
template<typename... Ts>
using GaudiTuples< PBASE >::indexed_by = boost::multi_index::indexed_by<Ts...>
private

Definition at line 353 of file GaudiTuples.h.

◆ member

template<class PBASE >
template<typename Obj , typename Type , Type Obj::* Member>
using GaudiTuples< PBASE >::member = boost::multi_index::member<Obj, Type, Member>
private

Definition at line 359 of file GaudiTuples.h.

◆ nTupleMap

◆ ordered_unique

template<class PBASE >
template<typename... Ts>
using GaudiTuples< PBASE >::ordered_unique = boost::multi_index::ordered_unique<Ts...>
private

Definition at line 357 of file GaudiTuples.h.

◆ tag

template<class PBASE >
template<typename T >
using GaudiTuples< PBASE >::tag = boost::multi_index::tag<T>
private

Definition at line 361 of file GaudiTuples.h.

◆ Tuple

template<class PBASE >
typedef Tuples::Tuple GaudiTuples< PBASE >::Tuple

the actual type of the tuple

Definition at line 59 of file GaudiTuples.h.

◆ TupleID

template<class PBASE >
typedef GaudiAlg::TupleID GaudiTuples< PBASE >::TupleID

the actual type of N-tuple ID

Definition at line 61 of file GaudiTuples.h.

Constructor & Destructor Documentation

◆ GaudiTuples() [1/2]

template<class PBASE >
template<typename U = PBASE, typename = std::enable_if_t<std::is_base_of_v<GaudiHistoAlg, PBASE>, U>>
GaudiTuples< PBASE >::GaudiTuples ( const std::string name,
ISvcLocator pSvcLocator 
)
inline

Algorithm constructor - the SFINAE constraint below ensures that this is constructor is only defined if PBASE derives from GaudiHistoAlg.

Definition at line 287 of file GaudiTuples.h.

287 : PBASE( name, pSvcLocator ) {}

◆ GaudiTuples() [2/2]

template<class PBASE >
template<typename U = PBASE, typename = std::enable_if_t<std::is_base_of_v<GaudiHistoTool, PBASE>, U>>
GaudiTuples< PBASE >::GaudiTuples ( const std::string type,
const std::string name,
const IInterface parent 
)
inline

Tool constructor - SFINAE-ed to insure this constructor is only defined if PBASE derives from AlgTool.

Definition at line 291 of file GaudiTuples.h.

292  : PBASE( type, name, parent ) {}

Member Function Documentation

◆ createEvtCol()

template<class PBASE >
std::unique_ptr< Tuples::TupleObj > GaudiTuples< PBASE >::createEvtCol ( const std::string name,
NTuple::Tuple tuple,
const CLID clid 
) const
protectedvirtual

create TupleObj for event tag collection

Attention
The method should never used directly by users
Parameters
namename/title
tuplethe underlying ntuple implementation
clidunique classID for ntuple
Returns
pointer to newly created TupelObj

Definition at line 275 of file GaudiTuples.icpp.

276  {
277  return Tuples::createTupleObj( this, "EvtCol '" + name + "'", tuple, clid, Tuples::EVTCOL );
278 }

◆ createNTuple()

template<class PBASE >
std::unique_ptr< Tuples::TupleObj > GaudiTuples< PBASE >::createNTuple ( const std::string name,
NTuple::Tuple tuple,
const CLID clid 
) const
protectedvirtual

create TupleObj

Attention
The method should never used directly by users
Parameters
namename/title
tuplethe underlying ntuple implementation
clidunique classID for ntuple
Returns
pointer to newly created TupleObj

Definition at line 265 of file GaudiTuples.icpp.

266  {
267  return Tuples::createTupleObj( this, "Tuple '" + name + "'", tuple, clid, Tuples::NTUPLE );
268 }

◆ evtCol() [1/2]

template<class PBASE >
Tuples::Tuple GaudiTuples< PBASE >::evtCol ( const std::string title,
const CLID clid = CLID_ColumnWiseTuple 
) const

Access an Event Tag Collection object (book on-demand) with unique identifier.

Tuple tuple = evtCol( "My Tag Collection" ) ;
tuple->column( "A" , sin(0.1) );
tuple->column( "B" , cos(0.1) );
tuple->column( "C" , tan(0.1) );
tuple->write();

The Event Tag Collection will get a unique identifier automatically assigned which by default will be equal to the histogram title. An option exists to instead use numerical IDs. In this case the first Event Tag Collection booked will be ID=1 the next ID=2 and so on. Note though this scheme is not recommended as it does NOT guarantee predictability of the ID a given Event Tag Collection will be given when filled under conditional statements, since in these circumstances the order in which the Event Tag Collection are first filled, and thus booked, will depend on the nature of the first few events read. This is particularly problematic when users submit many parallel 'sub-jobs' and then attempt to merge the final output ROOT (or HBOOK) files, since a given Event Tag Collection could have different IDs in each of the sub-jobs. Consequently it is strongly recommended that users do not use numerical automatic IDs unless they are sure they understand what they are doing.

Parameters
titleUnique title for Event Tag Collection
clidN-Tuple class identifier (row or column wise)
Returns
ntuple The Event Tag Collection object

Definition at line 134 of file GaudiTuples.icpp.

134  {
135  // look up in the table
136  auto& m = evtColByTitle();
137  auto tuple = m.find( title );
138  if ( tuple != m.end() ) return Tuple( tuple->tuple ); // RETURN
139  // Create the tuple ID
140  TupleID ID;
141  if ( this->useNumericAutoIDs() || title.empty() ) {
142  if ( !this->useNumericAutoIDs() ) {
143  this->Warning(
144  "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for evtCol ID",
146  .ignore();
147  }
148  // proposed the tuple ID
149  ID = TupleID( m_evtColMap.size() + 1 + evtColOffSet() );
150  // adjust the proposed ID
151  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.numeric() + 1 ); }
152  } else {
153  // use the title to create a unique literal ID
154  ID = TupleID( this->convertTitleToID( title ) );
155  // Just in case ...
156  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.idAsString() + "_" ); }
157  }
158  // return
159  return evtCol( ID, title, clid );
160 }

◆ evtCol() [2/2]

template<class PBASE >
Tuples::Tuple GaudiTuples< PBASE >::evtCol ( const TupleID ID,
const std::string title,
const CLID clid = CLID_ColumnWiseTuple 
) const

Access an Event Tag Collection object (book on-demand) with forced identifier.

// Book Ntuple with a numeric ID
Tuple tuple = evtCol( 1, "My Tag Collection" ) ;
// ... or
Tuple tuple = evtCol( "1", "My Tag Collection" ) ;
// ... or, Book Ntuple with a literal ID
Tuple tuple = evtCol( "mytuple", "My Tag Collection" ) ;
// ... or, Book Ntuple with a literal ID in a sub-dir
Tuple tuple = evtCol( "subdir/mytuple", "My Tag Collection" ) ;
// Fill and write
tuple->column( "A" , sin(0.1) );
tuple->column( "B" , cos(0.1) );
tuple->column( "C" , tan(0.1) );
tuple->write();
Attention
If the Event Tag Collection with given ID is already booked through automatic assignment of Event Tag Collection ID, the error will not be detected. Therefore it is recommended to use a non-trivial Event Tag Collection ID offset (property "EvtColOffSet") if one need to combine these techniques together It is still desirable to use the unique Event Tag Collection title to avoid a bad interference.
Parameters
IDThe forced Event Tag Collection ID
titleUnique title for Event Tag Collection
clidN-Tuple class identifier (row or column wise)
Returns
ntuple The Event Tag Collection object

Definition at line 216 of file GaudiTuples.icpp.

216  {
217  // Check ID
218  if ( ID.undefined() ) {
219  this->Error( "Undefined NTuple ID : Title='" + title1 + "'" ).ignore();
220  return Tuple( 0 );
221  }
222 
223  // look up in the table
224  auto& tuple = evtColByID();
225  auto i = tuple.find( ID );
226  if ( i != tuple.end() ) return Tuple( i->tuple ); // RETURN
227 
228  // convert ID to the string
229  const std::string tID = ID.idAsString();
230 
231  // adjust the NTuple title
232  const std::string title = title1.empty() ? ( "EvtCol #" + tID ) : title1;
233 
234  // book new ntuple
235  if ( !produceEvtCols() ) {
236  auto r = m_evtColMap.insert( nTupleMapItem{ title, ID, createEvtCol( title, nullptr, clid ) } );
237  if ( !r.second ) this->Error( "Failure to createEvtCol" ).ignore();
238  return Tuple( r.first->tuple );
239  }
240  // book NTuple
241  NTuple::Tuple* tup = nullptr;
242  if ( ID.numeric() ) {
243  tup = this->evtColSvc()->book( evtColPath(), ID.numericID(), clid, title );
244  } else if ( ID.literal() ) {
245  tup = this->evtColSvc()->book( evtColPath(), ID.literalID(), clid, title );
246  } else {
247  this->Error( "Undefined NTuple ID" ).ignore();
248  }
249 
250  // assertion
251  this->Assert( tup, "Could not book the EvtCol='" + title + "'" );
252  // some printout
253  if ( tup->registry() && this->msgLevel( MSG::DEBUG ) ) {
254  this->debug() << "Booked EvtCol '" << title << "' ID=" << tID << "' Path='" << evtColPath() << "' TS='"
255  << tup->registry()->identifier() << "'" << endmsg;
256  }
257  auto r = m_evtColMap.insert( nTupleMapItem{ title, ID, createEvtCol( title, tup, clid ) } );
258  if ( !r.second ) this->Error( "Failure to createEvtCol" ).ignore();
259  return Tuple( r.first->tuple );
260 }

◆ evtColDir()

template<class PBASE >
const std::string& GaudiTuples< PBASE >::evtColDir ( ) const
inline

get the Event Tag Collection directory (property "EvtColsDir")

Definition at line 235 of file GaudiTuples.h.

235 { return m_evtColDir; }

◆ evtColExists()

template<class PBASE >
bool GaudiTuples< PBASE >::evtColExists ( const TupleID ID) const

check the existence AND validity of the Event Tag Collection with the given ID

Definition at line 336 of file GaudiTuples.icpp.

336  {
337  auto& m = evtColByID();
338  return m.find( ID ) != m.end();
339 }

◆ evtColLUN()

template<class PBASE >
const std::string& GaudiTuples< PBASE >::evtColLUN ( ) const
inline

get the logical unit for Event Tag Collections (property "EvtColsLUN")

Definition at line 231 of file GaudiTuples.h.

231 { return m_evtColLUN; }

◆ evtColOffSet()

template<class PBASE >
TupleID::NumericID GaudiTuples< PBASE >::evtColOffSet ( ) const
inline

get the value for Event Tag Collection offset (property "EvtColsOffSet")

Definition at line 237 of file GaudiTuples.h.

237 { return m_evtColOffSet; }

◆ evtColPath()

template<class PBASE >
std::string GaudiTuples< PBASE >::evtColPath

get the constructed Event Tag Collection path

Definition at line 352 of file GaudiTuples.icpp.

352  {
353  std::string path = evtColLUN() + "/" + evtColTopDir() + evtColDir();
354  return splitEvtColDir() ? dirHbookName( path ) : path;
355 }

◆ evtColsPrint()

template<class PBASE >
bool GaudiTuples< PBASE >::evtColsPrint ( ) const
inline

print event collections at finalization

Definition at line 243 of file GaudiTuples.h.

243 { return m_evtColsPrint; }

◆ evtColTopDir()

template<class PBASE >
const std::string& GaudiTuples< PBASE >::evtColTopDir ( ) const
inline

get the top-level Event Tag Collection directory (property "EvtColsTopDir")

Definition at line 233 of file GaudiTuples.h.

233 { return m_evtColTopDir; }

◆ finalize()

template<class PBASE >
StatusCode GaudiTuples< PBASE >::finalize
overrideprotected

standard finalization method

Returns
status code

Definition at line 77 of file GaudiTuples.icpp.

77  {
78  if ( !( m_nTupleMap.empty() && m_evtColMap.empty() ) ) {
79  const int nNtuples = m_nTupleMap.size();
80  const int nEvtCols = m_evtColMap.size();
81  this->always() << "Booked " << nNtuples << " N-Tuples and " << nEvtCols << " Event Tag Collections" << endmsg;
82  }
83 
84  if ( produceNTuples() && tuplesPrint() ) printTuples();
86 
87  // release ntuples and clear the container
88  m_nTupleMap.clear();
89 
90  // release ntuples and clear the container
91  m_evtColMap.clear();
92 
93  // finalize base class
94  return PBASE::finalize();
95 }

◆ initialize()

template<class PBASE >
StatusCode GaudiTuples< PBASE >::initialize
overrideprotected

standard initialization method

Returns
status code

Definition at line 47 of file GaudiTuples.icpp.

47  {
48  // initialize base class
49  const StatusCode sc = PBASE::initialize();
50  if ( sc.isFailure() ) return sc;
51 
52  if ( produceNTuples() ) {
53  // check the existance of service
54  if ( this->ntupleSvc() == 0 ) { return this->Error( "INTupleSvc* points to NULL!" ); }
55  // Print ntuple path
56  this->Print( "The N-Tuple path is set to be '" + nTuplePath() + "'", StatusCode::SUCCESS, MSG::DEBUG ).ignore();
57  } else {
58  this->debug() << "Production of N-Tuples is switched OFF" << endmsg;
59  }
60 
61  if ( produceEvtCols() ) {
62  // check the existance of service
63  if ( 0 == this->evtColSvc() ) { return this->Error( "INTupleSvc* points to NULL!" ); }
64  // Print EvtCol path
65  this->Print( "The EventCol path is set to be '" + evtColPath() + "'", StatusCode::SUCCESS, MSG::DEBUG ).ignore();
66  } else {
67  this->debug() << "Production of Event Collections is switched OFF" << endmsg;
68  }
69 
70  return sc;
71 }

◆ nTuple() [1/2]

template<class PBASE >
Tuples::Tuple GaudiTuples< PBASE >::nTuple ( const std::string title,
const CLID clid = CLID_ColumnWiseTuple 
) const

Access an N-Tuple object (book on-demand) with unique identifier.

Tuple tuple = nTuple( "My N-Tuple" ) ;
tuple->column( "A" , sin(0.1) );
tuple->column( "B" , cos(0.1) );
tuple->column( "C" , tan(0.1) );
tuple->write();
Attention
The NTuple will get a unique identifier automatically assigned which by default will be equal to the histogram title. An option exists to instead use numerical IDs. In this case the first NTuple booked will be ID=1 the next ID=2 and so on. Note though this scheme is not recommended as it does NOT guarantee predictability of the ID a given NTuple will be given when filled under conditional statements, since in these circumstances the order in which the NTuple are first filled, and thus booked, will depend on the nature of the first few events read. This is particularly problematic when users submit many parallel 'sub-jobs' and then attempt to merge the final output ROOT (or HBOOK) files, since a given NTuple could have different IDs in each of the sub-jobs. Consequently it is strongly recommended that users do not use numerical automatic IDs unless they are sure they understand what they are doing.
Parameters
titleUnique title for N-Tuple
clidN-Tuple class identifier (row or column wise)
Returns
ntuple The ntuple object

Definition at line 101 of file GaudiTuples.icpp.

101  {
102  // look up in the table
103  auto& m = nTupleByTitle();
104  auto tuple = m.find( title );
105  if ( tuple != m.end() ) return Tuple( tuple->tuple ); // RETURN
106  // Create the tuple ID
107  TupleID ID;
108  if ( this->useNumericAutoIDs() || title.empty() ) {
109  if ( !this->useNumericAutoIDs() ) {
110  this->Warning(
111  "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for nTuple ID",
113  .ignore();
114  }
115  // propose the tuple ID
116  ID = TupleID( m_nTupleMap.size() + 1 + nTupleOffSet() );
117  // adjust the proposed ID
118  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.numeric() + 1 ); }
119  } else {
120  // use the title to create a unique literal ID
121  ID = TupleID( this->convertTitleToID( title ) );
122  // Just in case ...
123  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.idAsString() + "_" ); }
124  }
125  // return
126  return nTuple( ID, title, clid );
127 }

◆ nTuple() [2/2]

template<class PBASE >
Tuples::Tuple GaudiTuples< PBASE >::nTuple ( const TupleID ID,
const std::string title,
const CLID clid = CLID_ColumnWiseTuple 
) const

Access an N-Tuple object (book on-demand) with forced identifier.

// Book Ntuple with a numeric ID
Tuple tuple = nTuple( 1, "My tuple" ) ;
// ... or
Tuple tuple = nTuple( "1", "My tuple" ) ;
// ... or, Book Ntuple with a literal ID
Tuple tuple = nTuple( "mytuple", "My tuple" ) ;
// ... or, Book Ntuple with a literal ID in a sub-dir
Tuple tuple = nTuple( "subdir/mytuple", "My tuple" ) ;
// Fill and write NTuple
tuple->column( "A" , sin(0.1) );
tuple->column( "B" , cos(0.1) );
tuple->column( "C" , tan(0.1) );
tuple->write();
Attention
If the N-Tuple with given ID is already booked through automatic assignment of N-Tuple ID, the error will not be detected. Therefore it is recommended to use a non-trivial N-Tuple ID offset (property "NTupleOffSet") if one need to combine these techniques together It is still desirable to use the unique N-Tuple title to avoid a bad interference.
Parameters
IDThe forced N-Tuple ID
titleUnique title for N-Tuple
clidN-Tuple class identifier (row or column wise)
Returns
ntuple The ntuple object

Definition at line 167 of file GaudiTuples.icpp.

167  {
168  // Check ID
169  if ( ID.undefined() ) {
170  this->Error( "Undefined NTuple ID : Title='" + title1 + "'" ).ignore();
171  return Tuple( 0 );
172  }
173 
174  // look up in the table
175  auto& m = nTupleByID();
176  auto tuple = m.find( ID );
177  if ( tuple != m.end() ) return Tuple( tuple->tuple ); // RETURN
178 
179  // convert ID to the string
180  const std::string tID = ID.idAsString();
181 
182  // adjust the NTuple title
183  const std::string title = title1.empty() ? ( "NTuple #" + tID ) : title1;
184 
185  // book new ntuple
186  if ( !produceNTuples() ) {
187  auto r = m_nTupleMap.insert( nTupleMapItem{ title, ID, createNTuple( title, nullptr, clid ) } );
188  if ( !r.second ) this->Error( "Failure to createNTuple" ).ignore();
189  return Tuple( r.first->tuple );
190  }
191  // book NTupel
192  NTuple::Tuple* tup = nullptr;
193  if ( ID.numeric() ) {
194  tup = this->ntupleSvc()->book( nTuplePath(), ID.numericID(), clid, title );
195  } else if ( ID.literal() ) {
196  tup = this->ntupleSvc()->book( nTuplePath(), ID.literalID(), clid, title );
197  } else {
198  this->Error( "Undefined NTuple ID" ).ignore();
199  }
200 
201  // assertion
202  this->Assert( tup, "Could not book the N-Tuple='" + title + "'" );
203  // some printout
204  if ( tup->registry() && this->msgLevel( MSG::DEBUG ) ) {
205  this->debug() << "Booked NTuple '" << title << "' ID=" << tID << "' Path='" << nTuplePath() << "' TS='"
206  << tup->registry()->identifier() << "'" << endmsg;
207  }
208 
209  auto r = m_nTupleMap.insert( nTupleMapItem{ title, ID, createNTuple( title, tup, clid ) } );
210  if ( !r.second ) this->Error( "Failure to createNTuple" ).ignore();
211  return Tuple( r.first->tuple );
212  //
213 }

◆ nTupleDir()

template<class PBASE >
const std::string& GaudiTuples< PBASE >::nTupleDir ( ) const
inline

get the N-Tuple directory (property "NTupleDir")

Definition at line 221 of file GaudiTuples.h.

221 { return m_nTupleDir; }

◆ nTupleExists()

template<class PBASE >
bool GaudiTuples< PBASE >::nTupleExists ( const TupleID ID) const

check the existence AND validity of the N-Tuple with the given ID

Definition at line 328 of file GaudiTuples.icpp.

328  {
329  auto& m = nTupleByID();
330  return m.find( ID ) != m.end();
331 }

◆ nTupleLUN()

template<class PBASE >
const std::string& GaudiTuples< PBASE >::nTupleLUN ( ) const
inline

get the logical unit for N-Tuples (property "NTupleLUN")

Definition at line 217 of file GaudiTuples.h.

217 { return m_nTupleLUN; }

◆ nTupleOffSet()

template<class PBASE >
TupleID::NumericID GaudiTuples< PBASE >::nTupleOffSet ( ) const
inline

get the value for N-Tuple offset (property "NTupleOffSet")

Definition at line 223 of file GaudiTuples.h.

223 { return m_nTupleOffSet; }

◆ nTuplePath()

template<class PBASE >
std::string GaudiTuples< PBASE >::nTuplePath

get the constructed N-Tuple path

Definition at line 344 of file GaudiTuples.icpp.

344  {
345  const std::string path = nTupleLUN() + "/" + nTupleTopDir() + nTupleDir();
346  return splitNTupleDir() ? dirHbookName( path ) : path;
347 }

◆ nTupleTopDir()

template<class PBASE >
const std::string& GaudiTuples< PBASE >::nTupleTopDir ( ) const
inline

get the top-level N-Tuple directory (property "NTupleTopDir")

Definition at line 219 of file GaudiTuples.h.

219 { return m_nTupleTopDir; }

◆ printEvtCols()

template<class PBASE >
long GaudiTuples< PBASE >::printEvtCols

perform the actual printout of Event Tag Collections

Returns
number of active Event Tag Collections

Definition at line 306 of file GaudiTuples.icpp.

306  {
307  if ( m_evtColMap.empty() ) {
308  this->always() << "No Event Tag Collections are booked" << endmsg;
309  } else {
310  this->always() << "List of booked Event Tag Collections in directory "
311  << "\"" << evtColPath() << "\"" << endmsg;
312  }
313  for ( const auto& entry : this->evtColOrdered() ) {
314  if ( !entry.tuple->tuple() ) {
315  this->error() << " NTuple::Tuple* points to NULL" << endmsg;
316  continue;
317  }
318  this->always() << GaudiAlg::PrintTuple::print( entry.tuple->tuple(), entry.id )
319  << " Items:" << Gaudi::Utils::toString( entry.tuple->items() ) << endmsg;
320  }
321  //
322  return this->m_evtColMap.size();
323 }

◆ printTuples()

template<class PBASE >
long GaudiTuples< PBASE >::printTuples

perform the actual printout of N-tuples

Returns
number of active N-Tuples

Definition at line 283 of file GaudiTuples.icpp.

283  {
284 
285  if ( m_nTupleMap.empty() ) {
286  if ( this->msgLevel( MSG::DEBUG ) ) this->debug() << "No N-Tuples are booked" << endmsg;
287  } else {
288  this->always() << "List of booked N-Tuples in directory "
289  << "\"" << nTuplePath() << "\"" << endmsg;
290  }
291 
292  for ( const auto& entry : this->nTupleOrdered() ) {
293  if ( !entry.tuple->tuple() ) {
294  this->error() << " NTuple::Tuple* points to NULL" << endmsg;
295  continue;
296  }
297  this->always() << GaudiAlg::PrintTuple::print( entry.tuple->tuple(), entry.id ) << endmsg;
298  }
299  //
300  return this->m_nTupleMap.size();
301 }

◆ produceEvtCols()

template<class PBASE >
bool GaudiTuples< PBASE >::produceEvtCols ( ) const
inline

get the flag for Event Tag Collection production (property "EvtColsProduce")

Definition at line 227 of file GaudiTuples.h.

227 { return m_produceEvtCols; }

◆ produceNTuples()

template<class PBASE >
bool GaudiTuples< PBASE >::produceNTuples ( ) const
inline

get the flag for N-Tuple production (property "NTupleProduce")

Definition at line 213 of file GaudiTuples.h.

213 { return m_produceNTuples; }

◆ splitEvtColDir()

template<class PBASE >
bool GaudiTuples< PBASE >::splitEvtColDir ( ) const
inline

get the flag for Event Tag Collection path split (property "EvtColsSplitDir")

Definition at line 229 of file GaudiTuples.h.

229 { return m_splitEvtColDir; }

◆ splitNTupleDir()

template<class PBASE >
bool GaudiTuples< PBASE >::splitNTupleDir ( ) const
inline

get the flag for N-Tuple path split (property "NTupleSplitDir")

Definition at line 215 of file GaudiTuples.h.

215 { return m_splitNTupleDir; }

◆ tuplesPrint()

template<class PBASE >
bool GaudiTuples< PBASE >::tuplesPrint ( ) const
inline

print tuples at finalization

Definition at line 241 of file GaudiTuples.h.

241 { return m_tuplesPrint; }

Member Data Documentation

◆ m_evtColDir

template<class PBASE >
Gaudi::Property<std::string> GaudiTuples< PBASE >::m_evtColDir
private
Initial value:
{ this, "EvtColDir",
boost::algorithm::replace_all_copy( this->name(), ":", "_" ),
"Subdirectory for Event Tag Collections" }

Definition at line 341 of file GaudiTuples.h.

◆ m_evtColLUN

template<class PBASE >
Gaudi::Property<std::string> GaudiTuples< PBASE >::m_evtColLUN
private
Initial value:
{ this, "EvtColLUN", "EVTCOL",
"Logical File Unit for Event Tag Collections" }

Definition at line 337 of file GaudiTuples.h.

◆ m_evtColMap

template<class PBASE >
nTupleMap GaudiTuples< PBASE >::m_evtColMap
mutableprivate

the actual storage of event collections by title and ID

Definition at line 377 of file GaudiTuples.h.

◆ m_evtColOffSet

template<class PBASE >
Gaudi::Property<TupleID::NumericID> GaudiTuples< PBASE >::m_evtColOffSet { this, "EvtColOffSet", 0, "offset for numerical N-tuple ID" }
private

Definition at line 336 of file GaudiTuples.h.

◆ m_evtColsPrint

template<class PBASE >
Gaudi::Property<bool> GaudiTuples< PBASE >::m_evtColsPrint
private
Initial value:
{ this, "EvtColsPrint", false,
[this]( auto& ) {
if ( this->FSMState() >= Gaudi::StateMachine::INITIALIZED &&
this->evtColsPrint() )
this->printEvtCols();
},
"print statistics for Event Tag Collections " }

Definition at line 326 of file GaudiTuples.h.

◆ m_evtColTopDir

template<class PBASE >
Gaudi::Property<std::string> GaudiTuples< PBASE >::m_evtColTopDir
private
Initial value:
{ this, "EvtColTopDir", "",
"Top-level directory for Event Tag Collections" }

Definition at line 339 of file GaudiTuples.h.

◆ m_nTupleDir

template<class PBASE >
Gaudi::Property<std::string> GaudiTuples< PBASE >::m_nTupleDir
private
Initial value:
{
this, "NTupleDir", boost::algorithm::replace_all_copy( this->name(), ":", "_" ), "subdirectory for N-Tuples" }

Definition at line 321 of file GaudiTuples.h.

◆ m_nTupleLUN

template<class PBASE >
Gaudi::Property<std::string> GaudiTuples< PBASE >::m_nTupleLUN { this, "NTupleLUN", "FILE1", "Logical File Unit for N-tuples" }
private

Definition at line 319 of file GaudiTuples.h.

◆ m_nTupleMap

template<class PBASE >
nTupleMap GaudiTuples< PBASE >::m_nTupleMap
mutableprivate

the actual storage of ntuples by title and ID

Definition at line 369 of file GaudiTuples.h.

◆ m_nTupleOffSet

template<class PBASE >
Gaudi::Property<TupleID::NumericID> GaudiTuples< PBASE >::m_nTupleOffSet { this, "NTupleOffSet", 0, "offset for numerical N-tuple ID" }
private

Definition at line 318 of file GaudiTuples.h.

◆ m_nTupleTopDir

template<class PBASE >
Gaudi::Property<std::string> GaudiTuples< PBASE >::m_nTupleTopDir { this, "NTupleTopDir", "", "top-level directory for N-Tuples" }
private

Definition at line 320 of file GaudiTuples.h.

◆ m_produceEvtCols

template<class PBASE >
Gaudi::Property<bool> GaudiTuples< PBASE >::m_produceEvtCols
private
Initial value:
{ this, "EvtColsProduce", false,
"general switch to enable/disable Event Tag Collections" }

Definition at line 324 of file GaudiTuples.h.

◆ m_produceNTuples

template<class PBASE >
Gaudi::Property<bool> GaudiTuples< PBASE >::m_produceNTuples { this, "NTupleProduce", true, "general switch to enable/disable N-tuples" }
private

Definition at line 307 of file GaudiTuples.h.

◆ m_splitEvtColDir

template<class PBASE >
Gaudi::Property<bool> GaudiTuples< PBASE >::m_splitEvtColDir
private
Initial value:
{ this, "EvtColSplitDir", false,
"split long directory names into short pieces" }

Definition at line 334 of file GaudiTuples.h.

◆ m_splitNTupleDir

template<class PBASE >
Gaudi::Property<bool> GaudiTuples< PBASE >::m_splitNTupleDir
private
Initial value:
{ this, "NTupleSplitDir", false,
"split long directory names into short pieces (suitable for HBOOK)" }

Definition at line 316 of file GaudiTuples.h.

◆ m_tuplesPrint

template<class PBASE >
Gaudi::Property<bool> GaudiTuples< PBASE >::m_tuplesPrint
private
Initial value:
{ this, "NTuplePrint", true,
[this]( auto& ) {
if ( this->FSMState() >= Gaudi::StateMachine::INITIALIZED &&
this->tuplesPrint() )
this->printTuples();
},
"print N-tuple statistics" }

Definition at line 308 of file GaudiTuples.h.


The documentation for this class was generated from the following files:
GaudiTuples::nTupleLUN
const std::string & nTupleLUN() const
get the logical unit for N-Tuples (property "NTupleLUN")
Definition: GaudiTuples.h:217
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
std::tan
T tan(T... args)
GaudiTuples::nTupleDir
const std::string & nTupleDir() const
get the N-Tuple directory (property "NTupleDir")
Definition: GaudiTuples.h:221
std::string
STL class.
GaudiTuples::m_nTupleLUN
Gaudi::Property< std::string > m_nTupleLUN
Definition: GaudiTuples.h:319
GaudiAlg.HistoUtils.path
path
Definition: HistoUtils.py:960
GaudiTuples::m_produceEvtCols
Gaudi::Property< bool > m_produceEvtCols
Definition: GaudiTuples.h:324
Tuples::EVTCOL
@ EVTCOL
Definition: TupleObj.h:93
std::cos
T cos(T... args)
GaudiTuples::TupleID
GaudiAlg::TupleID TupleID
the actual type of N-tuple ID
Definition: GaudiTuples.h:61
GaudiTuples::m_evtColDir
Gaudi::Property< std::string > m_evtColDir
Definition: GaudiTuples.h:341
GaudiTuples::m_tuplesPrint
Gaudi::Property< bool > m_tuplesPrint
Definition: GaudiTuples.h:308
GaudiTuples::m_nTupleTopDir
Gaudi::Property< std::string > m_nTupleTopDir
Definition: GaudiTuples.h:320
GaudiTuples::m_splitEvtColDir
Gaudi::Property< bool > m_splitEvtColDir
Definition: GaudiTuples.h:334
GaudiTuples::evtColDir
const std::string & evtColDir() const
get the Event Tag Collection directory (property "EvtColsDir")
Definition: GaudiTuples.h:235
GaudiTuples::m_nTupleMap
nTupleMap m_nTupleMap
the actual storage of ntuples by title and ID
Definition: GaudiTuples.h:369
GaudiTuples::m_evtColOffSet
Gaudi::Property< TupleID::NumericID > m_evtColOffSet
Definition: GaudiTuples.h:336
GaudiTuples::createEvtCol
virtual std::unique_ptr< Tuples::TupleObj > createEvtCol(const std::string &name, NTuple::Tuple *tuple, const CLID &clid) const
create TupleObj for event tag collection
Definition: GaudiTuples.icpp:275
Tuples::NTUPLE
@ NTUPLE
Definition: TupleObj.h:92
GaudiTuples::produceEvtCols
bool produceEvtCols() const
get the flag for Event Tag Collection production (property "EvtColsProduce")
Definition: GaudiTuples.h:227
StatusCode
Definition: StatusCode.h:65
GaudiAlg::PrintTuple::print
static std::string print(const INTuple *tuple, const GaudiAlg::TupleID &ID)
Definition: Print.cpp:111
GaudiTuples::m_evtColsPrint
Gaudi::Property< bool > m_evtColsPrint
Definition: GaudiTuples.h:326
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:108
INTuple::write
virtual StatusCode write()=0
Write record of the NTuple (Shortcut of writeRecord)
GaudiTuples::m_splitNTupleDir
Gaudi::Property< bool > m_splitNTupleDir
Definition: GaudiTuples.h:316
GaudiTuples::printEvtCols
long printEvtCols() const
perform the actual printout of Event Tag Collections
Definition: GaudiTuples.icpp:306
GaudiTuples::m_nTupleDir
Gaudi::Property< std::string > m_nTupleDir
Definition: GaudiTuples.h:321
Gaudi::Details::Property::ParsingErrorPolicy::Warning
@ Warning
GaudiTuples::createNTuple
virtual std::unique_ptr< Tuples::TupleObj > createNTuple(const std::string &name, NTuple::Tuple *tuple, const CLID &clid) const
create TupleObj
Definition: GaudiTuples.icpp:265
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
GaudiTuples::evtCol
Tuple evtCol(const std::string &title, const CLID &clid=CLID_ColumnWiseTuple) const
Access an Event Tag Collection object (book on-demand) with unique identifier.
Definition: GaudiTuples.icpp:134
GaudiTuples::m_evtColLUN
Gaudi::Property< std::string > m_evtColLUN
Definition: GaudiTuples.h:337
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
Tuples::createTupleObj
auto createTupleObj(const OWNER *owner, const std::string &name, NTuple::Tuple *tuple, const CLID &clid=CLID_ColumnWiseTuple, const Tuples::Type type=Tuples::NTUPLE)
Templated helper functions allow to avoid heavy semantics of dealing with explicit type of class Tupl...
Definition: TupleDetail.h:222
std::sin
T sin(T... args)
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:354
GaudiTuples::m_evtColTopDir
Gaudi::Property< std::string > m_evtColTopDir
Definition: GaudiTuples.h:339
GaudiTuples::evtColExists
bool evtColExists(const TupleID &ID) const
check the existence AND validity of the Event Tag Collection with the given ID
Definition: GaudiTuples.icpp:336
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
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:76
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
GaudiTuples::nTuple
Tuple nTuple(const std::string &title, const CLID &clid=CLID_ColumnWiseTuple) const
Access an N-Tuple object (book on-demand) with unique identifier.
Definition: GaudiTuples.icpp:101
GaudiTuples::printTuples
long printTuples() const
perform the actual printout of N-tuples
Definition: GaudiTuples.icpp:283
Gaudi::StateMachine::INITIALIZED
@ INITIALIZED
Definition: StateMachine.h:25
GaudiTuples::evtColsPrint
bool evtColsPrint() const
print event collections at finalization
Definition: GaudiTuples.h:243
GaudiTuples::evtColPath
std::string evtColPath() const
get the constructed Event Tag Collection path
Definition: GaudiTuples.icpp:352
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
GaudiTuples::nTuplePath
std::string nTuplePath() const
get the constructed N-Tuple path
Definition: GaudiTuples.icpp:344
std::string::empty
T empty(T... args)
GaudiTuples::evtColOffSet
TupleID::NumericID evtColOffSet() const
get the value for Event Tag Collection offset (property "EvtColsOffSet")
Definition: GaudiTuples.h:237
GaudiTuples::splitEvtColDir
bool splitEvtColDir() const
get the flag for Event Tag Collection path split (property "EvtColsSplitDir")
Definition: GaudiTuples.h:229
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
GaudiTuples::nTupleTopDir
const std::string & nTupleTopDir() const
get the top-level N-Tuple directory (property "NTupleTopDir")
Definition: GaudiTuples.h:219
GaudiTuples::m_produceNTuples
Gaudi::Property< bool > m_produceNTuples
Definition: GaudiTuples.h:307
GaudiTuples::tuplesPrint
bool tuplesPrint() const
print tuples at finalization
Definition: GaudiTuples.h:241
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:82
GaudiTuples::splitNTupleDir
bool splitNTupleDir() const
get the flag for N-Tuple path split (property "NTupleSplitDir")
Definition: GaudiTuples.h:215
GaudiTuples::nTupleExists
bool nTupleExists(const TupleID &ID) const
check the existence AND validity of the N-Tuple with the given ID
Definition: GaudiTuples.icpp:328
GaudiTuples::m_nTupleOffSet
Gaudi::Property< TupleID::NumericID > m_nTupleOffSet
Definition: GaudiTuples.h:318