ATLAS Offline Software
Loading...
Searching...
No Matches
AthAnalysisHelper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
9#include "GaudiKernel/AttribStringParser.h"
10#include <algorithm>
11#include <string>
12#include "TROOT.h"
13
14const std::string AthAnalysisHelper::UNDEFINED = "__UNDEFINED__";
15
16//need a constructor, implemented here, so that the dictionary library is linked to
17//the implementation library (see ldd libAthAnalysisBaseCompsDict.so ... needs a link)
19
20
21IAppMgrUI* AthAnalysisHelper::initGaudi(const char* options) {
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}
42
43bool AthAnalysisHelper::toolExists( const std::string& fullName ) {
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}
53
54void AthAnalysisHelper::dumpJobOptionProperties(const std::string& client) {
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}
62
63std::string AthAnalysisHelper::getProperty(const std::string& client, const std::string& property) {
64 ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc","AthAnalysisHelper");
65 if(joSvc.retrieve().isFailure()) return UNDEFINED;
66 return joSvc->get(client+"."+property, UNDEFINED);
67}
68
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}
97
98void AthAnalysisHelper::dumpProperties(const IProperty& component) {
99 for(auto p : component.getProperties()) {
100 std::cout << p->name() << " = " << p->toString() << std::endl;
101 }
102}
103
104
105TFile* AthAnalysisHelper::getOutputFile(const std::string& streamName) {
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}
#define PRINT_AE(TYPE)
Handle mappings between names and auxid_t.
unsigned int uint
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...
static void dumpProperties(const std::string &client="")
static TFile * getOutputFile(const std::string &streamName)
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 void dumpJobOptionProperties(const std::string &client="")
Dump the properties from joboptionsvc of clients with names beginning with given string.
static bool toolExists(const std::string &fullName)
check if tool already exists. FullName = Parent.Name
static IAppMgrUI * initGaudi(const char *options="")
initGaudi method starts the gaudi ApplicationMgr ready for working with all the components
static const std::string UNDEFINED
Base class for elements of a container that can have aux data.
Definition AuxElement.h:483
const SG::auxid_set_t & getAuxIDs() const
Return a set of identifiers for existing data items for this object.
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
A set of aux data identifiers.
Definition AuxTypes.h:47
StatusCode parse(std::tuple< Tup... > &tup, const Gaudi::Parsers::InputData &input)
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27