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 <
RootCoreUtils/ThrowMsg.h
>
17
#include <
SampleHandler/MetaNames.h
>
18
#include <
SampleHandler/MetaObject.h
>
19
#include <
SampleHandler/SampleHandler.h
>
20
#include <
SampleHandler/SampleLocal.h
>
21
#include <TFile.h>
22
#include <TSystem.h>
23
#include <iostream>
24
#include <thread>
25
#include <chrono>
26
#include <random>
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
RCU_THROW_MSG
(
"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
RCU_THROW_MSG
(
"failed to open file: "
+ name);
66
//cppcheck-suppress rethrowNoCurrentException
67
throw
;
//compiler dummy
68
}
69
70
71
72
std::unique_ptr<SampleLocal>
73
mergeFiles
(
const
Sample
& sample,
const
std::string& location,
74
bool
overwrite)
75
{
76
std::unique_ptr<SampleLocal> result (
new
SampleLocal
(sample.name()));
77
result->add (location);
78
*result->meta() = *sample.meta();
79
if
(overwrite || gSystem->AccessPathName (location.c_str()) != 0)
80
{
81
std::vector<std::string>
files
= sample.makeFileList();
82
RCU::hadd
(location,
files
);
83
}
84
return
result;
85
}
86
87
88
89
SampleHandler
90
mergeFiles
(
const
SampleHandler
&
sh
,
const
std::string& location,
91
bool
overwrite)
92
{
93
SampleHandler
result;
94
for
(
auto
sample :
sh
)
95
{
96
std::string sublocation = location + sample->name() +
".root"
;
97
result.add (
mergeFiles
(*sample, sublocation, overwrite));
98
}
99
return
result;
100
}
101
}
re
const std::regex re(r_e)
Assert.h
MetaNames.h
MetaObject.h
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition
PrintMsg.h:53
SampleHandler.h
SampleLocal.h
ThrowMsg.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::SampleLocal
A Sample based on a simple file list.
Definition
SampleLocal.h:30
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:25
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:28
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition
PrunDriver.h:15
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:73
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