R3BROOT
R3B analysis software
Toggle main menu visibility
Loading...
Searching...
No Matches
R3BNeulandParDirCreator.h
Go to the documentation of this file.
1
/******************************************************************************
2
* Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3
* Copyright (C) 2019-2023 Members of R3B Collaboration *
4
* *
5
* This software is distributed under the terms of the *
6
* GNU General Public Licence (GPL) version 3, *
7
* copied verbatim in the file "LICENSE". *
8
* *
9
* In applying this license GSI does not waive the privileges and immunities *
10
* granted to it by virtue of its status as an Intergovernmental Organization *
11
* or submit itself to any jurisdiction. *
12
******************************************************************************/
13
14
#pragma once
15
#include "
R3BParRootFileIo.h
"
16
#include <FairParRootFileIo.h>
17
#include <FairRuntimeDb.h>
18
#include <
R3BException.h
>
19
#include <
R3BLogger.h
>
20
#include <TDirectory.h>
21
#include <fmt/core.h>
22
#include <string_view>
23
24
namespace
R3B::Neuland
25
{
26
class
ParDirCreator
27
{
28
public
:
29
explicit
ParDirCreator
(
30
ParRootFileIo
* parFileIO =
dynamic_cast<
ParRootFileIo
*
>
(FairRuntimeDb::instance()->getOutput()))
31
:
file_io_
{ parFileIO }
32
,
old_dir_
{ gDirectory }
33
{
34
if
(
file_io_
==
nullptr
)
35
{
36
throw
R3B::runtime_error
(
"unable to obtain the R3B::ParRootFileIo object!"
);
37
}
38
par_root_file_
= parFileIO->get_first_root_file();
39
40
if
(!
par_root_file_
->IsOpen() || !
par_root_file_
->IsWritable())
41
{
42
throw
R3B::runtime_error
(
"R3B::ParRootFile is either closed or unable to be written!"
);
43
}
44
}
45
46
~ParDirCreator
() noexcept {
old_dir_
->cd(); }
47
ParDirCreator
(
const
ParDirCreator
&) =
delete
;
48
ParDirCreator
(
ParDirCreator
&&) =
delete
;
49
auto
operator=
(
const
ParDirCreator
&) ->
ParDirCreator
& =
delete
;
50
auto
operator=
(
ParDirCreator
&&) ->
ParDirCreator
& =
delete
;
51
52
auto
mkdir
(std::string_view dir_name) ->
auto
*
53
{
54
if
(
par_root_file_
->IsZombie())
55
{
56
throw
R3B::runtime_error
(
57
fmt::format(
"File {} is not closed properly! Please delete it and create a new one!"
,
58
par_root_file_
->GetName()));
59
}
60
par_root_file_
->cd();
61
if
(dir_name.empty())
62
{
63
throw
R3B::runtime_error
(
"Cannot create a folder with empty string!"
);
64
}
65
if
(not gDirectory->IsWritable())
66
{
67
throw
R3B::runtime_error
(fmt::format(
"Directory {} is not writable currently!"
, gDirectory->GetName()));
68
}
69
70
// This is very slow
71
// // rm the dir and all its contents if existing
72
// if (auto* existing_dir = gDirectory->GetDirectory(dir_name.data()); existing_dir != nullptr)
73
// {
74
// R3BLOG(info, fmt::format("removing directory {} in {}", dir_name, gDirectory->GetName()));
75
// gDirectory->rmdir(dir_name.data());
76
// }
77
// else
78
// {
79
// R3BLOG(
80
// info,
81
// fmt::format("No directory {} in {}. Creating a new directory!", dir_name,
82
// gDirectory->GetName()));
83
// }
84
85
R3BLOG
(info, fmt::format(R
"("Creating a directory "{}" in "{}"")", dir_name, gDirectory->GetName()));
86
auto
* new_dir = gDirectory->mkdir(dir_name.data(), dir_name.data(),
true
);
87
if
(new_dir ==
nullptr
)
88
{
89
throw
R3B::runtime_error
(
"Cannot create a directory for the histrogams!"
);
90
}
91
return
new_dir;
92
}
93
94
private
:
95
ParRootFileIo
*
file_io_
=
nullptr
;
96
TFile*
par_root_file_
=
nullptr
;
97
TDirectory*
old_dir_
=
nullptr
;
98
};
99
}
// namespace R3B::Neuland
R3BException.h
R3BLogger.h
R3BLOG
#define R3BLOG(severity, x)
Definition
R3BLogger.h:33
R3BParRootFileIo.h
R3B::Neuland::ParDirCreator::ParDirCreator
ParDirCreator(const ParDirCreator &)=delete
R3B::Neuland::ParDirCreator::operator=
auto operator=(ParDirCreator &&) -> ParDirCreator &=delete
R3B::Neuland::ParDirCreator::mkdir
auto mkdir(std::string_view dir_name) -> auto *
Definition
R3BNeulandParDirCreator.h:52
R3B::Neuland::ParDirCreator::ParDirCreator
ParDirCreator(ParDirCreator &&)=delete
R3B::Neuland::ParDirCreator::file_io_
ParRootFileIo * file_io_
Definition
R3BNeulandParDirCreator.h:95
R3B::Neuland::ParDirCreator::par_root_file_
TFile * par_root_file_
Definition
R3BNeulandParDirCreator.h:96
R3B::Neuland::ParDirCreator::ParDirCreator
ParDirCreator(ParRootFileIo *parFileIO=dynamic_cast< ParRootFileIo * >(FairRuntimeDb::instance() ->getOutput()))
Definition
R3BNeulandParDirCreator.h:29
R3B::Neuland::ParDirCreator::old_dir_
TDirectory * old_dir_
Definition
R3BNeulandParDirCreator.h:97
R3B::Neuland::ParDirCreator::operator=
auto operator=(const ParDirCreator &) -> ParDirCreator &=delete
R3B::Neuland::ParDirCreator::~ParDirCreator
~ParDirCreator() noexcept
Definition
R3BNeulandParDirCreator.h:46
R3B::ParRootFileIo
Definition
R3BParRootFileIo.h:16
R3B::runtime_error
Definition
R3BException.h:26
R3B::Neuland
Simulation of NeuLAND Bar/Paddle.
Definition
R3BNeulandAnalysisApp.cxx:44
neuland
calibration
share
R3BNeulandParDirCreator.h
Generated by
1.18.0