6 #include "GaudiKernel/IRegistry.h"
7 #include "GaudiKernel/ToStream.h"
11 #include "GaudiAlg/GaudiTuples.h"
12 #include "GaudiAlg/Tuple.h"
13 #include "GaudiAlg/TupleObj.h"
14 #include "GaudiAlg/GaudiTupleAlg.h"
15 #include "GaudiAlg/TupleDetail.h"
16 #include "GaudiAlg/Print.h"
17 #include "GaudiAlg/HbookName.h"
30 #pragma warning ( disable:4661 ) // incomplete explicit templates
36 constexpr
struct releaseAndClear_t {
37 template <
typename C>
void operator()(C&
c)
const {
38 for (
auto&
i : c )
if (
i.second)
i.second->release();
43 constexpr
struct ordered_t {
45 std::map<typename C::key_type, typename C::mapped_type> operator()(
const C& c)
const {
54 template <
class PBASE>
67 if ( produceNTuples() )
70 if ( this->ntupleSvc() == 0 )
71 {
return this->Error(
"INTupleSvc* points to NULL!" ); }
73 this->Print(
"The N-Tuple path is set to be '" + nTuplePath() +
"'",
77 { this->debug() <<
"Production of N-Tuples is switched OFF" <<
endmsg; }
79 if ( produceEvtCols() )
82 if ( 0 == this->evtColSvc() )
83 {
return this->Error(
"INTupleSvc* points to NULL!" ); }
85 this->Print(
"The EventCol path is set to be '" + evtColPath() +
"'",
89 { this->debug() <<
"Production of Event Collections is switched OFF" <<
endmsg; }
97 template <
class PBASE>
106 if ( !( nTupleMapTitle () . empty () &&
107 nTupleMapID () . empty () &&
108 evtColMapTitle () . empty () &&
109 evtColMapID () . empty ()
112 const int nNtuples = nTupleMapID () . size () ;
113 const int nEvtCols = evtColMapID () . size ();
115 <<
"Booked " << nNtuples <<
" N-Tuples and " << nEvtCols
116 <<
" Event Tag Collections" <<
endmsg ;
119 if ( produceNTuples () && tuplesPrint () ) { printTuples () ; }
120 if ( produceEvtCols () && evtColsPrint () ) { printEvtCols () ; }
123 releaseAndClear(m_nTupleMapTitle);
126 releaseAndClear(m_nTupleMapID);
129 releaseAndClear(m_evtColMapTitle);
132 releaseAndClear(m_evtColMapID);
135 return PBASE::finalize();
141 template <
class PBASE>
143 (
const std::string& title ,
144 const CLID& clid )
const
147 auto* tuple = m_nTupleMapTitle[ title ] ;
148 if ( tuple ) {
return Tuple( tuple ) ; }
151 if ( this->useNumericAutoIDs() || title.empty() )
153 if ( ! this->useNumericAutoIDs() )
155 this -> Warning(
"Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for nTuple ID",
159 ID =
TupleID ( m_nTupleMapID.size() + 1 + nTupleOffSet() );
161 while ( nTupleExists(ID) || evtColExists(ID) )
167 ID =
TupleID( this->convertTitleToID(title) );
169 while ( nTupleExists(ID) || evtColExists(ID) )
173 return nTuple( ID , title , clid ) ;
180 template <
class PBASE>
182 (
const std::string& title ,
183 const CLID& clid )
const
187 if ( tuple ) {
return Tuple( tuple ) ; }
190 if ( this->useNumericAutoIDs() || title.empty() )
192 if ( ! this->useNumericAutoIDs() )
194 this -> Warning(
"Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for evtCol ID",
198 ID =
TupleID ( m_evtColMapID.size() + 1 + evtColOffSet() ) ;
200 while ( nTupleExists(ID) || evtColExists(ID) )
206 ID =
TupleID( this->convertTitleToID(title) );
208 while ( nTupleExists(ID) || evtColExists(ID) )
212 return evtCol( ID , title , clid ) ;
219 template <
class PBASE>
222 const std::string& title1 ,
223 const CLID& clid )
const
227 { this->Error(
"Undefined NTuple ID : Title='"+title1+
"'");
return Tuple(0); }
231 if( tuple ) {
return Tuple( tuple ) ; }
237 const std::string title = title1.empty() ? (
"NTuple #" + tID ) : title1 ;
240 if( produceNTuples() )
246 tup = this->ntupleSvc() ->
book ( nTuplePath() , ID.
numericID() , clid , title );
250 tup = this->ntupleSvc() ->
book ( nTuplePath() , ID.
literalID() , clid , title );
252 else { this->Error(
"Undefined NTuple ID" ); }
255 this->Assert( tup ,
"Could not book the N-Tuple='" + title +
"'" ) ;
258 { this->debug() <<
"Booked NTuple '" << title <<
"' ID=" << tID
259 <<
"' Path='" << nTuplePath() <<
"' TS='"
262 tuple = createNTuple ( title , tup , clid ) ;
271 m_nTupleMapID [ ID ] = tuple ;
274 m_nTupleMapTitle[ title ] = tuple ;
276 return Tuple( tuple ) ;
279 template <
class PBASE>
282 const std::string& title1 ,
283 const CLID& clid )
const
287 { this->Error(
"Undefined NTuple ID : Title='"+title1+
"'");
return Tuple(0); }
291 if ( tuple ) {
return Tuple( tuple ) ; }
297 const std::string title = title1.empty() ? (
"EvtCol #" + tID ) : title1 ;
300 if( produceEvtCols() )
306 tup = this->evtColSvc()->book ( evtColPath() , ID.
numericID() , clid , title ) ;
310 tup = this->evtColSvc()->book ( evtColPath() , ID.
literalID() , clid , title ) ;
312 else { this->Error(
"Undefined NTuple ID" ); }
315 this->Assert( tup ,
"Could not book the EvtCol='" + title +
"'" ) ;
318 { this->debug() <<
"Booked EvtCol '" << title <<
"' ID=" << tID
319 <<
"' Path='" << evtColPath() <<
"' TS='"
322 tuple = createEvtCol ( title , tup , clid ) ;
331 m_evtColMapID [ ID ] = tuple ;
334 m_evtColMapTitle[ title ] = tuple ;
336 return Tuple( tuple ) ;
341 template <
class PBASE>
345 const CLID& clid )
const
348 (
this ,
"Tuple '" + name +
"'" , tuple , clid ,
Tuples::NTUPLE ) ;
355 template <
class PBASE>
357 (
const std::string& name ,
359 const CLID& clid )
const
362 (
this ,
"EvtCol '" + name +
"'" , tuple , clid ,
Tuples::EVTCOL ) ;
367 template <
class PBASE>
371 if ( nTupleMapTitle().empty() && nTupleMapID().empty() )
372 {
if (this->msgLevel(
MSG::DEBUG)) this->debug() <<
"No N-Tuples are booked" <<
endmsg ; }
374 { this->always() <<
"List of booked N-Tuples in directory "
375 <<
"\"" << nTuplePath() <<
"\"" <<
endmsg ; }
377 for (
const auto& entry : ordered(nTupleMapID()) )
379 if ( !entry.second ) { continue ; }
382 { this->error() <<
" NTuple::Tuple* points to NULL" <<
endmsg ; continue ; }
386 return this->nTupleMapID().size() ;
391 template <
class PBASE>
394 if ( evtColMapTitle().empty() && evtColMapID().empty() )
395 { this->always() <<
"No Event Tag Collections are booked" <<
endmsg ; }
397 { this->always() <<
"List of booked Event Tag Collections in directory "
398 <<
"\"" << evtColPath() <<
"\"" <<
endmsg ; }
399 for (
const auto& entry : ordered( evtColMapID() ) )
401 if ( !entry.second ) { continue ; }
402 const auto tuple = entry.second->tuple() ;
404 { this->error() <<
" NTuple::Tuple* points to NULL" <<
endmsg ; continue ; }
410 return this->evtColMapID().size() ;
415 template <
class PBASE>
418 return m_nTupleMapID.end() != m_nTupleMapID.find ( ID ) ;
423 template <
class PBASE>
426 return m_evtColMapID.end() != m_evtColMapID.find ( ID ) ;
431 template <
class PBASE>
436 if (
this -> tuplesPrint() ) {
this -> printTuples () ; }
441 template <
class PBASE>
446 if (
this -> evtColsPrint() ) {
this -> printEvtCols () ; }
451 template <
class PBASE>
454 const std::string
path = nTupleLUN() +
"/" + nTupleTopDir() + nTupleDir();
455 return ( splitNTupleDir() ? dirHbookName( path ) : path ) ;
460 template <
class PBASE>
463 std::string
path = evtColLUN() +
"/" + evtColTopDir() + evtColDir();
464 return ( splitEvtColDir() ? dirHbookName( path ) : path );
TupleObj * 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...
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
virtual 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.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
auto begin(reverse_wrapper< T > &w)
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Tuple evtCol(const std::string &title, const CLID &clid=CLID_ColumnWiseTuple) const
Access an Event Tag Collection object (book on-demand) with unique identifier.
bool isFailure() const
Test for a status code of FAILURE.
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
void printEvtColHandler(Property &)
handler for "EvtColsPrint" property
NumericID numericID() const
Returns the numerical ID.
long printTuples() const
perform the actual printout of N-tuples
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
auto end(reverse_wrapper< T > &w)
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.
const LiteralID & literalID() const
Returns the ID as a LiteralID.
GaudiAlg::ID TupleID
the actual type for N-Tuple identifier (HBOOK-style)
def nTuple
Retrieve (book-on-demand) 'Smart'-N-tuple object.
unsigned int CLID
Class ID definition.
bool evtColExists(const TupleID &ID) const
check the existence AND validity of the Event Tag Collection with the given ID
Abstract base class which allows the user to interact with the actual N tuple implementation.
virtual 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
Property base class allowing Property* collections to be "homogeneous".
bool undefined() const
Is this ID undefined.
std::string nTuplePath() const
get the constructed N-Tuple path
GAUDI_API LiteralID idAsString() const
Return ID as string, for both numeric and literal IDs.
bool literal() const
Is this ID numeric.
void printNTupleHandler(Property &)
handler for "NTuplePrint" property
GAUDI_API AIDA::IHistogram1D * book(IHistogramSvc *svc, const std::string &path, const Gaudi::Histo1DDef &hist)
helper function to book 1D-histogram
ID class for Histogram and Ntuples.
bool numeric() const
Is this ID numeric.