ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthAnalysisBaseComps
src
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
5
#include "
AthAnalysisBaseComps/AthAnalysisHelper.h
"
6
7
#include "
AthContainers/AuxTypeRegistry.h
"
8
9
#include "GaudiKernel/AttribStringParser.h"
10
#include <algorithm>
11
#include <string>
12
#include "TROOT.h"
13
14
const
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)
18
AthAnalysisHelper::AthAnalysisHelper
() { }
19
20
21
IAppMgrUI*
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
43
bool
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
54
void
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
63
std::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
69
void
AthAnalysisHelper::printAuxElement
(
const
SG::AuxElement
& ae) {
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
}
97
98
void
AthAnalysisHelper::dumpProperties
(
const
IProperty& component) {
99
for
(
auto
p : component.getProperties()) {
100
std::cout << p->name() <<
" = "
<< p->toString() << std::endl;
101
}
102
}
103
104
105
TFile*
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
}
PRINT_AE
#define PRINT_AE(TYPE)
AthAnalysisHelper.h
AuxTypeRegistry.h
Handle mappings between names and auxid_t.
uint
unsigned int uint
Definition
LArOFPhaseFill.cxx:19
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
AthAnalysisHelper::dumpProperties
static void dumpProperties(const std::string &client="")
Definition
AthAnalysisHelper.h:363
AthAnalysisHelper::getOutputFile
static TFile * getOutputFile(const std::string &streamName)
Definition
AthAnalysisHelper.cxx:105
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
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::toolExists
static bool toolExists(const std::string &fullName)
check if tool already exists. FullName = Parent.Name
Definition
AthAnalysisHelper.cxx:43
AthAnalysisHelper::initGaudi
static IAppMgrUI * initGaudi(const char *options="")
initGaudi method starts the gaudi ApplicationMgr ready for working with all the components
Definition
AthAnalysisHelper.cxx:21
AthAnalysisHelper::UNDEFINED
static const std::string UNDEFINED
Definition
AthAnalysisHelper.h:42
AthAnalysisHelper::AthAnalysisHelper
AthAnalysisHelper()
Definition
AthAnalysisHelper.cxx:18
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition
AuxTypeRegistry.h:61
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition
AuxTypeRegistry.cxx:640
SG::auxid_set_t
A set of aux data identifiers.
Definition
AuxTypes.h:47
ServiceHandle
Definition
ClusterMakerTool.h:36
Gaudi::Parsers::parse
StatusCode parse(std::tuple< Tup... > &tup, const Gaudi::Parsers::InputData &input)
Definition
CaloGPUClusterAndCellDataMonitorOptions.h:284
SG::AuxElement
AuxElement(SG::AuxVectorData *container, size_t index)
Base class for elements of a container that can have aux data.
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition
AuxTypes.h:27
Generated on
for ATLAS Offline Software by
1.17.0