ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DataQuality
DataQualityInterfaces
src
HanUtils.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "TList.h"
6
#include "TObjArray.h"
7
#include "TKey.h"
8
#include "TDirectory.h"
9
#include "TROOT.h"
10
#include <string>
11
#include <iostream>
12
#include "
DataQualityInterfaces/HanUtils.h
"
13
14
namespace
dqi
{
15
16
std::mutex
root_mutex
;
17
18
TSeqCollection*
newTList
(
const
char
*name, TObject *obj )
19
{
20
TList *ret =
new
TList();
21
ret->SetName(name);
22
if
(obj != 0)
23
ret->Add(obj);
24
return
ret;
25
}
26
27
TSeqCollection*
newTObjArray
(
const
char
*name, TObject *obj, Int_t
size
)
28
{
29
TObjArray *ret =
new
TObjArray(
size
);
30
ret->SetName(name);
31
if
(obj != NULL)
32
ret->Add(obj);
33
return
ret;
34
}
35
36
TKey*
getObjKey
( TDirectory* dir,
const
std::string& path )
37
{
38
if
( dir == 0 )
39
return
0;
40
41
std::string::size_type i = path.find_first_of(
'/'
);
42
if
( i != std::string::npos ) {
43
std::string dName( path, 0, i );
44
std::string pName( path, i+1, std::string::npos );
45
if
( dName !=
""
) {
46
TDirectory* subDir = dir->GetDirectory(dName.c_str());
47
if
(subDir != 0) {
48
TKey* rv =
getObjKey
( subDir, pName );
49
//delete subDir;
50
return
rv;
51
}
52
// TKey* key = dir->FindKey( dName.c_str() );
53
// if( key != 0 ) {
54
// TDirectory* subDir = dynamic_cast<TDirectory*>( key->ReadObj() );
55
// TKey* rv = getObjKey( subDir, pName );
56
// // delete subDir;
57
// return rv;
58
// }
59
return
0;
60
}
61
return
getObjKey
( dir, pName );
62
}
63
64
return
dir->FindKey( path.c_str() );
65
}
66
67
DisableMustClean::DisableMustClean
() :
68
m_lock
(
root_mutex
),
69
m_useRecursiveDelete
(gROOT->MustClean())
70
{
71
gROOT->SetMustClean(
false
);
72
}
73
74
DisableMustClean::~DisableMustClean
()
75
{
76
gROOT->SetMustClean(
m_useRecursiveDelete
);
77
}
78
79
void
80
dolsr
(
const
TDirectory* dir, std::vector<std::string>& hists,
const
TDirectory* topdir)
81
{
82
// permit calling with two arguments
83
if
(topdir == NULL) {
84
topdir = dir;
85
}
86
TIter keys(dir->GetListOfKeys());
87
TKey* key;
88
std::string fullpath(dir->GetPath());
89
std::string toppath(topdir->GetPath());
90
std::string::size_type toppathlen = toppath.length();
91
while
((key =
dynamic_cast<
TKey*
>
(keys())) != NULL) {
92
if
(std::string(key->GetClassName()).starts_with(
"TDirectory"
)) {
93
TDirectory* newdir =
dynamic_cast<
TDirectory*
>
(key->ReadObj());
94
if
(!newdir) {
95
std::cerr <<
"WARNING: cannot read directory "
96
<< fullpath <<
"/"
<< key->GetName()
97
<<
"; skipping"
<< std::endl;
98
}
else
{
99
dolsr
(newdir, hists, topdir);
100
}
101
delete
newdir;
102
}
else
{
103
if
(std::string(key->GetName()) ==
"metadata"
) {
104
continue
;
105
}
106
std::string path;
107
if
(fullpath.substr(0, toppathlen) == toppath) {
108
int
extra = 1;
109
if
(toppath[toppathlen-1] ==
'/'
) extra = 0;
110
path = fullpath.substr(toppathlen + extra, std::string::npos);
111
}
else
{
112
path = fullpath;
113
}
114
hists.push_back(path+
"/"
+std::string(key->GetName()));
115
}
116
}
117
}
118
119
HanHistogramLink::
120
HanHistogramLink
(TDirectory* dir,
const
std::string& path)
121
:
m_dir
(dir)
122
,
m_path
(path)
123
{}
124
125
TObject*
HanHistogramLink::
126
getObject
()
127
{
128
//std::cout << "Getting " << m_dir->GetPath() << " " << m_path << std::endl;
129
return
m_dir
->Get(
m_path
.c_str());
130
/* std::unique_ptr<TKey> key(getObjKey(m_dir, m_path));
131
if (key.get() == 0) return 0;
132
TObject* rv = key->ReadObj();
133
if (TH1* hptr = dynamic_cast<TH1*>(rv)) { hptr->SetDirectory(0); }
134
return rv; */
135
}
136
137
}
HanUtils.h
size
size_t size() const
Number of registered mappings.
dqi::DisableMustClean::~DisableMustClean
~DisableMustClean()
Definition
HanUtils.cxx:74
dqi::DisableMustClean::DisableMustClean
DisableMustClean()
Definition
HanUtils.cxx:67
dqi::DisableMustClean::m_useRecursiveDelete
bool m_useRecursiveDelete
Definition
HanUtils.h:36
dqi::DisableMustClean::m_lock
std::unique_lock< std::mutex > m_lock
Definition
HanUtils.h:35
dqi::HanHistogramLink::m_dir
TDirectory * m_dir
Definition
HanUtils.h:25
dqi::HanHistogramLink::m_path
std::string m_path
Definition
HanUtils.h:26
dqi::HanHistogramLink::getObject
TObject * getObject()
Definition
HanUtils.cxx:126
dqi::HanHistogramLink::HanHistogramLink
HanHistogramLink(TDirectory *dir, const std::string &path)
Definition
HanUtils.cxx:120
dqi
Definition
CompositeAlgorithm.h:16
dqi::newTObjArray
TSeqCollection * newTObjArray(const char *name, TObject *obj=0, Int_t size=TCollection::kInitCapacity)
Definition
HanUtils.cxx:27
dqi::root_mutex
std::mutex root_mutex
Definition
HanUtils.cxx:16
dqi::dolsr
void dolsr(const TDirectory *dir, std::vector< std::string > &hists, const TDirectory *topdir=nullptr)
Definition
HanUtils.cxx:80
dqi::getObjKey
TKey * getObjKey(TDirectory *dir, const std::string &path)
Definition
HanUtils.cxx:36
dqi::newTList
TSeqCollection * newTList(const char *name, TObject *obj=0)
Definition
HanUtils.cxx:18
Generated on
for ATLAS Offline Software by
1.17.0