The Gaudi Framework  v36r1 (3e2fb5a8)
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 {this, "EvtColSplitDir", false, "split long directory names into short pieces"}
 
Gaudi::Property< TupleID::NumericIDm_evtColOffSet {this, "EvtColOffSet", 0, "offset for numerical N-tuple ID"}
 
Gaudi::Property< std::stringm_evtColLUN {this, "EvtColLUN", "EVTCOL", "Logical File Unit for Event Tag Collections"}
 
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 367 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 365 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 371 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 369 of file GaudiTuples.h.

◆ tag

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

Definition at line 373 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 287 of file GaudiTuples.icpp.

288  {
289  return Tuples::createTupleObj( this, "EvtCol '" + name + "'", tuple, clid, Tuples::EVTCOL );
290 }

◆ 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 277 of file GaudiTuples.icpp.

278  {
279  return Tuples::createTupleObj( this, "Tuple '" + name + "'", tuple, clid, Tuples::NTUPLE );
280 }

◆ 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 146 of file GaudiTuples.icpp.

146  {
147  // look up in the table
148  auto& m = evtColByTitle();
149  auto tuple = m.find( title );
150  if ( tuple != m.end() ) return Tuple( tuple->tuple ); // RETURN
151  // Create the tuple ID
152  TupleID ID;
153  if ( this->useNumericAutoIDs() || title.empty() ) {
154  if ( !this->useNumericAutoIDs() ) {
155  this->Warning(
156  "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for evtCol ID",
158  .ignore();
159  }
160  // proposed the tuple ID
161  ID = TupleID( m_evtColMap.size() + 1 + evtColOffSet() );
162  // adjust the proposed ID
163  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.numeric() + 1 ); }
164  } else {
165  // use the title to create a unique literal ID
166  ID = TupleID( this->convertTitleToID( title ) );
167  // Just in case ...
168  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.idAsString() + "_" ); }
169  }
170  // return
171  return evtCol( ID, title, clid );
172 }

◆ 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 228 of file GaudiTuples.icpp.

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

◆ 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 348 of file GaudiTuples.icpp.

348  {
349  auto& m = evtColByID();
350  return m.find( ID ) != m.end();
351 }

◆ 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 364 of file GaudiTuples.icpp.

364  {
365  std::string path = evtColLUN() + "/" + evtColTopDir() + evtColDir();
366  return splitEvtColDir() ? dirHbookName( path ) : path;
367 }

◆ 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 83 of file GaudiTuples.icpp.

89  {
90  if ( !( m_nTupleMap.empty() && m_evtColMap.empty() ) ) {
91  const int nNtuples = m_nTupleMap.size();
92  const int nEvtCols = m_evtColMap.size();
93  this->always() << "Booked " << nNtuples << " N-Tuples and " << nEvtCols << " Event Tag Collections" << endmsg;
94  }
95 
96  if ( produceNTuples() && tuplesPrint() ) printTuples();
98 
99  // release ntuples and clear the container
100  m_nTupleMap.clear();
101 
102  // release ntuples and clear the container
103  m_evtColMap.clear();
104 
105  // finalize base class
106  return PBASE::finalize();
107 }

◆ initialize()

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

standard initialization method

Returns
status code

Definition at line 47 of file GaudiTuples.icpp.

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

◆ 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 113 of file GaudiTuples.icpp.

113  {
114  // look up in the table
115  auto& m = nTupleByTitle();
116  auto tuple = m.find( title );
117  if ( tuple != m.end() ) return Tuple( tuple->tuple ); // RETURN
118  // Create the tuple ID
119  TupleID ID;
120  if ( this->useNumericAutoIDs() || title.empty() ) {
121  if ( !this->useNumericAutoIDs() ) {
122  this->Warning(
123  "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for nTuple ID",
125  .ignore();
126  }
127  // propose the tuple ID
128  ID = TupleID( m_nTupleMap.size() + 1 + nTupleOffSet() );
129  // adjust the proposed ID
130  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.numeric() + 1 ); }
131  } else {
132  // use the title to create a unique literal ID
133  ID = TupleID( this->convertTitleToID( title ) );
134  // Just in case ...
135  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.idAsString() + "_" ); }
136  }
137  // return
138  return nTuple( ID, title, clid );
139 }

◆ 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 179 of file GaudiTuples.icpp.

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

◆ 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 340 of file GaudiTuples.icpp.

340  {
341  auto& m = nTupleByID();
342  return m.find( ID ) != m.end();
343 }

◆ 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 356 of file GaudiTuples.icpp.

356  {
357  const std::string path = nTupleLUN() + "/" + nTupleTopDir() + nTupleDir();
358  return splitNTupleDir() ? dirHbookName( path ) : path;
359 }

◆ 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 318 of file GaudiTuples.icpp.

318  {
319  if ( m_evtColMap.empty() ) {
320  this->always() << "No Event Tag Collections are booked" << endmsg;
321  } else {
322  this->always() << "List of booked Event Tag Collections in directory "
323  << "\"" << evtColPath() << "\"" << endmsg;
324  }
325  for ( const auto& entry : this->evtColOrdered() ) {
326  if ( !entry.tuple->tuple() ) {
327  this->error() << " NTuple::Tuple* points to NULL" << endmsg;
328  continue;
329  }
330  this->always() << GaudiAlg::PrintTuple::print( entry.tuple->tuple(), entry.id )
331  << " Items:" << Gaudi::Utils::toString( entry.tuple->items() ) << endmsg;
332  }
333  //
334  return this->m_evtColMap.size();
335 }

◆ printTuples()

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

perform the actual printout of N-tuples

Returns
number of active N-Tuples

Definition at line 295 of file GaudiTuples.icpp.

295  {
296 
297  if ( m_nTupleMap.empty() ) {
298  if ( this->msgLevel( MSG::DEBUG ) ) this->debug() << "No N-Tuples are booked" << endmsg;
299  } else {
300  this->always() << "List of booked N-Tuples in directory "
301  << "\"" << nTuplePath() << "\"" << endmsg;
302  }
303 
304  for ( const auto& entry : this->nTupleOrdered() ) {
305  if ( !entry.tuple->tuple() ) {
306  this->error() << " NTuple::Tuple* points to NULL" << endmsg;
307  continue;
308  }
309  this->always() << GaudiAlg::PrintTuple::print( entry.tuple->tuple(), entry.id ) << endmsg;
310  }
311  //
312  return this->m_nTupleMap.size();
313 }

◆ 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 353 of file GaudiTuples.h.

◆ m_evtColLUN

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

Definition at line 350 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 389 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 349 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 340 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 351 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 335 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 333 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 381 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 332 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 334 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 338 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 321 of file GaudiTuples.h.

◆ m_splitEvtColDir

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

Definition at line 348 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 330 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 322 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:333
GaudiTuples::m_produceEvtCols
Gaudi::Property< bool > m_produceEvtCols
Definition: GaudiTuples.h:338
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:353
GaudiTuples::m_tuplesPrint
Gaudi::Property< bool > m_tuplesPrint
Definition: GaudiTuples.h:322
GaudiTuples::m_nTupleTopDir
Gaudi::Property< std::string > m_nTupleTopDir
Definition: GaudiTuples.h:334
GaudiTuples::m_splitEvtColDir
Gaudi::Property< bool > m_splitEvtColDir
Definition: GaudiTuples.h:348
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:381
GaudiTuples::m_evtColOffSet
Gaudi::Property< TupleID::NumericID > m_evtColOffSet
Definition: GaudiTuples.h:349
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:287
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
TimingHistograms.name
name
Definition: TimingHistograms.py:23
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:340
HistoDumpEx.r
r
Definition: HistoDumpEx.py:20
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:330
GaudiTuples::printEvtCols
long printEvtCols() const
perform the actual printout of Event Tag Collections
Definition: GaudiTuples.icpp:318
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:943
GaudiTuples::m_nTupleDir
Gaudi::Property< std::string > m_nTupleDir
Definition: GaudiTuples.h:335
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:277
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
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:146
GaudiTuples::m_evtColLUN
Gaudi::Property< std::string > m_evtColLUN
Definition: GaudiTuples.h:350
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:142
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:353
GaudiTuples::m_evtColTopDir
Gaudi::Property< std::string > m_evtColTopDir
Definition: GaudiTuples.h:351
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:348
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
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
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:113
GaudiTuples::printTuples
long printTuples() const
perform the actual printout of N-tuples
Definition: GaudiTuples.icpp:295
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:364
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:356
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:321
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:340
GaudiTuples::m_nTupleOffSet
Gaudi::Property< TupleID::NumericID > m_nTupleOffSet
Definition: GaudiTuples.h:332