30 # pragma warning( disable : 4661 ) // incomplete explicit templates 36 template <
class PBASE>
48 if ( produceNTuples() ) {
50 if ( this->ntupleSvc() == 0 ) {
return this->Error(
"INTupleSvc* points to NULL!" ); }
56 this->debug() <<
"Production of N-Tuples is switched OFF" <<
endmsg;
59 if ( produceEvtCols() ) {
61 if ( 0 == this->evtColSvc() ) {
return this->Error(
"INTupleSvc* points to NULL!" ); }
67 this->debug() <<
"Production of Event Collections is switched OFF" <<
endmsg;
76 template <
class PBASE>
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;
90 if ( produceNTuples() && tuplesPrint() ) printTuples();
91 if ( produceEvtCols() && evtColsPrint() ) printEvtCols();
100 return PBASE::finalize();
106 template <
class PBASE>
109 auto&
m = nTupleByTitle();
110 auto tuple =
m.find( title );
111 if ( tuple !=
m.end() )
return Tuple( tuple->tuple );
114 if ( this->useNumericAutoIDs() || title.
empty() ) {
115 if ( !this->useNumericAutoIDs() ) {
117 "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for nTuple ID",
122 ID =
TupleID( m_nTupleMap.size() + 1 + nTupleOffSet() );
124 while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID =
TupleID( ID.
numeric() + 1 ); }
127 ID =
TupleID( this->convertTitleToID( title ) );
129 while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID =
TupleID( ID.
idAsString() +
"_" ); }
132 return nTuple( ID, title, clid );
139 template <
class PBASE>
142 auto&
m = evtColByTitle();
143 auto tuple =
m.find( title );
144 if ( tuple !=
m.end() )
return Tuple( tuple->tuple );
147 if ( this->useNumericAutoIDs() || title.
empty() ) {
148 if ( !this->useNumericAutoIDs() ) {
150 "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for evtCol ID",
155 ID =
TupleID( m_evtColMap.size() + 1 + evtColOffSet() );
157 while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID =
TupleID( ID.
numeric() + 1 ); }
160 ID =
TupleID( this->convertTitleToID( title ) );
162 while ( nTupleExists( ID ) || evtColExists( ID ) ) { ID =
TupleID( ID.
idAsString() +
"_" ); }
165 return evtCol( ID, title, clid );
172 template <
class PBASE>
176 this->Error(
"Undefined NTuple ID : Title='" + title1 +
"'" ).ignore();
181 auto&
m = nTupleByID();
182 auto tuple =
m.find( ID );
183 if ( tuple !=
m.end() )
return Tuple( tuple->tuple );
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 );
200 tup = this->ntupleSvc()->book( nTuplePath(), ID.
numericID(), clid, title );
202 tup = this->ntupleSvc()->book( nTuplePath(), ID.
literalID(), clid, title );
204 this->Error(
"Undefined NTuple ID" ).ignore();
208 this->Assert( tup,
"Could not book the N-Tuple='" + title +
"'" );
211 this->debug() <<
"Booked NTuple '" << title <<
"' ID=" << tID <<
"' Path='" << nTuplePath() <<
"' TS='" 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 );
221 template <
class PBASE>
225 this->Error(
"Undefined NTuple ID : Title='" + title1 +
"'" ).ignore();
230 auto& tuple = evtColByID();
231 auto i = tuple.find( ID );
232 if ( i != tuple.end() )
return Tuple( i->tuple );
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 );
249 tup = this->evtColSvc()->book( evtColPath(), ID.
numericID(), clid, title );
251 tup = this->evtColSvc()->book( evtColPath(), ID.
literalID(), clid, title );
253 this->Error(
"Undefined NTuple ID" ).ignore();
257 this->Assert( tup,
"Could not book the EvtCol='" + title +
"'" );
260 this->debug() <<
"Booked EvtCol '" << title <<
"' ID=" << tID <<
"' Path='" << evtColPath() <<
"' TS='" 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 );
270 template <
class PBASE>
272 const CLID& clid )
const {
280 template <
class PBASE>
282 const CLID& clid )
const {
288 template <
class PBASE>
291 if ( m_nTupleMap.empty() ) {
292 if ( this->msgLevel(
MSG::DEBUG ) ) this->debug() <<
"No N-Tuples are booked" <<
endmsg;
294 this->always() <<
"List of booked N-Tuples in directory " 295 <<
"\"" << nTuplePath() <<
"\"" <<
endmsg;
298 for (
const auto& entry : this->nTupleOrdered() ) {
299 if ( !entry.tuple->tuple() ) {
300 this->error() <<
" NTuple::Tuple* points to NULL" <<
endmsg;
306 return this->m_nTupleMap.size();
311 template <
class PBASE>
313 if ( m_evtColMap.empty() ) {
314 this->always() <<
"No Event Tag Collections are booked" <<
endmsg;
316 this->always() <<
"List of booked Event Tag Collections in directory " 317 <<
"\"" << evtColPath() <<
"\"" <<
endmsg;
319 for (
const auto& entry : this->evtColOrdered() ) {
320 if ( !entry.tuple->tuple() ) {
321 this->error() <<
" NTuple::Tuple* points to NULL" <<
endmsg;
328 return this->m_evtColMap.size();
333 template <
class PBASE>
335 auto&
m = nTupleByID();
336 return m.find( ID ) !=
m.end();
341 template <
class PBASE>
343 auto&
m = evtColByID();
344 return m.find( ID ) !=
m.end();
349 template <
class PBASE>
351 const std::string path = nTupleLUN() +
"/" + nTupleTopDir() + nTupleDir();
352 return splitNTupleDir() ? dirHbookName( path ) :
path;
357 template <
class PBASE>
360 return splitEvtColDir() ? dirHbookName( path ) :
path;
static std::string print(const INTuple *tuple, const GaudiAlg::TupleID &ID)
bool nTupleExists(const TupleID &ID) const
check the existence AND validity of the N-Tuple with the given ID
Templated base class providing common 'ntupling' methods.
Header file for class TupleObj.
NumericID numericID() const noexcept
Returns the numerical ID.
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
constexpr static const auto SUCCESS
Tuple evtCol(const std::string &title, const CLID &clid=CLID_ColumnWiseTuple) const
Access an Event Tag Collection object (book on-demand) with unique identifier.
few useful function to construct names of Hbook histograms and directories functions are imported fro...
IRegistry * registry() const
Get pointer to Registry.
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
long printTuples() const
perform the actual printout of N-tuples
virtual const id_type & identifier() const =0
Full identifier (or key)
long printEvtCols() const
perform the actual printout of Event Tag Collections
This class is used for returning status codes from appropriate routines.
Tuple nTuple(const std::string &title, const CLID &clid=CLID_ColumnWiseTuple) const
Access an N-Tuple object (book on-demand) with unique identifier.
bool literal() const noexcept
Is this ID numeric.
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.
virtual std::unique_ptr< Tuples::TupleObj > createEvtCol(const std::string &name, NTuple::Tuple *tuple, const CLID &clid) const
create TupleObj for event tag collection
bool evtColExists(const TupleID &ID) const
check the existence AND validity of the Event Tag Collection with the given ID
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...
std::string evtColPath() const
get the constructed Event Tag Collection path
std::string nTuplePath() const
get the constructed N-Tuple path
const LiteralID & literalID() const noexcept
Returns the ID as a LiteralID.
GAUDI_API LiteralID idAsString() const
Return ID as string, for both numeric and literal IDs.
bool numeric() const noexcept
Is this ID numeric.
implementation of various functions for streaming.
bool undefined() const noexcept
Is this ID undefined.
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.
virtual std::unique_ptr< Tuples::TupleObj > createNTuple(const std::string &name, NTuple::Tuple *tuple, const CLID &clid) const
create TupleObj