ATLAS Offline Software
Loading...
Searching...
No Matches
VP1LocalEvtRetriever Class Reference

#include <VP1LocalEvtRetriever.h>

Inheritance diagram for VP1LocalEvtRetriever:
Collaboration diagram for VP1LocalEvtRetriever:

Public Slots

void updateLocalDirFromSource ()

Public Member Functions

 VP1LocalEvtRetriever (VP1AvailEvtsLocalDir *, const QString &, QObject *parent=0)
 ~VP1LocalEvtRetriever ()
void setSourceDir (QString)

Protected Member Functions

void run ()

Private Member Functions

void updateLocalDir ()

Private Attributes

VP1AvailEvtsLocalDirm_availEvts
QString m_sourcedir
QTimer * m_timer
QMutex m_mutex

Detailed Description

Definition at line 15 of file VP1LocalEvtRetriever.h.

Constructor & Destructor Documentation

◆ VP1LocalEvtRetriever()

VP1LocalEvtRetriever::VP1LocalEvtRetriever ( VP1AvailEvtsLocalDir * availEvts,
const QString & sourcedir,
QObject * parent = 0 )

Definition at line 13 of file VP1LocalEvtRetriever.cxx.

16 : QThread(parent)
17 , m_availEvts(availEvts)
18 , m_sourcedir(sourcedir)
19 , m_timer(0)
20{
21}
VP1AvailEvtsLocalDir * m_availEvts

◆ ~VP1LocalEvtRetriever()

VP1LocalEvtRetriever::~VP1LocalEvtRetriever ( )

Definition at line 23 of file VP1LocalEvtRetriever.cxx.

24{
25 delete m_timer;
26}

Member Function Documentation

◆ run()

void VP1LocalEvtRetriever::run ( )
protected

Definition at line 28 of file VP1LocalEvtRetriever.cxx.

29{
30 m_timer = new QTimer(0);
31 connect(m_timer, SIGNAL(timeout()), this, SLOT(updateLocalDirFromSource()),Qt::DirectConnection);
32 m_timer->start(3000);
34 exec();
35}

◆ setSourceDir()

void VP1LocalEvtRetriever::setSourceDir ( QString dir)

Definition at line 109 of file VP1LocalEvtRetriever.cxx.

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);
135}

◆ updateLocalDir()

void VP1LocalEvtRetriever::updateLocalDir ( )
private

Definition at line 43 of file VP1LocalEvtRetriever.cxx.

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}

◆ updateLocalDirFromSource

void VP1LocalEvtRetriever::updateLocalDirFromSource ( )
slot

Definition at line 37 of file VP1LocalEvtRetriever.cxx.

38{
39 QMutexLocker locker(&m_mutex);
41}

Member Data Documentation

◆ m_availEvts

VP1AvailEvtsLocalDir* VP1LocalEvtRetriever::m_availEvts
private

Definition at line 37 of file VP1LocalEvtRetriever.h.

◆ m_mutex

QMutex VP1LocalEvtRetriever::m_mutex
private

Definition at line 40 of file VP1LocalEvtRetriever.h.

◆ m_sourcedir

QString VP1LocalEvtRetriever::m_sourcedir
private

Definition at line 38 of file VP1LocalEvtRetriever.h.

◆ m_timer

QTimer* VP1LocalEvtRetriever::m_timer
private

Definition at line 39 of file VP1LocalEvtRetriever.h.


The documentation for this class was generated from the following files: