[Rivet-svn] rivet: User new hepdata website for data download. Discontinue S...

Rivet Mercurial rivet at projects.hepforge.org
Fri Feb 24 16:45:01 GMT 2017


details:   https://rivet.hepforge.org/hg/rivet/rev/bdc537abd7d5
branches:  
changeset: 5700:bdc537abd7d5
user:      Holger Schulz <holger.schulz at durham.ac.uk>
date:      Fri Feb 24 16:42:26 2017 +0000
description:
User new hepdata website for data download. Discontinue Spires key

diffs (40 lines):

--- a/bin/rivet-mkanalysis	Fri Feb 24 16:27:32 2017 +0000
+++ b/bin/rivet-mkanalysis	Fri Feb 24 16:42:26 2017 +0000
@@ -128,23 +128,26 @@
     ## Try to download YODA data file from HepData
     if STDANA:
         try:
-            import urllib
+            import urllib2, tarfile, StringIO
             hdurl = None
             if INSPIRE_SPIRES == "I":
-                hdurl = "http://hepdata.cedar.ac.uk/view/ins%s/yoda" % ANAINSPIREID
-            elif INSPIRE_SPIRES == "S":
-                hdurl = "http://hepdata.cedar.ac.uk/view/irn%s/yoda" % ANAINSPIREID
+                hdurl = "http://www.hepdata.net/record/ins%s?format=yoda" % ANAINSPIREID
             if hdurl:
                 logging.debug("Getting data file from HepData at %s" % hdurl)
-                httpstream = urllib.urlopen(hdurl)
-                yodastr = httpstream.read()
-                if not yodastr or "<html>" in yodastr:
+                response = urllib2.urlopen(hdurl)
+                download=response.read()
+                if not download or "<html" in download:
                     logging.warning("Problem encountered when getting data from HepData (%s). No reference data file written." % hdurl)
                 else:
-                    f = open("%s.yoda" % ANANAME, "w")
-                    f.write(yodastr)
-                    f.close()
-                httpstream.close()
+                    tar = tarfile.open(mode= "r:gz", fileobj = StringIO.StringIO(download))
+                    fnames = tar.getnames()
+                    if len(fnames)>1:
+                        logging.warning("Found more than one file on downloaded archive. Not writing data file")
+                    else:
+                        tar.extractall()
+                        import os
+                        os.rename(fnames[0], "%s.yoda"%ANANAME)
+                response.close()
             else:
                 logging.warning("Could not identify a URL for getting reference data from HepData. No reference data file written.")
         except Exception, e:


More information about the Rivet-svn mailing list