ATLAS Offline Software
Loading...
Searching...
No Matches
ToolsJoin.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7//
8// includes
9//
10
12
13#include <memory>
18
19//
20// method implementations
21//
22
23namespace SH
24{
25 void mergeSamples (SampleHandler& sh, const std::string& sampleName,
26 const std::string& pattern)
27 {
28 SampleHandler mysh;
29 auto mysample = std::make_shared<SampleLocal> (sampleName);
30 bool matched = false;
31
32 std::regex mypattern (pattern);
33 for (auto& sample : sh.samples())
34 {
35 if (RCU::match_expr (mypattern, sample->name()))
36 {
37 if (!matched)
38 {
39 // rationale: inherit the metadata (tree name, cross section,
40 // ...) from the first matched sample instead of falling
41 // back to the defaults.
42 *mysample->meta() = *sample->meta();
43 matched = true;
44 }
45 for (unsigned file = 0, end = sample->numFiles();
46 file != end; ++ file)
47 {
48 mysample->add (sample->fileName (file));
49 }
50 } else
51 {
52 mysh.add (sample);
53 }
54 }
55 // rationale: only add the merged sample if at least one sample
56 // matched, so we do not create a spurious empty sample.
57 if (matched)
58 mysh.add (mysample);
59 swap (mysh, sh);
60 }
61}
void swap(MetaObject &a, MetaObject &b)
standard swap
A class that manages a list of Sample objects.
void add(const Sample &sample)
add a copy of the sample to the handler
bool match_expr(const std::regex &expr, std::string_view str)
returns: whether we can match the entire string with the regular expression guarantee: strong failure...
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition PrunDriver.h:15
void mergeSamples(SampleHandler &sh, const std::string &sampleName, const std::string &pattern)
effects: remove all samples matching the name pattern, and join them into a single sample named sampl...
Definition ToolsJoin.cxx:25
TFile * file