From 8a1b85159c0a8e81c7d7df7d3a035a12be5a742f Mon Sep 17 00:00:00 2001 From: Will Buttinger <William.Buttinger@cern.ch> Date: Mon, 24 Oct 2016 13:31:31 +0200 Subject: [PATCH] 'new toString method and dumpProperties' (AthAnalysisBaseComps-00-00-28) * AthAnalysisHelper: added toString method, since gaudi's method adds extra quotations around strings of form "['b','a']", and then these will not set correctly. So if a string is given, just pass it straight as a string. * Also added dumpProperties method for quickly inspecting services and tools * Tagging AthAnalysisBaseComps-00-00-28 2016-08-24 Will Buttinger <will@cern.ch> * AthAnalysisHelper: switched initGaudi to use MinimalEventLoopMgr, because it causes creation of fewer services by default, in particular no EventSelector is made, which is good! * SuppressLogging.py: had to not suppress ApplicationMgr for now until ATN tests are ok with it * Tagging AthAnalysisBaseComps-00-00-27 Former-commit-id: 6d171e7dae301988153619be7e2fa973d7494e03 --- .../AthAnalysisBaseComps/AthAnalysisHelper.h | 28 +++++++++++++++++-- .../share/SuppressLogging.py | 20 ++++++++++++- .../src/AthAnalysisHelper.cxx | 10 ++++++- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/Control/AthAnalysisBaseComps/AthAnalysisBaseComps/AthAnalysisHelper.h b/Control/AthAnalysisBaseComps/AthAnalysisBaseComps/AthAnalysisHelper.h index fcb2e8f67dd..3c77ac977df 100644 --- a/Control/AthAnalysisBaseComps/AthAnalysisBaseComps/AthAnalysisHelper.h +++ b/Control/AthAnalysisBaseComps/AthAnalysisBaseComps/AthAnalysisHelper.h @@ -28,6 +28,9 @@ #include "GaudiKernel/IAppMgrUI.h" + +#include "GaudiKernel/ToolHandle.h" + class AthAnalysisHelper { //thought about being a namespace but went for static methods instead, in case I want private data members in future public: @@ -124,10 +127,15 @@ public: return theAlg->setProperty(property, value); } + template<typename T> static std::string toString(const T& value) { return Gaudi::Utils::toString( value ); } + static std::string toString(const std::string& value) { return value; } //gaudi's toString puts extra quote marks around things like "['b']" .. should probably stop that.. + static std::string toString(const char* value) { return value; } //gaudi's toString puts extra quote marks around things like "['b']" .. should probably stop that.. + + ///setProperty for services ... will allow setProperty on already-existing services template<typename T, typename W> static StatusCode setProperty(const ServiceHandle<T>& serviceHandle, const std::string& property, const W& value) { if(serviceHandle.isSet()) { - return dynamic_cast<Service&>(*serviceHandle).setProperty(property,Gaudi::Utils::toString ( value )); + return dynamic_cast<Service&>(*serviceHandle).setProperty(property,toString ( value )); } std::string fullName = serviceHandle.name(); std::string thePropertyName(property); @@ -141,7 +149,7 @@ public: //check if the service already exists if(Gaudi::svcLocator()->existsService(serviceHandle.name())) { //set property on the service directly - return dynamic_cast<Service&>(*serviceHandle).setProperty(property,Gaudi::Utils::toString ( value )); + return dynamic_cast<Service&>(*serviceHandle).setProperty(property,toString ( value )); } //service not existing, ok so add property to catalogue @@ -301,6 +309,22 @@ public: static void printAuxElement(const SG::AuxElement& ae); + ///Dump the properties of an IProperty + //these aren't necessarily the same as what is in the JobOptionsSvc + static void dumpProperties(const IProperty& component); + + template<typename T> static void dumpProperties(const ServiceHandle<T>& handle) { + if(!handle.isSet()) {std::cout << "Please retrieve service before dumping properties" << std::endl; return;} + return dumpProperties(dynamic_cast<const IProperty&>(*handle)); + } + template<typename T> static void dumpProperties(const ToolHandle<T>& handle) { + if(!handle.isSet()) {std::cout << "Please retrieve service before dumping properties" << std::endl; return;} + return dumpProperties(dynamic_cast<const IProperty&>(*handle)); + } + + + + ///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; diff --git a/Control/AthAnalysisBaseComps/share/SuppressLogging.py b/Control/AthAnalysisBaseComps/share/SuppressLogging.py index 51175357476..250d58a7527 100644 --- a/Control/AthAnalysisBaseComps/share/SuppressLogging.py +++ b/Control/AthAnalysisBaseComps/share/SuppressLogging.py @@ -1,5 +1,23 @@ -MessageSvc.setWarning += {"ClassIDSvc","PoolSvc","AthDictLoaderSvc","AthenaPoolAddressProviderSvc","ProxyProviderSvc","DBReplicaSvc","MetaDataSvc","MetaDataStore","AthenaPoolCnvSvc","TagMetaDataStore","EventSelector","ApplicationMgr","CoreDumpSvc","AthMasterSeq","EventPersistencySvc","ActiveStoreSvc","AthenaEventLoopMgr","AthOutSeq","AthRegSeq"}; +MessageSvc.setWarning += {"ClassIDSvc", + "PoolSvc", + "AthDictLoaderSvc", + "AthenaPoolAddressProviderSvc", + "ProxyProviderSvc", + "DBReplicaSvc", + "MetaDataSvc", + "MetaDataStore", + "AthenaPoolCnvSvc", + "TagMetaDataStore", + "EventSelector", + #"ApplicationMgr", can't silence because otherwise ATN tests fail, see ATLINFR-1235 + "CoreDumpSvc", + "AthMasterSeq", + "EventPersistencySvc", + "ActiveStoreSvc", + "AthenaEventLoopMgr", + "AthOutSeq", + "AthRegSeq"}; #also silence storegates if not dumping if not hasattr(StoreGateSvc,"Dump") or StoreGateSvc.Dump: MessageSvc.setWarning += ["StoreGateSvc"] diff --git a/Control/AthAnalysisBaseComps/src/AthAnalysisHelper.cxx b/Control/AthAnalysisBaseComps/src/AthAnalysisHelper.cxx index 743ff543e5e..f87269b3c6e 100644 --- a/Control/AthAnalysisBaseComps/src/AthAnalysisHelper.cxx +++ b/Control/AthAnalysisBaseComps/src/AthAnalysisHelper.cxx @@ -24,6 +24,8 @@ IAppMgrUI* AthAnalysisHelper::initGaudi(const char* options) { } else { propMgr->setProperty( "JobOptionsType", "NONE" ); //no joboptions given } + propMgr->setProperty("EventLoop","MinimalEventLoopMgr"); //using this instead of the default EventLoopMgr means some services (e.g. EventSelector) are not created, which is good! :-) + //configure and return theApp->configure(); propMgr->setProperty("OutputLevel","3"); //INFO @@ -70,4 +72,10 @@ if(typeinfo==typeid(TYPE) && ae.isAvailable<TYPE>(name)) std::cout << ae.auxdata #undef PRINT_AE } -} \ No newline at end of file +} + +void AthAnalysisHelper::dumpProperties(const IProperty& component) { + for(auto p : component.getProperties()) { + std::cout << p->name() << " = " << p->toString() << std::endl; + } +} -- GitLab