Skip to content
Snippets Groups Projects
Commit 6265a987 authored by Will Buttinger's avatar Will Buttinger Committed by Graeme Stewart
Browse files

'changed firstEvent to firstExecute' (AthAnalysisBaseComps-00-00-26)

	* src/AthAnalysisAlgorithm: changed firstEvent method to now be called firstExecute
	* AthAnalysisHelper: added another retrieveMetadata method, which just returns a string, always
	* Tagging AthAnalysisBaseComps-00-00-26

2016-08-02 Will Buttinger <will@cern.ch>
	* src/AthROOTErrorHandlerSvc: added CatchLevel property to catch all messages above or equal to the given level
	* Tagging AthAnalysisBaseComps-00-00-25

2016-08-01 Will Buttinger <will@cern.ch>
	* share/SuppressLogging.py: overhauled logging supression config
	* Tagging AthAnalysisBaseComps-00-00-24

2016-07-27 Will Buttinger <will@cern.ch>
	* Fix for cmake compilation
	* Tagging AthAnalysisBaseComps-00-00-23

2016-07-26  scott snyder  <snyder@bnl.gov>

        * Tagging AthAnalysisBaseComps-00-00-22.
	* Fix clang warnings: missing override keywords.
...
(Long ChangeLog diff - truncated)


Former-commit-id: 7f16b041
parent 4f9b9e49
No related branches found
No related tags found
No related merge requests found
Showing
with 236 additions and 30 deletions
......@@ -41,7 +41,7 @@ class AthAnalysisAlgorithm : public ::AthHistogramAlgorithm, virtual public IInc
const std::string& version=PACKAGE_VERSION);
virtual ~AthAnalysisAlgorithm();
virtual ~AthAnalysisAlgorithm() override;
/// @name Functions providing access to the input/output metadata
/// @{
......@@ -54,7 +54,7 @@ class AthAnalysisAlgorithm : public ::AthHistogramAlgorithm, virtual public IInc
/// @}
/// Function initialising the tool in the correct way in Athena
virtual StatusCode sysInitialize();
virtual StatusCode sysInitialize() override;
/// override to do firstEvent method
virtual StatusCode sysExecute() override;
......@@ -84,13 +84,13 @@ class AthAnalysisAlgorithm : public ::AthHistogramAlgorithm, virtual public IInc
/// @{
/// Function receiving incidents from IncidentSvc/TEvent
virtual void handle( const Incident& inc );
virtual void handle( const Incident& inc ) override;
/// Function called when a new input file is opened
virtual StatusCode beginInputFile();
/// Function called when first event is encountered
virtual StatusCode firstEvent();
/// Function called when first execute is encountered
virtual StatusCode firstExecute();
virtual TFile* currentFile(const char* evtSelName="EventSelector") final;
......
......@@ -26,12 +26,17 @@
#include "AthContainers/AuxElement.h"
#include "GaudiKernel/IAppMgrUI.h"
class AthAnalysisHelper { //thought about being a namespace but went for static methods instead, in case I want private data members in future
public:
AthAnalysisHelper(); //need a constructor to link the dictionary library with the implementation library
///initGaudi method starts the gaudi ApplicationMgr ready for working with all the components
static IAppMgrUI* initGaudi(const char* options = "");
///helper method for adding a property to the JobOptionsSvc
///to list all the properties in the catalogue, do: AthAnalysisHelper::dumpJobOptionProperties()
template<typename W> static StatusCode addPropertyToCatalogue( const std::string& name , const std::string& property, const W& value) {
......@@ -191,6 +196,19 @@ public:
return out;
}
///method that always returns as a string
///you can use from, e.g, pyROOT with
///evt = ROOT.POOL.TEvent()
///...
///ROOT.AAH.retrieveMetadata("/Folder","key",evt.inputMetaStore())
static std::string retrieveMetadata(const std::string& folder, const std::string& key, ServiceHandle<StoreGateSvc>& inputMetaStore) throw(std::exception) {
std::string out("");
StatusCode result = retrieveMetadata(folder,key,out,inputMetaStore);
if(result.isFailure()) { std::cout << "ERROR: Could not retrieve IOVMetadata with folder " << folder << " and key " << key << std::endl; }
return out;
}
///retrieve metadata from the input metadata storegate. Use checkMetaSG.py to see the 'folder' and 'key' values available
///always takes the first CondAttrListCollection (aka IOV) and the first channel number present in that IOV
......@@ -279,12 +297,21 @@ public:
///Print the aux variables of an xAOD object (aux element)
///An alternative to this method is the 'xAOD::dump' method
static void printAuxElement(const SG::AuxElement& ae);
///we keep a static handle to the joboptionsvc, since it's very useful
///can e.g. do: AAH::joSvc->readOptions("myJob.opts","$JOBOPTSEARCHPATH")
static ServiceHandle<IJobOptionsSvc> joSvc;
}; //AthAnalysisHelper class
class AAH : public AthAnalysisHelper {
};
......
<lcgdict>
<class name="AthAnalysisHelper" />
<class name="AAH" />
</lcgdict>
......@@ -17,18 +17,24 @@ atlas_depends_on_subdirs( PUBLIC
find_package( ROOT COMPONENTS Core Tree MathCore Hist RIO pthread )
# Component(s) in the package:
atlas_add_library( AthAnalysisBaseComps
atlas_add_library( AthAnalysisBaseCompsLib
src/*.cxx
PUBLIC_HEADERS AthAnalysisBaseComps
PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES AthenaBaseComps IOVDbDataModel GaudiKernel StoreGateLib SGtests AthContainers
PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES} )
atlas_add_component( AthAnalysisBaseComps
src/components/*.cxx
PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES AthenaBaseComps IOVDbDataModel GaudiKernel StoreGateLib SGtests AthContainers AthAnalysisBaseCompsLib
PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES})
atlas_add_dictionary( AthAnalysisBaseCompsDict
AthAnalysisBaseComps/AthAnalysisBaseCompsDict.h
AthAnalysisBaseComps/selection.xml
INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES ${ROOT_LIBRARIES} AthenaBaseComps StoreGateLib SGtests IOVDbDataModel GaudiKernel AthAnalysisBaseComps AthContainers )
LINK_LIBRARIES ${ROOT_LIBRARIES} AthenaBaseComps StoreGateLib SGtests IOVDbDataModel GaudiKernel AthContainers AthAnalysisBaseCompsLib )
# Install files from the package:
atlas_install_joboptions( share/*.py )
......
......@@ -19,13 +19,12 @@ use AthContainers AthContainers-* Control
## put here your package dependencies...
##
branches python src src/components
library AthAnalysisBaseComps *.cxx
apply_pattern installed_library
#library AthAnalysisBaseComps *.cxx
#apply_pattern installed_library
apply_pattern dual_use_library files="*.cxx"
apply_pattern declare_joboptions files="*.py"
......
#needs to happen at end of joboptions
svcMgr.MessageSvc.OutputLevel=WARNING
if hasattr(svcMgr,"PoolSvc") : svcMgr.PoolSvc.OutputLevel=ERROR #even stricter for PoolSvc! Fixme: maybe just add to setError below?
MessageSvc.setWarning += {"ClassIDSvc","PoolSvc","AthDictLoaderSvc","AthenaPoolAddressProviderSvc","ProxyProviderSvc","DBReplicaSvc","MetaDataSvc","MetaDataStore","AthenaPoolCnvSvc","TagMetaDataStore","EventSelector","ApplicationMgr","CoreDumpSvc","AthMasterSeq","EventPersistencySvc","ActiveStoreSvc","AthenaEventLoopMgr","AthOutSeq","AthRegSeq"};
svcMgr.MessageSvc.setInfo = Configurable.allConfigurables.keys()
svcMgr.MessageSvc.setError = ["HistogramPersistencySvc"] #even stricter for HistogramPersistencySvc too .. gives a silly/harmless warning otherwise
#also silence storegates if not dumping
if not hasattr(StoreGateSvc,"Dump") or StoreGateSvc.Dump: MessageSvc.setWarning += ["StoreGateSvc"]
if hasattr(svcMgr,"InputMetaDataStore"):
if not hasattr(svcMgr.InputMetaDataStore,"Dump") or svcMgr.InputMetaDataStore.Dump: MessageSvc.setWarning += ["InputMetaDataStore"]
MessageSvc.setError += ["HistogramPersistencySvc"] #even stricter for HistogramPersistencySvc too .. gives a silly/harmless warning otherwise
MessageSvc.setError += ["PoolSvc"] #even stricter for PoolSvc, to silence RootCollectionScehemeEditor warnings
#do this to suppress logging from a reinitialize of the eventselector
for svc in MessageSvc.setWarning:
if hasattr(svcMgr,svc): getattr(svcMgr,svc).OutputLevel=WARNING
for svc in MessageSvc.setError:
if hasattr(svcMgr,svc): getattr(svcMgr,svc).OutputLevel=ERROR
if not hasattr(svcMgr,"DBReplicaSvc"):
svcMgr += CfgMgr.DBReplicaSvc()
svcMgr.DBReplicaSvc.OutputLevel=WARNING
excludeList = ['CoreDumpSvc','TopAlg', 'DataModelCompatSvc', 'EventSelector', 'MetaDataSvc', 'ChronoStatSvc', 'AthDictLoaderSvc', 'AuditorSvc', 'ClassIDSvc', 'AthOutSeq', 'RndmGenSvc', 'InputMetaDataStore', 'StatusCodeSvc', 'AthMasterSeq', 'AthenaRootStreamerSvc', 'AthRegSeq', 'IOVDbMetaDataTool', 'Streams', 'ProxyProviderSvc', 'AlgContextAuditor', 'NTupleSvc', 'AthenaPoolCnvSvc', 'EventPersistencySvc', 'AthenaSealSvc', 'IncidentSvc', 'PoolSvc', 'ApplicationMgr', 'MetaDataStore', 'ServiceManager', 'AthenaPoolAddressProviderSvc', 'HistogramDataSvc', 'HistoryStore']
for x in excludeList :
while x in svcMgr.MessageSvc.setInfo : svcMgr.MessageSvc.setInfo.remove(x)
......@@ -57,7 +57,7 @@ StatusCode AthAnalysisAlgorithm::sysInitialize() {
StatusCode AthAnalysisAlgorithm::sysExecute() {
if(!m_doneFirstEvent) {
m_doneFirstEvent=true;
if( firstEvent().isFailure() ) {
if( firstExecute().isFailure() ) {
ATH_MSG_FATAL("Failure in firstEvent method");
return StatusCode::FAILURE;
}
......@@ -95,7 +95,7 @@ StatusCode AthAnalysisAlgorithm::beginInputFile() {
/// Dummy implementation that can be overridden by the derived tool.
///
StatusCode AthAnalysisAlgorithm::firstEvent() {
StatusCode AthAnalysisAlgorithm::firstExecute() {
// Return gracefully:
return StatusCode::SUCCESS;
......
......@@ -6,11 +6,31 @@
#include "AthContainers/AuxTypeRegistry.h"
ServiceHandle<IJobOptionsSvc> AthAnalysisHelper::joSvc = ServiceHandle<IJobOptionsSvc>("JobOptionsSvc","AthAnalysisHelper");
//need a constructor, implemented here, so that the dictionary library is linked to
//the implementation library (see ldd libAthAnalysisBaseCompsDict.so ... needs a link)
AthAnalysisHelper::AthAnalysisHelper() { }
IAppMgrUI* AthAnalysisHelper::initGaudi(const char* options) {
IAppMgrUI* theApp = Gaudi::createApplicationMgr();
//check if already configured
if(theApp->FSMState() != Gaudi::StateMachine::OFFLINE) return theApp;
//set the joboptions
SmartIF<IProperty> propMgr(theApp);
if(strlen(options)) {
propMgr->setProperty("JobOptionsPath",options);
} else {
propMgr->setProperty( "JobOptionsType", "NONE" ); //no joboptions given
}
//configure and return
theApp->configure();
propMgr->setProperty("OutputLevel","3"); //INFO
theApp->initialize();
return theApp;
}
void AthAnalysisHelper::dumpJobOptionProperties(const std::string& client) {
ServiceHandle<IJobOptionsSvc> joSvc("JobOptionsSvc","AthAnalysisHelper");
if(joSvc.retrieve().isFailure()) return;
......@@ -33,15 +53,21 @@ void AthAnalysisHelper::printAuxElement(const SG::AuxElement& ae) {
std::string name = reg.getName( aux );
std::cout << " " << name << " = ";
const std::type_info& typeinfo = *reg.getType(aux);
if(typeinfo==typeid(bool)) std::cout << ae.auxdata<bool>(name) << " (bool)" << std::endl;
else if(typeinfo==typeid(uint)) std::cout << ae.auxdata<uint>(name) << " (unsigned int)" << std::endl;
else if(typeinfo==typeid(float)) std::cout << ae.auxdata<float>(name) << " (float)" << std::endl;
else if(typeinfo==typeid(int)) std::cout << ae.auxdata<int>(name) << " (int)" << std::endl;
else if(typeinfo==typeid(double)) std::cout << ae.auxdata<double>(name) << " (double)" << std::endl;
else if(typeinfo==typeid(unsigned char)) std::cout << int(ae.auxdata<unsigned char>(name)) << " (unsigned char)" << std::endl; //always print as an int, that's what chars usually mean!
else if(typeinfo==typeid(char)) std::cout << int(ae.auxdata<char>(name)) << " (char)" << std::endl; //always print as an int, that's what chars usually mean!
else if(typeinfo==typeid(short)) std::cout << ae.auxdata<short>(name) << " (short)" << std::endl;
else if(typeinfo==typeid(unsigned short)) std::cout << ae.auxdata<unsigned short>(name) << " (unsigned short)" << std::endl;
#define PRINT_AE( TYPE ) \
if(typeinfo==typeid(TYPE) && ae.isAvailable<TYPE>(name)) std::cout << ae.auxdata<TYPE>(name) << " (" << #TYPE << ")" << std::endl;
PRINT_AE( bool )
else PRINT_AE(uint)
else PRINT_AE(int)
else PRINT_AE(float)
else PRINT_AE(double)
else PRINT_AE(unsigned char)
else PRINT_AE(char)
else PRINT_AE(short)
else PRINT_AE(unsigned short)
else PRINT_AE(unsigned long long)
else std::cout << " (" << System::typeinfoName( typeinfo ) << ")" << std::endl;
#undef PRINT_AE
}
}
\ No newline at end of file
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "AthROOTErrorHandlerSvc.h"
#include "TROOT.h"
ErrorHandlerFunc_t AthROOTErrorHandlerSvc::s_oldHandler = 0;
std::map<std::string, int> AthROOTErrorHandlerSvc::s_throwSources;
int AthROOTErrorHandlerSvc::s_catchLevel = kFatal+1;
AthROOTErrorHandlerSvc::AthROOTErrorHandlerSvc(const std::string& name, ISvcLocator *svcLoc) :
AthService(name, svcLoc)
{
//default map:
//levels are: kPrint, kInfo, kWarning, kError, kBreak, kSysError, kFatal
//set in joboptions using: import ROOT ... ROOT.kError
s_throwSources["TBranch::GetBasket"] = kError;
s_throwSources["TFile::ReadBuffer"] = kError;
declareProperty("ThrowSources",s_throwSources,"Map from source to error level. Any message at level or HIGHER will trigger runtime error");
//POSSIBLE EXTENSION: declareProperty("IgnoreSources", s_ignoreSources, "Map from source to error level. Any message at level or LOWER will be ignored");
declareProperty("CatchLevel",s_catchLevel=kFatal+1,"Throw runtime error for all messages at this level or HIGHER");
}
// Destructor
AthROOTErrorHandlerSvc::~AthROOTErrorHandlerSvc() {}
StatusCode AthROOTErrorHandlerSvc::initialize() {
ATH_MSG_DEBUG("Replacing ROOT ErrorHandler");
ErrorHandlerFunc_t h = ::SetErrorHandler( ErrorHandler );
if(h != ErrorHandler) s_oldHandler = h; //if statement protects against double-initialize causing infinite loop in ErrorHandler
return StatusCode::SUCCESS;
}
StatusCode AthROOTErrorHandlerSvc::finalize() {
ATH_MSG_DEBUG("Restoring old ROOT ErrorHandler");
if(s_oldHandler) ::SetErrorHandler( s_oldHandler );
s_oldHandler = 0;
return StatusCode::SUCCESS;
}
void AthROOTErrorHandlerSvc::ErrorHandler( Int_t level, Bool_t abort, const char* location, const char* message ) {
if(s_catchLevel <= level) {
std::ostringstream oss; oss << "AthROOTErrorHandlerSvc detected ROOT message >= CatchLevel " << s_catchLevel << " (" << level << "): " << location << " : " << message;
throw std::runtime_error(oss.str());
}
auto itr = s_throwSources.find(location);
if(itr!=s_throwSources.end() && itr->second <= level) {
std::ostringstream oss; oss << "AthROOTErrorHandlerSvc detected ROOT message from ThrowSources : " << location << " (level=" << level << ") : " << message;
throw std::runtime_error(oss.str());
}
//now pass on to old handler
if(s_oldHandler) s_oldHandler( level, abort, location, message );
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef __ATHROOTERRORHANDLERSVC__
#define __ATHROOTERRORHANDLERSVC__
#include "AthenaBaseComps/AthService.h"
/// AthROOTErrorHandlerSvc:
/// Replaces ROOT's standard error handler in order to detect
/// Problematic ROOT issues such as stale file handles and read failures
///
/// Author: Will Buttinger
///
/*Here's an example of how to include in an athena job options:
theApp.CreateSvc += ["AthROOTErrorHandlerSvc"]
*/
/*Here's an example test for the ROOT prompt:
AAH::initGaudi();
ServiceHandle<IService> s("AthROOTErrorHandlerSvc","");
std::map<std::string, int> sources; sources["test1"] = kError;
AAH::setProperty( s , "ThrowSources", sources )
s->initialize();
Error("aaa","bbb"); //should be ok
Error("test1","hello"); //should throw exception
*/
#include "TError.h"
class AthROOTErrorHandlerSvc : public AthService {
public:
// Constructors, destructor
AthROOTErrorHandlerSvc(const std::string& name, ISvcLocator *svcLoc);
virtual ~AthROOTErrorHandlerSvc();
virtual StatusCode initialize();
virtual StatusCode finalize();
static void ErrorHandler( Int_t level, Bool_t abort, const char* location, const char* message );
private:
static ErrorHandlerFunc_t s_oldHandler;
static std::map<std::string,int> s_throwSources;
static int s_catchLevel;
};
#endif
#include "GaudiKernel/DeclareFactoryEntries.h"
#include "../AthROOTErrorHandlerSvc.h"
DECLARE_SERVICE_FACTORY(AthROOTErrorHandlerSvc)
DECLARE_FACTORY_ENTRIES(AthAnalysisBaseComps) {
DECLARE_SERVICE(AthROOTErrorHandlerSvc)
}
#include "GaudiKernel/LoadFactoryEntries.h"
LOAD_FACTORY_ENTRIES(AthAnalysisBaseComps)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment