Commit c2ca84a5 authored by Adam Edward Barton's avatar Adam Edward Barton
Browse files

Merge branch 'return_code' into 'master'

merge xAOD::ReturnCode into StatusCode, migrate all users

See merge request atlas/athena!38140
parents d2d352f2 67d4a0ff
......@@ -64,7 +64,7 @@ namespace asg
{
checkType<StatusCode> (StatusCode::SUCCESS, StatusCode::FAILURE, StatusCode::FAILURE, [] (const StatusCode& sc) -> bool {return sc.isSuccess();});
#ifdef ROOTCORE
checkType<xAOD::TReturnCode> (xAOD::TReturnCode::kSuccess, xAOD::TReturnCode::kFailure, xAOD::TReturnCode::kRecoverable, [] (const xAOD::TReturnCode& sc) -> bool {return sc.isSuccess();});
checkType<StatusCode> (StatusCode::SUCCESS, StatusCode::FAILURE, StatusCode::RECOVERABLE, [] (const StatusCode& sc) -> bool {return sc.isSuccess();});
#endif
checkType<bool> (true, false, false, [] (const bool& sc) -> bool {return sc;});
}
......
......@@ -25,13 +25,24 @@
/// $Revision: 612639 $
/// $Date: 2014-08-20 14:26:10 +0200 (Wed, 20 Aug 2014) $
///
class [[nodiscard]] StatusCode {
class
#ifndef __CLING__
// cppyy will generate wrappers both for functions returning a value
// and the value being discarded. If we have [[nodiscard]] on,
// then we'll get warnings when cling compiles these wrappers.
// Since these wrappers are automatically generated by cppyy,
// we can't really avoid these other than by disabling them
// for the cling case.
[[nodiscard]]
#endif
StatusCode {
public:
/// Convenience StatusCode types
enum {
FAILURE = 0,
SUCCESS = 1
SUCCESS = 1,
RECOVERABLE = 2
};
/// Constructor from an integer status code
......@@ -50,6 +61,8 @@ public:
bool isSuccess() const;
/// Check if the operation was a failure
bool isFailure() const;
/// Check if the operation produced a recoverable issue
bool isRecoverable() const;
/// Automatic conversion operator
operator unsigned long() const;
......@@ -61,8 +74,10 @@ public:
/// Enable failure (with a backtrace) on an unchecked status code
static void enableFailure();
static void enableChecking() {enableFailure();};
/// Disable failure (no backtrace) on an unchecked status code
static void disableFailure();
static void disableChecking() {disableFailure();};
private:
/// Code returned by some function
......
......@@ -148,6 +148,12 @@ StatusCode::operator unsigned long() const {
return m_code;
}
bool StatusCode::isRecoverable() const {
m_checked = true;
return ( m_code == RECOVERABLE );
}
void StatusCode::enableFailure() {
s_failure = true;
......
......@@ -49,10 +49,9 @@ void checkType (const T2& scSuccess, const T2& scFailure1, const T2& scFailure2,
int main ()
{
StatusCode::enableFailure ();
xAOD::TReturnCode::enableFailure ();
// checkType<StatusCode> (StatusCode::SUCCESS, StatusCode::FAILURE, StatusCode::FAILURE, [] (const StatusCode& sc) -> bool {return sc.isSuccess();});
// checkType<xAOD::TReturnCode> (xAOD::TReturnCode::kSuccess, xAOD::TReturnCode::kFailure, xAOD::TReturnCode::kRecoverable, [] (const xAOD::TReturnCode& sc) -> bool {return sc.isSuccess();});
// checkType<StatusCode> (StatusCode::SUCCESS, StatusCode::FAILURE, StatusCode::RECOVERABLE, [] (const StatusCode& sc) -> bool {return sc.isSuccess();});
checkType<bool> (true, false, false, [] (const bool& sc) -> bool {return sc;});
return 0;
......
......@@ -8,7 +8,7 @@ cppyy.load_library("libDataModelTestDataReadDict")
def CHECK(sc):
if not sc.isSuccess():
raise Exception ('bad TReturnCode')
raise Exception ('bad StatusCode')
return
......
......@@ -12,7 +12,7 @@ import ROOT
import cppyy
ROOT.xAOD.TEvent
ROOT.xAOD.TReturnCode.enableFailure()
ROOT.StatusCode.enableChecking()
from AthenaCommon.Include import Include
......
......@@ -8,6 +8,7 @@
// Framework include(s).
#include "xAODRootAccess/Init.h"
#include "AsgMessaging/MessageCheck.h"
// EDM include(s).
#include "AthContainers/ConstDataVector.h"
......@@ -18,12 +19,16 @@
#include <TInterpreter.h>
int main() {
ANA_CHECK_SET_TYPE (int);
using namespace asg::msgUserCode;
// Suppress ubsan warning.
CxxUtils::ubsan_suppress ([]() { TInterpreter::Instance(); });
// Set up the runtime environment.
ROOT::EnableImplicitMT();
CHECK( xAOD::Init() );
ANA_CHECK( xAOD::Init() );
// Create a data frame object.
auto df = xAOD::MakeDataFrame( "${ASG_TEST_FILE_DATA}" );
......
......@@ -9,6 +9,7 @@
// Framework include(s).
#include "xAODRootAccess/Init.h"
#include "CxxUtils/ubsan_suppress.h"
#include "AsgMessaging/MessageCheck.h"
// EDM include(s).
#include "xAODBase/IParticleContainer.h"
......@@ -20,12 +21,16 @@
#include <iostream>
int main() {
ANA_CHECK_SET_TYPE (int);
using namespace asg::msgUserCode;
// Suppress ubsan warning.
CxxUtils::ubsan_suppress ([]() { TInterpreter::Instance(); });
// Set up the runtime environment.
ROOT::EnableImplicitMT();
CHECK( xAOD::Init() );
ANA_CHECK( xAOD::Init() );
// Create a data frame object.
auto df = xAOD::MakeDataFrame( "${ASG_TEST_FILE_DATA}" );
......
......@@ -11,6 +11,7 @@
#include "xAODRootAccess/tools/Message.h"
#include "xAODBase/IParticleContainer.h"
#include "CxxUtils/ubsan_suppress.h"
#include "AsgMessaging/MessageCheck.h"
// ROOT include(s).
#include <ROOT/RDataFrame.hxx>
......@@ -21,11 +22,15 @@
#include <iostream>
int main() {
ANA_CHECK_SET_TYPE (int);
using namespace asg::msgUserCode;
// Suppress ubsan warning.
CxxUtils::ubsan_suppress ([]() { TInterpreter::Instance(); });
// Set up the runtime environment.
CHECK( xAOD::Init() );
ANA_CHECK( xAOD::Init() );
// Create a data frame object.
auto df = xAOD::MakeDataFrame( "${ASG_TEST_FILE_DATA}" );
......
......@@ -9,6 +9,7 @@
// xAOD include(s).
#include "xAODRootAccess/Init.h"
#include "xAODRootAccess/tools/Message.h"
#include "AsgMessaging/MessageCheck.h"
// ROOT include(s).
#include <TFile.h>
......@@ -20,8 +21,11 @@
int main() {
ANA_CHECK_SET_TYPE (int);
using namespace asg::msgUserCode;
// Set up the runtime environment.
CHECK( xAOD::Init() );
ANA_CHECK( xAOD::Init() );
// Open the input file.
std::unique_ptr< TFile > ifile( TFile::Open( "${ASG_TEST_FILE_DATA}",
......@@ -34,7 +38,7 @@ int main() {
// Set up the event object.
xAOD::RDataSourceEvent event;
CHECK( event.readFrom( ifile.get() ) );
ANA_CHECK( event.readFrom( ifile.get() ) );
if( event.getEntry( 0 ) < 0 ) {
Error( "dataSourceEvent_test",
XAOD_MESSAGE( "Couldn't load the first event of the input "
......
......@@ -10,6 +10,8 @@
#include "xAODRootAccess/Init.h"
#include "xAODRootAccess/tools/Message.h"
#include "AsgMessaging/MessageCheck.h"
// ROOT include(s).
#include <TError.h>
......@@ -18,8 +20,11 @@
int main() {
ANA_CHECK_SET_TYPE (int);
using namespace asg::msgUserCode;
// Set up the runtime environment.
CHECK( xAOD::Init() );
ANA_CHECK( xAOD::Init() );
// Set up the data source.
xAOD::RDataSource ds( "${ASG_TEST_FILE_DATA}" );
......
......@@ -12,17 +12,6 @@
#include <iostream>
#include <vector>
/// Helper macro for checking return values
#define CHECK( EXP ) \
do { \
auto ret = EXP; \
if( ! ret.isSuccess() ) { \
Error( "dataSource_test", \
XAOD_MESSAGE( "Failed to execute: %s" ), #EXP ); \
return 1; \
} \
} while( false )
/// Helper print operator
template< typename FIRST, typename SECOND >
std::ostream& operator<< ( std::ostream& out,
......
......@@ -29,7 +29,7 @@ atlas_add_library( xAODRootAccess
PUBLIC_HEADERS xAODRootAccess
INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES ${ROOT_LIBRARIES} AthContainers xAODCore xAODEventFormat
xAODRootAccessInterfaces ${extra_libs} )
xAODRootAccessInterfaces AsgMessagingLib ${extra_libs} )
# Build a (Reflex) dictionary library:
atlas_add_dictionary( xAODRootAccessDict
......@@ -69,16 +69,14 @@ endmacro( _add_test )
if( NOT SIMULATIONBASE AND NOT GENERATIONBASE )
_add_test( ut_xaodrootaccess_metadata_test )
_add_test( ut_xaodrootaccess_athenaMode_test )
endif()
if( NOT GENERATIONBASE )
_add_test( ut_xaodrootaccess_remap_test )
_add_test( ut_xaodrootaccess_slimming_test )
_add_test( ut_xaodrootaccess_stats_test )
_add_test( ut_xaodrootaccess_tchain_test )
endif()
_add_test( ut_xaodrootaccess_slimming_test )
_add_test( ut_xaodrootaccess_stats_test )
_add_test( ut_xaodrootaccess_tauxvector_test )
_add_test( ut_xaodrootaccess_tauxstore_test )
_add_test( ut_xaodrootaccess_tauxstore_insertmove_test )
_add_test( ut_xaodrootaccess_tchain_test )
_add_test( ut_xaodrootaccess_tfileaccesstracer_test )
_add_test( ut_xaodrootaccess_tfilemerger_test )
_add_test( ut_xaodrootaccess_tstore_test )
......
......@@ -31,22 +31,22 @@ namespace xAOD {
/// Width of the message source strings
static size_t sMessageSourceWidth = 25;
TReturnCode Init( const char* appname ) {
StatusCode Init( const char* appname ) {
return Init( appname, 0, 0 );
}
TReturnCode Init( const char* appname, int* argc, char** argv ) {
StatusCode Init( const char* appname, int* argc, char** argv ) {
// Check if we need to do anything:
if( sInitialised ) return TReturnCode::kSuccess;
if( sInitialised ) return StatusCode::SUCCESS;
// Set up our own error handler function:
sErrorHandler = ::SetErrorHandler( ErrorHandler );
if( ! sErrorHandler ) {
std::cerr << "<xAOD::Init> ERROR Couldn't set up ROOT message "
<< "filtering" << std::endl;
return TReturnCode::kFailure;
return StatusCode::FAILURE;
}
// Create an application. This is needed to ensure the auto-loading
......@@ -87,7 +87,7 @@ namespace xAOD {
// Return gracefully:
sInitialised = true;
return TReturnCode::kSuccess;
return StatusCode::SUCCESS;
}
void SetMessageSourceWidth( size_t value ) {
......
......@@ -11,7 +11,6 @@
#include "xAODRootAccess/tools/xAODTMetaBranch.h"
#include "xAODRootAccess/tools/xAODTMetaTree.h"
#include "xAODRootAccess/tools/TTransTrees.h"
#include "xAODRootAccess/tools/TReturnCode.h"
#include "xAODRootAccess/tools/TFileMerger.h"
#include "xAODRootAccess/tools/TFileChecker.h"
#include "xAODRootAccess/MakeTransientTree.h"
......@@ -31,7 +30,6 @@
#pragma link C++ class xAODTMetaBranch;
#pragma link C++ class xAODTMetaTree;
#pragma link C++ class xAOD::TTransTrees;
#pragma link C++ class xAOD::TReturnCode;
#pragma link C++ class xAOD::TFileMerger;
#pragma link C++ class xAOD::TFileChecker;
#pragma link C++ function xAOD::MakeTransientTrees(TFile*,const char*);
......
......@@ -90,21 +90,21 @@ namespace xAOD {
/// But user code should probably not fiddle with this function.
///
/// @param mode The structure mode to set
/// @returns The usual TReturnCode values
/// @returns The usual StatusCode values
///
TReturnCode TAuxStore::setStructMode( EStructMode mode ) {
StatusCode TAuxStore::setStructMode( EStructMode mode ) {
// Only allow this on an uninitialised object:
if( m_branches.size() || ( m_structMode != kUndefinedStore ) ) {
::Error( "xAOD::TAuxStore::setStructMode",
XAOD_MESSAGE( "Trying to change the structure mode of an "
"initialised object" ) );
return TReturnCode::kFailure;
return StatusCode::FAILURE;
}
// Make the change:
m_structMode = mode;
return TReturnCode::kSuccess;
return StatusCode::SUCCESS;
}
const char* TAuxStore::prefix() const {
......@@ -159,7 +159,7 @@ namespace xAOD {
///
/// @param tree Pointer to the TTree that is being read from
///
TReturnCode TAuxStore::readFrom( ::TTree* tree, ::Bool_t printWarnings ) {
StatusCode TAuxStore::readFrom( ::TTree* tree, ::Bool_t printWarnings ) {
// Make sure that everything will be re-read after this:
reset();
......@@ -179,7 +179,7 @@ namespace xAOD {
if( ! br ) {
// We might not even have static branches, so this is not an error
// by itself...
return TReturnCode::kSuccess;
return StatusCode::SUCCESS;
}
// In order to read complex objects, like smart pointers from an
// auxiliary container variable-by-variable, the split level of the
......@@ -192,7 +192,7 @@ namespace xAOD {
"The reading of complex variables from it may/will fail!" );
}
return TReturnCode::kSuccess;
return StatusCode::SUCCESS;
}
/// This function is called by the infrastructure to connect the object
......@@ -200,7 +200,7 @@ namespace xAOD {
///
/// @param tree Pointer to the TTree that is being written to
///
TReturnCode TAuxStore::writeTo( ::TTree* tree ) {
StatusCode TAuxStore::writeTo( ::TTree* tree ) {
// Look for any auxiliary branches that have not been connected to yet:
RETURN_CHECK( "xAOD::TAuxStore::writeTo", scanInputTree() );
......@@ -216,7 +216,7 @@ namespace xAOD {
RETURN_CHECK( "xAOD::TAuxStore::writeTo", setupOutputData( id ) );
}
return TReturnCode::kSuccess;
return StatusCode::SUCCESS;
}
::Int_t TAuxStore::getEntry( ::Long64_t entry, ::Int_t getall ) {
......@@ -810,10 +810,10 @@ namespace xAOD {
/// TEvent when connecting to new input files/chains.
///
/// @param tree The tree to collect the information from
/// @returns <code>TReturnCode::kSuccess</code> if the function was
/// @returns <code>StatusCode::SUCCESS</code> if the function was
/// successful, something else otherwise
///
TReturnCode TAuxStore::initStats( ::TTree* tree ) {
StatusCode TAuxStore::initStats( ::TTree* tree ) {
// Connect the object to this input tree:
RETURN_CHECK( "initStats", readFrom( tree, kFALSE ) );
......@@ -832,7 +832,7 @@ namespace xAOD {
stats.setBranchNum( stats.branchNum() + nbranch );
// Return gracefully:
return TReturnCode::kSuccess;
return StatusCode::SUCCESS;
}
/// This internal function takes care of connecting to an individual
......@@ -843,11 +843,11 @@ namespace xAOD {
/// @returns <code>kTRUE</code> if the operation was successful,
/// <code>kFALSE</code> if not
///
TReturnCode TAuxStore::setupInputData( auxid_t auxid ) const {
StatusCode TAuxStore::setupInputData( auxid_t auxid ) const {
// Return right away if we already know that the branch is missing:
if( ( auxid < m_missingBranches.size() ) && m_missingBranches[ auxid ] ) {
return TReturnCode::kRecoverable;
return StatusCode::RECOVERABLE;
}
// Make sure the internal storage is large enough:
......@@ -860,14 +860,14 @@ namespace xAOD {
// Check if we need to do anything:
if( m_vecs[ auxid ] && m_branches[ auxid ] ) {
return TReturnCode::kSuccess;
return StatusCode::SUCCESS;
}
// A little sanity check:
if( ! m_inTree ) {
::Error( "xAOD::TAuxStore::setupInputData",
XAOD_MESSAGE( "No input TTree set up!" ) );
return TReturnCode::kFailure;
return StatusCode::FAILURE;
}
// Another sanity check:
......@@ -875,7 +875,7 @@ namespace xAOD {
::Error( "xAOD::TAuxStore::setupInputData",
XAOD_MESSAGE( "The internal variables of the object got "
"messed up?!?" ) );
return TReturnCode::kFailure;
return StatusCode::FAILURE;
}
// Get the property name:
......@@ -899,7 +899,7 @@ namespace xAOD {
m_missingBranches[ auxid ] = true;
// The branch doesn't exist, but this is not an error per se.
// The user may just be calling isAvailable(...) on the variable.
return TReturnCode::kRecoverable;
return StatusCode::RECOVERABLE;
}
// We have a dynamic branch:
staticBranch = kFALSE;
......@@ -924,7 +924,7 @@ namespace xAOD {
XAOD_MESSAGE( "Branch type and requested structure mode "
"differ for branch: %s" ),
brName.Data() );
return TReturnCode::kFailure;
return StatusCode::FAILURE;
}
// Check what variable it is:
......@@ -934,7 +934,7 @@ namespace xAOD {
::Error( "xAOD::TAuxStore::setupInputData",
XAOD_MESSAGE( "Couldn't determine the type of branch "
"\"%s\"" ), brName.Data() );
return TReturnCode::kFailure;
return StatusCode::FAILURE;
}
// Get the property type:
......@@ -954,7 +954,7 @@ namespace xAOD {
::Error( "xAOD::TAuxStore::setupInputData",
XAOD_MESSAGE( "Can't read/copy variable %s (%s)" ),
brName.Data(), clDummy->GetName() );
return TReturnCode::kRecoverable;
return StatusCode::RECOVERABLE;
}
const TString brTypeName = Utils::getTypeName( *brType ).c_str();
......@@ -970,7 +970,7 @@ namespace xAOD {
::Error( "xAOD::TAuxStore::setupInputData",
XAOD_MESSAGE( "No dictionary available for class \"%s\"" ),
brTypeName.Data() );
return TReturnCode::kFailure;
return StatusCode::FAILURE;
}
}
......@@ -992,7 +992,7 @@ namespace xAOD {
"variable %s (%i)" ),
brName.Data(),
static_cast< int >( auxid ) );
return TReturnCode::kFailure;
return StatusCode::FAILURE;
}
// Create a new branch handle:
......@@ -1045,7 +1045,7 @@ namespace xAOD {
m_vecs[ auxid ] = 0;
delete m_branches[ auxid ];
m_branches[ auxid ] = 0;
return TReturnCode::kFailure;
return StatusCode::FAILURE;
}
// Get the current entry:
......@@ -1084,7 +1084,7 @@ namespace xAOD {
}
// Return gracefully:
return TReturnCode::kSuccess;
return StatusCode::SUCCESS;
}
/// This function is used internally to create a "simple" output branch
......@@ -1094,13 +1094,13 @@ namespace xAOD {
/// @returns <code>kTRUE</code> if the operation was successful,
/// <code>kFALSE</code> if not
///
TReturnCode TAuxStore::setupOutputData( auxid_t auxid ) const {
StatusCode TAuxStore::setupOutputData( auxid_t auxid ) const {
// Check whether we need to do anything:
if( ! m_outTree ) return TReturnCode::kSuccess;
if( ! m_outTree ) return StatusCode::SUCCESS;
// Check if the variable needs to be written out:
if( ! isAuxIDSelected( auxid ) ) return TReturnCode::kSuccess;
if( ! isAuxIDSelected( auxid ) ) return StatusCode::SUCCESS;
// Make sure that containers are large enough:
if( m_vecs.size() <= auxid ) {
......@@ -1114,7 +1114,7 @@ namespace xAOD {
}
// Check if this auxiliary variable is already in the output:
if( m_branchesWritten[ auxid ] ) return TReturnCode::kSuccess;
if( m_branchesWritten[ auxid ] ) return StatusCode::SUCCESS;
// Check if the variable was put into the transient store as a
// decoration, and now needs to be put into the output file:
......@@ -1126,7 +1126,7 @@ namespace xAOD {
if( ! pptr ) {
::Fatal( "xAOD::TAuxStore::setupOutputData",
XAOD_MESSAGE( "Internal logic error detected" ) );
return TReturnCode::kFailure;
return StatusCode::FAILURE;
}
// The registry:
......@@ -1139,7 +1139,7 @@ namespace xAOD {
::Error( "xAOD::TAuxStore::setupOutputData",
XAOD_MESSAGE( "Couldn't create decoration in memory "
"for writing" ) );
return TReturnCode::kFailure;
return StatusCode::FAILURE;
}
// Get the type of this variable:
......@@ -1149,7 +1149,7 @@ namespace xAOD {
XAOD_MESSAGE( "Couldn't get the type of transient "
"variable %i" ),
static_cast< int >( auxid ) );
return TReturnCode::kFailure;
return StatusCode::FAILURE;
}
// Now get the factory for this variable:
const SG::IAuxTypeVectorFactory* factory =
......@@ -1158,7 +1158,7 @@ namespace xAOD {
::Error( "xAOD::TAuxStore::setupOutputData",
XAOD_MESSAGE( "No factory found for transient variable "
"%i" ), static_cast< int >( auxid ) );
return TReturnCode::kFailure;
return StatusCode::FAILURE;
}
// Finally, do the copy:
......@@ -1187,7 +1187,7 @@ namespace xAOD {
::Error( "xAOD::TAuxStore::setupOutputData",
XAOD_MESSAGE( "Structure mode unknown for variable %s" ),
SG::AuxTypeRegistry::instance().getName( auxid ).c_str() );
return TReturnCode::kFailure;
return StatusCode::FAILURE;
}
// Check if the variable exists already in memory:
......@@ -1236,7 +1236,7 @@ namespace xAOD {
// variable will not be accessed in a typeless way anymore.
m_branchesWritten[ auxid ] = true;
// Return gracefully:
return TReturnCode::kSuccess;
return StatusCode::SUCCESS;
}
// Check that we know the type of the branch:
......@@ -1245,7 +1245,7 @@ namespace xAOD {
::Error( "xAOD::TAuxStore::setupOutputData",
XAOD_MESSAGE( "There's an internal logic error in the "
"code" ) );
return TReturnCode::kFailure;
return StatusCode::FAILURE;