ATLAS Offline Software
Loading...
Searching...
No Matches
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
10
11#include <sstream>
12#include <mutex>
13#include <TPython.h>
14#include <TString.h>
15#include <TSystem.h>
24
25//
26// method implementations
27//
28
29namespace SH
30{
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;
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 }
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}
#define RCU_ASSERT(x)
Definition Assert.h:222
#define RCU_PRINT_MSG(message)
Definition PrintMsg.h:49
#define RCU_WARN_MSG(message)
Definition PrintMsg.h:52
A class that manages a list of Sample objects.
std::vector< Sample * >::const_iterator iterator
the iterator to use
a base class that manages a set of files belonging to a particular data set and the associated meta-d...
Definition Sample.h:54
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition PrunDriver.h:15
void fetchMetaData(MetaDataQuery &query)
effects: fetch information on all the samples/datasets specified guarantee: basic
Definition fetch.cxx:31
Definition query.py:1
an object containing the result of an AMI meta-data query
all the meta-data fields that we may try to read from AMI.
static const std::string kfactor
the k-factor of the sample
Definition MetaFields.h:82
static const std::string numEvents
the number of events
Definition MetaFields.h:64
static const std::string gridName
the field containing the name of the dataset on the grid
Definition MetaFields.h:34
static const std::string isData
whether the sample is data
Definition MetaFields.h:79
static const std::string lumi
the luminosity of the sample
Definition MetaFields.h:76
static const std::string crossSection
the cross section field
Definition MetaFields.h:58
static const std::string filterEfficiency
the filter efficiency of the sample
Definition MetaFields.h:85