ATLAS Offline Software
Loading...
Searching...
No Matches
AAH Class Reference

#include <AthAnalysisHelper.h>

Inheritance diagram for AAH:
Collaboration diagram for AAH:

Static Public Member Functions

static StatusCode setProperty (const GaudiHandleBase &toolHandle, const std::string &property, const int &value, bool override=true)
static StatusCode setProperty (const GaudiHandleBase &toolHandle, const std::string &property, const double &value, bool override=true)
static StatusCode setProperty (const GaudiHandleBase &toolHandle, const std::string &property, const std::string &value, bool override=true)
template<typename W>
static StatusCode setProperty (const std::string &name, const std::string &property, const W &value, bool override=true)
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: ... usual joboptions ... theApp.setup() #triggers population of property catalogue import ROOT ROOT.AAH.setProperty( "ToolSvc.MyTool" , "Property" , str(value) )
template<class W, typename = typename std::enable_if<!std::is_base_of<GaudiHandleBase,W>::value && !std::is_base_of<GaudiHandleArrayBase,W>::value>::type>
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 what to register the joboptionsvc Usage examples: ToolHandle<IMyTool> tool("MyTool/toolName"); CHECK( AthAnalysisHelper::setProperty( tool, "IntegerProperty", 5) ); CHECK( AthAnalysisHelper::setProperty( tool, "StringProperty", "hello") ); CHECK( AthAnalysisHelper::setProperty( tool, "StringArrayProperty", std::vector<std::string>({"a","b","c"}) ) ); CHECK( AthAnalysisHelper::setProperty( tool, "PublicToolHandleProperty", anotherToolHandle) ); CHECK( AthAnalysisHelper::setProperty( tool, "PrivateToolHandleName.SubToolIntegerProperty", 4) ); The last example assumes the 'MyTool' class has declared a ToolHandle("SubTool/PrivateToolHandleName",this) and 'SubTool' class has an integer property called 'SubToolIntegerProperty' declared
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 name, for setting private handles on.
static StatusCode setProperty (const GaudiHandleBase &toolHandle, const std::string &property, const GaudiHandleArrayBase &value, bool override=true)
template<typename W>
static StatusCode setProperty (IAlgTool *tool, const std::string &property, const W &value)
 setProperty on any tool, even when initialized
template<typename W>
static StatusCode setProperty (IAlgorithm *alg, const std::string &property, const W &value)
 setProperty on an alg, even when initialized
template<typename T, typename W>
static StatusCode setProperty (const ServiceHandle< T > &serviceHandle, const std::string &property, const W &value)
 setProperty for services ... will allow setProperty on already-existing services
static IAppMgrUI * initGaudi (const char *options="")
 initGaudi method starts the gaudi ApplicationMgr ready for working with all the components
template<typename W>
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, do: AthAnalysisHelper::dumpJobOptionProperties()
template<typename T>
static std::string toString (const T &value)
static std::string toString (const std::string &value)
static std::string toString (const char *value)
template<typename W>
static W * createTool (const std::string &typeAndName, INamedInterface *parent=0)
 Create a tool using the gaudi factory methods.
static IAlgTool * createTool (const std::string &typeAndName, INamedInterface *parent=0)
static IAlgorithm * createAlgorithm (const std::string &typeAndName)
static bool toolExists (const std::string &fullName)
 check if tool already exists. FullName = Parent.Name
static bool toolExists (const GaudiHandleBase &toolHandle)
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.POOL.TEvent() ... ROOT.AAH.retrieveMetadata("/Folder","key",evt.inputMetaStore())
static std::string retrieveMetadata (const std::string &folder, const std::string &key, ServiceHandle< StoreGateSvc > &inputMetaStore)
template<typename T>
static StatusCode retrieveMetadata (const std::string &folder, const std::string &key, T &out)
 retrieve metadata from the input metadata storegate.
template<typename T>
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
template<typename T>
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, in which case we take the first available channel channels have to be unsigned int, so can use -1 to signal 'take whatever first channel is (it isn't always 0)'
template<typename T>
static StatusCode retrieveMetadata (const std::string &folder, const std::string &key, T &out, const IOVTime &time, int channel=-1)
static void dumpJobOptionProperties (const std::string &client="")
 Dump the properties from joboptionsvc of clients with names beginning with given string.
static void dumpProperties (const std::string &client="")
static void dumpProperties (const SG::AuxElement &ae)
static void dumpProperties (const IProperty &component)
 Dump the properties of an IProperty.
template<typename T>
static void dumpProperties (const GaudiHandle< T > &handle)
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 available (i.e.
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::dump' method.
static TFile * getOutputFile (const std::string &streamName)

Static Public Attributes

static const std::string UNDEFINED = "__UNDEFINED__"

Detailed Description

Definition at line 396 of file AthAnalysisHelper.h.

Member Function Documentation

◆ addPropertyToCatalogue()

template<typename W>
StatusCode AthAnalysisHelper::addPropertyToCatalogue ( const std::string & name,
const std::string & property,
const W & value,
bool override = true )
inlinestaticinherited

helper method for adding a property to the JobOptionsSvc to list all the properties in the catalogue, do: AthAnalysisHelper::dumpJobOptionProperties()

Definition at line 50 of file AthAnalysisHelper.h.

50 {
51 ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc","AthAnalysisHelper");
52 if(joSvc.retrieve().isFailure()) return StatusCode::FAILURE;
53 if(!override) {
54 //check if property already defined. If so, then print a warning and return failure
55 std::string pValue = getProperty( name, property );
56 if( pValue != UNDEFINED) {
57 std::cout << "WARNING: " << name << "." << property << " already defined as " << pValue << " ... ignoring " << Gaudi::Utils::toString ( value ) << std::endl;
58 return StatusCode::FAILURE;
59 }
60 }
61
62 if constexpr (std::is_convertible<W, std::string>::value) {
63 // If value is already convertible to a string, don't use toString().
64 // Otherwise, toString() will add quotes around the string,
65 // which confuses things further on.
66 // (These quotes used to be removed by the old
67 // IJobOptionsSvc::addPropertyToCatalogue interface, but IOptionsSvc::set
68 // doesn't do that.)
69 joSvc->set( name+"."+property , std::string (value) );
70 }
71 else {
72 joSvc->set( name+"."+property , Gaudi::Utils::toString ( value ) );
73 }
74 return StatusCode::SUCCESS;
75 }
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 const std::string UNDEFINED

◆ createAlgorithm()

IAlgorithm * AthAnalysisHelper::createAlgorithm ( const std::string & typeAndName)
inlinestaticinherited

Definition at line 231 of file AthAnalysisHelper.h.

231 {
232 std::string type = typeAndName; std::string name = typeAndName;
233 std::string::size_type pos = type.find('/');
234 if(pos!=std::string::npos) {
235 type.resize (pos);
236 name = name.substr(pos+1,name.length());
237 }
238 IAlgorithm* out = Algorithm::Factory::create(type,name,Gaudi::svcLocator()).release();
239 out->addRef(); //important to increment the reference count so that Gaudi Garbage collection wont delete alg ahead of time
240 return out;
241 }

◆ createTool() [1/2]

template<typename W>
W * AthAnalysisHelper::createTool ( const std::string & typeAndName,
INamedInterface * parent = 0 )
inlinestaticinherited

Create a tool using the gaudi factory methods.

This creates tools that wont be known to the ToolSvc User is responsible for deleting the tool Parent is optional, allows your created tool to inherit OutputLevel properties from the parent If not parent specified, the ToolSvc will be used as the parent Please Note: The preferred method of creating tools is with a ToolHandle Usage: IMyTool* tool = AthAnalysisHelper::createTool<IMyTool>("ToolType/ToolName"); CHECK( AthAnalysisHelper::setProperty( tool, "Property", value ) ); CHECK( tool->initialize() ); Preferred: ToolHandle<IMyTool> tool("ToolType/ToolName"); CHECK( AthAnalysisHelper::setProperty( tool, "Property", value ) ); CHECK( tool.retrieve() );

Definition at line 204 of file AthAnalysisHelper.h.

204 {
205 std::string type = typeAndName; std::string name = typeAndName;
206 std::string::size_type pos = type.find('/');
207 if(pos!=std::string::npos) {
208 type.resize (pos);
209 name = name.substr(pos+1,name.length());
210 }
211 if(parent==0) {
212 //use ToolSvc as parent
213 parent = Gaudi::svcLocator()->service( "ToolSvc" );
214 }
215 IAlgTool *algtool = AlgTool::Factory::create(type,type,name,parent).release();
216 algtool->addRef(); //important to increment the reference count so that Gaudi Garbage collection wont delete alg ahead of time
217 W* out = dynamic_cast<W*>(algtool);
218 if(!out) {
219 std::cout << "ERROR: Tool of type " << type << " does not implement the interface " << System::typeinfoName(typeid(W)) << std::endl;
220 delete algtool;
221 return 0;
222 }
223 return out;
224 }

◆ createTool() [2/2]

IAlgTool * AthAnalysisHelper::createTool ( const std::string & typeAndName,
INamedInterface * parent = 0 )
inlinestaticinherited

Definition at line 225 of file AthAnalysisHelper.h.

225 {
226 return createTool<IAlgTool>(typeAndName,parent);
227 }
static W * createTool(const std::string &typeAndName, INamedInterface *parent=0)
Create a tool using the gaudi factory methods.

◆ dumpJobOptionProperties()

void AthAnalysisHelper::dumpJobOptionProperties ( const std::string & client = "")
staticinherited

Dump the properties from joboptionsvc of clients with names beginning with given string.

If string is blank, will print all clients Example usage: athena -i myJobOptions.py athena> theApp.setup() athena> import ROOT athena> ROOT.AAH.dumpJobOptionProperties() This will display all the joboption properties declared at the start of your job

Definition at line 54 of file AthAnalysisHelper.cxx.

54 {
55 ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc","AthAnalysisHelper");
56 if(joSvc.retrieve().isFailure()) return;
57 for(const auto& [name,value] : joSvc->items()) {
58 if(name.find(client)!=0) continue; //must start with client
59 std::cout << name << " = " << value << std::endl;
60 }
61}

◆ dumpProperties() [1/4]

template<typename T>
void AthAnalysisHelper::dumpProperties ( const GaudiHandle< T > & handle)
inlinestaticinherited

Definition at line 382 of file AthAnalysisHelper.h.

382 {
383 if(!handle.isSet()) {std::cout << "Please retrieve handle before dumping properties" << std::endl; return;}
384 return dumpProperties(dynamic_cast<const IProperty&>(*handle));
385 }
static void dumpProperties(const std::string &client="")

◆ dumpProperties() [2/4]

void AthAnalysisHelper::dumpProperties ( const IProperty & component)
staticinherited

Dump the properties of an IProperty.

Definition at line 98 of file AthAnalysisHelper.cxx.

98 {
99 for(auto p : component.getProperties()) {
100 std::cout << p->name() << " = " << p->toString() << std::endl;
101 }
102}

◆ dumpProperties() [3/4]

void AthAnalysisHelper::dumpProperties ( const SG::AuxElement & ae)
inlinestaticinherited

Definition at line 374 of file AthAnalysisHelper.h.

374{ printAuxElement(ae); } //list properties of an xAOD object
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...

◆ dumpProperties() [4/4]

void AthAnalysisHelper::dumpProperties ( const std::string & client = "")
inlinestaticinherited

Definition at line 363 of file AthAnalysisHelper.h.

363{ dumpJobOptionProperties(client); } //list properties of client present in catalogue
static void dumpJobOptionProperties(const std::string &client="")
Dump the properties from joboptionsvc of clients with names beginning with given string.

◆ getOutputFile()

TFile * AthAnalysisHelper::getOutputFile ( const std::string & streamName)
staticinherited

Definition at line 105 of file AthAnalysisHelper.cxx.

105 {
106 ServiceHandle<IProperty> histSvc("THistSvc","");
107 auto& prop = histSvc->getProperty("Output");
108
109 std::vector<std::string> outputs;
110 if( Gaudi::Parsers::parse(outputs,prop.toString()).isFailure() ) {
111 return nullptr;
112 }
113
114 //extract the DATAFILE part of the string
115 std::string fileName="";
116 for(std::string& output : outputs) {
117 if( output.substr(0,output.find(' '))!=streamName ) continue;
118
119 //got here .. means we found the stream ...
120 for(const auto& attrib : Gaudi::Utils::AttribStringParser(output.substr(output.find(' ')+1))) {
121 std::string TAG = attrib.tag;
122 std::transform(TAG.begin(), TAG.end(), TAG.begin(), [](unsigned char c){ return std::toupper(c); });
123
124 if(TAG=="FILE" || TAG=="DATAFILE") {
125 fileName = attrib.value;
126 break;
127 }
128
129 }
130 if(fileName.length()) {
131 return static_cast<TFile*>(gROOT->GetListOfFiles()->FindObject(fileName.c_str()));
132 }
133
134 }
135 return 0;
136
137}
StatusCode parse(std::tuple< Tup... > &tup, const Gaudi::Parsers::InputData &input)
output
Definition merge.py:16

◆ getProperty()

std::string AthAnalysisHelper::getProperty ( const std::string & client,
const std::string & property )
staticinherited

Check catalogue for property of specified client returns AAH::UNDEFINED in case of no property value available (i.e.

component will take the default property value) otherwise returns the property value in its string representation

Definition at line 63 of file AthAnalysisHelper.cxx.

63 {
64 ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc","AthAnalysisHelper");
65 if(joSvc.retrieve().isFailure()) return UNDEFINED;
66 return joSvc->get(client+"."+property, UNDEFINED);
67}

◆ initGaudi()

IAppMgrUI * AthAnalysisHelper::initGaudi ( const char * options = "")
staticinherited

initGaudi method starts the gaudi ApplicationMgr ready for working with all the components

Definition at line 21 of file AthAnalysisHelper.cxx.

21 {
22 IAppMgrUI* theApp = Gaudi::createApplicationMgr();
23 //check if already configured
24 if(theApp->FSMState() != Gaudi::StateMachine::OFFLINE) return theApp;
25 //set the joboptions
26 SmartIF<IProperty> propMgr(theApp);
27 if(strlen(options)) {
28 if (propMgr->setProperty("JobOptionsPath",options).isFailure()) return nullptr;
29 } else {
30 //no joboptions given
31 if (propMgr->setProperty( "JobOptionsType", "NONE" ).isFailure()) return nullptr;
32 }
33 //using this instead of the default EventLoopMgr means some services (e.g. EventSelector) are not created, which is good! :-)
34 if (propMgr->setProperty("EventLoop","MinimalEventLoopMgr").isFailure()) return nullptr;
35
36 //configure and return
37 if (theApp->configure().isFailure()) return nullptr;
38 propMgr->setProperty("OutputLevel","3").ignore(); //INFO
39 if (theApp->initialize().isFailure()) return nullptr;
40 return theApp;
41}

◆ printAuxElement()

void AthAnalysisHelper::printAuxElement ( const SG::AuxElement & ae)
staticinherited

Print the aux variables of an xAOD object (aux element) An alternative to this method is the 'xAOD::dump' method.

Definition at line 69 of file AthAnalysisHelper.cxx.

69 {
70 const SG::auxid_set_t& auxids = ae.getAuxIDs();
71 SG::AuxTypeRegistry& reg = SG::AuxTypeRegistry::instance();
72 for( SG::auxid_t aux : auxids) {
73 std::string name = reg.getName( aux );
74 std::cout << " " << name << " = ";
75 const std::type_info& typeinfo = *reg.getType(aux);
76#define PRINT_AE( TYPE ) \
77 if(typeinfo==typeid(TYPE)) { \
78 SG::ConstAccessor<TYPE> acc (aux); \
79 if (acc.isAvailable(ae)) std::cout << acc(ae) << " (" << #TYPE << ")" << std::endl; \
80 }
81
82 PRINT_AE( bool )
83 else PRINT_AE(uint)
84 else PRINT_AE(int)
85 else PRINT_AE(float)
86 else PRINT_AE(double)
87 else PRINT_AE(unsigned char)
88 else PRINT_AE(char)
89 else PRINT_AE(short)
90 else PRINT_AE(unsigned short)
91 else PRINT_AE(unsigned long long)
92 else std::cout << " (" << System::typeinfoName( typeinfo ) << ")" << std::endl;
93
94#undef PRINT_AE
95 }
96}
#define PRINT_AE(TYPE)
unsigned int uint
const SG::auxid_set_t & getAuxIDs() const
Return a set of identifiers for existing data items for this object.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27

◆ retrieveMetadata() [1/6]

std::string AthAnalysisHelper::retrieveMetadata ( const std::string & folder,
const std::string & key,
const ServiceHandle< StoreGateSvc > & inputMetaStore )
inlinestaticinherited

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())

Definition at line 254 of file AthAnalysisHelper.h.

254 {
255 std::string out("");
256 StatusCode result = retrieveMetadata(folder,key,out,inputMetaStore);
257 if(result.isFailure()) { std::cout << "ERROR: Could not retrieve IOVMetadata with folder " << folder << " and key " << key << std::endl; }
258 return out;
259 }
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....
::StatusCode StatusCode
StatusCode definition for legacy code.

◆ retrieveMetadata() [2/6]

std::string AthAnalysisHelper::retrieveMetadata ( const std::string & folder,
const std::string & key,
ServiceHandle< StoreGateSvc > & inputMetaStore )
inlinestaticinherited

Definition at line 260 of file AthAnalysisHelper.h.

260 {
261 std::string out("");
262 StatusCode result = retrieveMetadata(folder,key,out,inputMetaStore);
263 if(result.isFailure()) { std::cout << "ERROR: Could not retrieve IOVMetadata with folder " << folder << " and key " << key << std::endl; }
264 return out;
265 }

◆ retrieveMetadata() [3/6]

template<typename T>
StatusCode AthAnalysisHelper::retrieveMetadata ( const std::string & folder,
const std::string & key,
T & out )
inlinestaticinherited

retrieve metadata from the input metadata storegate.

Use 'meta-reader' to see the 'folder' and 'key' values available always takes the first CondAttrListCollection (aka IOV) and the first channel number present in that IOV

Definition at line 270 of file AthAnalysisHelper.h.

270 {
271 ServiceHandle<StoreGateSvc> inputMetaStore("StoreGateSvc/InputMetaDataStore", "AthAnalysisHelper");
272 if(inputMetaStore.retrieve().isFailure()) return StatusCode::FAILURE; //must remember to release
273 StatusCode result = retrieveMetadata(folder,key,out,inputMetaStore);
274 if(inputMetaStore.release().isFailure()) return StatusCode::FAILURE;
275 return result;
276 }

◆ retrieveMetadata() [4/6]

template<typename T>
StatusCode AthAnalysisHelper::retrieveMetadata ( const std::string & folder,
const std::string & key,
T & out,
const IOVTime & time,
int channel = -1 )
inlinestaticinherited

Definition at line 346 of file AthAnalysisHelper.h.

346 {
347 ServiceHandle<StoreGateSvc> inputMetaStore("StoreGateSvc/InputMetaDataStore", "AthAnalysisHelper");
348 if(inputMetaStore.retrieve().isFailure()) return StatusCode::FAILURE; //must remember to release
349 StatusCode result = retrieveMetadata(folder,key,out,inputMetaStore,time,channel);
350 if(inputMetaStore.release().isFailure()) return StatusCode::FAILURE;
351 return result;
352 }

◆ retrieveMetadata() [5/6]

template<typename T>
StatusCode AthAnalysisHelper::retrieveMetadata ( const std::string & folder,
const std::string & key,
T & out,
const ServiceHandle< StoreGateSvc > & inputMetaStore )
inlinestaticinherited

implemenation where you pass it a particular store instead

Definition at line 281 of file AthAnalysisHelper.h.

281 {
282 const IOVMetaDataContainer* cont = 0;
283 if( inputMetaStore->retrieve(cont,folder).isFailure()) return StatusCode::FAILURE;
284
285 //payload is a collection of condattrlistcollections
286 //only look a the first one, assuming it exists, and within that only look at the first channel;
287 if(cont->payloadContainer()->size()>0 && cont->payloadContainer()->at(0)->size()>0) {
288 //just try to retrieve the requested key from the attributelist - we will let it throw the coral::AttributeListException (inherits from std::exception) if it fails
289 //if the typeName is std::string, we will try to use the gaudi parsers to parse it
290 //otherwise we try to do a straight assignment
291 try {
292 const coral::Attribute& attr = cont->payloadContainer()->at(0)->attributeList(cont->payloadContainer()->at(0)->chanNum(0))[key];
293
294 if(attr.specification().typeName()=="string") {
295 if(Gaudi::Parsers::parse(out,attr.data<std::string>()).isFailure()) return StatusCode::FAILURE;
296 } else { //do a straight conversion, and just hope its ok (FIXME: should probably do a check of typeid(T) vs typeName)
297 out = attr.data<T>();
298 }
299 } catch(...) {
300 //anything that goes wrong is taken to be a failure
301 return StatusCode::FAILURE;
302 }
303
304 return StatusCode::SUCCESS;
305 }
306 return StatusCode::FAILURE;
307 }
const AttributeList & attributeList(ChanNum chanNum) const
attribute list for a given channel number
ChanNum chanNum(unsigned int index) const
channel number for index: (index = 0 to size-1)
size_type size() const
number of Chan/AttributeList pairs
const IOVPayloadContainer * payloadContainer() const
Access to payload container.
size_type size() const
size of payload vector
CondAttrListCollection * at(unsigned int i) const
Element access.
unsigned long long T

◆ retrieveMetadata() [6/6]

template<typename T>
StatusCode AthAnalysisHelper::retrieveMetadata ( const std::string & folder,
const std::string & key,
T & out,
const ServiceHandle< StoreGateSvc > & inputMetaStore,
const IOVTime & time,
int channel = -1 )
inlinestaticinherited

retrieve metadata, for a specified IOVTime and a specific channel, unless the channel is -1, in which case we take the first available channel channels have to be unsigned int, so can use -1 to signal 'take whatever first channel is (it isn't always 0)'

Definition at line 311 of file AthAnalysisHelper.h.

311 {
312 const IOVMetaDataContainer* cont = 0;
313 if( inputMetaStore->retrieve(cont,folder).isFailure()) return StatusCode::FAILURE;
314
315 //payload is a collection of condattrlistcollections
316 //have to find first one that the time lies in
317 auto cond = cont->payloadContainer()->find(time);
318 if(cond == cont->payloadContainer()->end()) { return StatusCode::FAILURE; }
319
320 //get the first channel number, if required
321 if(channel<0) channel = (*cond)->chanNum(0);
322
323 //get the channel pair.. checks if it exists...
324 auto attrlist = (*cond)->chanAttrListPair(channel);
325 if(attrlist == (*cond)->end()) { return StatusCode::FAILURE; }
326
327
328 //just try to retrieve the requested key from the attributelist - we will let it throw the coral::AttributeListException (inherits from std::exception) if it fails
329 //if the typeName is std::string, we will try to use the gaudi parsers to parse it
330 //otherwise we try to do a straight assignment
331 try {
332 const coral::Attribute& attr = attrlist->second[key];
333 if(attr.specification().typeName()=="string") {
334 if(Gaudi::Parsers::parse(out,attr.data<std::string>()).isFailure()) return StatusCode::FAILURE;
335 } else { //do a straight conversion, and just hope its ok (FIXME: should probably do a check of typeid(T) vs typeName)
336 out = attr.data<T>();
337 }
338 }
339 catch(...) {
340 return StatusCode::FAILURE;
341 }
342
343 return StatusCode::SUCCESS;
344 }
const_iterator end() const
End of payload vector.
const_iterator find(const IOVTime &time) const
find the first payload that has a IOVRange which includes the

◆ setProperty() [1/11]

StatusCode AAH::setProperty ( const GaudiHandleBase & toolHandle,
const std::string & property,
const double & value,
bool override = true )
inlinestatic

Definition at line 403 of file AthAnalysisHelper.h.

404 { return AthAnalysisHelper::setProperty (toolHandle, property, value, override); }
static StatusCode setProperty(const std::string &name, const std::string &property, const W &value, bool override=true)

◆ setProperty() [2/11]

StatusCode AthAnalysisHelper::setProperty ( const GaudiHandleBase & toolHandle,
const std::string & property,
const GaudiHandleArrayBase & value,
bool override = true )
inlinestatic

Definition at line 138 of file AthAnalysisHelper.h.

138 {
139 return setProperty( toolHandle, property, value.typesAndNames(), override );
140 }
static StatusCode setProperty(const GaudiHandleBase &toolHandle, const std::string &property, const int &value, bool override=true)

◆ setProperty() [3/11]

StatusCode AthAnalysisHelper::setProperty ( const GaudiHandleBase & toolHandle,
const std::string & property,
const GaudiHandleBase & value,
bool override = true )
inlinestatic

Partial template specialization for ToolHandles and ToolHandleArrays ... strips parent name from tool name, for setting private handles on.

Definition at line 131 of file AthAnalysisHelper.h.

131 {
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 );
137 }

◆ setProperty() [4/11]

StatusCode AAH::setProperty ( const GaudiHandleBase & toolHandle,
const std::string & property,
const int & value,
bool override = true )
inlinestatic

Definition at line 401 of file AthAnalysisHelper.h.

402 { return AthAnalysisHelper::setProperty (toolHandle, property, value, override); }

◆ setProperty() [5/11]

StatusCode AAH::setProperty ( const GaudiHandleBase & toolHandle,
const std::string & property,
const std::string & value,
bool override = true )
inlinestatic

Definition at line 405 of file AthAnalysisHelper.h.

406 { return AthAnalysisHelper::setProperty (toolHandle, property, value, override); }

◆ setProperty() [6/11]

template<class W, typename = typename std::enable_if<!std::is_base_of<GaudiHandleBase,W>::value && !std::is_base_of<GaudiHandleArrayBase,W>::value>::type>
StatusCode AthAnalysisHelper::setProperty ( const GaudiHandleBase & toolHandle,
const std::string & property,
const W & value,
bool override = true )
inlinestatic

helper method for setting a property on a tool before retrieving it uses the toolhandle to work out what to register the joboptionsvc Usage examples: ToolHandle<IMyTool> tool("MyTool/toolName"); CHECK( AthAnalysisHelper::setProperty( tool, "IntegerProperty", 5) ); CHECK( AthAnalysisHelper::setProperty( tool, "StringProperty", "hello") ); CHECK( AthAnalysisHelper::setProperty( tool, "StringArrayProperty", std::vector<std::string>({"a","b","c"}) ) ); CHECK( AthAnalysisHelper::setProperty( tool, "PublicToolHandleProperty", anotherToolHandle) ); CHECK( AthAnalysisHelper::setProperty( tool, "PrivateToolHandleName.SubToolIntegerProperty", 4) ); The last example assumes the 'MyTool' class has declared a ToolHandle("SubTool/PrivateToolHandleName",this) and 'SubTool' class has an integer property called 'SubToolIntegerProperty' declared

Definition at line 108 of file AthAnalysisHelper.h.

108 {
109 if(toolHandle.empty()) {
110 std::cout << "ERROR: Empty toolHandle passed to AthAnalysisHelper::setProperty" << std::endl;
111 return StatusCode::FAILURE;
112 }
113 std::string fullName = toolHandle.parentName() + "." + toolHandle.name();
114 std::string thePropertyName(property);
115 //if the property contains any "." then strip the last bit as the property name
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);
120 }
121 //check if the tool already exists, if so then we are too late!!
122 if( toolExists( fullName ) ) {
123 std::cout << "ERROR: Cannot setProperty on a tool that is already initialized" << std::endl;
124 return StatusCode::FAILURE;
125 }
126 //tool not existing, ok so add property to catalogue
127 return addPropertyToCatalogue(fullName, thePropertyName, value, override);
128 }
static bool toolExists(const std::string &fullName)
check if tool already exists. FullName = Parent.Name
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,...

◆ setProperty() [7/11]

template<typename T, typename W>
StatusCode AthAnalysisHelper::setProperty ( const ServiceHandle< T > & serviceHandle,
const std::string & property,
const W & value )
inlinestatic

setProperty for services ... will allow setProperty on already-existing services

Definition at line 168 of file AthAnalysisHelper.h.

168 {
169 if(serviceHandle.isSet()) {
170 return dynamic_cast<Service&>(*serviceHandle).setProperty(property,toString ( value ));
171 }
172 std::string fullName = serviceHandle.name();
173 std::string thePropertyName(property);
174 //if the property contains any "." then strip the last bit as the property name
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);
179 }
180
181 //check if the service already exists
182 if(Gaudi::svcLocator()->existsService(serviceHandle.name())) {
183 //set property on the service directly
184 return dynamic_cast<Service&>(*serviceHandle).setProperty(property,toString ( value ));
185 }
186
187 //service not existing, ok so add property to catalogue
188 return addPropertyToCatalogue(fullName, thePropertyName, value);
189 }
static std::string toString(const T &value)

◆ setProperty() [8/11]

StatusCode AthAnalysisHelper::setProperty ( const std::string & name,
const std::string & property,
const std::string & value,
bool override = true )
inlinestatic

non-template method, for use in joboptions current usage would be: ... usual joboptions ... theApp.setup() #triggers population of property catalogue import ROOT ROOT.AAH.setProperty( "ToolSvc.MyTool" , "Property" , str(value) )

Definition at line 89 of file AthAnalysisHelper.h.

89 {
90 return addPropertyToCatalogue( name, property, value, override );
91 } //set a property for a client in the catalogue

◆ setProperty() [9/11]

template<typename W>
StatusCode AthAnalysisHelper::setProperty ( const std::string & name,
const std::string & property,
const W & value,
bool override = true )
inlinestatic

Definition at line 79 of file AthAnalysisHelper.h.

79 {
80 return addPropertyToCatalogue(name,property,value,override);
81 }

◆ setProperty() [10/11]

template<typename W>
StatusCode AthAnalysisHelper::setProperty ( IAlgorithm * alg,
const std::string & property,
const W & value )
inlinestatic

setProperty on an alg, even when initialized

Definition at line 153 of file AthAnalysisHelper.h.

153 {
154 Gaudi::Algorithm* theAlg = dynamic_cast<Gaudi::Algorithm*>(alg);
155 if(!theAlg) {
156 std::cout << "ERROR: alg is not an Algorithm. Cannot AthAnalysisHelper::setProperty on it" << std::endl;
157 return StatusCode::FAILURE;
158 }
159 return theAlg->setProperty(property, value);
160 }

◆ setProperty() [11/11]

template<typename W>
StatusCode AthAnalysisHelper::setProperty ( IAlgTool * tool,
const std::string & property,
const W & value )
inlinestatic

setProperty on any tool, even when initialized

Definition at line 143 of file AthAnalysisHelper.h.

143 {
144 AlgTool* algtool = dynamic_cast<AlgTool*>(tool);
145 if(!algtool) {
146 std::cout << "ERROR: Tool is not an algtool. Cannot AthAnalysisHelper::setProperty on it" << std::endl;
147 return StatusCode::FAILURE;
148 }
149 return algtool->setProperty(property, value);
150 }

◆ toolExists() [1/2]

bool AthAnalysisHelper::toolExists ( const GaudiHandleBase & toolHandle)
inlinestaticinherited

Definition at line 246 of file AthAnalysisHelper.h.

246{ return toolExists( toolHandle.parentName() + "." + toolHandle.name() ); }

◆ toolExists() [2/2]

bool AthAnalysisHelper::toolExists ( const std::string & fullName)
staticinherited

check if tool already exists. FullName = Parent.Name

Definition at line 43 of file AthAnalysisHelper.cxx.

43 {
44 ServiceHandle<IToolSvc> toolSvc("ToolSvc","AthAnalysisHelper");
45 if(toolSvc.retrieve().isFailure()) return false;
46 auto existingTools = toolSvc->getInstances();
47 for(auto& toolName : existingTools) {
48 if(fullName==toolName) { toolSvc.release().ignore(); return true; }
49 }
50 toolSvc.release().ignore();
51 return false;
52}

◆ toString() [1/3]

std::string AthAnalysisHelper::toString ( const char * value)
inlinestaticinherited

Definition at line 164 of file AthAnalysisHelper.h.

164{ return value; } //gaudi's toString puts extra quote marks around things like "['b']" .. should probably stop that..

◆ toString() [2/3]

std::string AthAnalysisHelper::toString ( const std::string & value)
inlinestaticinherited

Definition at line 163 of file AthAnalysisHelper.h.

163{ return value; } //gaudi's toString puts extra quote marks around things like "['b']" .. should probably stop that..

◆ toString() [3/3]

template<typename T>
std::string AthAnalysisHelper::toString ( const T & value)
inlinestaticinherited

Definition at line 162 of file AthAnalysisHelper.h.

162{ return Gaudi::Utils::toString( value ); }

Member Data Documentation

◆ UNDEFINED

const std::string AthAnalysisHelper::UNDEFINED = "__UNDEFINED__"
staticinherited

Definition at line 42 of file AthAnalysisHelper.h.


The documentation for this class was generated from the following file: