The Gaudi Framework  v30r3 (a5ef0a68)
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<GaudiHistoAlg, PBASE>::value, 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<GaudiHistoTool, PBASE>::value, 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 Member Functions

void initGaudiTuplesConstructor ()
 Constructor initialization and job options. More...
 
void printNTupleHandler (Gaudi::Details::PropertyBase &)
 handler for "NTuplePrint" property More...
 
void printEvtColHandler (Gaudi::Details::PropertyBase &)
 handler for "EvtColsPrint" property More...
 

Private Attributes

Gaudi::Property< bool > m_produceNTuples {this, "NTupleProduce", true, "general switch to enable/disable N-tuples"}
 
Gaudi::Property< bool > m_tuplesPrint {this, "NTuplePrint", true, "print N-tuple statistics"}
 
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 {this, "EvtColsPrint", false, "print statistics for Event Tag Collections "}
 
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 43 of file GaudiTuples.h.

Member Typedef Documentation

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

Definition at line 369 of file GaudiTuples.h.

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

the actual type for histogram identifier

Definition at line 48 of file GaudiTuples.h.

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

Definition at line 367 of file GaudiTuples.h.

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

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

Definition at line 371 of file GaudiTuples.h.

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

Definition at line 375 of file GaudiTuples.h.

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

the actual type of the tuple

Definition at line 50 of file GaudiTuples.h.

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

the actual type of N-tuple ID

Definition at line 52 of file GaudiTuples.h.

Constructor & Destructor Documentation

template<class PBASE>
template<typename U = PBASE, typename = std::enable_if_t<std::is_base_of<GaudiHistoAlg, PBASE>::value, 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 278 of file GaudiTuples.h.

278  : PBASE( name, pSvcLocator )
279  {
281  }
void initGaudiTuplesConstructor()
Constructor initialization and job options.
Definition: GaudiTuples.h:319
template<class PBASE>
template<typename U = PBASE, typename = std::enable_if_t<std::is_base_of<GaudiHistoTool, PBASE>::value, 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 285 of file GaudiTuples.h.

286  : PBASE( type, name, parent )
287  {
289  }
void initGaudiTuplesConstructor()
Constructor initialization and job options.
Definition: GaudiTuples.h:319

Member Function Documentation

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

302 {
303  return Tuples::createTupleObj( this, "EvtCol '" + name + "'", tuple, clid, Tuples::EVTCOL );
304 }
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:226
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 289 of file GaudiTuples.icpp.

291 {
292  return Tuples::createTupleObj( this, "Tuple '" + name + "'", tuple, clid, Tuples::NTUPLE );
293 }
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:226
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 151 of file GaudiTuples.icpp.

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

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

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

Definition at line 226 of file GaudiTuples.h.

226 { return m_evtColDir; }
Gaudi::Property< std::string > m_evtColDir
Definition: GaudiTuples.h:352
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 365 of file GaudiTuples.icpp.

366 {
367  auto& m = evtColByID();
368  return m.find( ID ) != m.end();
369 }
constexpr double m
Definition: SystemOfUnits.h:94
template<class PBASE>
const std::string& GaudiTuples< PBASE >::evtColLUN ( ) const
inline

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

Definition at line 222 of file GaudiTuples.h.

222 { return m_evtColLUN; }
Gaudi::Property< std::string > m_evtColLUN
Definition: GaudiTuples.h:349
template<class PBASE>
TupleID::NumericID GaudiTuples< PBASE >::evtColOffSet ( ) const
inline

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

Definition at line 228 of file GaudiTuples.h.

228 { return m_evtColOffSet; }
Gaudi::Property< TupleID::NumericID > m_evtColOffSet
Definition: GaudiTuples.h:348
template<class PBASE >
std::string GaudiTuples< PBASE >::evtColPath ( ) const

get the constructed Event Tag Collection path

Definition at line 403 of file GaudiTuples.icpp.

404 {
405  std::string path = evtColLUN() + "/" + evtColTopDir() + evtColDir();
406  return splitEvtColDir() ? dirHbookName( path ) : path;
407 }
bool splitEvtColDir() const
get the flag for Event Tag Collection path split (property "EvtColsSplitDir")
Definition: GaudiTuples.h:220
const std::string & evtColDir() const
get the Event Tag Collection directory (property "EvtColsDir")
Definition: GaudiTuples.h:226
const std::string & evtColTopDir() const
get the top-level Event Tag Collection directory (property "EvtColsTopDir")
Definition: GaudiTuples.h:224
STL class.
const std::string & evtColLUN() const
get the logical unit for Event Tag Collections (property "EvtColsLUN")
Definition: GaudiTuples.h:222
template<class PBASE>
bool GaudiTuples< PBASE >::evtColsPrint ( ) const
inline

print event collections at finalization

Definition at line 234 of file GaudiTuples.h.

234 { return m_evtColsPrint; }
Gaudi::Property< bool > m_evtColsPrint
Definition: GaudiTuples.h:346
template<class PBASE>
const std::string& GaudiTuples< PBASE >::evtColTopDir ( ) const
inline

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

Definition at line 224 of file GaudiTuples.h.

224 { return m_evtColTopDir; }
Gaudi::Property< std::string > m_evtColTopDir
Definition: GaudiTuples.h:350
template<class PBASE >
StatusCode GaudiTuples< PBASE >::finalize ( )
overrideprotected

standard finalization method

Returns
status code

Definition at line 88 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 }
nTupleMap m_evtColMap
the actual storage of event collections by title and ID
Definition: GaudiTuples.h:391
bool evtColsPrint() const
print event collections at finalization
Definition: GaudiTuples.h:234
long printTuples() const
perform the actual printout of N-tuples
long printEvtCols() const
perform the actual printout of Event Tag Collections
nTupleMap m_nTupleMap
the actual storage of ntuples by title and ID
Definition: GaudiTuples.h:383
bool tuplesPrint() const
print tuples at finalization
Definition: GaudiTuples.h:232
bool produceEvtCols() const
get the flag for Event Tag Collection production (property "EvtColsProduce")
Definition: GaudiTuples.h:218
bool produceNTuples() const
get the flag for N-Tuple production (property "NTupleProduce")
Definition: GaudiTuples.h:204
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
template<class PBASE>
void GaudiTuples< PBASE >::initGaudiTuplesConstructor ( )
inlineprivate

Constructor initialization and job options.

Definition at line 319 of file GaudiTuples.h.

320  {
321  m_tuplesPrint.declareUpdateHandler( &GaudiTuples<PBASE>::printNTupleHandler, this );
322  m_evtColsPrint.declareUpdateHandler( &GaudiTuples<PBASE>::printEvtColHandler, this );
323  }
Templated base class providing common &#39;ntupling&#39; methods.
Definition: GaudiTuples.h:43
Gaudi::Property< bool > m_evtColsPrint
Definition: GaudiTuples.h:346
Gaudi::Property< bool > m_tuplesPrint
Definition: GaudiTuples.h:335
template<class PBASE >
StatusCode GaudiTuples< PBASE >::initialize ( )
overrideprotected

standard initialization method

Returns
status code

Definition at line 43 of file GaudiTuples.icpp.

44 {
45  // initialize base class
46  const StatusCode sc = PBASE::initialize();
47  if ( sc.isFailure() ) return sc;
48 
49  if ( produceNTuples() ) {
50  // check the existance of service
51  if ( this->ntupleSvc() == 0 ) {
52  return this->Error( "INTupleSvc* points to NULL!" );
53  }
54  // Print ntuple path
55  this->Print( "The N-Tuple path is set to be '" + nTuplePath() + "'", StatusCode( StatusCode::SUCCESS, true ),
56  MSG::DEBUG )
57  .ignore();
58  } else {
59  this->debug() << "Production of N-Tuples is switched OFF" << endmsg;
60  }
61 
62  if ( produceEvtCols() ) {
63  // check the existance of service
64  if ( 0 == this->evtColSvc() ) {
65  return this->Error( "INTupleSvc* points to NULL!" );
66  }
67  // Print EvtCol path
68  this->Print( "The EventCol path is set to be '" + evtColPath() + "'", StatusCode( StatusCode::SUCCESS, true ),
69  MSG::DEBUG )
70  .ignore();
71  } else {
72  this->debug() << "Production of Event Collections is switched OFF" << endmsg;
73  }
74 
75  return sc;
76 }
bool isFailure() const
Definition: StatusCode.h:139
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
std::string evtColPath() const
get the constructed Event Tag Collection path
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:218
bool produceNTuples() const
get the flag for N-Tuple production (property "NTupleProduce")
Definition: GaudiTuples.h:204
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
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.

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

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

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

Definition at line 212 of file GaudiTuples.h.

212 { return m_nTupleDir; }
Gaudi::Property< std::string > m_nTupleDir
Definition: GaudiTuples.h:341
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 356 of file GaudiTuples.icpp.

357 {
358  auto& m = nTupleByID();
359  return m.find( ID ) != m.end();
360 }
constexpr double m
Definition: SystemOfUnits.h:94
template<class PBASE>
const std::string& GaudiTuples< PBASE >::nTupleLUN ( ) const
inline

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

Definition at line 208 of file GaudiTuples.h.

208 { return m_nTupleLUN; }
Gaudi::Property< std::string > m_nTupleLUN
Definition: GaudiTuples.h:339
template<class PBASE>
TupleID::NumericID GaudiTuples< PBASE >::nTupleOffSet ( ) const
inline

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

Definition at line 214 of file GaudiTuples.h.

214 { return m_nTupleOffSet; }
Gaudi::Property< TupleID::NumericID > m_nTupleOffSet
Definition: GaudiTuples.h:338
template<class PBASE >
std::string GaudiTuples< PBASE >::nTuplePath ( ) const

get the constructed N-Tuple path

Definition at line 394 of file GaudiTuples.icpp.

395 {
396  const std::string path = nTupleLUN() + "/" + nTupleTopDir() + nTupleDir();
397  return splitNTupleDir() ? dirHbookName( path ) : path;
398 }
const std::string & nTupleLUN() const
get the logical unit for N-Tuples (property "NTupleLUN")
Definition: GaudiTuples.h:208
const std::string & nTupleTopDir() const
get the top-level N-Tuple directory (property "NTupleTopDir")
Definition: GaudiTuples.h:210
STL class.
const std::string & nTupleDir() const
get the N-Tuple directory (property "NTupleDir")
Definition: GaudiTuples.h:212
bool splitNTupleDir() const
get the flag for N-Tuple path split (property "NTupleSplitDir")
Definition: GaudiTuples.h:206
template<class PBASE>
const std::string& GaudiTuples< PBASE >::nTupleTopDir ( ) const
inline

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

Definition at line 210 of file GaudiTuples.h.

210 { return m_nTupleTopDir; }
Gaudi::Property< std::string > m_nTupleTopDir
Definition: GaudiTuples.h:340
template<class PBASE >
void GaudiTuples< PBASE >::printEvtColHandler ( Gaudi::Details::PropertyBase )
private

handler for "EvtColsPrint" property

Definition at line 384 of file GaudiTuples.icpp.

385 {
386  // no action if not yet initialized
387  if ( this->FSMState() < Gaudi::StateMachine::INITIALIZED ) return;
388  if ( this->evtColsPrint() ) this->printEvtCols();
389 }
bool evtColsPrint() const
print event collections at finalization
Definition: GaudiTuples.h:234
long printEvtCols() const
perform the actual printout of Event Tag Collections
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 333 of file GaudiTuples.icpp.

334 {
335  if ( m_evtColMap.empty() ) {
336  this->always() << "No Event Tag Collections are booked" << endmsg;
337  } else {
338  this->always() << "List of booked Event Tag Collections in directory "
339  << "\"" << evtColPath() << "\"" << endmsg;
340  }
341  for ( const auto& entry : this->evtColOrdered() ) {
342  if ( !entry.tuple->tuple() ) {
343  this->error() << " NTuple::Tuple* points to NULL" << endmsg;
344  continue;
345  }
346  this->always() << GaudiAlg::PrintTuple::print( entry.tuple->tuple(), entry.id )
347  << " Items:" << Gaudi::Utils::toString( entry.tuple->items() ) << endmsg;
348  }
349  //
350  return this->m_evtColMap.size();
351 }
nTupleMap m_evtColMap
the actual storage of event collections by title and ID
Definition: GaudiTuples.h:391
static std::string print(const INTuple *tuple, const GaudiAlg::TupleID &ID)
Definition: Print.cpp:153
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:356
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:209
template<class PBASE >
void GaudiTuples< PBASE >::printNTupleHandler ( Gaudi::Details::PropertyBase )
private

handler for "NTuplePrint" property

Definition at line 374 of file GaudiTuples.icpp.

375 {
376  // no action if not yet initialized
377  if ( this->FSMState() < Gaudi::StateMachine::INITIALIZED ) return;
378  if ( this->tuplesPrint() ) this->printTuples();
379 }
long printTuples() const
perform the actual printout of N-tuples
bool tuplesPrint() const
print tuples at finalization
Definition: GaudiTuples.h:232
template<class PBASE >
long GaudiTuples< PBASE >::printTuples ( ) const

perform the actual printout of N-tuples

Returns
number of active N-Tuples

Definition at line 309 of file GaudiTuples.icpp.

310 {
311 
312  if ( m_nTupleMap.empty() ) {
313  if ( this->msgLevel( MSG::DEBUG ) ) this->debug() << "No N-Tuples are booked" << endmsg;
314  } else {
315  this->always() << "List of booked N-Tuples in directory "
316  << "\"" << nTuplePath() << "\"" << endmsg;
317  }
318 
319  for ( const auto& entry : this->nTupleOrdered() ) {
320  if ( !entry.tuple->tuple() ) {
321  this->error() << " NTuple::Tuple* points to NULL" << endmsg;
322  continue;
323  }
324  this->always() << GaudiAlg::PrintTuple::print( entry.tuple->tuple(), entry.id ) << endmsg;
325  }
326  //
327  return this->m_nTupleMap.size();
328 }
static std::string print(const INTuple *tuple, const GaudiAlg::TupleID &ID)
Definition: Print.cpp:153
nTupleMap m_nTupleMap
the actual storage of ntuples by title and ID
Definition: GaudiTuples.h:383
std::string nTuplePath() const
get the constructed N-Tuple path
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
template<class PBASE>
bool GaudiTuples< PBASE >::produceEvtCols ( ) const
inline

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

Definition at line 218 of file GaudiTuples.h.

218 { return m_produceEvtCols; }
Gaudi::Property< bool > m_produceEvtCols
Definition: GaudiTuples.h:344
template<class PBASE>
bool GaudiTuples< PBASE >::produceNTuples ( ) const
inline

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

Definition at line 204 of file GaudiTuples.h.

204 { return m_produceNTuples; }
Gaudi::Property< bool > m_produceNTuples
Definition: GaudiTuples.h:334
template<class PBASE>
bool GaudiTuples< PBASE >::splitEvtColDir ( ) const
inline

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

Definition at line 220 of file GaudiTuples.h.

220 { return m_splitEvtColDir; }
Gaudi::Property< bool > m_splitEvtColDir
Definition: GaudiTuples.h:347
template<class PBASE>
bool GaudiTuples< PBASE >::splitNTupleDir ( ) const
inline

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

Definition at line 206 of file GaudiTuples.h.

206 { return m_splitNTupleDir; }
Gaudi::Property< bool > m_splitNTupleDir
Definition: GaudiTuples.h:336
template<class PBASE>
bool GaudiTuples< PBASE >::tuplesPrint ( ) const
inline

print tuples at finalization

Definition at line 232 of file GaudiTuples.h.

232 { return m_tuplesPrint; }
Gaudi::Property< bool > m_tuplesPrint
Definition: GaudiTuples.h:335

Member Data Documentation

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

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

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

the actual storage of event collections by title and ID

Definition at line 391 of file GaudiTuples.h.

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

Definition at line 348 of file GaudiTuples.h.

template<class PBASE>
Gaudi::Property<bool> GaudiTuples< PBASE >::m_evtColsPrint {this, "EvtColsPrint", false, "print statistics for Event Tag Collections "}
private

Definition at line 346 of file GaudiTuples.h.

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

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

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

Definition at line 339 of file GaudiTuples.h.

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

the actual storage of ntuples by title and ID

Definition at line 383 of file GaudiTuples.h.

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

Definition at line 338 of file GaudiTuples.h.

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

Definition at line 340 of file GaudiTuples.h.

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

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

Definition at line 334 of file GaudiTuples.h.

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

Definition at line 347 of file GaudiTuples.h.

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

template<class PBASE>
Gaudi::Property<bool> GaudiTuples< PBASE >::m_tuplesPrint {this, "NTuplePrint", true, "print N-tuple statistics"}
private

Definition at line 335 of file GaudiTuples.h.


The documentation for this class was generated from the following files: