The Gaudi Framework  v31r0 (aeb156f0)
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 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 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 357 of file GaudiTuples.h.

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

the actual type for histogram identifier

Definition at line 47 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 355 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 361 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 359 of file GaudiTuples.h.

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

Definition at line 363 of file GaudiTuples.h.

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

the actual type of the tuple

Definition at line 49 of file GaudiTuples.h.

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

the actual type of N-tuple ID

Definition at line 51 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 277 of file GaudiTuples.h.

277 : PBASE( name, pSvcLocator ) {}
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 281 of file GaudiTuples.h.

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

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

282  {
283  return Tuples::createTupleObj( this, "EvtCol '" + name + "'", tuple, clid, Tuples::EVTCOL );
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:215
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 271 of file GaudiTuples.icpp.

272  {
273  return Tuples::createTupleObj( this, "Tuple '" + name + "'", tuple, clid, Tuples::NTUPLE );
274 }
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:215
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 140 of file GaudiTuples.icpp.

140  {
141  // look up in the table
142  auto& m = evtColByTitle();
143  auto tuple = m.find( title );
144  if ( tuple != m.end() ) return Tuple( tuple->tuple ); // RETURN
145  // Create the tuple ID
146  TupleID ID;
147  if ( this->useNumericAutoIDs() || title.empty() ) {
148  if ( !this->useNumericAutoIDs() ) {
149  this->Warning(
150  "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for evtCol ID",
152  .ignore();
153  }
154  // proposed the tuple ID
155  ID = TupleID( m_evtColMap.size() + 1 + evtColOffSet() );
156  // adjust the proposed ID
157  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.numeric() + 1 ); }
158  } else {
159  // use the title to create a unique literal ID
160  ID = TupleID( this->convertTitleToID( title ) );
161  // Just in case ...
162  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.idAsString() + "_" ); }
163  }
164  // return
165  return evtCol( ID, title, clid );
166 }
nTupleMap m_evtColMap
the actual storage of event collections by title and ID
Definition: GaudiTuples.h:379
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:49
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
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:51
constexpr double m
Definition: SystemOfUnits.h:92
bool evtColExists(const TupleID &ID) const
check the existence AND validity of the Event Tag Collection with the given ID
TupleID::NumericID evtColOffSet() const
get the value for Event Tag Collection offset (property "EvtColsOffSet")
Definition: GaudiTuples.h:227
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 222 of file GaudiTuples.icpp.

222  {
223  // Check ID
224  if ( ID.undefined() ) {
225  this->Error( "Undefined NTuple ID : Title='" + title1 + "'" ).ignore();
226  return Tuple( 0 );
227  }
228 
229  // look up in the table
230  auto& tuple = evtColByID();
231  auto i = tuple.find( ID );
232  if ( i != tuple.end() ) return Tuple( i->tuple ); // RETURN
233 
234  // convert ID to the string
235  const std::string tID = ID.idAsString();
236 
237  // adjust the NTuple title
238  const std::string title = title1.empty() ? ( "EvtCol #" + tID ) : title1;
239 
240  // book new ntuple
241  if ( !produceEvtCols() ) {
242  auto r = m_evtColMap.insert( nTupleMapItem{title, ID, createEvtCol( title, nullptr, clid )} );
243  if ( !r.second ) this->Error( "Failure to createEvtCol" ).ignore();
244  return Tuple( r.first->tuple );
245  }
246  // book NTuple
247  NTuple::Tuple* tup = nullptr;
248  if ( ID.numeric() ) {
249  tup = this->evtColSvc()->book( evtColPath(), ID.numericID(), clid, title );
250  } else if ( ID.literal() ) {
251  tup = this->evtColSvc()->book( evtColPath(), ID.literalID(), clid, title );
252  } else {
253  this->Error( "Undefined NTuple ID" ).ignore();
254  }
255 
256  // assertion
257  this->Assert( tup, "Could not book the EvtCol='" + title + "'" );
258  // some printout
259  if ( tup->registry() && this->msgLevel( MSG::DEBUG ) ) {
260  this->debug() << "Booked EvtCol '" << title << "' ID=" << tID << "' Path='" << evtColPath() << "' TS='"
261  << tup->registry()->identifier() << "'" << endmsg;
262  }
263  auto r = m_evtColMap.insert( nTupleMapItem{title, ID, createEvtCol( title, tup, clid )} );
264  if ( !r.second ) this->Error( "Failure to createEvtCol" ).ignore();
265  return Tuple( r.first->tuple );
266 }
nTupleMap m_evtColMap
the actual storage of event collections by title and ID
Definition: GaudiTuples.h:379
T empty(T...args)
Tuples::Tuple Tuple
the actual type of the tuple
Definition: GaudiTuples.h:49
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
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:375
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:217
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
template<class PBASE>
const std::string& GaudiTuples< PBASE >::evtColDir ( ) const
inline

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

Definition at line 225 of file GaudiTuples.h.

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

342  {
343  auto& m = evtColByID();
344  return m.find( ID ) != m.end();
345 }
constexpr double m
Definition: SystemOfUnits.h:92
template<class PBASE>
const std::string& GaudiTuples< PBASE >::evtColLUN ( ) const
inline

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

Definition at line 221 of file GaudiTuples.h.

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

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

Definition at line 227 of file GaudiTuples.h.

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

get the constructed Event Tag Collection path

Definition at line 358 of file GaudiTuples.icpp.

358  {
359  std::string path = evtColLUN() + "/" + evtColTopDir() + evtColDir();
360  return splitEvtColDir() ? dirHbookName( path ) : path;
361 }
bool splitEvtColDir() const
get the flag for Event Tag Collection path split (property "EvtColsSplitDir")
Definition: GaudiTuples.h:219
const std::string & evtColDir() const
get the Event Tag Collection directory (property "EvtColsDir")
Definition: GaudiTuples.h:225
const std::string & evtColTopDir() const
get the top-level Event Tag Collection directory (property "EvtColsTopDir")
Definition: GaudiTuples.h:223
STL class.
const std::string & evtColLUN() const
get the logical unit for Event Tag Collections (property "EvtColsLUN")
Definition: GaudiTuples.h:221
template<class PBASE>
bool GaudiTuples< PBASE >::evtColsPrint ( ) const
inline

print event collections at finalization

Definition at line 233 of file GaudiTuples.h.

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

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

Definition at line 223 of file GaudiTuples.h.

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

standard finalization method

Returns
status code

Definition at line 83 of file GaudiTuples.icpp.

83  {
84  if ( !( m_nTupleMap.empty() && m_evtColMap.empty() ) ) {
85  const int nNtuples = m_nTupleMap.size();
86  const int nEvtCols = m_evtColMap.size();
87  this->always() << "Booked " << nNtuples << " N-Tuples and " << nEvtCols << " Event Tag Collections" << endmsg;
88  }
89 
90  if ( produceNTuples() && tuplesPrint() ) printTuples();
92 
93  // release ntuples and clear the container
94  m_nTupleMap.clear();
95 
96  // release ntuples and clear the container
97  m_evtColMap.clear();
98 
99  // finalize base class
100  return PBASE::finalize();
101 }
nTupleMap m_evtColMap
the actual storage of event collections by title and ID
Definition: GaudiTuples.h:379
bool evtColsPrint() const
print event collections at finalization
Definition: GaudiTuples.h:233
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:371
bool tuplesPrint() const
print tuples at finalization
Definition: GaudiTuples.h:231
bool produceEvtCols() const
get the flag for Event Tag Collection production (property "EvtColsProduce")
Definition: GaudiTuples.h:217
bool produceNTuples() const
get the flag for N-Tuple production (property "NTupleProduce")
Definition: GaudiTuples.h:203
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
template<class PBASE >
StatusCode GaudiTuples< PBASE >::initialize ( )
overrideprotected

standard initialization method

Returns
status code

Definition at line 43 of file GaudiTuples.icpp.

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

107  {
108  // look up in the table
109  auto& m = nTupleByTitle();
110  auto tuple = m.find( title );
111  if ( tuple != m.end() ) return Tuple( tuple->tuple ); // RETURN
112  // Create the tuple ID
113  TupleID ID;
114  if ( this->useNumericAutoIDs() || title.empty() ) {
115  if ( !this->useNumericAutoIDs() ) {
116  this->Warning(
117  "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for nTuple ID",
119  .ignore();
120  }
121  // propose the tuple ID
122  ID = TupleID( m_nTupleMap.size() + 1 + nTupleOffSet() );
123  // adjust the proposed ID
124  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.numeric() + 1 ); }
125  } else {
126  // use the title to create a unique literal ID
127  ID = TupleID( this->convertTitleToID( title ) );
128  // Just in case ...
129  while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID = TupleID( ID.idAsString() + "_" ); }
130  }
131  // return
132  return nTuple( ID, title, clid );
133 }
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:49
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
GaudiAlg::TupleID TupleID
the actual type of N-tuple ID
Definition: GaudiTuples.h:51
TupleID::NumericID nTupleOffSet() const
get the value for N-Tuple offset (property "NTupleOffSet")
Definition: GaudiTuples.h:213
constexpr double m
Definition: SystemOfUnits.h:92
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:371
bool evtColExists(const TupleID &ID) const
check the existence AND validity of the Event Tag Collection with the given ID
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 173 of file GaudiTuples.icpp.

173  {
174  // Check ID
175  if ( ID.undefined() ) {
176  this->Error( "Undefined NTuple ID : Title='" + title1 + "'" ).ignore();
177  return Tuple( 0 );
178  }
179 
180  // look up in the table
181  auto& m = nTupleByID();
182  auto tuple = m.find( ID );
183  if ( tuple != m.end() ) return Tuple( tuple->tuple ); // RETURN
184 
185  // convert ID to the string
186  const std::string tID = ID.idAsString();
187 
188  // adjust the NTuple title
189  const std::string title = title1.empty() ? ( "NTuple #" + tID ) : title1;
190 
191  // book new ntuple
192  if ( !produceNTuples() ) {
193  auto r = m_nTupleMap.insert( nTupleMapItem{title, ID, createNTuple( title, nullptr, clid )} );
194  if ( !r.second ) this->Error( "Failure to createNTuple" ).ignore();
195  return Tuple( r.first->tuple );
196  }
197  // book NTupel
198  NTuple::Tuple* tup = nullptr;
199  if ( ID.numeric() ) {
200  tup = this->ntupleSvc()->book( nTuplePath(), ID.numericID(), clid, title );
201  } else if ( ID.literal() ) {
202  tup = this->ntupleSvc()->book( nTuplePath(), ID.literalID(), clid, title );
203  } else {
204  this->Error( "Undefined NTuple ID" ).ignore();
205  }
206 
207  // assertion
208  this->Assert( tup, "Could not book the N-Tuple='" + title + "'" );
209  // some printout
210  if ( tup->registry() && this->msgLevel( MSG::DEBUG ) ) {
211  this->debug() << "Booked NTuple '" << title << "' ID=" << tID << "' Path='" << nTuplePath() << "' TS='"
212  << tup->registry()->identifier() << "'" << endmsg;
213  }
214 
215  auto r = m_nTupleMap.insert( nTupleMapItem{title, ID, createNTuple( title, tup, clid )} );
216  if ( !r.second ) this->Error( "Failure to createNTuple" ).ignore();
217  return Tuple( r.first->tuple );
218  //
219 }
T empty(T...args)
Tuples::Tuple Tuple
the actual type of the tuple
Definition: GaudiTuples.h:49
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
STL class.
virtual const id_type & identifier() const =0
Full identifier (or key)
constexpr double m
Definition: SystemOfUnits.h:92
nTupleMap m_nTupleMap
the actual storage of ntuples by title and ID
Definition: GaudiTuples.h:371
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:375
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:203
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
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 211 of file GaudiTuples.h.

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

334  {
335  auto& m = nTupleByID();
336  return m.find( ID ) != m.end();
337 }
constexpr double m
Definition: SystemOfUnits.h:92
template<class PBASE>
const std::string& GaudiTuples< PBASE >::nTupleLUN ( ) const
inline

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

Definition at line 207 of file GaudiTuples.h.

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

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

Definition at line 213 of file GaudiTuples.h.

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

get the constructed N-Tuple path

Definition at line 350 of file GaudiTuples.icpp.

350  {
351  const std::string path = nTupleLUN() + "/" + nTupleTopDir() + nTupleDir();
352  return splitNTupleDir() ? dirHbookName( path ) : path;
353 }
const std::string & nTupleLUN() const
get the logical unit for N-Tuples (property "NTupleLUN")
Definition: GaudiTuples.h:207
const std::string & nTupleTopDir() const
get the top-level N-Tuple directory (property "NTupleTopDir")
Definition: GaudiTuples.h:209
STL class.
const std::string & nTupleDir() const
get the N-Tuple directory (property "NTupleDir")
Definition: GaudiTuples.h:211
bool splitNTupleDir() const
get the flag for N-Tuple path split (property "NTupleSplitDir")
Definition: GaudiTuples.h:205
template<class PBASE>
const std::string& GaudiTuples< PBASE >::nTupleTopDir ( ) const
inline

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

Definition at line 209 of file GaudiTuples.h.

209 { return m_nTupleTopDir; }
Gaudi::Property< std::string > m_nTupleTopDir
Definition: GaudiTuples.h:324
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 312 of file GaudiTuples.icpp.

312  {
313  if ( m_evtColMap.empty() ) {
314  this->always() << "No Event Tag Collections are booked" << endmsg;
315  } else {
316  this->always() << "List of booked Event Tag Collections in directory "
317  << "\"" << evtColPath() << "\"" << endmsg;
318  }
319  for ( const auto& entry : this->evtColOrdered() ) {
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 )
325  << " Items:" << Gaudi::Utils::toString( entry.tuple->items() ) << endmsg;
326  }
327  //
328  return this->m_evtColMap.size();
329 }
nTupleMap m_evtColMap
the actual storage of event collections by title and ID
Definition: GaudiTuples.h:379
static std::string print(const INTuple *tuple, const GaudiAlg::TupleID &ID)
Definition: Print.cpp:134
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:334
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:192
template<class PBASE >
long GaudiTuples< PBASE >::printTuples ( ) const

perform the actual printout of N-tuples

Returns
number of active N-Tuples

Definition at line 289 of file GaudiTuples.icpp.

289  {
290 
291  if ( m_nTupleMap.empty() ) {
292  if ( this->msgLevel( MSG::DEBUG ) ) this->debug() << "No N-Tuples are booked" << endmsg;
293  } else {
294  this->always() << "List of booked N-Tuples in directory "
295  << "\"" << nTuplePath() << "\"" << endmsg;
296  }
297 
298  for ( const auto& entry : this->nTupleOrdered() ) {
299  if ( !entry.tuple->tuple() ) {
300  this->error() << " NTuple::Tuple* points to NULL" << endmsg;
301  continue;
302  }
303  this->always() << GaudiAlg::PrintTuple::print( entry.tuple->tuple(), entry.id ) << endmsg;
304  }
305  //
306  return this->m_nTupleMap.size();
307 }
static std::string print(const INTuple *tuple, const GaudiAlg::TupleID &ID)
Definition: Print.cpp:134
nTupleMap m_nTupleMap
the actual storage of ntuples by title and ID
Definition: GaudiTuples.h:371
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:192
template<class PBASE>
bool GaudiTuples< PBASE >::produceEvtCols ( ) const
inline

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

Definition at line 217 of file GaudiTuples.h.

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

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

Definition at line 203 of file GaudiTuples.h.

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

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

Definition at line 219 of file GaudiTuples.h.

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

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

Definition at line 205 of file GaudiTuples.h.

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

print tuples at finalization

Definition at line 231 of file GaudiTuples.h.

231 { return m_tuplesPrint; }
Gaudi::Property< bool > m_tuplesPrint
Definition: GaudiTuples.h:312

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 343 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 340 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 379 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 339 of file GaudiTuples.h.

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 330 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 341 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 325 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 323 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 371 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 322 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 324 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 328 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 311 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 338 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 320 of file GaudiTuples.h.

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


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