The Gaudi Framework  v33r0 (d5ea422b)
GaudiTuples< PBASE > Class Template Reference

Templated base class providing common 'ntupling' methods. More...

#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 291 of file GaudiTuples.icpp.

292  {
293  return Tuples::createTupleObj( this, "EvtCol '" + name + "'", tuple, clid, Tuples::EVTCOL );
294 }
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:225

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

282  {
283  return Tuples::createTupleObj( this, "Tuple '" + name + "'", tuple, clid, Tuples::NTUPLE );
284 }
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:225

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

150  {
151  // look up in the table
152  auto& m = evtColByTitle();
153  auto tuple = m.find( title );
154  if ( tuple != m.end() ) return Tuple( tuple->tuple ); // RETURN
155  // Create the tuple ID
156  TupleID ID;
157  if ( this->useNumericAutoIDs() || title.empty() ) {
158  if ( !this->useNumericAutoIDs() ) {
159  this->Warning(
160  "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for evtCol ID",
162  .ignore();
163  }
164  // proposed the tuple ID
165  ID = TupleID( m_evtColMap.size() + 1 + evtColOffSet() );
166  // adjust the proposed ID
167  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.numeric() + 1 ); }
168  } else {
169  // use the title to create a unique literal ID
170  ID = TupleID( this->convertTitleToID( title ) );
171  // Just in case ...
172  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.idAsString() + "_" ); }
173  }
174  // return
175  return evtCol( ID, title, clid );
176 }
nTupleMap m_evtColMap
the actual storage of event collections by title and ID
Definition: GaudiTuples.h:389
T empty(T... args)
TupleID::NumericID evtColOffSet() const
get the value for Event Tag Collection offset (property "EvtColsOffSet")
Definition: GaudiTuples.h:237
Tuples::Tuple Tuple
the actual type of the tuple
Definition: GaudiTuples.h:59
bool evtColExists(const TupleID &ID) const
check the existence AND validity of the Event Tag Collection with the given ID
bool nTupleExists(const TupleID &ID) const
check the existence AND validity of the N-Tuple with the given ID
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
GaudiAlg::TupleID TupleID
the actual type of N-tuple ID
Definition: GaudiTuples.h:61
constexpr double m
Tuple evtCol(const std::string &title, const CLID &clid=CLID_ColumnWiseTuple) const
Access an Event Tag Collection object (book on-demand) with unique identifier.

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

232  {
233  // Check ID
234  if ( ID.undefined() ) {
235  this->Error( "Undefined NTuple ID : Title='" + title1 + "'" ).ignore();
236  return Tuple( 0 );
237  }
238 
239  // look up in the table
240  auto& tuple = evtColByID();
241  auto i = tuple.find( ID );
242  if ( i != tuple.end() ) return Tuple( i->tuple ); // RETURN
243 
244  // convert ID to the string
245  const std::string tID = ID.idAsString();
246 
247  // adjust the NTuple title
248  const std::string title = title1.empty() ? ( "EvtCol #" + tID ) : title1;
249 
250  // book new ntuple
251  if ( !produceEvtCols() ) {
252  auto r = m_evtColMap.insert( nTupleMapItem{title, ID, createEvtCol( title, nullptr, clid )} );
253  if ( !r.second ) this->Error( "Failure to createEvtCol" ).ignore();
254  return Tuple( r.first->tuple );
255  }
256  // book NTuple
257  NTuple::Tuple* tup = nullptr;
258  if ( ID.numeric() ) {
259  tup = this->evtColSvc()->book( evtColPath(), ID.numericID(), clid, title );
260  } else if ( ID.literal() ) {
261  tup = this->evtColSvc()->book( evtColPath(), ID.literalID(), clid, title );
262  } else {
263  this->Error( "Undefined NTuple ID" ).ignore();
264  }
265 
266  // assertion
267  this->Assert( tup, "Could not book the EvtCol='" + title + "'" );
268  // some printout
269  if ( tup->registry() && this->msgLevel( MSG::DEBUG ) ) {
270  this->debug() << "Booked EvtCol '" << title << "' ID=" << tID << "' Path='" << evtColPath() << "' TS='"
271  << tup->registry()->identifier() << "'" << endmsg;
272  }
273  auto r = m_evtColMap.insert( nTupleMapItem{title, ID, createEvtCol( title, tup, clid )} );
274  if ( !r.second ) this->Error( "Failure to createEvtCol" ).ignore();
275  return Tuple( r.first->tuple );
276 }
nTupleMap m_evtColMap
the actual storage of event collections by title and ID
Definition: GaudiTuples.h:389
T empty(T... args)
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:82
virtual std::unique_ptr< Tuples::TupleObj > createEvtCol(const std::string &name, NTuple::Tuple *tuple, const CLID &clid) const
create TupleObj for event tag collection
bool produceEvtCols() const
get the flag for Event Tag Collection production (property "EvtColsProduce")
Definition: GaudiTuples.h:227
Tuples::Tuple Tuple
the actual type of the tuple
Definition: GaudiTuples.h:59
STL class.
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:385
std::string evtColPath() const
get the constructed Event Tag Collection path
virtual const id_type & identifier() const =0
Full identifier (or key)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ 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; }
Gaudi::Property< std::string > m_evtColDir
Definition: GaudiTuples.h:353

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

352  {
353  auto& m = evtColByID();
354  return m.find( ID ) != m.end();
355 }
constexpr double m

◆ 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; }
Gaudi::Property< std::string > m_evtColLUN
Definition: GaudiTuples.h:350

◆ 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; }
Gaudi::Property< TupleID::NumericID > m_evtColOffSet
Definition: GaudiTuples.h:349

◆ evtColPath()

template<class PBASE >
std::string GaudiTuples< PBASE >::evtColPath ( ) const

get the constructed Event Tag Collection path

Definition at line 368 of file GaudiTuples.icpp.

368  {
369  std::string path = evtColLUN() + "/" + evtColTopDir() + evtColDir();
370  return splitEvtColDir() ? dirHbookName( path ) : path;
371 }
const std::string & evtColDir() const
get the Event Tag Collection directory (property "EvtColsDir")
Definition: GaudiTuples.h:235
const std::string & evtColLUN() const
get the logical unit for Event Tag Collections (property "EvtColsLUN")
Definition: GaudiTuples.h:231
STL class.
const std::string & evtColTopDir() const
get the top-level Event Tag Collection directory (property "EvtColsTopDir")
Definition: GaudiTuples.h:233
bool splitEvtColDir() const
get the flag for Event Tag Collection path split (property "EvtColsSplitDir")
Definition: GaudiTuples.h:229

◆ 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; }
Gaudi::Property< bool > m_evtColsPrint
Definition: GaudiTuples.h:340

◆ 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; }
Gaudi::Property< std::string > m_evtColTopDir
Definition: GaudiTuples.h:351

◆ finalize()

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

standard finalization method

Returns
status code

Definition at line 93 of file GaudiTuples.icpp.

93  {
94  if ( !( m_nTupleMap.empty() && m_evtColMap.empty() ) ) {
95  const int nNtuples = m_nTupleMap.size();
96  const int nEvtCols = m_evtColMap.size();
97  this->always() << "Booked " << nNtuples << " N-Tuples and " << nEvtCols << " Event Tag Collections" << endmsg;
98  }
99 
100  if ( produceNTuples() && tuplesPrint() ) printTuples();
101  if ( produceEvtCols() && evtColsPrint() ) printEvtCols();
102 
103  // release ntuples and clear the container
104  m_nTupleMap.clear();
105 
106  // release ntuples and clear the container
107  m_evtColMap.clear();
108 
109  // finalize base class
110  return PBASE::finalize();
111 }
nTupleMap m_evtColMap
the actual storage of event collections by title and ID
Definition: GaudiTuples.h:389
long printTuples() const
perform the actual printout of N-tuples
bool produceEvtCols() const
get the flag for Event Tag Collection production (property "EvtColsProduce")
Definition: GaudiTuples.h:227
long printEvtCols() const
perform the actual printout of Event Tag Collections
bool produceNTuples() const
get the flag for N-Tuple production (property "NTupleProduce")
Definition: GaudiTuples.h:213
bool tuplesPrint() const
print tuples at finalization
Definition: GaudiTuples.h:241
nTupleMap m_nTupleMap
the actual storage of ntuples by title and ID
Definition: GaudiTuples.h:381
bool evtColsPrint() const
print event collections at finalization
Definition: GaudiTuples.h:243
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ initialize()

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

standard initialization method

Returns
status code

Definition at line 53 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( StatusCode::SUCCESS, true ),
63  MSG::DEBUG )
64  .ignore();
65  } else {
66  this->debug() << "Production of N-Tuples is switched OFF" << endmsg;
67  }
68 
69  if ( produceEvtCols() ) {
70  // check the existance of service
71  if ( 0 == this->evtColSvc() ) { return this->Error( "INTupleSvc* points to NULL!" ); }
72  // Print EvtCol path
73  this->Print( "The EventCol path is set to be '" + evtColPath() + "'", StatusCode( StatusCode::SUCCESS, true ),
74  MSG::DEBUG )
75  .ignore();
76  } else {
77  this->debug() << "Production of Event Collections is switched OFF" << endmsg;
78  }
79 
80  return sc;
81 }
std::string nTuplePath() const
get the constructed N-Tuple path
bool produceEvtCols() const
get the flag for Event Tag Collection production (property "EvtColsProduce")
Definition: GaudiTuples.h:227
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
bool produceNTuples() const
get the flag for N-Tuple production (property "NTupleProduce")
Definition: GaudiTuples.h:213
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
std::string evtColPath() const
get the constructed Event Tag Collection path
bool isFailure() const
Definition: StatusCode.h:141
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

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

117  {
118  // look up in the table
119  auto& m = nTupleByTitle();
120  auto tuple = m.find( title );
121  if ( tuple != m.end() ) return Tuple( tuple->tuple ); // RETURN
122  // Create the tuple ID
123  TupleID ID;
124  if ( this->useNumericAutoIDs() || title.empty() ) {
125  if ( !this->useNumericAutoIDs() ) {
126  this->Warning(
127  "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for nTuple ID",
129  .ignore();
130  }
131  // propose the tuple ID
132  ID = TupleID( m_nTupleMap.size() + 1 + nTupleOffSet() );
133  // adjust the proposed ID
134  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.numeric() + 1 ); }
135  } else {
136  // use the title to create a unique literal ID
137  ID = TupleID( this->convertTitleToID( title ) );
138  // Just in case ...
139  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.idAsString() + "_" ); }
140  }
141  // return
142  return nTuple( ID, title, clid );
143 }
T empty(T... args)
Tuples::Tuple Tuple
the actual type of the tuple
Definition: GaudiTuples.h:59
bool evtColExists(const TupleID &ID) const
check the existence AND validity of the Event Tag Collection with the given ID
bool nTupleExists(const TupleID &ID) const
check the existence AND validity of the N-Tuple with the given ID
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
TupleID::NumericID nTupleOffSet() const
get the value for N-Tuple offset (property "NTupleOffSet")
Definition: GaudiTuples.h:223
GaudiAlg::TupleID TupleID
the actual type of N-tuple ID
Definition: GaudiTuples.h:61
Tuple nTuple(const std::string &title, const CLID &clid=CLID_ColumnWiseTuple) const
Access an N-Tuple object (book on-demand) with unique identifier.
constexpr double m
nTupleMap m_nTupleMap
the actual storage of ntuples by title and ID
Definition: GaudiTuples.h:381

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

183  {
184  // Check ID
185  if ( ID.undefined() ) {
186  this->Error( "Undefined NTuple ID : Title='" + title1 + "'" ).ignore();
187  return Tuple( 0 );
188  }
189 
190  // look up in the table
191  auto& m = nTupleByID();
192  auto tuple = m.find( ID );
193  if ( tuple != m.end() ) return Tuple( tuple->tuple ); // RETURN
194 
195  // convert ID to the string
196  const std::string tID = ID.idAsString();
197 
198  // adjust the NTuple title
199  const std::string title = title1.empty() ? ( "NTuple #" + tID ) : title1;
200 
201  // book new ntuple
202  if ( !produceNTuples() ) {
203  auto r = m_nTupleMap.insert( nTupleMapItem{title, ID, createNTuple( title, nullptr, clid )} );
204  if ( !r.second ) this->Error( "Failure to createNTuple" ).ignore();
205  return Tuple( r.first->tuple );
206  }
207  // book NTupel
208  NTuple::Tuple* tup = nullptr;
209  if ( ID.numeric() ) {
210  tup = this->ntupleSvc()->book( nTuplePath(), ID.numericID(), clid, title );
211  } else if ( ID.literal() ) {
212  tup = this->ntupleSvc()->book( nTuplePath(), ID.literalID(), clid, title );
213  } else {
214  this->Error( "Undefined NTuple ID" ).ignore();
215  }
216 
217  // assertion
218  this->Assert( tup, "Could not book the N-Tuple='" + title + "'" );
219  // some printout
220  if ( tup->registry() && this->msgLevel( MSG::DEBUG ) ) {
221  this->debug() << "Booked NTuple '" << title << "' ID=" << tID << "' Path='" << nTuplePath() << "' TS='"
222  << tup->registry()->identifier() << "'" << endmsg;
223  }
224 
225  auto r = m_nTupleMap.insert( nTupleMapItem{title, ID, createNTuple( title, tup, clid )} );
226  if ( !r.second ) this->Error( "Failure to createNTuple" ).ignore();
227  return Tuple( r.first->tuple );
228  //
229 }
T empty(T... args)
std::string nTuplePath() const
get the constructed N-Tuple path
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:82
Tuples::Tuple Tuple
the actual type of the tuple
Definition: GaudiTuples.h:59
bool produceNTuples() const
get the flag for N-Tuple production (property "NTupleProduce")
Definition: GaudiTuples.h:213
STL class.
constexpr double m
nTupleMap m_nTupleMap
the actual storage of ntuples by title and ID
Definition: GaudiTuples.h:381
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:385
virtual std::unique_ptr< Tuples::TupleObj > createNTuple(const std::string &name, NTuple::Tuple *tuple, const CLID &clid) const
create TupleObj
virtual const id_type & identifier() const =0
Full identifier (or key)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ 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; }
Gaudi::Property< std::string > m_nTupleDir
Definition: GaudiTuples.h:335

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

344  {
345  auto& m = nTupleByID();
346  return m.find( ID ) != m.end();
347 }
constexpr double m

◆ 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; }
Gaudi::Property< std::string > m_nTupleLUN
Definition: GaudiTuples.h:333

◆ 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; }
Gaudi::Property< TupleID::NumericID > m_nTupleOffSet
Definition: GaudiTuples.h:332

◆ nTuplePath()

template<class PBASE >
std::string GaudiTuples< PBASE >::nTuplePath ( ) const

get the constructed N-Tuple path

Definition at line 360 of file GaudiTuples.icpp.

360  {
361  const std::string path = nTupleLUN() + "/" + nTupleTopDir() + nTupleDir();
362  return splitNTupleDir() ? dirHbookName( path ) : path;
363 }
bool splitNTupleDir() const
get the flag for N-Tuple path split (property "NTupleSplitDir")
Definition: GaudiTuples.h:215
STL class.
const std::string & nTupleTopDir() const
get the top-level N-Tuple directory (property "NTupleTopDir")
Definition: GaudiTuples.h:219
const std::string & nTupleLUN() const
get the logical unit for N-Tuples (property "NTupleLUN")
Definition: GaudiTuples.h:217
const std::string & nTupleDir() const
get the N-Tuple directory (property "NTupleDir")
Definition: GaudiTuples.h:221

◆ 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; }
Gaudi::Property< std::string > m_nTupleTopDir
Definition: GaudiTuples.h:334

◆ printEvtCols()

template<class PBASE >
long GaudiTuples< PBASE >::printEvtCols ( ) const

perform the actual printout of Event Tag Collections

Returns
number of active Event Tag Collections

Definition at line 322 of file GaudiTuples.icpp.

322  {
323  if ( m_evtColMap.empty() ) {
324  this->always() << "No Event Tag Collections are booked" << endmsg;
325  } else {
326  this->always() << "List of booked Event Tag Collections in directory "
327  << "\"" << evtColPath() << "\"" << endmsg;
328  }
329  for ( const auto& entry : this->evtColOrdered() ) {
330  if ( !entry.tuple->tuple() ) {
331  this->error() << " NTuple::Tuple* points to NULL" << endmsg;
332  continue;
333  }
334  this->always() << GaudiAlg::PrintTuple::print( entry.tuple->tuple(), entry.id )
335  << " Items:" << Gaudi::Utils::toString( entry.tuple->items() ) << endmsg;
336  }
337  //
338  return this->m_evtColMap.size();
339 }
nTupleMap m_evtColMap
the actual storage of event collections by title and ID
Definition: GaudiTuples.h:389
static std::string print(const INTuple *tuple, const GaudiAlg::TupleID &ID)
Definition: Print.cpp:144
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:341
std::string evtColPath() const
get the constructed Event Tag Collection path
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ printTuples()

template<class PBASE >
long GaudiTuples< PBASE >::printTuples ( ) const

perform the actual printout of N-tuples

Returns
number of active N-Tuples

Definition at line 299 of file GaudiTuples.icpp.

299  {
300 
301  if ( m_nTupleMap.empty() ) {
302  if ( this->msgLevel( MSG::DEBUG ) ) this->debug() << "No N-Tuples are booked" << endmsg;
303  } else {
304  this->always() << "List of booked N-Tuples in directory "
305  << "\"" << nTuplePath() << "\"" << endmsg;
306  }
307 
308  for ( const auto& entry : this->nTupleOrdered() ) {
309  if ( !entry.tuple->tuple() ) {
310  this->error() << " NTuple::Tuple* points to NULL" << endmsg;
311  continue;
312  }
313  this->always() << GaudiAlg::PrintTuple::print( entry.tuple->tuple(), entry.id ) << endmsg;
314  }
315  //
316  return this->m_nTupleMap.size();
317 }
static std::string print(const INTuple *tuple, const GaudiAlg::TupleID &ID)
Definition: Print.cpp:144
std::string nTuplePath() const
get the constructed N-Tuple path
nTupleMap m_nTupleMap
the actual storage of ntuples by title and ID
Definition: GaudiTuples.h:381
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ 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; }
Gaudi::Property< bool > m_produceEvtCols
Definition: GaudiTuples.h:338

◆ 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; }
Gaudi::Property< bool > m_produceNTuples
Definition: GaudiTuples.h:321

◆ 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; }
Gaudi::Property< bool > m_splitEvtColDir
Definition: GaudiTuples.h:348

◆ 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; }
Gaudi::Property< bool > m_splitNTupleDir
Definition: GaudiTuples.h:330

◆ 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; }
Gaudi::Property< bool > m_tuplesPrint
Definition: GaudiTuples.h:322

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: