ATLAS Offline Software
Loading...
Searching...
No Matches
VP1StreamMenuUpdater.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <QDir>
8#include <QFile>
9#include <QFileInfo>
10#include <QTextStream>
11#include <QTimer>
12#include <QDateTime>
13#include <QMutexLocker>
14
16 ,QMutex* mutex
17 ,QObject* parent)
18 : QThread(parent)
19 , m_inputdiractions(diractions)
20 , m_mutex(mutex)
21 , m_timer(0)
22{
23}
24
29
31{
33 m_timer = new QTimer(0);
34 connect(m_timer, SIGNAL(timeout()), this, SLOT(updateInputDirectoriesStatus()),Qt::DirectConnection);
35 m_timer->start(5000);
36 exec();
37}
38
40{
41 QMutexLocker locker(m_mutex);
42
43 for (QAction* act : m_inputdiractions.keys()) {
44 VP1DirStatusData& dirstatus = m_inputdiractions[act];
45 dirstatus.enabled = true;
46 dirstatus.bold = false;
47 dirstatus.dirStatus = "unknown";
48
49 // Check whether it exists and is really a directory
50 QFileInfo fi(dirstatus.inputDir);
51 if (!fi.exists()||!fi.isDir()) {
52 dirstatus.enabled = false;
53 dirstatus.dirStatus = "not found";
54 } else {
55 // Access the latest_vp1event file in order to get the name of the latest vp1 event file
56 // in the directory
57 QFile latestFileRef(dirstatus.inputDir + "/latest_vp1event");
58 if(latestFileRef.exists()
59 && latestFileRef.open(QIODevice::ReadOnly | QIODevice::Text)) {
60 QTextStream textStream(&latestFileRef);
61 QString latestFileName = textStream.readLine();
62 latestFileRef.close();
63
64 QFileInfo latestFile(latestFileName);
65 if(latestFile.exists()) {
66 int secondswithoutupdate = latestFile.lastModified().secsTo(QDateTime::currentDateTime());
67 dirstatus.bold = (secondswithoutupdate<60);
68 if (secondswithoutupdate<120)
69 dirstatus.dirStatus = QString::number(secondswithoutupdate)+" seconds since update";
70 else if (secondswithoutupdate<7200)
71 dirstatus.dirStatus = QString::number(static_cast<int>(secondswithoutupdate/60.0+0.5))+" minutes since update";
72 else
73 dirstatus.dirStatus = QString::number(static_cast<int>(secondswithoutupdate/3600.0+0.5))+" hours since update";
74 }
75 }
76 }
77 }
78}
QMap< QAction *, VP1DirStatusData > VP1DirStatuses
VP1StreamMenuUpdater(VP1DirStatuses &, QMutex *, QObject *parent=0)
VP1DirStatuses & m_inputdiractions
STL class.