17 size_t ExpPos =
str.find(exp);
18 if (ExpPos == std::string::npos)
return str;
19 str.replace(ExpPos,
exp.size(),rep);
38 std::map<std::string, int> weight_names{};
42 return StatusCode::SUCCESS;
48 return StatusCode::FAILURE;
58 return StatusCode::SUCCESS;
62 const EventContext& ctx = Gaudi::Hive::currentContext();
64 setFilterPassed(
true);
69 return StatusCode::FAILURE;
74 int mc_channel = !isData ? evtInfo->mcChannelNumber() : 0.;
75 unsigned int run_number = evtInfo->runNumber();
77 std::string trigger_stream{};
80 std::vector<RunMetaData>::iterator itr =
82 return meta.run_number == run_number && meta.trigger_stream == trigger_stream;
85 ATH_MSG_WARNING(
"No meta data information is available for " << run_number <<
". Please check on which stream you're running");
86 m_run_meta.emplace_back(run_number, trigger_stream);
89 itr->proc_events += 1;
90 itr->processed_blocks.insert(evtInfo->lumiBlock());
91 if (!itr->has_book_keeper) {
92 itr->total_lumi_blocks.insert(evtInfo->lumiBlock());
96 const unsigned int num_lhe = !
m_storeLHE ? 1 : evtInfo->mcEventWeights().size();
97 for (
unsigned int lhe_var = 0; lhe_var < num_lhe; ++lhe_var) {
98 std::vector<SimMetaData>::iterator itr =
100 return meta.mc_channel == mc_channel && meta.prw_channel == run_number && meta.variation_number == lhe_var;
103 ATH_MSG_WARNING(
"Failed to retrieve a proper meta data for dsid: " << mc_channel <<
" period: " << run_number
104 <<
" lhe weight: " << lhe_var);
105 m_sim_meta.emplace_back(mc_channel, run_number);
107 itr->weight_name =
"IncompleteMetaData";
108 itr->variation_number = lhe_var;
110 itr->proc_events += 1;
111 if (itr->has_book_keeper)
continue;
113 ATH_MSG_WARNING(
"Cut book keeper has not been loaded for sample DSID: "
114 << itr->mc_channel <<
" period: " << itr->prw_channel <<
" lhe variation: " << lhe_var);
117 itr->tot_events += 1;
118 const double weight = evtInfo->mcEventWeight(lhe_var);
119 itr->sum_w += weight;
120 itr->sum_w_squared += weight * weight;
124 return StatusCode::SUCCESS;
130 if (!
inputMetaStore()->retrieve(bks,
"CutBookkeepers").isSuccess()) {
131 ATH_MSG_WARNING(
"Could not retrieve the CutBookKeeperContainer. Although it should be there");
136 ATH_MSG_INFO(
"Check cutbook keeper "<<cbk->inputStream()<<
" name: "<<cbk->name()<<
" cycle: "<<cbk->cycle());
137 if (cbk->inputStream() == Stream && cbk->name() == cbk_name && cbk->cycle() > maxCycle) {
138 maxCycle = cbk->cycle();
142 }
else ATH_MSG_WARNING(
"The CutBookkeepers are not present in the file ");
143 if (!all)
ATH_MSG_DEBUG(
"Failed to retrieve cut book keeper for Stream: "<<Stream<<
" cbk_name: "<<cbk_name);
155 ATH_MSG_FATAL(
"The EventTypes() container of the EventStreamInfo is empty! Something wrong with the input file?");
156 return StatusCode::FAILURE;
164 ATH_MSG_WARNING(
"FileMetaData not found in input file, setting m_isDerivedAOD=false.");
167 std::string dataType{};
169 ATH_MSG_WARNING(
"MetaDataType::dataType not found in xAOD::FileMetaData, setting m_isDerivedAOD=false.");
175 std::string cbk_stream{};
176 using namespace std::literals;
177 for (
const std::string & trial: {
"StreamAOD"s,
"StreamESD"s,
"unknownStream"s }) {
182 const bool contains_keeper = all !=
nullptr;
183 if (!contains_keeper) {
188 std::string trigger_stream{};
191 std::vector<RunMetaData>::iterator itr =
193 return meta.run_number == run_number && trigger_stream == meta.trigger_stream;
197 m_run_meta.emplace_back(run_number, trigger_stream);
202 for (
const auto& Lumi : esi->
getLumiBlockNumbers()) { itr->total_lumi_blocks.insert(Lumi); }
203 itr->has_book_keeper = contains_keeper;
204 if (contains_keeper) itr->tot_events += all->nAcceptedEvents();
206 int dsid = esi->
getEventTypes().begin()->mc_channel_number();
210 std::vector<std::string> weight_names{};
212 std::map<std::string, int> weight_map{};
214 weight_names.resize(weight_map.size());
215 for (
const auto& w_pair : weight_map) { weight_names[w_pair.second] = w_pair.first; }
216 if (weight_names.empty()) {
218 weight_names.push_back(
"");
221 weight_names.push_back(
"");
223 for (
unsigned int lhe_var = 0; lhe_var < weight_names.size(); ++lhe_var) {
224 const std::string& lhe_weight = weight_names[lhe_var];
225 std::vector<SimMetaData>::iterator itr =
227 return meta.mc_channel == dsid && meta.prw_channel == run && meta.variation_number == lhe_var;
232 itr->weight_name = weight_names[lhe_var];
233 itr->variation_number = lhe_var;
239 std::vector<std::string> cb_names;
240 cb_names.emplace_back(lhe_weight);
241 cb_names.emplace_back(
"LHE3Weight_" + ReplaceExpInString(lhe_weight,
".",
""));
242 cb_names.push_back(ReplaceExpInString(cb_names.back(),
" ",
""));
243 cb_names.emplace_back(
"AllExecutedEvents_NonNominalMCWeight_" + std::to_string(lhe_var));
244 for (
const std::string& cb_name : cb_names) {
253 itr->has_book_keeper = mc_keeper !=
nullptr;
255 if (itr->has_book_keeper) {
266 return StatusCode::FAILURE;
269 ATH_MSG_FATAL(
"Metadata is inconsistent with the configuration");
270 return StatusCode::FAILURE;
272 return StatusCode::SUCCESS;
285 run_number =
meta.run_number;
286 tot_ev =
meta.tot_events;
287 proc_ev =
meta.proc_events;
288 stream_name =
meta.trigger_stream;
289 tot_lumi =
meta.total_lumi_blocks;
290 proc_lumi =
meta.processed_blocks;
293 return StatusCode::SUCCESS;
313 run_number =
meta.prw_channel;
314 mc_dsid =
meta.mc_channel;
315 lhe_var =
meta.variation_number;
317 prw_lumi =
meta.prw_lumi;
319 sum_w2 =
meta.sum_w_squared;
320 stream_name =
meta.weight_name;
322 tot_ev =
meta.tot_events;
323 proc_ev =
meta.proc_events;
326 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
This file contains the class definition for the EventStreamInfo class.
Handle class for reading from StoreGate.
const ServiceHandle< StoreGateSvc > & inputMetaStore() const
Const accessor for the input metadata store.
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....
This class provides the summary information stored for data written as a Event Stream.
const std::set< unsigned int > & getLumiBlockNumbers() const
const std::set< unsigned int > & getRunNumbers() const
const std::set< EventType > & getEventTypes() const
static const EventTypeCode IS_SIMULATION
true: IS_SIMULATION, false: IS_DATA
static void setNumLHE(unsigned int numLHE) ATLAS_THREAD_SAFE
Specify the number of LHE variations that are available in the sample.
std::string name() const override final
Returns the name of the branch.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
double sumOfEventWeightsSquared() const
Get the sum-of-(event-weights-squared) that this CutBookkeeper has seen.
double sumOfEventWeights() const
Get the sum-of-event-weights that this CutBookkeeper has seen.
uint64_t nAcceptedEvents() const
Get the number of accepted events that this CutBookkeeper has seen.
@ IS_SIMULATION
true: simulation, false: data
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
std::string ReplaceExpInString(std::string str, const std::string &exp, const std::string &rep)
Replaces all expressions an string by something else.
Class to store array like branches into the n-tuples.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
CutBookkeeper_v1 CutBookkeeper
Define the latest version of the CutBookkeeper class.
FileMetaData_v1 FileMetaData
Declare the latest version of the class.
CutBookkeeperContainer_v1 CutBookkeeperContainer
Define the latest version of the CutBookkeeperContainer class.