18#include <QDirIterator>
56 return EventID(evt.runNumber(),evt.eventNumber());
64 std::map<QString,std::pair<QDateTime,QList<VP1EventFile> > >
dircache;
72 : QObject(parent),
m_d(new
Imp)
76 m_d->tmpDir = QString(td + (td.endsWith(
"/")?
"":
"/")).replace(
"//",
"/");
84 if (!
m_d->tmpActiveRetrievalDir.isEmpty()&&
m_d->tmpActiveRetrievalDir!=
"bad")
85 QFile::remove(
m_d->tmpActiveRetrievalDir);
86 if (!
m_d->tmpLocalFileDir.isEmpty()&&
m_d->tmpLocalFileDir!=
"bad")
87 QFile::remove(
m_d->tmpLocalFileDir);
94 return m_d->timeCutForNew;
100 return m_d->maxLocalFilesToKeep;
112 QList<VP1EventFile> l;
115 std::set<Imp::EventID>::const_iterator histIt, histItE(
m_d->historySorted.end());
116 if (
m_d->timeCutForNew==0) {
154 m_d->cleanupTmpLocalFiles();
165 if (
m_d->lastAllLocal != allLocal) {
166 m_d->lastAllLocal = std::move(allLocal);
169 if (
m_d->lastFresh != fresh) {
170 m_d->lastFresh = std::move(fresh);
196 std::map<QString,std::pair<QDateTime,QList<VP1EventFile> > >
::iterator it =
m_d->dircache.find(dir);
197 if (it!=
m_d->dircache.end())
198 m_d->dircache.erase(it);
205 return QList<VP1EventFile>();
207 QFileInfo fi_dir(dir);
208 if (!fi_dir.exists()||!fi_dir.isDir())
209 return QList<VP1EventFile>();
211 QDateTime modtime = fi_dir.lastModified();
212 if (abs(modtime.time().msecsTo(QTime::currentTime()))>50) {
213 std::map<QString,std::pair<QDateTime,QList<VP1EventFile> > >
::iterator it =
m_d->dircache.find(dir);
214 if (it!=
m_d->dircache.end()&&it->second.first==modtime)
215 return it->second.second;
219 filters <<
"*_*.pool.root";
221 QDirIterator itDir(dir,filters,QDir::Files | QDir::NoDotAndDotDot | QDir::Readable | QDir::CaseSensitive);
223 QList<VP1EventFile> l;
224 while (itDir.hasNext()) {
225 QString fn = itDir.next();
226 fn.replace(
"//",
"/");
231 message(
"Could not decode event file name: "+fn);
236 m_d->dircache[dir]=std::make_pair(modtime,l);
250 if (!cachevar.isEmpty())
251 return cachevar==
"bad"?
"":cachevar;
254 if (!( fi.exists()&&fi.isDir())) {
255 theclass->message(
"Could not create subdir in "+
tmpDir+
", since it does not exists or is not a directory" );
262 QString dir =
tmpDir+(
tmpDir.endsWith(
"/")?
"":
"/")+preferredname+(i==1?QString(
""):QString::number(i))+
"/";
263 if (!QFile::exists(dir)) {
264 bool ok = QDir().mkdir(dir);
266 theclass->message(
"Could not create directory:: "+dir );
279 return m_d->attemptGenerationOfTmpSubdir(
"activeretrievals",
m_d->tmpActiveRetrievalDir);
285 return m_d->attemptGenerationOfTmpSubdir(
"eventfiles",
m_d->tmpLocalFileDir);
295 QString dir =
theclass->tmpLocalFileDir();
299 QList<VP1EventFile> events =
theclass->allLocalEvents();
309 QList<Imp::EventID> protectedEvents;
315 QList<VP1EventFile> freshEvts =
theclass->freshEvents();
324 for (
int i = events.count()-1; i>=0; --i ) {
325 if (protectedEvents.contains(
Imp::evtToID(events.at(i)))) {
328 QFile::remove(events.at(i).fileName());
340 if (
m_d->timeCutForNew==0) {
342 return evt.rawTime()==newestEvt.
rawTime() && evt.runNumber()==newestEvt.
runNumber();
346 const unsigned oldest_time = (
m_d->timeCutForNew<0||unsigned(
m_d->timeCutForNew)>newestEvt.
rawTime()) ? 0 : newestEvt.
rawTime() -
m_d->timeCutForNew;
347 return evt.rawTime() >= oldest_time;
bool operator==(const EventID &o) const
EventID(int r, unsigned long long e)
bool operator<(const EventID &o) const
unsigned long long eventNumber
VP1AvailEvents * theclass
QList< VP1EventFile > lastAllLocal
QList< VP1EventFile > lastFresh
std::map< QString, std::pair< QDateTime, QList< VP1EventFile > > > dircache
static EventID evtToID(const VP1EventFile &evt)
QString tmpActiveRetrievalDir
void cleanupTmpLocalFiles()
QString attemptGenerationOfTmpSubdir(const QString &preferredname, QString &cachevar)
std::set< EventID > historySorted
QList< EventID > historyOrdered
QList< VP1EventFile > allLocalEvents() const
void setCurrentEvent(int run, int event)
QList< VP1EventFile > freshEvents() const
virtual ~VP1AvailEvents()
void messageDebug(const QString &) const
QString tmpLocalFileDir() const
void message(const QString &) const
VP1AvailEvents(int timeCutForNew, const QString &tmpdir, int maxLocalFilesToKeep=-1, QObject *parent=0)
const QString & tmpDir() const
void allLocalEventsChanged()
bool requireNewestRunNumber() const
int timeCutForNew() const
bool inHistory(int run, int event) const
QList< VP1EventFile > allEventFilesInDir(const QString &dir) const
VP1EventFile newestEvent() const
int maxLocalFilesToKeep() const
void actualCheckForEventListChanges()
void invalidateDirCache(const QString &dir)
bool isConsideredFresh(const VP1EventFile &evt, const VP1EventFile &newestEvt) const
void cleanupAndCheckForEventListChanges()
void freshEventsChanged()
QString tmpActiveRetrievalDir()
static const char * prefix_verbose()
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.