40 # pragma warning( disable : 4661 ) // incomplete explicit templates 46 template <
class PBASE>
58 if ( produceNTuples() ) {
60 if ( this->ntupleSvc() == 0 ) {
return this->Error(
"INTupleSvc* points to NULL!" ); }
66 this->debug() <<
"Production of N-Tuples is switched OFF" <<
endmsg;
69 if ( produceEvtCols() ) {
71 if ( 0 == this->evtColSvc() ) {
return this->Error(
"INTupleSvc* points to NULL!" ); }
77 this->debug() <<
"Production of Event Collections is switched OFF" <<
endmsg;
86 template <
class PBASE>
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;
100 if ( produceNTuples() && tuplesPrint() ) printTuples();
101 if ( produceEvtCols() && evtColsPrint() ) printEvtCols();
110 return PBASE::finalize();
116 template <
class PBASE>
119 auto&
m = nTupleByTitle();
120 auto tuple =
m.find( title );
121 if ( tuple !=
m.end() )
return Tuple( tuple->tuple );
124 if ( this->useNumericAutoIDs() || title.
empty() ) {
125 if ( !this->useNumericAutoIDs() ) {
127 "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for nTuple ID",
132 ID =
TupleID( m_nTupleMap.size() + 1 + nTupleOffSet() );
134 while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID =
TupleID( ID.
numeric() + 1 ); }
137 ID =
TupleID( this->convertTitleToID( title ) );
139 while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID =
TupleID( ID.
idAsString() +
"_" ); }
142 return nTuple( ID, title, clid );
149 template <
class PBASE>
152 auto&
m = evtColByTitle();
153 auto tuple =
m.find( title );
154 if ( tuple !=
m.end() )
return Tuple( tuple->tuple );
157 if ( this->useNumericAutoIDs() || title.
empty() ) {
158 if ( !this->useNumericAutoIDs() ) {
160 "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for evtCol ID",
165 ID =
TupleID( m_evtColMap.size() + 1 + evtColOffSet() );
167 while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID =
TupleID( ID.
numeric() + 1 ); }
170 ID =
TupleID( this->convertTitleToID( title ) );
172 while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID =
TupleID( ID.
idAsString() +
"_" ); }
175 return evtCol( ID, title, clid );
182 template <
class PBASE>
186 this->Error(
"Undefined NTuple ID : Title='" + title1 +
"'" ).ignore();
191 auto&
m = nTupleByID();
192 auto tuple =
m.find( ID );
193 if ( tuple !=
m.end() )
return Tuple( tuple->tuple );
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 );
210 tup = this->ntupleSvc()->book( nTuplePath(), ID.
numericID(), clid, title );
212 tup = this->ntupleSvc()->book( nTuplePath(), ID.
literalID(), clid, title );
214 this->Error(
"Undefined NTuple ID" ).ignore();
218 this->Assert( tup,
"Could not book the N-Tuple='" + title +
"'" );
221 this->debug() <<
"Booked NTuple '" << title <<
"' ID=" << tID <<
"' Path='" << nTuplePath() <<
"' TS='" 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 );
231 template <
class PBASE>
235 this->Error(
"Undefined NTuple ID : Title='" + title1 +
"'" ).ignore();
240 auto& tuple = evtColByID();
241 auto i = tuple.find( ID );
242 if ( i != tuple.end() )
return Tuple( i->tuple );
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 );
259 tup = this->evtColSvc()->book( evtColPath(), ID.
numericID(), clid, title );
261 tup = this->evtColSvc()->book( evtColPath(), ID.
literalID(), clid, title );
263 this->Error(
"Undefined NTuple ID" ).ignore();
267 this->Assert( tup,
"Could not book the EvtCol='" + title +
"'" );
270 this->debug() <<
"Booked EvtCol '" << title <<
"' ID=" << tID <<
"' Path='" << evtColPath() <<
"' TS='" 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 );
280 template <
class PBASE>
282 const CLID& clid )
const {
290 template <
class PBASE>
292 const CLID& clid )
const {
298 template <
class PBASE>
301 if ( m_nTupleMap.empty() ) {
302 if ( this->msgLevel(
MSG::DEBUG ) ) this->debug() <<
"No N-Tuples are booked" <<
endmsg;
304 this->always() <<
"List of booked N-Tuples in directory " 305 <<
"\"" << nTuplePath() <<
"\"" <<
endmsg;
308 for (
const auto& entry : this->nTupleOrdered() ) {
309 if ( !entry.tuple->tuple() ) {
310 this->error() <<
" NTuple::Tuple* points to NULL" <<
endmsg;
316 return this->m_nTupleMap.size();
321 template <
class PBASE>
323 if ( m_evtColMap.empty() ) {
324 this->always() <<
"No Event Tag Collections are booked" <<
endmsg;
326 this->always() <<
"List of booked Event Tag Collections in directory " 327 <<
"\"" << evtColPath() <<
"\"" <<
endmsg;
329 for (
const auto& entry : this->evtColOrdered() ) {
330 if ( !entry.tuple->tuple() ) {
331 this->error() <<
" NTuple::Tuple* points to NULL" <<
endmsg;
338 return this->m_evtColMap.size();
343 template <
class PBASE>
345 auto&
m = nTupleByID();
346 return m.find( ID ) !=
m.end();
351 template <
class PBASE>
353 auto&
m = evtColByID();
354 return m.find( ID ) !=
m.end();
359 template <
class PBASE>
361 const std::string path = nTupleLUN() +
"/" + nTupleTopDir() + nTupleDir();
362 return splitNTupleDir() ? dirHbookName(
path ) :
path;
367 template <
class PBASE>
370 return splitEvtColDir() ? dirHbookName(
path ) :
path;
const LiteralID & literalID() const noexcept
Returns the ID as a LiteralID.
static std::string print(const INTuple *tuple, const GaudiAlg::TupleID &ID)
std::string nTuplePath() const
get the constructed N-Tuple path
IRegistry * registry() const
Get pointer to Registry.
long printTuples() const
perform the actual printout of N-tuples
virtual std::unique_ptr< Tuples::TupleObj > createEvtCol(const std::string &name, NTuple::Tuple *tuple, const CLID &clid) const
create TupleObj for event tag collection
Templated base class providing common 'ntupling' methods.
Header file for class TupleObj.
bool evtColExists(const TupleID &ID) const
check the existence AND validity of the Event Tag Collection with the given ID
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
long printEvtCols() const
perform the actual printout of Event Tag Collections
bool nTupleExists(const TupleID &ID) const
check the existence AND validity of the N-Tuple with the given ID
constexpr static const auto SUCCESS
few useful function to construct names of Hbook histograms and directories functions are imported fro...
NumericID numericID() const noexcept
Returns the numerical ID.
GAUDI_API LiteralID idAsString() const
Return ID as string, for both numeric and literal IDs.
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Tuple nTuple(const std::string &title, const CLID &clid=CLID_ColumnWiseTuple) const
Access an N-Tuple object (book on-demand) with unique identifier.
bool undefined() const noexcept
Is this ID undefined.
bool literal() const noexcept
Is this ID numeric.
This class is used for returning status codes from appropriate routines.
GaudiAlg::ID TupleID
the actual type for N-Tuple identifier (HBOOK-style)
collection of useful utilities to print certain objects (currently used for implementation in class G...
unsigned int CLID
Class ID definition.
Collection of few 'technical' methods for instantiation of tuples.
Abstract base class which allows the user to interact with the actual N tuple implementation.
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...
Tuple evtCol(const std::string &title, const CLID &clid=CLID_ColumnWiseTuple) const
Access an Event Tag Collection object (book on-demand) with unique identifier.
virtual std::unique_ptr< Tuples::TupleObj > createNTuple(const std::string &name, NTuple::Tuple *tuple, const CLID &clid) const
create TupleObj
std::string evtColPath() const
get the constructed Event Tag Collection path
bool numeric() const noexcept
Is this ID numeric.
virtual const id_type & identifier() const =0
Full identifier (or key)
implementation of various functions for streaming.
def nTuple(dirpath, ID, ID2=None, topdir=None, LUN='FILE1')
ID class for Histogram and Ntuples.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Header file for class : Tuple.