Index: fact/tools/pyscripts/pyfact/pyfact.py
===================================================================
--- fact/tools/pyscripts/pyfact/pyfact.py	(revision 13515)
+++ fact/tools/pyscripts/pyfact/pyfact.py	(revision 13516)
@@ -85,5 +85,6 @@
                 baseline_file_name='',
                 return_dict = None,
-                do_calibration = True):
+                do_calibration = True,
+                use_CalFactFits = True):
         """ initialize object
         
@@ -110,4 +111,5 @@
             return_dict = False
         self.return_dict = return_dict
+        self.use_CalFactFits = use_CalFactFits
         
         self.do_calibration = do_calibration
@@ -126,85 +128,114 @@
         
         # access data file
-        try:
-            data_file = FactFits(self.data_file_name)
-        except IOError:
-            print 'problem accessing data file: ', data_file_name
-            raise  # stop ! no data
-        #: data file (fits object)
-        self.data_file = data_file
-        
-        # get basic information about the data file
-        #: region of interest (number of DRS slices read)
-        self.nroi    = data_file.GetUInt('NROI')
-        #: number of pixels (should be 1440)
-        self.npix    = data_file.GetUInt('NPIX')
-        #: number of events in the data run
-        self.nevents = data_file.GetNumRows()
-        
-        # allocate the data memories
-        self.event_id = c_ulong()
-        self.trigger_type = c_ushort()
-        #: 1D array with raw data
-        self.data  = np.zeros( self.npix * self.nroi, np.int16 ).reshape(self.npix ,self.nroi)
-        #: slice where drs readout started
-        self.start_cells = np.zeros( self.npix, np.int16 )
-        #: time when the FAD was triggered, in some strange units...
-        self.board_times = np.zeros( 40, np.int32 )
-
-        # set the pointers to the data++
-        data_file.SetPtrAddress('EventNum', self.event_id)
-        data_file.SetPtrAddress('TriggerType', self.trigger_type)
-        data_file.SetPtrAddress('StartCellData', self.start_cells) 
-        data_file.SetPtrAddress('Data', self.data) 
-        data_file.SetPtrAddress('BoardTime', self.board_times) 
+        if use_CalFactFits:
+            try:
+                data_file = CalFactFits(data_file_name, calib_file_name)
+            except IOError:
+                print 'problem accessing data file: ', data_file_name
+                raise  # stop ! no data
                 
-        # open the calibration file
-        try:
-            calib_file = FactFits(self.calib_file_name)
-        except IOError:
-            print 'problem accessing calibration file: ', calib_file_name
-            raise
-        #: drs calibration file
-        self.calib_file = calib_file
-        
-        baseline_mean       = calib_file.GetN('BaselineMean')
-        gain_mean           = calib_file.GetN('GainMean')
-        trigger_offset_mean = calib_file.GetN('TriggerOffsetMean')
-
-        self.Nblm  = baseline_mean       / self.npix
-        self.Ngm   = gain_mean           / self.npix
-        self.Ntom  = trigger_offset_mean / self.npix
-
-        self.blm = np.zeros(baseline_mean, np.float32).reshape(self.npix , self.Nblm)
-        self.gm  = np.zeros(gain_mean, np.float32).reshape(self.npix , self.Ngm)
-        self.tom = np.zeros(trigger_offset_mean, np.float32).reshape(self.npix , self.Ntom)
-
-        calib_file.SetPtrAddress('BaselineMean', self.blm)
-        calib_file.SetPtrAddress('GainMean', self.gm)
-        calib_file.SetPtrAddress('TriggerOffsetMean', self.tom)
-        calib_file.GetRow(0)
-        
-        # make calibration constants double, so we never need to roll
-        self.blm = np.hstack((self.blm, self.blm))
-        self.gm = np.hstack((self.gm, self.gm))
-        self.tom = np.hstack((self.tom, self.tom))
-
-        self.v_bsl = np.zeros(self.npix)  # array of baseline values (all ZERO)
+            self.data_file = data_file
+            self.data      = np.empty( data_file.npix * data_file.nroi, np.float64)
+            data_file.SetNpcaldataPtr(self.data)
+
+            
+            self.nroi    = data_file.nroi
+            self.npix    = data_file.npix
+            self.nevents = data_file.nevents
+            
+            # Data per event
+            self.event_id     = None
+            self.trigger_type = None
+            self.data         = None
+            self.start_cells  = None
+            self.board_times  = None
+
+        else:
+            try:
+                data_file = FactFits(self.data_file_name)
+            except IOError:
+                print 'problem accessing data file: ', data_file_name
+                raise  # stop ! no data
+        
+            self.data_file = data_file
+            
+            # get basic information about the data file
+            #: region of interest (number of DRS slices read)
+            self.nroi    = data_file.GetUInt('NROI')
+            #: number of pixels (should be 1440)
+            self.npix    = data_file.GetUInt('NPIX')
+            #: number of events in the data run
+            self.nevents = data_file.GetNumRows()
+            
+            # allocate the data memories
+            self.event_id = c_ulong()
+            self.trigger_type = c_ushort()
+            #: 1D array with raw data
+            self.data  = np.zeros( self.npix * self.nroi, np.int16 ).reshape(self.npix ,self.nroi)
+            #: slice where drs readout started
+            self.start_cells = np.zeros( self.npix, np.int16 )
+            #: time when the FAD was triggered, in some strange units...
+            self.board_times = np.zeros( 40, np.int32 )
+
+            # set the pointers to the data++
+            data_file.SetPtrAddress('EventNum', self.event_id)
+            data_file.SetPtrAddress('TriggerType', self.trigger_type)
+            data_file.SetPtrAddress('StartCellData', self.start_cells) 
+            data_file.SetPtrAddress('Data', self.data) 
+            data_file.SetPtrAddress('BoardTime', self.board_times) 
+                    
+            # open the calibration file
+            try:
+                calib_file = FactFits(self.calib_file_name)
+            except IOError:
+                print 'problem accessing calibration file: ', calib_file_name
+                raise
+            #: drs calibration file
+            self.calib_file = calib_file
+            
+            baseline_mean       = calib_file.GetN('BaselineMean')
+            gain_mean           = calib_file.GetN('GainMean')
+            trigger_offset_mean = calib_file.GetN('TriggerOffsetMean')
+
+            self.Nblm  = baseline_mean       / self.npix
+            self.Ngm   = gain_mean           / self.npix
+            self.Ntom  = trigger_offset_mean / self.npix
+
+            self.blm = np.zeros(baseline_mean, np.float32).reshape(self.npix , self.Nblm)
+            self.gm  = np.zeros(gain_mean, np.float32).reshape(self.npix , self.Ngm)
+            self.tom = np.zeros(trigger_offset_mean, np.float32).reshape(self.npix , self.Ntom)
+
+            calib_file.SetPtrAddress('BaselineMean', self.blm)
+            calib_file.SetPtrAddress('GainMean', self.gm)
+            calib_file.SetPtrAddress('TriggerOffsetMean', self.tom)
+            calib_file.GetRow(0)
+            
+            # make calibration constants double, so we never need to roll
+            self.blm = np.hstack((self.blm, self.blm))
+            self.gm = np.hstack((self.gm, self.gm))
+            self.tom = np.hstack((self.tom, self.tom))
+
+            self.v_bsl = np.zeros(self.npix)  # array of baseline values (all ZERO)
 
     def __iter__(self):
         """ iterator """
         return self
-        
-    def __add__(self, jump_over):
-        self.data_file.GetRow(jump_over)
-        return self
-        
+
     def next(self):
         """ used by __iter__ """
-        if self.data_file.GetNextRow() == False:
-            raise StopIteration
-        else:
-            if self.do_calibration == True:
-                self.calibrate_drs_amplitude()
+        if self.use_CalFactFits:
+            if self.data_file.GetCalEvent() == False:
+                raise StopIteration
+            else:
+                self.event_id     = self.data_file.event_id
+                self.trigger_type = self.data_file.event_triggertype
+                self.start_cells  = self.data_file.event_offset
+                self.board_times  = self.data_file.event_boardtimes
+        else:
+            if self.data_file.GetNextRow() == False:
+                raise StopIteration
+            else:
+                if self.do_calibration == True:
+                    self.calibrate_drs_amplitude()
 
         #print 'nevents = ', self.nevents, 'event_id = ', self.event_id.value
@@ -217,6 +248,9 @@
         """ load the next event from disk and calibrate it
         """
-        self.data_file.GetNextRow()
-        self.calibrate_drs_amplitude()
+        if self.use_CalFactFits:
+            self.data_file.GetCalEvent()
+        else:
+            self.data_file.GetNextRow()
+            self.calibrate_drs_amplitude()
 
     def calibrate_drs_amplitude(self):
