ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
SampleHandler
Root
fetch.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
//
6
// includes
7
//
8
9
#include <
SampleHandler/fetch.h
>
10
11
#include <sstream>
12
#include <mutex>
13
#include <TPython.h>
14
#include <TString.h>
15
#include <TSystem.h>
16
#include <
SampleHandler/MetaDataQuery.h
>
17
#include <
SampleHandler/MetaDataSample.h
>
18
#include <
SampleHandler/MetaObject.h
>
19
#include <
RootCoreUtils/Assert.h
>
20
#include <
RootCoreUtils/PrintMsg.h
>
21
#include <
SampleHandler/MetaFields.h
>
22
#include <
SampleHandler/Sample.h
>
23
#include <
SampleHandler/SampleHandler.h
>
24
25
//
26
// method implementations
27
//
28
29
namespace
SH
30
{
31
void
fetchMetaData
(
MetaDataQuery
&
query
)
32
{
33
static
std::once_flag loaded;
34
auto
do_load = []() {
35
TString path =
"$ROOTCOREBIN/python/SampleHandler/SampleHandler_QueryAMI.py"
;
36
gSystem->ExpandPathName (path);
37
TPython::LoadMacro (path.Data());
38
};
39
std::call_once (loaded, do_load);
40
41
std::ostringstream command;
42
#if ROOT_VERSION_CODE >= ROOT_VERSION(6,33,01)
43
command <<
"_anyresult = "
;
44
#endif
45
command <<
"SampleHandler_QueryAmi(["
;
46
for
(std::size_t iter = 0, end =
query
.samples.size(); iter != end; ++ iter)
47
{
48
if
(iter != 0)
49
command <<
", "
;
50
command <<
"'"
<<
query
.samples[iter].name <<
"'"
;
51
}
52
command <<
"])"
;
53
#if ROOT_VERSION_CODE >= ROOT_VERSION(6,33,01)
54
std::any result;
55
TPython::Exec (command.str().c_str(), &result);
56
query
= std::any_cast<MetaDataQuery>(result);
57
#else
58
MetaDataQuery
* myquery =
static_cast<
MetaDataQuery
*
>
59
((
void
*) TPython::Eval (command.str().c_str()));
60
query
= *myquery;
61
#endif
62
}
63
64
65
void
fetchMetaData
(
SH::SampleHandler
&
sh
,
bool
override
)
66
{
67
std::vector<SH::Sample*> samples;
68
// typedef std::vector<SH::Sample*> SamplesIter;
69
MetaDataQuery
query
;
70
for
(
SH::SampleHandler::iterator
sample =
sh
.begin(),
71
end =
sh
.end(); sample != end; ++ sample)
72
{
73
std::string name = (*sample)->meta()->castString (
SH::MetaFields::gridName
,(*sample)->name());
74
query
.samples.push_back (
MetaDataSample
(name));
75
samples.push_back (&**sample);
76
}
77
fetchMetaData
(
query
);
78
79
if
(!
query
.messages.empty())
80
RCU_PRINT_MSG
(
query
.messages);
81
for
(std::size_t iter = 0, end =
query
.samples.size(); iter != end; ++ iter)
82
{
83
if
(
query
.samples[iter].unknown)
84
{
85
RCU_WARN_MSG
(
"failed to find sample "
+
query
.samples[iter].name);
86
}
else
87
{
88
RCU_ASSERT
(iter != samples.size());
89
SH::Sample
*sample = samples[iter];
90
91
if
(!
override
)
92
{
93
query
.samples[iter].isData = sample->meta()->castDouble (
SH::MetaFields::isData
,
query
.samples[iter].isData);
94
query
.samples[iter].luminosity = sample->meta()->castDouble (
SH::MetaFields::lumi
,
query
.samples[iter].luminosity);
95
query
.samples[iter].crossSection = sample->meta()->castDouble (
SH::MetaFields::crossSection
,
query
.samples[iter].crossSection);
96
query
.samples[iter].nevents = sample->meta()->castDouble (
SH::MetaFields::numEvents
,
query
.samples[iter].nevents);
97
query
.samples[iter].kfactor = sample->meta()->castDouble (
SH::MetaFields::kfactor
,
query
.samples[iter].kfactor);
98
query
.samples[iter].filterEfficiency = sample->meta()->castDouble (
SH::MetaFields::filterEfficiency
,
query
.samples[iter].filterEfficiency);
99
}
100
if
(
query
.samples[iter].isData != -1)
101
sample->meta()->setDouble (
SH::MetaFields::isData
,
query
.samples[iter].isData);
102
if
(
query
.samples[iter].luminosity != -1)
103
sample->meta()->setDouble (
SH::MetaFields::lumi
,
query
.samples[iter].luminosity);
104
if
(
query
.samples[iter].crossSection != -1)
105
sample->meta()->setDouble (
SH::MetaFields::crossSection
,
query
.samples[iter].crossSection);
106
if
(
query
.samples[iter].nevents != -1)
107
sample->meta()->setDouble (
SH::MetaFields::numEvents
,
query
.samples[iter].nevents);
108
if
(
query
.samples[iter].kfactor != -1)
109
sample->meta()->setDouble (
SH::MetaFields::kfactor
,
query
.samples[iter].kfactor);
110
if
(
query
.samples[iter].filterEfficiency != -1)
111
sample->meta()->setDouble (
SH::MetaFields::filterEfficiency
,
query
.samples[iter].filterEfficiency);
112
}
113
}
114
}
115
}
Assert.h
RCU_ASSERT
#define RCU_ASSERT(x)
Definition
Assert.h:217
MetaDataQuery.h
MetaDataSample.h
MetaFields.h
MetaObject.h
PrintMsg.h
RCU_PRINT_MSG
#define RCU_PRINT_MSG(message)
Definition
PrintMsg.h:44
RCU_WARN_MSG
#define RCU_WARN_MSG(message)
Definition
PrintMsg.h:47
SampleHandler.h
Sample.h
SH::SampleHandler
A class that manages a list of Sample objects.
Definition
SampleHandler.h:53
SH::SampleHandler::iterator
boost::transform_iterator< SamplePtrToRawSample, std::vector< std::shared_ptr< Sample > >::const_iterator > iterator
the iterator to use
Definition
SampleHandler.h:457
SH::Sample
a base class that manages a set of files belonging to a particular data set and the associated meta-d...
Definition
Sample.h:49
fetch.h
RCU::Shell
Definition
ShellExec.cxx:25
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition
PrunDriver.h:15
SH::fetchMetaData
void fetchMetaData(MetaDataQuery &query)
effects: fetch information on all the samples/datasets specified guarantee: basic
Definition
fetch.cxx:31
query
Definition
query.py:1
SH::MetaDataQuery
an object containing the result of an AMI meta-data query
Definition
MetaDataQuery.h:17
SH::MetaDataSample
all the meta-data fields that we may try to read from AMI.
Definition
MetaDataSample.h:15
SH::MetaFields::kfactor
static const std::string kfactor
the k-factor of the sample
Definition
MetaFields.h:74
SH::MetaFields::numEvents
static const std::string numEvents
the number of events
Definition
MetaFields.h:56
SH::MetaFields::gridName
static const std::string gridName
the field containing the name of the dataset on the grid
Definition
MetaFields.h:26
SH::MetaFields::isData
static const std::string isData
whether the sample is data
Definition
MetaFields.h:71
SH::MetaFields::lumi
static const std::string lumi
the luminosity of the sample
Definition
MetaFields.h:68
SH::MetaFields::crossSection
static const std::string crossSection
the cross section field
Definition
MetaFields.h:50
SH::MetaFields::filterEfficiency
static const std::string filterEfficiency
the filter efficiency of the sample
Definition
MetaFields.h:77
Generated on
for ATLAS Offline Software by
1.17.0