ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
SampleHandler
Root
ToolsOther.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
8
//
9
// includes
10
//
11
12
#include <
SampleHandler/ToolsOther.h
>
13
14
#include <
RootCoreUtils/Assert.h
>
15
#include <
RootCoreUtils/hadd.h
>
16
#include <
SampleHandler/MetaNames.h
>
17
#include <
SampleHandler/MetaObject.h
>
18
#include <
SampleHandler/SampleHandler.h
>
19
#include <
SampleHandler/SampleLocal.h
>
20
#include <TFile.h>
21
#include <TSystem.h>
22
#include <iostream>
23
#include <thread>
24
#include <chrono>
25
#include <random>
26
#include <stdexcept>
27
28
//
29
// method implementations
30
//
31
32
namespace
SH
33
{
34
std::unique_ptr<TFile>
35
openFile
(
const
std::string& name,
const
MetaObject
& options)
36
{
37
const
unsigned
retries
38
= options.castInteger (
MetaNames::openRetries
(),
39
MetaNames::openRetries_default
());
40
const
double
wait
41
= options.castDouble (
MetaNames::openRetriesWait
(),
42
MetaNames::openRetriesWait_default
());
43
if
(wait < 0)
44
throw
std::runtime_error (
"negative values not allowed for: "
+
MetaNames::openRetriesWait
());
45
46
std::unique_ptr<TFile> result;
47
48
static
std::atomic<unsigned> seed = 0;
49
std::default_random_engine
re
(++seed);
50
std::uniform_real_distribution wait_dist (wait/2, wait);
51
52
for
(
unsigned
tries = 0; tries <= retries; ++ tries)
53
{
54
if
(tries > 0)
55
{
56
unsigned
mywait = 1000 * wait_dist (
re
);
57
std::cout <<
"open failed, waiting "
<< (mywait/1000.) <<
" seconds: "
58
<< name << std::endl;
59
std::this_thread::sleep_for (std::chrono::milliseconds (mywait));
60
}
61
result.reset (TFile::Open (name.c_str(),
"READ"
));
62
if
(result !=
nullptr
)
63
return
result;
64
}
65
throw
std::runtime_error (
"failed to open file: "
+ name);
66
}
67
68
69
70
std::unique_ptr<SampleLocal>
71
mergeFiles
(
const
Sample
& sample,
const
std::string& location,
72
bool
overwrite)
73
{
74
auto
result = std::make_unique<SampleLocal> (sample.name());
75
result->add (location);
76
*result->meta() = *sample.meta();
77
if
(overwrite || gSystem->AccessPathName (location.c_str()) != 0)
78
{
79
std::vector<std::string>
files
= sample.makeFileList();
80
RCU::hadd
(location,
files
);
81
}
82
return
result;
83
}
84
85
86
87
SampleHandler
88
mergeFiles
(
const
SampleHandler
&
sh
,
const
std::string& location,
89
bool
overwrite)
90
{
91
SampleHandler
result;
92
for
(
auto
sample :
sh
)
93
{
94
std::string sublocation = location + sample->name() +
".root"
;
95
result.add (
mergeFiles
(*sample, sublocation, overwrite));
96
}
97
return
result;
98
}
99
}
re
const std::regex re(r_e)
Assert.h
MetaNames.h
MetaObject.h
SampleHandler.h
SampleLocal.h
ToolsOther.h
SH::MetaObject
A class that manages meta-data to be associated with an object.
Definition
MetaObject.h:48
SH::SampleHandler
A class that manages a list of Sample objects.
Definition
SampleHandler.h:53
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
hadd.h
files
std::vector< std::string > files
file names and file pointers
Definition
hcg.cxx:52
RCU::Shell
Definition
ShellExec.cxx:26
RCU::hadd
void hadd(const std::string &output_file, const std::vector< std::string > &input_files, unsigned max_files)
effects: perform the hadd functionality guarantee: basic failures: out of memory III failures: i/o er...
Definition
hadd.cxx:29
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition
DiskList.cxx:21
SH::mergeFiles
std::unique_ptr< SampleLocal > mergeFiles(const Sample &sample, const std::string &location, bool overwrite)
merge all the files in the sample into a single file in the given location
Definition
ToolsOther.cxx:71
SH::openFile
std::unique_ptr< TFile > openFile(const std::string &name, const MetaObject &options)
open a file with the given options
Definition
ToolsOther.cxx:35
SH::MetaNames::openRetries
static const std::string & openRetries()
the number of retries for opening a file
Definition
MetaNames.cxx:23
SH::MetaNames::openRetriesWait_default
static double openRetriesWait_default()
the default value of openRetriesWait
Definition
MetaNames.cxx:49
SH::MetaNames::openRetries_default
static unsigned openRetries_default()
the default value of openRetries
Definition
MetaNames.cxx:32
SH::MetaNames::openRetriesWait
static const std::string & openRetriesWait()
the amount of time (in seconds) to wait when doing retries
Definition
MetaNames.cxx:40
Generated on
for ATLAS Offline Software by
1.17.0