[Rivet-svn] r3369 - in trunk: . bin doc pyext

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Sat Sep 17 19:48:44 BST 2011


Author: buckley
Date: Sat Sep 17 19:48:44 2011
New Revision: 3369

Log:
Updating the mkanalysis, BibTeX-grabbing and other places that care about analysis SPIRES IDs to also be able to handle the new Inspire system record IDs. The missing link is getting to HepData from an Inspire code...

Modified:
   trunk/ChangeLog
   trunk/bin/rivet
   trunk/bin/rivet-mkanalysis
   trunk/doc/mk-analysis-html
   trunk/doc/mk-analysis-latex
   trunk/pyext/spiresbib.py

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Sat Sep 17 19:23:15 2011	(r3368)
+++ trunk/ChangeLog	Sat Sep 17 19:48:44 2011	(r3369)
@@ -1,5 +1,10 @@
 2011-09-17  Andy Buckley  <andy at insectnation.org>
 
+	* Updating the mkanalysis, BibTeX-grabbing and other places that
+	care about analysis SPIRES IDs to also be able to handle the new
+	Inspire system record IDs. The missing link is getting to HepData
+	from an Inspire code...
+
 	* Using the .info file rather than an in-code declaration to
 	specify that an analysis needs cross-section information.
 

Modified: trunk/bin/rivet
==============================================================================
--- trunk/bin/rivet	Sat Sep 17 19:23:15 2011	(r3368)
+++ trunk/bin/rivet	Sat Sep 17 19:48:44 2011	(r3369)
@@ -277,9 +277,16 @@
         print ""
         print "Status: %s" % ana.status()
         print ""
-        print "Spires ID: %s" % ana.spiresId()
-        print "Inspire URL: http://inspire-hep.net/search?p=find+key+%s" % ana.spiresId()
-        print "HepData URL: http://hepdata.cedar.ac.uk/view/irn%s" % ana.spiresId()
+
+        if ana.inspireId():
+            print "Inspire ID: %s" % ana.inspireId()
+            print "Inspire URL: http://inspire-hep.net/record/%s" % ana.inspireId()
+            # TODO: Need a way to get to HepData from an Inspire record
+        elif ana.spiresId():
+            print "Spires ID: %s" % ana.spiresId()
+            print "Inspire URL: http://inspire-hep.net/search?p=find+key+%s" % ana.spiresId()
+            print "HepData URL: http://hepdata.cedar.ac.uk/view/irn%s" % ana.spiresId()
+
         coll = ""
         if ana.collider():
             coll = ana.collider()

Modified: trunk/bin/rivet-mkanalysis
==============================================================================
--- trunk/bin/rivet-mkanalysis	Sat Sep 17 19:23:15 2011	(r3368)
+++ trunk/bin/rivet-mkanalysis	Sat Sep 17 19:48:44 2011	(r3369)
@@ -74,25 +74,27 @@
 
     ## Extract some metadata from the name if it matches the standard pattern
     import re
-    re_stdana = re.compile(r"^(\w+)_(\d{4})_S(\d+)$")
+    re_stdana = re.compile(r"^(\w+)_(\d{4})_(I|S)(\d+)$")
     match = re_stdana.match(ANANAME)
     STDANA = False
     ANAEXPT = "<Insert the experiment name>"
     ANAYEAR = "<Insert year of publication>"
-    ANASPIRESID = "<Insert the SPIRES IRN ID>"
+    INSPIRE_SPIRES = None
+    ANAINSPIREID = "<Insert the Inspire ID>"
     if match:
         STDANA = True
         ANAEXPT = match.group(1)
         ANAYEAR = match.group(2)
-        ANASPIRESID = match.group(3)
+        INSPIRE_SPIRES = match.group(3)
+        ANAINSPIREID = match.group(4)
     KEYWORDS = {
         "ANANAME" : ANANAME,
         "ANAEXPT" : ANAEXPT,
         "ANAYEAR" : ANAYEAR,
-        "ANASPIRESID" : ANASPIRESID
+        "ANAREFREPO" : "Spires" if INSPIRE_SPIRES == "S" else "Inspire",
+        "ANAINSPIREID" : ANAINSPIREID
         }
 
-
     ## Try to get bib info from SPIRES
     ANABIBKEY = ""
     ANABIBTEX = ""
@@ -100,10 +102,10 @@
     if STDANA:
         try:
             import spiresbib
-            logging.debug("Getting SPIRES biblio data for '%s'" % ANANAME)
-            bibkey, bibtex = spiresbib.get_bibtex_from_spires(ANASPIRESID)
+            logging.debug("Getting Inspire/SPIRES biblio data for '%s'" % ANANAME)
+            bibkey, bibtex = spiresbib.get_bibtex_from_repo(INSPIRE_SPIRES, ANAINSPIREID)
         except Exception, e:
-            logging.error("SPIRES oops: %s" % e)
+            logging.error("Inspire/SPIRES oops: %s" % e)
         if bibkey and bibtex:
             ANABIBKEY = bibkey
             ANABIBTEX = bibtex
@@ -115,7 +117,7 @@
     if STDANA:
         try:
             import urllib
-            hdurl = "http://hepdata.cedar.ac.uk/view/irn%s/aida" % ANASPIRESID
+            hdurl = "http://hepdata.cedar.ac.uk/view/irn%s/aida" % ANAINSPIREID
             logging.debug("Getting data file from HepData at %s" % hdurl)
             httpstream = urllib.urlopen(hdurl)
             aidastr = httpstream.read()
@@ -131,10 +133,12 @@
 
 
     if opts.INLINE:
+        KEYWORDS["ANAREFREPO_LOWER"] = KEYWORDS["ANAREFREPO"].lower()
         INLINEMETHODS="""
   public:
     string experiment()         const { return "%(ANAEXPT)s"; }
     string year()               const { return "%(ANAYEAR)s"; }
+    string %(ANAREFREPO_LOWER)sId()          const { return "%(ANAINSPIREID)s"; }
     string spiresId()           const { return "%(ANASPIRESID)s"; }
     string collider()           const { return ""; }
     string summary()            const { return ""; }
@@ -147,6 +151,7 @@
     vector<string> references() const { return vector<string>(); }
     vector<std::string> todos() const { return vector<string>(); }
     """ % KEYWORDS
+        del KEYWORDS["ANAREFREPO_LOWER"]
     else:
         INLINEMETHODS=""
 
@@ -176,10 +181,7 @@
     /// Constructor
     %(ANANAME)s()
       : Analysis("%(ANANAME)s")
-    {
-      /// @todo Set whether your finalize method needs the generator cross section
-      setNeedsCrossSection(true);
-    }
+    {    }
 
     //@}
 
@@ -276,7 +278,7 @@
 Summary: <Insert short %(ANANAME)s description>
 Experiment: %(ANAEXPT)s
 Collider: <Insert %(ANANAME)s collider>
-SpiresID: %(ANASPIRESID)s
+%(ANAREFREPO)sID: %(ANAINSPIREID)s
 Status: UNVALIDATED
 Authors:
  - Your Name <your at email.address>
@@ -289,6 +291,7 @@
   efficiency cut(s) that may be needed; essentially any details needed to set
   up a generator to reproduce the data.>
 NumEvents: 1000000
+NeedCrossSection: no
 #Beams: <Insert beam pair(s), e.g. [p-, p+] or [[p-, e-], [p-, e+]]>
 #Energies: <Insert list of run energies or beam energy pairs in GeV,
 #           e.g. [1960] or [[8.0, 3.5]] or [630, 1800]. Order pairs to match "Beams">

Modified: trunk/doc/mk-analysis-html
==============================================================================
--- trunk/doc/mk-analysis-html	Sat Sep 17 19:23:15 2011	(r3368)
+++ trunk/doc/mk-analysis-html	Sat Sep 17 19:48:44 2011	(r3369)
@@ -60,9 +60,14 @@
     page += "<h3 id='%s'>%s</h3>\n" % (aname, aname)
     page += "<b>%s</b><br/>\n" %  ana.summary()
     page += "<b>Experiment:</b> %s (%s)<br/>\n" % (ana.experiment(), ana.collider())
-    spiresbase = "http://inspire-hep.net/search?p=find+key"
-    page += "<b>Spires ID:</b> <a href='%s+%s'>%s</a><br/>\n" % \
-        (spiresbase, ana.spiresId(), ana.spiresId())
+    if ana.inspireId():
+        spiresbase = "http://inspire-hep.net/record"
+        page += "<b>Inspire ID:</b> <a href='%s/%s'>%s</a><br/>\n" % \
+            (spiresbase, ana.inspireId(), ana.inspireId())
+    elif ana.spiresId():
+        spiresbase = "http://inspire-hep.net/search?p=find+key"
+        page += "<b>Spires ID:</b> <a href='%s+%s'>%s</a><br/>\n" % \
+            (spiresbase, ana.spiresId(), ana.spiresId())
     page += "<b>Status:</b> %s<br/>\n" % ana.status()
 
 

Modified: trunk/doc/mk-analysis-latex
==============================================================================
--- trunk/doc/mk-analysis-latex	Sat Sep 17 19:23:15 2011	(r3368)
+++ trunk/doc/mk-analysis-latex	Sat Sep 17 19:48:44 2011	(r3369)
@@ -99,7 +99,11 @@
         if ana.collider():
             page += " (%s)" % ana.collider()
         page += "\\newline\n"
-    if ana.spiresId():
+    if ana.inspireId():
+        spiresbase = "http://inspire-hep.net/record"
+        page += "\\textbf{Inspire ID:} \\href{%s+%s}{%s}\\newline\n" % \
+            (spiresbase, ana.inspireId(), ana.inspireId())
+    elif ana.spiresId():
         spiresbase = "http://inspire-hep.net/search?p=find+key"
         page += "\\textbf{Spires ID:} \\href{%s+%s}{%s}\\newline\n" % \
             (spiresbase, ana.spiresId(), ana.spiresId())

Modified: trunk/pyext/spiresbib.py
==============================================================================
--- trunk/pyext/spiresbib.py	Sat Sep 17 19:23:15 2011	(r3368)
+++ trunk/pyext/spiresbib.py	Sat Sep 17 19:48:44 2011	(r3369)
@@ -6,24 +6,29 @@
 
 usage = """%prog <spiresid> [<spiresid2> ...]
 
-Given SPIRES paper IDs, fetch the corresponding BibTeX db entry from the SPIRES
-Web interface and write it to stdout.
+Given Inspire and SPIRES paper IDs, fetch the corresponding BibTeX db entry from
+the SPIRES Web interface and write it to stdout. Prefix the code with I or S
+appropriately.
 """
 
-def fetch_spires_bibtex(spiresid):
-    spiresurl = "http://inspire-hep.net/search?p=find+key+%s&of=hx" % str(spiresid)
-    logging.debug("Downloading SPIRES BibTeX from %s" % spiresurl)
-    hreq = urllib2.urlopen(spiresurl)
+def fetch_bibtex(iscode, refid):
+    if iscode.upper() == "I":
+        url = "http://inspire-hep.net/record/%s/export/hx" % str(refid)
+        logging.debug("Downloading Inspire BibTeX from %s" % url)
+    elif iscode.upper() == "S":
+        url = "http://inspire-hep.net/search?p=find+key+%s&of=hx" % str(refid)
+        logging.debug("Downloading SPIRES BibTeX from %s" % url)
+    hreq = urllib2.urlopen(url)
     bibtexhtml = hreq.read()
     hreq.close()
     #logging.debug(bibtexhtml)
     return bibtexhtml
 
 
-def extract_bibtex(spireshtml):
+def extract_bibtex(html):
     ## Extract BibTeX block from HTML
     re_spiresbibtex = re.compile(r'<pre>(.*?)</pre>', re.MULTILINE | re.DOTALL)
-    m = re_spiresbibtex.search(spireshtml)
+    m = re_spiresbibtex.search(html)
     if m is None:
         return None, None
     bib = m.group(1).strip()
@@ -39,18 +44,18 @@
     return key, bib
 
 
-def get_bibtex_from_spires(spiresid):
-    html = fetch_spires_bibtex(spiresid)
+def get_bibtex_from_repo(iscode, refid):
+    html = fetch_bibtex(iscode, refid)
     key, bibtex = extract_bibtex(html)
     return key, bibtex
 
 
-def get_bibtexs_from_spires(spiresids):
+def get_bibtexs_from_repos(iscodes_refids):
     bibdb = {}
-    for spiresid in spiresids:
-        key, bibtex = get_bibtex_from_spires(spiresid)
+    for iscode, refid in iscodes_refids:
+        key, bibtex = get_bibtex_from_repo(iscode, refid)
         if key and bibtex:
-            bibdb[spiresid] = (key, bibtex)
+            bibdb[refid] = (key, bibtex)
     return bibdb
 
 
@@ -61,8 +66,10 @@
     opts, args = parser.parse_args()
 
     ## Make individual bibinfo files
-    for sid in args:
-        key, bibtex = get_bibtex_from_spires(sid)
+    for arg in args:
+        iscode = arg[0]
+        refid = arg[1:]
+        key, bibtex = get_bibtex_from_repo(iscode, refid)
         import sys
         f = sys.stdout
         f.write("BibKey: %s\n" % key)
@@ -73,8 +80,8 @@
     # for sid, (key, bibtex) in bibdb.iteritems():
     #     print key, "=>\n", bibtex
 
-    # ## Pickle ref db
+    # ## Pickle ref db9151176
     # import cPickle as pickle
-    # fpkl = open("spiresbib.pkl", "w")
+    # fpkl = open("spiresbib.pkl", "w")repo
     # pickle.dump(bibdb)
     # fpkl.close()


More information about the Rivet-svn mailing list