ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
graphics
VP1
VP1Gui
src
VP1LocalEvtRetriever.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
VP1LocalEvtRetriever.h
"
6
#include "
VP1Gui/VP1AvailEvtsLocalDir.h
"
7
8
#include <QFile>
9
#include <QFileInfo>
10
#include <QTimer>
11
#include <QMutexLocker>
12
13
VP1LocalEvtRetriever::VP1LocalEvtRetriever
(
VP1AvailEvtsLocalDir
* availEvts
14
,
const
QString & sourcedir
15
, QObject* parent)
16
: QThread(parent)
17
,
m_availEvts
(availEvts)
18
,
m_sourcedir
(sourcedir)
19
,
m_timer
(0)
20
{
21
}
22
23
VP1LocalEvtRetriever::~VP1LocalEvtRetriever
()
24
{
25
delete
m_timer
;
26
}
27
28
void
VP1LocalEvtRetriever::run
()
29
{
30
m_timer
=
new
QTimer(0);
31
connect(
m_timer
, SIGNAL(timeout()),
this
, SLOT(
updateLocalDirFromSource
()),Qt::DirectConnection);
32
m_timer
->start(3000);
33
updateLocalDirFromSource
();
34
exec();
35
}
36
37
void
VP1LocalEvtRetriever::updateLocalDirFromSource
()
38
{
39
QMutexLocker locker(&
m_mutex
);
40
updateLocalDir
();
41
}
42
43
void
VP1LocalEvtRetriever::updateLocalDir
()
44
{
45
QList<VP1EventFile> evts =
m_availEvts
->allEventFilesInDir(
m_sourcedir
);
46
if
(evts.isEmpty()) {
47
m_availEvts
->cleanupAndCheckForEventListChanges();
//In case we e.g. changed to an empty input directory
48
return
;
49
}
50
//We don't copy more than enough to give us 3 fresh files. But if
51
//there are more available, we will check back in 3 seconds.
52
53
const
int
nfreshneeded = 3 -
m_availEvts
->freshEvents().count();
54
if
(evts.count()>
m_availEvts
->maxLocalFilesToKeep()+3&&nfreshneeded<=0) {
55
//Don't copy anything, but schedule cleanup and check back in 3 seconds:
56
m_availEvts
->cleanupAndCheckForEventListChanges();
57
// --- todo? QTimer::singleShot(3000, this, SLOT(updateLocalDirFromSource()));
58
return
;
59
}
60
61
static
unsigned
ntmpdlcount = 0;
62
63
QList<VP1EventFile> freshEvtsInSource =
m_availEvts
->freshEvents(evts.front(), evts);
64
65
QString ad =
m_availEvts
->tmpActiveRetrievalDir();
66
QString tmplocal =
m_availEvts
->tmpLocalFileDir();
67
bool
changestmplocal(
false
), changesad(
false
);
68
if
(!ad.isEmpty()&&!tmplocal.isEmpty()) {
69
int
ncopied(0);
70
for
(
VP1EventFile
evt : freshEvtsInSource) {
71
QString fn = evt.fileName();
72
QString basefn = QFileInfo(fn).fileName();
73
QString target = tmplocal + basefn;
74
if
(!QFile::exists(target)) {
75
QString tmptarget = ad+basefn+
"_"
+QString::number(ntmpdlcount++);
76
if
(!QFile::copy(fn,tmptarget)) {
77
m_availEvts
->message(
"Problems copying "
+fn+
" to "
+tmptarget);
78
changesad =
true
;
79
}
else
{
80
if
(!QFile::rename(tmptarget,target)) {
81
m_availEvts
->message(
"Problems moving "
+tmptarget+
" to "
+target+
" directory"
);
82
changesad =
true
;
83
}
else
{
84
if
(!QFile::exists(target)) {
85
m_availEvts
->message(
"Inconsistent copy of "
+basefn+
" to local tmp directory"
);
86
}
else
{
87
++ncopied;
88
m_availEvts
->messageDebug(
"Copied "
+basefn+
" to local tmp directory"
);
//Fixme: verbose!
89
changestmplocal =
true
;
90
}
91
}
92
}
93
}
94
if
(ncopied>=nfreshneeded) {
95
// -- todo? QTimer::singleShot(3000, this, SLOT(updateLocalDirFromSource()));
96
break
;
97
}
98
}
99
}
else
{
100
m_availEvts
->message(
"Problems with temporary local directories."
);
101
}
102
if
(changestmplocal)
103
m_availEvts
->invalidateDirCache(tmplocal);
104
if
(changesad)
105
m_availEvts
->invalidateDirCache(ad);
106
m_availEvts
->cleanupAndCheckForEventListChanges();
107
}
108
109
void
VP1LocalEvtRetriever::setSourceDir
(QString dir)
110
{
111
QMutexLocker locker(&
m_mutex
);
112
113
if
(!dir.endsWith(
"/"
))
114
dir +=
"/"
;
115
if
(
m_sourcedir
==dir)
116
return
;
117
118
//Ensure that the next event is from the new directory by removing
119
//all cached fresh events:
120
121
while
(
true
) {
122
QList<VP1EventFile> freshevts =
m_availEvts
->freshEvents();
123
if
(freshevts.isEmpty())
124
break
;
125
for
(
VP1EventFile
evt : freshevts) {
126
QString fn = evt.fileName();
127
if
(!QFile::remove(fn))
128
m_availEvts
->message(
"ERROR: Could not remove "
+fn);
129
}
130
}
131
132
//Now change directory
133
m_sourcedir
= std::move(dir);
134
updateLocalDir
();
135
}
VP1AvailEvtsLocalDir.h
VP1LocalEvtRetriever.h
VP1AvailEvtsLocalDir
Definition
VP1AvailEvtsLocalDir.h:24
VP1EventFile
Definition
VP1EventFile.h:23
VP1LocalEvtRetriever::updateLocalDirFromSource
void updateLocalDirFromSource()
Definition
VP1LocalEvtRetriever.cxx:37
VP1LocalEvtRetriever::m_timer
QTimer * m_timer
Definition
VP1LocalEvtRetriever.h:39
VP1LocalEvtRetriever::m_mutex
QMutex m_mutex
Definition
VP1LocalEvtRetriever.h:40
VP1LocalEvtRetriever::run
void run()
Definition
VP1LocalEvtRetriever.cxx:28
VP1LocalEvtRetriever::VP1LocalEvtRetriever
VP1LocalEvtRetriever(VP1AvailEvtsLocalDir *, const QString &, QObject *parent=0)
Definition
VP1LocalEvtRetriever.cxx:13
VP1LocalEvtRetriever::m_availEvts
VP1AvailEvtsLocalDir * m_availEvts
Definition
VP1LocalEvtRetriever.h:37
VP1LocalEvtRetriever::~VP1LocalEvtRetriever
~VP1LocalEvtRetriever()
Definition
VP1LocalEvtRetriever.cxx:23
VP1LocalEvtRetriever::setSourceDir
void setSourceDir(QString)
Definition
VP1LocalEvtRetriever.cxx:109
VP1LocalEvtRetriever::updateLocalDir
void updateLocalDir()
Definition
VP1LocalEvtRetriever.cxx:43
VP1LocalEvtRetriever::m_sourcedir
QString m_sourcedir
Definition
VP1LocalEvtRetriever.h:38
Generated on
for ATLAS Offline Software by
1.17.0