ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
AthAnalysisHelper Class Reference

#include <AthAnalysisHelper.h>

Inheritance diagram for AthAnalysisHelper:
Collaboration diagram for AthAnalysisHelper:

Public Member Functions

 AthAnalysisHelper ()
 

Static Public Member Functions

static IAppMgrUI * initGaudi (const char *options="")
 initGaudi method starts the gaudi ApplicationMgr ready for working with all the components More...
 
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() More...
 
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: ... More...
 
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 More...
 
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. More...
 
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 More...
 
template<typename W >
static StatusCode setProperty (IAlgorithm *alg, const std::string &property, const W &value)
 setProperty on an alg, even when initialized More...
 
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 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 More...
 
template<typename W >
static W * createTool (const std::string &typeAndName, INamedInterface *parent=0)
 Create a tool using the gaudi factory methods. More...
 
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 More...
 
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() ... More...
 
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. More...
 
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 More...
 
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)' More...
 
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. More...
 
static void dumpProperties (const std::string &client="")
 
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. More...
 
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. More...
 
static void dumpProperties (const SG::AuxElement &ae)
 
static void dumpProperties (const IProperty &component)
 Dump the properties of an IProperty. More...
 
template<typename T >
static void dumpProperties (const GaudiHandle< T > &handle)
 
static TFile * getOutputFile (const std::string &streamName)
 

Static Public Attributes

static const std::string UNDEFINED = "__UNDEFINED__"
 

Detailed Description

Definition at line 37 of file AthAnalysisHelper.h.

Constructor & Destructor Documentation

◆ AthAnalysisHelper()

AthAnalysisHelper::AthAnalysisHelper ( )

Definition at line 18 of file AthAnalysisHelper.cxx.

18 { }

Member Function Documentation

◆ addPropertyToCatalogue()

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

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 
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  }

◆ createAlgorithm()

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

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 >
static W* AthAnalysisHelper::createTool ( const std::string &  typeAndName,
INamedInterface *  parent = 0 
)
inlinestatic

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]

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

Definition at line 225 of file AthAnalysisHelper.h.

225  {
226  return createTool<IAlgTool>(typeAndName,parent);
227  }

◆ dumpJobOptionProperties()

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

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 >
static void AthAnalysisHelper::dumpProperties ( const GaudiHandle< T > &  handle)
inlinestatic

Definition at line 386 of file AthAnalysisHelper.h.

386  {
387  if(!handle.isSet()) {std::cout << "Please retrieve handle before dumping properties" << std::endl; return;}
388  return dumpProperties(dynamic_cast<const IProperty&>(*handle));
389  }

◆ dumpProperties() [2/4]

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

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]

static void AthAnalysisHelper::dumpProperties ( const SG::AuxElement ae)
inlinestatic

Definition at line 378 of file AthAnalysisHelper.h.

378 { printAuxElement(ae); } //list properties of an xAOD object

◆ dumpProperties() [4/4]

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

Definition at line 367 of file AthAnalysisHelper.h.

367 { dumpJobOptionProperties(client); } //list properties of client present in catalogue

◆ getOutputFile()

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

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(auto attrib : Gaudi::Utils::AttribStringParser(output.substr(output.find(' ')+1))) {
121  auto 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 }

◆ getProperty()

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

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 = "")
static

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

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

◆ retrieveMetadata() [1/6]

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

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  }

◆ retrieveMetadata() [2/6]

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

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 >
static StatusCode AthAnalysisHelper::retrieveMetadata ( const std::string &  folder,
const std::string &  key,
T &  out 
)
inlinestatic

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 >
static StatusCode AthAnalysisHelper::retrieveMetadata ( const std::string &  folder,
const std::string &  key,
T &  out,
const IOVTime time,
int  channel = -1 
)
inlinestatic

Definition at line 350 of file AthAnalysisHelper.h.

350  {
351  ServiceHandle<StoreGateSvc> inputMetaStore("StoreGateSvc/InputMetaDataStore", "AthAnalysisHelper");
352  if(inputMetaStore.retrieve().isFailure()) return StatusCode::FAILURE; //must remember to release
354  if(inputMetaStore.release().isFailure()) return StatusCode::FAILURE;
355  return result;
356  }

◆ retrieveMetadata() [5/6]

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

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  }

◆ retrieveMetadata() [6/6]

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

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  // cppcheck-suppress danglingTempReference; false positive
333  const coral::Attribute& attr = attrlist->second[key];
334  // cppcheck-suppress danglingTempReference; false positive
335  if(attr.specification().typeName()=="string") {
336  // cppcheck-suppress danglingTempReference; false positive
337  if(Gaudi::Parsers::parse(out,attr.data<std::string>()).isFailure()) return StatusCode::FAILURE;
338  } else { //do a straight conversion, and just hope its ok (FIXME: should probably do a check of typeid(T) vs typeName)
339  // cppcheck-suppress danglingTempReference; false positive
340  out = attr.data<T>();
341  }
342  }
343  catch(...) {
344  return StatusCode::FAILURE;
345  }
346 
347  return StatusCode::SUCCESS;
348  }

◆ setProperty() [1/8]

static 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  }

◆ setProperty() [2/8]

static 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() [3/8]

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 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  }

◆ setProperty() [4/8]

template<typename T , typename W >
static 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  }

◆ setProperty() [5/8]

static 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() [6/8]

template<typename W >
static 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() [7/8]

template<typename W >
static 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() [8/8]

template<typename W >
static 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]

static bool AthAnalysisHelper::toolExists ( const GaudiHandleBase &  toolHandle)
inlinestatic

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

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]

static std::string AthAnalysisHelper::toString ( const char *  value)
inlinestatic

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]

static std::string AthAnalysisHelper::toString ( const std::string &  value)
inlinestatic

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 >
static std::string AthAnalysisHelper::toString ( const T &  value)
inlinestatic

Definition at line 162 of file AthAnalysisHelper.h.

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

Member Data Documentation

◆ UNDEFINED

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

Definition at line 42 of file AthAnalysisHelper.h.


The documentation for this class was generated from the following files:
IOVMetaDataContainer::payloadContainer
const IOVPayloadContainer * payloadContainer() const
Access to payload container.
Definition: IOVMetaDataContainer.h:141
IOVPayloadContainer::at
CondAttrListCollection * at(unsigned int i) const
Element access.
Definition: IOVPayloadContainer.h:128
IOVMetaDataContainer
This class is a container for conditions data. It is intended to be used to store conditions data fro...
Definition: IOVMetaDataContainer.h:37
SGout2dot.alg
alg
Definition: SGout2dot.py:243
get_generator_info.result
result
Definition: get_generator_info.py:21
AthAnalysisHelper::toolExists
static bool toolExists(const std::string &fullName)
check if tool already exists. FullName = Parent.Name
Definition: AthAnalysisHelper.cxx:43
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
Gaudi::Parsers::parse
StatusCode parse(std::tuple< Tup... > &tup, const Gaudi::Parsers::InputData &input)
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:284
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:640
AthAnalysisHelper::setProperty
static StatusCode setProperty(const std::string &name, const std::string &property, const W &value, bool override=true)
Definition: AthAnalysisHelper.h:79
JetTiledMap::W
@ W
Definition: TiledEtaPhiMap.h:44
SG::AuxTypeRegistry::getName
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
Definition: AuxTypeRegistry.cxx:882
WriteCellNoiseToCool.fullName
fullName
Definition: WriteCellNoiseToCool.py:461
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
athena.value
value
Definition: athena.py:124
PRINT_AE
#define PRINT_AE(TYPE)
IOVPayloadContainer::size
size_type size() const
size of payload vector
Definition: IOVPayloadContainer.h:121
rerun_display.client
client
Definition: rerun_display.py:31
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:61
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
SG::AuxTypeRegistry::getType
const std::type_info * getType(SG::auxid_t auxid) const
Return the type of an aux data item.
Definition: AuxTypeRegistry.cxx:909
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
test_pyathena.parent
parent
Definition: test_pyathena.py:15
MuonSegmentReaderConfig.histSvc
histSvc
Definition: MuonSegmentReaderConfig.py:96
AthAnalysisHelper::addPropertyToCatalogue
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,...
Definition: AthAnalysisHelper.h:50
CondAttrListCollection::chanNum
ChanNum chanNum(unsigned int index) const
channel number for index: (index = 0 to size-1)
Definition: CondAttrListCollection.h:384
python.AtlRunQueryLib.options
options
Definition: AtlRunQueryLib.py:379
CondAttrListCollection::attributeList
const AttributeList & attributeList(ChanNum chanNum) const
attribute list for a given channel number
Definition: CondAttrListCollection.h:401
SG::AuxElement::getAuxIDs
const SG::auxid_set_t & getAuxIDs() const
Return a set of identifiers for existing data items for this object.
Definition: AuxElement.cxx:335
python.CreateTierZeroArgdict.outputs
outputs
Definition: CreateTierZeroArgdict.py:189
merge.output
output
Definition: merge.py:17
AthAnalysisHelper::dumpProperties
static void dumpProperties(const std::string &client="")
Definition: AthAnalysisHelper.h:367
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
AthAnalysisHelper::dumpJobOptionProperties
static void dumpJobOptionProperties(const std::string &client="")
Dump the properties from joboptionsvc of clients with names beginning with given string.
Definition: AthAnalysisHelper.cxx:54
AthAnalysisHelper::UNDEFINED
static const std::string UNDEFINED
Definition: AthAnalysisHelper.h:42
CondAttrListCollection::size
size_type size() const
number of Chan/AttributeList pairs
Definition: CondAttrListCollection.h:322
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
AthenaPoolExample_Copy.streamName
string streamName
Definition: AthenaPoolExample_Copy.py:39
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
AthAnalysisHelper::printAuxElement
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...
Definition: AthAnalysisHelper.cxx:69
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
IOVPayloadContainer::end
const_iterator end() const
End of payload vector.
Definition: IOVPayloadContainer.h:114
AthAnalysisHelper::getProperty
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 ...
Definition: AthAnalysisHelper.cxx:63
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
SG::auxid_set_t
A set of aux data identifiers.
Definition: AuxTypes.h:47
python.AppMgr.theApp
theApp
Definition: AppMgr.py:771
AthAnalysisHelper::toString
static std::string toString(const T &value)
Definition: AthAnalysisHelper.h:162
python.compressB64.c
def c
Definition: compressB64.py:93
IOVPayloadContainer::find
const_iterator find(const IOVTime &time) const
find the first payload that has a IOVRange which includes the
Definition: IOVPayloadContainer.h:136
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
AthAnalysisHelper::retrieveMetadata
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....
Definition: AthAnalysisHelper.h:254
ServiceHandle< Gaudi::Interfaces::IOptionsSvc >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37