diff --git a/Script/BeastFileNameParser.py b/Script/BeastFileNameParser.py
index 0b22ab93bc397677596e5b9a696522261b384e3e..32be9077cd0106386852ecf3a0a5b3694732c97c 100644
--- a/Script/BeastFileNameParser.py
+++ b/Script/BeastFileNameParser.py
@@ -1,12 +1,32 @@
+#!/usr/bin/env tdaq_python
 import os.path
 from BaseFileNameParser import BaseFileNameParser
 
+basepath = ""
+
+
+def init(params):
+    global basepath
+    basepath = params['basepath']
+
 
 class BeastFileNameParser(BaseFileNameParser):
 
     def __init__(self, filename):
+        global basepath
         BaseFileNameParser.__init__(self, filename)
-        self.dirname = '/'.join(os.path.dirname(filename).split('/')[-3:])
+        fulldir = os.path.dirname(filename)
+        if basepath:
+            self.dirname = os.path.relpath(fulldir, basepath)
+        else:
+            self.dirname = fulldir
 
     def Directory(self):
         return self.dirname
+
+
+if __name__=='__main__':
+    import sys
+    init({'basepath':sys.argv[1]})
+    p = BeastFileNameParser(sys.argv[2])
+    print p.Directory()