Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • holau/Gaudi
  • dmagdali/Gaudi
  • pmunozpa/Gaudi
  • ssottoco/Gaudi
  • cvarni/Gaudi
  • mafila/Gaudi
  • admorris/Gaudi
  • staider/Gaudi
  • gunther/Gaudi
  • bstanisl/Gaudi
  • jtorasso/Gaudi
  • wochung/Gaudi
  • mveghel/Gaudi
  • averbyts/Gaudi
  • dguest/Gaudi
  • alboyer/Gaudi
  • dkonst/Gaudi
  • jcarcell/Gaudi
  • elmsheus/Gaudi
  • hpxgaudi/Gaudi
  • ganis/Gaudi
  • tadej/Gaudi
  • hahansen/Gaudi
  • juesseiv/Gaudi
  • imjelde/gaudida
  • jheuel/Gaudi
  • mimazure/Gaudi
  • masato/Gaudi
  • dcasperfaser/Gaudi
  • faser/offline/Gaudi
  • axu/Gaudi
  • sailer/Gaudi
  • amete/Gaudi
  • ponyisi/Gaudi
  • vavolkl/Gaudi
  • mstahl/Gaudi
  • wlampl/Gaudi
  • kreczko/Gaudi
  • emoyse/Gaudi
  • dhynds/Gaudi
  • sstahl/Gaudi
  • rcurrie/Gaudi
  • smh/Gaudi
  • valassi/Gaudi
  • bwynne/Gaudi_gaudi
  • abarton/Gaudi
  • tsulaia/gaudigaudi
  • mnowak/Gaudi
  • roiser/Gaudi
  • merrenst/Gaudi
  • mato/Gaudi
  • christos/Gaudi
  • goetz/Gaudi
  • goetz/AtlasGaudi
  • tsulaia/atlasgaudi
  • olupton/Gaudi
  • pseyfert/Gaudi
  • graemes/Gaudi
  • akraszna/AtlasGaudi
  • cattanem/Gaudi
  • skluth/Gaudi
  • will/Gaudi
  • ssnyder/Gaudi
  • agonzale/Gaudi
  • leggett/AtlasGaudi
  • apearce/Gaudi
  • mnowak/Gaudi-ORIG
  • fwinkl/AtlasGaudi
  • bwynne/Gaudi_atlas
  • chamont/Gaudi
  • rmatev/Gaudi
  • lhcb/Gaudi
  • atlas/Gaudi
  • akraszna/GaudiGaudi
  • fwinkl/Gaudi
  • jonrob/Gaudi
  • azaborow/Gaudi
  • clemenci/Gaudi
  • hgraslan/Gaudi
  • srimanob/Gaudi
  • graven/Gaudi
  • hegner/Gaudi
  • gaudi/Gaudi
83 results
Show changes
Commits on Source (89)
Showing
with 246 additions and 853 deletions
......@@ -3,18 +3,23 @@ stages:
- test
- deploy
image: gitlab-registry.cern.ch/lhcb-core/lbdocker/centos7-build
variables:
NO_LBLOGIN: 1
before_script:
- export BINARY_TAG=x86_64-centos7-gcc7-opt
- export LCG_hostos=x86_64-centos7
- export PATH=/cvmfs/sft.cern.ch/lcg/contrib/CMake/3.8.1/Linux-x86_64/bin:/cvmfs/sft.cern.ch/lcg/contrib/ninja/1.7.1/x86_64-slc6:/cvmfs/sft.cern.ch/lcg/releases/Python/2.7.13-597a5/${BINARY_TAG}/bin:${PATH}
- export LCG_release_area=/cvmfs/sft.cern.ch/lcg/releases
- export PATH=/cvmfs/lhcb.cern.ch/lib/lhcb/LBSCRIPTS/dev/InstallArea/scripts:${PATH}
- export PYTHONPATH=/cvmfs/lhcb.cern.ch/lib/lhcb/LBSCRIPTS/dev/InstallArea/python:${PYTHONPATH}
- export CMAKE_PREFIX_PATH=/cvmfs/sft.cern.ch/lcg/releases:/cvmfs/projects.cern.ch/intelsw/psxe/linux/x86_64/2017/vtune_amplifier_xe
- export CCACHE_DIR=${PWD}/.ccache
- export CCACHE_CPP2=1
build:
image: lhcbdev/centos7-build:latest
tags:
- cvmfs
stage: build
......@@ -32,14 +37,30 @@ build:
- .ccache
expire_in: 1 week
test_headers:
tags:
- cvmfs
stage: test
script:
- curl -o artifacts.zip --location ${CI_PROJECT_URL}/builds/artifacts/master/download?job=test_headers
- unzip -q artifacts.zip '.ccache/*' || true
- /cvmfs/sft.cern.ch/lcg/releases/ccache/3.3.4-e92e5/${BINARY_TAG}/bin/ccache -z
- export LCG_release_area=${LCG_release_area}:/cvmfs/lhcb.cern.ch/lib/lcg/external
- make BUILDDIR=build test_public_headers_build
- /cvmfs/sft.cern.ch/lcg/releases/ccache/3.3.4-e92e5/${BINARY_TAG}/bin/ccache -s
artifacts:
paths:
- build
- .ccache
expire_in: 1 week
coding-conventions:
image: lhcbdev/centos7-build:latest
tags:
- cvmfs
stage: test
script:
- export LCG_release_area=${LCG_release_area}:/cvmfs/lhcb.cern.ch/lib/lcg/external
- pip install autopep8
- sudo pip install autopep8
- make BUILDDIR=build apply-formatting
- git diff > apply-formatting.patch
- git diff --stat --exit-code
......@@ -50,7 +71,6 @@ coding-conventions:
expire_in: 1 day
doxygen:
image: lhcbdev/centos7-build:latest
tags:
- cvmfs
stage: test
......@@ -70,7 +90,6 @@ doxygen:
expire_in: 1 day
test:
image: lhcbdev/centos7-build:latest
tags:
- cvmfs
stage: test
......
......@@ -27,11 +27,9 @@ endif()
include(${CMAKE_SOURCE_DIR}/cmake/externals.cmake)
# Declare project name and version
gaudi_project(Gaudi v30r1)
gaudi_project(Gaudi v30r2)
# These tests do not really fit in a subdirectory.
gaudi_add_test(cmake.EnvConfigTests
COMMAND nosetests --with-doctest ${CMAKE_SOURCE_DIR}/cmake/EnvConfig)
gaudi_add_test(cmake.CMakeModules
COMMAND nosetests ${CMAKE_SOURCE_DIR}/cmake/tests)
gaudi_add_test(cmake.QMTDeps
......
......@@ -102,6 +102,7 @@ namespace Gaudi
}
}
#if __cplusplus < 201703L
// implementation of C++17 std::as_const, see http://en.cppreference.com/w/cpp/utility/as_const
template <typename T>
constexpr std::add_const_t<T>& as_const( T& t ) noexcept
......@@ -111,7 +112,9 @@ namespace Gaudi
template <typename T>
void as_const( T&& t ) = delete;
#else
using std::as_const;
#endif
/////////////////////////////////////////
template <typename Out1, typename Out2, typename = std::enable_if_t<std::is_constructible<Out1, Out2>::value>>
......
......@@ -53,6 +53,7 @@
// ============================================================================
class Algorithm; // GaudiKernel
class AlgTool; // GaudiKernel
class ISvcLocator;
namespace Gaudi
{
namespace Utils
......
......@@ -13,6 +13,10 @@
// Include files
// ============================================================================
#include "boost/algorithm/string/replace.hpp"
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index_container.hpp>
// ============================================================================
// GaudiKernel
// ============================================================================
......@@ -46,10 +50,6 @@ public:
typedef Tuples::Tuple Tuple;
/// the actual type of N-tuple ID
typedef GaudiAlg::TupleID TupleID;
/// the actual type of (title) -> (tuple) mappping
typedef GaudiAlg::TupleMapTitle TupleMapTitle;
/// the actual type of (Numeric ID) -> (tuple) mappping
typedef GaudiAlg::TupleMapID TupleMapID;
// ==========================================================================
public:
// ==========================================================================
......@@ -244,24 +244,11 @@ public:
*/
long printEvtCols() const;
// ==========================================================================
public:
// ==========================================================================
/// check the existence AND validity of the N-Tuple with the given ID
bool nTupleExists( const TupleID& ID ) const;
/// check the existence AND validity of the Event Tag Collection with the given ID
bool evtColExists( const TupleID& ID ) const;
// ==========================================================================
protected:
// ==========================================================================
/// access to the all ntuples by title
const TupleMapTitle& nTupleMapTitle() const { return m_nTupleMapTitle; }
/// access to the all evet tag collections by title
const TupleMapTitle& evtColMapTitle() const { return m_evtColMapTitle; }
/// access to the all ntuples by numeric ID
const TupleMapID& nTupleMapID() const { return m_nTupleMapID; }
/// access to the all evet tag collections by numeric ID
const TupleMapID& evtColMapID() const { return m_evtColMapID; }
// ==========================================================================
protected:
// ==========================================================================
/** create TupleObj
......@@ -271,7 +258,8 @@ protected:
* @param clid unique classID for ntuple
* @return pointer to newly created TupleObj
*/
virtual Tuples::TupleObj* createNTuple( const std::string& name, NTuple::Tuple* tuple, const CLID& clid ) const;
virtual std::unique_ptr<Tuples::TupleObj> createNTuple( const std::string& name, NTuple::Tuple* tuple,
const CLID& clid ) const;
/** create TupleObj for event tag collection
* @attention The method should never used directly by users
* @param name name/title
......@@ -279,7 +267,8 @@ protected:
* @param clid unique classID for ntuple
* @return pointer to newly created TupelObj
*/
virtual Tuples::TupleObj* createEvtCol( const std::string& name, NTuple::Tuple* tuple, const CLID& clid ) const;
virtual std::unique_ptr<Tuples::TupleObj> createEvtCol( const std::string& name, NTuple::Tuple* tuple,
const CLID& clid ) const;
// ==========================================================================
public:
// ==========================================================================
......@@ -363,16 +352,48 @@ private:
Gaudi::Property<std::string> m_evtColDir{this, "EvtColDir",
boost::algorithm::replace_all_copy( this->name(), ":", "_" ),
"Subdirectory for Event Tag Collections"};
struct nTupleMapItem final {
std::string title;
TupleID id;
std::shared_ptr<Tuples::TupleObj> tuple;
};
struct title_t {
};
struct id_t {
};
struct order_t {
};
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>>>>;
// ==========================================================================
/// the actual storage of ntuples by title
mutable TupleMapTitle m_nTupleMapTitle;
/// the actual storage of ntuples by ID
mutable TupleMapID m_nTupleMapID;
/// the actual storage of ntuples by title and ID
mutable nTupleMap m_nTupleMap;
decltype( auto ) nTupleByID() const { return m_nTupleMap.template get<id_t>(); }
decltype( auto ) nTupleByTitle() const { return m_nTupleMap.template get<title_t>(); }
decltype( auto ) nTupleOrdered() const { return m_nTupleMap.template get<order_t>(); }
// ==========================================================================
/// the actual storage of event collections by title
mutable TupleMapTitle m_evtColMapTitle;
/// the actual storage of event collections by ID
mutable TupleMapID m_evtColMapID;
/// the actual storage of event collections by title and ID
mutable nTupleMap m_evtColMap;
decltype( auto ) evtColByID() const { return m_evtColMap.template get<id_t>(); }
decltype( auto ) evtColByTitle() const { return m_evtColMap.template get<title_t>(); }
decltype( auto ) evtColOrdered() const { return m_evtColMap.template get<order_t>(); }
// ==========================================================================
};
// ============================================================================
......
......@@ -29,29 +29,6 @@
#ifdef _WIN32
#pragma warning( disable : 4661 ) // incomplete explicit templates
#endif
//=============================================================================
// small helper to simplify the code...
namespace
{
constexpr struct releaseAndClear_t {
template <typename C>
void operator()( C& c ) const
{
for ( auto& i : c )
if ( i.second ) i.second->release();
c.clear();
}
} releaseAndClear{};
constexpr struct ordered_t {
template <typename C>
std::map<typename C::key_type, typename C::mapped_type> operator()( const C& c ) const
{
return {std::begin( c ), std::end( c )};
}
} ordered{};
}
//=============================================================================
// Initialize ntupling
......@@ -110,30 +87,20 @@ StatusCode GaudiTuples<PBASE>::
#endif
()
{
if ( !( nTupleMapTitle().empty() && nTupleMapID().empty() && evtColMapTitle().empty() && evtColMapID().empty() ) ) {
const int nNtuples = nTupleMapID().size();
const int nEvtCols = evtColMapID().size();
if ( !( m_nTupleMap.empty() && m_evtColMap.empty() ) ) {
const int nNtuples = m_nTupleMap.size();
const int nEvtCols = m_evtColMap.size();
this->always() << "Booked " << nNtuples << " N-Tuples and " << nEvtCols << " Event Tag Collections" << endmsg;
}
if ( produceNTuples() && tuplesPrint() ) {
printTuples();
}
if ( produceEvtCols() && evtColsPrint() ) {
printEvtCols();
}
// release ntuples and clear the container
releaseAndClear( m_nTupleMapTitle );
// release ntuples and clear the container
releaseAndClear( m_nTupleMapID );
if ( produceNTuples() && tuplesPrint() ) printTuples();
if ( produceEvtCols() && evtColsPrint() ) printEvtCols();
// release ntuples and clear the container
releaseAndClear( m_evtColMapTitle );
m_nTupleMap.clear();
// release ntuples and clear the container
releaseAndClear( m_evtColMapID );
m_evtColMap.clear();
// finalize base class
return PBASE::finalize();
......@@ -146,10 +113,9 @@ template <class PBASE>
Tuples::Tuple GaudiTuples<PBASE>::nTuple( const std::string& title, const CLID& clid ) const
{
// look up in the table
auto* tuple = m_nTupleMapTitle[title];
if ( tuple ) {
return Tuple( tuple );
} // RETURN
auto& m = nTupleByTitle();
auto tuple = m.find( title );
if ( tuple != m.end() ) return Tuple( tuple->tuple ); // RETURN
// Create the tuple ID
TupleID ID;
if ( this->useNumericAutoIDs() || title.empty() ) {
......@@ -160,7 +126,7 @@ Tuples::Tuple GaudiTuples<PBASE>::nTuple( const std::string& title, const CLID&
.ignore();
}
// propose the tuple ID
ID = TupleID( m_nTupleMapID.size() + 1 + nTupleOffSet() );
ID = TupleID( m_nTupleMap.size() + 1 + nTupleOffSet() );
// adjust the proposed ID
while ( nTupleExists( ID ) || evtColExists( ID ) ) {
ID = TupleID( ID.numeric() + 1 );
......@@ -185,10 +151,9 @@ template <class PBASE>
Tuples::Tuple GaudiTuples<PBASE>::evtCol( const std::string& title, const CLID& clid ) const
{
// look up in the table
Tuples::TupleObj* tuple = m_evtColMapTitle[title];
if ( tuple ) {
return Tuple( tuple );
} // RETURN
auto& m = evtColByTitle();
auto tuple = m.find( title );
if ( tuple != m.end() ) return Tuple( tuple->tuple ); // RETURN
// Create the tuple ID
TupleID ID;
if ( this->useNumericAutoIDs() || title.empty() ) {
......@@ -199,7 +164,7 @@ Tuples::Tuple GaudiTuples<PBASE>::evtCol( const std::string& title, const CLID&
.ignore();
}
// proposed the tuple ID
ID = TupleID( m_evtColMapID.size() + 1 + evtColOffSet() );
ID = TupleID( m_evtColMap.size() + 1 + evtColOffSet() );
// adjust the proposed ID
while ( nTupleExists( ID ) || evtColExists( ID ) ) {
ID = TupleID( ID.numeric() + 1 );
......@@ -230,10 +195,9 @@ Tuples::Tuple GaudiTuples<PBASE>::nTuple( const TupleID& ID, const std::string&
}
// look up in the table
Tuples::TupleObj* tuple = m_nTupleMapID[ID];
if ( tuple ) {
return Tuple( tuple );
} // RETURN
auto& m = nTupleByID();
auto tuple = m.find( ID );
if ( tuple != m.end() ) return Tuple( tuple->tuple ); // RETURN
// convert ID to the string
const std::string tID = ID.idAsString();
......@@ -242,38 +206,33 @@ Tuples::Tuple GaudiTuples<PBASE>::nTuple( const TupleID& ID, const std::string&
const std::string title = title1.empty() ? ( "NTuple #" + tID ) : title1;
// book new ntuple
if ( produceNTuples() ) {
// book NTupel
NTuple::Tuple* tup = nullptr;
if ( ID.numeric() ) {
tup = this->ntupleSvc()->book( nTuplePath(), ID.numericID(), clid, title );
} else if ( ID.literal() ) {
tup = this->ntupleSvc()->book( nTuplePath(), ID.literalID(), clid, title );
} else {
this->Error( "Undefined NTuple ID" ).ignore();
}
// assertion
this->Assert( tup, "Could not book the N-Tuple='" + title + "'" );
// some printout
if ( tup->registry() && this->msgLevel( MSG::DEBUG ) ) {
this->debug() << "Booked NTuple '" << title << "' ID=" << tID << "' Path='" << nTuplePath() << "' TS='"
<< tup->registry()->identifier() << "'" << endmsg;
}
tuple = createNTuple( title, tup, clid );
if ( !produceNTuples() ) {
auto r = m_nTupleMap.insert( nTupleMapItem{title, ID, createNTuple( title, nullptr, clid )} );
if ( !r.second ) this->Error( "Failure to createNTuple" ).ignore();
return Tuple( r.first->tuple );
}
// book NTupel
NTuple::Tuple* tup = nullptr;
if ( ID.numeric() ) {
tup = this->ntupleSvc()->book( nTuplePath(), ID.numericID(), clid, title );
} else if ( ID.literal() ) {
tup = this->ntupleSvc()->book( nTuplePath(), ID.literalID(), clid, title );
} else {
tuple = createNTuple( title, (NTuple::Tuple*)0, clid );
this->Error( "Undefined NTuple ID" ).ignore();
}
// increment the reference
tuple->addRef();
//
m_nTupleMapID[ID] = tuple;
// assertion
this->Assert( tup, "Could not book the N-Tuple='" + title + "'" );
// some printout
if ( tup->registry() && this->msgLevel( MSG::DEBUG ) ) {
this->debug() << "Booked NTuple '" << title << "' ID=" << tID << "' Path='" << nTuplePath() << "' TS='"
<< tup->registry()->identifier() << "'" << endmsg;
}
auto r = m_nTupleMap.insert( nTupleMapItem{title, ID, createNTuple( title, tup, clid )} );
if ( !r.second ) this->Error( "Failure to createNTuple" ).ignore();
return Tuple( r.first->tuple );
//
tuple->addRef();
m_nTupleMapTitle[title] = tuple;
// return
return Tuple( tuple );
}
// ============================================================================
template <class PBASE>
......@@ -286,10 +245,9 @@ Tuples::Tuple GaudiTuples<PBASE>::evtCol( const TupleID& ID, const std::string&
}
// look up in the table
Tuples::TupleObj* tuple = m_evtColMapID[ID];
if ( tuple ) {
return Tuple( tuple );
} // RETURN
auto& tuple = evtColByID();
auto i = tuple.find( ID );
if ( i != tuple.end() ) return Tuple( i->tuple ); // RETURN
// convert ID to the string
const std::string tID = ID.idAsString();
......@@ -298,45 +256,38 @@ Tuples::Tuple GaudiTuples<PBASE>::evtCol( const TupleID& ID, const std::string&
const std::string title = title1.empty() ? ( "EvtCol #" + tID ) : title1;
// book new ntuple
if ( produceEvtCols() ) {
// book NTuple
NTuple::Tuple* tup = nullptr;
if ( ID.numeric() ) {
tup = this->evtColSvc()->book( evtColPath(), ID.numericID(), clid, title );
} else if ( ID.literal() ) {
tup = this->evtColSvc()->book( evtColPath(), ID.literalID(), clid, title );
} else {
this->Error( "Undefined NTuple ID" ).ignore();
}
// assertion
this->Assert( tup, "Could not book the EvtCol='" + title + "'" );
// some printout
if ( tup->registry() && this->msgLevel( MSG::DEBUG ) ) {
this->debug() << "Booked EvtCol '" << title << "' ID=" << tID << "' Path='" << evtColPath() << "' TS='"
<< tup->registry()->identifier() << "'" << endmsg;
}
tuple = createEvtCol( title, tup, clid );
if ( !produceEvtCols() ) {
auto r = m_evtColMap.insert( nTupleMapItem{title, ID, createEvtCol( title, nullptr, clid )} );
if ( !r.second ) this->Error( "Failure to createEvtCol" ).ignore();
return Tuple( r.first->tuple );
}
// book NTuple
NTuple::Tuple* tup = nullptr;
if ( ID.numeric() ) {
tup = this->evtColSvc()->book( evtColPath(), ID.numericID(), clid, title );
} else if ( ID.literal() ) {
tup = this->evtColSvc()->book( evtColPath(), ID.literalID(), clid, title );
} else {
tuple = createEvtCol( title, (NTuple::Tuple*)0, clid );
this->Error( "Undefined NTuple ID" ).ignore();
}
// increment the reference
tuple->addRef();
//
m_evtColMapID[ID] = tuple;
//
tuple->addRef();
m_evtColMapTitle[title] = tuple;
// return
return Tuple( tuple );
// assertion
this->Assert( tup, "Could not book the EvtCol='" + title + "'" );
// some printout
if ( tup->registry() && this->msgLevel( MSG::DEBUG ) ) {
this->debug() << "Booked EvtCol '" << title << "' ID=" << tID << "' Path='" << evtColPath() << "' TS='"
<< tup->registry()->identifier() << "'" << endmsg;
}
auto r = m_evtColMap.insert( nTupleMapItem{title, ID, createEvtCol( title, tup, clid )} );
if ( !r.second ) this->Error( "Failure to createEvtCol" ).ignore();
return Tuple( r.first->tuple );
}
// ============================================================================
// create TupleObj
// ============================================================================
template <class PBASE>
Tuples::TupleObj* GaudiTuples<PBASE>::createNTuple( const std::string& name, NTuple::Tuple* tuple,
const CLID& clid ) const
std::unique_ptr<Tuples::TupleObj> GaudiTuples<PBASE>::createNTuple( const std::string& name, NTuple::Tuple* tuple,
const CLID& clid ) const
{
return Tuples::createTupleObj( this, "Tuple '" + name + "'", tuple, clid, Tuples::NTUPLE );
}
......@@ -346,8 +297,8 @@ Tuples::TupleObj* GaudiTuples<PBASE>::createNTuple( const std::string& name, NTu
// create TupleObj for event tag collection
// ============================================================================
template <class PBASE>
Tuples::TupleObj* GaudiTuples<PBASE>::createEvtCol( const std::string& name, NTuple::Tuple* tuple,
const CLID& clid ) const
std::unique_ptr<Tuples::TupleObj> GaudiTuples<PBASE>::createEvtCol( const std::string& name, NTuple::Tuple* tuple,
const CLID& clid ) const
{
return Tuples::createTupleObj( this, "EvtCol '" + name + "'", tuple, clid, Tuples::EVTCOL );
}
......@@ -358,26 +309,22 @@ template <class PBASE>
long GaudiTuples<PBASE>::printTuples() const
{
if ( nTupleMapTitle().empty() && nTupleMapID().empty() ) {
if ( m_nTupleMap.empty() ) {
if ( this->msgLevel( MSG::DEBUG ) ) this->debug() << "No N-Tuples are booked" << endmsg;
} else {
this->always() << "List of booked N-Tuples in directory "
<< "\"" << nTuplePath() << "\"" << endmsg;
}
for ( const auto& entry : ordered( nTupleMapID() ) ) {
if ( !entry.second ) {
continue;
}
const NTuple::Tuple* tuple = entry.second->tuple();
if ( !tuple ) {
for ( const auto& entry : this->nTupleOrdered() ) {
if ( !entry.tuple->tuple() ) {
this->error() << " NTuple::Tuple* points to NULL" << endmsg;
continue;
}
this->always() << GaudiAlg::PrintTuple::print( tuple, entry.first ) << endmsg;
this->always() << GaudiAlg::PrintTuple::print( entry.tuple->tuple(), entry.id ) << endmsg;
}
//
return this->nTupleMapID().size();
return this->m_nTupleMap.size();
}
// ============================================================================
// perform the actual printout of Evt Tag Collections
......@@ -385,26 +332,22 @@ long GaudiTuples<PBASE>::printTuples() const
template <class PBASE>
long GaudiTuples<PBASE>::printEvtCols() const
{
if ( evtColMapTitle().empty() && evtColMapID().empty() ) {
if ( m_evtColMap.empty() ) {
this->always() << "No Event Tag Collections are booked" << endmsg;
} else {
this->always() << "List of booked Event Tag Collections in directory "
<< "\"" << evtColPath() << "\"" << endmsg;
}
for ( const auto& entry : ordered( evtColMapID() ) ) {
if ( !entry.second ) {
continue;
}
const auto tuple = entry.second->tuple();
if ( !tuple ) {
for ( const auto& entry : this->evtColOrdered() ) {
if ( !entry.tuple->tuple() ) {
this->error() << " NTuple::Tuple* points to NULL" << endmsg;
continue;
}
this->always() << GaudiAlg::PrintTuple::print( tuple, entry.first )
<< " Items:" << Gaudi::Utils::toString( entry.second->items() ) << endmsg;
this->always() << GaudiAlg::PrintTuple::print( entry.tuple->tuple(), entry.id )
<< " Items:" << Gaudi::Utils::toString( entry.tuple->items() ) << endmsg;
}
//
return this->evtColMapID().size();
return this->m_evtColMap.size();
}
// ============================================================================
// check the existence AND validity of the N-Tuple with the given ID
......@@ -412,7 +355,8 @@ long GaudiTuples<PBASE>::printEvtCols() const
template <class PBASE>
bool GaudiTuples<PBASE>::nTupleExists( const TupleID& ID ) const
{
return m_nTupleMapID.end() != m_nTupleMapID.find( ID );
auto& m = nTupleByID();
return m.find( ID ) != m.end();
}
// ============================================================================
// check the existence AND validity of the Event Tag Collection with the given ID
......@@ -420,7 +364,8 @@ bool GaudiTuples<PBASE>::nTupleExists( const TupleID& ID ) const
template <class PBASE>
bool GaudiTuples<PBASE>::evtColExists( const TupleID& ID ) const
{
return m_evtColMapID.end() != m_evtColMapID.find( ID );
auto& m = evtColByID();
return m.find( ID ) != m.end();
}
// ============================================================================
// Handle method for changes in the 'NTuplePrint' property
......@@ -429,12 +374,8 @@ template <class PBASE>
void GaudiTuples<PBASE>::printNTupleHandler( Gaudi::Details::PropertyBase& )
{
// no action if not yet initialized
if ( this->FSMState() < Gaudi::StateMachine::INITIALIZED ) {
return;
}
if ( this->tuplesPrint() ) {
this->printTuples();
}
if ( this->FSMState() < Gaudi::StateMachine::INITIALIZED ) return;
if ( this->tuplesPrint() ) this->printTuples();
}
// ============================================================================
// Handle method for changes in the 'EvtColsPrint' property
......@@ -443,12 +384,8 @@ template <class PBASE>
void GaudiTuples<PBASE>::printEvtColHandler( Gaudi::Details::PropertyBase& )
{
// no action if not yet initialized
if ( this->FSMState() < Gaudi::StateMachine::INITIALIZED ) {
return;
}
if ( this->evtColsPrint() ) {
this->printEvtCols();
}
if ( this->FSMState() < Gaudi::StateMachine::INITIALIZED ) return;
if ( this->evtColsPrint() ) this->printEvtCols();
}
// ============================================================================
// get the constructed N-Tuple path
......@@ -457,7 +394,7 @@ template <class PBASE>
std::string GaudiTuples<PBASE>::nTuplePath() const
{
const std::string path = nTupleLUN() + "/" + nTupleTopDir() + nTupleDir();
return ( splitNTupleDir() ? dirHbookName( path ) : path );
return splitNTupleDir() ? dirHbookName( path ) : path;
}
// ============================================================================
// get the constructed Event Tag Collection path
......@@ -466,7 +403,7 @@ template <class PBASE>
std::string GaudiTuples<PBASE>::evtColPath() const
{
std::string path = evtColLUN() + "/" + evtColTopDir() + evtColDir();
return ( splitEvtColDir() ? dirHbookName( path ) : path );
return splitEvtColDir() ? dirHbookName( path ) : path;
}
// ============================================================================
// The END
......
......@@ -113,19 +113,6 @@ namespace GaudiAlg
>
Profile2DMapID;
// ==========================================================================
// ============================ NTuples =====================================
// ==========================================================================
/// the actual type for (title)->(tuple) map
typedef GaudiUtils::HashMap<std::string, // Key
Tuples::TupleObj* // Value
>
TupleMapTitle;
/// the actual type for (ID)->(tuple) map
typedef GaudiUtils::HashMap<TupleID, // Key
Tuples::TupleObj* // Value
>
TupleMapID;
// ==========================================================================
}
// ============================================================================
// The END
......
......@@ -86,8 +86,12 @@ namespace Gaudi
void invoke( std::index_sequence<I...>, std::index_sequence<O...> )
{
auto out = details::as_const( *this )( details::deref( std::get<I>( this->m_inputs ).get() )... );
#if __cplusplus < 201703L
(void)std::initializer_list<int>{
( details::put( std::get<O>( this->m_outputs ), std::get<O>( std::move( out ) ) ), 0 )...};
#else
( details::put( std::get<O>( this->m_outputs ), std::get<O>( std::move( out ) ) ), ... );
#endif
}
};
......
......@@ -116,46 +116,29 @@ namespace Tuples
*/
class GAUDI_API Tuple
{
/// default constructor is deleted -- except that ROOT wants one for dictionary
/// code generation. So we make it private, and do not implement it...
// Tuple() = delete;
Tuple();
public:
/** standard constructor
* @param tuple pointer to "real" tuple object
*/
Tuple( TupleObj* );
/// copy constructor
Tuple( const Tuple& ) = default;
Tuple( std::shared_ptr<TupleObj> tuple ) : m_tuple( std::move( tuple ) ) {}
/// destructor
virtual ~Tuple() = default;
/** assignment operator
* Tuples could be assigned in a safe way
* @param tuple tuple to be assigned
*/
Tuple& operator=( const Tuple& ) = default;
/** get the pointer to the underlying object
* @return pointer to underlying TupleObj
*/
TupleObj* operator->() const { return tuple(); }
TupleObj* operator->() const { return m_tuple.get(); }
/// check the validity of the tuple object
bool valid() const { return tuple(); }
bool valid() const { return static_cast<bool>( m_tuple ); }
protected:
/// Return the underlying tuple object
TupleObj* tuple() const { return m_tuple.get(); }
TupleObj* tuple() { return m_tuple.get(); }
private:
/// The tuple object
SmartIF<TupleObj> m_tuple;
/// The (shared) tuple object
std::shared_ptr<TupleObj> m_tuple;
};
/** @class TupleColumn
......@@ -274,7 +257,6 @@ namespace Tuples
class TupleColumn
{
public:
TupleColumn() = delete;
TupleColumn( std::string name, ITEM value ) : m_name( std::move( name ) ), m_value( std::move( value ) ) {}
/// Return the column name
......@@ -293,7 +275,7 @@ namespace Tuples
template <class ITEM>
inline TupleColumn<ITEM> make_column( std::string name, const ITEM& item )
{
return TupleColumn<ITEM>( std::move( name ), item );
return {std::move( name ), item};
}
/** helper function to create 'on-the-fly' the
......@@ -302,7 +284,7 @@ namespace Tuples
template <class ITEM>
inline TupleColumn<const ITEM*> make_column( std::string name, const ITEM* item )
{
return TupleColumn<const ITEM*>( std::move( name ), item );
return {std::move( name ), item};
}
/** helper function to create 'on-the-fly' the
......@@ -311,7 +293,7 @@ namespace Tuples
template <class ITEM>
inline TupleColumn<ITEM*> make_column( std::string name, ITEM* item )
{
return TupleColumn<ITEM*>( std::move( name ), item );
return {std::move( name ), item};
}
template <class ITEM>
......@@ -340,9 +322,7 @@ namespace Tuples
template <class ITEM>
inline Tuples::Tuple& operator<<( Tuples::Tuple& tuple, const Tuples::TupleColumn<ITEM>& item )
{
if ( !tuple.valid() ) {
return tuple;
} // no action for invalid tuple
if ( !tuple.valid() ) return tuple; // no action for invalid tuple
tuple->column( item.name(), item.value() );
return tuple;
}
......
......@@ -139,11 +139,10 @@ namespace Tuples
* @date 2004-1-24
*/
template <class HANDLER1, class HANDLER2>
inline TupleObj* createTupleObj( HANDLER1 handler1, HANDLER2 handler2, const std::string& name,
NTuple::Tuple* tuple, const CLID& clid = CLID_ColumnWiseTuple,
const Tuples::Type type = Tuples::NTUPLE )
auto createTupleObj( HANDLER1 handler1, HANDLER2 handler2, const std::string& name, NTuple::Tuple* tuple,
const CLID& clid = CLID_ColumnWiseTuple, const Tuples::Type type = Tuples::NTUPLE )
{
return new TupleObjImp<HANDLER1, HANDLER2>( handler1, handler2, name, tuple, clid, type );
return std::make_unique<TupleObjImp<HANDLER1, HANDLER2>>( handler1, handler2, name, tuple, clid, type );
}
/** @class ErrorHandler
......@@ -224,8 +223,8 @@ namespace Tuples
* @date 2004-1-24
*/
template <class OWNER>
inline TupleObj* createTupleObj( const OWNER* owner, const std::string& name, NTuple::Tuple* tuple,
const CLID& clid = CLID_ColumnWiseTuple, const Tuples::Type type = Tuples::NTUPLE )
auto createTupleObj( const OWNER* owner, const std::string& name, NTuple::Tuple* tuple,
const CLID& clid = CLID_ColumnWiseTuple, const Tuples::Type type = Tuples::NTUPLE )
{
return detail::createTupleObj( detail::make_handler( owner, &OWNER::Error ),
detail::make_handler( owner, &OWNER::Warning ), name, tuple, clid, type );
......
......@@ -21,6 +21,7 @@ namespace Tuples
{
/// the actual type for N-Tuple identifier (HBOOK-style)
typedef GaudiAlg::ID TupleID;
inline std::size_t hash_value( TupleID const& b ) { return b.hash(); }
}
// ============================================================================
......@@ -29,6 +30,7 @@ namespace GaudiAlg
{
/// the actual type for N-Tuple identifier
typedef Tuples::TupleID TupleID;
inline std::size_t hash_value( TupleID const& b ) { return b.hash(); }
}
// ============================================================================
......
......@@ -69,8 +69,7 @@ namespace Tuples
return T( std::forward<Arg>( i ) );
}
};
constexpr struct to_<float> to_float {
};
constexpr to_<float> to_float{};
template <typename Iterator>
using const_ref_t = std::add_const_t<typename std::iterator_traits<Iterator>::reference>;
......@@ -266,13 +265,10 @@ namespace Tuples
TupleObj( std::string name, NTuple::Tuple* tuple, const CLID& clid = CLID_ColumnWiseTuple,
const Tuples::Type type = Tuples::NTUPLE );
// ========================================================================
protected:
public:
// ========================================================================
/// destructor is protected
virtual ~TupleObj();
// ========================================================================
public:
// ========================================================================
/** Set the value for selected tuple column.
* If column does not exist, it will be automatically created
* and appended to the tuple
......@@ -793,28 +789,18 @@ namespace Tuples
*
* @author Gerhard Raven
*/
private:
template <typename Tuple, typename Value, std::size_t... I>
StatusCode columns_helper( const Value& value, const Tuple& tup, std::index_sequence<I...> )
{
auto scs = std::initializer_list<StatusCode>{
this->column( std::get<I>( tup ).first, Gaudi::invoke( std::get<I>( tup ).second, value ) )...};
auto is_ok = []( const StatusCode& sc ) -> bool { return sc.isSuccess(); };
auto i = std::find_if_not( begin( scs ), end( scs ), is_ok );
if ( i != end( scs ) ) {
// avoid unchecked StatusCodes...
std::for_each( std::next( i ), end( scs ), is_ok );
return *i;
}
return StatusCode::SUCCESS;
}
public:
template <typename Value, typename... Args>
StatusCode columns( Value&& value, Args&&... args )
{
return columns_helper( std::forward<Value>( value ), std::forward_as_tuple( std::forward<Args>( args )... ),
std::index_sequence_for<Args...>{} );
if ( sizeof...( Args ) == 0 ) return StatusCode::SUCCESS;
std::initializer_list<StatusCode> scs{
this->column( std::get<0>( args ), Gaudi::invoke( std::get<1>( args ), value ) )...};
return std::accumulate( std::next( begin( scs ) ), end( scs ), *begin( scs ),
[]( StatusCode sc, const StatusCode& i ) {
i.ignore(); // make sure there are no unchecked StatusCodes...
return sc.isFailure() ? sc : i; // latch to the first non-success case
} );
}
// ========================================================================
public:
......@@ -1037,7 +1023,8 @@ namespace Tuples
if ( !var ) return ErrorCodes::InvalidColumn;
// fill the array
std::transform( first, last, std::begin( *var ), std::cref( function ) );
std::transform( first, last, std::begin( *var ),
[&]( auto&& i ) { return Gaudi::invoke( function, std::forward<decltype( i )>( i ) ); } );
return StatusCode::SUCCESS;
}
......@@ -1106,7 +1093,7 @@ namespace Tuples
for ( size_t index = 0; first != last; ++first, ++index ) {
auto item = first_item;
for ( auto& var : vars ) {
( *var )[index] = ( item++ )->second( *first );
( *var )[index] = Gaudi::invoke( ( item++ )->second, *first );
}
}
......@@ -1419,7 +1406,7 @@ namespace Tuples
for ( ; first != last; ++first ) {
//
for ( MIndex iCol = 0; iCol < cols; ++iCol ) {
( *var )[iRow][iCol] = (float)( ( *first )[iCol] );
( *var )[iRow][iCol] = ( *first )[iCol];
}
//
++iRow;
......@@ -1537,7 +1524,7 @@ namespace Tuples
for ( ; first != last; ++first ) {
//
for ( FUN fun = funF; fun < funL; ++fun ) {
( *var )[iRow][fun - funF] = ( *fun )( *first );
( *var )[iRow][fun - funF] = Gaudi::invoke( *fun, *first );
}
//
++iRow;
......@@ -1871,8 +1858,8 @@ namespace Tuples
const std::string& length, const size_t maxv = 100 )
{
using Info = std::pair<KEY, VALUE>;
static const std::array<std::function<float( const Info& )>, 2> fns = {
{[]( const Info& i ) { return i.first; }, []( const Info& i ) { return i.second; }}};
static const std::array<float ( * )( const Info& ), 2> fns = {
{[]( const Info& i ) -> float { return i.first; }, []( const Info& i ) -> float { return i.second; }}};
return fmatrix( name, begin( fns ), end( fns ), begin( info ), end( info ), length, maxv );
}
// =======================================================================
......@@ -1908,22 +1895,6 @@ namespace Tuples
*/
NTuple::Tuple* tuple() { return m_tuple; }
// =======================================================================
/** return the reference counter
* @return current reference counter
*/
unsigned long refCount() const { return m_refCount; }
// =======================================================================
/** add the reference to TupleObj
* @return current reference counter
*/
unsigned long addRef() { return ++m_refCount; }
// =======================================================================
/** release the reference to TupleObj
* if reference counter becomes zero,
* object will be automatically deleted
*/
void release();
// =======================================================================
/// accessor to the N-Tuple CLID
const CLID& clid() const { return m_clid; }
// =======================================================================
......@@ -1992,57 +1963,10 @@ namespace Tuples
/// get the column
FMatrix* fMatrix( const std::string& name, const MIndex& rows, const MIndex& cols );
// =======================================================================
private:
// =======================================================================
/// delete the default/copy constructor and assignment
TupleObj() = delete;
/// delete the copy constructor and assignment
TupleObj( const TupleObj& ) = delete;
TupleObj& operator=( const TupleObj& ) = delete;
// =======================================================================
private:
// =======================================================================
/// the actual storage type for short columns
typedef GaudiUtils::HashMap<std::string, std::unique_ptr<Bool>> Bools;
// =======================================================================
/// the actual storage type for short columns
typedef GaudiUtils::HashMap<std::string, std::unique_ptr<Char>> Chars;
// =======================================================================
/// the actual storage type for unsigned short columns
typedef GaudiUtils::HashMap<std::string, std::unique_ptr<UChar>> UChars;
// =======================================================================
/// the actual storage type for short columns
typedef GaudiUtils::HashMap<std::string, std::unique_ptr<Short>> Shorts;
// =======================================================================
/// the actual storage type for unsigned short columns
typedef GaudiUtils::HashMap<std::string, std::unique_ptr<UShort>> UShorts;
// =======================================================================
/// the actual storage type for integer columns
typedef GaudiUtils::HashMap<std::string, std::unique_ptr<Int>> Ints;
// =======================================================================
/// the actual storage type for unsigned integer columns
typedef GaudiUtils::HashMap<std::string, std::unique_ptr<UInt>> UInts;
// =======================================================================
/// the actual storage type for longlong columns
typedef GaudiUtils::HashMap<std::string, std::unique_ptr<LongLong>> LongLongs;
// =======================================================================
/// the actual storage type for ulonglong columns
typedef GaudiUtils::HashMap<std::string, std::unique_ptr<ULongLong>> ULongLongs;
// =======================================================================
/// the actual storage type for float columns
typedef GaudiUtils::HashMap<std::string, std::unique_ptr<Float>> Floats;
// =======================================================================
/// the actual storage type for float columns
typedef GaudiUtils::HashMap<std::string, std::unique_ptr<Double>> Doubles;
// =======================================================================
/// the actual storage type for address columns
typedef GaudiUtils::HashMap<std::string, std::unique_ptr<Address>> Addresses;
// =======================================================================
/// the actual storage type for array columns
typedef GaudiUtils::HashMap<std::string, std::unique_ptr<FArray>> FArrays;
// =======================================================================
/// the actual storage type for matrix columns
typedef GaudiUtils::HashMap<std::string, std::unique_ptr<FMatrix>> FMatrices;
// =======================================================================
private:
// =======================================================================
/// name
......@@ -2060,53 +1984,57 @@ namespace Tuples
/// reference counter
size_t m_refCount = 0;
// =======================================================================
// helper type to define the actual storage types
template <typename T>
using ColumnStorage = GaudiUtils::HashMap<std::string, std::unique_ptr<T>>;
// =======================================================================
/// the actual storage of all 'bool' columns
mutable Bools m_bools;
mutable ColumnStorage<Bool> m_bools;
// =======================================================================
/// the actual storage of all 'Int' columns
mutable Chars m_chars;
mutable ColumnStorage<Char> m_chars;
// =======================================================================
/// the actual storage of all 'unsigned int' columns
mutable UChars m_uchars;
mutable ColumnStorage<UChar> m_uchars;
// =======================================================================
/// the actual storage of all 'Int' columns
mutable Shorts m_shorts;
mutable ColumnStorage<Short> m_shorts;
// =======================================================================
/// the actual storage of all 'unsigned int' columns
mutable UShorts m_ushorts;
mutable ColumnStorage<UShort> m_ushorts;
// =======================================================================
/// the actual storage of all 'Int' columns
mutable Ints m_ints;
mutable ColumnStorage<Int> m_ints;
// =======================================================================
/// the actual storage of all 'unsigned int' columns
mutable UInts m_uints;
mutable ColumnStorage<UInt> m_uints;
// =======================================================================
/// the actual storage of all 'longlong' columns
mutable LongLongs m_longlongs;
mutable ColumnStorage<LongLong> m_longlongs;
// =======================================================================
/// the actual storage of all 'ulonglong' columns
mutable ULongLongs m_ulonglongs;
mutable ColumnStorage<ULongLong> m_ulonglongs;
// =======================================================================
/// the actual storage of all 'Float' columns
mutable Floats m_floats;
mutable ColumnStorage<Float> m_floats;
// =======================================================================
/// the actual storage of all 'Double' columns
mutable Doubles m_doubles;
mutable ColumnStorage<Double> m_doubles;
// =======================================================================
/// the actual storage of all 'Address' columns
mutable Addresses m_addresses;
mutable ColumnStorage<Address> m_addresses;
// =======================================================================
/// the actual storage of all 'FArray' columns
mutable FArrays m_farrays;
mutable ColumnStorage<FArray> m_farrays;
// =======================================================================
/// the actual storage of all 'FArray' columns (fixed)
mutable FArrays m_arraysf;
mutable ColumnStorage<FArray> m_arraysf;
// =======================================================================
/// the actual storage of all 'FArray' columns
mutable FMatrices m_fmatrices;
mutable ColumnStorage<FMatrix> m_fmatrices;
// =======================================================================
/// the actual storage of all 'FMatrix' columns (fixed)
mutable FMatrices m_matricesf;
mutable ColumnStorage<FMatrix> m_matricesf;
// =======================================================================
/// all booked types:
ItemMap m_items;
......
......@@ -3,26 +3,6 @@
// ============================================================================
#include "GaudiAlg/Tuple.h"
#include "GaudiAlg/TupleObj.h"
// ============================================================================
// ============================================================================
/** @file Tuple.cpp
*
* Implementation file for class : Tuple
*
* @date 2002-10-30
* @author Vanya Belyaev Ivan.Belyaev@itep.ru
*/
// ============================================================================
// ============================================================================
/** Standard constructor
* @param tuple pointer to "real" tuple object
*/
// ============================================================================
Tuples::Tuple::Tuple( Tuples::TupleObj* tuple ) : m_tuple( tuple ) {}
// ============================================================================
// ============================================================================
// The END
// ============================================================================
......@@ -144,13 +144,9 @@ namespace
StatusCode column_( Tuples::TupleObj* parent, Container& container, const std::string& name, UT&& value,
ExtraArgs&&... ea )
{
if ( parent->invalid() ) {
return Tuples::ErrorCodes::InvalidTuple;
}
if ( parent->invalid() ) return Tuples::ErrorCodes::InvalidTuple;
auto item = find_or_create( parent, name, container, std::forward<ExtraArgs>( ea )... );
if ( !item ) {
return Tuples::ErrorCodes::InvalidColumn;
}
if ( !item ) return Tuples::ErrorCodes::InvalidColumn;
*item = std::forward<UT>( value );
return StatusCode::SUCCESS;
}
......@@ -246,27 +242,11 @@ Tuples::TupleObj::~TupleObj()
Tuples::Local::s_InstanceCounter.decrement( m_name );
}
// ============================================================================
// release the reference to TupleObj
// if reference counter becomes zero,
// object will be automatically deleted
// ============================================================================
void Tuples::TupleObj::release()
{
// decrease the reference counter
if ( refCount() > 0 ) {
--m_refCount;
}
// check references -- delete if needed
if ( 0 == refCount() ) delete this;
}
// ============================================================================
// write a record to NTuple
// ============================================================================
StatusCode Tuples::TupleObj::write()
{
if ( invalid() ) {
return ErrorCodes::InvalidTuple;
}
if ( invalid() ) return ErrorCodes::InvalidTuple;
return tuple()->write();
}
// ============================================================================
......@@ -297,9 +277,7 @@ namespace
StatusCode Tuples::TupleObj::fill( const char* format... )
{
// check the underlying tuple
if ( invalid() ) {
return ErrorCodes::InvalidTuple;
}
if ( invalid() ) return ErrorCodes::InvalidTuple;
// decode format string into tokens
auto tokens = tokenize( format, " ,;" );
/// decode arguments
......@@ -310,9 +288,7 @@ StatusCode Tuples::TupleObj::fill( const char* format... )
for ( auto token = tokens.cbegin(); tokens.cend() != token && status.isSuccess(); ++token ) {
double val = va_arg( valist, double );
status = column( *token, val );
if ( status.isFailure() ) {
Error( "fill(): Can not add column '" + *token + "' " );
}
if ( status.isFailure() ) Error( "fill(): Can not add column '" + *token + "' " );
}
// mandatory !!!
va_end( valist );
......@@ -325,12 +301,8 @@ StatusCode Tuples::TupleObj::fill( const char* format... )
// ============================================================================
StatusCode Tuples::TupleObj::column( const std::string& name, IOpaqueAddress* address )
{
if ( !evtColType() ) {
return ErrorCodes::InvalidOperation;
}
if ( !address ) {
return Error( "column('" + name + "') IOpaqueAddress* is NULL!", ErrorCodes::InvalidObject );
}
if ( !evtColType() ) return ErrorCodes::InvalidOperation;
if ( !address ) return Error( "column('" + name + "') IOpaqueAddress* is NULL!", ErrorCodes::InvalidObject );
return column_( this, m_addresses, name, address );
}
......@@ -484,9 +456,7 @@ Tuples::TupleObj::FArray* Tuples::TupleObj::fArray( const std::string& name, Tup
{
// existing array ?
auto found = m_farrays.find( name );
if ( m_farrays.end() != found ) {
return found->second.get();
}
if ( m_farrays.end() != found ) return found->second.get();
return create_( this, m_farrays, name,
[&]( const std::string& n, FArray& i ) { return this->tuple()->addIndexedItem( n, *length, i ); } );
}
......@@ -497,9 +467,7 @@ Tuples::TupleObj::FArray* Tuples::TupleObj::fArray( const std::string& name, con
{
// existing array ?
auto found = m_arraysf.find( name );
if ( m_arraysf.end() != found ) {
return found->second.get();
}
if ( m_arraysf.end() != found ) return found->second.get();
return create_( this, m_arraysf, name,
[&]( const std::string& n, FArray& i ) { return this->tuple()->addItem( n, rows, i ); } );
}
......@@ -511,9 +479,7 @@ Tuples::TupleObj::FMatrix* Tuples::TupleObj::fMatrix( const std::string& name, T
{
// existing array ?
auto found = m_fmatrices.find( name );
if ( m_fmatrices.end() != found ) {
return found->second.get();
}
if ( m_fmatrices.end() != found ) return found->second.get();
return create_( this, m_fmatrices, name, [&]( const std::string& n, FMatrix& i ) {
return this->tuple()->addIndexedItem( n, *length, cols, i );
} );
......@@ -526,9 +492,7 @@ Tuples::TupleObj::FMatrix* Tuples::TupleObj::fMatrix( const std::string& name, c
{
// existing array ?
auto found = m_matricesf.find( name );
if ( m_matricesf.end() != found ) {
return found->second.get();
}
if ( m_matricesf.end() != found ) return found->second.get();
return create_( this, m_matricesf, name,
[&]( const std::string& n, FMatrix& i ) { return this->tuple()->addItem( n, rows, cols, i ); } );
}
......
// ============================================================================
// STD & SLT
// ============================================================================
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <vector>
// ============================================================================
// GaudiKernel
// ============================================================================
#include "GaudiKernel/HashMap.h"
#include "GaudiKernel/ICounterSvc.h"
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/Service.h"
#include "GaudiKernel/Stat.h"
// ============================================================================
/** @class CounterSvc
* Simple implementation of the abstract interface ICounterSvc
* @author Markus FRANK
* @author Vanya BELYAEV ibelyaev@physics.syr.edu
* @date 2007-05-25
*/
class CounterSvc : public extends<Service, ICounterSvc>
{
public:
// inherit constructor
using extends::extends;
/// Standard destructor
~CounterSvc() override { remove().ignore(); }
/// Finalization
StatusCode finalize() override
{
if ( msgLevel( MSG::DEBUG ) || m_print ) {
print();
}
remove().ignore();
// finalize the base class
return Service::finalize(); ///< finalize the base class
}
// ==========================================================================
/** Access an existing counter object.
*
* @param group [IN] Hint for smart printing
* @param name [IN] Counter name
*
* @return Pointer to existing counter object (NULL if non existing).
*/
Counter* get( const std::string& group, const std::string& name ) const override;
/// get all counters form the given group:
ICounterSvc::Counters get( const std::string& group ) const override;
/** Create a new counter object. If the counter object exists already
* the existing object is returned. In this event the return code is
* COUNTER_EXISTS. The ownership of the actual counter stays with the
* service.
*
* @param group [IN] Hint for smart printing
* @param name [IN] Counter name
* @param initial_value [IN] Initial counter value
* @param refpCounter [OUT] Reference to store pointer to counter.
*
* @return StatusCode indicating failure or success.
*/
StatusCode create( const std::string& group, const std::string& name, longlong initial_value,
Counter*& refpCounter ) override;
/** Create a new counter object. If the counter object exists already,
* a std::runtime_error exception is thrown. The ownership of the
* actual counter stays with the service.
*
* @param group [IN] Hint for smart printing
* @param name [IN] Counter name
* @param initial_value [IN] Initial counter value
* @param refpCounter [OUT] Reference to store pointer to counter.
*
* @return Fully initialized CountObject.
*/
CountObject create( const std::string& group, const std::string& name, longlong initial_value = 0 ) override;
/** Remove a counter object. If the counter object does not exists,
* the return code is COUNTER_NOT_PRESENT. The counter may not
* be used anymore after this call.
* @param group [IN] Hint for smart printing
* @param name [IN] Counter name
* @param initial_value [IN] Initial counter value
* @param refpCounter [OUT] Reference to store pointer to counter.
* @return StatusCode indicating failure or success.
*/
StatusCode remove( const std::string& group, const std::string& name ) override;
/** Remove all counters of a given group. If no such counter exists
* the return code is COUNTER_NOT_PRESENT
* @param group [IN] Hint for smart printing
* @return StatusCode indicating failure or success.
*/
StatusCode remove( const std::string& group ) override;
/// Remove all known counter objects
virtual StatusCode remove();
/** Print counter value
* @param group [IN] Hint for smart printing
* @param name [IN] Counter name
* @param printer [IN] Print actor
*
* @return StatusCode indicating failure or success.
*/
StatusCode print( const std::string& group, const std::string& name, Printout& printer ) const override;
/** If no such counter exists the return code is COUNTER_NOT_PRESENT
* Note: This call is not direct access.
* @param group [IN] Hint for smart printing
* @param printer [IN] Print actor
*
* @return StatusCode indicating failure or success.
*/
StatusCode print( const std::string& group, Printout& printer ) const override;
/** Print counter value
* @param pCounter [IN] Pointer to Counter object
* @param printer [IN] Print actor
*
* @return StatusCode indicating failure or success.
*/
StatusCode print( const Counter* pCounter, Printout& printer ) const override;
/** Print counter value
* @param refCounter [IN] Reference to CountObject object
* @param printer [IN] Print actor
*
* @return StatusCode indicating failure or success.
*/
StatusCode print( const CountObject& pCounter, Printout& printer ) const override;
/** @param printer [IN] Print actor
* @return StatusCode indicating failure or success.
*/
StatusCode print( Printout& printer ) const override;
/// Default Printout for counters
StatusCode defaultPrintout( MsgStream& log, const Counter* pCounter ) const override;
private:
// find group/name for the counter:
inline std::pair<std::string, std::string> _find( const Counter* c ) const
{
if ( c ) {
for ( const auto& i : m_counts ) {
auto j = std::find_if( i.second.begin(), i.second.end(),
[&]( const NameMap::value_type& k ) { return k.second == c; } );
if ( j != i.second.end() ) return {i.first, j->first};
}
}
return {};
}
// get the overall number of counters
inline size_t num() const
{
return std::accumulate( m_counts.begin(), m_counts.end(), size_t{0}, []( size_t r, const CountMap::value_type& i ) {
return r + std::count_if( i.second.begin(), i.second.end(),
[]( const NameMap::value_type& j ) -> bool { return j.second; } );
} );
}
public:
/// "standard" printout a'la GaudiCommon
void print() const;
private:
typedef GaudiUtils::HashMap<std::string, Counter*> NameMap;
typedef GaudiUtils::HashMap<std::string, NameMap> CountMap;
// the actual map of counters
CountMap m_counts; ///< the actual map of counters
Gaudi::Property<bool> m_print{this, "PrintStat", true, "print statistics"};
Gaudi::Property<std::string> m_header{this, "StatTableHeader",
" Counter :: Group | # | sum | "
"mean/eff^* | rms/err^* | min | max |",
"the header row for the output Stat-table"};
Gaudi::Property<std::string> m_format1{
this, "RegularRowFormat",
" %|15.15s|%|-15.15s|%|32t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |",
"the format for the regular row in the output Stat-table"};
Gaudi::Property<std::string> m_format2{
this, "EfficiencyRowFormat",
"*%|15.15s|%|-15.15s|%|32t||%|10d| |%|11.5g| |(%|#9.7g| +- %|-#9.7g|)%%| ------- | ------- |",
"the format for the regular row in the outptu Stat-table"};
Gaudi::Property<bool> m_useEffFormat{this, "UseEfficiencyRowFormat", true,
"use the special format for printout of efficiency counters"};
};
// ===========================================================================
// Instantiation of a static factory class used by clients
// ===========================================================================
DECLARE_COMPONENT( CounterSvc )
// ===========================================================================
// Access a counter object by name and group
// ===========================================================================
CounterSvc::Counter* CounterSvc::get( const std::string& grp, const std::string& nam ) const
{
auto i = m_counts.find( grp );
if ( m_counts.end() == i ) {
return nullptr;
} // RETURN
auto j = i->second.find( nam );
if ( i->second.end() == j ) {
return nullptr;
} // RETURN
return j->second; // RETURN
}
// ===========================================================================
// get all counters form the given group:
// ===========================================================================
ICounterSvc::Counters CounterSvc::get( const std::string& group ) const
{
ICounterSvc::Counters result;
auto i = m_counts.find( group );
if ( i != m_counts.end() ) {
std::transform( i->second.begin(), i->second.end(), std::back_inserter( result ),
[&]( const NameMap::value_type& j ) {
return CountObject{j.second, i->first, j.first};
} );
}
return result;
}
// ===========================================================================
// Create/get a counter object.
// ===========================================================================
#ifdef __ICC
// disable icc remark #2259: non-pointer conversion from "longlong={long long}" to "double" may lose significant bits
#pragma warning( push )
#pragma warning( disable : 2259 )
#endif
StatusCode CounterSvc::create( const std::string& grp, const std::string& nam, longlong initial_value,
Counter*& refpCounter )
{
// try to find existing counter:
refpCounter = get( grp, nam );
if ( refpCounter ) {
return StatusCode( Status::COUNTER_EXISTS );
} // RETURN
// create the new counter
auto newc = new Counter();
refpCounter = newc;
if ( 0 != initial_value ) {
refpCounter->addFlag( static_cast<double>( initial_value ) ); // icc remark #2259
}
// find a proper group
auto i = m_counts.find( grp );
// (create a group if needed)
if ( m_counts.end() == i ) {
i = m_counts.emplace( grp, NameMap() ).first;
}
// insert new counter with proper name into proper group:
i->second.emplace( nam, newc );
return StatusCode::SUCCESS; // RETURN
}
#ifdef __ICC
// re-enable icc remark #2259
#pragma warning( pop )
#endif
// ===========================================================================
// Create a new counter object. If the counter object exists already,
// ===========================================================================
CounterSvc::CountObject CounterSvc::create( const std::string& group, const std::string& name, longlong initial_value )
{
Counter* p = nullptr;
StatusCode sc = create( group, name, initial_value, p );
if ( sc.isSuccess() && p ) {
return CountObject( p, group, name );
}
throw std::runtime_error( "CounterSvc::Counter('" + group + "::" + name + "') exists already!" );
}
// ===========================================================================
// Remove a counter object. The tuple (group,name) identifies the counter uniquely
// ===========================================================================
StatusCode CounterSvc::remove( const std::string& grp, const std::string& nam )
{
auto i = m_counts.find( grp );
if ( m_counts.end() == i ) {
return StatusCode( Status::COUNTER_NOT_PRESENT );
} // RETURN
auto j = i->second.find( nam );
if ( i->second.end() == j ) {
return StatusCode( Status::COUNTER_NOT_PRESENT );
} // RETURN
delete j->second;
i->second.erase( j );
return StatusCode::SUCCESS;
}
// ===========================================================================
// Remove a group of counter objects.
// ===========================================================================
StatusCode CounterSvc::remove( const std::string& grp )
{
auto i = m_counts.find( grp );
if ( m_counts.end() == i ) {
return StatusCode( Status::COUNTER_NOT_PRESENT );
} // RETURN
for ( auto& j : i->second ) delete j.second;
i->second.clear();
return StatusCode::SUCCESS;
}
// ===========================================================================
// Remove all known counter objects
// ===========================================================================
StatusCode CounterSvc::remove()
{
// remove group by group
for ( auto& i : m_counts ) remove( i.first ).ignore();
m_counts.clear();
return StatusCode::SUCCESS;
}
// ===========================================================================
// Print counter value
// ===========================================================================
StatusCode CounterSvc::print( const std::string& grp, const std::string& nam, Printout& printer ) const
{
const Counter* c = get( grp, nam );
if ( !c ) {
return StatusCode( Status::COUNTER_NOT_PRESENT );
} // RETURN
// create the stream and use it!
return printer( msgStream(), c );
}
namespace
{
/// Small helper class to add a check on the counter to the Printout class.
class conditionalPrint
{
private:
CounterSvc::Printout* printer;
MsgStream* log;
public:
conditionalPrint( CounterSvc::Printout& _p, MsgStream& _l ) : printer( &_p ), log( &_l ) {}
template <class Pair>
void operator()( const Pair& p )
{
if ( p.second ) {
( *printer )( *log, p.second ).ignore();
}
}
};
}
// ===========================================================================
// Print the counter value for the whole group of counters
// ===========================================================================
StatusCode CounterSvc::print( const std::string& grp, Printout& printer ) const
{
auto i = m_counts.find( grp );
if ( m_counts.end() == i ) {
return StatusCode( Status::COUNTER_NOT_PRESENT );
}
// Force printing in alphabetical order
std::map<std::string, Counter*> sorted_map( i->second.begin(), i->second.end() );
std::for_each( sorted_map.begin(), sorted_map.end(), conditionalPrint( printer, msgStream() ) );
return StatusCode::SUCCESS; // RETURN
}
// ===========================================================================
// Print counter value
// ===========================================================================
StatusCode CounterSvc::print( const Counter* pCounter, Printout& printer ) const
{
return printer( msgStream(), pCounter );
}
// ===========================================================================
// Print counter value
// ===========================================================================
StatusCode CounterSvc::print( const CountObject& refCounter, Printout& printer ) const
{
return print( refCounter.counter(), printer );
}
// ===========================================================================
// Print all known counters
// ===========================================================================
StatusCode CounterSvc::print( Printout& printer ) const
{
// Force printing in alphabetical order
std::map<std::pair<std::string, std::string>, Counter*> sorted_map;
for ( const auto& i : m_counts )
for ( const auto& j : i.second ) sorted_map[{i.first, j.first}] = j.second;
std::for_each( sorted_map.begin(), sorted_map.end(), conditionalPrint( printer, msgStream() ) );
return StatusCode::SUCCESS;
}
// ===========================================================================
// Print counter value
// ===========================================================================
StatusCode CounterSvc::defaultPrintout( MsgStream& log, const Counter* c ) const
{
if ( !c ) {
return StatusCode::FAILURE;
}
auto p = _find( c );
log << MSG::ALWAYS << CountObject( const_cast<Counter*>( c ), p.first, p.second ) << endmsg;
return StatusCode::SUCCESS;
}
// ===========================================================================
// "standard" printout a'la GaudiCommon
// ===========================================================================
void CounterSvc::print() const
{
// number of counters
const auto _num = num();
if ( 0 != _num ) {
always() << "Number of counters : " << _num << endmsg << m_header.value() << endmsg;
}
// Force printing in alphabetical order
std::map<std::pair<std::string, std::string>, Counter*> sorted_map;
for ( const auto& i : m_counts ) {
for ( const auto& j : i.second ) {
if ( j.second ) sorted_map[{i.first, j.first}] = j.second;
}
}
for ( const auto& i : sorted_map ) {
always() << Gaudi::Utils::formatAsTableRow( i.first.second, i.first.first, *i.second, m_useEffFormat, m_format1,
m_format2 )
<< endmsg;
}
}
// ============================================================================
// ============================================================================
// The END
// ============================================================================
......@@ -5,9 +5,7 @@
#include "GaudiKernel/IHiveWhiteBoard.h"
#include "GaudiKernel/ThreadLocalContext.h"
#include "GaudiKernel/SvcFactory.h"
DECLARE_SERVICE_FACTORY( AlgExecStateSvc )
DECLARE_COMPONENT( AlgExecStateSvc )
//=============================================================================
......
......@@ -11,12 +11,11 @@
/** @class AlgExecStateSvc
* @brief A service that keeps track of the execution state of Algorithm
* *
*
*/
class AlgExecStateSvc : public extends<Service, IAlgExecStateSvc>
{
public:
/// Constructor
using extends::extends;
typedef IAlgExecStateSvc::AlgStateMap_t AlgStateMap_t;
......
......@@ -35,7 +35,7 @@ StatusCode PythonConfig::evaluateConfig( const std::string& filename, const std:
// Now fire off the translation
handle<> ignored( ( PyRun_String( command.c_str(), Py_file_input, main_namespace.ptr(), main_namespace.ptr() ) ) );
} catch ( error_already_set ) {
} catch ( const error_already_set& ) {
std::cout << "Error in python script:" << std::endl;
PyErr_Print();
return StatusCode::FAILURE;
......
// Include files
// From Gaudi
#include "GaudiKernel/SvcFactory.h"
// local
#include "InertMessageSvc.h"
// ----------------------------------------------------------------------------
......@@ -10,7 +7,7 @@
//
// 12/02/2013: Danilo Piparo
// ----------------------------------------------------------------------------
DECLARE_SERVICE_FACTORY( InertMessageSvc )
DECLARE_COMPONENT( InertMessageSvc )
//---------------------------------------------------------------------------
......
// Include files
// From Gaudi
#include "GaudiKernel/SvcFactory.h"
// local
#include "TBBMessageSvc.h"
// ----------------------------------------------------------------------------
......@@ -10,7 +5,7 @@
//
// 22/06/2012: Marco Clemencic
// ----------------------------------------------------------------------------
DECLARE_SERVICE_FACTORY( TBBMessageSvc )
DECLARE_COMPONENT( TBBMessageSvc )
void TBBMessageSvc::reportMessage( const Message& msg, int outputLevel )
{
......