|
ATLAS Offline Software
|
Go to the documentation of this file.
13 #ifndef ATHANALYSISBASECOMPS_ATHANALYSISHELPER_H
14 #define ATHANALYSISBASECOMPS_ATHANALYSISHELPER_H 1
17 #include "GaudiKernel/ServiceHandle.h"
19 #include "Gaudi/Interfaces/IOptionsSvc.h"
20 #include "GaudiKernel/IToolSvc.h"
24 #include "GaudiKernel/AlgTool.h"
25 #include "GaudiKernel/Algorithm.h"
29 #include "GaudiKernel/IAppMgrUI.h"
32 #include "GaudiKernel/ToolHandle.h"
34 #include <type_traits>
52 if(joSvc.retrieve().isFailure())
return StatusCode::FAILURE;
57 std::cout <<
"WARNING: " <<
name <<
"." <<
property <<
" already defined as " << pValue <<
" ... ignoring " <<
Gaudi::Utils::toString (
value ) << std::endl;
58 return StatusCode::FAILURE;
69 joSvc->set(
name+
"."+property , std::string (
value) );
74 return StatusCode::SUCCESS;
109 if(toolHandle.empty()) {
110 std::cout <<
"ERROR: Empty toolHandle passed to AthAnalysisHelper::setProperty" << std::endl;
111 return StatusCode::FAILURE;
113 std::string
fullName = toolHandle.parentName() +
"." + toolHandle.name();
114 std::string thePropertyName(property);
116 std::string::size_type dotLocation = thePropertyName.find_last_of(
'.');
117 if(dotLocation != std::string::npos) {
118 fullName +=
"." + thePropertyName.substr(0,dotLocation);
119 thePropertyName = thePropertyName.substr(dotLocation+1,thePropertyName.length()-dotLocation);
123 std::cout <<
"ERROR: Cannot setProperty on a tool that is already initialized" << std::endl;
124 return StatusCode::FAILURE;
131 static StatusCode setProperty(
const GaudiHandleBase& toolHandle,
const std::string& property,
const GaudiHandleBase&
value,
bool override=
true) {
132 std::string subToolName(
value.name());
133 size_t start_pos = subToolName.find(toolHandle.name()+
".");
134 if(start_pos!=std::string::npos) { subToolName.replace( start_pos, toolHandle.name().length()+1,
"" ); }
135 std::string typeAndName =
value.type();
if(!subToolName.empty()) typeAndName +=
"/"+subToolName;
136 return setProperty( toolHandle, property, typeAndName,
override );
138 static StatusCode setProperty(
const GaudiHandleBase& toolHandle,
const std::string& property,
const GaudiHandleArrayBase&
value,
bool override=
true) {
139 return setProperty( toolHandle, property,
value.typesAndNames(),
override );
144 AlgTool* algtool =
dynamic_cast<AlgTool*
>(
tool);
146 std::cout <<
"ERROR: Tool is not an algtool. Cannot AthAnalysisHelper::setProperty on it" << std::endl;
147 return StatusCode::FAILURE;
149 return algtool->setProperty(property,
value);
154 Gaudi::Algorithm* theAlg =
dynamic_cast<Gaudi::Algorithm*
>(
alg);
156 std::cout <<
"ERROR: alg is not an Algorithm. Cannot AthAnalysisHelper::setProperty on it" << std::endl;
157 return StatusCode::FAILURE;
159 return theAlg->setProperty(property,
value);
169 if(serviceHandle.isSet()) {
170 return dynamic_cast<Service&
>(*serviceHandle).setProperty(property,
toString (
value ));
172 std::string
fullName = serviceHandle.name();
173 std::string thePropertyName(property);
175 std::string::size_type dotLocation = thePropertyName.find_last_of(
'.');
176 if(dotLocation != std::string::npos) {
177 fullName +=
"." + thePropertyName.substr(0,dotLocation);
178 thePropertyName = thePropertyName.substr(dotLocation+1,thePropertyName.length()-dotLocation);
182 if(Gaudi::svcLocator()->existsService(serviceHandle.name())) {
184 return dynamic_cast<Service&
>(*serviceHandle).setProperty(property,
toString (
value ));
204 template<
typename W>
static W*
createTool(
const std::string& typeAndName, INamedInterface*
parent = 0) {
205 std::string
type = typeAndName; std::string
name = typeAndName;
206 std::string::size_type
pos =
type.find(
'/');
207 if(
pos!=std::string::npos) {
213 parent = Gaudi::svcLocator()->service(
"ToolSvc" );
217 W*
out =
dynamic_cast<W*
>(algtool);
219 std::cout <<
"ERROR: Tool of type " <<
type <<
" does not implement the interface " << System::typeinfoName(
typeid(
W)) << std::endl;
226 return createTool<IAlgTool>(typeAndName,
parent);
232 std::string
type = typeAndName; std::string
name = typeAndName;
233 std::string::size_type
pos =
type.find(
'/');
234 if(
pos!=std::string::npos) {
238 IAlgorithm*
out = Algorithm::Factory::create(
type,
name,Gaudi::svcLocator()).release();
246 static bool toolExists(
const GaudiHandleBase& toolHandle) {
return toolExists( toolHandle.parentName() +
"." + toolHandle.name() ); }
257 if(
result.isFailure()) { std::cout <<
"ERROR: Could not retrieve IOVMetadata with folder " <<
folder <<
" and key " <<
key << std::endl; }
263 if(
result.isFailure()) { std::cout <<
"ERROR: Could not retrieve IOVMetadata with folder " <<
folder <<
" and key " <<
key << std::endl; }
272 if(inputMetaStore.retrieve().isFailure())
return StatusCode::FAILURE;
274 if(inputMetaStore.release().isFailure())
return StatusCode::FAILURE;
283 if( inputMetaStore->retrieve(cont,
folder).isFailure())
return StatusCode::FAILURE;
294 if(attr.specification().typeName()==
"string") {
297 out = attr.data<
T>();
301 return StatusCode::FAILURE;
304 return StatusCode::SUCCESS;
306 return StatusCode::FAILURE;
313 if( inputMetaStore->retrieve(cont,
folder).isFailure())
return StatusCode::FAILURE;
324 auto attrlist = (*cond)->chanAttrListPair(
channel);
325 if(attrlist == (*cond)->end()) {
return StatusCode::FAILURE; }
333 const coral::Attribute& attr = attrlist->second[
key];
335 if(attr.specification().typeName()==
"string") {
340 out = attr.data<
T>();
344 return StatusCode::FAILURE;
347 return StatusCode::SUCCESS;
352 if(inputMetaStore.retrieve().isFailure())
return StatusCode::FAILURE;
354 if(inputMetaStore.release().isFailure())
return StatusCode::FAILURE;
372 static std::string
getProperty(
const std::string&
client,
const std::string& property);
387 if(!handle.isSet()) {std::cout <<
"Please retrieve handle before dumping properties" << std::endl;
return;}
CondAttrListCollection * at(unsigned int i) const
Element access.
static StatusCode setProperty(const GaudiHandleBase &toolHandle, const std::string &property, const GaudiHandleArrayBase &value, bool override=true)
static bool toolExists(const std::string &fullName)
check if tool already exists. FullName = Parent.Name
static std::string toString(const std::string &value)
StatusCode parse(std::tuple< Tup... > &tup, const Gaudi::Parsers::InputData &input)
static StatusCode setProperty(const std::string &name, const std::string &property, const W &value, bool override=true)
static StatusCode setProperty(const GaudiHandleBase &toolHandle, const std::string &property, const W &value, bool override=true)
helper method for setting a property on a tool before retrieving it uses the toolhandle to work out w...
Base class for elements of a container that can have aux data.
static StatusCode retrieveMetadata(const std::string &folder, const std::string &key, T &out, const ServiceHandle< StoreGateSvc > &inputMetaStore)
implemenation where you pass it a particular store instead
static StatusCode setProperty(IAlgorithm *alg, const std::string &property, const W &value)
setProperty on an alg, even when initialized
static TFile * getOutputFile(const std::string &streamName)
static StatusCode setProperty(IAlgTool *tool, const std::string &property, const W &value)
setProperty on any tool, even when initialized
size_type size() const
size of payload vector
static StatusCode setProperty(const GaudiHandleBase &toolHandle, const std::string &property, const GaudiHandleBase &value, bool override=true)
Partial template specialization for ToolHandles and ToolHandleArrays ... strips parent name from tool...
Basic time unit for IOVSvc. Hold time as a combination of run and event numbers.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
::StatusCode StatusCode
StatusCode definition for legacy code.
static void dumpProperties(const SG::AuxElement &ae)
static StatusCode addPropertyToCatalogue(const std::string &name, const std::string &property, const W &value, bool override=true)
helper method for adding a property to the JobOptionsSvc to list all the properties in the catalogue,...
ChanNum chanNum(unsigned int index) const
channel number for index: (index = 0 to size-1)
static StatusCode setProperty(const std::string &name, const std::string &property, const std::string &value, bool override=true)
non-template method, for use in joboptions current usage would be: ...
const AttributeList & attributeList(ChanNum chanNum) const
attribute list for a given channel number
static StatusCode retrieveMetadata(const std::string &folder, const std::string &key, T &out)
retrieve metadata from the input metadata storegate.
static void dumpProperties(const std::string &client="")
static void dumpJobOptionProperties(const std::string &client="")
Dump the properties from joboptionsvc of clients with names beginning with given string.
static const std::string UNDEFINED
static StatusCode setProperty(const ServiceHandle< T > &serviceHandle, const std::string &property, const W &value)
setProperty for services ... will allow setProperty on already-existing services
size_type size() const
number of Chan/AttributeList pairs
static void dumpProperties(const GaudiHandle< T > &handle)
static IAppMgrUI * initGaudi(const char *options="")
initGaudi method starts the gaudi ApplicationMgr ready for working with all the components
static std::string retrieveMetadata(const std::string &folder, const std::string &key, ServiceHandle< StoreGateSvc > &inputMetaStore)
static StatusCode retrieveMetadata(const std::string &folder, const std::string &key, T &out, const IOVTime &time, int channel=-1)
static bool toolExists(const GaudiHandleBase &toolHandle)
static W * createTool(const std::string &typeAndName, INamedInterface *parent=0)
Create a tool using the gaudi factory methods.
def time(flags, cells_name, *args, **kw)
static void printAuxElement(const SG::AuxElement &ae)
Print the aux variables of an xAOD object (aux element) An alternative to this method is the 'xAOD::d...
const_iterator end() const
End of payload vector.
static std::string getProperty(const std::string &client, const std::string &property)
Check catalogue for property of specified client returns AAH::UNDEFINED in case of no property value ...
static IAlgorithm * createAlgorithm(const std::string &typeAndName)
static IAlgTool * createTool(const std::string &typeAndName, INamedInterface *parent=0)
static std::string toString(const T &value)
static StatusCode retrieveMetadata(const std::string &folder, const std::string &key, T &out, const ServiceHandle< StoreGateSvc > &inputMetaStore, const IOVTime &time, int channel=-1)
retrieve metadata, for a specified IOVTime and a specific channel, unless the channel is -1,...
const_iterator find(const IOVTime &time) const
find the first payload that has a IOVRange which includes the
Base class for elements of a container that can have aux data.
static std::string toString(const char *value)
static std::string retrieveMetadata(const std::string &folder, const std::string &key, const ServiceHandle< StoreGateSvc > &inputMetaStore)
method that always returns as a string you can use from, e.g, pyROOT with evt = ROOT....