Index: fact/tools/pyscripts/new_pyfact/pyfact.py
===================================================================
--- fact/tools/pyscripts/new_pyfact/pyfact.py	(revision 17978)
+++ fact/tools/pyscripts/new_pyfact/pyfact.py	(revision 17979)
@@ -10,9 +10,9 @@
 ROOT.gROOT.SetBatch(True)
 
-########## BUILDING OF THE SHARED OBJECT FILES ###############################
+#--------- BUILDING OF THE SHARED OBJECT FILES -------------------------------
 if __name__ == '__main__' and len(sys.argv) > 1 and 'build' in sys.argv[1]:
     ROOT.gSystem.AddLinkedLibs("-lz")
     root_make_string = ROOT.gSystem.GetMakeSharedLib()
-    if not "-std=c++0x" in root_make_string:
+    if "-std=c++0x" not in root_make_string:
         make_string = root_make_string.replace('$Opt', '$Opt -std=c++0x -D HAVE_ZLIB')
     ROOT.gSystem.SetMakeSharedLib(make_string)
@@ -21,17 +21,33 @@
     ROOT.gROOT.ProcessLine(".L extern_Mars_mcore/zfits.h+O")
     ROOT.gROOT.ProcessLine(".L extern_Mars_mcore/factfits.h+O")
-    if not "-std=c++0x" in root_make_string:
-        make_string = root_make_string.replace('$Opt', "$Opt -std=c++0x -D HAVE_ZLIB -D'PACKAGE_NAME=\"PACKAGE_NAME\"' "
-                                                        "-D'PACKAGE_VERSION=\"PACKAGE_VERSION\"' -D'REVISION=\"REVISION\"' ")
+    if "-std=c++0x" not in root_make_string:
+        make_string = root_make_string.replace(
+            '$Opt',
+            "$Opt -std=c++0x "
+            "-D HAVE_ZLIB "
+            "-D'PACKAGE_NAME=\"PACKAGE_NAME\"' "
+            "-D'PACKAGE_VERSION=\"PACKAGE_VERSION\"' "
+            "-D'REVISION=\"REVISION\"' "
+            )
     ROOT.gSystem.SetMakeSharedLib(make_string)
     ROOT.gROOT.ProcessLine(".L extern_Mars_mcore/DrsCalib.h+O")
 
-    ROOT.gInterpreter.GenerateDictionary("map<string,fits::Entry>","map;string;extern_Mars_mcore/fits.h")
-    ROOT.gInterpreter.GenerateDictionary("pair<string,fits::Entry>","map;string;extern_Mars_mcore/fits.h")
-    ROOT.gInterpreter.GenerateDictionary("map<string,fits::Table::Column>","map;string;extern_Mars_mcore/fits.h")
-    ROOT.gInterpreter.GenerateDictionary("pair<string,fits::Table::Column>","map;string;extern_Mars_mcore/fits.h")
-    ROOT.gInterpreter.GenerateDictionary("vector<DrsCalibrate::Step>","vector;extern_Mars_mcore/DrsCalib.h")
-
-########## USAGE #############################################################
+    ROOT.gInterpreter.GenerateDictionary(
+        "map<string,fits::Entry>",
+        "map;string;extern_Mars_mcore/fits.h")
+    ROOT.gInterpreter.GenerateDictionary(
+        "pair<string,fits::Entry>",
+        "map;string;extern_Mars_mcore/fits.h")
+    ROOT.gInterpreter.GenerateDictionary(
+        "map<string,fits::Table::Column>",
+        "map;string;extern_Mars_mcore/fits.h")
+    ROOT.gInterpreter.GenerateDictionary(
+        "pair<string,fits::Table::Column>",
+        "map;string;extern_Mars_mcore/fits.h")
+    ROOT.gInterpreter.GenerateDictionary(
+        "vector<DrsCalibrate::Step>",
+        "vector;extern_Mars_mcore/DrsCalib.h")
+
+#-------- USAGE -------------------------------------------------------------
 if __name__ == '__main__' and len(sys.argv) < 3:
     print """ Usage:
@@ -52,5 +68,5 @@
     sys.exit(1)
 
-#########  START OF PYFACT MODULE ############################################
+#--------  START OF PYFACT MODULE --------------------------------------------
 path = os.path.dirname(os.path.realpath(__file__))
 ROOT.gSystem.Load(path+'/AutoDict_map_string_fits__Entry__cxx.so')
@@ -66,27 +82,33 @@
 del path
 
-raw_base = '/fact/raw'
-aux_base = '/fact/aux'
+env_name = 'FACT_DATA_BASE_DIR'
+if env_name in os.environ:
+    base_path = os.environ[env_name]
+    raw_base = os.path.join(base_path, 'raw')
+    aux_base = os.path.join(base_path, 'aux')
+else:
+    raw_base = os.path.join('fact', 'raw')
+    aux_base = os.path.join('fact', 'aux')
 
 
 def stub_to_auxfile(s, s2=None, basep=aux_base, basen="*"):
-    """ FIXME :-) 
+    """ FIXME :-)
         It's not yet clear how to generate aux file names from stubs, or iterables
     """
     if s2 is not None:
-        s = "{0}_{1:03d}".format(s,s2)
+        s = "{0}_{1:03d}".format(s, s2)
     y = s[0:4]
     m = s[4:6]
     d = s[6:8]
     date = s[0:8]
-    r = s[9:12]
-    return os.path.join(basep,y,m,d,date+'.'+basen+'.fits')
+    #r = s[9:12]
+    return os.path.join(basep, y, m, d, date + '.' + basen + '.fits')
 
 
 def make_path(s):
     """ make path to fits file
-        
+
         s : string or iterable
-        
+
         Fits files in pyfact do not need to be specified by full paths
         A so called stub path is sufficient. A valid stub path looks like:
@@ -96,5 +118,5 @@
 
         In addition a file can be specified by a 2-element integer iterable,
-        e.g. a list or a tuple, whose first element is the integer denoting the 
+        e.g. a list or a tuple, whose first element is the integer denoting the
         'night' : yyyymmdd
         the 2nd integer is the 'run' : rrr
@@ -103,6 +125,6 @@
 
         the pyfact.Fits class can handle .fits, .fits.gz, and .fits.fz files.
-        stubs dont's specify which one should be used, so we need to check 
-        which one exists, if more than one file exists fitting to the stub, 
+        stubs dont's specify which one should be used, so we need to check
+        which one exists, if more than one file exists fitting to the stub,
         the order of precendence is:
             * .fits    -- since access should be pretty fast
@@ -116,5 +138,5 @@
         night = int(s[0])
         run = int(s[1])
-        _s = "{0:08d}_{1:03d}".format(night,run)
+        _s = "{0:08d}_{1:03d}".format(night, run)
     else:
         _s = s
@@ -122,16 +144,16 @@
     # so now s is some kind of string
     # maybe it is already a path:
-    if os.path.isabs( _s ):
-        # s is already an absolute path. 
+    if os.path.isabs(_s):
+        # s is already an absolute path.
         # maybe the file is not there, but we don't care about that
         return _s
 
-    # it was not an absolute path, maybe it's a relative path, let's check if 
+    # it was not an absolute path, maybe it's a relative path, let's check if
     # it points to a file.
-    elif os.path.exists( _s ):
+    elif os.path.exists(_s):
         # s is certainly a path, it even points to a file :-)
         return os.path.abspath(_s)
 
-    # okay ... s was not a path, so let's generate a nice absolute path 
+    # okay ... s was not a path, so let's generate a nice absolute path
     # from the stub, in case it is a stub ..
     elif re.match('\d{8}_\d{3}', _s):
@@ -140,13 +162,13 @@
         m = _s[4:6]
         d = _s[6:8]
-        r = _s[9:12]
-        start = os.path.join(raw_base,y,m,d,_s[:12]+'.fits')
+        #r = _s[9:12]
+        start = os.path.join(raw_base, y, m, d, _s[:12] + '.fits')
         candidates = [start, start+'.fz', start+'.gz']
         for c in candidates:
             if os.path.exists(c):
                 return c
-        # if we reached this point, s was a stub, but we were not 
-        # able to find a file on the file system... 
-        # let's return our best guess, the '.fz' file path 
+        # if we reached this point, s was a stub, but we were not
+        # able to find a file on the file system...
+        # let's return our best guess, the '.fz' file path
         # the Fits.__init__() will complain, if it can't find the file.
         return candidates[1]
@@ -154,5 +176,6 @@
         raise IOError("{0} can't be used for path generation".format(s))
 
-class Fits( object ):
+
+class Fits(object):
     """ General FITS file access
 
@@ -162,4 +185,5 @@
     """
     __module__ = 'pyfact'
+
     def __init__(self, path):
         """ Open fits file, parse header and setup table colums
@@ -178,7 +202,7 @@
     def __repr__(self):
         return '{s.__class__.__name__}(path="{s._path}")'.format(s=self)
-    
+
     def __str__(self):
-        s = """Fits object: 
+        s = """Fits object:
         path = {s._path}
         row = {s._current_row}
@@ -187,5 +211,4 @@
         return s
 
-
     def __len__(self):
         """ return the number of events, in case it's a FACT physics data file
@@ -197,14 +220,16 @@
         """
         """
-        str_to_bool = { 'T':True, 'F':False}
-        type_conversion = { 'I' : int, 'F' : float, 'T' : str, 'B' : str_to_bool.__getitem__}
+        str_to_bool = {'T': True, 'F': False}
+        type_conversion = {'I': int, 'F': float, 'T': str, 'B': str_to_bool.__getitem__}
 
         self.header = {}
         self.header_comments = {}
-        for key,entry in self.f.GetKeys():
+        for key, entry in self.f.GetKeys():
             try:
                 self.header[key] = type_conversion[entry.type](entry.value)
             except KeyError:
-                raise IOError("Error: entry type unknown.\n Is %s, but should be one of: [I,F,T,B]" % (entry.type) )
+                raise IOError(
+                    "Error: entry type unknown.\n "
+                    "Is %s, but should be one of: [I,F,T,B]" % (entry.type))
             self.header_comments[key] = entry.comment
 
@@ -212,8 +237,15 @@
         """
         """
-        col_type_to_np_type_map = { 'L' : 'b1',  'A' : 'a1', 'B' : 'i1',
-            'I' : 'i2', 'J' : 'i4', 'K' : 'i8', 'E' : 'f4', 'D' : 'f8'}
+        col_type_to_np_type_map = {
+            'L': 'b1',
+            'A': 'a1',
+            'B': 'i1',
+            'I': 'i2',
+            'J': 'i4',
+            'K': 'i8',
+            'E': 'f4',
+            'D': 'f8'}
         self.cols = {}
-        for key,col in self.f.GetColumns():
+        for key, col in self.f.GetColumns():
             self.cols[key] = np.zeros(col.num, col_type_to_np_type_map[col.type])
             if col.num != 0:
@@ -231,5 +263,5 @@
             else:
                 self._current_row += 1
-            if self.f.GetNextRow() == False:
+            if self.f.GetNextRow() is False:
                 self._current_row = None
                 raise StopIteration
@@ -237,13 +269,15 @@
             row = int(row)
             self._current_row = row
-            if self.f.GetRow(row) == False:
+            if self.f.GetRow(row) is False:
                 self._current_row = None
                 raise StopIteration
         return self
 
-class AuxFile( Fits ):
+
+class AuxFile(Fits):
     """ easy(?) access to FACT aux files
     """
     __module__ = 'pyfact'
+
     def __init__(self, path, verbose=False):
         self._verbose = verbose
@@ -251,11 +285,18 @@
 
     def _setup_columns(self):
-        col_type_to_np_type_map = { 'L' : 'b1',  'A' : 'a1', 'B' : 'i1',
-            'I' : 'i2', 'J' : 'i4', 'K' : 'i8', 'E' : 'f4', 'D' : 'f8'}
+        col_type_to_np_type_map = {
+            'L': 'b1',
+            'A': 'a1',
+            'B': 'i1',
+            'I': 'i2',
+            'J': 'i4',
+            'K': 'i8',
+            'E': 'f4',
+            'D': 'f8'}
         self._cols = {}
         self.cols = {}
-        
+
         N = len(self)
-        for key,col in self.f.GetColumns():
+        for key, col in self.f.GetColumns():
             self._cols[key] = np.zeros(col.num, col_type_to_np_type_map[col.type])
             self.cols[key] = np.zeros((N, col.num), col_type_to_np_type_map[col.type])
@@ -263,6 +304,5 @@
                 self.f.SetPtrAddress(key, self._cols[key])
 
-
-        for i,row in enumerate(self):
+        for i, row in enumerate(self):
             if self._verbose:
                 try:
@@ -274,13 +314,14 @@
 
             for key in self._cols:
-                self.cols[key][i,:] = self._cols[key]
-
-
-class RawData( Fits ):
+                self.cols[key][i, :] = self._cols[key]
+
+
+class RawData(Fits):
     """ Special raw data FITS file access (with DRS4 calibration)
 
         During iteration the C++ method DrsCalibration::Apply is being called.
     """
-    __module__='pyfact'
+    __module__ = 'pyfact'
+
     def __init__(self, data_path, calib_path):
         """ -constructor-
@@ -289,10 +330,10 @@
         """
         super(RawData, self).__init__(data_path)
-        self.cols['CalibData'] = np.zeros( self.cols['Data'].shape, np.float32)
-        self.cols['CalibData2D'] = self.cols['CalibData'].reshape( self.header['NPIX'], -1)
+        self.cols['CalibData'] = np.zeros(self.cols['Data'].shape, np.float32)
+        self.cols['CalibData2D'] = self.cols['CalibData'].reshape(self.header['NPIX'], -1)
         if not self.cols['CalibData2D'].base is self.cols['CalibData']:
             print "Error seomthing went wrong!"
         self.drs_calibration = ROOT.DrsCalibration()
-        self.drs_calibration.ReadFitsImp( calib_path )
+        self.drs_calibration.ReadFitsImp(calib_path)
 
         self.drs_calibrate = ROOT.DrsCalibrate()
@@ -308,24 +349,26 @@
         super(RawData, self).next(row)
 
-        self.drs_calibration.Apply( self.cols['CalibData'],
-                                    self.cols['Data'],
-                                    self.cols['StartCellData'],
-                                    self.header['NROI'])
+        self.drs_calibration.Apply(
+            self.cols['CalibData'],
+            self.cols['Data'],
+            self.cols['StartCellData'],
+            self.header['NROI']
+            )
 
         for previous_start_cells in self.list_of_previous_start_cells:
             self.drs_calibrate.CorrectStep(
-                                self.cols['CalibData'],
-                                self.header['NPIX'],
-                                self.header['NROI'],
-                                previous_start_cells,
-                                self.cols['StartCellData'],
-                                self.header['NROI']+10)
+                self.cols['CalibData'],
+                self.header['NPIX'],
+                self.header['NROI'],
+                previous_start_cells,
+                self.cols['StartCellData'],
+                self.header['NROI']+10)
             self.drs_calibrate.CorrectStep(
-                                self.cols['CalibData'],
-                                self.header['NPIX'],
-                                self.header['NROI'],
-                                previous_start_cells,
-                                self.cols['StartCellData'],
-                                3)
+                self.cols['CalibData'],
+                self.header['NPIX'],
+                self.header['NROI'],
+                previous_start_cells,
+                self.cols['StartCellData'],
+                3)
         self.list_of_previous_start_cells.append(self.cols['StartCellData'])
         if len(self.list_of_previous_start_cells) > 5:
@@ -336,5 +379,4 @@
 
         return self
-
 
 
@@ -348,5 +390,5 @@
     print "The files has these cols:", f.cols.keys()
 
-    for counter,row in enumerate(f):
+    for counter, row in enumerate(f):
         print "Event Id:", row.cols['EventNum']
         print "shape of column 'StartCellData'", row.cols['StartCellData'].shape
