Index: drsdaq/DRS/DRS.cc
===================================================================
--- drsdaq/DRS/DRS.cc	(revision 114)
+++ drsdaq/DRS/DRS.cc	(revision 132)
@@ -6,6 +6,6 @@
   Created by:   Stefan Ritt, Matthias Schneebeli
 
-  Modified by:  Sebastian Commichau, May-November 2008
-                commichau@phys.ethz.ch
+  Modified by:  Sebastian Commichau (2008)
+		Oliver Grimm (Nov 2009)
 
   Modification: This library works with:
@@ -13,6 +13,5 @@
                 - Struck VME controller (SIS 3100) => faster!
 
-  Contents:     Library functions for DRS board CMC card - requires
-                DRS version 2 or 3 
+  Library functions for DRS board CMC card - requires DRS version 2 or 3 
 
 \********************************************************************/
@@ -139,9 +138,6 @@
   
 #ifdef CT_VME 
-  if (!CloseVME()) 
-    printf("VME connection closed\n");
-  
-  if (!CloseCMEM())
-    printf("CMEM closed\n");
+  if (!CloseVME()) printf("VME connection closed\n");
+  if (!CloseCMEM()) printf("CMEM closed\n");
 #endif
 
@@ -155,28 +151,12 @@
 }
 
-/*------------------------------------------------------------------*/
+
+void DRS::InitialScan() {
+
+  int index = 0;
+  
+  unsigned short Firmware, Serial, Temperature;
+
 #ifdef CT_VME 
-int DRS::OpenVME() {
-
-  // Open VME connection
-  if ((ErrorCode = VME_Open()) != VME_SUCCESS) {
-    
-    VME_ErrorString(ErrorCode,ErrorString);
-    
-    printf("Error: %s\n",ErrorString);
-  }
-  
-  return ErrorCode;
-}
-#endif
-/*------------------------------------------------------------------*/
-
-void DRS::InitialScan() {
-
-  int index = 0;
-  
-  unsigned short Firmware, Serial, Temperature;
-
-#ifdef CT_VME 
   
   unsigned int BoardAddress;
@@ -185,7 +165,5 @@
     
     printf("VME connection opened\n");
-
-    if (!OpenCMEM())
-      printf("CMEM opened\n");
+    if (!OpenCMEM()) printf("CMEM opened\n");
     else return;
     
@@ -195,16 +173,12 @@
 
     MasterMap.window_size	= GEVPC_WINSIZE;                           // VME address window size
-    
     MasterMap.address_modifier	= VME_A32;  
     MasterMap.options		= 0;
-    
-    
+      
     // Check all VME slave slots 
     for (index = First_VME_Slot; index <= Last_VME_Slot; index++) {
-      
-      
+        
       MasterMap.vmebus_address	= GEVPC_BASE_ADDR + index * GEVPC_WINSIZE; // Update VME board base address
-
-      
+   
       if (DEBUG)
 	printf("Checking VME slot %d (base address: 0X%08X)\n",index,MasterMap.vmebus_address);
@@ -399,88 +373,4 @@
 }
 
-/*------------------------------------------------------------------*/
-
-#ifdef CT_VME 
-int DRS::MasterMapVME(int *MMap) {
-  
-  // Do master mapping  
-  if (ErrorCode = VME_MasterMap(&MasterMap, MMap)) {
-    
-    VME_ErrorString(ErrorCode,ErrorString);
-    
-    printf("Error: %s\n",ErrorString);
-  }
-  
-  return(ErrorCode);
-}
-#endif
-
-/*------------------------------------------------------------------*/
-
-#ifdef CT_VME 
-int DRS::MasterUnMapVME(int MMap) {
-  
-  // Delete master mapping
-  if (ErrorCode = VME_MasterUnmap(MMap)) {
-    
-    VME_ErrorString(ErrorCode,ErrorString);
-    
-    printf("Error: %s\n",ErrorString);
-  }
-  
-  return(ErrorCode);  
-}
-#endif
-
-/*------------------------------------------------------------------*/
-
-#ifdef CT_VME 
-int DRS::CloseVME() {
-  
-  // Close VME connection
-  if ((ErrorCode = VME_Close()) != VME_SUCCESS) {
-    
-    VME_ErrorString(ErrorCode,ErrorString);
-    
-    printf("Error: %s\n",ErrorString);
-  }
-  
-  return ErrorCode;
-}
-#endif
-
-/*------------------------------------------------------------------*/
-
-#ifdef CT_VME 
-int DRS::OpenCMEM() {
-  
-  // Open CMEM package
-  if ((ErrorCode = CMEM_Open()) != CMEM_RCC_SUCCESS) {
-    
-    VME_ErrorString(ErrorCode,ErrorString);
-    
-    printf("Error: %s\n",ErrorString);
-  }
-  
-  return ErrorCode;
-}
-#endif
-
-/*------------------------------------------------------------------*/
-
-#ifdef CT_VME 
-int DRS::CloseCMEM() {
-  
-  // Close CMEM package
-  if ((ErrorCode = CMEM_Close()) != CMEM_RCC_SUCCESS) {
-    
-    VME_ErrorString(ErrorCode,ErrorString);
-    
-    printf("Error: %s\n",ErrorString);
-  }
-  
-  return ErrorCode;
-}
-#endif
 
 /*------------------------------------------------------------------*/
@@ -506,4 +396,12 @@
   ,fDAC_INOFS(0)
   ,fDAC_BIAS(0)
+  ,fBaseAddress(BaseAddress)
+#ifdef CT_VME
+  ,fBoardAddress(BoardAddress)
+  ,fMasterMapping(MasterMapping)
+#endif
+#ifdef STRUCK_VME
+  ,fVMEInterface(MVME_Interface)
+#endif
   ,fRequiredFirmwareVersion(0)
   ,fFirmwareVersion(0)
@@ -514,14 +412,5 @@
   ,fNumberOfReadoutChannels(0)
   ,fExternalClockFrequency(0)
-  ,fBaseAddress(BaseAddress)
-#ifdef CT_VME
-  ,fBoardAddress(BoardAddress)
-  ,fMasterMapping(MasterMapping)
   ,fSlotNumber(SlotNumber)
-#endif
-#ifdef STRUCK_VME
-  ,fVMEInterface(MVME_Interface)
-  ,fSlotNumber(SlotNumber)
-#endif
   ,fFrequency(0)
   ,fDominoMode(0)
@@ -941,5 +830,5 @@
     
     // Copy contiguous block of memory starting from VirtualAddress
-    memcpy((unsigned long*)((unsigned long)VirtualAddress),(unsigned long*)data,size);
+    memcpy((void *) VirtualAddress, data, size);
 
     // Assign fields for BLT
@@ -1003,30 +892,17 @@
 #ifdef CT_VME
 
-  if (size > MEM_SEGMENT)
-    size = MEM_SEGMENT;
-
-  if (type == T_CTRL)
-    addr += PMC_CTRL_OFFSET;
-  else if (type == T_STATUS)
-    addr += PMC_STATUS_OFFSET;
-  else if (type == T_RAM) {
-    addr += PMC_RAM_OFFSET;
-  }
-  else if (type == T_FIFO) {
-    addr += PMC_FIFO_OFFSET;
-  }
+  if (size > MEM_SEGMENT) size = MEM_SEGMENT;
+
+  if (type == T_CTRL) addr += PMC_CTRL_OFFSET;
+  else if (type == T_STATUS) addr += PMC_STATUS_OFFSET;
+  else if (type == T_RAM) addr += PMC_RAM_OFFSET;
+  else if (type == T_FIFO) addr += PMC_FIFO_OFFSET;
 
   if (size == 1) {
-    
     VME_ReadFastUChar(fMasterMapping, fBoardAddress + addr, static_cast<unsigned char*>(data)); 
-  
-  } else if (size == 2) {
-    
+  } else if (size == 2) {   
     VME_ReadFastUShort(fMasterMapping, fBoardAddress + addr, static_cast<unsigned short*>(data)); 
-    
   } else if (size == 4) {
-    
     VME_ReadFastUInt(fMasterMapping, fBoardAddress + addr, static_cast<unsigned int*>(data)); 
-
   } else {
 
@@ -1036,5 +912,4 @@
     BLT_List.list_of_items[0].size_requested       = MEM_SEGMENT; 
     BLT_List.list_of_items[0].control_word         = VME_DMA_D64R | VME_A32;
-   
     BLT_List.number_of_items = 1;
 
@@ -1046,17 +921,5 @@
     
     // Copy contiguous block of memory starting from VirtualAddress
-    memcpy((unsigned long*)data,(unsigned long*)((unsigned long)VirtualAddress),size);
-
-    // Do pseudo BLT
-    /*for (i = 0; i < size; i += 4) 
-      VME_ReadFastUInt(fMasterMapping, fBoardAddress + addr + i, (unsigned int*)((unsigned char*)data + i));
-    
-    // Decode data
-    printf("pseudo BLT: %d %d\n",((*((unsigned char*)data + 1) & 0x0f) << 8) | *((unsigned char*)data), 
-	                         ((*((unsigned char*)data + 2)) << 4) | ((*((unsigned char*)data + 1)) >> 4) );
-
-    printf("pseudo BLT: %d %d\n",((*((unsigned char*)data + 5) & 0x0f) << 8) | *((unsigned char*)data + 4), 
-	                         ((*((unsigned char*)data + 6)) << 4) | ((*((unsigned char*)data + 5)) >> 4) );
-    */
+    memcpy(data, (void *) VirtualAddress ,size);
   }
   return size;
@@ -1119,71 +982,4 @@
 }
 
-
-/*------------------------------------------------------------------*/
-
-#ifdef CT_VME 
-int DRSBoard::AllocateSegmentCMEM(unsigned int SegSize, int *CMEM_SegIdentifier) {
-  
-  if ((ErrorCode = CMEM_SegmentAllocate(SegSize, "DMA_BUFFER", CMEM_SegIdentifier)) != CMEM_RCC_SUCCESS) {
-    
-    VME_ErrorString(ErrorCode,ErrorString);
-    
-    printf("Error: %s\n",ErrorString);
-  }
-
-  return ErrorCode;
-}
-#endif
-
-/*------------------------------------------------------------------*/
-
-#ifdef CT_VME 
-int DRSBoard::AssignPhysicalSegAddressCMEM(int CMEM_SegIdentifier, unsigned long* PCIAddress) {
-  
-  if ((ErrorCode = CMEM_SegmentPhysicalAddress(CMEM_SegIdentifier, PCIAddress)) != CMEM_RCC_SUCCESS) {
-    
-    VME_ErrorString(ErrorCode,ErrorString);
-    
-    printf("Error: %s\n",ErrorString);
-
-  }
-
-  return ErrorCode;
-}
-#endif
-
-/*------------------------------------------------------------------*/
-
-#ifdef CT_VME 
-int DRSBoard::AssignVirtualSegAddressCMEM(int CMEM_SegIdentifier, unsigned long* VirtualAddress) {
-
-  if ((ErrorCode = CMEM_SegmentVirtualAddress(CMEM_SegIdentifier, VirtualAddress)) != CMEM_RCC_SUCCESS) {
-
-    VME_ErrorString(ErrorCode,ErrorString);
-    
-    printf("Error: %s\n",ErrorString);
-
-  }
-
-  return ErrorCode;
-}
-#endif
-
-/*------------------------------------------------------------------*/
-
-#ifdef CT_VME 
- int DRSBoard::FreeSegmentCMEM(int CMEM_SegIdentifier) {
-  
-  // Free memory segment
-  if ((ErrorCode = CMEM_SegmentFree(CMEM_SegIdentifier)) != CMEM_RCC_SUCCESS) {
-
-    VME_ErrorString(ErrorCode,ErrorString);
-    
-    printf("Error: %s\n",ErrorString);
-  }
-  
-  return ErrorCode;
- }
-#endif
 
 /*------------------------------------------------------------------*/
@@ -1926,51 +1722,4 @@
 }
 
-/*------------------------------------------------------------------*/ 
-
-int DRSBoard::TransferWaves(unsigned long *p, int numberOfChannels)
-{
-  return TransferWaves(p, 0, numberOfChannels-1);
-}
-
-/*------------------------------------------------------------------*/ 
-
-int DRSBoard::TransferWaves(unsigned long *p, int firstChannel, int lastChannel)
-{
-
-  // Transfer all waveforms at once
-  int i, n, offset, n_requested;
-  
-  if (lastChannel < 0 || lastChannel > kNumberOfChips*kNumberOfChannels) {
-    printf("Error: Invalid channel index %d\n", lastChannel);
-    return 0;
-  }
-  
-  if (firstChannel < 0 || firstChannel > kNumberOfChips*kNumberOfChannels) {
-    printf("Error: Invalid channel index %d\n", firstChannel);
-    return 0;
-  }
-  
-  firstChannel = 0;
-  lastChannel = kNumberOfChips*kNumberOfChannels - 1;
-  
-  
-  n_requested = (lastChannel - firstChannel + 1) * sizeof(short int) * kNumberOfBins;
-  offset = firstChannel * sizeof(short int) * kNumberOfBins;
-
-  n = Read(T_RAM, p, offset, n_requested);
-
-  if (n != n_requested) {
-    printf("Error: only %d bytes read\n", n);
-    return  n;
-  }
-      
-  // Remember which waveforms have been transferred
-  for (i = firstChannel; i <= lastChannel; i++)
-    fWaveTransferred[i] = true;
-    
-  //fNumberOfTransferredWaves = numberOfChannels;
-  return n;
-}
-
 /*------------------------------------------------------------------*/
 
@@ -2025,43 +1774,4 @@
 /*------------------------------------------------------------------*/
 
-int DRSBoard::DecodeWave(unsigned long *waveforms, unsigned int chipIndex, unsigned char channel, unsigned short *waveform) 
-{
-
-  // Get waveform
-  int i, offset, ind;
-  
-  // Check valid parameters 
-  if (channel > 9 || chipIndex > 1)
-    return kWrongChannelOrChip;
-  
-  // Re-map channel 
-  if (fBoardVersion == 1) {
-    if (channel < 8)
-      channel = 7 - channel;
-    else
-      channel = 16 - channel;
-  } else {
-    channel = channel;
-  } 
-  
-  offset = kNumberOfBins * channel;
-
-  for (i = 0; i < kNumberOfBins; i++) {
-  
-    ind = i + offset;
-
-    // Lower 12 bit
-    if (chipIndex == 0)
-      waveform[i] = (unsigned short)(waveforms[ind] & 0X00000FFF);
-    // Upper 12 bit
-    else 
-      waveform[i] = (unsigned short)(((unsigned long)(waveforms[ind] & 0X00FFF000)) >> 12);
-  }
-  
-  return kSuccess;
-}
-
-/*------------------------------------------------------------------*/
-
 int DRSBoard::GetWave(unsigned int chipIndex, unsigned char channel, short *waveform, bool responseCalib,
                       int triggerCell, bool adjustToClock, float threshold)
@@ -2176,20 +1886,4 @@
 /*------------------------------------------------------------------*/
 
-int DRSBoard::GetWave(unsigned long *waveforms, unsigned int chipIndex, unsigned char channel, short *waveform, bool responseCalib, 
-                      int triggerCell, bool adjustToClock, float threshold)
-{
-  if (!fWaveTransferred[chipIndex*kNumberOfChannels+channel])
-    return kWaveNotAvailable;
-  unsigned short adcWaveform[kNumberOfBins];
-  int ret = DecodeWave(waveforms, chipIndex, channel, adcWaveform);
-  if (ret!=kSuccess)
-    return ret;
-  
-  return CalibrateWaveform(chipIndex, channel, adcWaveform, waveform, responseCalib,
-			   triggerCell, adjustToClock, threshold);
-}
-
-/*------------------------------------------------------------------*/
-
 int DRSBoard::GetADCWave(unsigned int chipIndex, unsigned char channel, unsigned short *waveform)
 {
@@ -2200,11 +1894,4 @@
 
 int DRSBoard::GetADCWave(unsigned char *waveforms,unsigned int chipIndex, unsigned char channel, unsigned short *waveform)
-{
-  return DecodeWave(waveforms, chipIndex, channel, waveform);
-}
-
-/*------------------------------------------------------------------*/
-
-int DRSBoard::GetADCWave(unsigned long *waveforms,unsigned int chipIndex, unsigned char channel, unsigned short *waveform)
 {
   return DecodeWave(waveforms, chipIndex, channel, waveform);
@@ -2311,47 +1998,4 @@
   fTriggerCell = triggerCell;
   return triggerCell;
-}
-
-/*------------------------------------------------------------------*/
-
-
-int DRSBoard::GetTriggerCell(unsigned long *waveforms,unsigned int chipIndex)
-{
-
-  int j, triggerCell;
-  bool calib = 0;
-  unsigned short baseLevel = 1000;
-  unsigned short triggerChannel[1024];
-  if (!fWaveTransferred[chipIndex*kNumberOfChannels+8])
-    return -1;
-  
-  GetADCWave(waveforms,chipIndex, 8, triggerChannel);
-  //calib = fResponseCalibration->SubtractADCOffset(chipIndex, 8, triggerChannel, triggerChannel, baseLevel); // Changed 07/10/2008, SCC
-    
-  triggerCell = -1;
-  for (j = 0; j < kNumberOfBins; j++) {
-    if (calib) {
-
-      if (triggerChannel[j] <= baseLevel+200
-	  && triggerChannel[(j + 1) % kNumberOfBins] > baseLevel+200) {
-	triggerCell = j;
-	break;
-      }
-    } else {
-
-      if (triggerChannel[j] >= 2000
-	  && triggerChannel[(j + 1) % kNumberOfBins] < 2000) {
-	triggerCell = j;
-	break;
-      }
-    }
-  }
-  
-  if (triggerCell == -1) {
-    return kInvalidTriggerSignal;
-  }
-  fTriggerCell = triggerCell;
-  return triggerCell;
-
 }
 
@@ -4445,2 +4089,114 @@
 }
 
+
+
+
+//**************************************************************************************************
+//**
+//** All functions special to the Concurrent Technologies single-board computer are collected here
+//**
+//************************************************************************************************** 
+
+#ifdef CT_VME 
+
+// Open VME connection
+int DRS::OpenVME() {
+
+  if ((ErrorCode = VME_Open()) != VME_SUCCESS) {
+    VME_ErrorString(ErrorCode,ErrorString); 
+    printf("Error: %s\n",ErrorString);
+  }  
+  return ErrorCode;
+}
+
+// Do master mapping  
+int DRS::MasterMapVME(int *MMap) {
+
+  if (ErrorCode = VME_MasterMap(&MasterMap, MMap)) {
+    VME_ErrorString(ErrorCode,ErrorString); 
+    printf("Error: %s\n",ErrorString);
+  }
+  return(ErrorCode);
+}
+
+// Delete master mapping
+int DRS::MasterUnMapVME(int MMap) {
+
+  if (ErrorCode = VME_MasterUnmap(MMap)) {
+    VME_ErrorString(ErrorCode,ErrorString); 
+    printf("Error: %s\n",ErrorString);
+  }  
+  return(ErrorCode);  
+}
+
+// Close VME connection
+int DRS::CloseVME() {
+
+  if ((ErrorCode = VME_Close()) != VME_SUCCESS) {    
+    VME_ErrorString(ErrorCode,ErrorString);
+    printf("Error: %s\n",ErrorString);
+  }
+  return ErrorCode;
+}
+
+// Open CMEM package
+int DRS::OpenCMEM() {
+  
+  if ((ErrorCode = CMEM_Open()) != CMEM_RCC_SUCCESS) {
+    VME_ErrorString(ErrorCode,ErrorString); 
+    printf("Error: %s\n",ErrorString);
+  }
+  return ErrorCode;
+}
+
+// Close CMEM package
+int DRS::CloseCMEM() {
+
+  if ((ErrorCode = CMEM_Close()) != CMEM_RCC_SUCCESS) {  
+    VME_ErrorString(ErrorCode,ErrorString);
+    printf("Error: %s\n",ErrorString);
+  }
+  return ErrorCode;
+}
+
+int DRSBoard::AllocateSegmentCMEM(unsigned int SegSize, int *CMEM_SegIdentifier) {
+  
+  if ((ErrorCode = CMEM_SegmentAllocate(SegSize, "DMA_BUFFER", CMEM_SegIdentifier)) != CMEM_RCC_SUCCESS) {
+    VME_ErrorString(ErrorCode,ErrorString); 
+    printf("Error: %s\n",ErrorString);
+  }
+  return ErrorCode;
+}
+
+
+int DRSBoard::AssignPhysicalSegAddressCMEM(int CMEM_SegIdentifier, unsigned long* PCIAddress) {
+  
+  if ((ErrorCode = CMEM_SegmentPhysicalAddress(CMEM_SegIdentifier, PCIAddress)) != CMEM_RCC_SUCCESS) {
+    VME_ErrorString(ErrorCode,ErrorString);
+    printf("Error: %s\n",ErrorString);
+  }
+  return ErrorCode;
+}
+
+
+int DRSBoard::AssignVirtualSegAddressCMEM(int CMEM_SegIdentifier, unsigned long* VirtualAddress) {
+
+  if ((ErrorCode = CMEM_SegmentVirtualAddress(CMEM_SegIdentifier, VirtualAddress)) != CMEM_RCC_SUCCESS) {
+    VME_ErrorString(ErrorCode,ErrorString);
+    printf("Error: %s\n",ErrorString);
+  }
+  return ErrorCode;
+}
+
+// Free memory segment
+int DRSBoard::FreeSegmentCMEM(int CMEM_SegIdentifier) {
+
+  if ((ErrorCode = CMEM_SegmentFree(CMEM_SegIdentifier)) != CMEM_RCC_SUCCESS) {
+    VME_ErrorString(ErrorCode,ErrorString); 
+    printf("Error: %s\n",ErrorString);
+  }  
+  return ErrorCode;
+ }
+
+
+#endif
Index: drsdaq/DRS/DRS.h
===================================================================
--- drsdaq/DRS/DRS.h	(revision 114)
+++ drsdaq/DRS/DRS.h	(revision 132)
@@ -20,13 +20,13 @@
 // Concurrent Technologies VME single board computer
 #ifdef CT_VME 
-#include "rcc_error/rcc_error.h"   // Error reporting
-#include "vme_rcc/vme_rcc.h"       // VME access
-#include "cmem_rcc/cmem_rcc.h"     // Allocation of contiguous memory
-#include "rcc_time_stamp/tstamp.h" // Time stamp library
+  #include "rcc_error/rcc_error.h"   // Error reporting
+  #include "vme_rcc/vme_rcc.h"       // VME access
+  #include "cmem_rcc/cmem_rcc.h"     // Allocation of contiguous memory
+  #include "rcc_time_stamp/tstamp.h" // Time stamp library
 #endif
 
 // Struck VME interface
 #ifdef STRUCK_VME
-#include "mvmestd.h"
+  #include "mvmestd.h"
 #endif
 
@@ -321,5 +321,30 @@
   unsigned int         fDAC_INOFS;
   unsigned int         fDAC_BIAS;
- 
+   
+ private:
+#ifdef CT_VME 
+  VME_ErrorCode_t          ErrorCode;
+  VME_BlockTransferList_t  BLT_List;
+  char                 ErrorString[VME_MAXSTRING];
+  int                  CMEM_SegIdentifier; 
+  unsigned long        PCIAddress;        // Physical address of contiguous buffer
+  unsigned long        VirtualAddress;    // Virtual address of contiguous buffer  
+  unsigned int         fBaseAddress;
+  unsigned int         fBoardAddress;
+  int                  fMasterMapping;
+
+  unsigned int GetBaseAddress() const {return fBaseAddress; }
+  unsigned int GetBoardAddress() const {return fBoardAddress; }
+
+  int          AllocateSegmentCMEM(unsigned int SegSize, int *CMEM_SegIdentifier);
+  int          AssignPhysicalSegAddressCMEM(int CMEM_SegIdentifier, unsigned long* PCIAddress);
+  int          AssignVirtualSegAddressCMEM(int CMEM_SegIdentifier, unsigned long* VirtualAddress);
+  int          FreeSegmentCMEM(int CMEM_SegIdentifier);
+#endif
+#ifdef STRUCK_VME
+  mvme_addr_t          fBaseAddress;
+  MVME_INTERFACE      *fVMEInterface;
+#endif
+
  protected:
   // Fields for DRS
@@ -334,25 +359,4 @@
   double               fExternalClockFrequency;
 
-  // VME
-#ifdef CT_VME 
-  VME_ErrorCode_t          ErrorCode;
-  VME_BlockTransferList_t  BLT_List;
-  
-  char                 ErrorString[VME_MAXSTRING];
-  
-  int                  CMEM_SegIdentifier; 
-
-  unsigned long        PCIAddress;        // Physical address of contiguous buffer
-  unsigned long        VirtualAddress;    // Virtual address of contiguous buffer  
-
-  unsigned int         fBaseAddress;
-  unsigned int         fBoardAddress;
-  int                  fMasterMapping;
-#endif
-#ifdef STRUCK_VME
-  mvme_addr_t          fBaseAddress;
-  MVME_INTERFACE      *fVMEInterface;
-#endif
-
   int                  fSlotNumber;
   double               fFrequency;
@@ -361,12 +365,6 @@
   int                  fTriggerEnable;
   int                  fDelayedStart;
-  int                  fTriggerCell;
-  
-#ifdef STRUCK_VME
+  int                  fTriggerCell;  
   unsigned char        fWaveforms[kNumberOfChips * kNumberOfChannels * 2 * kNumberOfBins];
-#endif
-#ifdef CT_VME
-  unsigned long        fWaveforms[kNumberOfChannels * kNumberOfBins]; 
-#endif
   
   // Fields for Calibration
@@ -390,11 +388,6 @@
   int                  fTriggerStartBin; // Start bin of the trigger
   bool                 kRotateWave;
-  
- private:
-  DRSBoard(const DRSBoard &c);              // Not implemented
-  DRSBoard &operator=(const DRSBoard &rhs); // Not implemented
-  
- public:
-  
+
+ public: 
   ~DRSBoard();
   
@@ -408,19 +401,6 @@
   // VME
   int          GetSlotNumber() const { return fSlotNumber; }
-
-#ifdef CT_VME 
-  unsigned int GetBaseAddress() const {return fBaseAddress; }
-  unsigned int GetBoardAddress() const {return fBoardAddress; }
-#endif
-
   int          Read(int type, void *data, unsigned int addr, int size);
   int          Write(int type, unsigned int addr, void *data, int size);
-
-#ifdef CT_VME 
-  int          AllocateSegmentCMEM(unsigned int SegSize, int *CMEM_SegIdentifier);
-  int          AssignPhysicalSegAddressCMEM(int CMEM_SegIdentifier, unsigned long* PCIAddress);
-  int          AssignVirtualSegAddressCMEM(int CMEM_SegIdentifier, unsigned long* VirtualAddress);
-  int          FreeSegmentCMEM(int CMEM_SegIdentifier);
-#endif
 
   void         RegisterTest(void);
@@ -471,17 +451,10 @@
   int          TransferWaves(unsigned char *p, int numberOfChannels = kNumberOfChips * kNumberOfChannels);
   int          TransferWaves(unsigned char *p, int firstChannel, int lastChannel);
-  int          TransferWaves(unsigned long *p, int numberOfChannels = kNumberOfChips * kNumberOfChannels);
-  int          TransferWaves(unsigned long *p, int firstChannel, int lastChannel);
   int          TransferWaves(int firstChannel, int lastChannel);
 
   int          DecodeWave(unsigned char *waveforms, unsigned int chipIndex, unsigned char channel,
   			  unsigned short *waveform);
-  int          DecodeWave(unsigned long *waveforms, unsigned int chipIndex, unsigned char channel,
-			  unsigned short *waveform);
   int          DecodeWave(unsigned int chipIndex, unsigned char channel, unsigned short *waveform);
 
-  int          GetWave(unsigned long *waveforms, unsigned int chipIndex, unsigned char channel, short *waveform, 
-		       bool responseCalib = false, int triggerCell = -1, bool adjustToClock = false, 
-		       float threshold = 0);
   int          GetWave(unsigned char *waveforms, unsigned int chipIndex, unsigned char channel, short *waveform,
 		       bool responseCalib = false, int triggerCell = -1, bool adjustToClock = false,
@@ -497,6 +470,4 @@
   int          GetADCWave(unsigned char *waveforms,unsigned int chipIndex, unsigned char channel,
   		  unsigned short *waveform);
-  int          GetADCWave(unsigned long *waveforms,unsigned int chipIndex, unsigned char channel,
-  		  unsigned short *waveform);
   
   void         RotateWave(int triggerCell, short *waveform);  
@@ -507,5 +478,4 @@
   int          GetTriggerCell(unsigned int chipIndex);
   int          GetTriggerCell(unsigned char *waveforms,unsigned int chipIndex);
-  int          GetTriggerCell(unsigned long *waveforms,unsigned int chipIndex);
   int          GetTriggerCell(float *waveform);
 
@@ -538,19 +508,14 @@
   
  protected:
-  // Protected methods
   void         ConstructBoard();
   void         ReadSerialNumber();
   
-  
-  TimeData    *GetTimeCalibration(unsigned int chipIndex, bool reinit = false);
-  
+  TimeData    *GetTimeCalibration(unsigned int chipIndex, bool reinit = false);  
   int          GetStretchedTime(float *time, float *measurement, int numberOfMeasurements, float period);
   
  public:
-  
 #ifdef CT_VME 
   DRSBoard(int MasterMapping, unsigned int BaseAddress, unsigned int BoardAddress, int SlotNumber);
 #endif
-
 #ifdef STRUCK_VME
   DRSBoard(MVME_INTERFACE * MVME_Interface, mvme_addr_t BaseAddress, int SlotNumber);
@@ -575,32 +540,24 @@
   
   DRSBoard        *fBoard[kMaxNumberOfBoards];
+  int              fNumberOfBoards;
+  
+#ifdef STRUCK_VME
+  MVME_INTERFACE *fVMEInterface;
+#endif
+ 
+ private:
+  DRS(const DRS &c);              // Not implemented
+  DRS &operator=(const DRS &rhs); // Not implemented
   
 #ifdef CT_VME 
   VME_MasterMap_t  MasterMap;
   VME_ErrorCode_t  ErrorCode;
-  
   char             ErrorString[VME_MAXSTRING];
-  
   int              MasterMapping[kMaxNumberOfBoards];
-#endif
-
-  int              fNumberOfBoards;
-  
-#ifdef STRUCK_VME
-  MVME_INTERFACE *fVMEInterface;
-#endif
- 
-
- private:
-  DRS(const DRS &c);              // Not implemented
-  DRS &operator=(const DRS &rhs); // Not implemented
-  
-
-#ifdef CT_VME 
+
   int OpenVME();
   int MasterMapVME(int* MMap);
   int MasterUnMapVME(int MMap);
   int CloseVME();
-  
   int OpenCMEM();
   int CloseCMEM();
Index: drsdaq/RawDataCTX.cc
===================================================================
--- drsdaq/RawDataCTX.cc	(revision 114)
+++ drsdaq/RawDataCTX.cc	(revision 132)
@@ -161,5 +161,5 @@
     }
     else {
-      if ((Count++) == EventNo) break;
+      if ((++Count)==EventNo || EventNo==0) break;
       if (fseek(Rawfile, EHeader->EventSize, SEEK_CUR) != 0) SEEK_OK = false;
     }
