Posts Tagged ‘howto’

Fix wireless at Edwards Dortmund

Tuesday, March 30th, 2010

The Edwards coffeehouse in Dortmund is a nice place to work with some friends, while having a beer or a coffee due to it’s huge tables, free wireless and central location.

Unfortunately their wireless network router is quite old and apparently gets confused by something in the OSX network stack (probably some bonjour packets). Whatever the reason is, the net effect is that you can connect to the network “edwardsnet” but you don’t get an IP address from it’s router. So the only way to solve this is to assign yourself a valid ip and configure the gateway and DNS by hand.

IPv6 Adress: 192.168.2.XXX  (best guess XXX in the range from 50 to 100)
Subnet Mask: 255.255.0.0
Router:      192.168.2.1
DNS:         8.8.8.8        (one of Googles public DNS servers)

Please note that you kind of have to guess a free ip. So please try to be polite and change your address if strange network behaviour occurs. Maybe best thing is to guess an ip use that one to scan the network using some pings and than use one of the ips that seem to be free.

Comet style demo using CheeryPy

Thursday, August 6th, 2009

The following illustrates how to update an SVG embeded in XHTML when new information is available on the server (aka COMET style). The trick is to querry the Server in a “long poll” through an XMLHttpRequest and then wait until Server has the new info ready. In this Example the delayed info is a new time string from the server after a REST style querry to the exposed “sleep” function of the CherryPy server.

The resulting app will be served under http://localhost:8080/xhr
and should show a rotating clock with the time send from the server
like seen here:

clock

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cherrypy
import time

__author__ = 'Stephan Nies'

server = 'localhost'

class Comet(object):
  """CherryPy for Comet-style asynchronous communication through XMLHttpRequest"""

  @cherrypy.expose
  def xhr(self):
    xhtml="""<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">

  <script type="text/javascript">

    function sendToServer(url){
      try{
        var http = new XMLHttpRequest();
        var url = url;
        http.open("GET", url, false);
        http.send(null);
        return http.responseText;
      }
      catch(ex){
        throw ex;
      }
    }

    function time(sec){
      return sendToServer("http://%s:8080/sleep/"+sec);
    }

    function update(x) {
      if (x > 360) {
        x = 0;
      }
      x = x + 6;
      t = time(5);
      document.getElementById("txt").firstChild.textContent = t;
      document.getElementById("clock").setAttribute("transform", "rotate("+x+",200,200)");
      setTimeout("update("+x+")", 100);
    }
  </script>

  <head>
    <title>SVG clock with time by server side comet</title>
  </head>

  <body onload="update(0)">
    <svg width="600px" height="400px" version="1.1"
    xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <defs>
        <g id="MyClock">
          <rect x="0" y="0" rx="20" ry="20" width="250" height="100"
          style="fill:red;stroke:black;stroke-width:5;opacity:0.5"/>
          <text id="txt" x="15" y="56"
          style="font-family:Verdana;font-size:16px"> It's SVG! </text>
        </g>
      </defs>
      <use id="clock" x="50" y="150" xlink:href="#MyClock" />
    </svg>
  </body>
</html>
    """
    cherrypy.response.headers['Content-Type'] = 'application/xhtml+xml'
    return xhtml % server

  @cherrypy.expose()
  def sleep(self, sec):
    sec = float(sec)
    time.sleep(sec)
    return str(time.ctime(time.time()))

cherrypy.config.update({
    'log.screen':True,
    'tools.sessions.on': True,
    'checker.on':False
})
cherrypy.server.socket_host = server
cherrypy.tree.mount(Comet(), config=None)
cherrypy.engine.start()
cherrypy.engine.block()

Please note that this code uses only standard conform technologies like XHTML, JavaScript and SVG and therefore should work without plugins on any standard conform Browser (tested on Firefox 3.0.12 and Safari 4.0.2). In other words: This Code doesn’t work in any Internet Explorer available to date (<= IE8).

Using PyRoot to write a TTree

Sunday, March 8th, 2009

Here is a quick example of how one can create and fill a simple TTree in PyRoot. I find this especially usefull when the input data are in form of a flat text file as python can do string parsing very well.

This script creates a C-style struct and uses the addresses of the elements inside to this to fill the root tree.

#!/usr/bin/env python
from ROOT import TTree, TFile, AddressOf, gROOT

def main():
  # Make a tree
  f = TFile('myTest.root','RECREATE')
  t = TTree('MyTree','My test tree')

  # Create a struct
  gROOT.ProcessLine(\
    "struct MyStruct{\
      Int_t someInt;\
      Double_t someDouble;\
    };")
  from ROOT import MyStruct

  # Create branches in the tree
  s = MyStruct()
  t.Branch('rootInt',AddressOf(s,'someInt'),'someInt/I')
  t.Branch('rootDouble',AddressOf(s,'someDouble'),'someDouble/D')

  # Fill tree
  for i in range(100):
    s.someInt = i
    s.someDouble = i
    t.Fill()

  f.Write()
  f.Close()

if __name__=='__main__':main()

Minimal histograms with PyRoot and Python

Thursday, February 26th, 2009

This time we do the same minimal histogram example, but using python. Again we assume that the user provides a file example.dat, that contains integer values in ascii format seperated by newlines.

call:

python historam.py example.dat

source for “histogram.py”:

import ROOT, sys

def readDataToHist(fileName):
  f = open(fileName);
  x_min = 0;
  x_max = 10;
  histo = ROOT.TH1I("h1","Histogram Title", 100,x_min,x_max);
  for line in f:
    raw = line[:-1]
    y = int(raw)
    histo.Fill(y);
  return histo;

def histogram(fileName):
  ROOT.gROOT.Reset()
  c1 = ROOT.TCanvas("c1","c1",800,800);
  histo = readDataToHist(fileName);
  c1.cd(1);
  histo.Draw();
  #c1.Update();
  c1.Print("histogram.pdf","Portrait pdf");

if __name__ == "__main__" :
  histogram(sys.argv[1])

Alternative tags for CMT in LHCb

Thursday, November 20th, 2008

So after a long time I finally figured out today how to set alternative
compile options in CMT when using the LHCb framework.

First there are some additonal tags besides the well known tags

for production and debugging code

slc4_amd64_gcc34
slc4_amd64_gcc34_db

one is for code coverage the other for performance tests

tag slc3_ia32_gcc344_cov
tag slc3_ia32_gcc344_pro

Most important is where all this stuff is set,

it’s in

 GaudiPolicy/cmt/requirements

Problem with the XXX_cov and XXX_pro is that there are no
supported prebuild binaries by CERN. So it’s all or nothing either
you build everything on your own or you are stuck. You can work
around that with a little hack:
getpack the GaudiPolicy package to your local cmtuser directory
and just add your additional flags to a supported tag.

If you just want to alter the cppflags for one package you would
just add something like this to the package’s requirements file:

macro_append cppflags " -g "

or

macro_append cppflags "" Linux " -g " Windows " -foo -bar"

Where Linux and Windows would act as a switch for different
compilation setups.and the quoted strings would be the appended
options. Note the first empty qoutes in the second example it’s just
the empty standard case.

Update:

As Stefan Roiser pointed out to me over at the cmt mailing list,
one possibility would be to produce your own requirements file

/my/dir/to/cmt/requirements

put your macro_append etc into there and set an enviornment variable

CMTUSERCONTEXT=/my/dir/to/cmt

Then your requirements file should be processed last, thus changing
appending your compiler flags etc as a last step of the configuration before
executing the make.

Also on the cmt mailing list Grigory Rybkin explained, that if you ever wonder
why your cppflags or any other macro behave weird you could check with

cmt show macro cppflags

Example output for package Moore on a Linux machine:

# Package CMT v1r20p20070208 defines macro cppflags as '-pipe -ansi -pedantic -W -Wall -Wwrite-strings
 -Wpointer-arith -Woverloaded-virtual ' for tag 'Linux'
# Package GaudiPolicy v8r5 defines macro cppflags as ' -fmessage-length=0 -Df2cFortran -fPIC -shared
 -D_GNU_SOURCE -Dlinux -Dunix -pipe -ansi -Wall -Wextra -pthread ' for default tag
# Package GaudiConf v10r13 appends to macro cppflags : ' -DAPPNAME=\"${package}\"
 -DAPPVERS=\"${version}\" ' for default tag
# Package RichKernel v7r17 appends to macro cppflags : ' -DRICHDEBUG ' for tag 'Linux&debug'
# Package LHCbKernel v9r2 remove from macro cppflags : '-DGOD_NOALLOC' for default tag
#
# Selection :
cppflags=' -fmessage-length=0 -Df2cFortran -fPIC -shared -D_GNU_SOURCE -Dlinux -Dunix -pipe -ansi
 -Wall -Wextra -pthread  -DAPPNAME=\"${package}\" -DAPPVERS=\"${version}\" -DRICHDEBUG '

And then use the “-e” option of make via brodcast, like:

cppflags=MYFLAGS cmt br make -e

it orders make to give environment precedence over variables from makefiles.