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

#include <VP1AvailEvtsHttp.h>

Inheritance diagram for VP1AvailEvtsHttp:
Collaboration diagram for VP1AvailEvtsHttp:

Classes

class  Imp

Signals

void allLocalEventsChanged ()
void freshEventsChanged ()
void message (const QString &) const

Public Member Functions

 VP1AvailEvtsHttp (const QString &fileinfoUrl, int updateInterval, int timeCutForNew, const QString &tmpcopydir, int maxLocalFilesToKeep=-1, QObject *parent=0)
virtual ~VP1AvailEvtsHttp ()
virtual void init ()
QList< VP1EventFileallLocalEvents () const
QList< VP1EventFilefreshEvents () const
VP1EventFile newestEvent () const
void setCurrentEvent (int run, int event)
int maxLocalFilesToKeep () const

Protected Member Functions

QList< VP1EventFilefreshEvents (VP1EventFile newestEvt, const QList< VP1EventFile > &) const
void cleanupAndCheckForEventListChanges ()
void invalidateDirCache (const QString &dir)
bool inHistory (int run, int event) const
QList< VP1EventFileallEventFilesInDir (const QString &dir) const
const QString & tmpDir () const
QString tmpLocalFileDir () const
QString tmpActiveRetrievalDir ()
int timeCutForNew () const
bool requireNewestRunNumber () const
bool isConsideredFresh (const VP1EventFile &evt, const VP1EventFile &newestEvt) const
void messageDebug (const QString &) const

Private Slots

void fileInfoChanged ()
void fileInfoDownloadSuccessful (const QString &urltofile, const QString &localtargetfile)
void fileInfoDownloadFailed (const QString &error, const QString &urltofile, const QString &localtargetfile)
void eventFileDownloadSuccessful (const QString &urltofile, const QString &localtargetfile, const QString &data)
void eventFileDownloadFailed (const QString &error, const QString &urltofile, const QString &localtargetfile)
void examineEvtsOnServer ()
void actualCleanup ()
void actualCheckForEventListChanges ()

Private Attributes

Impm_d

Detailed Description

Definition at line 24 of file VP1AvailEvtsHttp.h.

Constructor & Destructor Documentation

◆ VP1AvailEvtsHttp()

VP1AvailEvtsHttp::VP1AvailEvtsHttp ( const QString & fileinfoUrl,
int updateInterval,
int timeCutForNew,
const QString & tmpcopydir,
int maxLocalFilesToKeep = -1,
QObject * parent = 0 )

Definition at line 52 of file VP1AvailEvtsHttp.cxx.

58 : VP1AvailEvents(timeCutForNew,tmpcopydir,maxLocalFilesToKeep,parent), m_d(new Imp)
59{
60 m_d->theclass = this;
61 m_d->examineEvtsOnServerTimer = 0;
62 m_d->fileinfoUrl = fileinfoUrl;
63 QUrl url(fileinfoUrl);
64 if (url.isValid()) {
65 QString path = url.path();
66 QString infofilebasename = QFileInfo(path).fileName();
67 if (!infofilebasename.isEmpty()&&path.endsWith(infofilebasename)) {
68 m_d->baseUrl=fileinfoUrl;
69 m_d->baseUrl.chop(infofilebasename.count());
70 if (!QUrl(m_d->baseUrl).isValid())
71 m_d->baseUrl="";
72 else if (!m_d->baseUrl.endsWith("/"))
73 m_d->baseUrl += "/";
74 }
75 }
76
77 m_d->evtsOnServer = 0;
78 connect(&(m_d->httpgetfile_fileinfo),SIGNAL(downloadSuccessful(const QString&,const QString&,const QString&)),
79 this,SLOT(fileInfoDownloadSuccessful(const QString&,const QString&)));
80 connect(&(m_d->httpgetfile_fileinfo),SIGNAL(downloadFailed(const QString&,const QString&,const QString&,const QString&)),
81 this,SLOT(fileInfoDownloadFailed(const QString&,const QString&,const QString&)));
82 connect(&(m_d->httpgetfile_events),SIGNAL(downloadSuccessful(const QString&,const QString&,const QString&)),
83 this,SLOT(eventFileDownloadSuccessful(const QString&,const QString&,const QString&)));
84 connect(&(m_d->httpgetfile_events),SIGNAL(downloadFailed(const QString&,const QString&,const QString&,const QString&)),
85 this,SLOT(eventFileDownloadFailed(const QString&,const QString&,const QString&)));
86
87 m_d->webwatcher_fileinfo = new VP1WebWatcher(updateInterval*1000,this);
88 connect(m_d->webwatcher_fileinfo,SIGNAL(urlChanged(const QString&)),this,SLOT(fileInfoChanged()));
89}
VP1AvailEvents(int timeCutForNew, const QString &tmpdir, int maxLocalFilesToKeep=-1, QObject *parent=0)
int timeCutForNew() const
int maxLocalFilesToKeep() const
void eventFileDownloadSuccessful(const QString &urltofile, const QString &localtargetfile, const QString &data)
void fileInfoDownloadSuccessful(const QString &urltofile, const QString &localtargetfile)
void fileInfoDownloadFailed(const QString &error, const QString &urltofile, const QString &localtargetfile)
void eventFileDownloadFailed(const QString &error, const QString &urltofile, const QString &localtargetfile)
path
python interpreter configuration --------------------------------------—
Definition athena.py:128

◆ ~VP1AvailEvtsHttp()

VP1AvailEvtsHttp::~VP1AvailEvtsHttp ( )
virtual

Definition at line 99 of file VP1AvailEvtsHttp.cxx.

100{
101 delete m_d->evtsOnServer;
102 delete m_d;
103}

Member Function Documentation

◆ actualCheckForEventListChanges

void VP1AvailEvents::actualCheckForEventListChanges ( )
privateslotinherited

Definition at line 161 of file VP1AvailEvents.cxx.

162{
163 QList<VP1EventFile> allLocal = allLocalEvents();
164 QList<VP1EventFile> fresh = freshEvents();
165 if (m_d->lastAllLocal != allLocal) {
166 m_d->lastAllLocal = std::move(allLocal);
168 }
169 if (m_d->lastFresh != fresh) {
170 m_d->lastFresh = std::move(fresh);
172 }
173}
QList< VP1EventFile > allLocalEvents() const
QList< VP1EventFile > freshEvents() const
void allLocalEventsChanged()
void freshEventsChanged()

◆ actualCleanup

void VP1AvailEvents::actualCleanup ( )
privateslotinherited

Definition at line 151 of file VP1AvailEvents.cxx.

152{
153 //First we cleanup:
154 m_d->cleanupTmpLocalFiles();
155
156 //Then we schedule a check for event list changes:
157 QTimer::singleShot(10, this, SLOT(actualCheckForEventListChanges()));
158}
void actualCheckForEventListChanges()

◆ allEventFilesInDir()

QList< VP1EventFile > VP1AvailEvents::allEventFilesInDir ( const QString & dir) const
protectedinherited

Definition at line 202 of file VP1AvailEvents.cxx.

203{
204 if (dir.isEmpty())
205 return QList<VP1EventFile>();
206
207 QFileInfo fi_dir(dir);
208 if (!fi_dir.exists()||!fi_dir.isDir())
209 return QList<VP1EventFile>();
210
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;
216 }
217
218 QStringList filters;
219 filters << "*_*.pool.root";
220 //fixme
221 QDirIterator itDir(dir,filters,QDir::Files | QDir::NoDotAndDotDot | QDir::Readable | QDir::CaseSensitive);
222
223 QList<VP1EventFile> l;
224 while (itDir.hasNext()) {
225 QString fn = itDir.next();
226 fn.replace("//","/");
227 VP1EventFile evt(fn);
228 if (evt.isValid())
229 l << evt;
230 else
231 message("Could not decode event file name: "+fn);
232 }
233
234 std::sort(l.begin(), l.end());
235
236 m_d->dircache[dir]=std::make_pair(modtime,l);
237 return l;
238}
void message(const QString &) const
l
Printing final latex table to .tex output file.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.

◆ allLocalEvents()

QList< VP1EventFile > VP1AvailEvents::allLocalEvents ( ) const
inherited

Definition at line 241 of file VP1AvailEvents.cxx.

242{
244}
QString tmpLocalFileDir() const
QList< VP1EventFile > allEventFilesInDir(const QString &dir) const

◆ allLocalEventsChanged

void VP1AvailEvents::allLocalEventsChanged ( )
signalinherited

◆ cleanupAndCheckForEventListChanges()

void VP1AvailEvents::cleanupAndCheckForEventListChanges ( )
protectedinherited

Definition at line 176 of file VP1AvailEvents.cxx.

177{
178 //We schedule the cleanup to take place shortly. The check for event
179 //list changes will be scheduled after the cleanup:
180
181 //Then we schedule a check for event list changes:
182 QTimer::singleShot(10, this, SLOT(actualCleanup()));
183
184}

◆ eventFileDownloadFailed

void VP1AvailEvtsHttp::eventFileDownloadFailed ( const QString & error,
const QString & urltofile,
const QString & localtargetfile )
privateslot

Definition at line 244 of file VP1AvailEvtsHttp.cxx.

245{
246 message("Problems downloading "+urltofile+": "+error);
247 QFile::remove(localtargetfile);
248 m_d->getFileInfoLater();//Avoid stalling forever in case this is temporary.
250}
void invalidateDirCache(const QString &dir)
QString tmpActiveRetrievalDir()

◆ eventFileDownloadSuccessful

void VP1AvailEvtsHttp::eventFileDownloadSuccessful ( const QString & urltofile,
const QString & localtargetfile,
const QString & data )
privateslot

Definition at line 228 of file VP1AvailEvtsHttp.cxx.

229{
232
233 if (!QFile::rename(localtargetfile,data)) {
234 message("Error: Could not move "+localtargetfile+" to "+data);
235 QFile::remove(localtargetfile);
236 QFile::remove(data);
237 m_d->getFileInfoLater();//Avoid stalling forever in case this is temporary.
238 return;
239 }
241}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
void cleanupAndCheckForEventListChanges()

◆ examineEvtsOnServer

void VP1AvailEvtsHttp::examineEvtsOnServer ( )
privateslot

Definition at line 152 of file VP1AvailEvtsHttp.cxx.

153{
154 m_d->restartExamineEvtsOnServerTimer();//To ensure we don't get events too closely spaced here.
155 if (m_d->httpgetfile_events.numberOfPendingDownloads()>3)
156 return;
157 if (!m_d->evtsOnServer)
158 return;
159
160 //Start download of one of the files from the server?
161 VP1EventFile evtToGet;
162 QString localfiledir = tmpLocalFileDir();
163 if (localfiledir.isEmpty()) {
164 message("Problems with temporary local event file directory.");
165 return;
166 }
167
168 for (VP1EventFile evt : m_d->evtsOnServer->events(timeCutForNew(), requireNewestRunNumber() )) {
169 //We are looking for an event which was never seen before and not available locally:
170 if (!evt.isValid()||inHistory(evt.runNumber(),evt.eventNumber()))
171 continue;
172 if ( !QFile::exists ( localfiledir+evt.fileName() ) ) {
173 evtToGet=evt;
174 break;
175 }
176 }
177
178 if (!evtToGet.isValid()&&m_d->examineEvtsOnServerTimer)
179 m_d->examineEvtsOnServerTimer->stop();//No need to check back regularly until we get new information.
180
181 if (evtToGet.isValid()) {
182 //Before we get it, let us check that we don't already have 3
183 //fresh events locally which are newer than the one we are trying
184 //to download:
185 QList<VP1EventFile> freshLocalEvents = freshEvents();
186 unsigned nNewer(0);
187 for(VP1EventFile evt : freshLocalEvents) {
188 if (evt < evtToGet) {
189 ++nNewer;
190 if (nNewer>=3) {
191 return;
192 }
193 }
194 }
195 QString ad = tmpActiveRetrievalDir();
196 if (!ad.isEmpty()) {
197 QString url = m_d->baseUrl+evtToGet.fileName();
198 QString target = ad+evtToGet.fileName()+"_"+QString::number(Imp::ntmpdlcount++);
199 //A quick check that we are not already downloading that file currently:
200 if (!m_d->httpgetfile_events.isDownloading(url)&&!m_d->httpgetfile_events.isDownloadingTo(target)) {
201 QString err = m_d->httpgetfile_events.startDownload( url,target,evtToGet.md5Sum(),localfiledir+evtToGet.fileName());
202 if (!err.isEmpty()) {
203 message("Problems starting download of :" +url);
204 message(" => "+err);
205 }
206 } else {
207 //We are already downloading url - abort silently.
208 return;
209 }
210 } else {
211 message("Problems with temporary local download directory.");
212 }
213 }
214 invalidateDirCache(tmpActiveRetrievalDir());//Fixme: remove from here???
215}
bool requireNewestRunNumber() const
bool inHistory(int run, int event) const
static unsigned ntmpdlcount
const QString & fileName() const
bool isValid() const
const QString & md5Sum() const

◆ fileInfoChanged

void VP1AvailEvtsHttp::fileInfoChanged ( )
privateslot

Definition at line 106 of file VP1AvailEvtsHttp.cxx.

107{
108 if (m_d->webwatcher_fileinfo->lastResult(m_d->fileinfoUrl)!=VP1WebWatcher::EXISTS) {
109 message("Problems investigating "+m_d->fileinfoUrl);
110 message(" ===> "+m_d->webwatcher_fileinfo->lastResultToString(m_d->fileinfoUrl));
111 return;
112 }
113 QString ad = tmpActiveRetrievalDir();
114 if (ad.isEmpty()) {
115 message("Error: No temporary retrieval directory set!");
116 m_d->getFileInfoLater();//Avoid stalling forever (however this is an unlikely error).
117 return;
118 }
119 QString target = ad+"downloadedfileinfo.txt";
120 if ( QFileInfo(target).exists() && !QFile(target).remove() ) {
121 message("ERROR: Could not remove old "+target);
122 m_d->getFileInfoLater();//Avoid stalling forever in case user fixes error (i.e. fixes permissions).
123 return;
124 }
125 QString err = m_d->httpgetfile_fileinfo.startDownload( m_d->fileinfoUrl,target);
126 if (!err.isEmpty()) {
127 message("Problems starting download to get file-info file: "+err);
128 m_d->getFileInfoLater();//Avoid stalling forever in case user fixes error (i.e. fixes net connection).
129 }
130}
bool exists(const std::string &filename)
does a file exist

◆ fileInfoDownloadFailed

void VP1AvailEvtsHttp::fileInfoDownloadFailed ( const QString & error,
const QString & urltofile,
const QString & localtargetfile )
privateslot

Definition at line 219 of file VP1AvailEvtsHttp.cxx.

220{
221 message("Problems downloading "+urltofile+": "+error);
222 QFile::remove(localtargetfile);
224 m_d->getFileInfoLater();//Avoid stalling forever in case this is temporary.
225}

◆ fileInfoDownloadSuccessful

void VP1AvailEvtsHttp::fileInfoDownloadSuccessful ( const QString & urltofile,
const QString & localtargetfile )
privateslot

Definition at line 133 of file VP1AvailEvtsHttp.cxx.

134{
135 VP1EvtsOnServerInfo * newEvtsOnServerInfo = new VP1EvtsOnServerInfo(localtargetfile);
136 if (!newEvtsOnServerInfo->isValid()) {
137 message("Problems decoding info in file downloaded from "+urltofile);
138 message("Error: "+newEvtsOnServerInfo->error());
139 delete newEvtsOnServerInfo;
140 QFile::remove(localtargetfile);
141 m_d->getFileInfoLater();//Avoid stalling forever in case this is temporary.
143 return;
144 }
145 delete m_d->evtsOnServer;
146 m_d->evtsOnServer = newEvtsOnServerInfo;
147
149}
const QString & error() const

◆ freshEvents() [1/2]

QList< VP1EventFile > VP1AvailEvents::freshEvents ( ) const
inherited

Definition at line 129 of file VP1AvailEvents.cxx.

130{
132}
VP1EventFile newestEvent() const

◆ freshEvents() [2/2]

QList< VP1EventFile > VP1AvailEvents::freshEvents ( VP1EventFile newestEvt,
const QList< VP1EventFile > & inputEventList ) const
protectedinherited

Definition at line 110 of file VP1AvailEvents.cxx.

111{
112 QList<VP1EventFile> l;
113 if (!newestEvt.isValid())
114 return l;
115 std::set<Imp::EventID>::const_iterator histIt, histItE(m_d->historySorted.end());
116 if (m_d->timeCutForNew==0) {
117 if (m_d->historySorted.find(Imp::evtToID(newestEvt))==histItE)
118 l << newestEvt;
119 return l;
120 }
121 for(VP1EventFile evt : inputEventList)
122 if (m_d->historySorted.find(Imp::evtToID(evt))==histItE && isConsideredFresh(evt,newestEvt))
123 l << evt;
124 return l;
125}
static EventID evtToID(const VP1EventFile &evt)
bool isConsideredFresh(const VP1EventFile &evt, const VP1EventFile &newestEvt) const

◆ freshEventsChanged

void VP1AvailEvents::freshEventsChanged ( )
signalinherited

◆ inHistory()

bool VP1AvailEvents::inHistory ( int run,
int event ) const
protectedinherited

Definition at line 187 of file VP1AvailEvents.cxx.

188{
189 return m_d->historySorted.find(Imp::EventID(run,event))!=m_d->historySorted.end();
190}

◆ init()

void VP1AvailEvtsHttp::init ( )
virtual

Implements VP1AvailEvents.

Definition at line 92 of file VP1AvailEvtsHttp.cxx.

93{
94 m_d->webwatcher_fileinfo->addUrl(m_d->fileinfoUrl);//A signal will be triggered the first time the webwatcher knows anything about the url.
95 m_d->restartExamineEvtsOnServerTimer();
96}

◆ invalidateDirCache()

void VP1AvailEvents::invalidateDirCache ( const QString & dir)
protectedinherited

Definition at line 194 of file VP1AvailEvents.cxx.

195{
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);
199}

◆ isConsideredFresh()

bool VP1AvailEvents::isConsideredFresh ( const VP1EventFile & evt,
const VP1EventFile & newestEvt ) const
protectedinherited

Definition at line 336 of file VP1AvailEvents.cxx.

337{
338 //Notice: Logic here must be similar to logic in VP1EvtsOnServerInfo::events
339
340 if (m_d->timeCutForNew==0) {
341 //Special case where only the newest event is fresh
342 return evt.rawTime()==newestEvt.rawTime() && evt.runNumber()==newestEvt.runNumber();
343 }
344 if (requireNewestRunNumber()&&evt.runNumber()!=newestEvt.runNumber())
345 return false;
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;
348}
int runNumber() const
unsigned rawTime() const

◆ maxLocalFilesToKeep()

int VP1AvailEvents::maxLocalFilesToKeep ( ) const
inherited

Definition at line 98 of file VP1AvailEvents.cxx.

99{
100 return m_d->maxLocalFilesToKeep;
101}

◆ message

void VP1AvailEvents::message ( const QString & ) const
signalinherited

◆ messageDebug()

void VP1AvailEvents::messageDebug ( const QString & s) const
protectedinherited

Definition at line 351 of file VP1AvailEvents.cxx.

352{
353 std::cout<<VP1Msg::prefix_verbose()<<": "<<s.toStdString()<<std::endl;
354}
static const char * prefix_verbose()
Definition VP1Msg.h:59

◆ newestEvent()

VP1EventFile VP1AvailEvents::newestEvent ( ) const
inherited

Definition at line 135 of file VP1AvailEvents.cxx.

136{
137 QList<VP1EventFile> evts(allLocalEvents());
138 if (evts.isEmpty())
139 return VP1EventFile();//invalid
140 return evts.front();
141}

◆ requireNewestRunNumber()

bool VP1AvailEvents::requireNewestRunNumber ( ) const
inlineprotectedinherited

Definition at line 62 of file VP1AvailEvents.h.

62{ return false; /*fixme*/ }

◆ setCurrentEvent()

void VP1AvailEvents::setCurrentEvent ( int run,
int event )
inherited

Definition at line 144 of file VP1AvailEvents.cxx.

145{
146 m_d->historyOrdered << Imp::EventID(run,event);
147 m_d->historySorted.insert(Imp::EventID(run,event));
148}

◆ timeCutForNew()

int VP1AvailEvents::timeCutForNew ( ) const
protectedinherited

Definition at line 92 of file VP1AvailEvents.cxx.

93{
94 return m_d->timeCutForNew;
95}

◆ tmpActiveRetrievalDir()

QString VP1AvailEvents::tmpActiveRetrievalDir ( )
protectedinherited

Definition at line 277 of file VP1AvailEvents.cxx.

278{
279 return m_d->attemptGenerationOfTmpSubdir("activeretrievals",m_d->tmpActiveRetrievalDir);
280}

◆ tmpDir()

const QString & VP1AvailEvents::tmpDir ( ) const
protectedinherited

Definition at line 104 of file VP1AvailEvents.cxx.

105{
106 return m_d->tmpDir;
107}

◆ tmpLocalFileDir()

QString VP1AvailEvents::tmpLocalFileDir ( ) const
protectedinherited

Definition at line 283 of file VP1AvailEvents.cxx.

284{
285 return m_d->attemptGenerationOfTmpSubdir("eventfiles",m_d->tmpLocalFileDir);
286}

Member Data Documentation

◆ m_d

Imp* VP1AvailEvtsHttp::m_d
private

Definition at line 51 of file VP1AvailEvtsHttp.h.


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