diff --git a/.gitignore b/.gitignore
index 65c88a70de268ea0101f7a9f13b7f79f278f6352..427f7e4aa81c62a8f12eb895dba503ac9601d876 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,6 +31,11 @@ Pcie40Applications/pcie40_dma
 Pcie40Applications/pcie40_b2linkreset
 Pcie40Applications/pcie40_daq
 Pcie40Applications/pcie40_ul
+Pcie40Applications/pcie40_readFPGAversion
+Pcie40Applications/pcie40_klmbytestream
+Pcie40Applications/pcie40_dma_check
+Pcie40Applications/pcie40_ulreset
+Pcie40Applications/pcie40_miniPod
 *.d
 **/pcie40_reload.out
 
diff --git a/Pcie40Applications/Makefile b/Pcie40Applications/Makefile
index 2d2eab26dd6644c34e73781306395666282ac54c..ee95ed5c34e361f2275290cbf83d2d3bd0bd9a76 100644
--- a/Pcie40Applications/Makefile
+++ b/Pcie40Applications/Makefile
@@ -5,7 +5,7 @@ include $(TOP)/flags.mk
 
 PCIE40_ECS :=pcie40_ecs
 PCIE40_ECS_OBJS =main_pcie40_ecs.o
-PCIE40_ECS_CFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40DriverLibraries
+PCIE40_ECS_CXXFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40DriverLibraries
 PCIE40_ECS_INSTALL =$(PREFIX)/bin
 PCIE40_ECS_LDFLAGS = -L../Pcie40Libraries/lib -lpcie40 -L../Pcie40DriverLibraries/ -lpcie40driver_ecs 
 
@@ -23,34 +23,83 @@ PCIE40_RELOAD_INSTALL =$(PREFIX)/bin
 
 PCIE40_SLC :=pcie40_b2slc
 PCIE40_SLC_OBJS =main_pcie40_b2slc.o
-PCIE40_SLC_CFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Libraries
+PCIE40_SLC_CXXFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Libraries
 PCIE40_SLC_INSTALL =$(PREFIX)/bin
 PCIE40_SLC_LDFLAGS = -L../Pcie40Libraries/lib -lpcie40 -L../Pcie40DriverLibraries/ -lpcie40driver_ecs
 
+# PCIE40_KLMBYTESTREAM :=pcie40_klmbytestream
+# PCIE40_KLMBYTESTREAM_OBJS =main_pcie40_klmbytestream.o
+# PCIE40_KLMBYTESTREAM_CFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Libraries
+# PCIE40_KLMBYTESTREAM_INSTALL =$(PREFIX)/bin
+# PCIE40_KLMBYTESTREAM_LDFLAGS = -L../Pcie40Libraries/lib -lpcie40 -L../Pcie40DriverLibraries/ -lpcie40driver_ecs
+
 PCIE40_B2LRESET :=pcie40_b2linkreset
 PCIE40_B2LRESET_OBJS =main_pcie40_b2linkreset.o
-PCIE40_B2LRESET_CFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Libraries
+PCIE40_B2LRESET_CXXFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Libraries
 PCIE40_B2LRESET_INSTALL =$(PREFIX)/bin
 PCIE40_B2LRESET_LDFLAGS = -L../Pcie40Libraries/lib -lpcie40 -L../Pcie40DriverLibraries/ -lpcie40driver_ecs
 
 PCIE40_DMA :=pcie40_dma
 PCIE40_DMA_OBJS =main_pcie40_dma.o
-PCIE40_DMA_CFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Driver
+PCIE40_DMA_CXXFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Driver
 PCIE40_DMA_INSTALL =$(PREFIX)/bin
 PCIE40_DMA_LDFLAGS = -L../Pcie40Libraries/lib -lpcie40 -L../Pcie40DriverLibraries/ -lpcie40driver_ecs
 
 PCIE40_DAQ :=pcie40_daq
 PCIE40_DAQ_OBJS =main_pcie40_daq.o
-PCIE40_DAQ_CFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Driver
+PCIE40_DAQ_CXXFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Driver
 PCIE40_DAQ_INSTALL =$(PREFIX)/bin
 PCIE40_DAQ_LDFLAGS = -L../Pcie40Libraries/lib -lpcie40 -L../Pcie40DriverLibraries/ -lpcie40driver_ecs
 
+#
+# Begin : Added by S. Yamada 
+# 
 PCIE40_UL :=pcie40_ul
 PCIE40_UL_OBJS =main_pcie40_ul.o
-PCIE40_UL_CFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Driver
+PCIE40_UL_CXXFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Driver
 PCIE40_UL_INSTALL =$(PREFIX)/bin
 PCIE40_UL_LDFLAGS = -L../Pcie40Libraries/lib -lpcie40 -L../Pcie40DriverLibraries/ -lpcie40driver_ecs
 
+PCIE40_SEND_UL :=pcie40_send_ul
+PCIE40_SEND_UL_OBJS =main_pcie40_send_ul.o
+PCIE40_SEND_UL_CXXFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Driver
+PCIE40_SEND_UL_INSTALL =$(PREFIX)/bin
+PCIE40_SEND_UL_LDFLAGS = -L../Pcie40Libraries/lib -lpcie40 -L../Pcie40DriverLibraries/ -lpcie40driver_ecs
+
+PCIE40_UL_LIB :=pcie40_ul_lib
+PCIE40_UL_LIB_OBJS =pcie40_ul_lib.o
+PCIE40_UL_LIB_CXXFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Driver
+PCIE40_UL_LIB_INSTALL =$(PREFIX)/bin
+PCIE40_UL_LIB_LDFLAGS = -L../Pcie40Libraries/lib -lpcie40 -L../Pcie40DriverLibraries/ -lpcie40driver_ecs
+
+PCIE40_DMA_CHECK :=pcie40_dma_check
+PCIE40_DMA_CHECK_OBJS =main_pcie40_dma_check.o
+PCIE40_DMA_CHECK_CXXFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Driver
+PCIE40_DMA_CHECK_INSTALL =$(PREFIX)/bin
+PCIE40_DMA_CHECK_LDFLAGS = -L../Pcie40Libraries/lib -lpcie40 -L../Pcie40DriverLibraries/ -lpcie40driver_ecs
+
+PCIE40_ULRESET :=pcie40_ulreset
+PCIE40_ULRESET_OBJS =main_pcie40_ulreset.o
+PCIE40_ULRESET_CXXFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Driver
+PCIE40_ULRESET_INSTALL =$(PREFIX)/bin
+PCIE40_ULRESET_LDFLAGS = -L../Pcie40Libraries/lib -lpcie40 -L../Pcie40DriverLibraries/ -lpcie40driver_ecs
+
+#
+# End : Added by S. Yamada 
+# 
+
+PCIE40_READFPGAVERSION :=pcie40_readFPGAversion
+PCIE40_READFPGAVERSION_OBJS =main_pcie40_readFPGAversion.o
+PCIE40_READFPGAVERSION_CXXFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Driver -I$(TOP)/../Pcie40DriverLibraries
+PCIE40_READFPGAVERSION_INSTALL =$(PREFIX)/bin
+PCIE40_READFPGAVERSION_LDFLAGS = -L../Pcie40Libraries/lib -lpcie40 -L../Pcie40DriverLibraries/ -lpcie40driver_ecs
+
+PCIE40_MINIPOD :=pcie40_miniPod
+PCIE40_MINIPOD_OBJS =main_pcie40_miniPod.o
+PCIE40_MINIPOD_CXXFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Driver -I$(TOP)/../Pcie40DriverLibraries -I$(TOP)/../Pcie40Libraries
+PCIE40_MINIPOD_INSTALL =$(PREFIX)/bin
+PCIE40_MINIPOD_LDFLAGS = -L../Pcie40Libraries/lib -lpcie40 -L../Pcie40DriverLibraries/ -lpcie40driver_ecs
+
 VPATH :=$(TOP)
 
 include $(TOP)/rules.mk
@@ -58,10 +107,17 @@ include $(TOP)/rules.mk
 ifeq ($(ENABLE_PCIE40), true)
 $(eval $(call ODIR_template,PCIE40_ECS))
 $(eval $(call ODIR_template,PCIE40_SLC))
+$(eval $(call ODIR_template,PCIE40_KLMBYTESTREAM))
 $(eval $(call ODIR_template,PCIE40_B2LRESET))
 $(eval $(call ODIR_template,PCIE40_DMA))
 $(eval $(call ODIR_template,PCIE40_DAQ))
 $(eval $(call ODIR_template,PCIE40_UL))
+$(eval $(call ODIR_template,PCIE40_SEND_UL))
+#$(eval $(call ODIR_template,PCIE40_UL_LIB))
+$(eval $(call ODIR_template,PCIE40_ULRESET))
+$(eval $(call ODIR_template,PCIE40_DMA_CHECK))
+$(eval $(call ODIR_template,PCIE40_READFPGAVERSION))
+$(eval $(call ODIR_template,PCIE40_MINIPOD))
 $(eval $(call COPY_template,SCRIPTS,755))
 $(eval $(call LINK_template,PCIE40_RELOAD))
 $(eval $(call ODIR_template,PCIE40_RELOAD_SUID))
diff --git a/Pcie40Applications/main_pcie40_b2linkreset.c b/Pcie40Applications/main_pcie40_b2linkreset.cpp
similarity index 67%
rename from Pcie40Applications/main_pcie40_b2linkreset.c
rename to Pcie40Applications/main_pcie40_b2linkreset.cpp
index b62574c9bd91621a36d63a7801e5f85114764812..c65c25ad1396935275a629ace5f28a1b8b143590 100644
--- a/Pcie40Applications/main_pcie40_b2linkreset.c
+++ b/Pcie40Applications/main_pcie40_b2linkreset.cpp
@@ -1,7 +1,9 @@
-#include "pcie40_ecs.h"
-#include "pcie40_b2ecs.h"
 #include <stdio.h>
 
+extern "C" int  ecs_open(int dev, int bar);
+extern "C" void ecs_close(int dev, int bar);
+extern "C" int pcie40_resyncb2link(int dev, int ch);
+
 int main(int argc, char *argv[]) { 
   ecs_open( 0 , 2 ) ;
   int result = 0;
diff --git a/Pcie40Applications/main_pcie40_b2slc.c b/Pcie40Applications/main_pcie40_b2slc.cpp
similarity index 54%
rename from Pcie40Applications/main_pcie40_b2slc.c
rename to Pcie40Applications/main_pcie40_b2slc.cpp
index 45d4978f611c92dc4694928f5e9d3859bff60410..3d8493afc8b35c590d67b79a9becdd144b1cc851 100644
--- a/Pcie40Applications/main_pcie40_b2slc.c
+++ b/Pcie40Applications/main_pcie40_b2slc.cpp
@@ -1,9 +1,13 @@
-#include "pcie40_ecs.h"
 #include "pcie40_b2slc.h"
 #include <stdio.h>
 
-int main(int argc, char *argv[]) { 
-  ecs_open( 0 , 2 ) ;
+extern "C" int  ecs_open(int dev, int bar);
+extern "C" void ecs_close(int dev, int bar);
+
+int main(int argc, char** argv){
+  
+
+  ecs_open( 0 , 2 );
 
   int result = pcie40_readfee32( 0 , 1 , 0x12 ) ;
   
@@ -13,3 +17,5 @@ int main(int argc, char *argv[]) {
 
   return 0 ;
 }
+
+
diff --git a/Pcie40Applications/main_pcie40_daq.c b/Pcie40Applications/main_pcie40_daq.cpp
similarity index 96%
rename from Pcie40Applications/main_pcie40_daq.c
rename to Pcie40Applications/main_pcie40_daq.cpp
index 3130ab23d187633a4bdbb7a9b6e45a188d0714af..d07ab6dd542ab348270ff517e4f81b3d5fad9a0a 100644
--- a/Pcie40Applications/main_pcie40_daq.c
+++ b/Pcie40Applications/main_pcie40_daq.cpp
@@ -4,6 +4,11 @@
 #include <time.h>
 #include "altera_dma_regs.h"
 
+extern "C" int  ecs_open(int dev, int bar);
+extern "C" void ecs_close(int dev, int bar);
+extern "C" int pcie40_b2dmabufferreset(int fd);
+extern "C" int pcie40_b2dmapointerread(int fd , unsigned int ** pData );
+
 //#define USE_UL
 
 const int CRC16_XMODEM_TABLE[] = {
@@ -200,7 +205,8 @@ int main (int argc ,char** argv) {
   retry = 0 ;
 
   int i ;
-  int size, size_256, currentEventIndex, crc, nErr, nEvt, nRetry ;
+  int size, size_256, crc, nErr, nEvt, nRetry ;
+  unsigned int currentEventIndex ;
   currentEventIndex = 0 ;
   nErr = 0 ;
   nEvt = 0 ;
@@ -252,9 +258,7 @@ int main (int argc ,char** argv) {
   clock_t end = clock();
   time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
 
-  res = ecs_close( 0 , 0 ) ;
-  if ( -1 == res ) printf("ERROR: Could not close device (BAR 0)\n");
-  else printf("SUCCESS: Device closed for DMA\n");
+  ecs_close( 0 , 0 ) ;
 
   printf( "Timing = %f s\n" , time_spent ) ;
   printf( "Number of events = %d \n", nEvt ) ;  
diff --git a/Pcie40Applications/main_pcie40_dma.c b/Pcie40Applications/main_pcie40_dma.cpp
similarity index 50%
rename from Pcie40Applications/main_pcie40_dma.c
rename to Pcie40Applications/main_pcie40_dma.cpp
index 094c80ff7a02e4fd617751818f84abdd3c8deb61..f47cc0b3b6d75f4a8b7e70fa52d9bf68c6180efd 100644
--- a/Pcie40Applications/main_pcie40_dma.c
+++ b/Pcie40Applications/main_pcie40_dma.cpp
@@ -3,6 +3,11 @@
 #include <unistd.h>
 #include "altera_dma_regs.h"
 
+extern "C" int  ecs_open(int dev, int bar);
+extern "C" void ecs_close(int dev, int bar);
+extern "C" int pcie40_b2dmabufferreset(int fd);
+extern "C" int pcie40_b2dmapointerread(int fd , unsigned int ** pData );
+
 int main (int argc ,char** argv) {
   int res = ecs_open( 0 , 0 ) ;
   if ( -1 == res ) printf("ERROR: Could not open device (BAR 0)\n") ;
@@ -12,19 +17,31 @@ int main (int argc ,char** argv) {
   else printf("SUCCESS: Device opened for ECS\n");
   // Read DMA
   res = pcie40_b2dmabufferreset( 0 ) ;
-  unsigned int * data ; 
+  //  unsigned int data[ DMASIZE ] = { 0 } ; 
+  unsigned int * data;
+  int cnt = 0;
+  while( 1 ){
+    printf("Reading... %d\n", cnt );
   res = pcie40_b2dmapointerread( 0 , &data ) ;
+
   int i = 0 ;
   if ( res == 0 ) printf( "DMA Error\n" ) ;
   else {
-    for (i= 0 ;i < DMASIZE;i++) printf("0X%08x\n",data[i]);
+    printf("00000000  " );
+    for (i= 0 ;i < DMASIZE;i++){
+      printf("%08x ",data[i]);
+      if( ( i % 8 ) == 7 ){
+	printf("\n");
+	printf("%.8x  ", i + 1);
+      }
+    }
   }
+  usleep(500000);
+  cnt++;
+  }
+
   // 
-  res = ecs_close( 0 , 0 ) ;
-  if ( -1 == res ) printf("ERROR: Could not close device (BAR 0)\n");
-  else printf("SUCCESS: Device closed for DMA\n");
-  res = ecs_close( 0 , 2 ) ;
-  if ( -1 == res ) printf("ERROR: Could not close device (BAR 2)\n");
-  else printf("SUCCESS: Device closed for ECS\n");
+  ecs_close( 0 , 0 ) ;
+  ecs_close( 0 , 2 ) ;
   return 0 ;
 }
diff --git a/Pcie40Applications/main_pcie40_dma_check.c b/Pcie40Applications/main_pcie40_dma_check.c
new file mode 100644
index 0000000000000000000000000000000000000000..88b6efaf92b18b92dd13e28493153803193bdbd9
--- /dev/null
+++ b/Pcie40Applications/main_pcie40_dma_check.c
@@ -0,0 +1,359 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <time.h>
+#include "altera_dma_regs.h"
+
+extern "C" int  ecs_open(int dev, int bar);
+extern "C" void ecs_close(int dev, int bar);
+extern "C" int      ecs_write(int dev, int bar, unsigned add, int val);
+extern "C" int pcie40_b2dmabufferreset(int fd);
+extern "C" int pcie40_b2dmapointerread(int fd , unsigned int ** pData );
+
+//#define DEBUG
+
+#define MY_DMASIZE 47104
+
+const int CRC16_XMODEM_TABLE[] = {
+  0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
+  0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
+  0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
+  0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
+  0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
+  0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
+  0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
+  0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
+  0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
+  0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
+  0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
+  0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
+  0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
+  0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
+  0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
+  0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
+  0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
+  0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
+  0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
+  0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
+  0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
+  0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
+  0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
+  0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
+  0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
+  0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
+  0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
+  0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
+  0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
+  0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
+  0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
+  0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
+} ;
+
+
+
+int crc_calc( int * crc, unsigned int * data ){ 
+  int byte1, byte2, byte3, byte4 ;
+  byte1 = (*data) & 0xFF;
+  byte2 = ( (*data) & 0xFF00 ) >> 8;
+  byte3 = ( (*data) & 0xFF0000 ) >> 16;
+  byte4 = ( (*data) & 0xFF000000 ) >> 24;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte4] ;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte3] ;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte2] ;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte1] ;
+}
+
+
+int crc_calc_event( unsigned int* data, int start_pos ){
+  int i = 0;
+  int cur_pos = start_pos;
+  int first_crc ;
+  int crc = 0xffff ;
+  int size = data[ cur_pos % MY_DMASIZE ];
+
+  int good_flag = 0;
+
+  if( size > 0xffff || size <= 0 ){
+    printf("Invalid total event size %.8x\n", size);
+    return -1;
+  }
+
+  /* printf( "TRL %.8x %.8x %.8x\n",  */
+  /* 	  data[ ( cur_pos + size - 1 + MY_DMASIZE ) % MY_DMASIZE ],  */
+  /* 	  data[ ( cur_pos + 1 + size ) % MY_DMASIZE ],  */
+  /* 	  data[ ( cur_pos + 2 + size ) % MY_DMASIZE ] );  */
+
+  cur_pos = start_pos + 4;
+  unsigned int ctime = data[ cur_pos % MY_DMASIZE ];
+
+  cur_pos = start_pos + 3;
+  unsigned int evenum = data[ cur_pos % MY_DMASIZE ];
+  cur_pos = start_pos + 5;
+  unsigned int utime = data[ cur_pos % MY_DMASIZE ];
+  cur_pos = start_pos + 2;
+  unsigned int exp_run = data[ cur_pos % MY_DMASIZE ] ;
+
+  int offset = 8; // size of ROB header [words]
+
+  int link_num = 0;
+
+
+  crc_calc( &crc, &ctime );
+  crc_calc( &crc, &evenum );
+  crc_calc( &crc, &utime );
+  crc_calc( &crc, &exp_run );
+  first_crc = crc ;
+
+  
+#ifdef DEBUG
+  printf("Start\n");
+  for( i = start_pos ; i < start_pos + size ; i++){
+    printf("%.8x\n", data[ i % MY_DMASIZE ] );
+  }
+  printf("End\n");
+#endif
+  int bad = 0;
+  
+  while( offset + 4 < size ){ // 4 = ROB trailer size
+    cur_pos = start_pos + offset;
+    int size_link = data[ cur_pos % MY_DMASIZE ] & 0x000ffff ;
+    if ( 0 >= size_link || size_link > 10000000 ){
+      printf("[ERROR] Invalid size per link (%.8x words): link num %d\n", size_link, link_num);
+      return -1 ; // it could be that the memory was read
+    } 
+
+    //
+    // Calculation of CRC
+    //
+    crc = first_crc ;
+#ifdef DEBUG
+    printf("%.8x %.8x crc %.8x\n", data[ ( start_pos + offset ) % MY_DMASIZE ], data[ ( start_pos + offset + 1 ) % MY_DMASIZE ], crc );
+#endif
+    for ( cur_pos = start_pos + offset + 2 ; cur_pos < start_pos + offset + size_link -2; ++cur_pos ) {
+      crc_calc( &crc, &data[ cur_pos % MY_DMASIZE ] );
+#ifdef DEBUG
+      printf("crc %.8x data %.8x\n", crc, data[ cur_pos % MY_DMASIZE ] );
+#endif
+    }
+#ifdef DEBUG
+    printf("%.8x %.8x\n", data[ ( cur_pos ) % MY_DMASIZE ], data[ ( cur_pos + 1 ) % MY_DMASIZE ]);
+#endif
+    //    cur_pos = start_pos +  8 + size_link -2;
+    cur_pos = start_pos + offset + size_link -2;
+#ifdef DEBUG
+    printf("calcd %.4x data %.4x\n", crc, data[ cur_pos % MY_DMASIZE ] & 0xffff );
+#endif
+
+    //
+    // Check of CRC
+    //
+    if( ( crc & 0xffff ) != ( data[ cur_pos % MY_DMASIZE ] & 0xffff ) ){
+      printf("%.2d Bad  ! calcd %.4x data %.4x offset %.4x size %.4x szlnk %.4x trl %.8x\n", 
+	     link_num, crc, data[ cur_pos % MY_DMASIZE ] & 0xffff, offset, size, size_link, data[ (cur_pos+1) % MY_DMASIZE ] );
+      bad = 1;
+
+    }else{
+      good_flag = 1;
+      /* printf("%.2d Good ! calcd %.4x data %.4x offset %.4x size %.4x szlnk %.4x trl %.8x\n",  */
+      /* 	     link_num, crc, data[ cur_pos % MY_DMASIZE ] & 0xffff, offset, size, size_link, data[ (cur_pos+1) % MY_DMASIZE ] ); */
+
+    }
+    link_num++;
+    offset += size_link;
+  }
+
+  if( bad ){
+    //  if( evenum > 50000 ){
+    //  if( 1 ){
+    for( i = 0 ; i < size ; i++){
+      printf("%.8x ", data[ ( start_pos  + i ) % MY_DMASIZE ] );
+      if( i % 8 == 7 ) printf("\n");
+    }
+    printf("\n");
+    good_flag = -2;
+  }
+  return good_flag;
+     
+}
+
+int main (int argc ,char** argv) {
+  // Stop trigger
+  /* system( "ssh robbep@vme \"resetft -53\"" ) ; */
+  /* sleep( 2 ) ;  */
+
+  int res = ecs_open( 0 , 0 ) ;
+  if ( -1 == res ) printf("ERROR: Could not open device (BAR 0)\n") ;
+  else printf("SUCCESS: Device opened for DMA\n");
+  res = ecs_open( 0 , 2 ) ;
+  // ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
+  ecs_write( 0 , 2 ,  0x000501A0 , 0x1 ) ;
+  pcie40_b2dmabufferreset( 0 ) ; 
+  // Start trigger
+  //  fp = popen( "ssh robbep@vme \"trigft -53 pulse 1000 -1\"" , "r" ) ;
+  // sleep( 2 ) ;
+  /* while( fgets( buf , sizeof(buf) , fp ) != NULL ) {  */
+  /*   // printf( "A= %d\n" , strncmp( exp , buf , 3 ) ) ; */
+  /*   //    printf( strncmp( &buf[0] , 'exp' , 1 ) ) ; */
+  /*   tmp = strdup( buf ) ; */
+  /*   if ( strncmp( exp , buf , 3 ) == 0 ) { */
+  /*     //printf( '%s\n' , buf )  ; */
+  /*     // printf( "ICI\n" ) ; */
+  /*     ptr = strtok( tmp , " " ) ; */
+  /*     ptr = strtok( NULL , " " ) ; */
+  /*     ptr = strtok( NULL , " " ) ; */
+  /*     ptr = strtok( NULL , " " ) ; */
+  /*     // while ( ptr != NULL ) { */
+  /*     run = atoi( ptr ) ;  */
+  /*     //	ptr = strtok( NULL , " " ) ;  */
+  /*   } */
+  /*     //} */
+  /* } */
+  /* pclose( fp ) ; */
+  //sleep( 2 ) ; 
+
+  int run  = 0 ; 
+  FILE* fp; 
+  char * ptr ;
+  char * tmp ;
+  char buf[1000] ;
+  char exp[] = "exp" ; 
+
+  unsigned int * data ; 
+  double time_spent ;
+  int retry ;
+  int bad ;
+  int evn ;
+  evn = 0  ;
+  bad = 0 ;
+  retry = 0 ;
+  int pctime, putime ; 
+  pctime = 0 ;
+  putime = 0 ;
+
+  int i, j, k;
+  int size, size_256, currentEventIndex, crc, nErr, nEvt, nRetry, nMissed ;
+  currentEventIndex = 0 ;
+  nErr = 0 ;
+  nEvt = 0 ;
+  nRetry = 0 ;
+  nMissed = 0 ;
+  int read_dma = 1 ; 
+  clock_t begin = clock() ;
+  int size_zero_cnt = 0;
+
+  int start_flag = 1;
+
+  int magic; 
+  int size_link;
+
+  int offset; 
+  unsigned int next_exp_run, cur_exp_run = 0, evenum, ctime, utime, first_eve = 0; 
+  int start_pos = 0;
+  int cnt = 0;
+  int eve_cnt = 0, first_event_flag = 0, crc_err_eve_cnt = 0;
+    
+    
+  int cur_pos = 0;
+  int ret = 0;
+  unsigned int cur_eve = 0, next_eve = 0;
+  int mod_pos = 0;
+  int prev_err_pos = -1;
+
+  unsigned int prev_0 = 0, prev_1 = 0;
+
+  //    if ( ( nEvt % 1000 == 1 ) && ( size != 0 ) ) printf( "Event number %d\n", nEvt ) ;
+
+  //
+  // Read the 1st data
+  //
+  if ( read_dma == 1 ) { 
+    // set busy
+    //res = ecs_write( 0 , 2 ,  0x000501A0 , 0x1 ) ;
+    //sleep(5);
+    res = pcie40_b2dmapointerread( 0 , &data ) ;
+    if ( start_flag == 1 ){
+      ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
+      start_flag = 0;
+    }
+    //usleep( 5 ) ;
+    // release busy
+    //res = ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
+    read_dma = 1 ;
+  } 
+
+  //
+  // Main loop
+  //
+
+  while( 1 ){
+
+	
+      //
+      // Refresh DMA memory
+      //
+      res = pcie40_b2dmapointerread( 0 , &data ) ;
+      int wait_flag = 0;
+      if( data[0] == prev_0 && data[1] == prev_1 ){
+	sleep(1);
+	continue;
+      }else{
+	prev_0 = data[ 0 ];
+	prev_1 = data[ 1 ];
+      }
+      
+      //
+      // Scan to find x"7f7f...."
+      //
+      int old_flag = 0;
+      for ( j = 0 ; j < MY_DMASIZE ; ++j ) { 
+	if ( ( data[ j ] & 0xffff0000 ) == 0xffaa0000 ){
+	  if ( ( data[ ( j + 1 ) % MY_DMASIZE ] & 0xffff0000 ) != 0x33330000){
+
+	    //
+	    // Ignore previous events
+	    //
+	    old_flag = 0;
+	    for ( k = 1 ; k < MY_DMASIZE ; ++k ) { 
+	      if ( ( data[ ( j + k ) % MY_DMASIZE ] & 0xffff0000 ) == 0xffaa0000 ){
+		if( (int)(( data[ ( j + k ) % MY_DMASIZE ] & 0x0000ffff ) - ( data[ j ] & 0x0000ffff )) < 0 && 
+		    (int)(( data[ ( j + k ) % MY_DMASIZE ] & 0x0000ffff ) - ( data[ j ] & 0x0000ffff )) > -10000 ){
+		  old_flag = 1;
+		  printf("next %.8x cur %.8x old %d\n",data[ ( j + k ) % MY_DMASIZE ] & 0x0000ffff, ( data[ j ] & 0x0000ffff ),old_flag);fflush(stdout);
+		}else{
+		  old_flag = 0;
+		  printf("next %.8x cur %.8x old %d\n",data[ ( j + k ) % MY_DMASIZE ] & 0x0000ffff, ( data[ j ] & 0x0000ffff ),old_flag);fflush(stdout);
+		}
+		break;
+	      }	      
+	    }
+
+	    printf("pos %.8x DIFF %d old %d\n", ( j + 1 ) % MY_DMASIZE, (int)( data[ ( j + k ) % MY_DMASIZE ] & 0x0000ffff ) - ( data[ j ] & 0x0000ffff ), old_flag);
+	    if(old_flag == 1) break;
+	    if( ( ( j + 1 ) % MY_DMASIZE ) == 0 ) break;
+
+	    printf("ERROR pos %.8x %.8x %.8x old %d\n", 
+		   ( j + 1 ) % MY_DMASIZE,
+		   data[ j ],
+		   data[ ( j + 1 ) % MY_DMASIZE ], old_flag		   );
+
+	    //
+	    // Hex dump
+	    // 
+	    for ( k = 0 ; k < MY_DMASIZE ; ++k ) { 
+		printf("%.8x ", data[ k % MY_DMASIZE ] );
+		if( k % 8 == 7 ){ 
+		  printf("\n");
+		  printf("pos  %.8x %.8x ", MY_DMASIZE , k);
+		}
+	    }
+	    printf("\n");
+	    prev_err_pos = ( j + 1 ) % MY_DMASIZE;
+	    break;
+	  }
+	}
+      }
+
+  }
+
+  return 0 ;
+}
diff --git a/Pcie40Applications/main_pcie40_ecs.c b/Pcie40Applications/main_pcie40_ecs.cpp
similarity index 99%
rename from Pcie40Applications/main_pcie40_ecs.c
rename to Pcie40Applications/main_pcie40_ecs.cpp
index 47f1c70df96d5817896fc87796c05b4bb9c68466..8f9e455ce0fe3ca08947f98c12b50cb9fafae7a4 100644
--- a/Pcie40Applications/main_pcie40_ecs.c
+++ b/Pcie40Applications/main_pcie40_ecs.cpp
@@ -110,7 +110,7 @@ int main(int argc, char *argv[])
     p40_ecs_w32(regs, flag_addroff, flag_writeval);
   } else if (flag_read) {
     uint32_t reg = p40_ecs_r32(regs, flag_addroff);
-    printf("0x%08x", reg);
+    printf("0x%08x\n", reg);
   }
   p40_ecs_close(ecs, regs, flag_barnum);
 
diff --git a/Pcie40Applications/main_pcie40_klmbytestream.c b/Pcie40Applications/main_pcie40_klmbytestream.c
new file mode 100644
index 0000000000000000000000000000000000000000..a7902b777ab3f82c9ce8d49602945176a69a85d1
--- /dev/null
+++ b/Pcie40Applications/main_pcie40_klmbytestream.c
@@ -0,0 +1,124 @@
+#include "pcie40_ecs.h"
+#include "pcie40_b2slc.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+typedef struct {
+  unsigned int chip_no;
+  unsigned int rpc_board;
+  __uint16_t thresh_values[48];
+}KLMFPGAconfig;
+
+typedef union {
+  char charval[2];
+  __uint16_t uint16val;
+}uint16toChar;
+
+int writeConfig(int fd, KLMFPGAconfig * config) {
+  const unsigned int lane_no = 8 + (*config).rpc_board;
+  const unsigned int chip_no = (*config).chip_no;
+
+  const __uint16_t sof = 0xF000; // start of frame pre-shifted
+  const __uint16_t eof = 0x0008;
+  const __uint16_t type_wr = 0x0200; // write command (1) pre-shifted
+  const __uint16_t type_ud = 0x0E00; // update command (7) pre-shifted
+  const size_t sof_eof_nbits = 4; // SOF/EOF bits
+  //    const size_t lane_nbits = 5; // lane bits
+  const size_t chip_nbits = 4; // channel bits
+  const size_t rc_pkt_size = 3; // 16-bit words
+
+  //    const unsigned int rpc_nbds = 13; // number of boards
+  //    const unsigned int rpc_nfpga = 2; // number of FPGAs
+  const unsigned int rpc_nchan = 48; // number of channels per FPGA
+  const unsigned int rpc_naddr = rpc_nchan / 16 + rpc_nchan; // number of addresses/FPGA
+
+  //    const size_t rpc_pkt_size = rpc_nbds * rpc_nfpga * rpc_naddr * rc_pkt_size; // total size
+  const unsigned int fpga_pkt_size = rpc_naddr * rc_pkt_size; // packet size per FPGA
+
+  const __uint16_t rpc_pulser[rpc_nchan / 16] = {0};
+  __uint16_t rpc_thresh[48] = {0} ;
+  //  const __uint16_t (&rpc_thresh)[48] = config.thresh_values;
+  int ii = 0 ;
+  for ( ii = 0 ; ii < 48 ; ++ii ) rpc_thresh[ ii ] = (*config).thresh_values[ ii ] ;
+
+  __uint16_t fpga_word[48*3] = {0};
+  __uint16_t data, temp;
+  unsigned int idx = 0;
+  unsigned int addr = 0 ;
+
+  for (addr = 0; addr < rpc_naddr; addr++) {
+    if (addr <= 47)
+      data = rpc_thresh[addr];
+    else
+      data = rpc_pulser[addr - 48];
+    temp = chip_no | (lane_no << chip_nbits);
+    if (addr == rpc_naddr - 1)
+      temp = temp | sof | type_ud;
+    else
+      temp = temp | sof | type_wr;
+    fpga_word[idx] = temp;
+    temp = (addr << 4) | (data >> 12);
+    fpga_word[idx + 1] = temp;
+    temp = (data << sof_eof_nbits) | eof;
+    fpga_word[idx + 2] = temp;
+    idx = idx + 3;
+  }
+
+  __uint16_t word;
+  uint16toChar uch;
+  const size_t fpga_pkt_n_bytes = 2 * fpga_pkt_size;
+  char stream_data[fpga_pkt_n_bytes];
+  size_t i = 0 ;
+  for (i = 0; i < fpga_pkt_size; i++) {
+    word = fpga_word[i];
+    uch.uint16val = word;
+    stream_data[2 * i] = uch.charval[1];
+    stream_data[2 * i + 1] = uch.charval[0];
+  }
+    
+  int ret = pcie40_writebytestream(0,fd,fpga_pkt_n_bytes,stream_data);
+  return ret;
+}
+
+int main(int argc, char *argv[]) { 
+  ecs_open( 0 , 2 ) ;
+
+  KLMFPGAconfig config;
+  unsigned int thresh = strtoul(argv[1],0,16);
+  size_t i = 0 ;
+  for (i = 0; i < 48; i++)
+    config.thresh_values[i] = thresh;
+  printf( "Setting threshold value %d for all channels.\n" , thresh );
+  int b = 0 ;
+  int c = 0 ;
+  int hslb_id = 0 ;
+  int try_no = 0 ;
+  int ret;
+
+  for(b=0;b<13;b++){
+    for( c=0;c<2;c++){
+      config.chip_no = c;
+      config.rpc_board = b;
+                     
+      // Stream the config through HSLBs    
+      for(hslb_id=0;hslb_id<4;hslb_id++){
+	for(try_no = 0; try_no < 3; try_no++){
+	  ret = writeConfig(hslb_id, &config);
+	  if(ret == 0)
+	    break;
+	}
+	if(ret)
+	  printf("Packet streaming failed for HSLB= %d, board= %d, chip= %d\n", hslb_id , b ,  c ) ;
+	else
+	  printf( "Packet streamed successfully for HSLB= %d, board = %d ,chip= %d\n" , hslb_id , b , c ) ;
+	usleep(500);
+      }
+    }
+  }
+
+  
+  ecs_close( 0 , 2 ) ;
+
+  return 0 ;
+}
diff --git a/Pcie40Applications/main_pcie40_miniPod.c b/Pcie40Applications/main_pcie40_miniPod.c
new file mode 100644
index 0000000000000000000000000000000000000000..52ceab990e5c7e3b2a28ba3c460a75d5aa16b4e8
--- /dev/null
+++ b/Pcie40Applications/main_pcie40_miniPod.c
@@ -0,0 +1,712 @@
+/**---------------------------------------------------------------------------------------------
+* \file				minipodCmd.c
+*
+* \brief This file contains the command interpreter to execute some commands on the
+Avago minipods of the AMC40.
+*
+* \details Command flags are 
+*   -d            vendor data read
+*   -t            internal temperatures read
+*   -p 33 or 25   the used power read
+*	 -o            the optical pave read
+*   -e            elapsed power on
+*   -v r or w     read or write VOD
+*   -d r or w     deamphasis read or write
+*   -q r or w     equalization read or write
+*   -n the target components which can be:
+*           x   a channel number
+*           tx  for all tx
+*           rx  for all rx
+*           all for all
+* 
+* output values are strings composed of pairs cahnnelNb=Value comma separated.
+*
+* \author PYD : Pierre-Yves Duval
+* \version 0.1
+* \date 18/06/2013
+* \copyright (c) Copyright CERN for the benefit of the LHCb Collaboration.
+*    Distributed under the terms of the GNU General Public Licence V3.
+*    ana.py script is free and open source software.
+*
+* CHANGELOG
+*    PYD : 18/06/2013 initial version
+*    PYD : 04/3/2014 add the script mode with raw printing
+*    PYD : 07/01/2016 adpated to PCIe40
+*-----------------------------------------------------------------------------------------------
+*/
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <getopt.h>
+
+#define MPOCPP 1 	
+#include <avagoMinipodCtrl.h>
+#include <i2cDriver.h>
+#include <systemConfig.h>
+
+#define DEBUG 0
+#define NONE 999
+
+#define VPRINT(a) if(interactiv) printf(a);
+#define DPRINT(a) if(debug) printf(a);
+#define STATUS_LINE printf("=======================================================================================\n")
+
+int interactiv = 1;
+int debug = DEBUG;
+
+enum targetsMp {ALLMP, ALLTX, ALLRX, SINGLEMP};
+enum targetsCh {ALLCH, SINGLECH};
+
+enum targetsMp currentMpTarget = ALLMP;
+
+int  currentBoard = 0;
+int  currentMinipod = NONE;
+int  currentChannel = NONE;
+
+enum commands {                         
+//					initSpeed, useless because init speed is executed at each program start
+//                                        getSpeed, can't work because library is reloaded
+					errorStatus,
+					dumpLos,
+					dumpFault,
+					dumpBiasCurrent,
+					dumpLightOutput,
+					doReset,
+					channelDisable,
+					channelEnable,
+					channelDump,
+					marginActivation,
+					marginDeactivation,
+					marginDump,
+					
+					fullStatus,
+					vendorData, 
+					squelchDisable, 
+					squelchEnable, 
+					squelchDump, 
+					internalTmp, 
+					vcc33, 
+					vcc25, 
+					dumpLightInput, 
+					pwOnElapsed, 
+					vodRd, 
+					vodWr, 
+					deamphasRd, 
+					deamphasWr, 
+					equalRd, 
+					equalWr,
+					channelPolarInvert,
+					channelPolarNormal,
+					channelPolarDump
+					};
+
+enum commands cmd = fullStatus;
+
+int      arrayParams[12] = {NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE};
+int      array2Params[2] = {NONE,NONE};
+int      singleParam = NONE;
+
+void printHelp(){
+	VPRINT("Usage : minipodCmd  ......  c'est la .....\n");
+	VPRINT("--------------------------COMMANDS--------------------------------\n");
+	VPRINT("--init-speed		   set i2c bus speed (inClock & SCL freq)(default 125000000 and 100000)\n");
+//	VPRINT("--get-speed		   sget the last set i2c bus speed (inClock & SCL freq)\n");
+	VPRINT("--full-status		print the full minipods status\n");
+	VPRINT("--temperature		print the internal temperature of minipods\n");
+	VPRINT("--vcc-3.3		print the 3.3 Vcc values of minipods\n");
+	VPRINT("--vcc-2.5		print the 2.5 Vcc values of minipods\n");
+	VPRINT("--error-status		print general erro status of minipods\n");
+	VPRINT("--los-status		print LOS loss of signal status channels\n");
+	VPRINT("--faults-status		print faults of TX minipods channels\n");
+	VPRINT("--bias-current		print bias current of TX minipods channels\n");
+	VPRINT("--light-output		print light output optical power of TX minipods channels\n");
+	VPRINT("--light-input		print light input optical power PAVE of RX minipods channels\n");
+	VPRINT("--reset			do minipods reset (parameters set to factory values)\n");
+	VPRINT("--channel-disable	disable minipods channels\n");
+	VPRINT("--channel-enable	enable minipods channels\n");
+	VPRINT("--channel-dump		print enable/disable status of minipods channels\n");
+	VPRINT("--squelch-disable	disable squelch of minipods channels\n");
+	VPRINT("--squelch-enable	enable squelch of minipods channels\n");
+	VPRINT("--squelch-dump		print squelch status of minipods channels\n");
+	VPRINT("--margin-activation	activate margin of TX minipods channels\n");
+	VPRINT("--margin-deactivation	deactivate margin of TX minipods channels\n");
+	VPRINT("--margin-dump		print margin activation status of minipods channels\n");
+	VPRINT("--vendor-info		print vendor informations of minipods\n");
+	VPRINT("--in-equal-read		read the input  equalization values of minipods channeles\n");
+	VPRINT("--in-equal-write	set values for the input equalization of minipods channels\n");
+	VPRINT("--out-amplitude-read	read the output amplitude VOD of RX minipods channels\n");
+	VPRINT("--out-amplitude-write	set values for the output amplitude VOD of RX minipods channels\n");
+	VPRINT("--out-deamphas-read	read the output deamphasis of RX minipods channels\n");
+	VPRINT("--out-deamphas-write	set values for the output deamphasis of RX minipods channels\n");
+	VPRINT("--polarity-invert	invert polarity of minipods channels\n");
+	VPRINT("--polarity-normal	normal plority for minipods channels\n");
+	VPRINT("--polarity-dump		print enable/disable status of minipods polarity inversion\n");
+	
+   VPRINT("-------------------WRITE VALUES SPECIFICATION----------------------\n");
+   VPRINT("--param-list (-l) values		parameter 12 comma separated values\n");
+   VPRINT("--param-pair (-d) values		parameter 2 comma separated values\n");
+   VPRINT("--param-val (-v)  value		parameter one single value\n");
+   VPRINT("-------------------TARGETS SPECIFICATION---------------------------\n");
+	VPRINT("BOARDS\n");
+   VPRINT("--board (-b)	the board number to deal with:\n");
+   VPRINT("CHANNELS\n");
+   VPRINT("--channel (-c)	the target components channel specifier which can be:\n");
+   VPRINT("\tx	a channel number ( x value is between O and 11)\n");
+   VPRINT("\tall	for all channels\n");
+   VPRINT("MINIPODS\n");
+   VPRINT("--module (-m)	the target minipod specifier which can be:\n");
+   VPRINT("\tx	a minipod number ( x value is between O and 7)\n");
+   VPRINT("\tall	for all minipods\n");   
+   VPRINT("Default is \"all\" but:\n");
+   VPRINT("when writing specify at least: one minipod OR one channel (write all minipods) OR both\n");
+   VPRINT("when reading specify:\n");
+   VPRINT("\tno target (all will be printed)\n");
+   VPRINT("\tone minipod (all minipods channels will be printed)\n");
+   VPRINT("\tone minipod and a channel\n");
+   VPRINT("--------------------------SERVICES--------------------------------\n");
+   VPRINT("-h     this help\n");
+   VPRINT("-i     interactiv mode, errors are printed\n");
+   VPRINT("-s     script mode, minimum raw data are printed\n");
+}
+/***********************************************/
+void dumpStatus() 
+{
+	printf("NOT YET IMPLEMENTED\n");
+}
+/***********************************************/
+int scan12values(char *chain, int *data){
+	if (sscanf(chain, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", 
+						    data,(data+1),(data+2),(data+3),(data+4),(data+5),
+						    (data+6),(data+7),(data+8),(data+9),(data+10),(data+11)) !=12){
+		printf("ERROR: parameter sting doesnt contain 12 comma separated values\n");
+		return(-1);
+		}
+	return(0);
+}
+int scan2values(char *chain, int *data){
+	if (sscanf(chain, "%d,%d", 
+						    data,(data+1)) !=2){
+		printf("ERROR: parameter sting doesnt contain 2 comma separated values\n");
+		return(-1);
+		}
+	return(0);
+}
+int scan1value(char *chain, int *data){
+	if (sscanf(chain, "%d", data) != 1){
+		printf("ERROR: parameter string doesnt contain 1 single value\n");
+		return(-1);
+		}
+	return(0);
+}
+/***********************************************************************************
+* function to print the general error status
+**************************************************************************************/
+void printErrorStatus(int dev){
+	switch (currentMpTarget) {
+     				case ALLMP:
+     							mpod_dumpErrStatusAll(dev);
+     							break;
+     				case SINGLEMP:
+     							mpod_dumpErrStatus(dev, currentMinipod);
+     							break;
+     				default: printf("ERROR: unknown target\n");
+     							exit(0);
+     			}
+	}
+/***********************************************************************************
+* function to print status with a dump function by minipod which return 6 values
+* It use two different function if its a global printing foa all minipods or
+* only one.
+* in : ptr to function to print for 1 minipod
+*      ptr to filtering function which minimod to print (should return 1 for selected)
+**************************************************************************************/
+void printMinipodInfo(int dev, int(*dumpAll)(int), int(*dump)(int, int, int*)){
+int val;
+
+        	switch (currentMpTarget) {
+     				case ALLMP:
+     							dumpAll(dev);
+     							break;
+     				case SINGLEMP:
+     							dump(dev, currentMinipod, &val);
+     							break;
+     				default: printf("ERROR: unknown target\n");
+     							exit(0);
+     				}  
+}     
+/****************************************************************************
+* function to print status with a dump function by minipod
+* in : ptr to function to print for 1 minipod
+*      ptr to filtering function which minimod to print (should return 1 for selected)
+*****************************************************************************/
+void printChannelInfo(int dev, int(*dump)(int,int), int(*filter)(int)){
+int i;
+ switch (currentMpTarget) {
+	case ALLMP:
+     	for (i=0; i<8; i++){
+     		if (filter!=NULL)
+     			if (!filter(i))
+     				continue;
+     		dump(dev,i);
+     		}
+     		break;
+   case SINGLEMP:
+     			dump(dev, currentMinipod);
+     		break;
+   default: printf("ERROR: unknown target\n");
+   exit(0);
+ }
+}
+/****************************************************************************
+* function to set bits in words for channel parameters stored in one bit
+* in : setbit : pointer to function to set the bit channel
+*      filter : ptr to filtering function which minimod to print (should return 1 for selected)
+*      bval   : the bit value to write 0/1
+*****************************************************************************/
+void setBitsChannel(int dev, int(*setBit)(int,int,int,int), int(*filter)(int), int bval){
+int minipod, channel;
+
+	switch (currentMpTarget) {
+     case ALLMP:
+    		for (minipod=0; minipod<8; minipod++){
+    			if (filter!=NULL)
+     				if (!filter(minipod))
+     					continue; 		
+    			if (currentChannel==NONE){
+    				for (channel=0; channel<12; channel++)
+    						setBit(dev, minipod, channel, bval);
+     			}
+     			else
+     						setBit(dev, minipod, currentChannel, bval);
+     		}
+     		break;
+     case SINGLEMP:
+     		if (currentChannel==NONE){
+     			for (channel=0; channel<12; channel++)
+    					setBit(dev, currentMinipod, channel, bval);
+     		}
+     		else
+     					setBit(dev, currentMinipod, currentChannel, bval);
+     		break;
+     default: printf("ERROR: unknown target\n");
+     		exit(0);
+   }
+}
+/****************************************************************************
+* function to print status with a dump function by minipod
+* in : dump  : ptr to function to print for 1 minipod
+*      filter: ptr to filtering function which minimod to print (should return 1 for selected)
+*****************************************************************************/
+void printfloatMSBLSB(int dev, int(*dump)(int, int,float**), int(*filter)(int)) {
+int    minipod;
+float	*bloc    = 0;
+
+switch (currentMpTarget) {
+   case ALLMP:
+      for (minipod=0; minipod<8; minipod++){
+    		if (filter!=NULL)
+     			if (!filter(minipod))
+     				continue;      	      
+     		dump(dev, minipod, &bloc); // prints on output
+     		free(bloc);
+     	}
+     	break;
+   case SINGLEMP:
+if (filter!=NULL)
+  if (!filter(currentMinipod)){
+						printf("ERROR: Minipod %d is a wrong command's target\n",currentMinipod);
+     					return;  
+         }
+     	dump(dev, currentMinipod, &bloc); // prints on output
+     	free(bloc);
+     	break;
+   default: printf("ERROR: unknown target\n");
+     	exit(0);
+   } 	
+}	
+
+/*****************************************************************************************
+* Function to read 12 channel values passed as a bloc of integers. Used for registers
+* organized in 6 word with values encode on 4 bits.
+* in : read     : ptr to function to read for 1 minipod
+*      readChan : ptr to function to read for 1 channel of 1 minipod
+*      filter   : 
+*****************************************************************************************/
+void read12Int(int dev, int(*read)(int,int,int**), int(*readChan)(int,int,int,int*), int(*filter)(int)) {
+int minipod, code;
+int *bloc = 0;//PYD
+
+ switch (currentMpTarget) {
+   case ALLMP:
+      for (minipod=0; minipod<8; minipod++){
+      	  	if (filter!=NULL)
+     				if (!filter(minipod))
+     					continue; 
+     			read(dev, minipod, &bloc); // prints on output all channels
+     			free(bloc);
+     	}
+   break;
+   case SINGLEMP: // one minipod
+     	if (filter!=NULL){
+     		if (!filter(currentMinipod)){
+						printf("ERROR: Minipod %d is a wrong command's target\n",currentMinipod);
+     					return;  
+         }
+      }
+     	if (currentChannel==NONE){
+     		read(dev, currentMinipod, &bloc); // prints on output all channels
+     		free(bloc);
+     	}
+     	else {
+     		readChan(dev, currentMinipod, currentChannel, &code); // print one channel
+     	}
+   break;
+   default: printf("ERROR: unknown target\n");
+     	exit(0);
+	} 
+}    
+/*****************************************************************************************
+* Function to write 12 channel values passed as a bloc of integers. Used for registers
+* organized in 8 word with values encode on 4 bits.
+* in : write     : ptr to function to write in 1 minipod channels
+*      writeChan : ptr to function to write in 1 channel of 1 minipod
+*      filter   : 
+*****************************************************************************************/
+void write12Int(int dev, int(*write)(int,int,int*), int(*writeChan)(int,int,int,int), int(*filter)(int)) {
+int minipod;
+
+ switch (currentMpTarget) {
+   case ALLMP:
+      for (minipod=0; minipod<8; minipod++){
+      	if (filter!=NULL)
+     				if (!filter(minipod))
+     					continue; 
+     		if (currentChannel==NONE){
+     				if (arrayParams[0]!=NONE)
+     						write(dev, minipod, arrayParams); // prints on output
+     				else
+     						printf("ERROR: you should specify the 12 values to write\n");
+     		}
+     		else {
+     			if (singleParam != NONE)
+     						writeChan(dev, minipod, currentChannel, singleParam); // prints on output
+     			else
+     						printf("ERROR: you should specify a value to write\n");
+     		}
+     	}//for
+     	break;
+   case SINGLEMP:
+      if (filter!=NULL)
+     		if (!filter(currentMinipod))
+     					break;    	
+     	if (currentChannel==NONE){
+     		if (arrayParams[0]!=NONE)
+     				write(dev, currentMinipod, arrayParams); // prints on output
+     		else
+     				printf("ERROR: you should specify the 12 values to write\n");
+     	}
+     	else {
+     		if (singleParam != NONE)
+     				writeChan(dev, currentMinipod, currentChannel, singleParam); // prints on output
+     		else
+     				printf("ERROR: you should specify a value to write\n");
+     	}
+     	break;
+    default: printf("ERROR: unknown target\n");
+     	exit(0);
+ } 
+}
+
+/***********************************************/
+int main (int argc, char **argv) {
+
+char * optstring = "m:c:l:d:v:b:fsh";
+struct option longopts[] = {
+		/* name            	has_arg  	flag                 val   */
+//		{ "init-speed",  		   0,		(int*)&cmd,		initSpeed },
+//		{ "get-speed",  		   0,		(int*)&cmd,		getSpeed },
+		{ "full-status",  		0,		(int*)&cmd,		fullStatus },
+		{ "error-status",  		0,		(int*)&cmd,		errorStatus },
+		{ "los-status",    		0,		(int*)&cmd,		dumpLos },	
+		{ "faults-status", 		0, 	(int*)&cmd,		dumpFault},
+		{ "bias-current", 		0, 	(int*)&cmd,		dumpBiasCurrent},
+		{ "temperature",			0,    (int*)&cmd, 	internalTmp},
+		{ "vcc-3.3",				0,    (int*)&cmd,  	vcc33},	
+		{ "vcc-2.5",				0,  	(int*)&cmd,  	vcc25},
+		{ "light-output",   		0,   	(int*)&cmd,		dumpLightOutput},
+		{ "elapsed",       		0,   	(int*)&cmd, 	pwOnElapsed},
+		{ "reset",					0,    (int*)&cmd, 	doReset},
+
+		{ "channel-disable",  	0,    (int*)&cmd,		channelDisable},
+		{ "channel-enable",   	0,    (int*)&cmd, 	channelEnable},
+		{ "channel-dump",    	0, 	(int*)&cmd, 	channelDump},
+
+		{ "squelch-disable",		0,  	(int*)&cmd,   squelchDisable},
+		{ "squelch-enable", 		0,  	(int*)&cmd,   squelchEnable},
+		{ "squelch-dump", 		0, 	(int*)&cmd,   squelchDump},
+
+		{ "margin-activation",  0,   	(int*)&cmd,  	marginActivation},
+		{ "margin-deactivation",0,  	(int*)&cmd,  	marginDeactivation},
+		{ "margin-dump",   		0, 	(int*)&cmd,  	marginDump},
+
+		{ "vendor-info",  		0,    (int*)&cmd,		vendorData},
+
+		{ "in-equal-read",		0, 	(int*)&cmd,		equalRd},
+		{ "in-equal-write",  	0, 	(int*)&cmd, 	equalWr},
+
+		{ "light-input",    	0, 	   (int*)&cmd, 	dumpLightInput},
+	
+		{ "out-amplitude-read", 0, 	(int*)&cmd,   vodRd},
+		{ "out-amplitude-write",0,		(int*)&cmd,   vodWr},
+		
+		{ "out-deamphas-read", 	0,		(int*)&cmd,   deamphasRd},
+		{ "out-deamphas-write", 0, 	(int*)&cmd,   deamphasWr},
+
+		{ "polarity-invert",  	0,    (int*)&cmd,		channelPolarInvert},
+		{ "polarity-normal",   	0,    (int*)&cmd, 	channelPolarNormal},
+		{ "polarity-dump",    	0, 	(int*)&cmd, 	channelPolarDump},
+
+		{ "module",     			1, 	NULL,   'm' },
+		{ "channel",    			1, 	NULL,   'c' },
+		{ "param-list", 			1, 	NULL,   'l' },
+		{ "param-val",  			1,  	NULL,   'v' },
+		{ "param-pair",  			1,  	NULL,   'd' },
+		{ "board",  			        1,  	NULL,   'b' },
+		/* Le dernier element doit etre nul */
+		{ NULL,    					0,	NULL,	0  },
+	};
+int	longindex;
+int	option;
+char *cvalue = NULL;
+int   i, minipod;	
+opterr = 1;
+ 
+// can only be scanned once
+  while ((option = getopt_long(argc, argv, optstring, longopts, & longindex)) != -1) {
+
+		switch (option) {
+			case 'm' :
+				 			DPRINT("m\n");
+             			cvalue = optarg;
+ 				 			if (strncmp(cvalue, "all", 3)==0){
+             			     DPRINT("all\n");
+             			     currentMpTarget = ALLMP;
+                     }
+                     else if(sscanf(cvalue, "%d", &i) != 0){ //It's an int.
+             	                if((i>=0) && (i<=7)){
+             		               currentMinipod = i;
+             		               currentMpTarget  = SINGLEMP;
+             	                }
+             	                else {
+             		                VPRINT("ERROR: Wrong minipod number [should be 0 to 5]\n");
+             		                printHelp();
+             		                exit(0);
+             	                }
+                     }
+                     else {
+             	             VPRINT("ERROR: Wrong target component specification\n");
+             	             printHelp();
+             	             exit(0);
+                     } 
+				break;
+			case 'b' :
+				DPRINT("b\n");
+                                cvalue = optarg;
+				if(sscanf(cvalue, "%d", &i) != 0){ //It's an int.
+             	                    if(i < MAX_DEV){
+             		                  currentBoard = i;
+                                          DPRINT("Current board changed\n");
+                                    }
+             	                    else {
+             		                  VPRINT("ERROR: impossible board number\n");
+             	                          printHelp();
+             	                          exit(0);
+             	                          }
+				}
+				break;
+			case 'c' :
+				 DPRINT("c\n");
+                                 cvalue = optarg;
+                                 if (strncmp(cvalue, "all", 3)==0) {
+             	                      DPRINT("all\n");
+                                 }
+                                 else if(sscanf(cvalue, "%d", &i) != 0){ //It's an int.
+             	                         if((i>=0) && (i<=11)){
+             		                        currentChannel = i;
+             	                         }
+             	                         else {
+             		                      VPRINT("ERROR: Wrong channel number [should be 0 to 11]\n");
+             		                      printHelp();
+             		                      exit(0);
+             	                         }
+                                }
+                                else {
+             	                      VPRINT("ERROR: Wrong target component specification\n");
+             	                      printHelp();
+             	                      exit(0);
+                                     }
+				break;
+			case 'l' :
+				 DPRINT("l\n");
+        		 //printf("parameters %s\n", optarg);
+		       if (scan12values(optarg, arrayParams) !=0)
+		       	exit(0);
+				break;
+			case 'd' :
+				 DPRINT("d\n");
+        		 //printf("parameters %s\n", optarg);
+		       if (scan2values(optarg, array2Params) !=0)
+		       	exit(0);
+				break;
+			case 'v' :
+				 DPRINT("v\n");
+        		 //printf("single parameter %s\n", optarg);
+		       if (scan1value(optarg, &singleParam) !=0)
+		       	exit(0);
+				break;
+			case 's':
+				mpod_setMode(1);
+				break;
+			case 'h':
+				printHelp();
+				return(0);
+				break;
+			case 0 :
+				break;
+			case '?' :
+				break;
+		}//switch
+  }//while
+  //set default value
+/* Remove because reinitialize the bus at each command */
+  if (mpod_init(currentBoard, 100000000, 100000))
+			exit(2);
+
+  switch (cmd) {
+      case errorStatus:
+      		printErrorStatus(currentBoard);
+      		break;
+		case dumpLos:
+			printChannelInfo(currentBoard, mpod_losDumpAll,NULL);
+			break;
+		case dumpFault:
+     		printChannelInfo(currentBoard, mpod_faultDumpAll,mpod_isTX);
+			break;
+		case dumpBiasCurrent:
+			printfloatMSBLSB(currentBoard, mpod_biasCurrent, mpod_isTX);
+			break;
+		case dumpLightOutput:
+			printfloatMSBLSB(currentBoard, mpod_lightOutput, mpod_isTX);
+			break;
+         case internalTmp: // validated OK
+         	printMinipodInfo(currentBoard, mpod_internalTempDumpAll, mpod_internalTemp);
+         	break;
+         case vcc33: // validated OK
+         	printMinipodInfo(currentBoard, mpod_internal33VccDumpAll, mpod_internal33Vcc);
+         	break;	
+         case vcc25: // validated OK
+         	printMinipodInfo(currentBoard, mpod_internal25VccDumpAll, mpod_internal25Vcc);
+         	break;       	
+         case dumpLightInput: // validated OK
+         	printfloatMSBLSB(currentBoard, mpod_lightInput, mpod_isRX);
+         	break;      	
+         case pwOnElapsed:
+         	printf("Not implemeneted because information is wrong in the chip\n");
+         	break;       
+     		case vendorData:
+     			printChannelInfo(currentBoard, mpod_dumpVendorData,NULL);
+             break;
+      	case fullStatus:
+     			 //dumpStatus();
+     			 printMinipodInfo(currentBoard, mpod_internalTempDumpAll, mpod_internalTemp);
+     			 printMinipodInfo(currentBoard, mpod_internal33VccDumpAll, mpod_internal33Vcc);
+     			 printMinipodInfo(currentBoard, mpod_internal25VccDumpAll, mpod_internal25Vcc);
+     			 printErrorStatus(currentBoard);
+     			 printChannelInfo(currentBoard, mpod_losDumpAll,NULL);
+     			 printChannelInfo(currentBoard, mpod_faultDumpAll,mpod_isTX);
+     			 printfloatMSBLSB(currentBoard, mpod_biasCurrent, mpod_isTX);
+     			 printfloatMSBLSB(currentBoard, mpod_lightOutput, mpod_isTX);
+             break;   
+			case doReset:
+             switch (currentMpTarget) {
+     				case ALLMP:
+      						for (minipod=0; minipod<8; minipod++)
+     									mpod_reset(currentBoard, minipod); 
+     							break;
+     				case SINGLEMP:
+     									mpod_reset(currentBoard, currentMinipod);
+     							break;
+     				default: printf("ERROR: unknown target\n");
+     							exit(0);
+     				}
+				break;
+				
+			case channelDisable:
+				setBitsChannel(currentBoard, mpod_channelDisable, NULL, 1);
+				break;
+			case channelEnable:
+				setBitsChannel(currentBoard, mpod_channelDisable, NULL, 0);
+				break;
+			case channelDump:
+				printChannelInfo(currentBoard, mpod_channelDisDumpAll,NULL);
+				break;
+
+			case channelPolarInvert:
+				setBitsChannel(currentBoard, mpod_polarityFlip, NULL, 1);
+				break;
+			case channelPolarNormal:
+				setBitsChannel(currentBoard, mpod_polarityFlip, NULL, 0);
+				break;
+			case channelPolarDump:
+				printChannelInfo(currentBoard, mpod_channelPolarFlipDumpAll,NULL);
+				break;
+			
+			case marginActivation:
+				setBitsChannel(currentBoard, mpod_marginActivation, mpod_isTX, 1);
+				break;
+			case marginDeactivation:
+				setBitsChannel(currentBoard, mpod_marginActivation, mpod_isTX, 0);
+				break;
+			case marginDump:
+				printChannelInfo(currentBoard, mpod_marginActDumpAll,mpod_isTX);
+				break;
+							
+         case squelchDisable: 
+         	setBitsChannel(currentBoard, mpod_squelchDisable, NULL, 1);
+         	break;       	
+         case squelchEnable: 
+         	setBitsChannel(currentBoard, mpod_squelchDisable, NULL, 0);
+         	break;
+         case squelchDump: 
+         	printChannelInfo(currentBoard, mpod_squelchDumpAll,NULL);
+         	break;     
+         	    	
+         case vodRd:
+         	read12Int(currentBoard, mpod_readVOD, mpod_readVODSingle, mpod_isRX);
+         	break;
+         case vodWr:
+         	write12Int(currentBoard, mpod_writeVOD, mpod_writeVODSingle, mpod_isRX); 
+         	break;	
+         	
+         case deamphasRd:
+            read12Int(currentBoard, mpod_readDeamphasis, mpod_readDeamphasisSingle, mpod_isRX);
+         	break;         	
+         case deamphasWr:
+         	write12Int(currentBoard, mpod_writeDeamphasis, mpod_writeDeamphasisSingle, mpod_isRX);
+         	break;
+         	
+        case equalRd:
+            read12Int(currentBoard, mpod_readEqualization, mpod_readEqualizationSingle, mpod_isTX);
+         	break;   	
+         case equalWr:
+         	write12Int(currentBoard, mpod_writeEqualization, mpod_writeEqualizationSingle, mpod_isTX);       	
+         	break;	
+          default:
+          	printf("Should never happen the command requested is unknown\n");
+            exit(0);
+      	} // switch   
+      	
+     return(0);
+}
diff --git a/Pcie40Applications/main_pcie40_readFPGAversion.cpp b/Pcie40Applications/main_pcie40_readFPGAversion.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..bd0a146a267ab05fb996fb1fb9697acd7b1c224c
--- /dev/null
+++ b/Pcie40Applications/main_pcie40_readFPGAversion.cpp
@@ -0,0 +1,43 @@
+/****************************************************************************************//**
+* \file				readFPGAMemoire.c
+*
+*  lecture de la memore du FPGA 
+*  la taille est de x octets
+* l'adresse de depart de lecture vaut 0
+*//********************************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+
+extern "C" int ecs_openLli(int dev);
+extern "C" int  ecs_iordLli(int dev, unsigned add, unsigned *val);
+extern "C" void ecs_closeLli(int dev); 
+
+#define SIZE_MEMO_FPGA 1024   /* taille  max de la memoire interne FPG */
+
+int main(int argc, char *argv[]){
+	int board = 0;
+        int i;
+	unsigned val;
+	int reg = 0;
+        char contenuMemoireFPGA[SIZE_MEMO_FPGA + 1];
+
+	ecs_openLli(board);
+	for(i=0; i < SIZE_MEMO_FPGA; i++)
+        {
+	   if (ecs_iordLli(board, reg, &val)!=0)
+             {
+		 printf("LLI bar2 Read fails at 0x%08x\n", reg);
+		 exit(0);
+             }
+
+           contenuMemoireFPGA[i] = val;
+	   reg += 4;
+           
+	}
+        contenuMemoireFPGA[SIZE_MEMO_FPGA+1] = '\0';
+ 	printf("contenu memoire FPGA   %s\n",contenuMemoireFPGA);		
+	ecs_closeLli(board);
+	return 0;
+}
+
diff --git a/Pcie40Applications/main_pcie40_send_ul.cpp b/Pcie40Applications/main_pcie40_send_ul.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6c68ed670879683be6eabe161c6d47b2caab3554
--- /dev/null
+++ b/Pcie40Applications/main_pcie40_send_ul.cpp
@@ -0,0 +1,629 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <time.h>
+#include "altera_dma_regs.h"
+#include <errno.h>
+#include <string.h>
+
+// socket programming
+#include <netdb.h>
+#include <netinet/tcp.h>
+#include <sys/mman.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <csignal>
+
+
+
+#define SENDBUF_WORDS 10000
+#define LOCAL_HOSTNAME "b3ropc02"
+#define LISTEN_PORT 30001
+
+
+extern "C" int  ecs_open(int dev, int bar);
+extern "C" void ecs_close(int dev, int bar);
+extern "C" int pcie40_b2dmabufferreset(int fd);
+extern "C" int pcie40_b2dmapointerread(int fd , unsigned int ** pData );
+extern "C" int      ecs_write(int dev, int bar, unsigned add, int val);
+
+//#define DEBUG
+
+const int CRC16_XMODEM_TABLE[] = {
+  0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
+  0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
+  0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
+  0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
+  0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
+  0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
+  0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
+  0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
+  0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
+  0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
+  0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
+  0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
+  0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
+  0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
+  0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
+  0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
+  0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
+  0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
+  0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
+  0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
+  0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
+  0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
+  0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
+  0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
+  0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
+  0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
+  0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
+  0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
+  0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
+  0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
+  0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
+  0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
+} ;
+
+
+int Accept()
+{
+  //
+  // Connect to cprtb01
+  //
+  struct hostent* host;
+  host = gethostbyname( LOCAL_HOSTNAME );
+  if (host == NULL) {
+    printf("[FATAL] hostname(%s) cannot be resolved(%s). Check /etc/hosts. Exiting...\n",
+            LOCAL_HOSTNAME, strerror(errno));
+    fflush(stdout);
+    exit(1);
+  }
+
+  //
+  // Bind and listen
+  //
+  int fd_listen;
+  struct sockaddr_in sock_listen;
+  sock_listen.sin_family = AF_INET;
+  sock_listen.sin_addr.s_addr = *(unsigned int*)host->h_addr_list[0];
+
+  socklen_t addrlen = sizeof(sock_listen);
+  sock_listen.sin_port = htons( LISTEN_PORT );
+  fd_listen = socket(PF_INET, SOCK_STREAM, 0);
+
+  int flags = 1;
+  int ret = setsockopt(fd_listen, SOL_SOCKET, SO_REUSEADDR, &flags, (socklen_t)sizeof(flags));
+  if (ret < 0) {
+    perror("Failed to set REUSEADDR");
+  }
+
+  if (bind(fd_listen, (struct sockaddr*)&sock_listen, sizeof(struct sockaddr)) < 0) {
+    printf("[FATAL] Failed to bind. Maybe other programs have already occupied this port(%d). Exiting...\n",
+           LISTEN_PORT ); fflush(stdout);
+    // Check the process occupying the port 30000.
+    FILE* fp;
+    char buf[256];
+    char cmdline[500];
+    sprintf(cmdline, "/usr/sbin/ss -ap | grep %d", LISTEN_PORT);
+    if ((fp = popen(cmdline, "r")) == NULL) {
+      printf("[WARNING] Failed to run %s\n", cmdline);
+    }
+    while (fgets(buf, 256, fp) != NULL) {
+      printf("[ERROR] Failed to bind. output of ss(port %d) : %s\n", LISTEN_PORT, buf); fflush(stdout);
+    }
+    // Error message
+    fclose(fp);
+    printf("[FATAL] Failed to bind.(%s) Maybe other programs have already occupied this port(%d). Exiting...",
+            strerror(errno), LISTEN_PORT);
+    fflush(stdout);
+    exit(1);
+  }
+
+  int val1 = 0;
+  setsockopt(fd_listen, IPPROTO_TCP, TCP_NODELAY, &val1, (socklen_t)sizeof(val1));
+  int backlog = 1;
+  if (listen(fd_listen, backlog) < 0) {
+    char err_buf[500];
+    printf("Failed in listen(%s). Exting...", strerror(errno));
+    fflush(stdout);
+    exit(1);
+  }
+
+  //
+  // Accept
+  //
+  int fd_accept;
+  struct sockaddr_in sock_accept;
+  printf("[DEBUG] Accepting... : port %d server %s\n", LISTEN_PORT, LOCAL_HOSTNAME );
+  fflush(stdout);
+
+  if ((fd_accept = accept(fd_listen, (struct sockaddr*) & (sock_accept), &addrlen)) == 0) {
+    char err_buf[500];
+    printf( "[FATAL] Failed to accept(%s). Exiting...", strerror(errno));
+    fflush(stdout);
+    exit(-1);
+  } else {
+    //    B2INFO("Done.");
+    printf("[DEBUG] Done.\n"); fflush(stdout);
+
+    //    set timepout option
+    struct timeval timeout;
+    timeout.tv_sec = 1;
+    timeout.tv_usec = 0;
+    ret = setsockopt(fd_accept, SOL_SOCKET, SO_SNDTIMEO, &timeout, (socklen_t)sizeof(timeout));
+    if (ret < 0) {
+      printf( "[FATAL] Failed to set TIMEOUT. Exiting..." ); 
+      fflush(stdout);
+      exit(-1);
+    }
+  }
+
+  close(fd_listen);
+  return fd_accept;
+
+}
+
+
+
+int crc_calc( int * crc, unsigned int * data ){ 
+  int byte1, byte2, byte3, byte4 ;
+  byte1 = (*data) & 0xFF;
+  byte2 = ( (*data) & 0xFF00 ) >> 8;
+  byte3 = ( (*data) & 0xFF0000 ) >> 16;
+  byte4 = ( (*data) & 0xFF000000 ) >> 24;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte4] ;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte3] ;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte2] ;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte1] ;
+}
+
+
+int crc_calc_event( unsigned int* data, int start_pos ){
+  int i = 0;
+  int cur_pos = start_pos;
+  int first_crc ;
+  int crc = 0xffff ;
+  int size = data[ cur_pos % DMASIZE ];
+
+  int good_flag = 0;
+
+  if( size > 0xffff || size <= 0 ){
+    printf("Invalid total event size %.8x\n", size);
+    return -1;
+  }
+
+  /* printf( "TRL %.8x %.8x %.8x\n",  */
+  /* 	  data[ ( cur_pos + size - 1 + DMASIZE ) % DMASIZE ],  */
+  /* 	  data[ ( cur_pos + 1 + size ) % DMASIZE ],  */
+  /* 	  data[ ( cur_pos + 2 + size ) % DMASIZE ] );  */
+
+  cur_pos = start_pos + 4;
+  unsigned int ctime = data[ cur_pos % DMASIZE ];
+
+  cur_pos = start_pos + 3;
+  unsigned int evenum = data[ cur_pos % DMASIZE ];
+  cur_pos = start_pos + 5;
+  unsigned int utime = data[ cur_pos % DMASIZE ];
+  cur_pos = start_pos + 2;
+  unsigned int exp_run = data[ cur_pos % DMASIZE ] ;
+
+  int offset = 8; // size of ROB header [words]
+
+  int link_num = 0;
+
+
+  crc_calc( &crc, &ctime );
+  crc_calc( &crc, &evenum );
+  crc_calc( &crc, &utime );
+  crc_calc( &crc, &exp_run );
+  first_crc = crc ;
+
+  
+#ifdef DEBUG
+  printf("Start\n");
+  for( i = start_pos ; i < start_pos + size ; i++){
+    printf("%.8x\n", data[ i % DMASIZE ] );
+  }
+  printf("End\n");
+#endif
+  int bad = 0;
+  //  printf("good flag %d\n", good_flag); fflush(stdout);
+  
+  while( offset + 4 < size ){ // 4 = ROB trailer size
+    cur_pos = start_pos + offset;
+    int size_link = data[ cur_pos % DMASIZE ] & 0x000ffff ;    if ( 0 >= size_link || size_link > 10000000 ){
+      printf("[ERROR] Invalid size per link (%.8x words): link num %d\n", size_link, link_num);
+      return -1 ; // it could be that the memory was read
+    } 
+
+    //
+    // Calculation of CRC
+    //
+    crc = first_crc ;
+#ifdef DEBUG
+    printf("%.8x %.8x crc %.8x\n", data[ ( start_pos + offset ) % DMASIZE ], data[ ( start_pos + offset + 1 ) % DMASIZE ], crc );
+#endif
+    for ( cur_pos = start_pos + offset + 2 ; cur_pos < start_pos + offset + size_link -2; ++cur_pos ) {
+      crc_calc( &crc, &data[ cur_pos % DMASIZE ] );
+#ifdef DEBUG
+      printf("crc %.8x data %.8x\n", crc, data[ cur_pos % DMASIZE ] );
+#endif
+    }
+#ifdef DEBUG
+    printf("%.8x %.8x\n", data[ ( cur_pos ) % DMASIZE ], data[ ( cur_pos + 1 ) % DMASIZE ]);
+#endif
+    //    cur_pos = start_pos +  8 + size_link -2;
+    cur_pos = start_pos + offset + size_link -2;
+#ifdef DEBUG
+    printf("calcd %.4x data %.4x\n", crc, data[ cur_pos % DMASIZE ] & 0xffff );
+#endif
+
+    //
+    // Check of CRC
+    //
+    if( ( crc & 0xffff ) != ( data[ cur_pos % DMASIZE ] & 0xffff ) ){
+      printf("%.2d Bad  ! calcd %.4x data %.4x offset %.4x size %.4x szlnk %.4x trl %.8x\n", 
+	     link_num, crc, data[ cur_pos % DMASIZE ] & 0xffff, offset, size, size_link, data[ (cur_pos+1) % DMASIZE ] );
+      bad = 1;
+
+    }else{
+      good_flag = 1;
+      // printf("%.2d Good ! calcd %.4x data %.4x offset %.4x size %.4x szlnk %.4x trl %.8x\n", link_num, crc, data[ cur_pos % DMASIZE ] & 0xffff, offset, size, size_link, data[ (cur_pos+1) % DMASIZE ] );
+      
+      
+
+    }
+    link_num++;
+    offset += size_link;
+  }
+
+
+  if( bad ){
+  //  if( evenum > 50000 ){
+    //  if( 1 ){
+    for( i = 0 ; i < size ; i++){
+      printf("%.8x ", data[ ( start_pos  + i ) % DMASIZE ] );
+      if( i % 8 == 7 ) printf("\n");
+    }
+    printf("\n");
+    good_flag = -2;
+  }
+  return good_flag;
+     
+}
+
+  int decode_data_wUL( unsigned int * data , unsigned int * ce , int * crc , int * run , 
+		       int * bad , int *evn , int * retry , int * pctime , int * putime , 
+		       int * nmissed ) { 
+
+    int magic; 
+    int size, size_link;
+    int ix ;
+
+    int offset; 
+    unsigned int exp_run, evenum, ctime, utime; 
+    int start_pos = *ce;
+    int cnt = 0;
+    int cur_pos = *ce + 1;
+    int ret = 0;
+    
+    while( !( ( ( magic = data[ cur_pos % DMASIZE ] ) & 0xffff0000 ) != 0x7f7f0000 ) ){
+      usleep(1000);
+      cnt++;
+      //
+      // Scan to find x"7f7f...."
+      //
+      if( cnt > 10 ){
+	cnt = 0;
+	int j = 0 ; 
+	for ( j = 0 ; j < DMASIZE ; ++j ) { 
+	  if ( ( ( data[ ( cur_pos + j ) % DMASIZE ] & 0xffff0000 ) == 0x7f7f0000 ) ){
+	    evenum = data[ ( cur_pos + j + 2 ) % DMASIZE ];
+	    if( evenum > *evn ){
+	      *evn = evenum;
+	      cur_pos = ( cur_pos + j - 1 + DMASIZE ) % DMASIZE;
+	      size = data[ cur_pos ] ;
+	      *ce = ( cur_pos + size ) % DMASIZE;
+	      printf( "New Event number prev %d new %d pos %d size %d\n" , *evn ,  evenum, cur_pos, size );
+	      crc_calc_event( data, cur_pos );
+
+	    }else{
+	      printf( "Old Event number prev %d new %d pos %d\n" , *evn ,  evenum, ( cur_pos + j - 1 + DMASIZE ) % DMASIZE );
+	      break;
+	    }
+	  }else{
+	    continue;
+	  }
+	}
+      }
+    }
+
+    return size ;
+  }
+
+  int main (int argc ,char** argv) {
+
+
+    int send_buf[SENDBUF_WORDS];
+    // Stop trigger
+    /* system( "ssh robbep@vme \"resetft -53\"" ) ; */
+    /* sleep( 2 ) ;  */
+
+    int res = ecs_open( 0 , 0 ) ;
+    if ( -1 == res ) printf("ERROR: Could not open device (BAR 0)\n") ;
+    else printf("SUCCESS: Device opened for DMA\n");
+    res = ecs_open( 0 , 2 ) ;
+    // ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
+    ecs_write( 0 , 2 ,  0x000501A0 , 0x1 ) ;
+    pcie40_b2dmabufferreset( 0 ) ; 
+    // Start trigger
+    //  fp = popen( "ssh robbep@vme \"trigft -53 pulse 1000 -1\"" , "r" ) ;
+    // sleep( 2 ) ;
+    /* while( fgets( buf , sizeof(buf) , fp ) != NULL ) {  */
+    /*   // printf( "A= %d\n" , strncmp( exp , buf , 3 ) ) ; */
+    /*   //    printf( strncmp( &buf[0] , 'exp' , 1 ) ) ; */
+    /*   tmp = strdup( buf ) ; */
+    /*   if ( strncmp( exp , buf , 3 ) == 0 ) { */
+    /*     //printf( '%s\n' , buf )  ; */
+    /*     // printf( "ICI\n" ) ; */
+    /*     ptr = strtok( tmp , " " ) ; */
+    /*     ptr = strtok( NULL , " " ) ; */
+    /*     ptr = strtok( NULL , " " ) ; */
+    /*     ptr = strtok( NULL , " " ) ; */
+    /*     // while ( ptr != NULL ) { */
+    /*     run = atoi( ptr ) ;  */
+    /*     //	ptr = strtok( NULL , " " ) ;  */
+    /*   } */
+    /*     //} */
+    /* } */
+    /* pclose( fp ) ; */
+    //sleep( 2 ) ; 
+
+    int run  = 0 ; 
+    FILE* fp; 
+    char * ptr ;
+    char * tmp ;
+    char buf[1000] ;
+    char exp[] = "exp" ; 
+
+    unsigned int * data ; 
+    double time_spent ;
+    int retry ;
+    int bad ;
+    int evn ;
+    evn = 0  ;
+    bad = 0 ;
+    retry = 0 ;
+    int pctime, putime ; 
+    pctime = 0 ;
+    putime = 0 ;
+
+    int i ;
+    int size, size_256, currentEventIndex, crc, nErr, nEvt, nRetry, nMissed ;
+    currentEventIndex = 0 ;
+    nErr = 0 ;
+    nEvt = 0 ;
+    nRetry = 0 ;
+    nMissed = 0 ;
+    int read_dma = 1 ; 
+    clock_t begin = clock() ;
+    int size_zero_cnt = 0;
+
+    int start_flag = 1;
+
+    int magic; 
+    int size_link;
+
+    int offset; 
+    unsigned int next_exp_run, cur_exp_run = 0, evenum, ctime, utime, first_eve = 0; 
+    int start_pos = 0;
+    int cnt = 0;
+    int eve_cnt = 0, first_event_flag = 0, crc_err_eve_cnt = 0;
+    
+    
+    int cur_pos = 0;
+    int ret = 0;
+    unsigned int cur_eve = 0, next_eve = 0;
+    int mod_pos = 0;
+
+    int sent_bytes = 0;
+    int while_cnt = 0;
+    //    if ( ( nEvt % 1000 == 1 ) && ( size != 0 ) ) printf( "Event number %d\n", nEvt ) ;
+
+
+    int m_socket_send = Accept();
+
+    //
+    // Read the 1st data
+    //
+    if ( read_dma == 1 ) { 
+      // set busy
+      //res = ecs_write( 0 , 2 ,  0x000501A0 , 0x1 ) ;
+      //sleep(5);
+      res = pcie40_b2dmapointerread( 0 , &data ) ;
+      if ( start_flag == 1 ){
+	ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
+	start_flag = 0;
+      }
+      //usleep( 5 ) ;
+      // release busy
+      //res = ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
+      read_dma = 1 ;
+    } 
+
+    //
+    // Main loop
+    //
+    while( 1 ){
+      while( 1 ){
+	if( ( ( ( magic = data[ ( cur_pos + 1 ) % DMASIZE ] ) & 0xffff0000 ) == 0x7f7f0000 )
+	    && ( data[ ( cur_pos +  data[ cur_pos  % DMASIZE ] - 1 + DMASIZE ) % DMASIZE ] == 0x7fff0006 ) 
+	      // && ( ( data[ ( cur_pos +  data[ cur_pos  % DMASIZE ] - 4 + DMASIZE ) % DMASIZE ] & 0x0000ffff )
+	      // 	  == ( data[ ( cur_pos + 3 ) % DMASIZE ] & 0x0000ffff ) ) 
+	    ){
+	  if( while_cnt % 1000 == 0 ){
+	    	 //    printf("GOT %.8x %.8x %.8x %.8x\n", 
+	    	 // data[ ( cur_pos + 1 ) % DMASIZE ], 
+	    	 // data[ ( cur_pos +  data[ cur_pos  % DMASIZE ] - 1 + DMASIZE ) % DMASIZE ],
+	    	 // data[ ( cur_pos +  data[ cur_pos  % DMASIZE ] - 4 + DMASIZE ) % DMASIZE ],
+	    	 // data[ ( cur_pos + 3 ) % DMASIZE ]
+	  	 // 	  );
+	  }
+	  while_cnt++;
+	  break;
+	}else{
+	   if( ( data[ ( cur_pos + 1 ) % DMASIZE ] & 0xffff0000 ) == 0x7f7f0000 ){
+	     // printf("magic hdr %.8x trl %.8x eve hdr %.8x trl %8.x cnt %d\n", 
+	     // 	   data[ ( cur_pos + 1 ) % DMASIZE ],
+	     // 	   data[ ( cur_pos +  data[ cur_pos  % DMASIZE ] - 1 + DMASIZE ) % DMASIZE ],
+	     // 	   data[ ( cur_pos + 3 ) % DMASIZE ],
+	     // 	   data[ ( cur_pos +  data[ cur_pos  % DMASIZE ] - 4 + DMASIZE ) % DMASIZE ],
+	     // 	   eve_cnt
+	     // 	   );
+	   }
+	}
+	//	printf("MAGIC %.8x\n", magic);
+
+	//	usleep(1000); // to avoid BUSY loop
+	
+	//
+	// Refresh DMA memory
+	//
+	res = pcie40_b2dmapointerread( 0 , &data ) ;
+
+
+
+	int wait_flag = 0;
+	//
+	// Scan to find x"7f7f...."
+	//
+	if( cnt > 100 ){
+	  cnt = 0;
+	  int j = 0 ; 
+
+	  for ( j = 0 ; j < DMASIZE ; ++j ) { 
+
+#ifdef DEBUG	    
+	    printf("%.8x %d\n", data[ ( cur_pos + j + 1 ) % DMASIZE ], cur_pos + j );
+#endif
+	    if ( ( ( data[ ( cur_pos + j + 1 ) % DMASIZE ] & 0xffff0000 ) == 0x7f7f0000 ) ){
+	      next_eve = data[ ( cur_pos + j + 3 ) % DMASIZE ];
+	      next_exp_run =  data[ ( cur_pos + j + 2 ) % DMASIZE ] ;
+
+	      // printf( "TRAILER %.8x %.8x %.8x\n",data[ ( cur_pos + j + data[ ( cur_pos + j + DMASIZE ) % DMASIZE ] - 1 + DMASIZE ) % DMASIZE ] );
+
+	      if( next_eve > cur_eve || next_exp_run > cur_exp_run ){
+		/* if( data[ ( ( data[ ( cur_pos + j + DMASIZE ) % DMASIZE ] ) - 1 + DMASIZE ) % DMASIZE ] != 0x7fff0006 ){ */
+		/*   usleep(1000); */
+		/*   break; */
+		/* } */
+		cur_pos = ( cur_pos + j + DMASIZE ) % DMASIZE;
+		size = data[ cur_pos ];
+		//		printf( "Detect new Event number prev %.8x new %.8x pos %.8x size %.8x cnt %d\n" , cur_eve , next_eve, cur_pos, size, eve_cnt );
+		break;
+	      }else{
+		//		printf( "Detect Old Event number prev %.8x new %.8x pos %d cnt %d\n" , cur_eve , next_eve, ( cur_pos + j + DMASIZE ) % DMASIZE, eve_cnt );
+		break;
+	      }
+	    }else{
+	      continue;
+	    }
+	  }
+	}
+	//	printf("Scanning... cnt=%d\n",  cnt );
+	cnt++;
+      }
+      size = data[ cur_pos ] ;
+ 
+      next_eve = data[ ( cur_pos + 3 ) % DMASIZE ];
+      next_exp_run = data[ ( cur_pos + 2 ) % DMASIZE ];
+
+      if( first_event_flag == 0 || cur_exp_run != next_exp_run ){
+	first_event_flag = 1;
+	first_eve = next_eve;
+	crc_err_eve_cnt = 0;
+	eve_cnt = 0;
+      }
+      eve_cnt++;
+      ret = crc_calc_event( data, cur_pos );
+
+      if( ret != 1 ){
+	crc_err_eve_cnt++;
+      }
+
+
+      //      printf("Sending...\n"); fflush(stdout);
+      //
+      // Send data
+      //
+	int n = 0;
+
+	//Fill iov info.
+	enum {
+	  NUM_BUFFER = 1
+	};
+	struct iovec iov[ NUM_BUFFER ];
+	iov[0].iov_len = sizeof(int) * size;
+
+	
+	if( cur_pos + size > DMASIZE ){
+	  memcpy( send_buf, data + cur_pos, DMASIZE - cur_pos );
+	  memcpy( send_buf + ( DMASIZE - cur_pos ), data, size - ( DMASIZE - cur_pos ) );
+	  iov[0].iov_base = (char*)send_buf;
+	}else{
+	  iov[0].iov_base = (char*)(data + cur_pos);
+	}
+
+	while (true) {
+	  if ((n = writev( m_socket_send, iov, NUM_BUFFER)) < 0) {
+	    if (errno == EINTR) {
+	      continue;
+	    } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
+	      continue;
+	    } else {
+	      printf("[WARNING] WRITEV error.(%s) : sent %d bytes, header %d bytes body %d trailer %d\n" ,
+		      strerror(errno), n, iov[0].iov_len, iov[1].iov_len, iov[2].iov_len);
+	      fflush(stdout);
+	      exit(1);
+	    }
+	  }
+
+	  break;
+	}
+
+	sent_bytes += n;
+
+
+
+      if(ret != 1 || eve_cnt % 1000 == 0 ){
+	printf( "[INFO] Event number prev %.8x new %.8x pos %.8x size %.8x sent %.1lf[MB]\n" , cur_eve , next_eve, cur_pos, size , sent_bytes*1.e-6);
+	fflush(stdout);
+      }
+      cur_eve = next_eve;
+      cur_exp_run = next_exp_run;
+      if(ret != 1 ||  eve_cnt % 1000 == 0 ){
+	printf("[INFO] STATUS : tot eve %d read eve %d err_eve %d run %d\n", next_eve - first_eve, eve_cnt, crc_err_eve_cnt, cur_exp_run );
+	fflush(stdout);
+      }
+      mod_pos = ( cur_pos + size ) % 8;
+      if( mod_pos != 0 ){
+	cur_pos = ( cur_pos + size + DMASIZE + ( 8 - mod_pos) ) % DMASIZE ;
+      }else{
+	cur_pos = ( cur_pos + size + DMASIZE ) % DMASIZE ;
+      }
+
+    }
+
+
+    clock_t end = clock();
+    time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
+
+    ecs_close( 0 , 0 ) ;
+
+    printf( "Timing = %f s\n" , time_spent ) ;
+    printf( "Number of events = %d \n", nEvt ) ;  
+    printf( "Number of errors = %d \n", nErr ) ; 
+    printf( "Number of retries = %d \n", nRetry ) ;
+    printf( "Number of missed = %d \n", nMissed ) ;
+    return 0 ;
+  }
diff --git a/Pcie40Applications/main_pcie40_ul.c b/Pcie40Applications/main_pcie40_ul.c
deleted file mode 100644
index f445bcb6557502225f960bc5bf0f26d4de6a02b4..0000000000000000000000000000000000000000
--- a/Pcie40Applications/main_pcie40_ul.c
+++ /dev/null
@@ -1,377 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <time.h>
-#include "altera_dma_regs.h"
-
-const int CRC16_XMODEM_TABLE[] = {
-  0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
-  0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
-  0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
-  0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
-  0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
-  0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
-  0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
-  0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
-  0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
-  0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
-  0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
-  0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
-  0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
-  0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
-  0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
-  0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
-  0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
-  0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
-  0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
-  0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
-  0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
-  0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
-  0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
-  0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
-  0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
-  0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
-  0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
-  0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
-  0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
-  0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
-  0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
-  0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
-} ;
-
-int print_data( unsigned int *data ){
-  int j = 0;
-     printf("Try -----------------------------------\n"); 
-     for ( j = 0 ; j < DMASIZE ; ++j ) { 
-       printf( "%.8x " , data[ j ] ) ; 
-       if( j % 8 == 7 ) printf("\n"); 
-     } 
-}
-
-int crc_calc( int * crc, unsigned int * data ){ 
-  int byte1, byte2, byte3, byte4 ;
-  byte1 = (*data) & 0xFF;
-  byte2 = ( (*data) & 0xFF00 ) >> 8;
-  byte3 = ( (*data) & 0xFF0000 ) >> 16;
-  byte4 = ( (*data) & 0xFF000000 ) >> 24;
-  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte4] ;
-  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte3] ;
-  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte2] ;
-  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte1] ;
-}
-
-int decode_data_wUL( unsigned int * data , unsigned int * ce , int * crc , int * prev_exp_run , 
-		     int * bad , int *evn , int * retry , int * pctime , int * putime , 
-		     int * nmissed ) { 
-
-  int magic; 
-  int size, size_link, size_256;
-  int ix, new = 0;
-
-  int offset; 
-  unsigned int exp_run, evenum, ctime, utime, cur_pos = 0; 
-
-  if( *ce < 0 || DMASIZE < *ce ){
-    printf("Current positoin is out of DMASIZE %d. Exiting...\n", *ce );
-    exit(1);
-  }
-
-  *crc = 0 ;
-  size = data[ ( *ce ) % DMASIZE ]  ;
-  magic = data[ ( *ce + 1 ) % DMASIZE ] ;
-  exp_run = data[ ( *ce + 2 ) % DMASIZE ];
-  evenum = data[ ( *ce + 3 ) % DMASIZE ];
-
-  // Check a new event is available in the memory
-  if( ( magic & 0xffff0000 ) != 0x7f7f0000 ){
-    printf("[ERROR] Invalid magic number(7f7f)  %.8x pos %d\n", magic, *ce );
-    printf("[DEBUG] %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n",
-	   data[ ( *ce ) % DMASIZE ], data[ ( *ce + 1 ) % DMASIZE ], data[ ( *ce + 2 ) % DMASIZE ], 
-	   data[ ( *ce + 3 ) % DMASIZE ], data[ ( *ce + 4 ) % DMASIZE ], data[ ( *ce + 5 ) % DMASIZE ],
-	   data[ ( *ce + 6 ) % DMASIZE ], data[ ( *ce + 7 ) % DMASIZE ] );
-    //    if( *prev_exp_run != -1)  print_data(data);
-    print_data(data);
-
-    // search for next good event
-    int j = 0 ; 
-    for ( j = *ce ; j < *ce + DMASIZE ; ++j ) { 
-      if ( ( ( data[ j % DMASIZE ] & 0xffff0000 ) == 0x7f7f0000 ) && 
-	   ( ( data[ ( j + 2 ) % DMASIZE ]  > *evn ) ) ) {
-	size = data[ ( j - 1 ) % DMASIZE ] ;
-
-	exp_run = data[ ( j + 1 ) % DMASIZE ];
-	evenum = data[ ( j + 2 ) % DMASIZE ];
-	cur_pos = ( j - 1 ) % DMASIZE;
-	printf("[INFO] New ! eve %.8x pos %d size %d\n", evenum, j - 1, size);
-	new = 1;
-	printf("[DEBUG] %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n",
-	       data[ ( j - 1 ) % DMASIZE ],data[ ( j  ) % DMASIZE ],
-	       data[ ( j + 1 ) % DMASIZE ], data[ ( j + 2 ) % DMASIZE ], 
-	       data[ ( j + 3 ) % DMASIZE ], data[ ( j + 4 ) % DMASIZE ], data[ ( j + 5 ) % DMASIZE ],
-	       data[ ( j + 6 ) % DMASIZE ], data[ ( j + 7 ) % DMASIZE ], data[ ( j + 8 ) % DMASIZE ]);
-	break ;
-      } 
-      if( j == *ce + DMASIZE - 1 ) return -1;
-    }     
-  }
-
-
-  printf("[INFO]  Good! run %.8x prevrun %.8x eve %.8x pos %.8x size %.8x\n", exp_run, *prev_exp_run, evenum, *ce, size);
-
-  
-  if( size % 8 != 0 ){
-    size_256 = ( size/8 + 1 )*8;
-  } else { 
-    size_256 = size ;
-  }
-
-  if( exp_run == *prev_exp_run && evenum - *evn != 1 ){
-    printf("[WARNING] Missing events run cur %.8x pre %.8x eve cur %.8x pre %.8x\n", exp_run, *prev_exp_run, evenum, *evn );
-  }
-
-  if( (int)exp_run < (int)(*prev_exp_run) && *prev_exp_run < 0x1000000 ){
-    printf("[NOTICE] Reached prev. run data : run cur %.8x pre %.8x eve cur %.8x pre %.8x\n", exp_run, *prev_exp_run, evenum, *evn );
-    return -1;
-  }else if( exp_run > 0x1000000 ){
-    printf("[ERROR] Too large run num! run %.8x prevrun %.8x eve %.8x pos %.8x size %.8x\n", exp_run, *prev_exp_run, evenum, *ce, size);
-    if( new == 1 ){
-	printf("[DEBUG] %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n",
-	       data[ ( cur_pos  ) % DMASIZE ],
-	       data[ ( cur_pos + 1 ) % DMASIZE ], data[ ( cur_pos + 2 ) % DMASIZE ], 
-	       data[ ( cur_pos + 3 ) % DMASIZE ], data[ ( cur_pos + 4 ) % DMASIZE ], data[ ( cur_pos + 5 ) % DMASIZE ],
-	       data[ ( cur_pos + 6 ) % DMASIZE ], data[ ( cur_pos + 7 ) % DMASIZE ], data[ ( cur_pos + 8 ) % DMASIZE ]);
-    }else{
-      printf("[DEBUG] %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n",
-	   data[ ( *ce ) % DMASIZE ], data[ ( *ce + 1 ) % DMASIZE ], data[ ( *ce + 2 ) % DMASIZE ], 
-	   data[ ( *ce + 3 ) % DMASIZE ], data[ ( *ce + 4 ) % DMASIZE ], data[ ( *ce + 5 ) % DMASIZE ],
-	   data[ ( *ce + 6 ) % DMASIZE ], data[ ( *ce + 7 ) % DMASIZE ] );
-    }
-    return -1;
-  }else{
-    if( new == 1 ) *ce = cur_pos;
-    *ce = *ce + size_256;    
-    //    printf("new pos %d size %d\n", *ce, size_256);
-    *prev_exp_run = exp_run;
-    *evn = evenum;
-  }
-
-  return 0;
-  
-  if ( 0 == size ) return 0 ;
-  
-  ix = *ce + 4;
-  ctime = data[ ix % DMASIZE ];
-  ix = *ce + 3;
-  evenum = data[ ix % DMASIZE ];
-  ix = *ce + 5;
-  utime = data[ ix % DMASIZE ];
-  ix = *ce + 2;
-  exp_run = data[ ix % DMASIZE ] ;
-  
-  //  printf("exprun %.8x eve %d ce %d\n", exp_run, evenum , *ce );
-  
-  if ( ( exp_run >> 8 ) != *prev_exp_run ) { // it may be that the old data is still in memory
-    return 0 ; 
-  }
-
-  if ( evenum < *evn ) return 0 ;
-
-  if ( evenum != *evn ) {
-    printf( "Bad event number %d %d %d %d %d %d retry = %d\n" , evenum , *evn , ctime , utime , *pctime , *putime ,
-	    *retry ) ;
-    *nmissed += (- *evn + evenum ) ;
-    *evn = evenum ;
-    *bad = 1 ;
-    //if ( evenum != 0 ) { 
-    //  int j = 0 ;
-    //  for ( j = 0 ; j < DMASIZE ; ++j ) {
-    //	printf( "%d  %.8x  %d\n" , j , data[ j ] , *ce ) ;
-    //  }
-    //  exit( 0 ) ;
-    //}
-  }
-
-
-  *putime = utime ; 
-  *pctime = ctime ; 
-
-  offset = 8; // size of ROB header [words]
-
-  int first_crc ;
-  *crc = 0xffff ;
-  crc_calc( crc, &ctime );
-  crc_calc( crc, &evenum );
-  crc_calc( crc, &utime );
-  crc_calc( crc, &exp_run );
-  first_crc = *crc ;
-
-  while( offset + 4 != size ){ // 4 = ROB trailer size
-    ix = *ce + offset;
-    size_link = data[ ix % DMASIZE ] & 0x00ffffff ;
-    if ( 0 == size_link ) return 0 ; // it could be that the memory was read
-    // while being filled
-
-    // Calculation of CRC
-    *crc = first_crc ;
-
-    for ( ix = *ce + offset + 2 ; ix < *ce + offset + size_link -2; ++ix ) {
-      crc_calc( crc, &data[ ix % DMASIZE ] );
-    }
-  
-    ix = *ce + 8 + size_link -2;
-    if( ( *crc & 0xffff ) != ( data[ ix % DMASIZE ] & 0xffff ) ){
-      // retry, could be that the event is not fully in memory
-      //ecs_write( 0 , 2 ,  0x000501A0 , 0x1 ) ;
-      ++(*retry) ;
-      if ( *retry < 10 ) { 
-	return 0 ;
-      }
-      *bad = 1 ;
-      printf( "Error in CRC comparison calc %.8x : data %.8x, offset = %d, retry = %d\n" , *crc , data[ ix % DMASIZE ] , 
-	      offset, *retry );
-
-      //      if ( evenum != 0 ) { 
-      // int j = 0 ;
-      // for ( j = 0 ; j < DMASIZE ; ++j ) {
-      //	  printf( "%d  %.8x  %d\n" , j , data[ j ] , *ce ) ;
-      //	}
-      //	exit( 0 ) ;
-      //}
-
-      *retry = 0 ; 
-    }
-    // ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
-    
-    offset += size_link;
-    if( offset + 4 > size ){
-      printf( "Invalid data size sum of link size %d size = %d\n" , 
-	      offset + 4, size );
-      //      if ( evenum != 0 ) { 
-      //  int j = 0 ;
-      //  for ( j = 0 ; j < DMASIZE ; ++j ) {
-      //	  printf( "%d  %.8x  %d\n" , j , data[ j ] , *ce ) ;
-      //  }
-      //	exit( 0 ) ;
-      //}
-      return -1 ; 
-    }
-  }
-  return size ;
-}
-
-int main(int argc ,char** argv) {
-  // Stop trigger
-  system( "ssh yamadas@ttd7 \"resetft -23\"" ) ;
-  sleep( 2 ) ; 
-  int res = ecs_open( 0 , 0 ) ;
-  if ( -1 == res ) printf("ERROR: Could not open device (BAR 0)\n") ;
-  else printf("SUCCESS: Device opened for DMA\n");
-  res = ecs_open( 0 , 2 ) ;
-  // ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
-  ecs_write( 0 , 2 ,  0x000501A0 , 0x1 ) ;
-  pcie40_b2dmabufferreset( 0 ) ; 
-  // Start trigger
-  int run  = -1 ; 
-  FILE* fp; 
-  char * ptr ;
-  char * tmp ;
-  fp = popen( "ssh yamadas@ttd7 \"trigft -23 poisson 5 -1\"" , "r" ) ;
-  char buf[1000] ;
-  char exp[] = "exp" ; 
-  sleep( 2 ) ;
-  /* while( fgets( buf , sizeof(buf) , fp ) != NULL ) { */
-  /*   //    printf( "buf %s\n" , buf ); */
-  /*   //    printf( "A= %d\n" , strncmp( exp , buf , 3 ) ) ; */
-  /*   //    printf( strncmp( &buf[0] , 'exp' , 1 ) ) ; */
-  /*   tmp = strdup( buf ) ; */
-  /*   if ( strncmp( exp , buf , 3 ) == 0 ) { */
-  /*     //printf( '%s\n' , buf )  ; */
-  /*     // printf( "ICI\n" ) ; */
-  /*     ptr = strtok( tmp , " " ) ; */
-  /*     ptr = strtok( NULL , " " ) ; */
-  /*     ptr = strtok( NULL , " " ) ; */
-  /*     ptr = strtok( NULL , " " ) ; */
-  /*     // while ( ptr != NULL ) { */
-  /*     run = atoi( ptr ) ;  */
-  /*     //	ptr = strtok( NULL , " " ) ;  */
-  /*   } */
-  /*     //} */
-  /* } */
-  pclose( fp ) ;
-
-  //sleep( 2 ) ; 
-
-  // Read DMA
-  unsigned int * data ; 
-  double time_spent ;
-  int retry ;
-  int bad ;
-  int evn ;
-  int ret = 0;
-  evn = 0  ;
-  bad = 0 ;
-  retry = 0 ;
-  int pctime, putime ; 
-  pctime = 0 ;
-  putime = 0 ;
-
-  int i, j ;
-  int size, size_256, currentEventIndex, prev_ce, crc, nErr, nEvt, nRetry, nMissed ;
-  currentEventIndex = 0 ;
-  prev_ce = 0;
-  nErr = 0 ;
-  nEvt = 0 ;
-  nRetry = 0 ;
-  nMissed = 0 ;
-  int read_dma = 1 ; 
-  clock_t begin = clock() ;
-
-  //  for ( i = 0 ; i < 10000000 ; ++i ) { 
-  for ( i = 0 ; i < 1000000 ; ++i ) { 
-
-    //    if ( ( nEvt % 1000 == 1 ) && ( size != 0 ) ) printf( "Event number %d\n", nEvt ) ;
-    if ( read_dma == 1 ) { 
-      // set busy
-      //res = ecs_write( 0 , 2 ,  0x000501A0 , 0x1 ) ;
-      //sleep(5);
-      res = pcie40_b2dmapointerread( 0 , &data ) ;
-      if ( 1 == i )   ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
-      //usleep( 5 ) ;
-      // release busy
-      //res = ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
-      read_dma = 1 ;
-    } 
-
-
-
-    bad = 0 ;
-    while( currentEventIndex < DMASIZE && currentEventIndex >= 0 ){
-      //      printf("index %d data %.8x\n", currentEventIndex, data[ ( currentEventIndex + 1 ) % DMASIZE ] );
-      currentEventIndex = currentEventIndex % DMASIZE ; 
-      prev_ce = currentEventIndex;
-      if( decode_data_wUL( data , &currentEventIndex , &crc , &run , &bad , &evn , &retry , &pctime , &putime , &nMissed ) < 0 ){ 
-	sleep(1);
-	break;
-      }
-    }
-    currentEventIndex = currentEventIndex % DMASIZE ; 
-    printf("cnt %d pos %d run %.8x evn %.8x\n", nEvt, currentEventIndex, run, evn);
-    nEvt++;
-    read_dma = 1 ;
-    retry = 0 ;
-  }
-
-  clock_t end = clock();
-  time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
-
-  res = ecs_close( 0 , 0 ) ;
-  if ( -1 == res ) printf("ERROR: Could not close device (BAR 0)\n");
-  else printf("SUCCESS: Device closed for DMA\n");
-
-  printf( "Timing = %f s\n" , time_spent ) ;
-  printf( "Number of events = %d \n", nEvt ) ;  
-  printf( "Number of errors = %d \n", nErr ) ; 
-  printf( "Number of retries = %d \n", nRetry ) ;
-  printf( "Number of missed = %d \n", nMissed ) ;
-  return 0 ;
-}
diff --git a/Pcie40Applications/main_pcie40_ul.cpp b/Pcie40Applications/main_pcie40_ul.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c0a5014e7569b59d1b858fe8f63737c87fd27028
--- /dev/null
+++ b/Pcie40Applications/main_pcie40_ul.cpp
@@ -0,0 +1,392 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <time.h>
+#include "altera_dma_regs.h"
+
+extern "C" int  ecs_open(int dev, int bar);
+extern "C" void ecs_close(int dev, int bar);
+extern "C" int pcie40_b2dmabufferreset(int fd);
+extern "C" int pcie40_b2dmapointerread(int fd , unsigned int ** pData );
+extern "C" int      ecs_write(int dev, int bar, unsigned add, int val);
+
+//#define DEBUG
+
+const int CRC16_XMODEM_TABLE[] = {
+  0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
+  0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
+  0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
+  0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
+  0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
+  0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
+  0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
+  0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
+  0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
+  0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
+  0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
+  0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
+  0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
+  0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
+  0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
+  0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
+  0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
+  0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
+  0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
+  0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
+  0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
+  0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
+  0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
+  0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
+  0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
+  0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
+  0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
+  0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
+  0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
+  0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
+  0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
+  0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
+} ;
+
+
+
+int crc_calc( int * crc, unsigned int * data ){ 
+  int byte1, byte2, byte3, byte4 ;
+  byte1 = (*data) & 0xFF;
+  byte2 = ( (*data) & 0xFF00 ) >> 8;
+  byte3 = ( (*data) & 0xFF0000 ) >> 16;
+  byte4 = ( (*data) & 0xFF000000 ) >> 24;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte4] ;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte3] ;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte2] ;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte1] ;
+}
+
+
+int crc_calc_event( unsigned int* data, int start_pos ){
+  int i = 0;
+  int cur_pos = start_pos;
+  int first_crc ;
+  int crc = 0xffff ;
+  int size = data[ cur_pos % DMASIZE ];
+
+  int good_flag = 0;
+
+  if( size > 0xffff || size <= 0 ){
+    printf("Invalid total event size %.8x\n", size);
+    return -1;
+  }
+
+  /* printf( "TRL %.8x %.8x %.8x\n",  */
+  /* 	  data[ ( cur_pos + size - 1 + DMASIZE ) % DMASIZE ],  */
+  /* 	  data[ ( cur_pos + 1 + size ) % DMASIZE ],  */
+  /* 	  data[ ( cur_pos + 2 + size ) % DMASIZE ] );  */
+
+  cur_pos = start_pos + 4;
+  unsigned int ctime = data[ cur_pos % DMASIZE ];
+
+  cur_pos = start_pos + 3;
+  unsigned int evenum = data[ cur_pos % DMASIZE ];
+  cur_pos = start_pos + 5;
+  unsigned int utime = data[ cur_pos % DMASIZE ];
+  cur_pos = start_pos + 2;
+  unsigned int exp_run = data[ cur_pos % DMASIZE ] ;
+
+  int offset = 8; // size of ROB header [words]
+
+  int link_num = 0;
+
+
+  crc_calc( &crc, &ctime );
+  crc_calc( &crc, &evenum );
+  crc_calc( &crc, &utime );
+  crc_calc( &crc, &exp_run );
+  first_crc = crc ;
+
+  
+#ifdef DEBUG
+  printf("Start\n");
+  for( i = start_pos ; i < start_pos + size ; i++){
+    printf("%.8x\n", data[ i % DMASIZE ] );
+  }
+  printf("End\n");
+#endif
+  int bad = 0;
+  
+  while( offset + 4 < size ){ // 4 = ROB trailer size
+    cur_pos = start_pos + offset;
+    int size_link = data[ cur_pos % DMASIZE ] & 0x000ffff ;
+    if ( 0 >= size_link || size_link > 10000000 ){
+      printf("[ERROR] Invalid size per link (%.8x words): link num %d\n", size_link, link_num);
+      return -1 ; // it could be that the memory was read
+    } 
+
+    //
+    // Calculation of CRC
+    //
+    crc = first_crc ;
+#ifdef DEBUG
+    printf("%.8x %.8x crc %.8x\n", data[ ( start_pos + offset ) % DMASIZE ], data[ ( start_pos + offset + 1 ) % DMASIZE ], crc );
+#endif
+    for ( cur_pos = start_pos + offset + 2 ; cur_pos < start_pos + offset + size_link -2; ++cur_pos ) {
+      crc_calc( &crc, &data[ cur_pos % DMASIZE ] );
+#ifdef DEBUG
+      printf("crc %.8x data %.8x\n", crc, data[ cur_pos % DMASIZE ] );
+#endif
+    }
+#ifdef DEBUG
+    printf("%.8x %.8x\n", data[ ( cur_pos ) % DMASIZE ], data[ ( cur_pos + 1 ) % DMASIZE ]);
+#endif
+    //    cur_pos = start_pos +  8 + size_link -2;
+    cur_pos = start_pos + offset + size_link -2;
+#ifdef DEBUG
+    printf("calcd %.4x data %.4x\n", crc, data[ cur_pos % DMASIZE ] & 0xffff );
+#endif
+
+    //
+    // Check of CRC
+    //
+    if( ( crc & 0xffff ) != ( data[ cur_pos % DMASIZE ] & 0xffff ) ){
+      printf("%.2d Bad  ! calcd %.4x data %.4x offset %.4x size %.4x szlnk %.4x trl %.8x\n", 
+	     link_num, crc, data[ cur_pos % DMASIZE ] & 0xffff, offset, size, size_link, data[ (cur_pos+1) % DMASIZE ] );
+      bad = 1;
+
+    }else{
+      good_flag = 1;
+       // printf("%.2d Good ! calcd %.4x data %.4x offset %.4x size %.4x szlnk %.4x trl %.8x\n",  
+       // 	      link_num, crc, data[ cur_pos % DMASIZE ] & 0xffff, offset, size, size_link, data[ (cur_pos+1) % DMASIZE ] ); 
+
+    }
+    link_num++;
+    offset += size_link;
+  }
+
+  if( bad ){
+    for( i = 0 ; i < size ; i++){
+      printf("%.8x ", data[ ( start_pos  + i ) % DMASIZE ] );
+      if( i % 8 == 7 ) printf("\n");
+    }
+    printf("\n");
+    good_flag = -2;
+  }
+  return good_flag;
+     
+}
+
+
+  int main (int argc ,char** argv) {
+    // Stop trigger
+    /* system( "ssh robbep@vme \"resetft -53\"" ) ; */
+    /* sleep( 2 ) ;  */
+
+    int res = ecs_open( 0 , 0 ) ;
+    if ( -1 == res ) printf("ERROR: Could not open device (BAR 0)\n") ;
+    else printf("SUCCESS: Device opened for DMA\n");
+    res = ecs_open( 0 , 2 ) ;
+    // ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
+    ecs_write( 0 , 2 ,  0x000501A0 , 0x1 ) ;
+    pcie40_b2dmabufferreset( 0 ) ; 
+    // Start trigger
+    //  fp = popen( "ssh robbep@vme \"trigft -53 pulse 1000 -1\"" , "r" ) ;
+    // sleep( 2 ) ;
+    /* while( fgets( buf , sizeof(buf) , fp ) != NULL ) {  */
+    /*   // printf( "A= %d\n" , strncmp( exp , buf , 3 ) ) ; */
+    /*   //    printf( strncmp( &buf[0] , 'exp' , 1 ) ) ; */
+    /*   tmp = strdup( buf ) ; */
+    /*   if ( strncmp( exp , buf , 3 ) == 0 ) { */
+    /*     //printf( '%s\n' , buf )  ; */
+    /*     // printf( "ICI\n" ) ; */
+    /*     ptr = strtok( tmp , " " ) ; */
+    /*     ptr = strtok( NULL , " " ) ; */
+    /*     ptr = strtok( NULL , " " ) ; */
+    /*     ptr = strtok( NULL , " " ) ; */
+    /*     // while ( ptr != NULL ) { */
+    /*     run = atoi( ptr ) ;  */
+    /*     //	ptr = strtok( NULL , " " ) ;  */
+    /*   } */
+    /*     //} */
+    /* } */
+    /* pclose( fp ) ; */
+    //sleep( 2 ) ; 
+
+    int run  = 0 ; 
+    FILE* fp; 
+    char * ptr ;
+    char * tmp ;
+    char buf[1000] ;
+    char exp[] = "exp" ; 
+
+    unsigned int * data ; 
+    double time_spent ;
+    int retry ;
+    int bad ;
+    int evn ;
+    evn = 0  ;
+    bad = 0 ;
+    retry = 0 ;
+    int pctime, putime ; 
+    pctime = 0 ;
+    putime = 0 ;
+
+    int i ;
+    int size, size_256, currentEventIndex, crc, nErr, nEvt, nRetry, nMissed ;
+    currentEventIndex = 0 ;
+    nErr = 0 ;
+    nEvt = 0 ;
+    nRetry = 0 ;
+    nMissed = 0 ;
+    int read_dma = 1 ; 
+    clock_t begin = clock() ;
+    int size_zero_cnt = 0;
+
+    int start_flag = 1;
+
+    int magic; 
+    int size_link;
+
+    int offset; 
+    unsigned int next_exp_run, cur_exp_run = 0, evenum, ctime, utime, first_eve = 0; 
+    int start_pos = 0;
+    int cnt = 0, dma_cnt = 0;
+    int eve_cnt = 0, first_event_flag = 0, crc_err_eve_cnt = 0;
+    
+    
+    int cur_pos = 0;
+    int ret = 0;
+    unsigned int cur_eve = 0, next_eve = 0;
+    int mod_pos = 0;
+
+    //    if ( ( nEvt % 1000 == 1 ) && ( size != 0 ) ) printf( "Event number %d\n", nEvt ) ;
+
+    //
+    // Read the 1st data
+    //
+    if ( read_dma == 1 ) { 
+      // set busy
+      //res = ecs_write( 0 , 2 ,  0x000501A0 , 0x1 ) ;
+      //sleep(5);
+      res = pcie40_b2dmapointerread( 0 , &data ) ;
+      dma_cnt++;
+      if ( start_flag == 1 ){
+	ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
+	start_flag = 0;
+      }
+      //usleep( 5 ) ;
+      // release busy
+      //res = ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
+      read_dma = 1 ;
+    } 
+
+    //
+    // Main loop
+    //
+    while( 1 ){
+      while( 1 ){
+	// if( ( data[ ( cur_pos + 1 ) % DMASIZE ] & 0xffff0000 ) == 0x7f7f0000 ){
+	//   printf("HEAD %.8x TRAIL %.8x\n", data[ ( cur_pos + 1 ) % DMASIZE ], 
+	// 	 data[ ( cur_pos +  data[ cur_pos  % DMASIZE ] - 1 + DMASIZE ) % DMASIZE ] );
+	// }
+	//	if( !( ( ( ( magic = data[ ( cur_pos + 1 ) % DMASIZE ] ) & 0xffff0000 ) != 0x7f7f0000 ) ) ){
+	if( !( ( ( ( magic = data[ ( cur_pos + 1 ) % DMASIZE ] ) & 0xffff0000 ) != 0x7f7f0000 )
+	       || data[ ( cur_pos +  data[ cur_pos  % DMASIZE ] - 1 + DMASIZE ) % DMASIZE ] != 0x7fff0006 ) ){
+	  break;
+	}
+	//	usleep(1000); // to avoid BUSY loop
+	
+	//
+	// Refresh DMA memory
+	//
+	res = pcie40_b2dmapointerread( 0 , &data ) ;
+	dma_cnt++;
+	int wait_flag = 0;
+
+	//
+	// Scan to find x"7f7f...."
+	//
+	if( cnt > 100 ){
+	  cnt = 0;
+	  int j = 0 ; 
+	  for ( j = 0 ; j < DMASIZE ; ++j ) { 
+#ifdef DEBUG	    
+	    printf("%.8x %d\n", data[ ( cur_pos + j + 1 ) % DMASIZE ], cur_pos + j );
+#endif
+	    if ( ( ( data[ ( cur_pos + j + 1 ) % DMASIZE ] & 0xffff0000 ) == 0x7f7f0000 ) ){
+	      next_eve = data[ ( cur_pos + j + 3 ) % DMASIZE ];
+	      next_exp_run =  data[ ( cur_pos + j + 2 ) % DMASIZE ] ;
+
+	      if( dma_cnt % 1000 == 0 ){
+		printf( "7f7f is found. TRAILER %.8x eve %.8x exprun %.8x pos %d dmacnt %d\n", 
+		      data[ ( cur_pos + j + data[ ( cur_pos + j + DMASIZE ) % DMASIZE ] - 1 + DMASIZE ) % DMASIZE ], 
+			next_eve, next_exp_run, ( cur_pos + j + 1 ) % DMASIZE, dma_cnt );
+	      }
+
+	      if( next_eve > cur_eve && next_exp_run >= cur_exp_run ){
+		/* if( data[ ( ( data[ ( cur_pos + j + DMASIZE ) % DMASIZE ] ) - 1 + DMASIZE ) % DMASIZE ] != 0x7fff0006 ){ */
+		/*   usleep(1000); */
+		/*   break; */
+		/* } */
+		cur_pos = ( cur_pos + j + DMASIZE ) % DMASIZE;
+		size = data[ cur_pos ];
+		//				printf( "Detect new Event number prev %.8x new %.8x pos %.8x size %.8x\n" , cur_eve , next_eve, cur_pos, size );
+		break;
+	      }else{
+		//				printf( "Detect Old Event number prev %.8x new %.8x pos %d\n" , cur_eve , next_eve, ( cur_pos + j + DMASIZE ) % DMASIZE );
+		break;
+	      }
+	    }else{
+	      continue;
+	    }
+	  }
+	}
+	cnt++;
+      }
+      size = data[ cur_pos ] ;
+
+      //
+      // Check event-data
+      //
+      next_eve = data[ ( cur_pos + 3 ) % DMASIZE ];
+      next_exp_run = data[ ( cur_pos + 2 ) % DMASIZE ];
+
+      if( first_event_flag == 0 || cur_exp_run != next_exp_run ){
+	first_event_flag = 1;
+	first_eve = next_eve;
+	// crc_err_eve_cnt = 0;
+	// eve_cnt = 0;
+      }
+      eve_cnt++;
+      ret = crc_calc_event( data, cur_pos );
+      //      printf("crc ret %d cnt %d\n", eve_cnt);
+      if( ret != 1 ){
+	crc_err_eve_cnt++;
+      }
+
+      if(ret != 1 || eve_cnt % 100 == 0 ){
+	printf( "Event number prev %.8x new %.8x pos %.8x size %.8x\n" , cur_eve , next_eve, cur_pos, size );
+      }
+      cur_eve = next_eve;
+      cur_exp_run = next_exp_run;
+      if(ret != 1 ||  eve_cnt % 100 == 0 ){
+	printf("STATUS : tot eve %d read eve %d err_eve %d run %d\n", next_eve - first_eve, eve_cnt, crc_err_eve_cnt, cur_exp_run );
+      }
+      mod_pos = ( cur_pos + size ) % 8;
+      if( mod_pos != 0 ){
+	cur_pos = ( cur_pos + size + DMASIZE + ( 8 - mod_pos) ) % DMASIZE ;
+      }else{
+	cur_pos = ( cur_pos + size + DMASIZE ) % DMASIZE ;
+      }
+
+    }
+
+
+    clock_t end = clock();
+    time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
+
+    ecs_close( 0 , 0 ) ;
+
+    printf( "Timing = %f s\n" , time_spent ) ;
+    printf( "Number of events = %d \n", nEvt ) ;  
+    printf( "Number of errors = %d \n", nErr ) ; 
+    printf( "Number of retries = %d \n", nRetry ) ;
+    printf( "Number of missed = %d \n", nMissed ) ;
+    return 0 ;
+  }
diff --git a/Pcie40Applications/main_pcie40_ulreset.cpp b/Pcie40Applications/main_pcie40_ulreset.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..566f83cb97d3e311b86c2e4a47f09792e4730c27
--- /dev/null
+++ b/Pcie40Applications/main_pcie40_ulreset.cpp
@@ -0,0 +1,28 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <time.h>
+#include "altera_dma_regs.h"
+
+extern "C" int  ecs_open(int dev, int bar);
+extern "C" void ecs_close(int dev, int bar);
+extern "C" int      ecs_write(int dev, int bar, unsigned add, int val);
+
+//#define DEBUG
+
+int main (int argc ,char** argv) {
+  
+  int res = ecs_open( 0 , 0 ) ;
+  res = ecs_open( 0 , 2 ) ;
+
+  //
+  // Turn on pio_cmd1_s(2) to reset UL  
+  // ( From messages in https://b2rc.kek.jp/channel/daq_upgrade_pcie40 )
+  // 
+  ecs_write( 0 , 2 ,  0x00050400 , 0x0);
+  ecs_write( 0 , 2 ,  0x00050400 , 0x4 );
+  ecs_write( 0 , 2 ,  0x00050400 , 0x0 );
+
+  ecs_close( 0 , 0 ) ;
+  return 0 ;
+}
diff --git a/Pcie40Applications/pcie40_ul_lib.cpp b/Pcie40Applications/pcie40_ul_lib.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..289d2f7bedf2c336f6be79d2e64c4e52b531147a
--- /dev/null
+++ b/Pcie40Applications/pcie40_ul_lib.cpp
@@ -0,0 +1,380 @@
+#include "pcie40_ul_lib.h"
+
+int crc_calc( int * crc, unsigned int * data ){ 
+  int byte1, byte2, byte3, byte4 ;
+  byte1 = (*data) & 0xFF;
+  byte2 = ( (*data) & 0xFF00 ) >> 8;
+  byte3 = ( (*data) & 0xFF0000 ) >> 16;
+  byte4 = ( (*data) & 0xFF000000 ) >> 24;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte4] ;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte3] ;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte2] ;
+  *crc = ((((*crc))<<8)&0xff00) ^ CRC16_XMODEM_TABLE[((((*crc))>>8)&0xff)^byte1] ;
+}
+
+
+int crc_calc_event( unsigned int* data, int start_pos ){
+  int i = 0;
+  int cur_pos = start_pos;
+  int first_crc ;
+  int crc = 0xffff ;
+  int size = data[ cur_pos % DMASIZE ];
+
+  int good_flag = 0;
+
+  if( size > 0xffff || size <= 0 ){
+    printf("Invalid total event size %.8x\n", size);
+    return -1;
+  }
+
+  /* printf( "TRL %.8x %.8x %.8x\n",  */
+  /* 	  data[ ( cur_pos + size - 1 + DMASIZE ) % DMASIZE ],  */
+  /* 	  data[ ( cur_pos + 1 + size ) % DMASIZE ],  */
+  /* 	  data[ ( cur_pos + 2 + size ) % DMASIZE ] );  */
+
+  cur_pos = start_pos + 4;
+  unsigned int ctime = data[ cur_pos % DMASIZE ];
+
+  cur_pos = start_pos + 3;
+  unsigned int evenum = data[ cur_pos % DMASIZE ];
+  cur_pos = start_pos + 5;
+  unsigned int utime = data[ cur_pos % DMASIZE ];
+  cur_pos = start_pos + 2;
+  unsigned int exp_run = data[ cur_pos % DMASIZE ] ;
+
+  int offset = 8; // size of ROB header [words]
+
+  int link_num = 0;
+
+
+  crc_calc( &crc, &ctime );
+  crc_calc( &crc, &evenum );
+  crc_calc( &crc, &utime );
+  crc_calc( &crc, &exp_run );
+  first_crc = crc ;
+
+  
+#ifdef DEBUG
+  printf("Start\n");
+  for( i = start_pos ; i < start_pos + size ; i++){
+    printf("%.8x\n", data[ i % DMASIZE ] );
+  }
+  printf("End\n");
+#endif
+  int bad = 0;
+  
+  while( offset + 4 < size ){ // 4 = ROB trailer size
+    cur_pos = start_pos + offset;
+    int size_link = data[ cur_pos % DMASIZE ] & 0x000ffff ;
+    if ( 0 >= size_link || size_link > 10000000 ){
+      printf("[ERROR] Invalid size per link (%.8x words): link num %d\n", size_link, link_num);
+      return -1 ; // it could be that the memory was read
+    } 
+
+    //
+    // Calculation of CRC
+    //
+    crc = first_crc ;
+#ifdef DEBUG
+    printf("%.8x %.8x crc %.8x\n", data[ ( start_pos + offset ) % DMASIZE ], data[ ( start_pos + offset + 1 ) % DMASIZE ], crc );
+#endif
+    for ( cur_pos = start_pos + offset + 2 ; cur_pos < start_pos + offset + size_link -2; ++cur_pos ) {
+      crc_calc( &crc, &data[ cur_pos % DMASIZE ] );
+#ifdef DEBUG
+      printf("crc %.8x data %.8x\n", crc, data[ cur_pos % DMASIZE ] );
+#endif
+    }
+#ifdef DEBUG
+    printf("%.8x %.8x\n", data[ ( cur_pos ) % DMASIZE ], data[ ( cur_pos + 1 ) % DMASIZE ]);
+#endif
+    //    cur_pos = start_pos +  8 + size_link -2;
+    cur_pos = start_pos + offset + size_link -2;
+#ifdef DEBUG
+    printf("calcd %.4x data %.4x\n", crc, data[ cur_pos % DMASIZE ] & 0xffff );
+#endif
+
+    //
+    // Check of CRC
+    //
+    if( ( crc & 0xffff ) != ( data[ cur_pos % DMASIZE ] & 0xffff ) ){
+      printf("%.2d Bad  ! calcd %.4x data %.4x offset %.4x size %.4x szlnk %.4x trl %.8x\n", 
+	     link_num, crc, data[ cur_pos % DMASIZE ] & 0xffff, offset, size, size_link, data[ (cur_pos+1) % DMASIZE ] );
+      bad = 1;
+
+    }else{
+      good_flag = 1;
+       // printf("%.2d Good ! calcd %.4x data %.4x offset %.4x size %.4x szlnk %.4x trl %.8x\n",  
+       // 	      link_num, crc, data[ cur_pos % DMASIZE ] & 0xffff, offset, size, size_link, data[ (cur_pos+1) % DMASIZE ] ); 
+
+    }
+    link_num++;
+    offset += size_link;
+  }
+
+  if( bad ){
+  //  if( evenum > 50000 ){
+    //  if( 1 ){
+    for( i = 0 ; i < size ; i++){
+      printf("%.8x ", data[ ( start_pos  + i ) % DMASIZE ] );
+      if( i % 8 == 7 ) printf("\n");
+    }
+    printf("\n");
+    good_flag = -2;
+  }
+  return good_flag;
+     
+}
+
+  int decode_data_wUL( unsigned int * data , unsigned int * ce , int * crc , int * run , 
+		       int * bad , int *evn , int * retry , int * pctime , int * putime , 
+		       int * nmissed ) { 
+
+    int magic; 
+    int size, size_link;
+    int ix ;
+
+    int offset; 
+    unsigned int exp_run, evenum, ctime, utime; 
+    int start_pos = *ce;
+    int cnt = 0;
+    int cur_pos = *ce + 1;
+    int ret = 0;
+    
+    while( !( ( ( magic = data[ cur_pos % DMASIZE ] ) & 0xffff0000 ) != 0x7f7f0000 ) ){
+      usleep(1000);
+      cnt++;
+      //
+      // Scan to find x"7f7f...."
+      //
+      if( cnt > 10 ){
+	cnt = 0;
+	int j = 0 ; 
+	for ( j = 0 ; j < DMASIZE ; ++j ) { 
+	  if ( ( ( data[ ( cur_pos + j ) % DMASIZE ] & 0xffff0000 ) == 0x7f7f0000 ) ){
+	    evenum = data[ ( cur_pos + j + 2 ) % DMASIZE ];
+	    if( evenum > *evn ){
+	      *evn = evenum;
+	      cur_pos = ( cur_pos + j - 1 + DMASIZE ) % DMASIZE;
+	      size = data[ cur_pos ] ;
+	      *ce = ( cur_pos + size ) % DMASIZE;
+	      printf( "New Event number prev %d new %d pos %d size %d\n" , *evn ,  evenum, cur_pos, size );
+	      crc_calc_event( data, cur_pos );
+
+	    }else{
+	      printf( "Old Event number prev %d new %d pos %d\n" , *evn ,  evenum, ( cur_pos + j - 1 + DMASIZE ) % DMASIZE );
+	      break;
+	    }
+	  }else{
+	    continue;
+	  }
+	}
+      }
+    }
+
+    return size ;
+  }
+
+int readout(){
+//  int main (int argc ,char** argv) {
+    // Stop trigger
+    /* system( "ssh robbep@vme \"resetft -53\"" ) ; */
+    /* sleep( 2 ) ;  */
+
+    int res = ecs_open( 0 , 0 ) ;
+    if ( -1 == res ) printf("ERROR: Could not open device (BAR 0)\n") ;
+    else printf("SUCCESS: Device opened for DMA\n");
+    res = ecs_open( 0 , 2 ) ;
+    // ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
+    ecs_write( 0 , 2 ,  0x000501A0 , 0x1 ) ;
+    pcie40_b2dmabufferreset( 0 ) ; 
+    // Start trigger
+    //  fp = popen( "ssh robbep@vme \"trigft -53 pulse 1000 -1\"" , "r" ) ;
+    // sleep( 2 ) ;
+    /* while( fgets( buf , sizeof(buf) , fp ) != NULL ) {  */
+    /*   // printf( "A= %d\n" , strncmp( exp , buf , 3 ) ) ; */
+    /*   //    printf( strncmp( &buf[0] , 'exp' , 1 ) ) ; */
+    /*   tmp = strdup( buf ) ; */
+    /*   if ( strncmp( exp , buf , 3 ) == 0 ) { */
+    /*     //printf( '%s\n' , buf )  ; */
+    /*     // printf( "ICI\n" ) ; */
+    /*     ptr = strtok( tmp , " " ) ; */
+    /*     ptr = strtok( NULL , " " ) ; */
+    /*     ptr = strtok( NULL , " " ) ; */
+    /*     ptr = strtok( NULL , " " ) ; */
+    /*     // while ( ptr != NULL ) { */
+    /*     run = atoi( ptr ) ;  */
+    /*     //	ptr = strtok( NULL , " " ) ;  */
+    /*   } */
+    /*     //} */
+    /* } */
+    /* pclose( fp ) ; */
+    //sleep( 2 ) ; 
+
+    int run  = 0 ; 
+    FILE* fp; 
+    char * ptr ;
+    char * tmp ;
+    char buf[1000] ;
+    char exp[] = "exp" ; 
+
+    unsigned int * data ; 
+    double time_spent ;
+    int retry ;
+    int bad ;
+    int evn ;
+    evn = 0  ;
+    bad = 0 ;
+    retry = 0 ;
+    int pctime, putime ; 
+    pctime = 0 ;
+    putime = 0 ;
+
+    int i ;
+    int size, size_256, currentEventIndex, crc, nErr, nEvt, nRetry, nMissed ;
+    currentEventIndex = 0 ;
+    nErr = 0 ;
+    nEvt = 0 ;
+    nRetry = 0 ;
+    nMissed = 0 ;
+    int read_dma = 1 ; 
+    clock_t begin = clock() ;
+    int size_zero_cnt = 0;
+
+    int start_flag = 1;
+
+    int magic; 
+    int size_link;
+
+    int offset; 
+    unsigned int next_exp_run, cur_exp_run = 0, evenum, ctime, utime, first_eve = 0; 
+    int start_pos = 0;
+    int cnt = 0;
+    int eve_cnt = 0, first_event_flag = 0, crc_err_eve_cnt = 0;
+    
+    
+    int cur_pos = 0;
+    int ret = 0;
+    unsigned int cur_eve = 0, next_eve = 0;
+    int mod_pos = 0;
+
+    //    if ( ( nEvt % 1000 == 1 ) && ( size != 0 ) ) printf( "Event number %d\n", nEvt ) ;
+
+    //
+    // Read the 1st data
+    //
+    if ( read_dma == 1 ) { 
+      // set busy
+      //res = ecs_write( 0 , 2 ,  0x000501A0 , 0x1 ) ;
+      //sleep(5);
+      res = pcie40_b2dmapointerread( 0 , &data ) ;
+      if ( start_flag == 1 ){
+	ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
+	start_flag = 0;
+      }
+      //usleep( 5 ) ;
+      // release busy
+      //res = ecs_write( 0 , 2 ,  0x000501A0 , 0x0 ) ;
+      read_dma = 1 ;
+    } 
+
+    //
+    // Main loop
+    //
+    while( 1 ){
+      while( 1 ){
+	if( !( ( ( ( magic = data[ ( cur_pos + 1 ) % DMASIZE ] ) & 0xffff0000 ) != 0x7f7f0000 )
+	    || data[ ( cur_pos +  data[ cur_pos  % DMASIZE ] - 1 + DMASIZE ) % DMASIZE ] != 0x7fff0006 ) ){
+	  break;
+	}
+	//	printf("MAGIC %.8x\n", magic);
+
+	//	usleep(1000); // to avoid BUSY loop
+	
+	//
+	// Refresh DMA memory
+	//
+	res = pcie40_b2dmapointerread( 0 , &data ) ;
+	int wait_flag = 0;
+	//
+	// Scan to find x"7f7f...."
+	//
+	if( cnt > 100 ){
+	  cnt = 0;
+	  int j = 0 ; 
+	  for ( j = 0 ; j < DMASIZE ; ++j ) { 
+#ifdef DEBUG	    
+	    printf("%.8x %d\n", data[ ( cur_pos + j + 1 ) % DMASIZE ], cur_pos + j );
+#endif
+	    if ( ( ( data[ ( cur_pos + j + 1 ) % DMASIZE ] & 0xffff0000 ) == 0x7f7f0000 ) ){
+	      next_eve = data[ ( cur_pos + j + 3 ) % DMASIZE ];
+	      next_exp_run =  data[ ( cur_pos + j + 2 ) % DMASIZE ] ;
+
+	      //	      printf( "TRAILER %.8x %.8x %.8x\n",data[ ( cur_pos + j + data[ ( cur_pos + j + DMASIZE ) % DMASIZE ] - 1 + DMASIZE ) % DMASIZE ] );
+
+	      if( next_eve > cur_eve && next_exp_run >= cur_exp_run ){
+		/* if( data[ ( ( data[ ( cur_pos + j + DMASIZE ) % DMASIZE ] ) - 1 + DMASIZE ) % DMASIZE ] != 0x7fff0006 ){ */
+		/*   usleep(1000); */
+		/*   break; */
+		/* } */
+		cur_pos = ( cur_pos + j + DMASIZE ) % DMASIZE;
+		size = data[ cur_pos ];
+		//		printf( "Detect new Event number prev %.8x new %.8x pos %.8x size %.8x\n" , cur_eve , next_eve, cur_pos, size );
+		break;
+	      }else{
+		//		printf( "Detect Old Event number prev %.8x new %.8x pos %d\n" , cur_eve , next_eve, ( cur_pos + j + DMASIZE ) % DMASIZE );
+		break;
+	      }
+	    }else{
+	      continue;
+	    }
+	  }
+	}
+	cnt++;
+      }
+      size = data[ cur_pos ] ;
+ 
+      next_eve = data[ ( cur_pos + 3 ) % DMASIZE ];
+      next_exp_run = data[ ( cur_pos + 2 ) % DMASIZE ];
+
+      if( first_event_flag == 0 || cur_exp_run != next_exp_run ){
+	first_event_flag = 1;
+	first_eve = next_eve;
+	crc_err_eve_cnt = 0;
+	eve_cnt = 0;
+      }
+      eve_cnt++;
+      ret = crc_calc_event( data, cur_pos );
+      if( ret != 1 ){
+	crc_err_eve_cnt++;
+      }
+
+      if(ret != 1 || eve_cnt % 100 == 0 ){
+	printf( "Event number prev %.8x new %.8x pos %.8x size %.8x\n" , cur_eve , next_eve, cur_pos, size );
+      }
+      cur_eve = next_eve;
+      cur_exp_run = next_exp_run;
+      if(ret != 1 ||  eve_cnt % 10000 == 0 ){
+	printf("STATUS : tot eve %d read eve %d err_eve %d run %d\n", next_eve - first_eve, eve_cnt, crc_err_eve_cnt, cur_exp_run );
+      }
+      mod_pos = ( cur_pos + size ) % 8;
+      if( mod_pos != 0 ){
+	cur_pos = ( cur_pos + size + DMASIZE + ( 8 - mod_pos) ) % DMASIZE ;
+      }else{
+	cur_pos = ( cur_pos + size + DMASIZE ) % DMASIZE ;
+      }
+
+    }
+
+
+    clock_t end = clock();
+    time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
+
+    ecs_close( 0 , 0 ) ;
+
+    printf( "Timing = %f s\n" , time_spent ) ;
+    printf( "Number of events = %d \n", nEvt ) ;  
+    printf( "Number of errors = %d \n", nErr ) ; 
+    printf( "Number of retries = %d \n", nRetry ) ;
+    printf( "Number of missed = %d \n", nMissed ) ;
+    return 0 ;
+  }
diff --git a/Pcie40Applications/pcie40_ul_lib.h b/Pcie40Applications/pcie40_ul_lib.h
new file mode 100644
index 0000000000000000000000000000000000000000..6f580bf8171d5bd42ddad2c7f00657df1860395b
--- /dev/null
+++ b/Pcie40Applications/pcie40_ul_lib.h
@@ -0,0 +1,59 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <time.h>
+#include "altera_dma_regs.h"
+
+extern "C" int  ecs_open(int dev, int bar);
+extern "C" void ecs_close(int dev, int bar);
+extern "C" int pcie40_b2dmabufferreset(int fd);
+extern "C" int pcie40_b2dmapointerread(int fd , unsigned int ** pData );
+extern "C" int      ecs_write(int dev, int bar, unsigned add, int val);
+
+//#define DEBUG
+
+const int CRC16_XMODEM_TABLE[] = {
+  0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
+  0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
+  0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
+  0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
+  0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
+  0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
+  0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
+  0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
+  0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
+  0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
+  0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
+  0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
+  0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
+  0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
+  0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
+  0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
+  0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
+  0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
+  0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
+  0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
+  0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
+  0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
+  0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
+  0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
+  0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
+  0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
+  0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
+  0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
+  0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
+  0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
+  0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
+  0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
+} ;
+
+
+
+int crc_calc( int * crc, unsigned int * data );
+
+int crc_calc_event( unsigned int* data, int start_pos );
+
+int decode_data_wUL( unsigned int * data , unsigned int * ce , int * crc , int * run , 
+		       int * bad , int *evn , int * retry , int * pctime , int * putime , 
+		     int * nmissed );
+int readout();
diff --git a/Pcie40Driver/altera_dma_regs.h b/Pcie40Driver/altera_dma_regs.h
index 939a3f6e34d7fc89406a78c2941d2e1382102290..e121c6cc79c76b30553be9495f3e65c348a6fb93 100644
--- a/Pcie40Driver/altera_dma_regs.h
+++ b/Pcie40Driver/altera_dma_regs.h
@@ -3,14 +3,14 @@
 
 
 #define ALTERA_DMA_DESCRIPTOR_NUM 4
-#define DMASIZE 0x2000
+#define DMASIZE 0x10000
 //#define ALTERA_STATUS_FIFO_DATA 0x50120
 //#define ALTERA_RESET_FIFO_DATA  0x50100
 #define ALTERA_STATUS_FIFO_DATA 0x0
 #define ALTERA_RESET_FIFO_DATA  0x0
 
 #define ALTERA_MEM_MAIN_BUF0_START 0x200000
-#define ALTERA_MEM_MAIN_BUF0_SIZE  0x1FFF
+#define ALTERA_MEM_MAIN_BUF0_SIZE  0xFFFF
 #define ALTERA_MEM_MAIN_BUF1_START 0x202000
 #define ALTERA_MEM_MAIN_BUF1_SIZE  0x1FFF
 #define ALTERA_MEM_MAIN_BUF2_START 0x204000
diff --git a/Pcie40Libraries/Makefile b/Pcie40Libraries/Makefile
index b37bcba0607b5da91f9cf9529be3ef50868f02c5..8969d645969d3af8b3adff0ce4c61ab5a52264fa 100644
--- a/Pcie40Libraries/Makefile
+++ b/Pcie40Libraries/Makefile
@@ -1,7 +1,7 @@
 CC=gcc -fPIC -g
 CFLAGS= -c -Wall 
 LDFLAGS=
-
+GPP = g++ -fPIC
 #defined global variables and programs to build
 include Makefile.conf
 
@@ -21,7 +21,7 @@ ECS_SRC= pcie40_ecs.c
 ECS_OBJ=$(ECS_SRC:%.c=$(OBJ_DIR)%.o)
 
 #Minipods
-MINIPODS_SRC= i2cDriver.c
+MINIPODS_SRC= i2cDriver.c avagoMinipodCtrl.c
 MINIPODS_OBJ=$(MINIPODS_SRC:%.c=$(OBJ_DIR)%.o)
 
 #LTC2990
@@ -29,7 +29,7 @@ LTC2990_SRC=
 LTC2990_OBJ=$(LTC2990_SRC:$(SRC_DIR)$(LTC2990_DIR)%.c=$(OBJ_DIR)%.o)
 
 # Belle II specific libraries (slow control, ECS, ...) 
-B2LIB_SRC= pcie40_b2slc.c pcie40_b2ecs.c pcie40_b2dma.c
+B2LIB_SRC= pcie40_b2slc.cpp pcie40_b2ecs.c pcie40_b2dma.c
 B2LIB_OBJ=$(B2LIB_SRC:%.c=$(OBJ_DIR)%.o)
 
 # static libraries
@@ -88,7 +88,7 @@ $(LTC2990_LIB) : $(LTC2990_OBJ)
 $(LLI_DYNLIB) : $(ECS_OBJ) $(MINIPODS_OBJ)
 	@echo "Construction of dynamic LLI technical Library for V2"
 	mkdir -p lib
-	$(CC) -o $(LIB_DIR)$(LLI_DYNLIB) -shared $(ECS_OBJ) $(PLL_OBJ) $(MINIPODS_OBJ) $(B2LIB_OBJ) -L $(PCIE40_DYN_LIB) -lpcie40driver_ecs
+	$(GPP) -o $(LIB_DIR)$(LLI_DYNLIB) -shared $(ECS_OBJ) $(PLL_OBJ) $(MINIPODS_OBJ) $(B2LIB_OBJ) -L $(PCIE40_DYN_LIB) -lpcie40driver_ecs
 	@echo 
 
 clean: mrproper
diff --git a/Pcie40Libraries/avagoMinipodCtrl.c b/Pcie40Libraries/avagoMinipodCtrl.c
new file mode 100644
index 0000000000000000000000000000000000000000..7921f89b077ddf77600807e07f1dea84a0b69b80
--- /dev/null
+++ b/Pcie40Libraries/avagoMinipodCtrl.c
@@ -0,0 +1,2451 @@
+/****************************************************************************************//**
+* \file				avagoMinipodCtrl.c
+*
+* \brief This file contains the user driver to control the 6 AVAGO miniPOD of the AMC40 board.
+* 
+* \author PYD : 17/4/2012
+* \version 0.1
+* \date 17/4/2012
+* \copyright (c) Copyright CERN for the benefit of the LHCb Collaboration.
+*    Distributed under the terms of the GNU General Public Licence V3.
+*    ana.py script is free and open source software.
+*
+* CHANGELOG
+*    PYD : 17/4/2012 initial version
+*    PYD : 12/6/2015 several i2c buses implemented
+*    PYD : 07/01/2016 adaptation for PCIe40
+*    PYD : 15/09/2016 add multi boards
+*    PYD : 01/10/2018 remove code for ES12 and ES3 versions
+*//********************************************************************************************/
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <math.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <linux/i2c-dev.h>
+#include <systemConfig.h>
+#include <i2cDriver.h>
+#include <avagoMinipodCtrl.h>
+
+ typedef struct {
+	int reg;
+	int quart;
+	} quartPlace;
+ /**
+ *  \var mpod_vodQuarters
+ *  \brief Channels are organized from 0 to 11. Data of channel X are at index X in the array.
+ *
+ *     The channel data are:
+ *
+ *       The register number     : tab[chnId][0]
+ *
+ *       The associated quarter  : tab[chnId][1]  (0 means low, 1 means high quarter)
+*/
+
+static quartPlace mpod_vodQuarters[12] = {
+  {MPOD_RXVOD1, 0},{MPOD_RXVOD1, 1},{MPOD_RXVOD2, 0},{MPOD_RXVOD2, 1},{MPOD_RXVOD3, 0},{MPOD_RXVOD3, 1},
+  {MPOD_RXVOD4, 0},{MPOD_RXVOD4, 1},{MPOD_RXVOD5, 0},{MPOD_RXVOD5, 1},{MPOD_RXVOD6, 0},{MPOD_RXVOD6, 1}
+ };
+ /**
+ *  \var mpod_deamphQuarters
+ *  \brief Channels are organized from 0 to 11. Data of channel X are at index X in the array.
+ *
+ *     The channel data are:
+ *
+ *       The register number     : tab[chnId][0]
+ *
+ *       The associated quarter  : tab[chnId][1]  (0 means low, 1 means high quarter)
+*/
+static quartPlace mpod_deamphQuarters[12] = {
+  {MPOD_RXDEAMPH1, 0},{MPOD_RXDEAMPH1, 1},{MPOD_RXDEAMPH2, 0},{MPOD_RXDEAMPH2, 1},{MPOD_RXDEAMPH3, 0},{MPOD_RXDEAMPH3, 1},
+  {MPOD_RXDEAMPH4, 0},{MPOD_RXDEAMPH4, 1},{MPOD_RXDEAMPH5, 0},{MPOD_RXDEAMPH5, 1},{MPOD_RXDEAMPH6, 0},{MPOD_RXDEAMPH6, 1}
+ };
+ /**
+ *  \var mpod_equalzQuarters
+ *  \brief Channels are organized from 0 to 11. Data of channel X are at index X in the array.
+ *
+ *     The channel data are:
+ *
+ *       The register number     : tab[chnId][0]
+ *
+ *       The associated quarter  : tab[chnId][1]  (0 means low, 1 means high quarter)
+*/
+static quartPlace mpod_equalzQuarters[12] = {
+  {MPOD_TXEQUALZ1, 0},{MPOD_TXEQUALZ1, 1},{MPOD_TXEQUALZ2, 0},{MPOD_TXEQUALZ2, 1},{MPOD_TXEQUALZ3, 0},{MPOD_TXEQUALZ3, 1},
+  {MPOD_TXEQUALZ4, 0},{MPOD_TXEQUALZ4, 1},{MPOD_TXEQUALZ5, 0},{MPOD_TXEQUALZ5, 1},{MPOD_TXEQUALZ6, 0},{MPOD_TXEQUALZ6, 1}
+ };
+/**
+ *  \var mpod_ampControlCodes
+ *  \brief Receiver output Amplitude - Default De-Amphasis given in mVppd unit
+ *
+ *     The they are 8 possible code values x = 0 to 7:
+ *
+ *     For each code we have the Min value tab[x][0], Nominal value tab[x][1], Max Value tab[x][2]
+ *
+ *     Note: another way to get the nominal value without this array is to compute (code+1)*100
+*/
+static unsigned mpod_ampControlCodes[][3] = {
+	{ 70,100,130},
+	{150,200,250},
+	{240,300,360},
+	{320,400,480},
+	{400,500,600},/*default*/
+	{480,600,720},
+	{560,700,840},
+	{640,800,960}/*full scale*/
+	};
+/**
+ *  \var mpod_equalizationCodes
+ *  \brief Transmitter equalization control
+ *
+ *     The they are 8 possible code values x = 0 to 7:
+ *
+ *     For each code we have the Peak value tab[x][0], Midband value tab[x][1], Peak vs Midband Value tab[x][2]
+ *
+*/
+static float mpod_equalizationCodes[][3] = {
+	{0.3 ,-0.1 ,0.4 },
+	{1.3 ,-0.9 ,2.2 },
+	{2.1 ,-1.8 ,3.9 },
+	{3.05,-3.05,6.1 },
+	{4.1 ,-4.7 ,8.8 },
+	{5.0 ,-6.6 ,11.6},
+	{5.6 ,-8.3 ,13.9},
+	{6.1 ,-10.6,16.7}
+	};
+/* CHECK HOW THE READ WRITE BIT IS MANAGED IN THE DRIVER
+# For TX the address is 0101hjkx (hjk is hard add) (x is 1=R 0=W)
+# For RX the address is 0110hjkx (hjk is hard add) (x is 1=R 0=W)
+# NOTE the x is added in Read/Write function into the driver so don't use it here
+# partern 0 +   0101/TX or 0110/RX + fixAdd on 3digits
+
+minipod devices devices addresses */
+/**
+ *  \var mpod_devAdd
+ *  \brief The i2c addresses of the 8 channels controlers.
+ *
+*/
+static unsigned mpod_devAdd[8] = { 
+/* FR
+  0x30,   //!<sRX GBT add(0) 0b 0011 0000  
+  0x2a,   //!<sTX GBT add(1) 0b 0010 1010  
+  0x31,   //!<sRX GBT add(2) 0b 0011 0001  
+  0x2b,   //!<sTX GBT add(3) 0b 0010 1011  
+  0x32,   //!<sRX GBT add(4) 0b 0011 0010  
+  0x2c,   //!<sTX Gbe add(5) 0b 0010 1100  
+  0x33,   //!<sRX Gbe add(6) 0b 0011 0011  
+  0x2d,   //!<sTX Gbe add(7) 0b 0010 1101  
+*/
+/* MJ */ 
+  0x30, //!<sRX GBT add(0) 0b 0011 0000 
+  0x28, //!<sTX GBT add(1) 0b 0010 1000 
+  0x31, //!<sRX GBT add(2) 0b 0011 0001 
+  0x29, //!<sTX GBT add(3) 0b 0010 1001 
+  0x32, //!<sRX GBT add(4) 0b 0011 0010 
+  0x2a, //!<sTX Gbe add(5) 0b 0010 1010 
+  0x33, //!<sRX Gbe add(6) 0b 0011 0011 
+  0x2b, //!<sTX Gbe add(7) 0b 0010 1011 
+};
+
+static int mpod_rx[8] = {1, 0, 1, 0, 1, 0, 1, 0};
+static int mpod_tx[8] = {0, 1, 0, 1, 0, 1, 0, 1};
+
+static int mpod_scriptMode = 0; // mode of printing: 0 for human users else for script scanning
+static int mpod_hideText = 0;
+
+/***********************************************************************//**
+ * \fn int mpod_setMode()
+ * \brief Function to set the mode in which the data will be formatted on stdout.
+ *       
+ * By default the mode is 0 fir human typing the command in a system console.
+ * Comments and pretty printings are used to make it easy for a human user 
+ * to read the command results.
+ * In the other mode the results are output in a minimalist comma separated values
+ * which can be easily scanned by a scripting program.
+ *
+ * \param   mode: 0 human oriented, other for script scanning
+ *//***********************************************************************/
+ int mpod_setMode(int mode){
+ 	mpod_scriptMode=mode;
+	return(0);
+ }
+
+ int mpod_setTextMode(int mode){
+ 	mpod_hideText=mode;
+	return(0);
+ }
+
+/***********************************************************************//**
+ * \fn int mpod_init(int dev)
+ * \brief Function to init the avago i2c bus.
+ *      This function has to be done before any i2c access to minipods
+ *       
+ * Function to program the prescale the SCL clock line. Should be called
+ *        before the I2C use.
+ *
+ * \param   inCLK: the input system clock ferquency in Hz
+ * \param SCLfreq: the target SCL clock frequency in Hz
+ * \return 0 success, -1 error
+ *//***********************************************************************/
+int mpod_init(int dev, unsigned inCLK, unsigned SCLfreq){
+    return( i2c_init(dev, I2C_BUS_MINIPODS, inCLK, SCLfreq) );
+}
+/***********************************************************************//**
+ * \fn void mpod_getInit(int dev)
+ * \brief Reads the last values in the prescale of the SCL clock line.
+ *       
+ *
+ * \param   inCLK: the system clock ferquency in Hz
+ * \param SCLfreq: the target SCL clock frequency in Hz
+ *//***********************************************************************/
+void mpod_getInit(int dev, unsigned *inCLK, unsigned *SCLfreq){
+    i2c_getInit(dev, I2C_BUS_MINIPODS, inCLK, SCLfreq);
+}
+/**************************************************************************//**
+ * \fn int mpod_exist(int mpid)
+ * \brief Function to check if the given minipod exists
+ *
+ * \param mpid : the minipod number 0-7
+ * \return 0 no, 1 yes
+ *//**************************************************************************/
+int mpod_exists(int mpid){
+	if ((mpid<0) || (mpid>7)){
+		printf("ERROR: minipod munber %d is not between 0 and 7\n",mpid);
+		return(0);
+	}
+return 1;
+}
+/**************************************************************************//**
+ * \fn int mpod_add(int mpid, unsigned *add)
+ * \brief Function to get the I2C address of a given minipod
+ *
+ * \param mpid : the minipod number 0-7
+ * \param add  : a pointer where to get the adress
+ * \return 0 success, -1 error
+ *//**************************************************************************/
+static int mpod_add(int mpid, unsigned *add){
+	if (!mpod_exists(mpid))
+		return(-1);
+	*add = mpod_devAdd[mpid];
+return 0;
+}
+/**************************************************************************//**
+ * \fn int mpod_isTX(int mpid)
+ * \brief Function to test if a minipod is a transmitter
+ *
+ * \param mpid : the minipod number 0-7
+ * \return 1=yes, 0=no
+ *//**************************************************************************/
+int mpod_isTX(int mpid){
+	if (!mpod_exists(mpid))
+		return(-1);
+return(mpod_tx[mpid]);
+}
+/**************************************************************************//**
+ * \fn int mpod_isRX(int mpid)
+ * \brief Function to test if a minipod is a receiver
+ *
+ * \param mpid : the minipod number 0-7
+ * \return 1=yes, 0=no
+ *//**************************************************************************/
+int mpod_isRX(int mpid){
+	if (!mpod_exists(mpid))
+		return(-1);
+return(mpod_rx[mpid]);
+}
+/*********************************************************************//**
+ * \fn int mpod_write(int dev, int mpid, char reg, unsigned val)
+ * \brief Function to write val at register reg in minipod number mpid
+ *
+ * \param mpid: the target minipod
+ * \param  reg: the device register
+ * \param  val: the value to write (4bytes)
+ * \return 0 success, -1 error
+ *//*********************************************************************/
+int mpod_write(int dev, int mpid, char reg, unsigned val){
+	unsigned add;
+	int ret;
+	
+	if(mpod_add(mpid, &add)!=0)
+		return(-1);
+
+	ret = i2c_writeMem(dev, I2C_BUS_MINIPODS, add, reg, &val);
+	usleep(10000); // not clean but tested as usefull
+	return (ret);
+}
+/******************************************************//**
+ * \fn int mpod_read(int dev, int mpid, char reg, unsigned *val)
+ * \brief Function to read register reg and get value in val
+ *
+ * \param mpid: the target minipod
+ * \param  reg: the device register
+ * \param  val: a ptr to a word to receive the value(4bytes)
+ * \return 0 success, -1 error
+ *//******************************************************/
+int mpod_read(int dev, int mpid, char reg, unsigned *val){
+	unsigned add;
+
+	if(mpod_add(mpid, &add)!=0)
+		return(-1);
+
+	return( i2c_readMem(dev, I2C_BUS_MINIPODS, add, reg, val) );
+}
+/********************************************************************//**
+ * \fn int mpod_readBloc(int dev, int file , int index , int nb, unsigned *data)
+ * \brief Function to select the used memory page
+ *
+ * This function malloc the space to put the data in. The user should
+ * free it after use.
+ *
+ * \param mpid : the target minipod number 0 to 7
+ * \param index: the start register index
+ * \param    nb: the number of registers to read
+ * \param  data: a pointer to an array to receive the read values
+ * \return 0 success, -1 error
+ *//********************************************************************/
+int mpod_readBloc(int dev, int mpid , int index , int nb , unsigned **data){
+	unsigned add;
+
+	if(mpod_add(mpid, &add)!=0)
+		return(-1);
+//	printf("PYD read on bus %d at add 0x%x reg index %d for %d words\n",I2C_BUS_Minipod, add, index, nb);
+	return( i2c_multReadMem(dev, I2C_BUS_MINIPODS, add, index, nb, data) );
+}
+/******************************************************//**
+ * \fn int mpod_pageSelect(int dev, int mpid, int page)
+ * \brief Function to select the used memory page
+ *
+ * \param mpid: the target minipod
+ * \param page: the selected page id (0 or 1)
+ * \return 0 success, -1 error
+ *//******************************************************/
+int mpod_pageSelect(int dev, int mpid , unsigned page) {
+	unsigned val;
+	if ((page<0) || (page >1)){
+		printf("ERROR: MPOD page number should be 0 or 1 not %d\n", page);
+		return(-1);
+	}
+	// read the current value
+//	printf("Setting page %d for minipod %d\n", page, mpid);
+	mpod_write(dev, mpid, MPOD_PAGEREG, page);
+	mpod_read(dev,  mpid, MPOD_PAGEREG, &val);
+	if (val!=page){
+		printf("ERROR: page selection on mpod %d failed\n", mpid);
+		return(-1);
+	}
+//	printf("Current page is now %d for minipod %d\n",val, mpid);
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_get12IntData(int(*get)(int,int**), int mpid, int *data)
+ * \brief Function to wrap other functions to get the 12 channels data of a minipod in python
+ *
+ * Function to avoid to have to manage dynamically allocated arrays in the python wrapper.
+ * used for getVOD, getDeamphasis, getEqualization
+ *
+ * \param mpid: the target RX minipod component 0, 2, 4 and 6 (RX)
+ * \param data: a pointer to an already allocated array of 12 code values
+ *              (chn 0 to 11) that the user will have to freed after use.
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+static int mpod_get12IntData(int dev,int(*get)(int,int,int**),int mpid, int *data){
+	int *bloc;
+	int i, status;
+	status = get(dev,mpid, &bloc);
+	if (status==0){
+	
+		for (i=0; i<12; i++)
+			data[i]=bloc[i];
+		free(bloc);
+	}
+	return(status);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_get12FloatData(int(*get)(int,float**), int mpid, float *data)
+ * \brief Function to wrap other functions to get the 12 channels data of a minipod in python
+ *
+ * Function to avoid to have to manage dynamically allocated arrays in the python wrapper.
+ * used for biasCurrent, lightOutput, lightInput
+ *
+ * \param mpid: the target RX minipod component 0, 2, 4 and 6 (RX)
+ * \param data: a pointer to an already allocated array of 12 code values
+ *              (chn 0 to 11) that the user will have to freed after use.
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+static int mpod_get12FloatData(int dev, int(*get)(int,int,float**),int mpid, float *data){
+	float *bloc;
+	int i, status;
+	status = get(dev, mpid, &bloc);
+	if (status==0){
+		for (i=0; i<12; i++)
+			data[i]=bloc[i];
+		free(bloc);
+	}
+	return(status);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_setBitIn12bitsOn2words (int dev, int mpid, int channel, int flag
+ 													unsigned word1, unsigned word2,
+ 													char *regMsg,
+													(int)(*filter)(int))
+ * \brief Function to set or unset a bit for a channel in a representation spanning on
+ *        2 contiguous 8 bits registers.
+ *
+ * \param mpid   : the target minipod component 0 to 5
+ * \param channel: the target channel 0 to 12
+ * \param flag   : 0=enable  1=disable
+ * \param word1  : low number register with bits for channels 8 to 11
+ * \param word2  : high number register with bits for channels 0 to 7
+ * \param regMsg : string identifying the register function
+ * \param filter : filtering function for the type of minipod
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+static int mpod_setBitIn12bitsOn2words(int dev, int mpid, int channel, int flag, 
+											unsigned word1, unsigned word2,
+											char *regMsg,
+											int(*filter)(int) ){
+int shift;
+unsigned reg, cval, val;
+
+if (filter)
+ if (!filter(mpid)){
+ 	printf("ERROR: %s only for TX minipods\n", regMsg);
+ 	return(-1);
+ }
+ if (channel<8){
+	reg = word2;
+	shift = channel;
+	}
+ else if (channel<=12) {
+	reg = word1;
+	shift = channel - 8;
+	}
+ else {
+	printf("ERROR : channel should be in <0-11>\n");
+	return(-1);
+ }
+ mpod_read(dev, mpid, reg, &cval);
+ if (flag){ //disable
+	val = cval | (1<<shift);
+	if (mpod_write(dev, mpid, reg, val)){
+		printf("ERROR: can't %s for channel %d in minipod %d board %d\n", regMsg, channel, mpid, dev);
+		return(-1);
+  }
+ } 
+ else { //enable
+	val = cval & ~(1<<shift);
+	if (mpod_write(dev, mpid, reg, val)){
+		printf("ERROR: can't %s for channel %d in minipod %d board %d\n", regMsg, channel, mpid, dev);
+		return(-1);
+	}
+ }
+return(0);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_dumpAllBitsIn12bitsOn2words (int dev, int mpid, 
+ 													unsigned word1, unsigned word2,
+ 													char *regMsg,
+													(int)(*filter)(int))
+ * \brief Function to dump all values coded as 1 bits per channel in 2 contiguous 8 bits registers.
+ *
+ * \param mpid   : the target minipod component 0 to 7
+ * \param word1  : low number register with bits for channels 8 to 11
+ * \param word2  : high number register with bits for channels 0 to 7
+ * \param regName: string identifying the register function
+ * \param filter : filtering function for the type of minipod
+ * \param no     : character for 0
+ * \param yes    : character for 1
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+static int mpod_dumpAllBitIn12bitsOn2words(int dev, int mpid, 
+											unsigned word1, unsigned word2,
+											char *regName,
+											int(*filter)(int),
+											char no, char yes ){
+	unsigned val;
+	int ch;
+	
+	if (filter)
+	 if (filter(mpid)){
+		printf("ERROR: %s registers not available for this type of minipod\n", regName);
+		return(0);
+	}
+	if (!mpod_scriptMode){
+		for (ch=0; ch<12; ch++) printf("---");
+			printf("\n");
+		printf("minipod %d %s\n", mpid, regName);
+		for (ch=0; ch<12; ch++) printf("---");
+		printf("\n");
+		for (ch=0; ch<12; ch++) printf("%2d ",ch);
+		printf("\n");	
+		for (ch=0; ch<12; ch++) printf("---");
+		printf("\n");
+	}
+	if (mpod_read(dev, mpid, word2, &val )){
+		printf("ERROR: MPOD can't read %s register 2 on i2c bus\n", regName);
+		return(-1);
+	}
+	if (!mpod_scriptMode){
+		for (ch=0; ch<8; ch++){
+			if ( (val & (1<<ch)) != 0 ) printf(" %c ",yes);
+			else                        printf(" %c ",no);
+		}
+	} else {
+		for (ch=0; ch<8; ch++){
+			if ( (val & (1<<ch)) != 0 ) printf("%c,",yes);
+			else                        printf("%c,",no);
+		}	
+	}
+	if (mpod_read(dev, mpid, word1, &val )){
+		printf("ERROR: MPOD can't read %s register 1 on i2c bus\n", regName);
+		return(-1);
+	}
+	if (!mpod_scriptMode){
+		for (ch=8; ch<12; ch++){
+			if ( (val & (1<<(ch-8))) != 0 ) printf(" %c ",yes);
+			else                            printf(" %c ",no);
+		}
+	} else {
+		for (ch=8; ch<12; ch++){
+			if ( (val & (1<<(ch-8))) != 0 ) ch==11 ? printf("%c",yes): printf("%c,",yes);
+			else                            ch==11 ? printf("%c",no): printf("%c,",no);
+		}	
+	}
+	printf("\n");
+	if (!mpod_scriptMode){
+		for (ch=0; ch<12; ch++) printf("---");
+			printf("\n");
+	}
+	return(0);
+}
+
+/*****************************************************************************************//**
+ * \fn int mpod_mkListBitsIn12bitsOn2words (int dev, int mpid, 
+ 													unsigned word1, unsigned word2,
+                                       char *regName,
+													(int)(*filter)(int),
+                                       char no,
+                                       char yes,
+                                       char **data)
+ * \brief Function to list all values coded as 1 bits per channel in 2 contiguous 8 bits registers.
+ *
+ * The first register has 8 bits and the second 4 bits.
+ *
+ * This function is used by the python wrapper
+ *
+ * \param mpid   : the target minipod component 0 to 7
+ * \param word1  : low number register with bits for channels 8 to 11
+ * \param word2  : high number register with bits for channels 0 to 7
+ * \param filter : filtering function for the type of minipod
+ * \param no     : character for 0
+ * \param yes    : character for 1
+ * \param data   : the comma separated values in a string allocated by this function that should be freed
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+static int mpod_mkListBitIn12bitsOn2words(int dev, int mpid, 
+                                          unsigned word1, unsigned word2,
+                                          char *regName,
+                                          int(*filter)(int),
+                                          char no, char yes,
+                                          char **data ){
+	unsigned val;
+	int ch;	
+        char *str;
+	
+	// Allocate the memory to make a string
+	if (!(str = malloc(50))) { // 12 value with , except last followed by \n
+		printf("ERROR: Can't malloc memory for 12 comma separated values\n");
+		return(-1);
+	}
+	for  (ch=0; ch<50; ch++)
+	    str[ch] = '\n';
+	    
+	if (filter)
+	 if (filter(mpid)){
+		printf("ERROR: %s registers not available for this type of minipod\n", regName);
+		return(0);
+	}
+	if (mpod_read(dev, mpid, word2, &val )){
+		printf("ERROR: MPOD can't read %s register 2 on i2c bus\n", regName);
+		return(-1);
+	}
+	for (ch=0; ch<8; ch++){
+		if ( (val & (1<<ch)) != 0 ) {
+		    sprintf(str+2*ch,"%c,",yes);
+		}
+		else{
+		    sprintf(str+2*ch,"%c,",no);
+		}
+	}	
+	if (mpod_read(dev, mpid, word1, &val )){
+		printf("ERROR: MPOD can't read %s register 1 on i2c bus\n", regName);
+		return(-1);
+	}
+	for (ch=8; ch<12; ch++){
+		if ( (val & (1<<(ch-8))) != 0 ) {
+		    if (ch == 11){
+		        sprintf(str+2*ch,"%c",yes);
+		    }
+		    else {
+		        sprintf(str+2*ch,"%c,",yes);
+		        }      
+		}
+		else {
+		    if (ch == 11){
+		        sprintf(str+2*ch,"%c",no);
+		        }
+		        
+		    else {
+		        sprintf(str+2*ch,"%c,",no);
+		        }
+		}
+	}
+	*data = str;
+	return(0);
+}
+/********************************************************************//**
+ * \fn int mpod_getVendorName(int dev, int mpid , char **bloc)
+ * \brief Function read the vendor name from register 152 to 167
+ *
+ * \param mpid : the target minipod component 0 to 7
+ * \param bloc : a pointer to an array to receive the read values
+ *         The bloc is allocated by the function and should be freed
+ *         by the user
+ * \return 0 success, -1 error
+ *//********************************************************************/
+int mpod_getVendorName(int dev, int mpid, char **bloc){
+	int i;
+	char     *chdata; // allocated here tp make conversion from unsigned to char
+	unsigned *data;   // will be allocated by the called function
+	int size =   MPOD_NBVENDORNAME+1;
+
+	// Allocate the memory to make a string
+	if (!(chdata = malloc(size+1))) {
+		printf("ERROR: Can't malloc memory for vendor data\n");
+		return(-1);
+	}
+	// get data
+	if ( mpod_readBloc(dev, mpid , MPOD_VENDORNAMEREG , size , &data )!=0){
+		printf("ERROR: MPOD can't read vendor name on i2c bus\n");
+		return(-1);
+	}
+
+	for (i=0; i<MPOD_NBVENDORNAME; i++){
+		chdata[i] = (char)data[i];
+	}
+
+	chdata[i]='\0';	
+	free(data);
+	*bloc = chdata;
+	return(0);
+}
+/********************************************************************//**
+ * \fn int mpod_getVendorOUI(int dev, int mpid , char **bloc)
+ * \brief Function read the vendor OUIom register 168 to 170
+ *
+ * Attention: the characters returned are not printable but values
+ * to print as hexa digits to be interpreted.
+ *
+ * \param mpid : the target minipod component 0 to 7
+ * \param bloc : a pointer to an array to receive the read values
+ *         The bloc is allocated by the function and should be freed
+ *         by the user
+ * \return 0 success, -1 error
+ *//********************************************************************/
+int mpod_getVendorOUI(int dev, int mpid, char **bloc){
+	int i;
+	char     *chdata; // allocated here tp make conversion from unsigned to char
+	unsigned *data;   // will be allocated by the called function
+	int size =   MPOD_NBVENDOROUI+1;
+
+	// Allocate the memory to make a string
+	if (!(chdata = malloc(size+1))) {
+		printf("ERROR: Can't malloc memory for vendor OUI data\n");
+		return(-1);
+	}
+	// get data
+	if ( mpod_readBloc(dev, mpid , MPOD_VENDOROUIREG , size , &data )!=0){
+		printf("ERROR: MPOD can't read vendor OUI on i2c bus\n");
+		return(-1);
+	}
+	for (i=0; i<MPOD_NBVENDOROUI; i++){
+		chdata[i] = (char)data[i];
+	}
+	free(data);
+	*bloc = chdata;
+	return(0);
+}
+/********************************************************************//**
+ * \fn int mpod_getVendorPartNumber(int dev, int mpid , char **bloc)
+ * \brief Function read the vendor part number from register 171 to 186
+ *
+ * \param mpid : the target minipod component 0 to 7
+ * \param bloc : a pointer to an array to receive the read values
+ *         The bloc is allocated by the function and should be freed
+ *         by the user
+ * \return 0 success, -1 error
+ *//********************************************************************/
+int mpod_getVendorPartNumber(int dev, int mpid, char **bloc){
+	int i;
+	char     *chdata; // allocated here tp make conversion from unsigned to char
+	unsigned *data;   // will be allocated by the called function
+	int size =   MPOD_NBVENDORPART+1;
+
+	// Allocate the memory to make a string
+	if (!(chdata = malloc(size+1))) {
+		printf("ERROR: Can't malloc memory for vendor part number data\n");
+		return(-1);
+	}
+	// get data
+	if ( mpod_readBloc(dev, mpid , MPOD_VENDORPARTREG , size , &data )!=0){
+		printf("ERROR: MPOD can't read vendor part number on i2c bus\n");
+		return(-1);
+	}
+	for (i=0; i<MPOD_NBVENDORPART; i++){
+		chdata[i] = (char)data[i];
+	}
+	chdata[i]='\0';
+	free(data);
+	*bloc = chdata;
+	return(0);
+}
+/********************************************************************//**
+ * \fn int mpod_getVendorRevNumber(int dev, int mpid , char **bloc)
+ * \brief Function read the revision number from register 187 to 188
+ *
+ * \param mpid : the target minipod component 0 to 7
+ * \param bloc : a pointer to an array to receive the read values
+ *         The bloc is allocated by the function and should be freed
+ *         by the user
+ * \return 0 success, -1 error
+ *//********************************************************************/
+int mpod_getVendorRevNumber(int dev, int mpid, char **bloc){
+	int i;
+	char     *chdata; // allocated here tp make conversion from unsigned to char
+	unsigned *data;   // will be allocated by the called function
+	int size =   MPOD_NBVENDORREV+1;
+
+	// Allocate the memory to make a string
+	if (!(chdata = malloc(size+1))) {
+		printf("ERROR: Can't malloc memory for vendor revision number data\n");
+		return(-1);
+	}
+	// get data
+	if ( mpod_readBloc(dev, mpid , MPOD_VENDORREVREG , size , &data )!=0){
+		printf("ERROR: MPOD can't read vendor revision number on i2c bus\n");
+		return(-1);
+	}
+	for (i=0; i<MPOD_NBVENDORREV; i++){
+		chdata[i] = (char)data[i];
+	}
+	chdata[i]='\0';
+	free(data);
+	*bloc = chdata;
+	return(0);
+}
+/********************************************************************//**
+ * \fn int mpod_getVendorSerialNumber(int dev, int mpid , char **bloc)
+ * \brief Function read the vendor serial number from register 189 to 204
+ *
+ * \param mpid : the target minipod component 0 to 7
+ * \param bloc : a pointer to an array to receive the read values
+ *         The bloc is allocated by the function and should be freed
+ *         by the user
+ * \return 0 success, -1 error
+ *//********************************************************************/
+int mpod_getVendorSerialNumber(int dev, int mpid, char **bloc){
+	int i;
+	char     *chdata; // allocated here tp make conversion from unsigned to char
+	unsigned *data;   // will be allocated by the called function
+	int size =   MPOD_NBVENDORSER+1;
+
+	// Allocate the memory to make a string
+	if (!(chdata = malloc(size+1))) {
+		printf("ERROR: Can't malloc memory for vendor serial number data\n");
+		return(-1);
+	}
+	// get data
+	if ( mpod_readBloc(dev, mpid , MPOD_VENDORSERREG , size , &data )!=0){
+		printf("ERROR: MPOD can't read vendor serial number on i2c bus\n");
+		return(-1);
+	}
+	for (i=0; i<MPOD_NBVENDORSER; i++){
+		chdata[i] = (char)data[i];
+	}
+	chdata[i]='\0';
+	free(data);
+	*bloc = chdata;
+	return(0);
+}
+/********************************************************************//**
+ * \fn int mpod_getVendorDate(int dev, int mpid , char **bloc)
+ * \brief Function read the vendor date from register 205 to 212
+ *
+ * \param mpid : the target minipod component 0 to 7
+ * \param bloc : a pointer to an array to receive the read values
+ *         The bloc is allocated by the function and should be freed
+ *         by the user
+ * \return 0 success, -1 error
+ *//********************************************************************/
+int mpod_getVendorDate(int dev, int mpid, char **bloc){
+	int i;
+	char     *chdata; // allocated here tp make conversion from unsigned to char
+	unsigned *data;   // will be allocated by the called function
+	int size =   MPOD_NBVENDORDATE+1;
+
+	// Allocate the memory to make a string
+	if (!(chdata = malloc(size+1))) {
+		printf("ERROR: Can't malloc memory for vendor date data\n");
+		return(-1);
+	}
+	// get data
+	if ( mpod_readBloc(dev, mpid , MPOD_VENDORDATEREG , size , &data )!=0){
+		printf("ERROR: MPOD can't read vendor date on i2c bus\n");
+		return(-1);
+	}
+	for (i=0; i<MPOD_NBVENDORDATE; i++){
+		chdata[i] = (char)data[i];
+	}
+	chdata[i]='\0';
+	free(data);
+	*bloc = chdata;
+	return(0);
+}
+/********************************************************************//**
+ * \fn int mpod_dumpVendorData(int dev, int mpid)
+ * \brief Function print the vendor data of a minipod
+ *
+ * \param mpid : the target minipod component 0 to 7
+ * \return 0 success, -1 error
+ *//********************************************************************/
+int mpod_dumpVendorData(int dev, int mpid){
+	int i;
+	char *bloc;
+	
+	if (!mpod_scriptMode){
+		printf("----------------------\n");
+		printf("minipod %d vendor data\n",  mpid);
+		printf("----------------------\n");
+	};
+	if (mpod_getVendorName(dev, mpid, &bloc)==-1) return(-1);
+	else {
+		printf("vendor name     :%s\n", bloc);
+		free(bloc);
+	}
+	if (mpod_getVendorOUI(dev, mpid, &bloc)==-1) return(-1);
+	else {
+		printf("vendor OUI      :");
+		for (i=0; i<MPOD_NBVENDOROUI; i++)
+			printf("0x%02xh ",bloc[i]);
+		printf("\n");
+		free(bloc);
+	}
+	if (mpod_getVendorPartNumber(dev, mpid, &bloc)==-1) return(-1);
+	else {
+		printf("part number     :%s\n", bloc);
+		free(bloc);
+	}
+	if (mpod_getVendorRevNumber(dev, mpid, &bloc)==-1) return(-1);
+	else {
+		printf("revision number :%s\n", bloc);
+		free(bloc);
+	}
+	if (mpod_getVendorSerialNumber(dev, mpid, &bloc)==-1) return(-1);
+	else {
+		printf("serial number   :%s\n", bloc);
+		free(bloc);
+	}
+	if (mpod_getVendorDate(dev, mpid, &bloc)==-1) return(-1);
+	else {
+		printf("date            :%s\n", bloc);
+		free(bloc);
+	}
+	return(0);
+}
+/********************************************************************//**
+ * \fn int mpod_getVendorData(int dev, int mpid)
+ * \brief Function to get a string with the vendor data of a minipod
+ *
+ * Function used in the python wrapper
+ *
+ * \param mpid : the target minipod component 0 to 7
+ * \param data : the vendor data's string allocated here that should be
+ * \param        by the caller              
+ * \return 0 success, -1 error
+ *//********************************************************************/
+int mpod_getVendorData(int dev, int mpid, char **data){
+	int i;
+	char *bloc;
+	char *str;
+	
+	if ((str = malloc(1000))==0){
+		printf("ERROR: Can't malloc memory to build the vendor data info string\n");
+		return(-1);
+	}
+	sprintf(str+strlen(str),"minipod:%d,", mpid);
+	if (mpod_getVendorName(dev, mpid, &bloc)==-1) return(-1);
+	else {
+		sprintf(str+strlen(str),"vendor-name:%s,", bloc);
+		free(bloc);
+	}
+	if (mpod_getVendorOUI(dev, mpid, &bloc)==-1) return(-1);
+	else {
+		sprintf(str+strlen(str),"vendor-OUI:");
+		for (i=0; i<MPOD_NBVENDOROUI; i++)
+			sprintf(str+strlen(str),"0x%02xh ",bloc[i]);
+		sprintf(str+strlen(str),",");
+		free(bloc);
+	}
+	if (mpod_getVendorPartNumber(dev, mpid, &bloc)==-1) return(-1);
+	else {
+		sprintf(str+strlen(str),"part-number:%s,", bloc);
+		free(bloc);
+	}
+	if (mpod_getVendorRevNumber(dev, mpid, &bloc)==-1) return(-1);
+	else {
+		sprintf(str+strlen(str),str+strlen(str),"revision-number:%s,", bloc);
+		free(bloc);
+	}
+	if (mpod_getVendorSerialNumber(dev, mpid, &bloc)==-1) return(-1);
+	else {
+		sprintf(str+strlen(str),"serial-number:%s,", bloc);
+		free(bloc);
+	}
+	if (mpod_getVendorDate(dev, mpid, &bloc)==-1) return(-1);
+	else {
+		sprintf(str+strlen(str),"date:%s", bloc);
+		free(bloc);
+	}
+	*data = str;
+	return(0);
+}
+/*********************************************************************************//**
+ * \fn int mpod_squelchDisable(int dev, int mpid , int channel , int disable)
+ * \brief Function to disable/enable squelch on one channel of a component
+ *
+ * \param mpid   : the target minipod component 0 to 7
+ * \param channel: the channel number 0-11
+ * \param disable: the flag 1=disable 0=enable
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+int mpod_squelchDisable(int dev, int mpid , int channel , int disable){
+
+char regMsg[]="squelch disable";
+return (mpod_setBitIn12bitsOn2words(dev, mpid, 
+												channel, 
+												disable, 
+												MPOD_SQUELCHREG1, 
+												MPOD_SQUELCHREG2,
+												regMsg, 
+												NULL));
+}
+/*********************************************************************************//**
+ * \fn int mpod_squelchDisableAll(int dev, int mpid , int disable)
+ * \brief Function to disable/enable squelch on all channels of a component
+ *
+ * \param mpid   : the target minipod component 0 to 7
+ * \param disable: the flag 1=disable 0=enable
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+int mpod_squelchDisableAll(int dev, int mpid, int disable){
+	int mask;
+	if (disable){
+		printf("Switching squelch to OFF on ALL channels of component %d\n", mpid);
+		mask = 0xff;
+		if (mpod_write(dev, mpid, MPOD_SQUELCHREG2, mask)){
+			printf("ERROR: MPOD can't write squelch register on i2c bus\n");
+			return(-1);
+		};
+		mpod_write(dev, mpid, MPOD_SQUELCHREG1, mask); /*also write useless high quarter doesn't harm*/
+	} else {
+		printf("Switching squelch to ON on ALL channels of component %d\n", mpid);
+		mask = 0x0;
+		if (mpod_write(dev, mpid, MPOD_SQUELCHREG2, mask)){
+			printf("ERROR: MPOD can't write squelch register on i2c bus\n");
+			return(-1);
+		};
+		mpod_write(dev, mpid, MPOD_SQUELCHREG1, mask); /*also write useless high quarter doesn't harm*/
+	}
+	return(0);
+}
+/*********************************************************************************//**
+ * \fn int mpod_squelchDumpAll(int dev, int mpid)
+ * \brief Function to dump the value of squelch enabled status for all channels
+ *
+ * \param mpid: the target minipod component 0 to 7
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+int mpod_squelchDumpAll(int dev, int mpid){
+char regName[]="Squelch enable/disable";
+
+return mpod_dumpAllBitIn12bitsOn2words(dev, mpid, 
+											MPOD_SQUELCHREG1, MPOD_SQUELCHREG2,
+											regName,
+											NULL,
+											'e','d');
+}
+/*********************************************************************************//**
+ * \fn int mpod_dumpErrStatusValues(int dev, int mpid)
+ * \brief Function to dump the data not ready, int, los and faul  status of one minipod
+ *
+ * \param mpid: the target minipod component 0 to 7
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+static int mpod_dumpErrStatusValues(int dev, int mpid){
+unsigned val;
+	if (mpod_read(dev, mpid, MPOD_ERRORSTAT, &val )){
+		printf("ERROR: MPOD can't read error status register on i2c bus\n");
+		return(-1);
+	}
+	if (!mpod_scriptMode){
+		if (mpod_isTX(mpid))
+			printf("!  %d   !  %d    !  %d  !  %d  !        %d       !\n", mpid, 3>(val&0x8), 2>(val&0x4), 1>(val&0x2), val&01);
+		else
+			printf("!  %d   !  *    !  %d  !  %d  !        %d       !\n",  mpid,              2>(val&0x4), 1>(val&0x2), val&01);
+	} else {
+		if (mpod_isTX(mpid))
+			printf("%d,%d,%d,%d,%d\n", mpid, 3>(val&0x8), 2>(val&0x4), 1>(val&0x2), val&01);
+		else
+			printf("%d,*,%d,%d,%d\n",  mpid,              2>(val&0x4), 1>(val&0x2), val&01);		
+	}
+	
+	return 0;
+}
+/*********************************************************************************//**
+ * \fn int mpod_getErrStatus(int dev, int mpid, char **data)
+ * \brief Function to get the data not ready,int,los and faul status of one minipod
+ *
+ * Function used by the python wrapper
+ * \param mpid: the target minipod component 0 to 7
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+int mpod_getErrStatus(int dev, int mpid, char **data){
+unsigned val;
+char *str;
+	if ((str = malloc(100))==0){
+		printf("ERROR: Can't malloc memory to build the error status info string\n");
+		return(-1);
+	}
+	if (mpod_read(dev, mpid, MPOD_ERRORSTAT, &val )){
+		printf("ERROR: MPOD can't read error status register on i2c bus\n");
+		return(-1);
+	}
+	if (mpod_isTX(mpid))
+		sprintf(str,"fault:%d,los:%d,intL:%d,data-not-ready:%d\n", 3>(val&0x8), 2>(val&0x4), 1>(val&0x2), val&01);
+	else
+		sprintf(str,"fault:*,los:%d,intL:%d,data-not-ready:%d\n",                2>(val&0x4), 1>(val&0x2), val&01);		
+   *data = str;
+	return(0);
+}
+/*********************************************************************************//**
+ * \fn int mpod_dumpErrStatus(int dev, int mpid)
+ * \brief Function to dump the data not ready, int, los and faul  status of one minipod
+ *
+ * \param mpid: the target minipod component 0 to 7
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+int mpod_dumpErrStatus(int dev, int mpid){
+	if (!mpod_scriptMode){
+		printf("minipod %d error status\n", mpid);
+		printf("!-------------------------------------------!\n");
+		printf("! MPOD ! FAULT ! LOS ! INT ! DATA NOT READY !\n");
+		printf("!-------------------------------------------!\n");
+	}
+	mpod_dumpErrStatusValues(dev, mpid);
+	if (!mpod_scriptMode)
+		printf("!-------------------------------------------!\n");
+return(0);
+}
+/*********************************************************************************//**
+ * \fn int mpod_dumpErrStatusAll(int dev)
+ * \brief Function to dump the data not ready, int, los and faul  status of all minipods
+ *
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+int mpod_dumpErrStatusAll(int dev){
+int     mpid;
+	if (!mpod_scriptMode){
+		printf("minipod all error status\n");
+		printf("!-------------------------------------------!\n");
+		printf("! MPOD ! FAULT ! LOS ! INT ! DATA NOT READY !\n");
+		printf("!-------------------------------------------!\n");
+	}
+	for (mpid=0; mpid<=7; mpid++){
+		mpod_dumpErrStatusValues(dev, mpid);
+	}
+	if (!mpod_scriptMode)
+		printf("!-------------------------------------------!\n");
+return(0);
+}
+/*********************************************************************************//**
+ * \fn int mpod_losDumpAll(int dev, int mpid)
+ * \brief Function to dump the los status for all channels of one minipod
+ *
+ * \param mpid: the target minipod component 0 to 7
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+int mpod_losDumpAll(int dev, int mpid){
+char regName[]="Loss of signal";
+
+return mpod_dumpAllBitIn12bitsOn2words(dev, mpid, 
+											MPOD_LOSREG1, MPOD_LOSREG2,
+											regName,
+											NULL,
+											'0','1');
+}
+/*********************************************************************************//**
+ * \fn int mpod_losListAll(int dev, int mpid, char **data)
+ * \brief Function to make a list of the the los status for all channels of one minipod
+ *
+ * Attention bits should be reordered for 0 to 11
+ * Function used by the python wrapper
+ *
+ * \param mpid: the target minipod component 0 to 7
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+int mpod_losListAll(int dev, int mpid, char **data){
+char regName[]="Loss of signal";
+int status;
+
+// attention clear on read register
+status = mpod_mkListBitIn12bitsOn2words(dev, mpid, 
+				MPOD_LOSREG1, MPOD_LOSREG2,
+				regName,
+				NULL,
+				'0','1',
+                                 data );
+printf("Loss of signal :%s\n", *data);
+
+return status;
+}
+/*********************************************************************************//**
+ * \fn int mpod_fualtDumpAll(int dev, int mpid)
+ * \brief Function to dump the fault status for all channels of one TX  minipod
+ *
+ * \param mpid: the target minipod component 0 to 7
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+int mpod_faultDumpAll(int dev, int mpid){
+char regName[]="Faults";
+
+return mpod_dumpAllBitIn12bitsOn2words(dev, mpid, 
+											MPOD_FAULTREG1, MPOD_FAULTREG2,
+											regName,
+											mpod_isRX,
+											'0','1');
+}
+/*********************************************************************************//**
+ * \fn int mpod_internalTemp(int dev, int mpid, int *temp)
+ * \brief Function to get the temperature value of one minipod
+ *
+ * \param mpid: the target minipod component 0 to 7
+ * \param temp: a pointer to the variable to receive the temperature
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+int mpod_internalTemp(int dev, int mpid, int *temp){
+	unsigned valh;
+
+	// only use the higher temp at +- 3°C
+	if (mpod_read(dev, mpid , MPOD_INTEMPMSB , &valh )){
+		printf("ERROR: MPOD can't read the internal temperature register on i2c bus\n");
+		return(-1);
+	}
+	*temp = valh;
+	if (mpod_hideText);
+	else if (mpod_scriptMode)
+		printf("%d,",*temp);
+	else
+		printf("minipod %d internal temperature %dC\n",mpid, *temp);
+		
+//	printf("Internal temperature of minipod %d is %d°C\n", mpid, *temp);
+	return(0);
+}
+/*********************************************************************************//**
+ * \fn int mpod_internalTempDumpAll(int dev)
+ * \brief Function to print the temperatures value of all minipods
+ *
+ * \param mpid: the target minipod component 0 to 7
+ * \param temp: a pointer to the variable to receive the temperature
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+int mpod_internalTempDumpAll(int dev){
+	int i, temp;
+	for (i=0; i<8; i++){
+		mpod_internalTemp(dev, i, &temp);
+	}
+	return(0);
+}
+/*********************************************************************************//**
+ * \fn int mpod_internal33Vcc(int dev, int mpid, int *vcc)
+ * \brief Function to get the 3.3 vCC value of one minipod
+ *
+ * \param mpid: the target minipod component 0 to 7
+ * \param  vcc: a pointer to the variable to receive the voltage in uV
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+int mpod_internal33Vcc(int dev, int mpid, int *vcc){
+	unsigned valh, vall;
+	// see how the target device is specified ... compute target device address
+	if (mpod_read(dev, mpid, MPOD_33VCCMSB , &valh )){
+		printf("ERROR: MPOD can't read the 3.3Vcc register on i2c bus\n");
+		return(-1);
+	}
+	mpod_read(dev, mpid , MPOD_33VCCLSB , &vall);
+	*vcc = (valh<<8) + vall; // value in uV
+   if (mpod_hideText);
+	else if (mpod_scriptMode)
+		printf("%.2f,",(float)*vcc/10000);
+	else
+		printf("3.3 power of minipod %d is %.2fV\n", mpid, (float)*vcc/10000);
+	return(0);
+}
+/*********************************************************************************//**
+ * \fn int mpod_internal33VccDumpAll(int dev)
+ * \brief Function to get the 3.3 vCC value of all minipods voltage in uV
+ *
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+int mpod_internal33VccDumpAll(int dev){
+	int i, temp;
+	for (i=0; i<8; i++){
+		mpod_internal33Vcc(dev, i, &temp);
+	}
+	return(0);
+}
+/*********************************************************************************//**
+ * \fn int mpod_internal25Vcc(int dev, int mpid, int *vcc)
+ * \brief Function to get the 2.5 vCC value of one minipod
+ *
+ * \param mpid: the target minipod component 0 to 7
+ * \param  vcc: a pointer to the variable to receive the voltage in uV
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+int mpod_internal25Vcc(int dev, int mpid, int *vcc){
+	unsigned valh, vall;
+	// see how the target device is specified ... compute target device address
+	if (mpod_read(dev, mpid, MPOD_25VCCMSB , &valh )){
+		printf("ERROR: MPOD can't read the 2.5Vcc register on i2c bus\n");
+		return(-1);
+	}
+	mpod_read(dev, mpid , MPOD_25VCCLSB , &vall);
+	*vcc = (valh<<8) + vall;
+	if (mpod_hideText);
+	else if (mpod_scriptMode)
+		printf("%2.2f,",(float)*vcc/10000);
+	else
+		printf("2.5 power of minipod %d is %2.2fV\n", mpid, (float)*vcc/10000);
+	return(0);
+}
+/*********************************************************************************//**
+ * \fn int mpod_internal25VccDumpAll(int dev)
+ * \brief Function to get the 2.5 vCC value of all minipods voltage in uV
+ *
+ * \return 0 success, -1 error
+ *//*********************************************************************************/
+int mpod_internal25VccDumpAll(int dev){
+	int i, temp;
+	for (i=0; i<8; i++){
+		mpod_internal25Vcc(dev, i, &temp);
+	}
+	return(0);
+}
+/***********************************************************************************//**
+ * \fn int mpod_biasCurrent(int dev, int mpid, float **data)
+ * \brief Function to get and print all bias current values of one TX minipod
+ *
+ * \param mpid: the target minipod component 1, 3, 5 ,7
+ * \param data: a pointer at which the function will put an allocated array of 12 values
+ *              (chn 0 to 11) that the user will have to freed after use.
+ *              value returned in the array are in uA
+ * \return 0 success, -1 error
+ *//***********************************************************************************/
+int mpod_biasCurrent(int dev, int mpid, float **data){
+	unsigned valh, vall, reg, chn;
+	float val;
+	float *cval;
+	
+	if (!(mpod_isTX(mpid))){
+		printf("ERROR: bias current monitoring only available for TX minipods\n");
+		return(-1);
+	};
+	if (!mpod_scriptMode)
+		printf("Bias current of minipod %d\n", mpid);
+	if (!(cval = malloc(12*sizeof(float)))){
+		printf("ERROR: Can't malloc memory for bias current data\n");
+		return(-1);
+	}
+	/* All the  registers for all channels are in sequence starting with channel 11 downto 0.
+	   They are coded on two bytes the first beeing the MSB. */
+	reg = MPOD_BIASCURLSB00;
+	for (chn=0; chn<12; chn++){
+		if (mpod_read(dev, mpid, reg , &vall )){
+			printf("ERROR: MPOD can't read the bias current register on i2c bus\n");
+			return(-1);
+		}
+		mpod_read(dev, mpid, reg-1 , &valh);
+		val = (float)((valh<<8) + vall) * 2; // unit is 2 uA
+		if (!mpod_scriptMode)
+			printf("[%2d] %4.1f uA\n", chn, val);
+		else
+			printf("%4.1f,", val);
+		reg=reg-2;
+	}//for
+	if (mpod_scriptMode) printf("\n"); // change line for each minipod
+	*data = cval;
+	return(0);
+}
+/***********************************************************************************//**
+ * \fn int mpod_getBiasCurrent(int dev, int mpid, float *data)
+ * \brief Function to get and print all bias current values of one TX minipod in python
+ *
+ * \param mpid: the target minipod component 1, 3, 5 ,7
+ * \param data: a pointer to an already allocated array of 12 values
+ *              
+ * \return 0 success, -1 error
+ *//***********************************************************************************/
+int mpod_getBiasCurrent(int dev, int mpid, float *data){
+	return mpod_get12FloatData(dev, mpod_biasCurrent, mpid, data);
+}
+/***********************************************************************************//**
+ * \fn int mpod_dumpLightPower(	int dev, int mpid,
+ 	int reg,
+ 	char *regMsg,
+ 	(int)(*filter)(int),
+ 	float **data)
+ * \brief Function to get and print all light power values organized as 2 bytes MSB/LSB
+ *        per parameter. values are in 0.1 uW units coded 16 bits unsigned integers
+ *
+ * \param mpid		: the target minipod component 0, 2 or 4
+ * \param reg 		: the LSB register number for module 0
+ * \param regMsg	: the register identification message
+ * \param filter  : the filtering function to select proper type of minipods
+ * \param data		: a pointer at which the function will put an allocated array of 11 values
+ *              	  (chn 0 to 11) that the user will have to freed after use.
+ *              	  value returned in the array are in uW
+ * \return 0 success, -1 error
+ *//***********************************************************************************/
+static int mpod_dumpLightpower(int dev, int mpid,int reg,char *regMsg,int (*filter)(int),float **data){
+	unsigned valh, vall, chn;
+	float val;
+	float *cval;
+	
+	if (filter)
+ 	  if (!filter(mpid)){
+ 		printf("ERROR: %s doesn't apply to this type of minipod\n", regMsg);
+ 		return(-1);
+ 	}
+	if (!mpod_scriptMode)
+		printf("%s of minipod %d\n", regMsg, mpid);
+	if (!(cval = malloc(12*sizeof(float)))){
+		printf("ERROR: Can't malloc memory for %s data\n", regMsg);
+		return(-1);
+	}
+	/* All the  registers for all channels are in sequence starting with channel 11 downto 0.
+	   They are coded on two bytes the first beeing the MSB. */
+	for (chn=0; chn<12; chn++){
+		if (mpod_read(dev, mpid, reg , &vall )){
+			printf("ERROR: MPOD can't read the %s register on i2c bus\n",regMsg);
+			return(-1);
+		}
+		mpod_read(dev, mpid, reg-1 , &valh);
+		val = (float)((valh<<8) + vall) * 0.1; // unit is 0.1 uW
+		cval[chn] = 10 * log10f(val/1000);
+		if (!mpod_scriptMode)
+			printf("[%2d] %04.1f \tuW %02.2f dBm\n", chn, val, cval[chn]);
+		else
+			printf("%04.1f,%02.2f,", val, cval[chn]);
+		reg=reg-2;
+	}//for
+	if (mpod_scriptMode) printf("\n"); // one minipod per line
+	*data = cval;
+	return(0);
+}
+/***********************************************************************************//**
+ * \fn int mpod_lightOutput(int dev, int mpid, float **data)
+ * \brief Function to get and print all light output values of one TX minipod
+ *
+ * \param mpid: the target minipod component 1, 3,  5 or 7
+ * \param data: a pointer at which the function will put an allocated array of 11 values
+ *              (chn 0 to 11) that the user will have to freed after use.
+ *              value returned in the array are in uW
+ * \return 0 success, -1 error
+ *//***********************************************************************************/
+int mpod_lightOutput(int dev, int mpid, float **data){
+	char regMsg[] = "light output power";
+	
+	return mpod_dumpLightpower(dev, mpid,MPOD_LIGHTOUTLSB00,regMsg,mpod_isTX,data);
+}
+/***********************************************************************************//**
+ * \fn int mpod_getLightOutput(int dev, int mpid, float *data)
+ * \brief Function to get and print all light output values of one TX minipod in python
+ *
+ * \param mpid: the target minipod component 1, 3,  5 or 7
+ * \param data: a pointer to an already allocated allocated array of 12 values
+ *              value returned in the array are in uW
+ * \return 0 success, -1 error
+ *//***********************************************************************************/
+int mpod_getLightOutput(int dev, int mpid, float *data){
+	return mpod_get12FloatData(dev, mpod_lightOutput, mpid, data);
+}
+/***********************************************************************************//**
+ * \fn int mpod_lightInput(int dev, int mpid, float **data)
+ * \brief Function to get and print all optical power values of one RX minipod
+ *
+ * \param mpid: the target minipod component 0, 2 , 4 or 6
+ * \param data: a pointer at which the function will put an allocated array of 11 values
+ *              (chn 0 to 11) that the user will have to freed after use.
+ *              value returned in the array are in dBm
+ * \return 0 success, -1 error
+ *//***********************************************************************************/
+int mpod_lightInput(int dev, int mpid, float **data){
+	char regMsg[] = "light input power PAVE";
+	
+	return mpod_dumpLightpower(dev,mpid,MPOD_OPPOWERLSB00,regMsg,mpod_isRX,data);
+}
+/***********************************************************************************//**
+ * \fn int mpod_getLightInput(int dev, int mpid, float *data)
+ * \brief Function to get and print all light input values of one RX minipod in python
+ *
+ * \param mpid: the target minipod component 0, 2 , 4 or 6
+ * \param data: a pointer to an already allocated allocated array of 12 values
+ *              value returned in the array are in uW
+ * \return 0 success, -1 error
+ *//***********************************************************************************/
+int mpod_getLightInput(int dev, int mpid, float *data){
+	return mpod_get12FloatData(dev, mpod_lightInput, mpid, data);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_elapsedPowerOn(int dev, int mpid, int *dur)
+ * \brief Function to get the elapsed operating time of one minipod in hours (2h resolution)
+ *
+ *  Comment: this data seem not implemeneted in the chips while documented.
+ *
+ * \param mpid: the target minipod component 0 to 7
+ * \param  dur: a pointer at which the function will put the read value.
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_elapsedPowerOn(int dev, int mpid, int *dur){
+	unsigned valh, vall;
+	
+	// see how the target device is specified ... compute target device address
+	if (mpod_read(dev, mpid, MPOD_ELAPSEREGMSB, &valh)){
+		printf("ERROR: MPOD can't read the power elapse register on i2c bus");
+		return(-1);
+	}
+	mpod_read(dev, mpid, MPOD_ELAPSEREGLSB , &vall);
+	*dur = 2*((valh<<8) + vall);
+	if (!mpod_scriptMode)
+		printf("Component %d is running since %d Hours (2H granularity)\n", mpid, *dur);
+	else
+		printf("%d",*dur); // in hours 2H granularity
+		
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_reset(int dev, int mpid)
+ * \brief Function to reset all registers values to their default factory values.
+ *
+ * \param mpid: the target minipod component 0 to 7
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_reset(int dev, int mpid){
+	
+	if (mpod_write(dev, mpid, MPOD_RESET  , 1)){
+			printf("ERROR: can't reset minipod %d board %d\n", mpid, dev);
+			return(-1);
+		}
+	printf("Reset done on minipod %d board %d\n", mpid, dev);
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_channelDisable (int dev, int mpid, int channel, int flag)
+ * \brief Function to disable one channel of one minipod.
+ *
+ * \param mpid   : the target minipod component 0 to 7
+ * \param channel: the target channel 0 to 12
+ * \param flag   : 0=enable  1=disable
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_channelDisable(int dev, int mpid, int channel, int flag){
+
+char regMsg[]="channel disable";
+return (mpod_setBitIn12bitsOn2words(dev, mpid, channel, flag, MPOD_CHDISABLE1, MPOD_CHDISABLE2,
+									regMsg, NULL));
+}
+/*****************************************************************************************//**
+ * \fn int mpod_channelDisDumpAll (int dev, int mpid)
+ * \brief Function to dump the disable status of all channels of one minipod.
+ *
+ * \param mpid   : the target minipod component 0 to 7
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_channelDisDumpAll(int dev, int mpid){
+char regName[]="Disable status enable/disable";
+
+return mpod_dumpAllBitIn12bitsOn2words(dev, mpid, 
+											MPOD_CHDISABLE1, MPOD_CHDISABLE2,
+											regName,
+											NULL,
+											'e','d');
+}
+/*****************************************************************************************//**
+ * \fn int mpod_polarityFlip (int dev, int mpid, int channel, int flag)
+ * \brief Function to flip input/output polarity one channel of one minipod.
+ *
+ * \param mpid   : the target minipod component 0 to 7
+ * \param channel: the target channel 0 to 12
+ * \param flag   : 0=enable  1=disable
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_polarityFlip(int dev, int mpid, int channel, int flag){
+
+char regMsg[]="polarity flipped";
+int res;
+
+mpod_pageSelect(dev, mpid , 1) ;
+res = mpod_setBitIn12bitsOn2words(dev, mpid, channel, flag, MPOD_POLARFLIP1, MPOD_POLARFLIP2,
+									regMsg, NULL);
+mpod_pageSelect(dev, mpid , 0) ;
+return res;
+}
+/*****************************************************************************************//**
+ * \fn int mpod_channelPolarFlipDumpAll (int dev, int mpid)
+ * \brief Function to dump the input/output polarity status of all channels of one minipod.
+ *
+ * \param mpid   : the target minipod component 0 to 7
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_channelPolarFlipDumpAll(int dev, int mpid){
+char regName[]="Polarity flip status";
+int res;
+
+mpod_pageSelect(dev, mpid , 1) ;
+res = mpod_dumpAllBitIn12bitsOn2words(dev, mpid, 
+											MPOD_POLARFLIP1, MPOD_POLARFLIP2,
+											regName,
+											NULL,
+											'0','1');
+mpod_pageSelect(dev, mpid , 0) ;
+return res;
+}
+/*****************************************************************************************//**
+ * \fn int mpod_marginActivation (int dev, int mpid, int channel, int flag)
+ * \brief Function to acivate margin one channel of one minipod.
+ *
+ * \param mpid   : the target minipod component 0 to 7
+ * \param channel: the target channel 0 to 12
+ * \param flag   : 0=enable  1=disable
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_marginActivation(int dev, int mpid, int channel, int flag){
+
+char regMsg[]="margin activation";
+return (mpod_setBitIn12bitsOn2words(dev, mpid, channel, flag, MPOD_MARGINACT1, MPOD_MARGINACT2,
+									regMsg, mpod_isTX));
+}
+/*****************************************************************************************//**
+ * \fn int mpod_marginActDumpAll (int dev, int mpid)
+ * \brief Function to dump the margin activation status of all channels of one minipod.
+ *
+ * \param mpid   : the target minipod component 0 to 7
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_marginActDumpAll(int dev, int mpid){
+char regName[]="margin activation/deactivation";
+return mpod_dumpAllBitIn12bitsOn2words(dev, mpid, 
+											MPOD_MARGINACT1, MPOD_MARGINACT2,
+											regName,
+											mpod_isRX,
+											'd','a');
+}
+/*****************************************************************************************//**
+ * \fn int mpod_readPatQuartMulti(int dev, int mpid, unsigned **data, int higherReg, char *idChain)
+ * \brief Function general to read the 12 channels 4 bits codes of a minipod when they are 
+ *  stored 2 by 2 (msb/lsb) in 6 registers (reverse order higher channel in lower registers) 
+ *
+ * It is used to factorize code for VOD, deamphasis and equalization read/write global or single
+ *
+ * \param mpid: the target RX minipod component 0, 2, 4 and 6 (RX)
+ * \param data: a pointer at which the function will put an allocated array of 12 code values
+ *              (chn 0 to 11) that the user will have to freed after use.
+ * \param higherReg : the higher register number (for channel 0 and 1)
+ * \param idChain: an identification chain to put in error message
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+static int mpod_readPatQuartMulti(int dev, int mpid, int **data, int higherReg, char *idChain){
+	int reg, i, msb, lsb, chn;
+	unsigned val;
+	int     *res;
+	
+	mpod_pageSelect(dev, mpid , 1) ;
+	if (!(res = malloc(12*sizeof(int)))){
+		printf("ERROR: Can't malloc memory for  amplitude control data\n");
+		return(-1);
+	}
+	/* All the output amplitude control registers for all channels are in sequence with two channels per reg
+	   starting with channel 11-10 ending with 1-0  thus 6 conscecutive regs*/
+	chn = 0;
+	reg = higherReg;
+	for (i=6; i>0; i--){
+		if (mpod_read(dev, mpid, reg, &val)){
+			printf("ERROR: MPOD can't read the %s register on i2c bus\n", idChain);
+			return(-1);
+		}
+		msb = val/16;
+		lsb = val & 0x0f;
+		// store the codes to pass to the user
+		res[chn]  =lsb;
+		res[chn+1]=msb;
+		chn=chn+2;
+		reg = reg-1;
+	}
+	*data=res;
+	mpod_pageSelect(dev, mpid , 0);
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_readPatQuartSingle(int dev, int mpid, int channel, int *code, unsigned *places, char *idChain)
+ * \brief Function to get the RX output amplitude control of one channel of a minipod
+ *
+ * \param mpid    : the target RX minipod component 0, 2, 4 and 6 (RX)
+ * \param channel : the channel to read
+ * \param data    : a pointer at which the function will put the returned code value.
+ * \param places  : an array giving the register/places pairs for all channels
+ * \param idChain : an identification chain to put in error message
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+static int mpod_readPatQuartSingle(int dev, int mpid, int channel, int *code, quartPlace *places, char *idChain){
+	int reg, qval;
+	unsigned val;
+	
+	mpod_pageSelect(dev, mpid , 1) ;
+	reg = places[channel].reg; 
+	if (mpod_read(dev, mpid, reg, &val)){
+			printf("ERROR: MPOD can't read %s register on i2c bus\n", idChain);
+			return(-1);
+	}
+	// test low quarter is used and extract the proper quarter
+	qval = (places[channel].quart==0) ? val & 0x0f : val/16;
+	// qval = ((*places)[channel][1]==0) ? val & 0x0f : val/16;
+	*code=qval;
+	mpod_pageSelect(dev, mpid , 0);
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_writePatQuartMulti(int dev, int mpid, unsigned *data, int higherReg, char *idChain)
+ 
+ * \brief Function general to write the 12 channels 4 bits codes of a minipod when they are 
+ *  stored 2 by 2 (msb/lsb) in 6 registers (reverse order higher channel in lower registers) 
+ *
+ * It is used to factorize code for VOD, deamphasis and equalization read/write global or single
+ *
+ * \param mpid: the target RX minipod component 0, 2, 4 and 6 
+ * \param data: a pointer to an array of 12 code values ordered from channel 0 to 11
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+static int mpod_writePatQuartMulti(int dev, int mpid, int *data, int higherReg, char *idChain){
+	int i, val, chn, reg;
+
+	mpod_pageSelect(dev, mpid, 1) ;
+	/* All the output amplitude control registers for all channels are in sequence with two channels per reg
+	   starting with channel 11-10 ending with 1-0  thus 6 conscecutive regs*/
+	reg = higherReg;
+	chn = 0;
+	for (i=6; i>0; i--){
+		val = (data[chn+1]<<4) + data[chn];
+		if (mpod_write(dev, mpid, reg, val)){
+			printf("ERROR: can't write the RX %s register on i2c bus", idChain);
+			return(-1);
+		}
+		chn = chn+2;
+		reg = reg-1;
+	}
+	mpod_pageSelect(dev, mpid , 0);
+	return(0);
+}
+/***************************************************************************************************//**
+ * \fn int mpod_writePatQuartSingle(int dev, int mpid, int channel,  int code, quartPlaces *places, char *idChain)
+ * \brief Function to set the RX output amplitude control of the a channel of a minipod
+ *
+ * Note this function is not efficient but we dont care we keep it simple!
+ *
+ * \param mpid    : the target RX minipod component 0, 2, 4 and 6
+ * \param channel : the channel to set the value 
+ * \param places  : the array describing the places of all channel and registers/codes associations
+ * \param code    : the code value to write (0 to 7)
+ * \param idChain : the string to identify the function in error messages
+ * \return 0 success, -1 error
+ *//***************************************************************************************************/
+static int mpod_writePatQuartSingle(int dev, int mpid, int channel, int code, quartPlace *places, char *idChain){
+
+	int val, reg;
+	unsigned curData;
+
+	mpod_pageSelect(dev, mpid , 1);
+	reg = places[channel].reg;
+	if (mpod_read(dev, mpid, reg, &curData)){
+			printf("ERROR: MPOD can't read the %s register on i2c bus\n", idChain);
+			return(-1);
+	}
+	if (places[channel].quart==0) {// test if low quarter is used 
+		val = curData & 0xf0; //nullify used quarter
+		val = val | code;
+	}
+	else {
+		val = curData & 0xf; //nullify used quarter
+		val  = val | (code<<4);
+	}
+	if (mpod_write(dev, mpid, reg, val)){
+			printf("ERROR: MPOD can't write the RX %s register on i2c bus\n", idChain);
+			return(-1);
+		}
+	mpod_pageSelect(dev, mpid , 0);
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn void mpod_printVOD(int dev, int mpid, unsigned *data)
+ * \brief Function to print the RX output amplitude control of the 12 channels of a minipod
+ *
+ * \param mpid: the target RX minipod component 0, 2, 4 and 6 (RX)
+ * \param data: a pointer at which the function receive an array with 12 code valuesb to print
+
+ *//****************************************************************************************/
+static void mpod_printVOD(int dev, int mpid, int *data){
+	int i;
+	if (!mpod_scriptMode){
+		printf("VOD output amplitude for minipod %d board %d\n", mpid, dev);
+		printf("---------------------------------------------\n");
+		printf(" chn ! code! Min ! Nominal ! Max ! Units    !\n");
+		printf("---------------------------------------------\n");
+	}
+	for (i=0; i<12; i++){
+		if (!mpod_scriptMode)
+			printf(" %3d ! %3d ! %3d !   %3d   ! %3d ! mVppd !\n", i, data[i],
+					mpod_ampControlCodes[data[i]][0], mpod_ampControlCodes[data[i]][1], mpod_ampControlCodes[data[i]][2]);
+		else
+			printf("%3d,%3d,%3d,%3d,%3d,", i,  data[i], 
+					mpod_ampControlCodes[data[i]][0], mpod_ampControlCodes[data[i]][1], mpod_ampControlCodes[data[i]][2]);
+	}	
+	if (!mpod_scriptMode)
+		printf("------------------------------------------\n");
+	else
+		printf("\n");
+}
+/*****************************************************************************************//**
+ * \fn void mpod_printVODSingle(int dev, int mpid, int channel, int code)
+ * \brief Function to print the RX output amplitude control of one channel of a minipod
+ *
+ * \param mpid    : the target RX minipod component 0, 2, 4 and 6 (RX)
+ * \param channel : the channel to print
+ * \param data    : the code value of this channel to print.
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+static void mpod_printVODSingle(int dev, int mpid, int channel, int code){
+	if (!mpod_scriptMode){
+		printf("VOD output amplitude for minipod %d channel %d board %d\n", mpid, channel, dev);
+		printf("------------------------------------------\n");
+		printf(" chn ! code! Min ! Nominal ! Max ! Units !\n");
+		printf("------------------------------------------\n");
+	}
+	if (!mpod_scriptMode)
+		printf(" %3d ! %3d ! %3d !   %3d   ! %3d ! mVppd !\n", channel,  code,
+					mpod_ampControlCodes[code][0], mpod_ampControlCodes[code][1], mpod_ampControlCodes[code][2]);
+	else
+		printf("%3d,%3d,%3d,%3d,%3d,", channel,  code,
+					mpod_ampControlCodes[code][0], mpod_ampControlCodes[code][1], mpod_ampControlCodes[code][2]);
+	if (!mpod_scriptMode)
+		printf("------------------------------------------\n");
+	else
+		printf("\n");
+}
+/*****************************************************************************************//**
+ * \fn int mpod_readVOD(int dev, int mpid, unsigned **data)
+ * \brief Function to get the RX output amplitude control of the 12 channels of a minipod
+ *
+ * \param mpid: the target RX minipod component 0, 2, 4 and 6 (RX)
+ * \param data: a pointer at which the function will put an allocated array of 12 code values
+ *              (chn 0 to 11) that the user will have to freed after use.
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_readVOD(int dev, int mpid, int **data){
+	char subject[] = "VOD amplitude control";
+
+	// check RX
+	if (!(mpod_isRX(mpid))){
+		printf("ERROR: minpod %d is not an RX\n", mpid);
+		return(-1);
+	};
+	// get the data
+	if (mpod_readPatQuartMulti(dev, mpid, data, MPOD_RXVOD1, subject)==-1)
+		return(-1);
+	// print the data
+	mpod_printVOD(dev, mpid, *data);
+	return(0);
+}
+
+/*****************************************************************************************//**
+ * \fn int mpod_getVOD(int dev, int mpid, unsigned *data)
+ * \brief Function to get the RX output amplitude control of the 12 channels of a minipod in python
+ *
+ * Function to avoid to have to manage dynamically allocated arrays in the python wrapper.
+ *
+ * \param mpid: the target RX minipod component 0, 2, 4 and 6 (RX)
+ * \param data: a pointer to an already allocated array of 12 code values
+ *              (chn 0 to 11) that the user will have to freed after use.
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_getVOD(int dev, int mpid, int *data){
+	return mpod_get12IntData(dev, mpod_readVOD,mpid, data);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_readVODSingle(int dev, int mpid, int channel, int *code)
+ * \brief Function to get the RX output amplitude control of one channel of a minipod
+ *
+ * \param mpid    : the target RX minipod component 0, 2, 4 and 6 (RX)
+ * \param channel : the channel to read
+ * \param data    : a pointer at which the function will put the returned code value.
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_readVODSingle(int dev, int mpid, int channel, int *code){
+	char subject[] = "VOD amplitude control";
+	
+	// check RX
+	if (!(mpod_isRX(mpid))){
+		printf("ERROR: minpod %d is not an RX\n", mpid);
+		return(-1);
+	};
+	// get the data
+	if (mpod_readPatQuartSingle(dev, mpid, channel, code, mpod_vodQuarters, subject)==-1)
+		return(-1);
+	// print the data
+	mpod_printVODSingle(dev, mpid, channel, *code);
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_writeVOD(int dev, int mpid, unsigned *data)
+ * \brief Function to set the RX output amplitude control of the 12 channels of a minipod
+ *
+ * \param mpid: the target RX minipod component 0, 2, 4 and 6 
+ * \param data: a pointer to an array of 12 code values ordered from channel 0 to 11
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_writeVOD(int dev, int mpid, int *data){
+	char subject[] = "VOD amplitude control";
+	
+	// check RX
+	if (!(mpod_isRX(mpid))){
+		printf("ERROR: minpod %d is not an RX\n", mpid);
+		return(-1);
+	};
+	// write the data
+	mpod_writePatQuartMulti(dev, mpid, data, MPOD_RXVOD1, subject);
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_writeVODSingle(int dev, int mpid, int channel, int code)
+ * \brief Function to set the RX output amplitude control of the a channel of a minipod
+ *
+ * Note this function is not efficient but we dont care we keep it simple!
+ *
+ * \param mpid    : the target RX minipod component 0, 2, 4 and 6
+ * \param channel : the channel to set the value 
+ * \param data    : the code value to write (0 to 7)
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_writeVODSingle(int dev, int mpid, int channel, int code){
+	char subject[] = "VOD amplitude control";
+	
+	// check RX
+	if (!(mpod_isRX(mpid))){
+		printf("ERROR: minipod %d is not an RX\n", mpid);
+		return(-1);
+	};
+	// check code
+	if (code>7){
+		printf("ERROR: RX output amplitude control register code should be less than 0111b\n");
+		return(-1);
+	}
+	// write the data
+	mpod_writePatQuartSingle(dev, mpid, channel, code, mpod_vodQuarters, subject);
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn void mpod_printDeamphasis(int dev, int mpid, unsigned *data)
+ * \brief Function to print the RX output deamphasis codes of the 12 channels of a minipod
+ *
+ * \param mpid: the target RX minipod component 0, 2, 4 and 6 (RX)
+ * \param data: a pointer at which the function receive an array with 12 code values to print
+
+ *//****************************************************************************************/
+static void mpod_printDeamphasis(int dev, int mpid, int *data){
+	int i;
+	if (!mpod_scriptMode){
+		printf("output deamphasis for minipod %d board %d\n", mpid, dev);
+		printf("------------------------\n");
+		printf(" chn ! code !Deamphasis!\n");
+		printf("------------------------\n");
+	}
+	for (i=0; i<12; i++){
+		if (!mpod_scriptMode)
+			printf(" %3d !  %3d !  %3d%c    !\n", i,   data[i], (data[i]*100/7), '%');
+		else
+			printf("%3d,%3d,%3d%c,", i,   data[i], (data[i]*100/7), '%');
+	}
+	if (!mpod_scriptMode)
+		printf("------------------------\n");
+	else
+		printf("\n");
+}
+/*****************************************************************************************//**
+ * \fn void mpod_printDeamphasisSingle(int dev, int mpid, int channel, int code)
+ * \brief Function to print the RX deamphasis code of one channel of a minipod
+ *
+ * \param mpid    : the target RX minipod component 0, 2, 4 and 6 (RX)
+ * \param channel : the channel to print
+ * \param data    : the code value of this channel to print.
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+static void mpod_printDeamphasisSingle(int dev, int mpid, int channel, int code){	
+	if (!mpod_scriptMode){						
+		printf("output deamphasis for minipod %d board %d\n", mpid, dev);
+		printf("------------------------\n");
+		printf(" chn ! code !Deamphasis!\n");
+		printf("------------------------\n");
+	}
+	if (!mpod_scriptMode)	
+		printf(" %3d !  %3d !  %3d%c    !\n", channel,   code, (code*100/7), '%');
+	else
+		printf("%3d,%3d,%3d%c,", channel,   code, (code*100/7), '%');
+	if (!mpod_scriptMode)
+		printf("------------------------\n");
+	else
+		printf("\n");
+}
+/*****************************************************************************************//**
+ * \fn int mpod_readDeamphasis(int dev, int mpid, int **data)
+ * \brief Function to get the RX deamphasis control of the 12 channels of a minipod
+ *
+ * \param mpid: the target minipod component 0, 2, 4 or 6
+ * \param data: a pointer at which the function will put an allocated array of 12 code values
+ *              (chn 0 to 11) that the user will have to freed after use.
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_readDeamphasis(int dev, int mpid, int **data){
+	char subject[] = "Deamphasis control";
+
+	// check RX
+	if (!(mpod_isRX(mpid))){
+		printf("ERROR: minpod %d is not an RX\n", mpid);
+		return(-1);
+	};
+	// get the data
+	if (mpod_readPatQuartMulti(dev, mpid, data, MPOD_RXDEAMPH1, subject)==-1)
+		return(-1);
+	   
+	// print the data
+	mpod_printDeamphasis(dev, mpid, *data);
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_getDeamphasis(int dev, int mpid, int *data)
+ * \brief Function to get the RX deamphasis control of the 12 channels of a minipod in python
+ *
+ * Function developped for the python wrapper to avoid manipulation of dynamically allocated
+ * array of data in python.
+ *
+ * \param mpid: the target minipod component 0, 2, 4 or 6
+ * \param data: a pointer to an already allocated array of 12 code values
+ *              (chn 0 to 11) that the user will have to freed after use.
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_getDeamphasis(int dev, int mpid, int *data){
+	return mpod_get12IntData(dev, mpod_readDeamphasis,mpid, data);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_readDeamphasisSingle(int dev, int mpid, int channel, int *code)
+ * \brief Function to get the RX deamphasis control of the one channel of a minipod
+ *
+ * \param mpid    : the target minipod component 0, 2, 4 or 6
+ * \param channel : the channel to read
+ * \param data    : a pointer at which the function will put the read code value
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_readDeamphasisSingle(int dev, int mpid, int channel, int *code){
+	char subject[] = "Deamphasis control";
+	
+	// check RX
+	if (!(mpod_isRX(mpid))){
+		printf("ERROR: minpod %d is not an RX\n", mpid);
+		return(-1);
+	};
+	// get the data
+	if (mpod_readPatQuartSingle(dev, mpid, channel, code, mpod_deamphQuarters, subject)==-1)
+		return(-1);
+
+	// print the value
+	mpod_printDeamphasisSingle(dev, mpid, channel, *code);
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_writeDeamphasis(int dev, int mpid, int *data)
+ * \brief Function to set the RX deamphasis control of the 12 channels of a minipod
+ *
+ * \param mpid: the target minipod component 0,2, 4 or 6
+ * \param data: a pointer to an array of 11 code values ordered from channel 0 to 11
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_writeDeamphasis(int dev, int mpid, int *data){
+	char subject[] = "Deamphasis control";
+	
+	// check RX
+	if (!(mpod_isRX(mpid))){
+		printf("ERROR: minpod %d is not an RX\n", mpid);
+		return(-1);
+	};
+	// write the data
+	mpod_writePatQuartMulti(dev, mpid, data, MPOD_RXDEAMPH1, subject);
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_writeDeamphasisSingle(int dev, int mpid, int channel, int code)
+ * \brief Function to set the RX deamphasis control of one channels of one minipod
+ *
+ * \param mpid    : the target minipod component 0,2,4 or 6
+ * \param channel : the target channel
+ * \param data    : the code value to write
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_writeDeamphasisSingle(int dev, int mpid, int channel, int code){
+	char subject[] = "Deamphasis control";
+	
+	// check RX
+	if (!(mpod_isRX(mpid))){
+		printf("ERROR: minpod %d is not an RX\n", mpid);
+		return(-1);
+	}
+	// check code
+	if (code>7){
+		printf("ERROR: RX deamphasis register code should be less than 0111b");
+		return(-1);
+	}
+	mpod_writePatQuartSingle(dev, mpid, channel, code, mpod_deamphQuarters, subject);
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn void mpod_printEqualization(int dev, int mpid, unsigned *data)
+ * \brief Function to print the TX equalization codes of the 12 channels of a minipod
+ *
+ * \param mpid: the target TX minipod component 0, 2 and 6 (TX)
+ * \param data: a pointer at which the function receive an array with 12 code values to print
+
+ *//****************************************************************************************/
+static int mpod_printEqualization(int dev, int mpid, int *data){
+	int i;
+   if (!(mpod_isTX(mpid))){
+		printf("ERROR: Equalization only available for TX minipods\n");
+		return(-1);
+	};
+	if (!mpod_scriptMode){
+		printf("equalization for minipod %d borad %d\n", mpid, dev);
+		printf("-----------------------------------------------\n");
+		printf(" chn ! code! peak !midband\t!peak<>midband!\n");
+		printf("-----------------------------------------------\n");
+	}
+	for (i=0; i<12; i++){
+		if (!mpod_scriptMode)
+			printf(" %3d ! %3d ! %2.2f !%2.2f\t! %2.2f\t     !\n", i,   data[i],
+				mpod_equalizationCodes[data[i]][0], mpod_equalizationCodes[data[i]][1], mpod_equalizationCodes[data[i]][2]);
+		else
+			printf("%3d,%3d,%2.2f,%2.2f,%2.2f,", i,   data[i],
+				mpod_equalizationCodes[data[i]][0], mpod_equalizationCodes[data[i]][1], mpod_equalizationCodes[data[i]][2]);
+	}
+	if (!mpod_scriptMode)
+		printf("-----------------------------------------------\n");
+	else
+		printf("\n");
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn void mpod_printEqualizationSingle(int dev, int mpid, int channel, int code)
+ * \brief Function to print the TX deamphasis code of one channel of a minipod
+ *
+ * \param mpid    : the target TX minipod component 1, 3, 5 and 7 
+ * \param channel : the channel to print
+ * \param data    : the code value of this channel to print.
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+static int mpod_printEqualizationSingle(int dev, int mpid, int channel, int code){
+	if (!(mpod_isTX(mpid))){
+		printf("ERROR: Equalization only available for TX minipods\n");
+		return(-1);
+	};
+	if (!mpod_scriptMode){							
+		printf("equalization for minipod %d board %d\n", mpid, dev);
+		printf("-----------------------------------------------\n");
+		printf(" chn ! code! peak !midband\t!peak<>midband!\n");
+		printf("-----------------------------------------------\n");
+	}
+	if (!mpod_scriptMode)
+		printf(" %3d ! %3d ! %2.2f !%2.2f\t! %2.2f\t     !\n", channel,   code,
+				mpod_equalizationCodes[code][0], mpod_equalizationCodes[code][1], mpod_equalizationCodes[code][2]);
+	else
+		printf("%3d,%3d,%2.2f,%2.2f,%2.2f,", channel,   code,
+				mpod_equalizationCodes[code][0], mpod_equalizationCodes[code][1], mpod_equalizationCodes[code][2]);
+	if (!mpod_scriptMode)
+		printf("-----------------------------------------------\n");
+	else
+		printf("\n");
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_readEqualization(int dev, int mpid, int  **data)
+ * \brief Function to get the TX Equalization control of the 12 channels of a minipod
+ *
+ * \param mpid: the target minipod component 0, 2 or 4
+ * \param data: a pointer at which the function will put an allocated array of 12 code values
+ *              (chn 0 to 11) that the user will have to freed after use.
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_readEqualization(int dev, int mpid, int **data){
+	char subject[] = "equalization control";
+	
+	// check TX
+	if (!(mpod_isTX(mpid))){
+		printf("ERROR: minpod %d is not a TX\n", mpid);
+		return(-1);
+	}
+	// get the data
+	if (mpod_readPatQuartMulti(dev, mpid, data, MPOD_TXEQUALZ1, subject)==-1)
+		return(-1);
+	   
+	// print the data
+	mpod_printEqualization(dev, mpid, *data);
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_getEqualization(int dev, int mpid, int  *data)
+ * \brief Function to get the TX Equalization control of the 12 channels of a minipod in python
+ *
+ * Function developped for the python wrapping to prevent the exchange of a dynamically allocated
+ * array that should be free after use.
+
+ * \param mpid: the target minipod component 0, 2 or 4
+ * \param data: a pointer to an already allocated array of 12 code values
+ *          
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_getEqualization(int dev, int mpid, int *data){
+	return mpod_get12IntData(dev, mpod_readEqualization ,mpid, data);
+}
+
+/*****************************************************************************************//**
+ * \fn int mpod_readEqualizationSingle(int dev, int mpid, int channel, int *code)
+ * \brief Function to get the TX equalization control of the one channel of a minipod
+ *
+ * \param mpid    : the target minipod component 0, 2 or 4
+ * \param channel : the channel to read
+ * \param data    : a pointer at which the function will put the read code value
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_readEqualizationSingle(int dev, int mpid, int channel, int *code){
+	char subject[] = "Equalization control";
+	
+	// check TX
+	if (!(mpod_isTX(mpid))){
+		printf("ERROR: minpod %d is not an TX\n", mpid);
+		return(-1);
+	};
+	// get the data
+	if (mpod_readPatQuartSingle(dev, mpid, channel, code, mpod_equalzQuarters, subject)==-1)
+		return(-1);
+
+	// print the value
+	mpod_printEqualizationSingle(dev, mpid, channel, *code);
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_writeEqualization(int dev, int mpid, int *data)
+ * \brief Function to set the TX Equalization control of the 12 channels of a minipod
+ *
+ * \param mpid: the target minipod component 0,2 or 4
+ * \param data: a pointer to an array of 12 code values ordered from channel 0 to 11
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_writeEqualization(int dev, int mpid, int *data){
+	char subject[] = "Equalization control";
+	// check TX
+	if (!(mpod_isTX(mpid))){
+		printf("ERROR: minpod %d is not an TX\n", mpid);
+		return(-1);
+	}
+	// write the data
+	mpod_writePatQuartMulti(dev, mpid, data, MPOD_TXEQUALZ1, subject);
+	return(0);
+}
+/*****************************************************************************************//**
+ * \fn int mpod_writeEqualizationSingle(int dev, int mpid, int channel, int code)
+ * \brief Function to set the TX equalization control of one channels of one minipod
+ *
+ * \param mpid    : the target minipod component 0,2 or 4
+ * \param channel : the target channel
+ * \param data    : the code value to write
+ * \return 0 success, -1 error
+ *//****************************************************************************************/
+int mpod_writeEqualizationSingle(int dev, int mpid, int channel, int code){
+	char subject[] = "Equalization control";
+	
+	// check TX
+	if (!(mpod_isTX(mpid))){
+		printf("ERROR: minpod %d is not an TX\n", mpid);
+		return(-1);
+	}
+	// check code
+	if (code>7){
+		printf("ERROR: TX deamphasis register code should be less than 0111b");
+		return(-1);
+	}
+
+	mpod_writePatQuartSingle(dev, mpid, channel, code, mpod_equalzQuarters, subject);
+	return(0);
+}
+#ifdef MAIN_MINIPOD
+/*==============================*/
+/* main test program to execute */
+/*==============================*/
+int main(int argc, char **argv){
+	int      i, mp, vcc, dur;
+	float    *fdata = 0;
+	int      *data, *data2;
+	int      testVOD[]  ={0x04,0x4,0x4,0x4,0x4,0x4,0x4,0x04,0x4,0x4,0x4,0x4};	
+	int      testCodes[] ={0x01,0x2,0x3,0x4,0x5,0x6,0x7,0x1,0x2,0x3,0x4,0x5};
+	
+
+	/* ATTENTION CHECK THE necessary bus clock init setting is done in the driver */
+	if (mpod_init(0, 125000000, 100000))
+		exit(2);
+
+	///#I2C_PageSelect $targetDevice 1
+	if (mpod_pageSelect(0, 3, 1)==-1) exit(2);
+	///#I2C_PageSelect $targetDevice 0
+	if (mpod_pageSelect(0, 3, 0)==-1) exit(2);
+	
+	
+ ///  ========================== VENDOR DATA  ==========================
+	for (mp=0; mp<6; mp++) {
+		if (mpod_dumpVendorData(0,mp)==-1){
+			printf("\nERROR: Can't print vendor data for minipod %d\n\n", mp);
+			}
+	}
+	///  ========================== SQUELCH  ==========================
+	mpod_squelchDumpAll(0,0);
+	mpod_squelchDisableAll(0, 0, 0);
+	mpod_squelchDumpAll(0, 0);
+	mpod_squelchDisableAll(0, 0, 1);
+	mpod_squelchDumpAll(0, 0);
+	mpod_squelchDisable(0, 0 , 2 , 0);
+	mpod_squelchDisable(0, 0 , 9 , 0);
+	mpod_squelchDumpAll(0, 0);
+	mpod_squelchDisable(0, 0 , 2 , 1);
+	mpod_squelchDisable(0, 0 , 9 , 1);
+	
+	mpod_internalTempDumpAll(0);
+	
+	
+	/// ========================== I2C_Internal33Vcc 3  ==========================
+	if (mpod_internal33Vcc(0, 0, 3, &vcc))
+		exit(2);
+	else {
+		printf("\tTEST Got 3.3 Vcc %d\n", vcc);
+	}
+	/// ========================== I2C_Internal25Vcc 3  ==========================
+	if (mpod_internal25Vcc(0, 3, &vcc))
+		exit(2);
+	else {
+		printf("\tTEST Got 2.5 Vcc %d\n", vcc);
+	}
+	
+	/// ========================== I2C_lightInput 2  ==========================
+	if (mpod_lightInput(0, 2, &fdata))
+		exit(2);
+	else {
+		printf("\tTEST Got optical power\n");
+		for (i=0;i<12;i++) 
+			printf("\tTEST data[%d]=%2.2f dBm\n", i, fdata[i]);
+		free(fdata);
+	}
+	for (mp=0; mp<6; mp++){
+		if (mpod_lightInput(0, mp, &fdata))
+			exit(2);
+	}
+	for (mp=0; mp<6; mp++){
+		mpod_elapsedPowerOn(0, mp, &dur);
+	}	
+	
+	//  ========================== VOD  ==========================
+	// read store current values
+	printf("READ-STORE CURRENT VOD\n");
+	for (mp=0; mp<6; mp++){
+		if (!(mp%2)) continue;
+		if (mpod_readVOD(0, mp, &data))
+			exit(2);
+		else {
+			for (i=0;i<12;i++) 
+				printf("\tTEST vod[%d]=%d ", i, data[i]);
+			printf("\n");
+		}
+	}
+	// put new values
+	printf("WRITE NEW VOD\n");
+	for (mp=0; mp<6; mp++){
+		if (!(mp%2)) continue;
+		mpod_writeVOD(0, mp, testVOD);
+	}
+	// print to check
+	printf("READ CHECK NEW VOD\n");
+	for (mp=0; mp<6; mp++){
+		if (!(mp%2)) continue;
+		if (mpod_readVOD(0, mp, &data2))
+			exit(2);
+		else {
+			for (i=0;i<12;i++) 
+				printf("\tTEST vod[%d]=%d ", i, data2[i]);
+			printf("\n");
+			free(data2);	
+		}
+	}
+	// restore saved values
+	printf("READ CHECK NEW VOD\n");
+	for (mp=0; mp<6; mp++){
+		if (!(mp%2)) continue;
+		mpod_writeVOD(0, mp, data);
+	}
+	free(data);
+	// check again
+	printf("RESTORE STORED VOD\n");
+	for (mp=0; mp<6; mp++){
+		if (!(mp%2)) continue;
+		if (mpod_readVOD(0, mp, &data2))
+			exit(2);
+		else {
+			for (i=0;i<12;i++) 
+				printf("\tTEST vod[%d]=%d ", i, data2[i]);
+			printf("\n");
+			free(data2);	
+		}
+	}
+	// ========================== DEAMPHASIS ===========================
+	// read store current values
+	printf("DUMP CURENT DEAMPHASIS\n");
+	for (mp=0; mp<6; mp++){
+		if (!(mp%2)) continue;
+		if (mpod_readDeamphasis(0, mp, &data))
+			exit(2);
+		else {
+			for (i=0;i<12;i++) 
+				printf("\tTEST deamp[%d]=%d ", i, data[i]);
+			printf("\n");
+		}
+	}
+	// put new values
+	printf("WRITE NEW DEAMPHASIS\n");
+	for (mp=0; mp<6; mp++){
+		if (!(mp%2)) continue;
+		mpod_writeDeamphasis(0, mp, testCodes);
+	}
+	// print to check
+	printf("READ TO CHECK DEAMPHASIS\n");
+	for (mp=0; mp<6; mp++){
+		if (!(mp%2)) continue;
+		if (mpod_readDeamphasis(0, mp, &data2))
+			exit(2);
+		else {
+			for (i=0;i<12;i++) 
+				printf("\tTEST deamp[%d]=%d ", i, data2[i]);
+			printf("\n");
+			free(data2);	
+		}
+	}
+	// restore saved values
+	printf("RESTORE OLD DEAMPHASIS\n");
+	for (mp=0; mp<6; mp++){
+		if (!(mp%2)) continue;
+		mpod_writeDeamphasis(0, mp, data);
+	}
+	free(data);
+	// check again
+	printf("READ TO CHECK AGAIN DEAMPHASIS\n");
+	for (mp=0; mp<6; mp++){
+		if (!(mp%2)) continue;
+		if (mpod_readDeamphasis(0, mp, &data2))
+			exit(2);
+		else {
+			for (i=0;i<12;i++) 
+				printf("\tTEST deamp[%d]=%d ", i, data2[i]);
+			printf("\n");
+			free(data2);	
+		}
+	}
+	
+	//  ========================== EQUALIZATION  ==========================
+	// read store current values
+	printf("DUMP CURENT EQUALIZATION\n");
+	for (mp=0; mp<6; mp++){
+		if (mp%2) continue;
+		if (mpod_readEqualization(0, mp, &data))
+			exit(2);
+		else {
+			for (i=0;i<12;i++) 
+				printf("\tTEST deamp[%d]=%d ", i, data[i]);
+			printf("\n");
+		}
+	}
+	// put new values
+	printf("WRITE NEW EQUALIZATION\n");
+	for (mp=0; mp<6; mp++){
+		if (mp%2) continue;
+		mpod_writeEqualization(0, mp, testCodes);
+	}
+	// print to check
+	printf("READ TO CHECK EQUALIZATION\n");
+	for (mp=0; mp<6; mp++){
+		if (mp%2) continue;
+		if (mpod_readEqualization(0, mp, &data2))
+			exit(2);
+		else {
+			for (i=0;i<12;i++) 
+				printf("\tTEST deamp[%d]=%d ", i, data2[i]);
+			printf("\n");
+			free(data2);	
+		}
+	}
+	// restore saved values
+	printf("RESTORE OLD EQUALIZATION\n");
+	for (mp=0; mp<6; mp++){
+		if (mp%2) continue;
+		mpod_writeEqualization(0, mp, data);
+	}
+	free(data);
+	// check again
+	printf("READ TO CHECK AGAIN EQUALIZATION\n");
+	for (mp=0; mp<6; mp++){
+		if (mp%2) continue;
+		if (mpod_readEqualization(0, mp, &data2))
+			exit(2);
+		else {
+			for (i=0;i<12;i++) 
+				printf("\tTEST deamp[%d]=%d ", i, data2[i]);
+			printf("\n");
+			free(data2);	
+		}
+	}
+	
+return(0);
+}
+#endif
+
+
diff --git a/Pcie40Libraries/avagoMinipodCtrl.h b/Pcie40Libraries/avagoMinipodCtrl.h
new file mode 100644
index 0000000000000000000000000000000000000000..273c966e0d6cd1d9068aa1623e48efc34325e534
--- /dev/null
+++ b/Pcie40Libraries/avagoMinipodCtrl.h
@@ -0,0 +1,235 @@
+/**---------------------------------------------------------------------------------------------
+* \file				avagoMinipodCtrl.h
+*
+* \brief This file contains the user driver to control the 6 AVAGO miniPOD of the AMC40 board.
+* 
+* \author PYD : Pierre-Yves Duval
+* \version 0.1
+* \date 17/4/2012
+
+-------------------------------------------------------------------------------------------------*/
+
+/*-----------------------------------------------------------------------------------------------
+* PYD : 17/4/2012 initial version
+* PYD : 12/6/2015 Several i2c bus implemented for PCIe40
+*-----------------------------------------------------------------------------------------------
+*/
+
+#define MPOD_DBG  0 /*!<debug flag */
+#define MPOD_TEST 0 /*!<test flag */
+
+#define MPOD_ERRORSTAT        2 /*!<index of data nor ready, intl, LOS, fault status*/
+#define MPOD_LOSREG1          9 /*!<index of LOS reg for channel  11 downto 8 (reg low quarter)*/
+#define MPOD_LOSREG2         10 /*!<index of LOS reg for channel 7 downto 0 */
+#define MPOD_FAULTREG1       11 /*!<index of TX FAULT reg for channel  11 downto 8 (reg low quarter)*/
+#define MPOD_FAULTREG2       12 /*!<index of TX FAULT reg for channel 7 downto 0 */
+#define MPOD_INTEMPMSB       28 /*!<index of internal temperature monitor MSB*/
+#define MPOD_INTEMPLSB       29 /*!<index of internal temperature monitor LSB*/
+#define MPOD_33VCCMSB	     32 /*!<index of 3.3 Vcc monitor MSB*/
+#define MPOD_33VCCLSB	     33 /*!<index of 3.3 Vcc monitor LSB*/
+#define MPOD_25VCCMSB	     34 /*!<index of 2.5 Vcc monitor MSB*/
+#define MPOD_25VCCLSB	     35 /*!<index of 2.5 Vcc monitor LSB*/
+
+/* FOR TX component ONLY on page OOh */
+#define MPOD_BIASCURMSB11   40  /*!<index of TX Current BIAS monitor MSB fot channel 11*/
+#define MPOD_BIASCURLSB11   41  /*!<index of TX Current BIAS monitor LSB fot channel 11*/
+#define MPOD_BIASCURMSB10   42  /*!<index of TX Current BIAS monitor MSB fot channel 10*/
+#define MPOD_BIASCURLSB10   43  /*!<index of TX Current BIAS monitor LSB fot channel 10*/
+#define MPOD_BIASCURMSB09   44  /*!<index of TX Current BIAS monitor MSB fot channel 09*/
+#define MPOD_BIASCURLSB09   45  /*!<index of TX Current BIAS monitor LSB fot channel 09*/
+#define MPOD_BIASCURMSB08   46  /*!<index of TX Current BIAS monitor MSB fot channel 08*/
+#define MPOD_BIASCURLSB08   47  /*!<index of TX Current BIAS monitor LSB fot channel 08*/
+#define MPOD_BIASCURMSB07   48  /*!<index of TX Current BIAS monitor MSB fot channel 07*/
+#define MPOD_BIASCURLSB07   49  /*!<index of TX Current BIAS monitor LSB fot channel 07*/
+#define MPOD_BIASCURMSB06   50  /*!<index of TX Current BIAS monitor MSB fot channel 06*/
+#define MPOD_BIASCURLSB06   51  /*!<index of TX Current BIAS monitor LSB fot channel 06*/
+#define MPOD_BIASCURMSB05   52  /*!<index of TX Current BIAS monitor MSB fot channel 05*/
+#define MPOD_BIASCURLSB05   53  /*!<index of TX Current BIAS monitor LSB fot channel 05*/
+#define MPOD_BIASCURMSB04   54  /*!<index of TX Current BIAS monitor MSB fot channel 04*/
+#define MPOD_BIASCURLSB04   55  /*!<index of TX Current BIAS monitor LSB fot channel 04*/
+#define MPOD_BIASCURMSB03   56  /*!<index of TX Current BIAS monitor MSB fot channel 03*/
+#define MPOD_BIASCURLSB03   57  /*!<index of TX Current BIAS monitor LSB fot channel 03*/
+#define MPOD_BIASCURMSB02   58  /*!<index of TX Current BIAS monitor MSB fot channel 02*/
+#define MPOD_BIASCURLSB02   59  /*!<index of TX Current BIAS monitor LSB fot channel 02*/
+#define MPOD_BIASCURMSB01   60  /*!<index of TX Current BIAS monitor MSB fot channel 01*/
+#define MPOD_BIASCURLSB01   61  /*!<index of TX Current BIAS monitor LSB fot channel 01*/
+#define MPOD_BIASCURMSB00   62  /*!<index of TX Current BIAS monitor MSB fot channel 00*/
+#define MPOD_BIASCURLSB00   63  /*!<index of TX Current BIAS monitor LSB fot channel 00*/
+
+#define MPOD_LIGHTOUTMSB11   64  /*!<index of TX Light Output monitor MSB fot channel 11*/
+#define MPOD_LIGHTOUTLSB11   65  /*!<index of TX Light Output monitor LSB fot channel 11*/
+#define MPOD_LIGHTOUTMSB10   66  /*!<index of TX Light Output monitor MSB fot channel 10*/
+#define MPOD_LIGHTOUTLSB10   67  /*!<index of TX Light Output monitor LSB fot channel 10*/
+#define MPOD_LIGHTOUTMSB09   68  /*!<index of TX Light Output monitor MSB fot channel 09*/
+#define MPOD_LIGHTOUTLSB09   69  /*!<index of TX Light Output monitor LSB fot channel 09*/
+#define MPOD_LIGHTOUTMSB08   70  /*!<index of TX Light Output monitor MSB fot channel 08*/
+#define MPOD_LIGHTOUTLSB08   71  /*!<index of TX Light Output monitor LSB fot channel 08*/
+#define MPOD_LIGHTOUTMSB07   72  /*!<index of TX Light Output monitor MSB fot channel 07*/
+#define MPOD_LIGHTOUTLSB07   73  /*!<index of TX Light Output monitor LSB fot channel 07*/
+#define MPOD_LIGHTOUTMSB06   74  /*!<index of TX Light Output monitor MSB fot channel 06*/
+#define MPOD_LIGHTOUTLSB06   75  /*!<index of TX Light Output monitor LSB fot channel 06*/
+#define MPOD_LIGHTOUTMSB05   76  /*!<index of TX Light Output monitor MSB fot channel 05*/
+#define MPOD_LIGHTOUTLSB05   77  /*!<index of TX Light Output monitor LSB fot channel 05*/
+#define MPOD_LIGHTOUTMSB04   78  /*!<index of TX Light Output monitor MSB fot channel 04*/
+#define MPOD_LIGHTOUTLSB04   79  /*!<index of TX Light Output monitor LSB fot channel 04*/
+#define MPOD_LIGHTOUTMSB03   80  /*!<index of TX Light Output monitor MSB fot channel 03*/
+#define MPOD_LIGHTOUTLSB03   81  /*!<index of TX Light Output monitor LSB fot channel 03*/
+#define MPOD_LIGHTOUTMSB02   82  /*!<index of TX Light Output monitor MSB fot channel 02*/
+#define MPOD_LIGHTOUTLSB02   83  /*!<index of TX Light Output monitor LSB fot channel 02*/
+#define MPOD_LIGHTOUTMSB01   84  /*!<index of TX Light Output monitor MSB fot channel 01*/
+#define MPOD_LIGHTOUTLSB01   85  /*!<index of TX Light Output monitor LSB fot channel 01*/
+#define MPOD_LIGHTOUTMSB00   86  /*!<index of TX Light Output monitor MSB fot channel 00*/
+#define MPOD_LIGHTOUTLSB00   87  /*!<index of TX Light Output monitor LSB fot channel 00*/
+
+/* FOR RX component ONLY on page OOh */
+#define MPOD_OPPOWERMSB11   64  /*!<index of RX optical input optical power monitor MSB fot channel 11*/
+#define MPOD_OPPOWERLSB11   65  /*!<index of RX optical input optical power monitor LSB fot channel 11*/
+#define MPOD_OPPOWERMSB10   66  /*!<index of RX optical input optical power monitor MSB fot channel 10*/
+#define MPOD_OPPOWERLSB10   67  /*!<index of RX optical input optical power monitor LSB fot channel 10*/
+#define MPOD_OPPOWERMSB09   68  /*!<index of RX optical input optical power monitor MSB fot channel 09*/
+#define MPOD_OPPOWERLSB09   69  /*!<index of RX optical input optical power monitor LSB fot channel 09*/
+#define MPOD_OPPOWERMSB08   70  /*!<index of RX optical input optical power monitor MSB fot channel 08*/
+#define MPOD_OPPOWERLSB08   71  /*!<index of RX optical input optical power monitor LSB fot channel 08*/
+#define MPOD_OPPOWERMSB07   72  /*!<index of RX optical input optical power monitor MSB fot channel 07*/
+#define MPOD_OPPOWERLSB07   73  /*!<index of RX optical input optical power monitor LSB fot channel 07*/
+#define MPOD_OPPOWERMSB06   74  /*!<index of RX optical input optical power monitor MSB fot channel 06*/
+#define MPOD_OPPOWERLSB06   75  /*!<index of RX optical input optical power monitor LSB fot channel 06*/
+#define MPOD_OPPOWERMSB05   76  /*!<index of RX optical input optical power monitor MSB fot channel 05*/
+#define MPOD_OPPOWERLSB05   77  /*!<index of RX optical input optical power monitor LSB fot channel 05*/
+#define MPOD_OPPOWERMSB04   78  /*!<index of RX optical input optical power monitor MSB fot channel 04*/
+#define MPOD_OPPOWERLSB04   79  /*!<index of RX optical input optical power monitor LSB fot channel 04*/
+#define MPOD_OPPOWERMSB03   80  /*!<index of RX optical input optical power monitor MSB fot channel 03*/
+#define MPOD_OPPOWERLSB03   81  /*!<index of RX optical input optical power monitor LSB fot channel 03*/
+#define MPOD_OPPOWERMSB02   82  /*!<index of RX optical input optical power monitor MSB fot channel 02*/
+#define MPOD_OPPOWERLSB02   83  /*!<index of RX optical input optical power monitor LSB fot channel 02*/
+#define MPOD_OPPOWERMSB01   84  /*!<index of RX optical input optical power monitor MSB fot channel 01*/
+#define MPOD_OPPOWERLSB01   85  /*!<index of RX optical input optical power monitor LSB fot channel 01*/
+#define MPOD_OPPOWERMSB00   86  /*!<index of RX optical input optical power monitor MSB fot channel 00*/
+#define MPOD_OPPOWERLSB00   87  /*!<index of RX optical input optical power monitor LSB fot channel 00*/
+
+#define MPOD_ELAPSEREGMSB    88  /*!<index of elapsed operating time MSB in 2 hours units*/
+#define MPOD_ELAPSEREGLSB    88  /*!<index of elapsed operating time LSB in 2 hours units*/
+#define MPOD_SQUELCHREG1     94  /*!<index of squelch reg for channel  11 downto 8 (reg low quarter)*/
+#define MPOD_SQUELCHREG2     95  /*!<index of squelch reg for channel 7 downto 0 */
+#define MPOD_PAGEREG        127  /*!<page selection register */         
+#define MPOD_VENDORNAMEREG  152  /*!<index of the register with the first byte of the name of the vendor in ASCII*/
+#define MPOD_VENDOROUIREG   168  /*!<index of the register with the first byte of the OUI as hexa values*/
+#define MPOD_VENDORPARTREG  171  /*!<index of the register with the first byte of the part number of the vendor in ASCII*/
+#define MPOD_VENDORREVREG   187  /*!<index of the register with the first byte of the revision number of the vendor in ASCII*/
+#define MPOD_VENDORSERREG   189  /*!<index of the register with the first byte of the serial number of the vendor in ASCII*/
+#define MPOD_VENDORDATEREG  205  /*!<index of the register with the first byte of the date of the vendor in ASCII*/
+
+/* for TX and RX on page 00h */
+#define MPOD_RESET           91  /*!<index of register to reset all registers to factory values */
+#define MPOD_CHDISABLE1      92  /*!<index of DISABLE reg for channel 11 downto 8 (reg low quarter)*/
+#define MPOD_CHDISABLE2      93  /*!<index of DISABLE reg for channel 7 downto 0 */
+//PYD
+/* for TX and RX on page 01h */
+#define MPOD_POLARFLIP1      226  /*!<index of DISABLE reg for channel 11 downto 8 (reg low quarter)*/
+#define MPOD_POLARFLIP2      227  /*!<index of DISABLE reg for channel 7 downto 0 */
+//PYD
+/* for TX only on page 00h */
+#define MPOD_MARGINACT1      99  /*!<index of Margin Activation reg for channel 11 downto 8 (reg low quarter)*/
+#define MPOD_MARGINACT2     100  /*!<index of Margin Activation reg for channel 7 downto 0 */
+
+/* FOR RX component ONLY on page O1h */
+#define MPOD_RXVOD6      228  /*!<index of RX output amplitude control VOD for channels 11 and 10*/
+#define MPOD_RXVOD5      229  /*!<index of RX output amplitude control VOD for channels 9 and 8*/
+#define MPOD_RXVOD4      230  /*!<index of RX output amplitude control VOD for channels 7 and 6*/
+#define MPOD_RXVOD3      231  /*!<index of RX output amplitude control VOD for channels 5 and 4*/
+#define MPOD_RXVOD2      232  /*!<index of RX output amplitude control VOD for channels 3 and 2*/
+#define MPOD_RXVOD1      233  /*!<index of RX output amplitude control VOD for channels 1 and 0*/
+/* FOR TX component ONLY on page O1h */
+#define MPOD_TXEQUALZ6      228  /*!<index of RX output equalization control for channels 11 and 10*/
+#define MPOD_TXEQUALZ5      229  /*!<index of RX output equalization control for channels 9 and 8*/
+#define MPOD_TXEQUALZ4      230  /*!<index of RX output equalization control for channels 7 and 6*/
+#define MPOD_TXEQUALZ3      231  /*!<index of RX output equalization control for channels 5 and 4*/
+#define MPOD_TXEQUALZ2      232  /*!<index of RX output equalization control for channels 3 and 2*/
+#define MPOD_TXEQUALZ1      233  /*!<index of RX output equalization control for channels 1 and 0*/
+
+/* FOR RX component ONLY on page O1h */
+#define MPOD_RXDEAMPH6   234  /*!<index of RX output deamphasis control for channels 11 and 10*/
+#define MPOD_RXDEAMPH5   235  /*!<index of RX output deamphasis control for channels 9 and 8*/
+#define MPOD_RXDEAMPH4   236  /*!<index of RX output deamphasis control for channels 7 and 6*/
+#define MPOD_RXDEAMPH3   237  /*!<index of RX output deamphasis control for channels 5 and 4*/
+#define MPOD_RXDEAMPH2   238  /*!<index of RX output deamphasis control for channels 3 and 2*/
+#define MPOD_RXDEAMPH1   239  /*!<index of RX output deamphasis control for channels 1 and 0*/
+
+
+#define MPOD_NBVENDORNAME     15 /*!<size in register of the vendor name "AVAGO"*/
+#define MPOD_NBVENDOROUI       3 /*!<size in register of the vendor OUI (IEEE ID) "OOh 17h 6Ah" for AVAGO*/
+#define MPOD_NBVENDORPART     16 /*!<size in register of the vendor part number in ascii "AFBR-811FN1Z"*/
+#define MPOD_NBVENDORREV       2 /*!<size in register of the vendor revision number in ASCII: coded with space (20h)*/
+#define MPOD_NBVENDORSER      16 /*!<size in register of the vendor serial number in ASCII*/
+#define MPOD_NBVENDORDATE      8 /*!<size in register of the vendor date code YYYYMMDD (ASCII)*/
+
+#ifdef MPOCPP
+extern "C" { 
+#endif
+
+/* public functions */
+int mpod_setMode			  		(int mode);
+int mpod_setTextMode				(int mode);
+int mpod_exists               (int mpid);
+int mpod_init                 (int dev, unsigned inCLK, unsigned SCLfreq);
+void mpod_getInit             (int dev, unsigned *inCLK, unsigned *SCLfreq);
+int mpod_isTX                 (int mpid);
+int mpod_isRX                 (int mpid);
+int mpod_dumpErrStatus        (int dev, int mpid);
+int mpod_dumpErrStatusAll(int dev);
+int mpod_dumpVendorData       (int dev, int mpid);
+int mpod_getVendorName        (int dev, int mpid, char **bloc);
+int mpod_getVendorOUI         (int dev, int mpid, char **bloc);
+int mpod_getVendorPartNumber  (int dev, int mpid, char **bloc);
+int mpod_getVendorRevNumber   (int dev, int mpid, char **bloc);
+int mpod_getVendorDate        (int dev, int mpid, char **bloc);
+int mpod_getVendorSerialNumber(int dev, int mpid, char **bloc);
+int mpod_squelchDisable       (int dev, int mpid , int channel , int disable);
+int mpod_squelchDisableAll    (int dev, int mpid, int disable);
+int mpod_squelchDumpAll       (int dev, int mpid);
+int mpod_losDumpAll           (int dev, int mpid);
+int mpod_faultDumpAll         (int dev, int mpid);
+int mpod_internalTemp         (int dev, int mpid, int *temp);
+int mpod_internalTempDumpAll(int dev);
+int mpod_internal33Vcc        (int dev, int mpid, int *vcc);
+int mpod_internal33VccDumpAll(int dev);
+int mpod_internal25Vcc        (int dev, int mpid, int *vcc);
+int mpod_internal25VccDumpAll(int dev);
+int mpod_biasCurrent          (int dev, int mpid, float **data);
+int mpod_getBiasCurrent       (int dev, int mpid, float *data);
+int mpod_lightOutput          (int dev, int mpid, float **data);
+int mpod_getLightOutput       (int dev, int mpid, float *data);
+int mpod_lightInput           (int dev, int mpid, float **data);
+int mpod_getlightInput        (int dev, int mpid, float *data);
+int mpod_elapsedPowerOn       (int dev, int mpid, int *dur);
+int mpod_reset                (int dev, int mpid);
+int mpod_channelDisable       (int dev, int mpid, int channel, int flag);
+int mpod_channelDisDumpAll    (int dev, int mpid);
+//PYD
+int mpod_polarityFlip         (int dev, int mpid, int channel, int flag);
+int mpod_channelPolarFlipDumpAll(int dev, int mpid);
+//PYD
+int mpod_marginActivation     (int dev, int mpid, int channel, int flag);
+int mpod_marginActDumpAll     (int dev, int mpid);
+
+int mpod_readVOD              (int dev, int mpid, int **data);
+int mpod_getVOD					(int dev, int mpid, int *data);
+int mpod_readVODSingle        (int dev, int mpid, int channel, int *code);
+int mpod_writeVOD             (int dev, int mpid, int *data);
+int mpod_writeVODSingle       (int dev, int mpid, int channel, int code);
+
+int mpod_readDeamphasis       (int dev, int mpid, int **data);
+int mpod_getDeamphasis			(int dev, int mpid, int *data);
+int mpod_readDeamphasisSingle (int dev, int mpid, int channel, int *code);
+int mpod_writeDeamphasis      (int dev, int mpid, int *data);
+int mpod_writeDeamphasisSingle(int dev, int mpid, int channel, int code);
+
+int mpod_readEqualization       (int dev, int mpid, int **data);
+int mpod_getEqualization        (int dev, int mpid, int *data);
+int mpod_readEqualizationSingle (int dev, int mpid, int channel, int *code);
+int mpod_writeEqualization      (int dev, int mpid, int *data);
+int mpod_writeEqualizationSingle(int dev, int mpid, int channel, int code);
+
+#ifdef MPOCPP
+} 
+#endif
diff --git a/Pcie40Libraries/pcie40_b2ecs.c b/Pcie40Libraries/pcie40_b2ecs.c
index 4535a8b3acf4162628651d41e7aa2a0975ad3cec..4834244757985250647e245a42fc4a7e46ba0827 100644
--- a/Pcie40Libraries/pcie40_b2ecs.c
+++ b/Pcie40Libraries/pcie40_b2ecs.c
@@ -6,29 +6,29 @@
 // **************************************************************************
 // Status of the b2link: 0 = BAD, 1 = GOOD
 // **************************************************************************
-int pcie40_b2linkstatus(int dev, int fd) { 
+int pcie40_b2linkstatus(int dev, int ch) { 
   int ret = 0 ;
   ret = ecs_read( dev , ECS_BAR , ECS_B2LINK_STATUS_ADD ) ;
-  return ( ( ret & ( 1 << ( ECS_B2LINK_STATUS_BIT + fd ) ) ) 
-	   >> ( ECS_B2LINK_STATUS_BIT + fd ) ) ;
+  return ( ( ret & ( 1 << ( ECS_B2LINK_STATUS_BIT + ch ) ) ) 
+	   >> ( ECS_B2LINK_STATUS_BIT + ch ) ) ;
 }
 
 // **************************************************************************
 // Resynchronize the b2link, returns 1 if success, 0 if error 
 // **************************************************************************
-int pcie40_resyncb2link(int dev , int fd ) { 
+int pcie40_resyncb2link(int dev , int ch) { 
   int ret = 0 ;
   int i ; 
   for ( i = 0 ; i<10 ; i++ ) {
     ret = ecs_write( dev , ECS_BAR , ECS_B2LINK_RESET_ADD , 0x0 ) ;
     if ( 0 != ret ) return 0 ;
     ret = ecs_write( dev , ECS_BAR , ECS_B2LINK_RESET_ADD , 
-		     1 << ( ECS_B2LINK_RESET_BIT + fd ) ) ;
+		     1 << ( ECS_B2LINK_RESET_BIT + ch ) ) ;
     if ( 0 != ret ) return 0 ;
     ret = ecs_write( dev , ECS_BAR , ECS_B2LINK_RESET_ADD , 0x0 ) ;
     if ( 0 != ret ) return 0 ;
     usleep( 1000000 );
-    ret = pcie40_b2linkstatus( dev , fd ) ;
+    ret = pcie40_b2linkstatus( dev , ch ) ;
     if ( 1 == ret ) return ret ;
   }    
 
diff --git a/Pcie40Libraries/pcie40_b2ecs.h b/Pcie40Libraries/pcie40_b2ecs.h
index a15b79bc8e7945a84e897704ca9905b2b86171f9..a7a8691543e3f9f81016145c03dcddc11c998ac5 100644
--- a/Pcie40Libraries/pcie40_b2ecs.h
+++ b/Pcie40Libraries/pcie40_b2ecs.h
@@ -14,8 +14,8 @@
 // Functions to read/write registers and stream files to Front End
 
 /// b2link status (1 = OK, 0= BAD)
-int pcie40_b2linkstatus(int dev, int fd);
+int pcie40_b2linkstatus(int dev, int ch);
 
 /// Resynchronize b2link
-int pcie40_resyncb2link(int dev, int fd);
+int pcie40_resyncb2link(int dev, int ch);
 #endif // PCIE40_B2ECS_H
diff --git a/Pcie40Libraries/pcie40_b2slc.c b/Pcie40Libraries/pcie40_b2slc.c
deleted file mode 100644
index dd646e5c063304d9effd0cb66616383d43d3527c..0000000000000000000000000000000000000000
--- a/Pcie40Libraries/pcie40_b2slc.c
+++ /dev/null
@@ -1,253 +0,0 @@
-// File for Belle2 slow control access with PCIe40 
-#include "pcie40_b2slc.h"
-#include <unistd.h>
-#include "pcie40_ecs.h"
-
-/* ---------------------------------------------------------------------- *\
-   readfee8
-   returns -1 in case of error
-\* ---------------------------------------------------------------------- */
-int pcie40_readfee8( int dev , int fd , int adr) {
-  // PCIe40
-  if ( ( adr <=0 ) || ( adr > 0x7F ) ) return -1 ;
-  // Reset the FIFO (Emit and reception)
-  unsigned ret = 0 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 
-		   1 << SLC_WFIFO_RESET_BIT ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 0 ) ;
-  if ( ret != 0 ) return -1 ;
-
-  // Fill the FIFO with the requested information: write MSB first
-  int data_word_1 = 0xFFFE ;
-  int data_word_2 = 0x0001 ;
-  int data_word_3 = 0x8000 | ( adr & 0x7F ) ;
-  int data_word_4 = 0x000c ;
-  int data_word_5 = 0xEEEE ;
-
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40  , 
-		   (int) ( data_word_1 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40 , 
-		   (int) ( data_word_2 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40 , 
-		   (int) ( data_word_3 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40 , 
-		   (int) ( data_word_4 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40 , 
-		   (int) ( data_word_5 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-
-  // start emit
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_START_ADD , 
-  		   1 << ( SLC_WFIFO_EMIT_BIT + fd ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 0 ) ;
-  if ( ret != 0 ) return -1 ;
-
-  // Wait for the result to come back (1 word in the fifo)
-  int i ;
-  for ( i=0 ; i<10 ; i++ ) {
-    usleep( 10 ) ; //10 ms
-    ret = ecs_read( dev , SLC_BAR , SLC_RFIFO_STATUS + fd * 0x40 ) ;
-    if ( ret == 1 ) break;
-  }
-
-  if (i == 10) return -1;
-
-  // Read the value 
-  ret = ecs_read( dev , SLC_BAR , SLC_RFIFO_ADD + fd * 0x40 );
-  
-  // check address consistency
-  if ( ( ( ret & 0x7F00 ) >> 8 ) != adr ) return -1 ;
-
-  return ( ret & 0xFF ) ;
-}
-
-//==============================================================================
-// Write 8b
-//==============================================================================
-int pcie40_writefee8( int dev , int fd , int adr , int val ) {
-  // PCIe40
-  if ( ( adr <=0 ) || ( adr > 0x7F ) ) return -1 ;
-  // Reset the FIFO
-  unsigned ret = 0 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 
-		   1 << ( SLC_WFIFO_RESET_BIT + fd ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 0 ) ;
-  if ( ret != 0 ) return -1 ;
-
-  // Fill the FIFO with the requested information: write MSB first
-  int data_word_1 = 0xFFFF ;
-  int data_word_2 = 0x0001 ;
-  int data_word_3 = 0x8000 | ( adr & 0x7F ) ;
-  int data_word_4 = 0x0000 | ( val & 0xFF ) ;
-  int data_word_5 = 0xEEEE ;
-
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40 , 
-		   (int) ( data_word_1 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40 , 
-		   (int) ( data_word_2 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40 , 
-		   (int) ( data_word_3 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40 , 
-		   (int) ( data_word_4 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40 , 
-		   (int) ( data_word_5 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-
-  // start emit
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 
-  		   1 << ( SLC_WFIFO_EMIT_BIT + fd ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 0 ) ;
-  if ( ret != 0 ) return -1 ;
-
-  return 0 ;
-}
-
-//==============================================================================
-// Read 32b
-//==============================================================================
-unsigned long pcie40_readfee32( int dev , int fd , int adr ) {
-  // PCIe40
-  if ( ( adr <0 ) || ( adr > 0xFFFF ) ) return -1 ;
-  // Reset the FIFO
-  unsigned ret = 0 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 
-		   1 << SLC_WFIFO_RESET_BIT ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 0 ) ;
-  if ( ret != 0 ) return -1 ;
-
-  // Fill the FIFO with the requested information: write MSB first
-  int data_word_1 = 0xFFFB ;
-  int data_word_2 = 0x7000 | ( ( adr & 0xFF00 ) >> 8 ) ;
-  int data_word_3 = 0x7000 | ( adr & 0xFF ) ;
-  int data_word_5 = 0xEEEE ;
-
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40 , 
-		   (int) ( data_word_1 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40 , 
-		   (int) ( data_word_2 & 0xFFFFFFFF ) ) ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40 , 
-		   (int) ( data_word_3 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40 , 
-		   (int) ( data_word_5 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-
-  // start emit
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_START_ADD , 
-  		   1 << ( SLC_WFIFO_EMIT_BIT + fd ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_START_ADD , 0 ) ;
-  if ( ret != 0 ) return -1 ;
-
-  // Wait for the result to come back
-  int i ;
-  for ( i=0 ; i<10 ; i++ ) {
-    usleep( 10 ) ; //10 ms
-    ret = ecs_read( dev , SLC_BAR , SLC_RFIFO_STATUS + fd * 0x40 ) ;
-    if ( ret == 4 ) break;
-  }
-
-  if (i == 10) return -1;
-
-  // Read the value 
-  int ret1 = ecs_read( dev , SLC_BAR , SLC_RFIFO_ADD + fd * 0x40 );
-  int ret2 = ecs_read( dev , SLC_BAR , SLC_RFIFO_ADD + fd * 0x40 );
-
-  int add1 = ( ret1 & 0x7F000000 ) >> 24 ;
-  int add2 = ( ret1 & 0x7F00 ) >> 8 ;
-  int add3 = ( ret2 & 0x7F000000 ) >> 24 ;
-  int add4 = ( ret2 & 0x7F00 ) >> 8 ;
-
-  if ( ( add1 != 0x6C ) || ( add2 != 0x6D ) || ( add3 != 0x6A ) || ( add4 != 0x6B ) )
-    return -1 ;
-
-  int res1 = ( ret1 & 0xFF0000 ) >> 16 ;
-  int res2 = ( ret1 & 0xFF ) ;
-  int res3 = ( ret2 & 0xFF0000 ) >> 16 ;
-  int res4 = ( ret2 & 0xFF ) ;
-
-  return 0xFFFFFFFF & ( ( res2 << 24 ) | ( res1 << 16 ) | ( res4 << 8 ) | ( res3 ) ) ;
-}
-
-//==============================================================================
-// Write 32b
-//==============================================================================
-int pcie40_writefee32( int dev , int fd , int adr , int val ) { 
-  // PCIe40
-  if ( ( adr <0 ) || ( adr > 0xFFFF ) ) return -1 ;
-  // Reset the FIFO
-  unsigned ret = 0 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 
-		   1 << ( SLC_WFIFO_RESET_BIT + fd ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 0 ) ;
-  if ( ret != 0 ) return -1 ;
-
-  int val1 = ( val & 0xFF ) ;
-  int val2 = ( val & 0xFF00 ) >> 8 ;
-  int val3 = ( val & 0xFF0000 ) >> 16 ;
-  int val4 = ( val & 0xFF000000 ) >> 24 ;
-
-  // Fill the FIFO with the requested information: write MSB first
-  int data_word_1 = 0xFFFC ;
-  int data_word_2 = 0x7000 | ( ( adr & 0xFF00 ) >> 8 ) ;
-  int data_word_3 = 0x7000 | ( adr & 0xFF ) ;
-  int data_word_4 = 0x7000 | val4 ;
-  int data_word_5 = 0x7000 | val3 ;
-  int data_word_6 = 0x7000 | val2 ;
-  int data_word_7 = 0x7000 | val1 ;
-  int data_word_8 = 0xEEEE ;
-
-
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40  , 
-		   (int) ( data_word_1 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40 , 
-		   (int) ( data_word_2 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD  + fd * 0x40 , 
-		   (int) ( data_word_3 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40  , 
-		   (int) ( data_word_4 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40  , 
-		   (int) ( data_word_5 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40  , 
-		   (int) ( data_word_6 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40  , 
-		   (int) ( data_word_7 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + fd * 0x40  , 
-		   (int) ( data_word_8 & 0xFFFFFFFF ) ) ;
-  if ( ret != 0 ) return -1 ;
-
-  // start emit
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 
-  		   1 << ( SLC_WFIFO_EMIT_BIT + fd ) ) ;
-  if ( ret != 0 ) return -1 ;
-  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 0 ) ;
-  if ( ret != 0 ) return -1 ;
-
-  return ret;
-}
-
-int pcie40_writestream( int dev , int fd , char * filename ) {
-  return 0 ;
-}
diff --git a/Pcie40Libraries/pcie40_b2slc.cpp b/Pcie40Libraries/pcie40_b2slc.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..bf86765ad1e59f65e599b4d9b0886e4953007618
--- /dev/null
+++ b/Pcie40Libraries/pcie40_b2slc.cpp
@@ -0,0 +1,524 @@
+// File for Belle2 slow control access with PCIe40 
+#include "pcie40_b2slc.h"
+#include <unistd.h>
+#include <stdio.h>
+#include <vector>
+#include <string.h>
+
+// ===== 
+// CALL C functions
+// =====
+
+extern "C" int      ecs_write(int dev, int bar, unsigned add, int val); 
+extern "C" unsigned ecs_read(int dev, int bar, unsigned add) ; 
+int pcie40_writestream_internal( int dev , int ch , char * filename , int do_sleep ) ;
+
+///////////////////////////////////////////////////////////////////////////
+// Internal functions for slow control,, do not use outside of this library
+///////////////////////////////////////////////////////////////////////////
+int pcie40_writeFifoFillLevel( int dev , int ch ) {
+  unsigned ret = 0 ;
+  ret = ecs_read( dev , SLC_BAR , SLC_RFIFO_STATUS + ch * 0x20 ) ;
+  return ( ret & 0x1FF ) ; 
+}
+
+int pcie40_readFifoFillLevel( int dev , int ch ) {
+  unsigned ret = ecs_read( dev , SLC_BAR , SLC_RFIFO_STATUS + ch * 0x20 ) ;
+  ret = ( ret & 0xFF800 ) >> 11 ;
+  return ret ;
+}
+
+int pcie40_resetWriteFifo( int dev , int ch ) { 
+  unsigned ret = 0 ;
+  unsigned wle = 0 ; 
+  // wait that the FIFO are empty
+  int i ;
+  for ( i=0 ; i<10 ; i++ ) {
+    wle = pcie40_writeFifoFillLevel( dev , ch ) ; 
+    if ( wle == 0 ) break;
+    usleep( 10 ) ; //10 ms
+  }
+
+  if (i == 10) {
+    printf( "Timeout reset write\n" ) ;
+  }
+
+  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 0 ) ;
+  if ( ret != 0 ) return -1 ;
+  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 
+		   1 << ( SLC_WFIFO_RESET_BIT + ch ) ) ;
+  if ( ret != 0 ) return -1 ;
+  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 0 ) ;
+  if ( ret != 0 ) return -1 ;
+
+  // Check that FIFO is really reset
+  wle = pcie40_writeFifoFillLevel( dev , ch ) ; 
+  if ( 0 != wle ) {
+    printf( "Write FIFO not empty\n" ) ; 
+    return -1 ; 
+  }
+
+  return ret ;
+}
+
+int pcie40_resetReadFifo( int dev , int ch ) { 
+  unsigned ret = 0 ;
+  unsigned rle = 0 ; 
+  // wait that the FIFO are empty
+  int i ;
+  for ( i=0 ; i<10 ; i++ ) {
+    rle = pcie40_readFifoFillLevel( dev , ch ) ; 
+    if ( rle == 0 ) break;
+    usleep( 10 ) ; //10 ms
+  }
+
+  if (i == 10) {
+    printf( "Timeout reset read\n" ) ;
+  }
+
+  ret = ecs_write( dev , SLC_BAR , SLC_RFIFO_RESET_ADD , 0 ) ;
+  if ( ret != 0 ) return -1 ;  
+  ret = ecs_write( dev , SLC_BAR , SLC_RFIFO_RESET_ADD , 
+		   1 << ( SLC_RFIFO_RESET_BIT + ch ) ) ;
+  if ( ret != 0 ) return -1 ;
+  ret = ecs_write( dev , SLC_BAR , SLC_RFIFO_RESET_ADD , 0 ) ;
+  if ( ret != 0 ) return -1 ;
+  // check that FIFO is empty 
+  rle = pcie40_readFifoFillLevel( dev , ch ) ; 
+  if ( 0 != rle ) { 
+    printf( "Read FIFO not empty\n" ) ; 
+    return -1 ; 
+  }
+  return ret ;
+}
+
+int pcie40_writeToFifo( int dev , int ch , std::vector< int > & data ) {
+  std::vector< int >::iterator it ;
+  unsigned ret = 0 ;
+  unsigned fl = 0 ; 
+  unsigned tries = 0 ; 
+  while ( fl != data.size() ) {
+    for ( it = data.begin() ; it != data.end() ; ++it ) {
+      ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + ch * 0x20  , 
+		       (int) ( (*it) & 0xFFFFFFFF ) ) ;
+      if ( ret != 0 ) return -1 ;
+    }
+    fl = pcie40_writeFifoFillLevel( dev , ch ) ; 
+    if ( fl == data.size() ) return ret ; 
+    // Reset Write FIFO 
+    ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 0 ) ;
+    if ( ret != 0 ) return -1 ;
+    ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 
+		     1 << ( SLC_WFIFO_RESET_BIT + ch ) ) ;
+    if ( ret != 0 ) return -1 ;
+    ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 0 ) ;
+    if ( ret != 0 ) return -1 ;
+    
+    tries++ ; 
+    if ( tries == 10 ) { 
+      printf( "Cannot write FIFO\n" ) ; 
+      return -1 ;
+    }
+  }
+  return ret ;
+}
+
+int pcie40_startEmit( int dev , int ch , int expected ) {
+  unsigned ret = 0 ;
+  if ( expected != -1 ) { 
+    // check that FIFO is written
+    ret = pcie40_writeFifoFillLevel( dev , ch ) ;
+    if ( expected != ret ) { 
+      printf( "Write FIFO not written correctly\n" ) ;
+      return -1 ; 
+    }
+  }
+
+  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_START_ADD , 0 ) ;
+  if ( ret != 0 ) return -1 ;
+  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_START_ADD , 
+         1 << ( SLC_WFIFO_EMIT_BIT + ch ) ) ;
+  if ( ret != 0 ) return -1 ;
+  ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_START_ADD , 0 ) ;
+  if ( ret != 0 ) return -1 ;
+  return ret ;
+}
+
+int pcie40_waitRead( int dev , int ch , int length ) {
+  unsigned ret = 0 ;
+  int i ;
+  for ( i=0 ; i<100 ; i++ ) {
+    ret = pcie40_readFifoFillLevel( dev , ch ) ; 
+    if ( ret == length ) break;
+    usleep( 10 ) ; //10 us
+  }
+
+  if (i == 10) {
+    printf( "Timeout\n" ) ;
+    return -1 ;
+  } 
+  return 0 ; 
+}
+
+int pcie40_readData( int dev , int ch , std::vector< int > & result , int length ) {
+  unsigned ret = 0 ;
+  int i = 0 ; 
+
+  for ( i = 0 ; i < length ; ++i ) {
+    ret = ecs_read( dev , SLC_BAR , SLC_RFIFO_ADD + ch * 0x20 );
+    result.push_back( ret ) ;
+  }
+  ret = pcie40_readFifoFillLevel( dev , ch ) ;
+  if ( ret != 0 ) { printf( "Not all FIFO read\n" ) ; } 
+  return 0 ;
+}
+/* ---------------------------------------------------------------------- *\
+   readfee8
+   returns -1 in case of error
+\* ---------------------------------------------------------------------- */
+int pcie40_readfee8( int dev , int ch , int adr) {
+  // PCIe40
+  if ( ( adr <=0 ) || ( adr > 0x7F ) ) return -1 ;
+  // Reset the FIFO (Emit)
+  unsigned ret = 0 ;
+  ret = pcie40_resetWriteFifo( dev , ch ) ;
+  if ( ret != 0 ) return ret ;
+
+  // Fill the FIFO with the requested information: write MSB first
+  std::vector< int > data ;
+  data.push_back( 0xFFFE ) ; 
+  data.push_back( 0x0001 ) ; 
+  data.push_back( 0x8000 | ( adr & 0x7F ) ) ; 
+  data.push_back( 0x000c ) ; 
+  data.push_back( 0xEEEE ) ;
+
+  ret = pcie40_writeToFifo( dev , ch , data ) ;
+  if ( ret != 0 ) return ret ;
+
+  // reset read FIFO
+  ret = pcie40_resetReadFifo( dev , ch ) ;
+  if ( ret != 0 ) return ret ;
+
+  // start emit
+  ret = pcie40_startEmit( dev , ch , 5 ) ;
+  if ( ret != 0 ) return -1 ;
+
+  // Wait for the result to come back (40 words in the fifo)
+  ret = pcie40_waitRead( dev , ch , 5 ) ;
+  if ( ret != 0 ) return -1 ;
+
+  // Read the value 
+  std::vector< int > result ; 
+  ret = pcie40_readData( dev , ch , result , 5 ) ;
+
+  int ret2 = result.at( 1 ) ; 
+  int ret3 = result.at( 2 ) ; 
+  // check address consistency
+  if ( ( ( ret2 & 0x7F ) ) != adr ) return -1 ;
+
+  return ( ret3 & 0xFF ) ;
+}
+
+//==============================================================================
+// Write 8b
+//==============================================================================
+int pcie40_writefee8( int dev , int ch , int adr , int val ) {
+  // PCIe40
+  if ( ( adr <=0 ) || ( adr > 0x7F ) ) return -1 ;
+  // Reset the FIFO
+  unsigned ret = 0 ;
+  ret = pcie40_resetWriteFifo( dev , ch ) ;
+  if ( ret != 0 ) return ret ;
+
+  // Fill the FIFO with the requested information: write MSB first
+  std::vector< int > data ;
+  data.push_back( 0xFFFF ) ; 
+  data.push_back( 0x0001 ) ; 
+  data.push_back( 0x8000 | ( adr & 0x7F ) ) ; 
+  data.push_back( 0x0000 | ( val & 0xFF ) ) ;
+  data.push_back( 0xEEEE ) ;
+  ret = pcie40_writeToFifo( dev , ch , data ) ;
+  if ( ret != 0 ) return ret ;
+
+  // start emit
+  ret = pcie40_startEmit( dev , ch , 5 ) ;
+  if ( ret != 0 ) return -1 ;
+
+  return 0 ;
+}
+
+//==============================================================================
+// Read 32b
+//==============================================================================
+unsigned long pcie40_readfee32( int dev , int ch , int adr ) {
+  // PCIe40
+  if ( ( adr <0 ) || ( adr > 0xFFFF ) ) return -1 ;
+  // Reset the FIFO
+  unsigned ret = 0 ;
+  ret = pcie40_resetWriteFifo( dev , ch ) ;
+  if ( ret != 0 ) return ret ;
+
+  // Fill the FIFO with the requested information: write MSB first
+  std::vector< int > data ;
+  data.push_back( 0xFFFB ) ; 
+  data.push_back( 0x7000 | ( ( adr & 0xFF00 ) >> 8 ) ) ; 
+  data.push_back( 0x7000 | ( adr & 0xFF ) ) ; 
+  data.push_back( 0xEEEE ) ;
+
+  ret = pcie40_writeToFifo( dev , ch , data ) ;
+  if ( ret != 0 ) return ret ;
+
+  // reset read FIFO
+  ret = pcie40_resetReadFifo( dev , ch ) ;
+  if ( ret != 0 ) return ret ;
+
+  // start emit
+  ret = pcie40_startEmit( dev , ch , 4 ) ;
+  if ( ret != 0 ) return -1 ;
+
+  // Wait for the result to come back
+  ret = pcie40_waitRead( dev , ch , 7 ) ;
+  if ( ret != 0 ) return -1 ;
+
+  // Read the value 
+  std::vector< int > result ;
+  ret = pcie40_readData( dev , ch , result , 7 ) ;
+
+  int t_ret1 = result.at(0);
+  int t_ret2 = result.at(1);
+  int t_ret3 = result.at(2);
+  int t_ret4 = result.at(3);  
+  int t_ret5 = result.at(4);
+  int t_ret6 = result.at(5);
+
+  if ( ( t_ret1 & 0x0000FFFF ) != 0xFFFF ) {
+    printf( "Bad header\n" ) ;
+    return -1 ; 
+  }
+  if ( ( t_ret6 & 0x0000FFFF ) != 0xEEEE ) { 
+    printf( "Bad trailer\n" ) ; 
+    return -1 ;
+  }
+
+  int add1 = ( t_ret2 & 0xFF00 ) >> 8 ;
+  int add2 = ( t_ret3 & 0xFF00 ) >> 8 ;
+  int add3 = ( t_ret4 & 0xFF00 ) >> 8 ;
+  int add4 = ( t_ret5 & 0xFF00 ) >> 8 ;
+  
+  if ( ( add1 & 0xF8 ) != 0x10 ) { 
+    printf( "Bad address1 %X\n" , add1 ) ; 
+    return -1 ;
+  }
+  if ( ( add2 & 0xF8 ) != 0x10 ) { 
+    printf( "Bad address2 %X\n" , add2 ) ; 
+    return -1 ;
+  }
+  if ( ( add3 & 0xF8 ) != 0x10 ) {
+    printf( "Bad address3 %X\n" , add3 ) ; 
+    return -1 ;
+  }
+  if ( ( add4 & 0xF8 ) != 0x10 ) {
+    printf( "Bad address4 %X\n" , add4 ) ; 
+    return -1 ;
+  }
+
+  add1 += 0x58 ;
+  add2 += 0x58 ;
+  add3 += 0x58 ;
+  add4 += 0x58 ;
+  
+  if ( ( add2 != 0x6C ) || ( add1 != 0x6D ) || ( add4 != 0x6A ) || ( add3 != 0x6B ) )
+    {
+      printf( "Unexpected address %X %X %X %X\n" , add1 , add2 , add3 , add4 ) ;
+      return -1 ;
+    }
+
+  int res1 = ( t_ret2 & 0xFF ) ;
+  int res2 = ( t_ret3 & 0xFF ) ;
+  int res3 = ( t_ret4 & 0xFF ) ;
+  int res4 = ( t_ret5 & 0xFF ) ;
+
+  return 0xFFFFFFFF & ( ( res1 << 24 ) | ( res2 << 16 ) | ( res3 << 8 ) | ( res4 ) ) ;
+}
+
+//==============================================================================
+// Write 32b
+//==============================================================================
+int pcie40_writefee32( int dev , int ch , int adr , int val ) { 
+  // PCIe40
+  if ( ( adr <0 ) || ( adr > 0xFFFF ) ) return -1 ;
+  // Reset the FIFO
+  unsigned ret = 0 ;
+  ret = pcie40_resetWriteFifo( dev , ch ) ;
+  if ( ret != 0 ) return ret ;
+
+  int val1 = ( val & 0xFF ) ;
+  int val2 = ( val & 0xFF00 ) >> 8 ;
+  int val3 = ( val & 0xFF0000 ) >> 16 ;
+  int val4 = ( val & 0xFF000000 ) >> 24 ;
+
+  // Fill the FIFO with the requested information: write MSB first
+  std::vector< int > data ;
+  data.push_back( 0xFFFC ) ; 
+  data.push_back( 0x7000 | ( ( adr & 0xFF00 ) >> 8 ) ) ; 
+  data.push_back( 0x7000 | ( adr & 0xFF ) ) ; 
+  data.push_back( 0x7000 | val4 ) ; 
+  data.push_back( 0x7000 | val3 ) ; 
+  data.push_back( 0x7000 | val2 ) ; 
+  data.push_back( 0x7000 | val1 ) ;
+  data.push_back( 0xEEEE ) ;
+
+  ret = pcie40_writeToFifo( dev , ch , data ) ;
+  if ( ret != 0 ) return ret ;
+
+  // start emit
+  ret = pcie40_startEmit( dev , ch , 8 ) ;
+  if ( ret != 0 ) return -1 ;
+
+  return ret;
+}
+
+
+int pcie40_writestream_klm( int dev , int ch , char * filename ) { 
+  return pcie40_writestream_internal( dev , ch , filename , 0 ) ;
+}
+
+int pcie40_writestream_arich( int dev , int ch , char * filename ) { 
+  return pcie40_writestream_internal( dev , ch , filename , 1 ) ;
+}
+
+int pcie40_writestream( int dev , int ch , char *filename , const char * detector )  { 
+  if ( strcmp( detector , "KLM" ) == 0 ) { 
+    return pcie40_writestream_klm( dev , ch , filename ) ;
+  } else if ( strcmp( detector , "ARICH" ) == 0 ) { 
+    return pcie40_writestream_arich( dev , ch , filename ) ; 
+  } 
+  printf( "ERROR : detector not supported\n" ) ;
+  return -1 ; 
+} 
+
+int pcie40_writestream_internal( int dev , int ch , char * filename , int do_sleep ) {
+  // PCIe40
+  // Check if the file exists
+  const char * mode = "r" ; 
+  FILE * fp = fopen( filename , mode ) ;
+  if ( 0 == fp ) {
+    printf( "The file does not exist\n" ) ;
+    return -1 ; 
+  }
+
+  unsigned ret = 0 ;
+ 
+  // Read the file
+  int c = 0 ;
+  int count = 0 ;
+  int count_sleep = 0 ;
+  std::vector< int > data ; 
+  while ((c = getc(fp)) != EOF) {
+    if ( count == 0 ) // Stream write : insert FFFD
+      data.push_back( 0xFFFD ) ; 
+    count++ ; count_sleep++ ;
+    data.push_back( (int) ( ( ( 0x70 << 8 ) | ( c & 0xFF ) ) & 0xFFFFFFFF ) ) ;
+
+    if ( 6 == count ) {
+      data.push_back( 0xEEEE ) ;
+      // Reset the FIFO
+      ret = pcie40_resetWriteFifo( dev , ch ) ;
+      
+      if ( ret != 0 ) { 
+	fclose( fp ) ; 
+	return -1 ;
+      }
+
+      ret = pcie40_writeToFifo( dev , ch , data ) ;
+      if ( ret != 0 ) { 
+        fclose( fp ) ; 
+        return -1 ;
+      }    
+      ret = pcie40_startEmit( dev , ch , -1 ) ;
+      if ( ret != 0 ) { 
+        fclose( fp ) ; 
+        return -1 ;
+      }  
+      if ( ( count_sleep >= 100 ) && ( do_sleep ) ) {
+	usleep( 1 ) ; 
+	count_sleep = 0 ;
+      }
+      count = 0 ; 
+      data.clear() ;
+    }
+  }
+  fclose( fp ) ;
+
+  // End of the file -> 0xEEEE 
+  data.push_back( 0xEEEE ) ; 
+
+  // Reset the FIFO
+  ret = pcie40_resetWriteFifo( dev , ch ) ;
+  
+  if ( ret != 0 ) { 
+    fclose( fp ) ; 
+    return -1 ;
+  }
+  
+  ret = pcie40_writeToFifo( dev , ch , data ) ;
+  if ( ret != 0 ) return -1 ;
+
+  // start emit
+  ret = pcie40_startEmit( dev , ch , -1 ) ; 
+  if ( ret != 0 ) return -1 ;
+
+  return ret ;
+}
+
+int pcie40_writebytestream( int dev, int ch, int len, const char *bytes  )
+{
+  unsigned ret = 0 ;
+ 
+  // Read the file
+  int c = 0 ;
+  int i = 0 ;
+  int count = 0 ;
+  std::vector< int > data ; 
+  while ( len != i ) {
+    if ( count == 0 ) // Stream write : insert FFFD
+      data.push_back( 0xFFFD ) ; 
+    count++ ; 
+    c = bytes[ i ] ; 
+    i++ ; 
+    data.push_back( (int) ( ( ( 0x70 << 8 ) | ( c & 0xFF ) ) & 0xFFFFFFFF ) ) ;
+
+    if ( 6 == count ) {
+      data.push_back( 0xEEEE ) ;
+      // Reset the FIFO
+      ret = pcie40_resetWriteFifo( dev , ch ) ;
+      
+      if ( ret != 0 ) return -1 ;
+
+      ret = pcie40_writeToFifo( dev , ch , data ) ;
+      if ( ret != 0 ) return -1 ;
+      ret = pcie40_startEmit( dev , ch , -1 ) ;
+      if ( ret != 0 ) return -1 ;
+
+      count = 0 ; 
+      data.clear() ;
+    }
+  }
+
+  // End of the file -> 0xEEEE 
+  data.push_back( 0xEEEE ) ; 
+
+  // Reset the FIFO
+  ret = pcie40_resetWriteFifo( dev , ch ) ;
+  
+  if ( ret != 0 ) return -1 ;
+  
+  ret = pcie40_writeToFifo( dev , ch , data ) ;
+  if ( ret != 0 ) return -1 ;
+
+  // start emit
+  ret = pcie40_startEmit( dev , ch , -1 ) ; 
+  if ( ret != 0 ) return -1 ;
+
+  return ret ;
+}
diff --git a/Pcie40Libraries/pcie40_b2slc.h b/Pcie40Libraries/pcie40_b2slc.h
index 2b50c037578e36ad5cd82bd3fb620e3f124a2915..c07e7ccdec577d12db16c5ae66c481553afb4ad6 100644
--- a/Pcie40Libraries/pcie40_b2slc.h
+++ b/Pcie40Libraries/pcie40_b2slc.h
@@ -6,25 +6,37 @@
 // BAR number for Slow control interface
 #define SLC_BAR 2
 // Address of the register to reset the write FIFO and bit to use
-#define SLC_WFIFO_RESET_ADD 0x00050200
-#define SLC_WFIFO_RESET_BIT 8
-#define SLC_WFIFO_START_ADD 0x00050260
+#define SLC_WFIFO_RESET_ADD 0x00050560
+#define SLC_WFIFO_RESET_BIT 0
+#define SLC_RFIFO_RESET_ADD 0x000505a0
+#define SLC_RFIFO_RESET_BIT 0
+#define SLC_WFIFO_START_ADD 0x00050480
 #define SLC_WFIFO_EMIT_BIT 0
 #define SLC_WFIFO_ADD 0x00060000
-#define SLC_RFIFO_STATUS 0x00060120
-#define SLC_RFIFO_ADD 0x00060100
+#define SLC_RFIFO_STATUS 0x00060010
+#define SLC_RFIFO_ADD 0x00060000
 
 // Functions to read/write registers and stream files to Front End
+#ifndef USE_PCIE40
+extern "C" {
+#endif 
+int pcie40_readfee8(int dev, int ch, int adr);
 
-int pcie40_readfee8(int dev, int fd, int adr);
+int pcie40_writefee8(int dev, int ch, int adr, int val);
 
-int pcie40_writefee8(int dev, int fd, int adr, int val);
+unsigned long pcie40_readfee32(int dev, int ch, int adr);
 
-unsigned long pcie40_readfee32(int dev, int fd , int adr);
+int pcie40_writefee32(int dev, int ch, int adr, int val);
 
-int pcie40_writefee32(int dev, int fd , int adr, int val);
+int pcie40_writestream_klm(int dev, int ch, char *filename);
+int pcie40_writestream_arich(int dev, int ch, char *filename);
+int pcie40_writestream( int dev , int ch , char *filename , const char * detector ) ;
 
-int pcie40_writestream(int dev, int fd , char *filename);
+int pcie40_writebytestream(int dev, int ch, int len, const char *bytes);
+
+#ifndef USE_PCIE40
+}
+#endif
 
 #endif // PCIE40_B2SLC_H
 
diff --git a/Python/components/fpga_comp.py b/Python/components/fpga_comp.py
index fa108773e67da639cc7fb44ee69a5819c0ea02d5..2aee8e6f2b3cf5ed630efa3c92d1ef4e72379e62 100644
--- a/Python/components/fpga_comp.py
+++ b/Python/components/fpga_comp.py
@@ -540,16 +540,24 @@ class Arria10(object):
         char = ""
         string = ""
         status, val = mem.read(self.dev, base_address + 0)
-        if chr(val) == "{":
-            while char != "}":
-                status, val = mem.read(self.dev, base_address + 4 * word)
-                word += 1
-                char = chr(val)
-                string += char
-        else:
-            string = "{\"design_version\" : \"not implemented\"}"
-
-        return json.loads(string)
+        try:
+            if chr(val) == "{":
+                while char != "}":
+                    status, val = mem.read(self.dev, base_address + 4 * word)
+                    word += 1
+                    char = chr(val)
+                    string += char
+            else:
+                string = "{\"design_version\" : \"not implemented\"}"
+        except:
+                string = "{\"design_version\" : \"not implemented\"}"            
+        string=string.rstrip('0}')+'}'
+        jsret = None
+        try: 
+            jsret = json.loads( string )
+        except:
+            jsret = json.loads("{\"design_version\" : \"not implemented\"}")
+        return jsret
 
     def runNumber(self): 
         status, val = mem.read( self.dev , 0x00050020 )
@@ -557,7 +565,7 @@ class Arria10(object):
 
     def triggerTag(self): 
         status, val = mem.read( self.dev , 0x00050040 )
-        return ( val & 0xFF00 ) >> 8 | ( val & 0x00FF ) << 8  
+        return val   
 
     def clockUp(self):
         status, val = mem.read( self.dev , 0x00050000 )
@@ -579,24 +587,82 @@ class Arria10(object):
         status, val = mem.read( self.dev , 0x00050000 )
         return ( val & 0x1 ) >> 0 
 
+    def rxReadyIndividual(self, i):
+        add = 0x00050160
+        if ( i > 23 ): add = 0x00050180
+        status, val = mem.read( self.dev , add )
+        return ( val & ( 0x1 << (i%24) ) ) >> (i%24) 
+
+    def validChannel(self,i):
+        add = 0x00050520
+        if ( i > 23 ): add = 0x00050540
+        status, val = mem.read( self.dev , add )
+        return ( val & ( 0x1 << (i%24) ) ) >> (i%24)         
+
     def txReady(self):
         status, val = mem.read( self.dev , 0x00050000 )
         return ( val & 0x2 ) >> 1 
 
+    def txReadyIndividual(self, i):
+        add = 0x000501a0
+        if ( i > 23 ) : add = 0x000501C0
+        status, val = mem.read( self.dev , add )
+        return ( val & ( 0x1 << (i%24) ) ) >> ( i%24 )          
+
     def b2linkReady(self):
         status, val = mem.read( self.dev , 0x00050000 )
         return ( val & 0x4 ) >> 2 
+
+    def b2linkReadyIndividual(self, i):
+        add1 = 0x000500E0
+        add2 = 0x00050120
+        if ( i > 23 ):
+            add1 = 0x00050100
+            add2 = 0x00050140
+        status, val1 = mem.read( self.dev , add1 )
+        status, val2 = mem.read( self.dev , add2 )
+        return ( ( ( val1 & ( 0x1 << (i%24) ) ) >> (i%24) ) & ( ( val2 & ( 0x1 << (i%24) ) ) >> (i%24) ) ) 
         
-    def resynchronizeLink(self):
-        mem.write( self.dev , 0x00050100 , 0x0 )
-        mem.write( self.dev , 0x00050100 , 0x4 )
-        mem.write( self.dev , 0x00050100 , 0x0 )
+    def resynchronizeLink(self, i ):
+        add = 0x00050440
+        if ( i > 23 ) : add = 0x00050460
+        mem.write( self.dev , add , 0x0 )
+        mem.write( self.dev , add , 0x1 << (i%24) )
+        mem.write( self.dev , add , 0x0 )
 
     def resetTriggerCounter(self):
         mem.write( self.dev , 0x00050100 , 0x0 )
         mem.write( self.dev , 0x00050100 , 0x2 )
         mem.write( self.dev , 0x00050100 , 0x0 )
 
+    def activateAllChannels(self):
+        mem.write( self.dev , 0x00050520 , 0xFFFFFF ) 
+        mem.write( self.dev , 0x00050540 , 0xFFFFFF ) 
+
+    def deactivateAllChannels(self):
+        mem.write( self.dev , 0x00050520 , 0x0 ) 
+        mem.write( self.dev , 0x00050540 , 0x0 ) 
+
+    def toggleActivateChannel( self , i):
+        if ( i < 24 ):
+            status, val = mem.read( self.dev , 0x00050520 )
+            stat = ( ( 1 << i ) & val ) >> i  
+            if stat == 1:
+                new_val = ( ~( ( 1 << i ) & val ) & 0xFFFFFF ) & val
+                mem.write( self.dev , 0x00050520 , new_val ) 
+            else:
+                new_val = ( ( 1 << i ) | val ) 
+                mem.write( self.dev , 0x00050520 , new_val ) 
+        else: 
+            status, val = mem.read( self.dev , 0x00050540 )
+            stat = ( ( 1 << ( i -24 ) ) & val ) >> ( i - 24 ) 
+            if stat == 1:
+                new_val = ( ~( ( 1 << ( i - 24 ) ) & val ) & 0xFFFFFF ) & val
+                mem.write( self.dev , 0x00050540 , new_val ) 
+            else:
+                new_val = ( ( 1 << ( i - 24 ) ) | val ) 
+                mem.write( self.dev , 0x00050540 , new_val ) 
+
 def main():
     """ Main function
     instanciation of Class Si534x()
diff --git a/Python/lli/mem_multi.py b/Python/lli/mem_multi.py
index 2f593766664a138debd1637bddf148e61486583b..e419336421db61a9ee80d8c826b62611a979a029 100644
--- a/Python/lli/mem_multi.py
+++ b/Python/lli/mem_multi.py
@@ -75,7 +75,7 @@ def read(board, add):
     status = lli.ecs_iordBar(board, 2, add, byref(cval))
 
     if ((cval.value & 0xffffffff) == 0xffffffff):
-        print "ERROR: read 0xffffffff at "+hex(add & 0xffffffff)
+        # print "ERROR: read 0xffffffff at "+hex(add & 0xffffffff)
         status = -1
     else:
         # print "OK passed read  at 0x%08x value 0x%08x" % \
diff --git a/README.md b/README.md
index 5121ef59165a77333c5163bce6629419e15c737a..c42d5f214c03599f1b152f402c5f3115ed12ba4a 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,59 @@
 # Software
 
-Instructions how to install the software can be found [here](https://gitlab.in2p3.fr/belle2-daq-upgrade/software/wikis/Installation) 
+## Instructions how to install the software  
 
-To use the software, instructions can be found [here](https://gitlab.in2p3.fr/belle2-daq-upgrade/software/wikis/Scripts)
-and the list of test programs is [here](https://gitlab.in2p3.fr/belle2-daq-upgrade/software/wikis/TestPrograms)
\ No newline at end of file
+`sudo yum install kernel-devel`
+
+`sudo yum install epel-release`
+
+`sudo yum install python-pip`
+
+`sudo yum install python-devel`
+
+`sudo yum groupinstall 'development tools'`
+
+`pip install py`
+
+To clone the repository using 
+```ssh://git@stash.desy.de:7999/bidu/software.git```
+
+Build the software (driver, interface libraries, application programs ...)
+
+`cd Software`
+
+`make`
+
+## To use the software
+
+- Setup the environment variables
+
+`cd Scripts`
+
+`source setup.sh`
+
+- Re-load the PCIe bus (mandatory after a new firmware is programmed)
+
+`pcie40_reload`
+
+- Sometimes, reloading the driver is also mandatory (after power off or when something goes wrong)
+
+`pcie40_reload -m`
+
+## How to use the application programs.
+- `python pll_status.py 0`: configure the clock tree. Press `F2` to use the clock from FTSW or `F3` to use the local oscillator clock (also with a frequency of 127.1 MHz). This application needs a large terminal to work correctly otherwise it will not open
+
+- `python pll_status_small.py 0`: configure the clock tree. Press `F2` to use the clock from FTSW or `F3` to use the local oscillator clock (also with a frequency of 127.1 MHz). This application works on small terminal window but will display less information than `pll_status.py`
+
+- `python testBL.py`: send a trigger from the FTSW board and read data back in the PCIe40 (edit the file to adapt the name of the VME controller board to communicate with the FTSW module)
+
+- `pcie40_reload`: reload the driver after programming the firmware of the PCIe40 board. After reloading the driver, you also need to correct the device file permissions with `sudo chmod o+rw /dev/pcie40_0_*`
+
+- `pcie40_program -c 1 file.sof`: program the firmware of the PCIe40 board with `file.sof`
+
+- `pcie40_ecs -b 2 -a N -r`: read 32 bits at address N of the BAR2 register space
+
+- `pcie40_ecs -b 2 -a N -w D`: write D at address N of the BAR register space
+
+- `pcie40_b2slc`: slow control register access 
+
+## Start-Kit manual for usage of PCIe40 can be found [here](https://confluence.desy.de/display/BI/PCIe40+Documentation?preview=/145594091/145594869/PCIe40_StartKit.pdf)
diff --git a/ROPCApplications/daq/dataobjects/SConscript b/ROPCApplications/daq/dataobjects/SConscript
new file mode 100644
index 0000000000000000000000000000000000000000..8add187a02b76b64493e5ca86560cc30dd60390a
--- /dev/null
+++ b/ROPCApplications/daq/dataobjects/SConscript
@@ -0,0 +1,5 @@
+Import('env')
+
+env['LIBS'] = ['$ROOT_LIBS', 'rawdata_dataobjects']
+
+Return('env')
diff --git a/ROPCApplications/daq/dataobjects/include/SendHeader.h b/ROPCApplications/daq/dataobjects/include/SendHeader.h
new file mode 100644
index 0000000000000000000000000000000000000000..3124e69f5e18d92d0c4bc72a38aa691908115335
--- /dev/null
+++ b/ROPCApplications/daq/dataobjects/include/SendHeader.h
@@ -0,0 +1,93 @@
+//+
+// File : SendHeader.h
+// Description : Module to handle SendHeader attached by COPPER DAQ
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef SENDHEADER_H
+#define SENDHEADER_H
+
+#include "rawdata/dataobjects/RawHeader_latest.h"
+
+namespace Belle2 {
+
+  //  class SendHeader : public TObject {
+  class SendHeader {
+  public:
+
+    //! Default constructor
+    SendHeader();
+
+    //! Constructor using existing pointer to raw data buffer
+    SendHeader(int*);
+    //! Destructor
+    ~SendHeader();
+
+    //! Get Header contents
+    int* GetBuffer(void);
+
+    //! set buffer
+    void SetBuffer(int* hdr);
+
+    void Initialize(); //! initialize Header
+
+    void SetNwords(int total_data_nwords);    //! set contents of Header
+
+    void SetNumEventsinPacket(int num_events);
+    void SetNumNodesinPacket(int num_nodes);
+    void SetEventNumber(int eve_num);
+    void SetNodeID(int node_id);
+
+    void SetExpRunWord(unsigned int exp_run);
+
+
+    void SetRunNum(int run_num);   //!
+    void SetSubRunNum(int subrun_num);  //!
+    void SetExpNum(int exp_num);   //!
+
+    int GetTotalNwords();  //! get contents of Header
+    int GetHdrNwords();  //! get contents of Header
+    int GetNumEventsinPacket();
+    int GetNumNodesinPacket();
+    int GetEventNumber();
+    int GetNodeID();
+
+    int GetRunNum(); //!
+    int GetSubRunNum(); //!
+    int GetExpNum(); //!
+    int GetRunNumSubRunNum(); //!
+
+    RawHeader_latest tmp_header; //!
+
+    /* Data Format : Node info */
+    enum {
+      SENDHDR_NWORDS = 6
+    };
+
+  private:
+
+    /* Data Format : Fixed length part*/
+    enum {
+      POS_NWORDS = 0,
+      POS_HDR_NWORDS = 1,
+      POS_NUM_EVE_NUM_NODES = 2,
+      POS_EXP_RUN_NUM = 3,
+      POS_EVE_NUM = 4,
+      POS_NODE_ID = 5
+    };
+
+
+
+    int m_buffer[ SENDHDR_NWORDS ];
+
+    //    ClassDef(SendHeader, 1);
+  };
+
+
+
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/dataobjects/include/SendTrailer.h b/ROPCApplications/daq/dataobjects/include/SendTrailer.h
new file mode 100644
index 0000000000000000000000000000000000000000..ec08df6416165255be321a0fa6e4e204beb8d954
--- /dev/null
+++ b/ROPCApplications/daq/dataobjects/include/SendTrailer.h
@@ -0,0 +1,60 @@
+//+
+// File : SendTrailer.h
+// Description : Module to handle SendTrailer attached by COPPER DAQ
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef SENDTRAILER_H
+#define SENDTRAILER_H
+
+namespace Belle2 {
+
+  //  class SendTrailer{
+  //  class SendTrailer : public TObject {
+  class SendTrailer {
+  public:
+    //! Default constructor
+    SendTrailer();
+
+    //! Constructor using existing pointer to raw data buffer
+    SendTrailer(int*);
+
+    //! Destructor
+    ~SendTrailer();
+
+    int* GetBuffer(); //! return buffer
+
+    void SetBuffer(int* bufin); //! set buffer
+
+    void Initialize(); //! initialize header
+
+    void SetChksum(int chksum);   //! initialize header
+
+    void SetMagicWord(); //!
+
+    int GetTrlNwords(); //!
+
+    int GetMagicWord(); //!
+
+    enum {
+      SENDTRL_NWORDS = 2
+    };
+  private:
+
+    enum {
+      POS_CHKSUM = 0,
+      POS_TERM_WORD = 1
+    };
+
+    enum {
+      MAGIC_WORD_SEND_TRAILER = 0x7fff0007
+    };
+
+    int m_buffer[ SENDTRL_NWORDS ];
+    //    ClassDef(SendTrailer, 1);
+  };
+}
+
+#endif
diff --git a/ROPCApplications/daq/dataobjects/include/SndHdrTemp.h b/ROPCApplications/daq/dataobjects/include/SndHdrTemp.h
new file mode 100644
index 0000000000000000000000000000000000000000..154a9fd8568099be157f709d3f30a292ee7fc042
--- /dev/null
+++ b/ROPCApplications/daq/dataobjects/include/SndHdrTemp.h
@@ -0,0 +1,95 @@
+//+
+// File : SndHdrTemp.h
+// Description : Module to handle SndHdrTemp attached by COPPER DAQ
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef SNDHDRTEMP_H
+#define SNDHDRTEMP_H
+
+#include <TObject.h>
+
+#include "rawdata/dataobjects/RawHeader_latest.h"
+
+namespace Belle2 {
+
+  class SndHdrTemp : public TObject {
+    //  class SndHdrTemp {
+  public:
+
+    //! Default constructor
+    SndHdrTemp();
+
+    //! Constructor using existing pointer to raw data buffer
+    SndHdrTemp(int*);
+    //! Destructor
+    ~SndHdrTemp();
+
+    //! Get Header contents
+    int* GetBuffer(void);
+
+    //! set buffer
+    void SetBuffer(int* hdr);
+
+    void Initialize(); //! initialize Header
+
+    void SetNwords(int total_data_nwords);    //! set contents of Header
+
+    void SetNumEventsinPacket(int num_events);
+    void SetNumNodesinPacket(int num_nodes);
+    void SetEventNumber(int eve_num);
+    void SetNodeID(int node_id);
+
+    void SetExpRunWord(unsigned int exp_run);
+
+
+    void SetRunNum(int run_num);   //!
+    void SetSubRunNum(int subrun_num);  //!
+    void SetExpNum(int exp_num);   //!
+
+    int GetTotalNwords();  //! get contents of Header
+    int GetHdrNwords();  //! get contents of Header
+    int GetNumEventsinPacket();
+    int GetNumNodesinPacket();
+    int GetEventNumber();
+    int GetNodeID();
+
+    int GetRunNum(); //!
+    int GetSubRunNum(); //!
+    int GetExpNum(); //!
+    int GetRunNumSubRunNum(); //!
+
+    RawHeader_latest tmp_header; //!
+
+    /* Data Format : Node info */
+    enum {
+      SENDHDR_NWORDS = 6
+    };
+
+  private:
+
+    /* Data Format : Fixed length part*/
+    enum {
+      POS_NWORDS = 0,
+      POS_HDR_NWORDS = 1,
+      POS_NUM_EVE_NUM_NODES = 2,
+      POS_EXP_RUN_NUM = 3,
+      POS_EVE_NUM = 4,
+      POS_NODE_ID = 5
+    };
+
+
+
+    int m_buffer[ SENDHDR_NWORDS ];
+
+    ClassDef(SndHdrTemp, 1);
+  };
+
+
+
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/dataobjects/include/linkdef.h b/ROPCApplications/daq/dataobjects/include/linkdef.h
new file mode 100644
index 0000000000000000000000000000000000000000..cbd658a3d46c2df2a7a29257e8a6dd0fbadeaf7a
--- /dev/null
+++ b/ROPCApplications/daq/dataobjects/include/linkdef.h
@@ -0,0 +1,11 @@
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+#pragma link C++ nestedclasses;
+
+#pragma link C++ class Belle2::SendHeader+;
+#pragma link C++ class Belle2::SendTrailer+;
+#pragma link C++ class Belle2::SndHdrTemp+;
+#endif
diff --git a/ROPCApplications/daq/dataobjects/src/SendHeader.cc b/ROPCApplications/daq/dataobjects/src/SendHeader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..263328270aded199584c7e1329b983aa360f0b1a
--- /dev/null
+++ b/ROPCApplications/daq/dataobjects/src/SendHeader.cc
@@ -0,0 +1,161 @@
+//+
+// File : SendHeader.cc
+// Description : Module to handle SendHeader attached by COPPER DAQ
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include "daq/dataobjects/SendHeader.h"
+
+using namespace std;
+using namespace Belle2;
+
+//ClassImp(SendHeader);
+
+SendHeader::SendHeader()
+{
+  Initialize();
+  //  cout << "SendHeader NULL constructor" << endl;
+}
+
+SendHeader::SendHeader(int* buffer)
+{
+  //  cout << "SendHeader constructor with buffer" << endl;
+  memcpy(m_buffer, buffer, SENDHDR_NWORDS * sizeof(int));
+}
+
+SendHeader::~SendHeader()
+{
+}
+
+int* SendHeader::GetBuffer()
+{
+  return m_buffer;
+}
+
+void SendHeader::SetBuffer(int* bufin)
+{
+  memcpy(m_buffer, bufin, SENDHDR_NWORDS * sizeof(int));
+}
+
+void SendHeader::Initialize()
+{
+  memset(m_buffer, 0, sizeof(int)* SENDHDR_NWORDS);
+  m_buffer[ POS_HDR_NWORDS ] = SENDHDR_NWORDS;
+}
+
+
+// Set Values
+
+void SendHeader::SetNwords(int total_data_nwords)
+{
+  m_buffer[ POS_NWORDS ] = total_data_nwords;
+}
+
+void SendHeader::SetExpRunWord(unsigned int exp_run)
+{
+  m_buffer[ POS_EXP_RUN_NUM ] = exp_run;
+}
+
+void SendHeader::SetNumEventsinPacket(int num_events)
+{
+  m_buffer[ POS_NUM_EVE_NUM_NODES ] =
+    (m_buffer[ POS_NUM_EVE_NUM_NODES ] & 0x0000FFFF) |
+    ((num_events << 16) & 0xFFFF0000);
+}
+
+void SendHeader::SetNumNodesinPacket(int num_nodes)
+{
+  m_buffer[ POS_NUM_EVE_NUM_NODES ] =
+    (m_buffer[ POS_NUM_EVE_NUM_NODES ] & 0xFFFF0000) |
+    (num_nodes & 0x0000FFFF);
+}
+
+
+void SendHeader::SetEventNumber(int eve_num)
+{
+  m_buffer[ POS_EVE_NUM ] = eve_num;
+}
+
+
+void SendHeader::SetNodeID(int node_id)
+{
+  m_buffer[ POS_NODE_ID ] = node_id;
+}
+
+
+void SendHeader::SetRunNum(int run_num)
+{
+
+  unsigned int inv_mask = ~((unsigned int)(tmp_header.RUNNO_MASK));
+  m_buffer[ POS_EXP_RUN_NUM ] =
+    ((unsigned int)m_buffer[ POS_EXP_RUN_NUM ] & inv_mask) |
+    (((unsigned int)run_num << tmp_header.RUNNO_SHIFT) & tmp_header.RUNNO_MASK);
+
+  return;
+}
+
+void SendHeader::SetSubRunNum(int subrun_num)
+{
+
+  unsigned int inv_mask = ~((unsigned int)(tmp_header.SUBRUNNO_MASK));
+  m_buffer[ POS_EXP_RUN_NUM ] =
+    ((unsigned int)m_buffer[ POS_EXP_RUN_NUM ] & inv_mask) | ((unsigned int)subrun_num & tmp_header.SUBRUNNO_MASK);
+  return;
+}
+
+void SendHeader::SetExpNum(int exp_num)
+{
+
+  unsigned int inv_mask = ~((unsigned int)(tmp_header.EXP_MASK));
+  m_buffer[ POS_EXP_RUN_NUM ] =
+    ((unsigned int)m_buffer[ POS_EXP_RUN_NUM ] & inv_mask) |
+    (((unsigned int)exp_num << tmp_header.EXP_SHIFT) & tmp_header.EXP_MASK);
+
+  return;
+}
+
+
+
+// Get Values
+
+int SendHeader::GetTotalNwords() {  return m_buffer[ POS_NWORDS ];}
+int SendHeader::GetHdrNwords() {    return SENDHDR_NWORDS; }
+int SendHeader::GetNumEventsinPacket()
+{
+  return
+    ((m_buffer[ POS_NUM_EVE_NUM_NODES ] & 0xFFFF0000) >> 16) & 0x0000FFFF;
+
+}
+int SendHeader::GetNumNodesinPacket() {  return m_buffer[ POS_NUM_EVE_NUM_NODES ] & 0x0000FFFF; }
+
+int SendHeader::GetEventNumber() { return m_buffer[ POS_EVE_NUM ]; }
+
+int SendHeader::GetNodeID() { return m_buffer[ POS_NODE_ID ]; }
+
+int SendHeader::GetRunNum()
+{
+  return (((unsigned int)(m_buffer[ POS_EXP_RUN_NUM ]) & tmp_header.RUNNO_MASK) >> tmp_header.RUNNO_SHIFT);
+}
+
+int SendHeader::GetSubRunNum()
+{
+  return ((unsigned int)(m_buffer[ POS_EXP_RUN_NUM ]) & tmp_header.SUBRUNNO_MASK);
+}
+
+int SendHeader::GetRunNumSubRunNum()
+{
+
+  return ((unsigned int)(m_buffer[ POS_EXP_RUN_NUM ]) &
+          (tmp_header.RUNNO_MASK | tmp_header.SUBRUNNO_MASK));
+}
+
+
+int SendHeader::GetExpNum()
+{
+
+  return (((unsigned int)(m_buffer[ POS_EXP_RUN_NUM ]) & tmp_header.EXP_MASK) >> tmp_header.EXP_SHIFT);
+}
+
+
diff --git a/ROPCApplications/daq/dataobjects/src/SendTrailer.cc b/ROPCApplications/daq/dataobjects/src/SendTrailer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..50ff95919d8ed1b28673bcf0d8804cc713c78a20
--- /dev/null
+++ b/ROPCApplications/daq/dataobjects/src/SendTrailer.cc
@@ -0,0 +1,68 @@
+//+
+// File : SendTrailer.h
+// Description : Module to handle SendTrailer attached by COPPER DAQ
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include "daq/dataobjects/SendTrailer.h"
+
+#include <cstring>
+
+using namespace std;
+using namespace Belle2;
+
+//ClassImp(SendTrailer);
+
+SendTrailer::SendTrailer()
+{
+  Initialize();
+  //  cout << "SendTrailer NULL constructor" << endl;
+}
+
+SendTrailer::SendTrailer(int* buffer)
+{
+  memcpy(m_buffer, buffer, SENDTRL_NWORDS * sizeof(int));
+}
+
+SendTrailer::~SendTrailer()
+{
+}
+
+int* SendTrailer::GetBuffer()
+{
+  return m_buffer;
+}
+
+void SendTrailer::SetBuffer(int* bufin)
+{
+  memcpy(m_buffer, bufin, SENDTRL_NWORDS * sizeof(int));
+}
+
+void SendTrailer::Initialize()
+{
+  memset(m_buffer, 0, SENDTRL_NWORDS * sizeof(int));
+  SetMagicWord();
+}
+
+
+void SendTrailer::SetChksum(int chksum)
+{
+  m_buffer[ POS_CHKSUM ] = chksum;
+}
+
+void SendTrailer::SetMagicWord()
+{
+  m_buffer[ POS_TERM_WORD ] = MAGIC_WORD_SEND_TRAILER;
+}
+
+int SendTrailer::GetMagicWord()
+{
+  return m_buffer[ POS_TERM_WORD ];
+}
+
+int SendTrailer::GetTrlNwords()
+{
+  return SENDTRL_NWORDS;
+}
diff --git a/ROPCApplications/daq/dataobjects/src/SndHdrTemp.cc b/ROPCApplications/daq/dataobjects/src/SndHdrTemp.cc
new file mode 100644
index 0000000000000000000000000000000000000000..549f52489d4e2ac27279b564539f876eb559e0eb
--- /dev/null
+++ b/ROPCApplications/daq/dataobjects/src/SndHdrTemp.cc
@@ -0,0 +1,161 @@
+//+
+// File : SendHeader.cc
+// Description : Module to handle SendHeader attached by COPPER DAQ
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include "daq/dataobjects/SndHdrTemp.h"
+
+using namespace std;
+using namespace Belle2;
+
+ClassImp(SndHdrTemp);
+
+SndHdrTemp::SndHdrTemp()
+{
+  Initialize();
+  //  cout << "SndHdrTemp NULL constructor" << endl;
+}
+
+SndHdrTemp::SndHdrTemp(int* buffer)
+{
+  //  cout << "SndHdrTemp constructor with buffer" << endl;
+  memcpy(m_buffer, buffer, SENDHDR_NWORDS * sizeof(int));
+}
+
+SndHdrTemp::~SndHdrTemp()
+{
+}
+
+int* SndHdrTemp::GetBuffer()
+{
+  return m_buffer;
+}
+
+void SndHdrTemp::SetBuffer(int* bufin)
+{
+  memcpy(m_buffer, bufin, SENDHDR_NWORDS * sizeof(int));
+}
+
+void SndHdrTemp::Initialize()
+{
+  memset(m_buffer, 0, sizeof(int)* SENDHDR_NWORDS);
+  m_buffer[ POS_HDR_NWORDS ] = SENDHDR_NWORDS;
+}
+
+
+// Set Values
+
+void SndHdrTemp::SetNwords(int total_data_nwords)
+{
+  m_buffer[ POS_NWORDS ] = total_data_nwords;
+}
+
+void SndHdrTemp::SetExpRunWord(unsigned int exp_run)
+{
+  m_buffer[ POS_EXP_RUN_NUM ] = exp_run;
+}
+
+void SndHdrTemp::SetNumEventsinPacket(int num_events)
+{
+  m_buffer[ POS_NUM_EVE_NUM_NODES ] =
+    (m_buffer[ POS_NUM_EVE_NUM_NODES ] & 0x0000FFFF) |
+    ((num_events << 16) & 0xFFFF0000);
+}
+
+void SndHdrTemp::SetNumNodesinPacket(int num_nodes)
+{
+  m_buffer[ POS_NUM_EVE_NUM_NODES ] =
+    (m_buffer[ POS_NUM_EVE_NUM_NODES ] & 0xFFFF0000) |
+    (num_nodes & 0x0000FFFF);
+}
+
+
+void SndHdrTemp::SetEventNumber(int eve_num)
+{
+  m_buffer[ POS_EVE_NUM ] = eve_num;
+}
+
+
+void SndHdrTemp::SetNodeID(int node_id)
+{
+  m_buffer[ POS_NODE_ID ] = node_id;
+}
+
+
+void SndHdrTemp::SetRunNum(int run_num)
+{
+
+  unsigned int inv_mask = ~((unsigned int)(tmp_header.RUNNO_MASK));
+  m_buffer[ POS_EXP_RUN_NUM ] =
+    ((unsigned int)m_buffer[ POS_EXP_RUN_NUM ] & inv_mask) |
+    (((unsigned int)run_num << tmp_header.RUNNO_SHIFT) & tmp_header.RUNNO_MASK);
+
+  return;
+}
+
+void SndHdrTemp::SetSubRunNum(int subrun_num)
+{
+
+  unsigned int inv_mask = ~((unsigned int)(tmp_header.SUBRUNNO_MASK));
+  m_buffer[ POS_EXP_RUN_NUM ] =
+    ((unsigned int)m_buffer[ POS_EXP_RUN_NUM ] & inv_mask) | ((unsigned int)subrun_num & tmp_header.SUBRUNNO_MASK);
+  return;
+}
+
+void SndHdrTemp::SetExpNum(int exp_num)
+{
+
+  unsigned int inv_mask = ~((unsigned int)(tmp_header.EXP_MASK));
+  m_buffer[ POS_EXP_RUN_NUM ] =
+    ((unsigned int)m_buffer[ POS_EXP_RUN_NUM ] & inv_mask) |
+    (((unsigned int)exp_num << tmp_header.EXP_SHIFT) & tmp_header.EXP_MASK);
+
+  return;
+}
+
+
+
+// Get Values
+
+int SndHdrTemp::GetTotalNwords() {  return m_buffer[ POS_NWORDS ];}
+int SndHdrTemp::GetHdrNwords() {    return SENDHDR_NWORDS; }
+int SndHdrTemp::GetNumEventsinPacket()
+{
+  return
+    ((m_buffer[ POS_NUM_EVE_NUM_NODES ] & 0xFFFF0000) >> 16) & 0x0000FFFF;
+
+}
+int SndHdrTemp::GetNumNodesinPacket() {  return m_buffer[ POS_NUM_EVE_NUM_NODES ] & 0x0000FFFF; }
+
+int SndHdrTemp::GetEventNumber() { return m_buffer[ POS_EVE_NUM ]; }
+
+int SndHdrTemp::GetNodeID() { return m_buffer[ POS_NODE_ID ]; }
+
+int SndHdrTemp::GetRunNum()
+{
+  return (((unsigned int)(m_buffer[ POS_EXP_RUN_NUM ]) & tmp_header.RUNNO_MASK) >> tmp_header.RUNNO_SHIFT);
+}
+
+int SndHdrTemp::GetSubRunNum()
+{
+  return ((unsigned int)(m_buffer[ POS_EXP_RUN_NUM ]) & tmp_header.SUBRUNNO_MASK);
+}
+
+int SndHdrTemp::GetRunNumSubRunNum()
+{
+
+  return ((unsigned int)(m_buffer[ POS_EXP_RUN_NUM ]) &
+          (tmp_header.RUNNO_MASK | tmp_header.SUBRUNNO_MASK));
+}
+
+
+int SndHdrTemp::GetExpNum()
+{
+
+  return (((unsigned int)(m_buffer[ POS_EXP_RUN_NUM ]) & tmp_header.EXP_MASK) >> tmp_header.EXP_SHIFT);
+}
+
+
diff --git a/ROPCApplications/daq/rawdata/include/CprErrorMessage.h b/ROPCApplications/daq/rawdata/include/CprErrorMessage.h
new file mode 100644
index 0000000000000000000000000000000000000000..03431ba9d0da547300a803e657670ae17832fa87
--- /dev/null
+++ b/ROPCApplications/daq/rawdata/include/CprErrorMessage.h
@@ -0,0 +1,49 @@
+//+
+// File : CprErrorMessage.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 29 - Dec - 2013
+//-
+
+#ifndef CPRERRORMESSAGE_H
+#define CPRERRORMESSAGE_H
+
+// Includes
+#include <stdio.h>
+#include <stdlib.h>
+#include <string>
+#include <daq/slc/readout/RunInfoBuffer.h>
+
+namespace Belle2 {
+
+  class CprErrorMessage {
+  public:
+    //! Default constructor
+    CprErrorMessage();
+
+    //! Default constructor
+    //    CprErrorMessage( const char* entry_name );
+
+
+    //! Destructor
+    virtual ~CprErrorMessage();
+
+    //!
+    void PrintError(char* err_message, const char* file, const char* func_name, const int line);
+
+    //!
+    void PrintError(const int shmflag, RunInfoBuffer* nsm_status, char* err_message, const char* file, const char* func_name,
+                    const int line);
+
+    //!
+    void PrintError(const int shmflag, RunInfoBuffer* nsm_status, std::string err_str);
+
+    //!
+    void PrintError(const char* err_message);
+
+
+  };
+}
+
+#endif
diff --git a/ROPCApplications/daq/rawdata/include/DesSer.h b/ROPCApplications/daq/rawdata/include/DesSer.h
new file mode 100644
index 0000000000000000000000000000000000000000..2d1b65d15042bb6dd6f1cd4199cad5397e85eda3
--- /dev/null
+++ b/ROPCApplications/daq/rawdata/include/DesSer.h
@@ -0,0 +1,324 @@
+//+
+// File : DesSer.h
+// Description : Module to receive data from outside and store it to DataStore
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 4 - Sep - 2014
+//-
+
+#ifndef DESSER_H
+#define DESSER_H
+
+#include <string>
+#include <vector>
+
+#include <sys/time.h>
+#include <errno.h>
+
+#include <daq/slc/readout/RunInfoBuffer.h>
+#include <daq/rawdata/CprErrorMessage.h>
+#include <daq/rawdata/modules/DAQConsts.h>
+#include <rawdata/dataobjects/PreRawCOPPERFormat_latest.h>
+
+#include <daq/dataobjects/SendHeader.h>
+#include <daq/dataobjects/SendTrailer.h>
+
+#define BUF_SIZE_WORD 4800
+
+////////////////////////////////////////////
+// From Serializer.cc
+////////////////////////////////////////////
+
+
+namespace Belle2 {
+
+  /*! A class definition of an input module for Sequential ROOT I/O */
+
+  class DesSer {
+
+    // Public functions
+  public:
+
+    //! Constructor / Destructor
+    DesSer();
+
+    //    DesSer();
+    virtual ~DesSer();
+
+    void initialize(bool close_listen = true);
+
+    //! Module functions to be called from event process
+    virtual void DataAcquisition() = 0;
+
+    //! dump error data
+    void printData(int* buf, int nwords);
+
+    //! # of events in a run
+    int max_nevt;
+
+    //! time to stop a run
+    double max_seconds;
+
+    //! Compression Level
+    int m_compressionLevel;
+
+    //! No. of sent events
+    int n_basf2evt;
+
+    //! No. of prev sent events
+    int m_prev_nevt;
+
+    //! dump filename
+    std::string m_dump_fname;
+
+    //! dump file descripter
+    FILE* m_fp_dump;
+
+    //! buffer
+    int* m_buffer;
+
+    //! buffer
+    int* m_bufary[ NUM_PREALLOC_BUF ];
+    //    int* m_bufary[NUM_EVT_PER_BASF2LOOP];
+
+    //! Getbuffer
+    int* getPreAllocBuf();
+
+    //! Getbuffer
+    int* getNewBuffer(int nwords, int* delete_flag);
+
+    // For monitoring
+    timeval m_t0;
+    double m_recvd_totbytes;
+    double m_recvd_prev_totbytes;
+    double m_sent_totbytes;
+    double m_sent_prev_totbytes;
+    int m_ncycle;
+    //! for time monitoring
+    double cur_time;
+
+    double m_start_time;
+    double m_prev_time;
+    int prev_event;
+
+    //! store time info.
+    double getTimeSec();
+
+    //! store time info.
+    void recordTime(int event, double* array);
+
+    //! calculate checksum
+    unsigned int calcSimpleChecksum(int* buf, int nwords);
+
+    //! calculate checksum
+    unsigned int calcXORChecksum(int* buf, int nwords);
+
+
+    void clearNumUsedBuf()
+    {
+      m_num_usedbuf = 0;
+      return ;
+    }
+
+    //! monitor rate
+    void RateMonitor(unsigned int nevt);
+
+
+    //! # of already used buffers
+    int m_num_usedbuf;
+
+    //! Node Name for SLC
+    std::string m_nodename;
+
+    //! Node ID for SLC
+    int m_nodeid;
+
+    //! Run info buffer
+    RunInfoBuffer m_status;
+
+    //! run no.
+    unsigned int m_exprunsubrun_no;
+
+    //! run no.
+    unsigned int m_prev_exprunsubrun_no;
+
+    //! exp no.
+    int m_exp_no;
+
+    //! data type
+    int m_data_type;
+
+    //! trunc mask
+    int m_trunc_mask;
+
+    //! Use shared memory
+    int m_shmflag;
+
+    //! open shared memory
+    void shmOpen(char* path_cfg, char* path_sta);
+
+    //! Get shared memory
+    int* shmGet(int fd, int size_words);
+
+    //! file descripter for shm
+    int m_shmfd_cfg;
+
+    //! file descripter for shm
+    int m_shmfd_sta;
+
+    //! buffer for shared memory
+    //int* m_cfg_buf;
+    //! buffer for shared memory
+    //int* m_cfg_sta;
+
+    int monitor_numeve;
+
+    //! start flag
+    int m_start_flag;
+
+    //! wrapper for B2LOG system
+    CprErrorMessage print_err;
+
+    //! report status to SLC
+    //    static RunInfoBuffer g_status;
+    //    RunInfoBuffer g_status;
+
+    PreRawCOPPERFormat_latest m_pre_rawcpr;
+
+    ///////////////////////////////
+    // From Serializer.cc
+    ///////////////////////////////
+
+    //! Module functions to be called from main process
+    void initializeNode();
+
+    //! Module functions to be called from event process
+    void beginRun();
+
+    void endRun();
+    void terminate();
+
+    //    int sendByWriteV(RawDataBlock* rawdblk);
+    int sendByWriteV(RawDataBlockFormat* rawdblk);
+    //    void Connect(const char* hostname, const int port);
+    void Accept(bool close_listen = true);
+
+    //    void fillSendHeaderTrailer(SendHeader* hdr, SendTrailer* trl, RawDataBlock* rawdblk);
+    void fillSendHeaderTrailer(SendHeader* hdr, SendTrailer* trl, RawDataBlockFormat* rawdblk);
+
+    // Data members
+
+    //! send buffer
+    int Send(int socket, char* buf, int size_bytes);
+
+
+    //! buffer for shared memory
+    int* m_cfg_buf;
+
+    //! buffer for shared memory
+    int* m_cfg_sta;
+
+    //! flag to show that run-controller pauses a run
+    int m_run_pause;
+
+    //! flag to show that there is some errors with which DAQ cannot continue.
+    int m_run_error;
+
+  protected :
+    //! check data contents
+    //   StoreArray<RawDataBlock> raw_datablkarray;
+
+    //! # of connections
+    int m_num_connections;
+
+    //! Reciever basf2 Socket
+    //    std::vector<EvtSocketRecv*> m_recv;
+
+    //! hostname of upstream Data Sources
+    std::vector<std::string> m_hostname_from;
+
+    //! port # to connect data sources
+    std::vector<int> m_port_from;
+
+    std::vector<int> m_socket_recv;
+
+    //    StoreArray<RawFTSW> raw_ftswarray;
+
+    //    StoreArray<RawCOPPER> rawcprarray;
+
+    //    StoreArray<ReducedRawCOPPER> rawcprarray;
+
+    int event_diff;
+
+    unsigned int m_prev_copper_ctr;
+
+    unsigned int m_prev_evenum;
+
+    ///////////////////////////////
+    // From Serializer.cc
+    ///////////////////////////////
+
+    //! Reciever Socket
+    int m_socket_send;
+
+    enum {
+      COPPER = 1,
+      ROPC = 2
+    };
+
+    //! Destination Host
+    std::string m_hostname_local;
+
+    //! Destination port
+    int m_port_to;
+
+    //! EvtSocket
+    //    EvtSocketSend* m_sock;
+
+    //! How to handle data
+    std::string p_method;
+    int p_method_val;
+
+#ifdef NONSTOP
+    //! for nonstop DAQ
+    int* m_ptr;
+
+    //! run no.
+    int m_run_no;
+
+    //! run no.
+    int m_prev_run_no;
+
+    //! for nonstop DAQ
+    int checkRunPause();
+
+    //! for nonstop DAQ
+    int checkRunRecovery();
+
+    //! for nonstop DAQ
+    void openRunPauseNshm();
+
+    //! for nonstop DAQ
+    void resumeRun();
+
+    //! for nonstop DAQ
+    void pauseRun();
+
+    //! for nonstop DAQ
+    void waitResume();
+
+    //! call checkrunstop
+    void callCheckRunPause(std::string& err_str);
+
+    //! Read data/check a connection
+    int CheckConnection(int socket);
+#endif
+
+    //! which format is used
+    RawHeader_latest tmp_header;
+
+  };
+
+} // end namespace Belle2
+
+#endif // DESSERCOPPER_H
diff --git a/ROPCApplications/daq/rawdata/include/DesSerCOPPER.h b/ROPCApplications/daq/rawdata/include/DesSerCOPPER.h
new file mode 100644
index 0000000000000000000000000000000000000000..e3d205bf5f6a336171a501dec70c970180c2ed27
--- /dev/null
+++ b/ROPCApplications/daq/rawdata/include/DesSerCOPPER.h
@@ -0,0 +1,73 @@
+//+
+// File : DesSerCOPPER.h
+// Description : Module to receive data from outside and store it to DataStore
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 4 - Sep - 2014
+//-
+
+#ifndef DESSERCOPPER_H
+#define DESSERCOPPER_H
+
+#include <daq/rawdata/DesSer.h>
+
+
+////////////////////////////////////////////
+// From Serializer.cc
+////////////////////////////////////////////
+
+
+namespace Belle2 {
+
+  /*! A class definition of an input module for Sequential ROOT I/O */
+
+  class DesSerCOPPER : public DesSer {
+
+    // Public functions
+  public:
+
+    //! Constructor / Destructor
+    DesSerCOPPER(std::string host_recv, int port_recv, std::string host_send, int port_send, int shmflag,
+                 const std::string& nodename, int nodeid, int finesse_bitflag);
+    //    DesSerCOPPER();
+    virtual ~DesSerCOPPER();
+
+    //! Module functions to be called from event process
+    void DataAcquisition();
+
+    //! Read one event from COPPER
+    int* readOneEventFromCOPPERFIFO(const int entry, int* delete_flag, int* m_size_word);
+
+    //! open COPPER
+    void openCOPPER();
+
+    //! Module functions to be called from main process
+    void initializeCOPPER();
+
+    //! receive data
+    int readFD(int fd, char* buf, int data_size_byte, int delete_flag);
+
+    //! file descripter for COPPER
+    int m_cpr_fd;
+
+    //! bit flag of FINESSE slots to use
+    int m_use_slot;
+
+    //! bit flag of FINESSE slots to use
+    int m_finesse_bit_flag;
+
+  protected :
+
+
+#ifdef NONSTOP
+    //! for nonstop DAQ
+    void waitResume();
+
+    //! for nonstop DAQ
+    void resumeRun();
+#endif
+  };
+
+} // end namespace Belle2
+
+#endif // DESSERCOPPER_H
diff --git a/ROPCApplications/daq/rawdata/include/DesSerPrePC.h b/ROPCApplications/daq/rawdata/include/DesSerPrePC.h
new file mode 100644
index 0000000000000000000000000000000000000000..bd3742701373da6b0be4040d1947824e73fbaee0
--- /dev/null
+++ b/ROPCApplications/daq/rawdata/include/DesSerPrePC.h
@@ -0,0 +1,62 @@
+//+
+// File : DeSerializerPrePC.h
+// Description : Module to receive data from outside and store it to DataStore
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 4 - Sep - 2014
+//-
+
+#ifndef DESSERPREPC_H
+#define DESSERPREPC_H
+#include <daq/rawdata/DesSer.h>
+
+////////////////////////////////////////////
+// From Serializer.cc
+////////////////////////////////////////////
+
+
+namespace Belle2 {
+
+  /*! A class definition of an input module for Sequential ROOT I/O */
+
+  class DesSerPrePC : public DesSer {
+
+    // Public functions
+  public:
+
+    //! Constructor / Destructor
+    DesSerPrePC(std::string host_recv, int port_recv, std::string host_send, int port_send, int shmflag,
+                const std::string& nodename, int nodeid);
+    //    DesSerPrePC();
+    virtual ~DesSerPrePC();
+
+    //! Module functions to be called from event process
+    void DataAcquisition();
+
+  protected :
+    //! Accept connection
+    int Connect();
+
+    //! receive data
+    int recvFD(int fd, char* buf, int data_size_byte, int flag);
+
+    //! receive data
+    int* recvData(int* delete_flag, int* total_m_size_word, int* num_events_in_sendblock, int* num_nodes_in_sendblock);
+
+    //! attach buffer to RawDataBlock
+    void setRecvdBuffer(RawDataBlockFormat* raw_datablk, int* delete_flag);
+
+    //! check data contents
+    void checkData(RawDataBlockFormat* raw_datablk, unsigned int* eve_copper_0);
+
+#ifdef NONSTOP
+
+    //! for nonstop DAQ
+    void waitResume();
+#endif
+
+  };
+
+} // end namespace Belle2
+
+#endif // MODULEHELLO_H
diff --git a/ROPCApplications/daq/rawdata/include/des_ser_prePC_main.h b/ROPCApplications/daq/rawdata/include/des_ser_prePC_main.h
new file mode 100644
index 0000000000000000000000000000000000000000..77fda6db80ad8bfe07c74e12570dad7f15fb5c86
--- /dev/null
+++ b/ROPCApplications/daq/rawdata/include/des_ser_prePC_main.h
@@ -0,0 +1,106 @@
+//+
+// File : des_ser_prePC_main.h
+// Description : Base class for Module to receive data from outside and store it to DataStore
+//
+// Author : Satoru Yamada Itoh, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef DES_SER_PREPC_MAIN_H
+#define DES_SER_PREPC_MAIN_H
+
+#include <string>
+#include <vector>
+#include <stdlib.h>
+/* #include <sys/time.h> */
+
+/* #include <framework/core/Module.h> */
+/* #include <framework/pcore/EvtMessage.h> */
+/* #include <framework/pcore/MsgHandler.h> */
+/* #include <framework/datastore/DataStore.h> */
+/* #include <framework/datastore/StoreObjPtr.h> */
+/* #include <framework/datastore/StoreArray.h> */
+/* #include <framework/dataobjects/EventMetaData.h> */
+
+/* #include <daq/dataflow/EvtSocket.h> */
+/* #include <daq/slc/readout/RunInfoBuffer.h> */
+/* #include <daq/rawdata/CprErrorMessage.h> */
+/* #include <daq/rawdata/modules/DAQConsts.h> */
+
+
+/* #include <rawdata/dataobjects/RawDataBlock.h> */
+//#include <rawdata/dataobjects/RawCOPPER.h>
+
+/* #include <sys/socket.h> */
+/* #include <sys/types.h> */
+/* #include <arpa/inet.h> */
+/* #include <netinet/in.h> */
+/* #include <netinet/tcp.h> */
+
+/* #include <sys/mman.h> */
+/* #include <sys/stat.h> */
+/* #include <fcntl.h> */
+
+/* using namespace std; */
+/* using namespace Belle2; */
+
+/* namespace Belle2 { */
+
+/*   /\*! A class definition of an input module for Sequential ROOT I/O *\/ */
+
+/*   class des_ser_prePC_main{ */
+
+/*     // Public functions */
+/*   public: */
+
+/*     //! Constructor / Destructor */
+/*     des_ser_prePC_mainModule(); */
+/*     virtual ~des_ser_prePC_mainModule(); */
+
+/*     //! Module functions to be called from main process */
+/*     virtual void initialize(); */
+
+/*     //! Module functions to be called from main process */
+/*     virtual void event(); */
+
+/*   protected : */
+/*     //! hostname */
+/*     string m_host_recv; */
+
+/*     //! hostname */
+/*     string m_host_send; */
+
+/*     //! port number */
+/*     int m_port_recv; */
+
+/*     //! port number */
+/*     int m_port_send; */
+
+/*     //! Messaage handler */
+/*     MsgHandler* m_msghandler; */
+
+/*     //! Compression Level */
+/*     int m_compressionLevel; */
+
+/*     //! Node(PC or COPPER) ID */
+/*     int m_nodeid; */
+
+/*     //! Node name */
+/*     std::string m_nodename; */
+
+/*     //! Use shared memory -> 1; Without shm -> 0 */
+/*     int m_shmflag; */
+
+/*     // Event Meta Data */
+/*     StoreObjPtr<EventMetaData> m_eventMetaDataPtr; */
+
+/*   private: */
+
+
+/*   public: */
+
+/*   }; */
+
+/* } // end namespace Belle2 */
+
+#endif // MODULEHELLO_H
diff --git a/ROPCApplications/daq/rawdata/modules/include/DAQConsts.h b/ROPCApplications/daq/rawdata/modules/include/DAQConsts.h
new file mode 100644
index 0000000000000000000000000000000000000000..4dc20119470d19b73ddc77fc65dc018dfbd4af23
--- /dev/null
+++ b/ROPCApplications/daq/rawdata/modules/include/DAQConsts.h
@@ -0,0 +1,138 @@
+//+
+// File : DAQConsts.h
+// Description : Header file for constants common to DAQ modules
+//
+// Author : Satoru Yamada Itoh, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef DAQCONSTS_H
+#define DAQCONSTS_H
+
+#define REDUCED_RAWCOPPER
+
+//#define NONSTOP
+//#define NONSTOP_DEBUG
+//#define NONSTOP_SLC
+
+//#define RAWDATASIZE 1
+/* #define WORD_SENDHEADER 1 */
+/* #define WORD_SENDTRAILER 1 */
+/* #define WORD_RAWCPRHEADER 16 */
+
+
+#define BASE_PORT_ROPC_COPPER 30000
+#define NUM_EVT_PER_BASF2LOOP_COPPER 50
+#define NUM_EVT_PER_BASF2LOOP_PC 1
+#define NUM_PREALLOC_BUF 500
+
+// global variables for non-stop DAQ
+
+
+
+#ifdef NONSTOP
+extern int g_run_pause;
+extern int g_run_error;
+extern int g_run_resuming;
+#endif
+
+const int sp8test_run_starttime[93] = {
+  -1, 1381029053
+  , 1381029116
+  , 1381029212
+  , 1381029294
+  , 1381029461
+  , 1381029515
+  , 1381029585
+  , 1381029634
+  , 1381029779
+  , 1381029884
+  , 1381029967
+  , 1381030359
+  , 1381031134
+  , 1381031221
+  , 1381031325
+  , 1381031418
+  , 1381031554
+  , 1381031621
+  , 1381031836
+  , 1381034808
+  , 1381034941
+  , 1381035044
+  , 1381035354
+  , 1381036072
+  , 1381037030
+  , 1381037146
+  , 1381037345
+  , 1381037638
+  , 1381038699
+  , 1381039391
+  , 1381039816
+  , 1381040036
+  , 1381041389
+  , 1381041442
+  , 1381041497
+  , 1381041762
+  , 1381042464
+  , 1381043331
+  , 1381046109
+  , 1381046342
+  , 1381046390
+  , 1381046571
+  , 1381046589
+  , 1381049032
+  , 1381049196
+  , 1381049867
+  , 1381049925
+  , 1381050883
+  , 1381054508
+  , 1381054875
+  , 1381055316
+  , 1381055550
+  , 1381055772
+  , 1381056812
+  , 1381057213
+  , 1381057307
+  , 1381058937
+  , 1381059752
+  , 1381060015
+  , 1381060050
+  , 1381060524
+  , 1381061531
+  , 1381061572
+  , 1381061648
+  , 1381061749
+  , 1381062569
+  , 1381062687
+  , 1381063320
+  , 1381063720
+  , 1381064134
+  , 1381067028
+  , 1381067698
+  , 1381069387
+  , 1381070333
+  , 1381071744
+  , 1381071838
+  , 1381072694
+  , 1381073760
+  , 1381073790
+  , 1381074369
+  , 1381074621
+  , 1381074946
+  , 1381075404
+  , 1381075516
+  , 1381077354
+  , 1381077382
+  , 1381078479
+  , 1381078693
+  , 1381079579
+  , 1381079710
+  , 1381079865
+  , 1381079906
+};
+
+//#define WITH_HEADER_TRAILER
+
+//#define DUMMY
+
+#endif
diff --git a/ROPCApplications/daq/rawdata/modules/include/copper.h b/ROPCApplications/daq/rawdata/modules/include/copper.h
new file mode 100644
index 0000000000000000000000000000000000000000..97d5dc8e3e2166667b3e6ed57a633f6e7c22f9d6
--- /dev/null
+++ b/ROPCApplications/daq/rawdata/modules/include/copper.h
@@ -0,0 +1,221 @@
+#ifndef _COPPER_H_
+#define _COPPER_H_
+
+#define COPPER_DRIVER_HEADER_MAGIC  0x7FFF0008
+#define COPPER_DRIVER_FOOTER_MAGIC  0x7FFF0009
+
+struct copper_header {
+  int magic;
+  int event_number;
+  int subsys;
+  int crate;
+  int slot;
+  unsigned int ttrx[2];
+};
+
+struct copper_footer {
+  int chksum_xor;
+  int magic;
+};
+
+#ifndef _LINUX_IOCTL_H
+#include <linux/ioctl.h>
+#endif
+
+int peek_next_event_size(void);
+int shift_next_event_size(void);
+
+/* register positions */
+#define COPPER_FF_STA   0x00000000  // COPPER Event FIFO Status
+#define COPPER_CONF_WA_AE 0x00000010  // COPPER Event FIFO Ach Almost Empty
+#define COPPER_CONF_WB_AE 0x00000014  // COPPER Event FIFO Bch Almost Empty
+#define COPPER_CONF_WC_AE 0x00000018  // COPPER Event FIFO Cch Almost Empty
+#define COPPER_CONF_WD_AE 0x0000001C  // COPPER Event FIFO Dch Almost Empty
+#define COPPER_CONF_WA_FF 0x00000020  // COPPER Event FIFO Ach Defined Quantity
+#define COPPER_CONF_WB_FF 0x00000024  // COPPER Event FIFO Bch Defined Quantity
+#define COPPER_CONF_WC_FF 0x00000028  // COPPER Event FIFO Cch Defined Quantity
+#define COPPER_CONF_WD_FF 0x0000002C  // COPPER Event FIFO Dch Defined Quantity
+#define COPPER_CONF_WA_AF 0x00000030  // COPPER Event FIFO Ach Almost Full
+#define COPPER_CONF_WB_AF 0x00000034  // COPPER Event FIFO Bch Almost Full
+#define COPPER_CONF_WC_AF 0x00000038  // COPPER Event FIFO Cch Almost Full
+#define COPPER_CONF_WD_AF 0x0000003C  // COPPER Event FIFO Dch Almost Full
+#define COPPER_FF_RST   0x00000050  // COPPER Event FIFO & FINESSE Soft Reset
+#define COPPER_FINESSE_STA  0x00000054  // FINESSE Status
+#define COPPER_ALMFULL_ENB  0x00000058  // COPPER Almost Full Flag Enable
+#define COPPER_VERSION    0x0000005C  // COPPER firmware version
+#define COPPER_TRGCM    0x00000060  // COPPER Trigger Command
+#define COPPER_TRG_LENG   0x00000064  // COPPER Trigger Interval
+#define COPPER_LEF_READSEL  0x00000068  // Length FIFO Read Select
+#define COPPER_LEF_TOTAL  0x0000006C  // Length FIFO Total Data
+#define COPPER_LEF_AB   0x00000080  // COPPER Length FIFO A&Bch Data
+#define COPPER_LEF_CD   0x00000084  // COPPER Length FIFO C&Dch Data
+#define COPPER_LEF_STA    0x00000088  // COPPER Length FIFO Status
+#define COPPER_LEF_WA_FF  0x00000090  // COPPER Length FIFO Ach Defined Quantity
+#define COPPER_LEF_WB_FF  0x00000094  // COPPER Length FIFO Bch Defined Quantity
+#define COPPER_LEF_WC_FF  0x00000098  // COPPER Length FIFO Cch Defined Quantity
+#define COPPER_LEF_WD_FF  0x0000009C  // COPPER Length FIFO Dch Defined Quantity
+#define COPPER_LEF_WA_AF  0x000000A0  // COPPER Length FIFO Ach Almost Full
+#define COPPER_LEF_WB_AF  0x000000A4  // COPPER Length FIFO Bch Almost Full
+#define COPPER_LEF_WC_AF  0x000000A8  // COPPER Length FIFO Cch Almost Full
+#define COPPER_LEF_WD_AF  0x000000AC  // COPPER Length FIFO Dch Almost Full
+#define COPPER_INT_STA    0x000000B0  // COPPER Interrupt Status
+#define COPPER_INT_MASK   0x000000B4  // COPPER Interrupt Mask
+#define COPPER_FF_RW    0x000000B8  // COPPER Event FIFO Single Read/Write Control
+#define COPPER_INT_FACTOR 0x000000BC  // COPPER Interruption Factor Reg.
+#define COPPER_FF_WA    0x00000100  // COPPER Event FIFO Ach Single Write
+#define COPPER_FF_WB    0x00000104  // COPPER Event FIFO Bch Single Write
+#define COPPER_FF_WC    0x00000108  // COPPER Event FIFO Cch Single Write
+#define COPPER_FF_WD    0x0000010C  // COPPER Event FIFO Dch Single Write
+#define COPPER_FF_RA    0x00000110  // COPPER Event FIFO Ach Single Read
+#define COPPER_FF_RB    0x00000114  // COPPER Event FIFO Bch Single Read
+#define COPPER_FF_RC    0x00000118  // COPPER Event FIFO Cch Single Read
+#define COPPER_FF_RD    0x0000011C  // COPPER Event FIFO Dch Single Read
+#define COPPER_FF_DMA   0x00400000  // Event FIFO DMA Read Reg.
+
+// 2005/01/17 Append
+#define COPPER_EWRP_A   0x00000140  // COPPER Event FIFO Ach Read/Write Pointer
+#define COPPER_EWRP_B   0x00000144  // COPPER Event FIFO Bch Read/Write Pointer
+#define COPPER_EWRP_C   0x00000148  // COPPER Event FIFO Cch Read/Write Pointer
+#define COPPER_EWRP_D   0x0000014C  // COPPER Event FIFO Dch Read/Write Pointer
+
+#define COPPER_WEA_COUNTER  0x00000150  // FINESSE Ach WE Counter
+#define COPPER_WEB_COUNTER  0x00000154  // FINESSE Bch WE Counter
+#define COPPER_WEC_COUNTER  0x00000158  // FINESSE Cch WE Counter
+#define COPPER_WED_COUNTER  0x0000015C  // FINESSE Dch WE Counter
+
+#define COPPER_LWRA_DMA   0x00000160  // COPPER Length FIFO Ach Read/Write Pointer for DMA
+#define COPPER_LWRB_DMA   0x00000164  // COPPER Length FIFO Bch Read/Write Pointer for DMA
+#define COPPER_LWRC_DMA   0x00000168  // COPPER Length FIFO Cch Read/Write Pointer for DMA
+#define COPPER_LWRD_DMA   0x0000016C  // COPPER Length FIFO Dch Read/Write Pointer for DMA
+
+#define COPPER_DMA_TRANS  0x00000170  // COPPER DMA Counter
+#define COPPER_DMA_TS_ENB 0x00000174  // COPPER DMA Counter Control
+
+#define COPPER_RW_DEBUG   0x000000FC  // Memory for Debug
+
+/* alias */
+
+#define COPPER_LEF_WA_THR COPPER_LEF_WA_FF
+#define COPPER_LEF_WB_THR COPPER_LEF_WB_FF
+#define COPPER_LEF_WC_THR COPPER_LEF_WC_FF
+#define COPPER_LEF_WD_THR COPPER_LEF_WD_FF
+
+/* ioctl cmds */
+
+#define COPPER_MAGIC    0xdf
+
+#define CPRIOGET_FF_STA   _IOR(COPPER_MAGIC, COPPER_FF_STA, sizeof(unsigned int))
+#define CPRIOGET_CONF_WA_AE _IOR(COPPER_MAGIC, COPPER_CONF_WA_AE, sizeof(unsigned int))
+#define CPRIOGET_CONF_WB_AE _IOR(COPPER_MAGIC, COPPER_CONF_WB_AE, sizeof(unsigned int))
+#define CPRIOGET_CONF_WC_AE _IOR(COPPER_MAGIC, COPPER_CONF_WC_AE, sizeof(unsigned int))
+#define CPRIOGET_CONF_WD_AE _IOR(COPPER_MAGIC, COPPER_CONF_WD_AE, sizeof(unsigned int))
+#define CPRIOGET_CONF_WA_FF _IOR(COPPER_MAGIC, COPPER_CONF_WA_FF, sizeof(unsigned int))
+#define CPRIOGET_CONF_WB_FF _IOR(COPPER_MAGIC, COPPER_CONF_WB_FF, sizeof(unsigned int))
+#define CPRIOGET_CONF_WC_FF _IOR(COPPER_MAGIC, COPPER_CONF_WC_FF, sizeof(unsigned int))
+#define CPRIOGET_CONF_WD_FF _IOR(COPPER_MAGIC, COPPER_CONF_WD_FF, sizeof(unsigned int))
+#define CPRIOGET_CONF_WA_AF _IOR(COPPER_MAGIC, COPPER_CONF_WA_AF, sizeof(unsigned int))
+#define CPRIOGET_CONF_WB_AF _IOR(COPPER_MAGIC, COPPER_CONF_WB_AF, sizeof(unsigned int))
+#define CPRIOGET_CONF_WC_AF _IOR(COPPER_MAGIC, COPPER_CONF_WC_AF, sizeof(unsigned int))
+#define CPRIOGET_CONF_WD_AF _IOR(COPPER_MAGIC, COPPER_CONF_WD_AF, sizeof(unsigned int))
+#define CPRIOGET_FF_RST   _IOR(COPPER_MAGIC, COPPER_FF_RST, sizeof(unsigned int))
+#define CPRIOGET_FINESSE_STA  _IOR(COPPER_MAGIC, COPPER_FINESSE_STA, sizeof(unsigned int))
+#define CPRIOGET_ALMFULL_ENB  _IOR(COPPER_MAGIC, COPPER_ALMFULL_ENB, sizeof(unsigned int))
+#define CPRIOGET_VERSION  _IOR(COPPER_MAGIC, COPPER_VERSION, sizeof(unsigned int))
+#define CPRIOGET_TRGCM    _IOR(COPPER_MAGIC, COPPER_TRGCM, sizeof(unsigned int))
+#define CPRIOGET_TRG_LENG _IOR(COPPER_MAGIC, COPPER_TRG_LENG, sizeof(unsigned int))
+#define CPRIOGET_LEF_READSEL  _IOR(COPPER_MAGIC, COPPER_LEF_READSEL, sizeof(unsigned int))
+#define CPRIOGET_LEF_TOTAL  _IOR(COPPER_MAGIC, COPPER_LEF_TOTAL, sizeof(unsigned int))
+#define CPRIOGET_LEF_AB   _IOR(COPPER_MAGIC, COPPER_LEF_AB, sizeof(unsigned int))
+#define CPRIOGET_LEF_CD   _IOR(COPPER_MAGIC, COPPER_LEF_CD, sizeof(unsigned int))
+#define CPRIOGET_LEF_STA  _IOR(COPPER_MAGIC, COPPER_LEF_STA, sizeof(unsigned int))
+#define CPRIOGET_LEF_WA_FF  _IOR(COPPER_MAGIC, COPPER_LEF_WA_FF, sizeof(unsigned int))
+#define CPRIOGET_LEF_WB_FF  _IOR(COPPER_MAGIC, COPPER_LEF_WB_FF, sizeof(unsigned int))
+#define CPRIOGET_LEF_WC_FF  _IOR(COPPER_MAGIC, COPPER_LEF_WC_FF, sizeof(unsigned int))
+#define CPRIOGET_LEF_WD_FF  _IOR(COPPER_MAGIC, COPPER_LEF_WD_FF, sizeof(unsigned int))
+#define CPRIOGET_LEF_WA_AF  _IOR(COPPER_MAGIC, COPPER_LEF_WA_AF, sizeof(unsigned int))
+#define CPRIOGET_LEF_WB_AF  _IOR(COPPER_MAGIC, COPPER_LEF_WB_AF, sizeof(unsigned int))
+#define CPRIOGET_LEF_WC_AF  _IOR(COPPER_MAGIC, COPPER_LEF_WC_AF, sizeof(unsigned int))
+#define CPRIOGET_LEF_WD_AF  _IOR(COPPER_MAGIC, COPPER_LEF_WD_AF, sizeof(unsigned int))
+#define CPRIOGET_INT_STA  _IOR(COPPER_MAGIC, COPPER_INT_STA, sizeof(unsigned int))
+#define CPRIOGET_INT_MASK _IOR(COPPER_MAGIC, COPPER_INT_MASK, sizeof(unsigned int))
+#define CPRIOGET_FF_RW    _IOR(COPPER_MAGIC, COPPER_FF_RW, sizeof(unsigned int))
+#define CPRIOGET_INT_FACTOR _IOR(COPPER_MAGIC, COPPER_INT_FACTOR, sizeof(unsigned int))
+#define CPRIOGET_FF_WA    _IOR(COPPER_MAGIC, COPPER_FF_WA, sizeof(unsigned int))
+#define CPRIOGET_FF_WB    _IOR(COPPER_MAGIC, COPPER_FF_WB, sizeof(unsigned int))
+#define CPRIOGET_FF_WC    _IOR(COPPER_MAGIC, COPPER_FF_WC, sizeof(unsigned int))
+#define CPRIOGET_FF_WD    _IOR(COPPER_MAGIC, COPPER_FF_WD, sizeof(unsigned int))
+#define CPRIOGET_FF_RA    _IOR(COPPER_MAGIC, COPPER_FF_RA, sizeof(unsigned int))
+#define CPRIOGET_FF_RB    _IOR(COPPER_MAGIC, COPPER_FF_RB, sizeof(unsigned int))
+#define CPRIOGET_FF_RC    _IOR(COPPER_MAGIC, COPPER_FF_RC, sizeof(unsigned int))
+#define CPRIOGET_FF_RD    _IOR(COPPER_MAGIC, COPPER_FF_RD, sizeof(unsigned int))
+#define CPRIOGET_FF_DMA   _IOR(COPPER_MAGIC, COPPER_FF_DMA, sizeof(unsigned int))
+
+#define CPRIOSET_FF_STA   _IOW(COPPER_MAGIC, COPPER_FF_STA, sizeof(unsigned int))
+#define CPRIOSET_CONF_WA_AE _IOW(COPPER_MAGIC, COPPER_CONF_WA_AE, sizeof(unsigned int))
+#define CPRIOSET_CONF_WB_AE _IOW(COPPER_MAGIC, COPPER_CONF_WB_AE, sizeof(unsigned int))
+#define CPRIOSET_CONF_WC_AE _IOW(COPPER_MAGIC, COPPER_CONF_WC_AE, sizeof(unsigned int))
+#define CPRIOSET_CONF_WD_AE _IOW(COPPER_MAGIC, COPPER_CONF_WD_AE, sizeof(unsigned int))
+#define CPRIOSET_CONF_WA_FF _IOW(COPPER_MAGIC, COPPER_CONF_WA_FF, sizeof(unsigned int))
+#define CPRIOSET_CONF_WB_FF _IOW(COPPER_MAGIC, COPPER_CONF_WB_FF, sizeof(unsigned int))
+#define CPRIOSET_CONF_WC_FF _IOW(COPPER_MAGIC, COPPER_CONF_WC_FF, sizeof(unsigned int))
+#define CPRIOSET_CONF_WD_FF _IOW(COPPER_MAGIC, COPPER_CONF_WD_FF, sizeof(unsigned int))
+#define CPRIOSET_CONF_WA_AF _IOW(COPPER_MAGIC, COPPER_CONF_WA_AF, sizeof(unsigned int))
+#define CPRIOSET_CONF_WB_AF _IOW(COPPER_MAGIC, COPPER_CONF_WB_AF, sizeof(unsigned int))
+#define CPRIOSET_CONF_WC_AF _IOW(COPPER_MAGIC, COPPER_CONF_WC_AF, sizeof(unsigned int))
+#define CPRIOSET_CONF_WD_AF _IOW(COPPER_MAGIC, COPPER_CONF_WD_AF, sizeof(unsigned int))
+#define CPRIOSET_FF_RST   _IOW(COPPER_MAGIC, COPPER_FF_RST, sizeof(unsigned int))
+#define CPRIOSET_FINESSE_STA  _IOW(COPPER_MAGIC, COPPER_FINESSE_STA, sizeof(unsigned int))
+#define CPRIOSET_ALMFULL_ENB  _IOW(COPPER_MAGIC, COPPER_ALMFULL_ENB, sizeof(unsigned int))
+#define CPRIOSET_TRGCM    _IOW(COPPER_MAGIC, COPPER_TRGCM, sizeof(unsigned int))
+#define CPRIOSET_TRG_LENG _IOW(COPPER_MAGIC, COPPER_TRG_LENG, sizeof(unsigned int))
+#define CPRIOSET_LEF_READSEL  _IOW(COPPER_MAGIC, COPPER_LEF_READSEL, sizeof(unsigned int))
+#define CPRIOSET_LEF_TOTAL  _IOW(COPPER_MAGIC, COPPER_LEF_TOTAL, sizeof(unsigned int))
+#define CPRIOSET_LEF_AB   _IOW(COPPER_MAGIC, COPPER_LEF_AB, sizeof(unsigned int))
+#define CPRIOSET_LEF_CD   _IOW(COPPER_MAGIC, COPPER_LEF_CD, sizeof(unsigned int))
+#define CPRIOSET_LEF_STA  _IOW(COPPER_MAGIC, COPPER_LEF_STA, sizeof(unsigned int))
+#define CPRIOSET_LEF_WA_FF  _IOW(COPPER_MAGIC, COPPER_LEF_WA_FF, sizeof(unsigned int))
+#define CPRIOSET_LEF_WB_FF  _IOW(COPPER_MAGIC, COPPER_LEF_WB_FF, sizeof(unsigned int))
+#define CPRIOSET_LEF_WC_FF  _IOW(COPPER_MAGIC, COPPER_LEF_WC_FF, sizeof(unsigned int))
+#define CPRIOSET_LEF_WD_FF  _IOW(COPPER_MAGIC, COPPER_LEF_WD_FF, sizeof(unsigned int))
+#define CPRIOSET_LEF_WA_AF  _IOW(COPPER_MAGIC, COPPER_LEF_WA_AF, sizeof(unsigned int))
+#define CPRIOSET_LEF_WB_AF  _IOW(COPPER_MAGIC, COPPER_LEF_WB_AF, sizeof(unsigned int))
+#define CPRIOSET_LEF_WC_AF  _IOW(COPPER_MAGIC, COPPER_LEF_WC_AF, sizeof(unsigned int))
+#define CPRIOSET_LEF_WD_AF  _IOW(COPPER_MAGIC, COPPER_LEF_WD_AF, sizeof(unsigned int))
+#define CPRIOSET_INT_STA  _IOW(COPPER_MAGIC, COPPER_INT_STA, sizeof(unsigned int))
+#define CPRIOSET_INT_MASK _IOW(COPPER_MAGIC, COPPER_INT_MASK, sizeof(unsigned int))
+#define CPRIOSET_FF_RW    _IOW(COPPER_MAGIC, COPPER_FF_RW, sizeof(unsigned int))
+#define CPRIOSET_INT_FACTOR _IOW(COPPER_MAGIC, COPPER_INT_FACTOR, sizeof(unsigned int))
+#define CPRIOSET_FF_WA    _IOW(COPPER_MAGIC, COPPER_FF_WA, sizeof(unsigned int))
+#define CPRIOSET_FF_WB    _IOW(COPPER_MAGIC, COPPER_FF_WB, sizeof(unsigned int))
+#define CPRIOSET_FF_WC    _IOW(COPPER_MAGIC, COPPER_FF_WC, sizeof(unsigned int))
+#define CPRIOSET_FF_WD    _IOW(COPPER_MAGIC, COPPER_FF_WD, sizeof(unsigned int))
+#define CPRIOSET_FF_RA    _IOW(COPPER_MAGIC, COPPER_FF_RA, sizeof(unsigned int))
+#define CPRIOSET_FF_RB    _IOW(COPPER_MAGIC, COPPER_FF_RB, sizeof(unsigned int))
+#define CPRIOSET_FF_RC    _IOW(COPPER_MAGIC, COPPER_FF_RC, sizeof(unsigned int))
+#define CPRIOSET_FF_RD    _IOW(COPPER_MAGIC, COPPER_FF_RD, sizeof(unsigned int))
+#define CPRIOSET_FF_DMA   _IOW(COPPER_MAGIC, COPPER_FF_DMA, sizeof(unsigned int))
+
+/* alias */
+
+#define CPRIOSET_LEF_WA_THR CPRIOSET_LEF_WA_FF
+#define CPRIOSET_LEF_WB_THR CPRIOSET_LEF_WB_FF
+#define CPRIOSET_LEF_WC_THR CPRIOSET_LEF_WC_FF
+#define CPRIOSET_LEF_WD_THR CPRIOSET_LEF_WD_FF
+
+#define CPRIOGET_LEF_WA_THR CPRIOGET_LEF_WA_FF
+#define CPRIOGET_LEF_WB_THR CPRIOGET_LEF_WB_FF
+#define CPRIOGET_LEF_WC_THR CPRIOGET_LEF_WC_FF
+#define CPRIOGET_LEF_WD_THR CPRIOGET_LEF_WD_FF
+
+/* cmds */
+
+#define CPRIO_RESET_FINESSE _IO(COPPER_MAGIC, 1)
+#define CPRIO_INIT_RUN    _IO(COPPER_MAGIC, 2)
+#define CPRIO_RESET_COPPER  _IO(COPPER_MAGIC, 3)
+#define CPRIO_SET_SUBSYS  _IO(COPPER_MAGIC, 4)
+#define CPRIO_SET_CRATE   _IO(COPPER_MAGIC, 5)
+#define CPRIO_SET_SLOT    _IO(COPPER_MAGIC, 6)
+#define CPRIO_FORCE_DMA     _IO(COPPER_MAGIC, 7)
+#define CPRIO_END_RUN     _IO(COPPER_MAGIC, 8)
+
+#endif  /* _COPPER_H_ */
diff --git a/ROPCApplications/daq/rawdata/src/CprErrorMessage.cc b/ROPCApplications/daq/rawdata/src/CprErrorMessage.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7d983dbac9e29416136aefde2da35439c5ff48d1
--- /dev/null
+++ b/ROPCApplications/daq/rawdata/src/CprErrorMessage.cc
@@ -0,0 +1,99 @@
+//+
+// File : ErrorLog.h
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+//#include <framework/logging/Logger.h>
+#include <daq/rawdata/CprErrorMessage.h>
+// #include <time.h>
+#include <syslog.h>
+// #include <framework/core/Module.h>
+
+using namespace std;
+using namespace Belle2;
+
+//REG_MODULE(CprErrorMessage)
+// CprErrorMessage::CprErrorMessage( const char* entry_name )
+// {
+//   //  openlog( entry_name, LOG_PERROR, LOG_LOCAL0 );
+// }
+
+CprErrorMessage::CprErrorMessage()
+{
+  openlog("", LOG_PERROR , LOG_LOCAL0);
+}
+
+CprErrorMessage::~CprErrorMessage()
+{
+  closelog();
+}
+
+
+void CprErrorMessage::PrintError(const int shmflag, RunInfoBuffer* nsm_status, string err_str)
+{
+  if (shmflag > 0) {
+    nsm_status->reportError(RunInfoBuffer::CPRFIFO_FULL);//need to implement error flag
+  }
+  PrintError(err_str.c_str());
+}
+
+void CprErrorMessage::PrintError(const int shmflag, RunInfoBuffer* nsm_status, char* err_message,
+                                 const char* file, const char* func_name, const int line)
+{
+  string err_str = err_message;
+  if (shmflag > 0) {
+    nsm_status->reportError(RunInfoBuffer::CPRFIFO_FULL);//need to implement error flag
+  }
+  PrintError(err_message, file, func_name, line);
+}
+
+
+void CprErrorMessage::PrintError(char* err_message, const char* file, const char* func_name, const int line)
+{
+  char err_buf[500];
+  sprintf(err_buf, "%s : %s %s %d", err_message, file, func_name, line);
+  //  fprintf( stderr, "[FATAL] %s", err_message);
+  printf("%s", err_buf);  fflush(stdout);
+  //  B2FATAL(err_buf);
+  //  printf("AL] %s\n", err_buf);
+  exit(1);
+
+//   time_t     current;
+//   time(&current);
+//   printf("\033[31m");
+//   perror("[ERROR] 0: ");
+//   printf("[ERROR] 1: %s", ctime(&current));
+//   printf("[ERROR] 2: %s\n", err_message);
+//   printf("[ERROR] 3: [file] %s [Line] %d\n", file, line);
+//   printf("[ERROR] 4: [function] %s\n", func_name);
+//   printf("\033[0m");
+//   fflush(stdout);
+//   errmsg(LOG_LOCAL0|LOG_ERR,
+//   "CRITICAL : %s : init_shm() failed to get shmhead ( %p )\n",
+//   __PRETTY_FUNCTION__, shmhead );
+
+  return;
+}
+
+
+
+void CprErrorMessage::PrintError(const char* err_message)
+{
+  printf("[DEBUG] %s", err_message);
+  fflush(stdout);
+  //  B2FATAL(err_message);
+  printf("[FATAL] %s\n", err_message); exit(1);
+
+//   printf("\033[31m");
+//   printf("\033[47m");
+//   //  B2FATAL(err_message);
+//   perror("[ERROR] 0: ");
+//   printf("[ERROR] 1: %s", ctime(&current));
+//   printf("[ERROR] 2: %s\n", err_message);
+//   printf("\033[0m");
+//   printf("\033[40m");
+//   fflush(stdout);
+  return;
+}
diff --git a/ROPCApplications/daq/rawdata/src/DesSer.cc b/ROPCApplications/daq/rawdata/src/DesSer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a0612b1e054ff2b9e05ace1f0183217e54fa24f6
--- /dev/null
+++ b/ROPCApplications/daq/rawdata/src/DesSer.cc
@@ -0,0 +1,717 @@
+//+
+// File : DeSerializerPC.cc
+// Description : Module to receive data from eb0 and send it to eb1tx
+//
+// Author : Satoru Yamada Itoh, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+#include <daq/rawdata/DesSer.h>
+
+#include <netdb.h>
+#include <netinet/tcp.h>
+
+#include <sys/mman.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+
+#include <csignal>
+
+
+
+//#define DEBUG
+using namespace std;
+using namespace Belle2;
+
+//----------------------------------------------------------------
+//                 Implementation
+//----------------------------------------------------------------
+
+DesSer::DesSer()
+{
+
+  m_num_connections = 1;
+
+  m_exprunsubrun_no = 0; // will obtain info from data
+
+  m_prev_exprunsubrun_no = 0xFFFFFFFF;
+
+#ifdef NONSTOP
+  m_run_pause = 0;
+
+  m_run_error = 0;
+#endif
+
+  //  B2INFO("DeSerializerPrePC: Constructor done.");
+  printf("[DEBUG] DesSer: Constructor done.\n"); fflush(stdout);
+}
+
+
+
+DesSer::~DesSer()
+{
+
+}
+
+
+int* DesSer::getPreAllocBuf()
+{
+  int* tempbuf = 0;
+  if (m_num_usedbuf < NUM_PREALLOC_BUF) {
+    tempbuf = m_bufary[ m_num_usedbuf  ];
+    m_num_usedbuf++;
+  } else {
+    char err_buf[500];
+    sprintf(err_buf,
+            "No pre-allocated buffers are left. %d > %d. Not enough buffers are allocated or "
+            "memory leak or forget to call ClearNumUsedBuf every event loop. Exting...",
+            m_num_usedbuf, NUM_PREALLOC_BUF);
+    print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    sleep(1234567);
+    exit(1);
+  }
+  return tempbuf;
+}
+
+
+int* DesSer::getNewBuffer(int nwords, int* delete_flag)
+{
+
+  int* temp_buf = NULL;
+  // Prepare buffer
+  if (nwords >  BUF_SIZE_WORD) {
+    *delete_flag = 1;
+    temp_buf = new int[ nwords ];
+  } else {
+    if ((temp_buf = getPreAllocBuf()) == 0x0) {
+      char err_buf[500];
+      sprintf(err_buf, "Null pointer from GetPreALlocBuf(). Exting...\n");
+      print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      sleep(1234567);
+      exit(1);
+    } else {
+      *delete_flag = 0;
+    }
+  }
+
+  return temp_buf;
+
+}
+
+void DesSer::initialize(bool close_listen)
+{
+  printf("[DEBUG] DesSer: initialize() started.\n"); fflush(stdout);
+  signal(SIGPIPE , SIG_IGN);
+
+  //
+  // initialize Rx part from DeSerializer**.cc
+  //
+
+  // allocate buffer
+  for (int i = 0 ; i < NUM_PREALLOC_BUF; i++) {
+    m_bufary[i] = new int[ BUF_SIZE_WORD ];
+  }
+  m_buffer = new int[ BUF_SIZE_WORD ];
+
+  // initialize buffer
+  for (int i = 0 ; i < NUM_PREALLOC_BUF; i++) {
+    memset(m_bufary[i], 0,  BUF_SIZE_WORD * sizeof(int));
+  }
+
+  // Open message handler
+  clearNumUsedBuf();
+  // Shared memory
+  if (m_shmflag > 0) {
+    if (m_nodename.size() == 0 || m_nodeid < 0) {
+      m_shmflag = 0;
+    } else {
+      m_status.open(m_nodename, m_nodeid);
+      m_status.reportReady();
+    }
+  }
+
+  event_diff = 0;
+
+  m_prev_copper_ctr = 0xFFFFFFFF;
+  m_prev_evenum = 0xFFFFFFFF;
+
+
+  //
+  // initialize Rx part from DeSerializer**.cc
+  //
+  m_start_flag = 0;
+  n_basf2evt = -1;
+  m_compressionLevel = 0;
+
+#ifdef DUMMY
+  m_buffer = new int[ BUF_SIZE_WORD ];
+#endif
+  Accept(close_listen);
+#ifdef NONSTOP
+  openRunPauseNshm();
+#endif
+
+
+  // For monitor
+  if (m_status.isAvailable()) {
+    m_status.setOutputNBytes(0);
+    m_status.setOutputCount(0);
+  }
+  //  B2INFO("DesSer: initialize() was done.");
+  printf("[DEBUG] DesSer: initialize() was done.\n"); fflush(stdout);
+
+}
+
+
+/////////////////////////////////////////////////////
+//   From Serializer.cc
+/////////////////////////////////////////////////////
+
+//void DesSer::fillSendHeaderTrailer(SendHeader* hdr, SendTrailer* trl, RawDataBlock* rawdblk)
+void DesSer::fillSendHeaderTrailer(SendHeader* hdr, SendTrailer* trl, RawDataBlockFormat* rawdblk)
+{
+
+  int total_send_nwords =
+    hdr->GetHdrNwords() +
+    rawdblk->TotalBufNwords() +
+    //    rawhdr.GetNwords() +
+    trl->GetTrlNwords();
+
+  hdr->SetNwords(total_send_nwords);
+  hdr->SetNumEventsinPacket(rawdblk->GetNumEvents());
+  hdr->SetNumNodesinPacket(rawdblk->GetNumNodes());
+
+  //
+  // For bug check
+  //
+  if (rawdblk->GetNumEntries() == 1) {
+    if (total_send_nwords != (rawdblk->GetBuffer(0))[ 0 ] + 8) {
+      char err_buf[500];
+      sprintf(err_buf, "Length error. total length %d rawdblk length %d. Exting...\n" ,
+              total_send_nwords, (rawdblk->GetBuffer(0))[ 0 ]);
+      printData(rawdblk->GetBuffer(0), rawdblk->TotalBufNwords());
+      print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      sleep(1234567);
+      exit(-1);
+    }
+  }
+
+
+  for (int i = 0; i < rawdblk->GetNumEntries(); i++) {
+
+    //copy event # from a tonp COPPER block
+    if (!(rawdblk->CheckFTSWID(i)) && !(rawdblk->CheckTLUID(i))) {
+      tmp_header.SetBuffer(rawdblk->GetBuffer(i));
+      hdr->SetEventNumber(tmp_header.GetEveNo());
+      hdr->SetNodeID(tmp_header.GetNodeID());
+      hdr->SetExpRunWord(tmp_header.GetExpRunSubrun());
+      break;
+    }
+
+    //Error if you cannot find any COPPER block
+    if (i == (rawdblk->GetNumEntries() - 1)) {
+      printf("[DEBUG] i= %d : num entries %d : Tot words %d\n", i , rawdblk->GetNumEntries(), rawdblk->TotalBufNwords());
+      printData(rawdblk->GetBuffer(0), rawdblk->TotalBufNwords());
+
+      char err_buf[500] = "[FATAL] CORRUPTED DATA: No COPPER blocks in RawDataBlock. Exiting...";
+      print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      sleep(1234567);
+      exit(-1);
+    }
+  }
+  return;
+}
+
+
+//int DesSer::sendByWriteV(RawDataBlock* rawdblk)
+int DesSer::sendByWriteV(RawDataBlockFormat* rawdblk)
+{
+  SendHeader send_header;
+  SendTrailer send_trailer;
+  fillSendHeaderTrailer(&send_header, &send_trailer, rawdblk);
+
+  enum {
+    NUM_BUFFER = 3
+  };
+  struct iovec iov[ NUM_BUFFER ];
+
+  // check Body data size
+  int rawcopper_nwords = rawdblk->TotalBufNwords();
+
+  //Fill iov info.
+  iov[0].iov_base = (char*)send_header.GetBuffer();
+  iov[0].iov_len = sizeof(int) * send_header.GetHdrNwords();
+
+  iov[1].iov_base = (char*)rawdblk->GetWholeBuffer();
+  iov[1].iov_len = sizeof(int) * rawcopper_nwords;
+
+  iov[2].iov_base = (char*)send_trailer.GetBuffer();
+  iov[2].iov_len = sizeof(int) * send_trailer.GetTrlNwords();
+
+  // Send Multiple buffers
+  int n = 0;
+  while (true) {
+    if ((n = writev(m_socket_send, iov, NUM_BUFFER)) < 0) {
+      if (errno == EINTR) {
+        continue;
+      } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
+#ifdef NONSTOP
+        string err_str;
+        callCheckRunPause(err_str);
+#endif
+        continue;
+      } else {
+        char err_buf[500];
+        sprintf(err_buf, "[WARNING] WRITEV error.(%s) : sent %d bytes, header %d bytes body %d trailer %d\n" ,
+                strerror(errno), n, iov[0].iov_len, iov[1].iov_len, iov[2].iov_len);
+#ifdef NONSTOP
+        m_run_error = 1;
+        //        B2ERROR(err_buf);
+        printf("%s\n", err_buf); fflush(stdout);
+        string err_str = "RUN_ERROR";
+        throw (err_str);  // To exit this module, go to DeSerializer** and wait for run-resume.
+#else
+        print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        exit(1);
+#endif
+      }
+    }
+    break;
+  }
+
+#ifdef DEBUG
+  printf("[DEBUG] *******BODY**********\n");
+  printf("[DEBUG] \n%.8d : ", 0);
+  printData((int*)(iov[1].iov_base), iov[1].iov_len);
+#endif
+
+
+  int total_send_bytes = sizeof(int) * send_header.GetTotalNwords();
+
+
+  //
+  // Retry sending
+  //
+  if (n != total_send_bytes) {
+    //    B2WARNING("Serializer: Sent byte(" << n << "bytes) is not same as the event size (" << total_send_bytes << "bytes). Retrying...");
+    printf("[WARNING] Serializer: Sent byte( %d bytes) is not same as the event size ( %d bytes). Retrying...\n", n,
+           total_send_bytes); // back to WARNING due to request from Konno-san on 2018/7/3
+    fflush(stdout);
+
+    double retry_start = getTimeSec();
+    // Send Header
+    if (n < (int)(iov[ 0 ].iov_len)) {
+      n += Send(m_socket_send, (char*)iov[ 0 ].iov_base + n, iov[ 0 ].iov_len - n);
+    }
+
+    if (n < (int)(iov[ 0 ].iov_len + iov[ 1 ].iov_len)) {
+      n += Send(m_socket_send, (char*)iov[ 1 ].iov_base + (n - iov[ 0 ].iov_len), iov[ 1 ].iov_len - (n - iov[ 0 ].iov_len));
+    }
+
+    if (n < (int)(iov[ 0 ].iov_len + iov[ 1 ].iov_len + iov[ 2 ].iov_len)) {
+      n += Send(m_socket_send, (char*)iov[ 2 ].iov_base + (n - iov[ 0 ].iov_len - iov[ 1 ].iov_len),
+                iov[ 2 ].iov_len - (n - iov[ 0 ].iov_len - iov[ 1 ].iov_len));
+    }
+    double retry_end = getTimeSec();
+    //    B2WARNING("Resending ends. It takes " << retry_end - retry_start << "(s)");
+    printf("[WARNING] Resending ends. It takes %lf (s)\n", retry_end - retry_start);
+    fflush(stdout); // back to WARNING due to request from Konno-san on 2018/7/3
+  }
+  //   printf( "[DEBUG] n %d total %d\n", n, total_send_bytes);
+  //  delete temp_buf;
+
+  return total_send_bytes;
+
+}
+
+
+int DesSer::Send(int socket, char* buf, int size_bytes)
+{
+  int sent_bytes = 0;
+  while (true) {
+    int ret = 0;
+    if ((ret = send(socket,
+                    buf + sent_bytes, size_bytes - sent_bytes,  MSG_NOSIGNAL)) < 0) {
+      if (errno == EINTR) {
+        continue;
+      } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
+#ifdef NONSTOP
+        string err_str;
+        callCheckRunPause(err_str);
+#endif
+        continue;
+      } else {
+        char err_buf[500];
+        sprintf(err_buf, "[WARNING] SEND ERROR.(%s)", strerror(errno));
+#ifdef NONSTOP
+        m_run_error = 1;
+        //        B2ERROR(err_buf);
+        printf("%s\n", err_buf); fflush(stdout);
+        string err_str = "RUN_ERROR";
+        throw (err_str);  // To exit this module, go to DeSerializer** and wait for run-resume.
+#else
+        print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        exit(1);
+#endif
+      }
+    }
+    sent_bytes += ret;
+    if (sent_bytes == size_bytes) break;
+  }
+  return sent_bytes;
+}
+
+void DesSer::Accept(bool close_listen)
+{
+  //
+  // Connect to cprtb01
+  //
+  struct hostent* host;
+  host = gethostbyname(m_hostname_local.c_str());
+  if (host == NULL) {
+    char temp_buf[500];
+    sprintf(temp_buf, "[FATAL] hostname(%s) cannot be resolved(%s). Check /etc/hosts. Exiting...\n",
+            m_hostname_local.c_str(), strerror(errno));
+    print_err.PrintError(temp_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    exit(1);
+  }
+
+  //
+  // Bind and listen
+  //
+  int fd_listen;
+  struct sockaddr_in sock_listen;
+  sock_listen.sin_family = AF_INET;
+  sock_listen.sin_addr.s_addr = *(unsigned int*)host->h_addr_list[0];
+
+  socklen_t addrlen = sizeof(sock_listen);
+  sock_listen.sin_port = htons(m_port_to);
+  fd_listen = socket(PF_INET, SOCK_STREAM, 0);
+
+  int flags = 1;
+  int ret = setsockopt(fd_listen, SOL_SOCKET, SO_REUSEADDR, &flags, (socklen_t)sizeof(flags));
+  if (ret < 0) {
+    perror("Failed to set REUSEADDR");
+  }
+
+  if (bind(fd_listen, (struct sockaddr*)&sock_listen, sizeof(struct sockaddr)) < 0) {
+    printf("[FATAL] Failed to bind. Maybe other programs have already occupied this port(%d). Exiting...\n",
+           m_port_to); fflush(stdout);
+    // Check the process occupying the port 30000.
+    FILE* fp;
+    char buf[256];
+    char cmdline[500];
+    sprintf(cmdline, "/usr/sbin/ss -ap | grep %d", m_port_to);
+    if ((fp = popen(cmdline, "r")) == NULL) {
+      printf("[WARNING] Failed to run %s\n", cmdline);
+    }
+    while (fgets(buf, 256, fp) != NULL) {
+      printf("[ERROR] Failed to bind. output of ss(port %d) : %s\n", m_port_to, buf); fflush(stdout);
+    }
+    // Error message
+    fclose(fp);
+    char temp_char[500];
+    sprintf(temp_char, "[FATAL] Failed to bind.(%s) Maybe other programs have already occupied this port(%d). Exiting...",
+            strerror(errno), m_port_to);
+    print_err.PrintError(temp_char, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    exit(1);
+  }
+
+  int val1 = 0;
+  setsockopt(fd_listen, IPPROTO_TCP, TCP_NODELAY, &val1, (socklen_t)sizeof(val1));
+  int backlog = 1;
+  if (listen(fd_listen, backlog) < 0) {
+    char err_buf[500];
+    sprintf(err_buf, "Failed in listen(%s). Exting...", strerror(errno));
+    print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    exit(-1);
+  }
+
+  //
+  // Accept
+  //
+  int fd_accept;
+  struct sockaddr_in sock_accept;
+  printf("[DEBUG] Accepting... : port %d server %s\n", m_port_to, m_hostname_local.c_str());
+  fflush(stdout);
+
+  if ((fd_accept = accept(fd_listen, (struct sockaddr*) & (sock_accept), &addrlen)) == 0) {
+    char err_buf[500];
+    sprintf(err_buf, "[FATAL] Failed to accept(%s). Exiting...", strerror(errno));
+    print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    exit(-1);
+  } else {
+    //    B2INFO("Done.");
+    printf("[DEBUG] Done.\n"); fflush(stdout);
+
+    //    set timepout option
+    struct timeval timeout;
+    timeout.tv_sec = 1;
+    timeout.tv_usec = 0;
+    ret = setsockopt(fd_accept, SOL_SOCKET, SO_SNDTIMEO, &timeout, (socklen_t)sizeof(timeout));
+    if (ret < 0) {
+      char temp_char[100] = "[FATAL] Failed to set TIMEOUT. Exiting...";
+      print_err.PrintError(temp_char, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      exit(-1);
+    }
+  }
+
+  if (close_listen) {
+    close(fd_listen);
+  }
+
+  //   int flag = 1;
+  //   ret = setsockopt(fd_accept, IPPROTO_TCP, TCP_NODELAY, (char*)&flag, sizeof(flag) );
+  m_socket_send = fd_accept;
+
+  if (m_status.isAvailable()) {
+    m_status.setOutputPort(ntohs(sock_listen.sin_port));
+    m_status.setOutputAddress(sock_listen.sin_addr.s_addr);
+    //    B2INFO("Accepted " << (int)ntohs(sock_listen.sin_port) << " " << (int)sock_listen.sin_addr.s_addr);
+    printf("Accepted. port %d address %u\n", (int)ntohs(sock_listen.sin_port), (int)sock_listen.sin_addr.s_addr); fflush(stdout);
+  }
+
+  return;
+
+}
+
+double DesSer::getTimeSec()
+{
+  struct timeval t;
+  gettimeofday(&t, NULL);
+  return (t.tv_sec + t.tv_usec * 1.e-6);
+}
+
+
+void DesSer::recordTime(int event, double* array)
+{
+  if (event >= 50000 && event < 50500) {
+    array[ event - 50000 ] = getTimeSec() - m_start_time;
+  }
+  return;
+}
+
+
+unsigned int DesSer::calcXORChecksum(int* buf, int nwords)
+{
+  unsigned int checksum = 0;
+  for (int i = 0; i < nwords; i++) {
+    checksum = checksum ^ buf[ i ];
+  }
+  return checksum;
+}
+
+
+void DesSer::printData(int* buf, int nwords)
+{
+  printf("[DEBUG]");
+  for (int i = 0; i < nwords; i++) {
+    printf("%.8x ", buf[ i ]);
+    if (i % 10 == 9) printf("\n[DEBUG]");
+  }
+  printf("\n[DEBUG]");
+  printf("\n");
+  return;
+}
+
+
+#ifdef NONSTOP
+void DesSer::openRunPauseNshm()
+{
+  char path_shm[100] = "/cpr_pause_resume";
+  int fd = shm_open(path_shm, O_RDONLY, 0666);
+  if (fd < 0) {
+    printf("[DEBUG] %s\n", path_shm);
+    perror("[ERROR] shm_open2");
+    exit(1);
+  }
+  m_ptr = (int*)mmap(NULL, sizeof(int), PROT_READ, MAP_SHARED, fd, 0);
+  return;
+}
+
+int DesSer::checkRunPause()
+{
+#ifdef NONSTOP_SLC
+  if (m_status.getState() == m_status.PAUSING) {
+#else
+  if (*m_ptr) {
+#endif
+    return 1;
+  } else {
+    return 0;
+  }
+}
+
+int DesSer::checkRunRecovery()
+{
+#ifdef NONSTOP_SLC
+  if (m_status.getState() == m_status.RESUMING) {
+#else
+  if (*m_ptr) {
+#endif
+    return 0;
+  } else {
+    return 1;
+  }
+}
+
+void DesSer::resumeRun()
+{
+#ifdef NONSTOP_DEBUG
+  printf("\033[34m");
+  printf("###########(Ser) the 1st event sicne the resume  ###############\n");
+  fflush(stdout);
+  printf("\033[0m");
+#endif
+  m_run_error = 0;
+  m_run_pause = 0;
+  return;
+}
+
+
+void DesSer::pauseRun()
+{
+  m_run_pause = 1;
+#ifdef NONSTOP_DEBUG
+  printf("###########(Ser) Pause the run ###############\n");
+  fflush(stdout);
+#endif
+  return;
+}
+
+
+
+
+void DesSer::callCheckRunPause(string& err_str)
+{
+#ifdef NONSTOP_DEBUG
+  printf("\033[34m");
+  printf("###########(DesSer) TIMEOUT.  ###############\n");
+  fflush(stdout);
+  printf("\033[0m");
+#endif
+  if (checkRunPause()) {
+#ifdef NONSTOP_DEBUG
+    printf("\033[31m");
+    printf("###########(DesSer) Pause is detected. ###############\n");
+    fflush(stdout);
+    printf("\033[0m");
+#endif
+    m_run_pause = 1;
+    throw (err_str);
+  }
+  return;
+}
+
+
+int DesSer::CheckConnection(int socket)
+{
+  // Modify Yamagata-san's eb/iseof.cc
+
+
+  int ret;
+  char buffer[100000];
+  int eagain_cnt = 0;
+  int tot_ret = 0;
+  printf("CC1\n"); fflush(stdout);
+  ret = send(socket, buffer, 0, MSG_DONTWAIT);
+  printf("CC2\n"); fflush(stdout);
+  switch (ret) {
+    case 0:
+      break;
+    case -1:
+      if (errno == EAGAIN) {
+        printf("EAGAIN %d cnt %d recvd %d\n", socket, eagain_cnt, tot_ret); fflush(stdout);
+        /* not EOF, no data in queue */
+        if (eagain_cnt > 100) {
+          return 0;
+        }
+        usleep(10000);
+        eagain_cnt++;
+      } else {
+        printf("ERROR %d errno %d err %s\n", socket , errno, strerror(errno)); fflush(stdout);
+        close(socket);
+        return -1;
+      }
+    default:
+      printf("Return value %d of send is strange. Exting...\n",  ret);
+      fflush(stdout);
+      exit(1);
+  }
+
+  while (true) {
+
+    //
+    // Extract data in the socket buffer of a peer
+    //
+    //    ret = recv( socket, buffer, sizeof(buffer), MSG_PEEK|MSG_DONTWAIT );
+    ret = recv(socket, buffer, sizeof(buffer), MSG_DONTWAIT);
+    switch (ret) {
+      case 0: /* EOF */
+        printf("EOF %d\n", socket); fflush(stdout);
+        close(socket);
+        return -1;
+      case -1:
+        if (errno == EAGAIN) {
+          printf("EAGAIN %d cnt %d recvd %d\n", socket, eagain_cnt, tot_ret); fflush(stdout);
+          /* not EOF, no data in queue */
+          if (eagain_cnt > 100) {
+            return 0;
+          }
+          usleep(10000);
+          eagain_cnt++;
+        } else {
+          printf("ERROR %d errno %d err %s\n", socket , errno, strerror(errno)); fflush(stdout);
+          close(socket);
+          return -1;
+        }
+        break;
+      default:
+        tot_ret += ret;
+        printf("Flushing data in socket buffer : sockid = %d %d bytes tot %d bytes\n", socket, ret, tot_ret); fflush(stdout);
+    }
+  }
+}
+
+
+#endif
+
+void DesSer::shmOpen(char*, char*)
+//(char* path_cfg, char* path_sta)
+{
+  errno = 0;
+  /*m_shmfd_cfg = shm_open( "/cpr_config2", O_CREAT | O_EXCL | O_RDWR, 0666);
+  if (m_shmfd_cfg < 0) {
+    if (errno != EEXIST) {
+      perror("shm_open1");
+      exit(1);
+    }
+  m_shmfd_cfg = shm_open(path_cfg, O_RDWR, 0666);
+  if (m_shmfd_cfg < 0) {
+    printf( "[DEBUG] %s\n", path_cfg);
+    perror("[ERROR] shm_open2");
+    exit(1);
+  }
+  */
+  //}
+  /*
+  m_shmfd_sta = shm_open( "/cpr_status2", O_CREAT | O_EXCL | O_RDWR, 0666);
+  if (m_shmfd_sta < 0) {
+    if (errno != EEXIST) {
+      perror("shm_open1");
+      exit(1);
+    }
+  m_shmfd_sta = shm_open(path_sta , O_RDWR, 0666);
+  if (m_shmfd_sta < 0) {
+    printf( "[DEBUG] %s\n", path_sta);
+    perror("[ERROR] shm_open2");
+    exit(1);
+  }
+  //}
+  int size = 4 * sizeof(int);
+  ftruncate(m_shmfd_cfg, size);
+  ftruncate(m_shmfd_sta, size);
+    */
+}
+
+
+
diff --git a/ROPCApplications/daq/rawdata/src/DesSerCOPPER.cc b/ROPCApplications/daq/rawdata/src/DesSerCOPPER.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4681734150a558ca15927b3c74b6ac32fcd1b4e1
--- /dev/null
+++ b/ROPCApplications/daq/rawdata/src/DesSerCOPPER.cc
@@ -0,0 +1,598 @@
+//+
+// File : DesSerCOPPER.cc
+// Description : Module to receive data from eb0 and send it to eb1tx
+//
+// Author : Satoru Yamada Itoh, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <daq/rawdata/modules/copper.h>
+#include <daq/rawdata/DesSerCOPPER.h>
+
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+using namespace std;
+using namespace Belle2;
+
+
+
+//----------------------------------------------------------------
+//                 Implementation
+//----------------------------------------------------------------
+
+DesSerCOPPER::DesSerCOPPER(string host_recv, int port_recv, string host_send, int port_send, int shmflag,
+                           const std::string& nodename, int nodeid, int finesse_bitflag)
+{
+  m_finesse_bit_flag = finesse_bitflag;
+
+  for (int i = 0 ; i < m_num_connections; i++) {
+    //  m_hostname_from.push_back( "localhost");
+    m_hostname_from.push_back(host_recv);
+    //  m_port_from.push_back(30000);
+    m_port_from.push_back(port_recv) ;
+    m_socket_recv.push_back(-1);
+  }
+
+  //  m_port_to = 31001;
+  m_port_to = port_send;
+  //  m_hostname_local = "localhost";
+  m_hostname_local = host_send;
+  m_nodename = nodename;
+
+  m_shmflag = shmflag;
+
+  m_nodeid = nodeid;
+
+  //  B2INFO("DeSerializerPrePC: Constructor done.");
+  printf("[DEBUG] DeSerializerPrePC: Constructor done.\n"); fflush(stdout);
+}
+
+
+
+DesSerCOPPER::~DesSerCOPPER()
+{
+}
+
+void DesSerCOPPER::DataAcquisition()
+{
+  // For data check
+  unsigned int eve_copper_0 = 0;
+  //  B2INFO("initializing...");
+  printf("[DEBUG] initializing...\n"); fflush(stdout);
+  initialize(false);
+
+
+  //  B2INFO("Done.");
+  printf("[DEBUG] Done.\n"); fflush(stdout);
+
+  unsigned int m_prev_ftsweve32 = 0xffffffff;
+
+  if (m_start_flag == 0) {
+    //
+    // Connect to eb0: This should be here because we want Serializer first to accept connection from eb1tx
+    //
+    initializeCOPPER();
+    //    Connect();
+
+    if (m_status.isAvailable()) {
+      //      B2INFO("DeSerializerPrePC: Waiting for Start...\n");
+      printf("[DEBUG] DeSerializerPrePC: Waiting for Start...\n"); fflush(stdout);
+      m_status.reportRunning();
+    }
+    m_start_time = getTimeSec();
+    n_basf2evt = 0;
+  }
+
+  //
+  // Main loop
+  //
+  while (1) {
+    //
+    // Stand-by loop
+    //
+#ifdef NONSTOP
+    if (m_run_pause > 0 || m_run_error > 0) {
+      waitResume();
+    }
+#endif
+
+    clearNumUsedBuf();
+    //    RawDataBlock raw_datablk[ NUM_EVT_PER_BASF2LOOP_PC ];
+    RawDataBlockFormat raw_datablk[ NUM_EVT_PER_BASF2LOOP_PC ];
+
+
+    //
+    // Recv loop
+    //
+    for (int j = 0; j < NUM_EVT_PER_BASF2LOOP_PC; j++) {
+      //
+      // Receive data from COPPER
+      //
+      eve_copper_0 = 0;
+      int delete_flag_from =
+        0; // Delete flag for temp_rawdatablk.It can be set to 1 by setRecvdBuffer if the buffer size is larger than that of pre-allocated buffer.
+      int delete_flag_to =
+        0; // Delete flag for raw_datablk[i]. It can be set to 1 by getNewBuffer if the buffer size is larger than that of pre-allocated buffer.
+      RawDataBlockFormat temp_rawdatablk;
+      try {
+
+        int delete_flag = 0, m_size_word = 0;
+
+        if (m_start_flag == 0) {
+          printf("[DEBUG] DeSerializerCOPPER: Reading the 1st event from COPPER FIFO... run %.8x eve %.8x\n", m_prev_exprunsubrun_no,
+                 m_prev_ftsweve32); fflush(stdout);
+        }
+        int* temp_buf;
+
+        temp_buf = readOneEventFromCOPPERFIFO(j, &delete_flag, &m_size_word);
+        m_status.copyEventHeader(temp_buf);
+        if (m_start_flag == 0) {
+          printf("[DEBUG] DeSerializerCOPPER: Done. the size of the 1st event is %d words\n", m_size_word); fflush(stdout);
+        }
+        const int num_nodes = 1;
+        const int num_events = 1;
+        PreRawCOPPERFormat_latest temp_rawcopper;
+        temp_rawcopper.SetBuffer(temp_buf, m_size_word, 0, num_events, num_nodes);
+        // Fill header and trailer
+        try {
+          m_prev_ftsweve32 = temp_rawcopper.FillTopBlockRawHeader(m_nodeid, m_prev_ftsweve32, m_prev_exprunsubrun_no, &m_exprunsubrun_no);
+          m_prev_exprunsubrun_no = m_exprunsubrun_no;
+          //    fillNewRawCOPPERHeader( &temp_rawcopper );
+        } catch (string err_str) {
+          print_err.PrintError(m_shmflag, &m_status, err_str);
+          exit(1);
+        }
+
+//  if (m_dump_fname.size() > 0) {
+//    dumpData((char*)temp_buf, m_size_word * sizeof(int));
+//  }
+        m_recvd_totbytes += m_size_word * sizeof(int);
+
+        //  temp_rawdblk =  raw_dblkarray.appendNew();
+        //  temp_rawdatablk->SetBuffer(temp_buf, m_size_word, delete_flag, num_events, num_nodes);
+        raw_datablk[ j ].SetBuffer(temp_buf, m_size_word, delete_flag, num_events, num_nodes);
+
+      } catch (string err_str) {
+        printf("Error was detected\n"); fflush(stdout);
+        break;
+      }
+    }
+
+#ifdef NONSTOP
+    // Goto Stand-by loop when run is paused or stopped by error
+    if (m_run_pause != 0 || m_run_error != 0) continue;
+#endif
+
+
+    ///////////////////////////////////////////////////////////////
+    // From Serializer.cc
+    //////////////////////////////////////////////////////////////
+    if (m_start_flag == 0) {
+      m_start_time = getTimeSec();
+      n_basf2evt = 0;
+    }
+
+    //
+    // Send data
+    //
+    for (int j = 0; j < NUM_EVT_PER_BASF2LOOP_PC; j++) {
+      if (m_start_flag == 0) {
+        //        B2INFO("SerializerPC: Sending the 1st packet...");
+        printf("[DEBUG] SerializerPC: Sending the 1st packet...\n"); fflush(stdout);
+      }
+      try {
+        m_sent_totbytes += sendByWriteV(&(raw_datablk[ j ]));
+      } catch (string err_str) {
+#ifdef NONSTOP
+        break;
+#endif
+        print_err.PrintError((char*)err_str.c_str(), __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        exit(1);
+      }
+      if (m_start_flag == 0) {
+        //        B2INFO("Done. ");
+        printf("[DEBUG] Done.\n"); fflush(stdout);
+        m_start_flag = 1;
+      }
+    }
+
+#ifdef NONSTOP
+    // Goto Stand-by loop when run is paused or stopped by error
+    if (m_run_pause != 0 || m_run_error != 0) continue;
+#endif
+
+    //
+    // Monitor
+    //
+    if (max_nevt >= 0 || max_seconds >= 0.) {
+#ifdef AIUEO
+      if (n_basf2evt % 10000 == 0) {
+//     if ((n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC >= max_nevt && max_nevt > 0)
+//         || (getTimeSec() - m_start_time > max_seconds && max_seconds > 0.)) {
+        printf("[DEBUG] RunStop was detected. ( Setting:  Max event # %d MaxTime %lf ) Processed Event %d Elapsed Time %lf[s]\n",
+               max_nevt , max_seconds, n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC, getTimeSec() - m_start_time);
+      }
+#endif
+    }
+
+    if ((n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC) % 100000 == 0) {
+      double interval = cur_time - m_prev_time;
+      double total_time = cur_time - m_start_time;
+      printf("[DEBUG] Event %12d Rate %6.2lf[kHz] Recvd %6.2lf[MB/s] sent %6.2lf[MB/s] RunTime %8.2lf[s] interval %8.4lf[s]\n",
+             n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC,
+             (n_basf2evt  - m_prev_nevt)*NUM_EVT_PER_BASF2LOOP_PC / interval / 1.e3,
+             (m_recvd_totbytes - m_recvd_prev_totbytes) / interval / 1.e6,
+             (m_sent_totbytes - m_sent_prev_totbytes) / interval / 1.e6,
+             total_time,
+             interval);
+      fflush(stdout);
+
+      m_prev_time = cur_time;
+      m_recvd_prev_totbytes = m_recvd_totbytes;
+      m_sent_prev_totbytes = m_sent_totbytes;
+      m_prev_nevt = n_basf2evt;
+      cur_time = getTimeSec();
+    }
+
+    n_basf2evt++;
+
+    if (m_status.isAvailable()) {
+      m_status.setOutputNBytes(m_sent_totbytes);
+      m_status.setOutputCount(n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC);
+    }
+
+  }
+
+  return;
+}
+
+/////////////////////////////////////////////////////
+//   From Serializer.cc
+/////////////////////////////////////////////////////
+
+#ifdef NONSTOP
+void DesSerCOPPER::waitResume()
+{
+  if (m_run_pause == 0) {
+    while (true) {
+      if (checkRunPause()) break;
+#ifdef NONSTOP_DEBUG
+      printf("\033[31m");
+      printf("###########(DesSerCOPPER) Waiting for Runstop()  ###############\n");
+      fflush(stdout);
+      printf("\033[0m");
+#endif
+      sleep(1);
+    }
+  }
+
+  // close COPPER FIFO
+  if (m_cpr_fd != -1) close(m_cpr_fd);
+  m_cpr_fd = -1;
+
+  while (true) {
+#ifdef NONSTOP_DEBUG
+    printf("\033[31m");
+    printf("###########(Ser) Waiting for Resume ###############\n");
+    fflush(stdout);
+    printf("\033[0m");
+#endif
+    if (checkRunRecovery()) {
+      m_run_pause = 0;
+      m_run_error = 0;
+
+      break;
+    }
+    sleep(1);
+  }
+
+  printf("Done!\n"); fflush(stdout);
+
+  if (CheckConnection(m_socket_send) < 0) {
+    printf("Trying Accept1\n"); fflush(stdout);
+    Accept(false);
+    printf("Trying Accept2\n"); fflush(stdout);
+  }
+
+  resumeRun();
+  return;
+}
+
+
+
+void DesSerCOPPER::resumeRun()
+{
+  initializeCOPPER();
+#ifdef NONSTOP_DEBUG
+  printf("\033[34m");
+  printf("###########(Ser) the 1st event sicne the resume  ###############\n");
+  fflush(stdout);
+  printf("\033[0m");
+#endif
+  m_run_error = 0;
+  m_run_pause = 0;
+  return;
+}
+
+
+
+#endif
+
+
+
+int* DesSerCOPPER::readOneEventFromCOPPERFIFO(const int entry, int* delete_flag, int* m_size_word)
+{
+
+  // prepare buffer
+  *m_size_word = 0;
+  int* temp_buf = m_bufary[ entry ];
+  temp_buf[0] =  BUF_SIZE_WORD ;
+  *delete_flag = 0;
+
+  //
+  // Read data from HSLB
+  //
+#ifndef DUMMY
+  int recvd_byte = (m_pre_rawcpr.tmp_header.RAWHEADER_NWORDS) * sizeof(int);
+  // Firstly, read data with an allocated buffer.
+  while (1) {
+    int read_size = 0;
+    if ((read_size = read(m_cpr_fd, (char*)m_bufary[entry] + recvd_byte, sizeof(int) *  BUF_SIZE_WORD  - recvd_byte)) < 0) {
+      if (errno == EINTR) {
+        continue;
+      } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
+
+        if (recvd_byte > (int)((m_pre_rawcpr.tmp_header.RAWHEADER_NWORDS) * sizeof(int))) {
+          char err_buf[500];
+          sprintf(err_buf, "[FATAL] EAGAIN return in the middle of an event( COPPER driver should't do this.). Exting...");
+          print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+          exit(-1);
+        }
+
+#ifdef NONSTOP
+        // Check run-pause request from SLC
+        string err_str;
+        callCheckRunPause(err_str);
+#endif
+        continue;
+
+      } else {
+        char err_buf[500];
+        sprintf(err_buf, "[FATAL] Failed to read data from COPPER. Exiting...");
+        print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        exit(-1);
+      }
+    } else {
+      recvd_byte += read_size;
+      if (recvd_byte - (m_pre_rawcpr.tmp_header.RAWHEADER_NWORDS) * sizeof(int) > (int)(sizeof(int) *
+          (m_pre_rawcpr.POS_DATA_LENGTH + 1)))break;
+    }
+  }
+
+  //
+  // Calcurate data size
+  //
+  *m_size_word = m_bufary[ entry ][ m_pre_rawcpr.POS_DATA_LENGTH + (m_pre_rawcpr.tmp_header.RAWHEADER_NWORDS) ]
+                 + m_pre_rawcpr.SIZE_COPPER_DRIVER_HEADER + m_pre_rawcpr.SIZE_COPPER_DRIVER_TRAILER
+                 + m_pre_rawcpr.tmp_header.RAWHEADER_NWORDS +
+                 m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS; // 9 words are COPPER haeder and trailer size.
+
+  //
+  // If there are data remaining to be read, continue reading
+  //
+  if ((int)((*m_size_word - m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS) * sizeof(int)) > recvd_byte) {
+
+    // If event size is larger than BUF_SIZE_WORD, allocate a new buffer
+    if (*m_size_word >  BUF_SIZE_WORD) {
+      *delete_flag = 1;
+      temp_buf = new int[ *m_size_word ];
+      memcpy(temp_buf, m_bufary[ entry ], recvd_byte);
+      recvd_byte += readFD(m_cpr_fd, (char*)temp_buf + recvd_byte,
+                           (*m_size_word - m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS) * sizeof(int) - recvd_byte, *delete_flag);
+    } else {
+
+      recvd_byte += readFD(m_cpr_fd, (char*)(m_bufary[ entry ]) + recvd_byte,
+                           (*m_size_word - m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS) * sizeof(int) - recvd_byte, *delete_flag);
+    }
+
+    if ((int)((*m_size_word - m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS) * sizeof(int)) != recvd_byte) {
+      char    err_buf[500];
+
+      sprintf(err_buf, "[FATAL] CORRUPTED DATA: Read less bytes(%d) than expected(%d:%d). Exiting...\n",
+              recvd_byte,
+              *m_size_word * sizeof(int) - m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS * sizeof(int),
+              m_bufary[ entry ][ m_pre_rawcpr.POS_DATA_LENGTH ]);
+      print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      exit(-1);
+    }
+  } else if ((int)((*m_size_word - m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS) * sizeof(int)) < recvd_byte) {
+    char    err_buf[500];
+    sprintf(err_buf, "[FATAL] CORRUPTED DATA: Read more than data size. Exiting...: %d %d %d %d %d\n",
+            recvd_byte, *m_size_word * sizeof(int) , m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS * sizeof(int),
+            m_bufary[ entry ][ m_pre_rawcpr.POS_DATA_LENGTH ],  m_pre_rawcpr.POS_DATA_LENGTH);
+    print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    exit(-1);
+  }
+#else
+  //
+  // Make dummy data
+  //
+  *m_size_word = 256 + entry;
+  m_bufary[entry][0] = *m_size_word;
+#endif
+
+  //
+  // Fill Data length
+  //
+  temp_buf[ 0 ] = *m_size_word;
+
+
+#ifdef TIME_MONITOR
+  if (n_basf2evt >= 50000 && n_basf2evt < 50500) {
+    cur_time = getTimeSec();
+    time_array2[ n_basf2evt - 50000 ] = cur_time - m_start_time;
+  }
+#endif
+
+#ifdef CHECK_SUM
+  unsigned int checksum = 0;
+  for (int i = 0; i < m_bufary[entry][0]; i++) {
+    if (i != 2) checksum += m_bufary[entry][i];
+  }
+  m_bufary[entry][2] = checksum;
+#endif
+  return temp_buf;
+}
+
+
+
+void DesSerCOPPER::initializeCOPPER()
+{
+
+#ifndef DUMMY
+  m_use_slot = 0; /* bit mask */
+  int slot_shift;
+
+  if ((m_finesse_bit_flag & 0x1) == 1) {
+    slot_shift = 0; // a:0, b:1, c:2, d:3
+    m_use_slot |= 1 << slot_shift;  //
+  }
+
+  if (((m_finesse_bit_flag >> 1) & 0x1) == 1) {
+    slot_shift = 1; // a:0, b:1, c:2, d:3
+    m_use_slot |= 1 << slot_shift;  //
+  }
+
+  if (((m_finesse_bit_flag >> 2) & 0x1) == 1) {
+    slot_shift = 2; // a:0, b:1, c:2, d:3
+    m_use_slot |= 1 << slot_shift;  //
+  }
+
+  if (((m_finesse_bit_flag >> 3) & 0x1) == 1) {
+    slot_shift = 3; // a:0, b:1, c:2, d:3
+    m_use_slot |= 1 << slot_shift;  //
+  }
+  //
+  // Present slots to use
+  //
+  if (! m_use_slot) {
+    char err_buf[100] = "[FATAL] Slot is not specified. Exiting...";
+    print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    exit(1);
+  } else {
+    int slot;
+    printf("[DEBUG] ");
+    for (slot = 0; slot < 4; slot++) {
+      if (m_use_slot & (1 << slot)) printf(" %c", 'A' + slot);
+    }
+    printf("\n");
+  }
+
+
+#endif
+
+#ifndef YAMADA_DUMMY
+  //  B2INFO("Opening COPPER...");  fflush(stderr);
+  printf("[DEBUG] Opening COPPER...\n"); fflush(stdout);
+  openCOPPER();
+  //  B2INFO("Done.\n"); fflush(stderr);
+  printf("[DEBUG] Done.\n"); fflush(stdout);
+#endif
+}
+
+
+void DesSerCOPPER::openCOPPER()
+{
+
+  if (m_cpr_fd != -1) {
+    close(m_cpr_fd);
+    m_cpr_fd = -1;
+  }
+  //
+  // Open a finesse device
+  //
+  if ((m_cpr_fd = open("/dev/copper/copper", O_RDONLY)) == -1) {
+    char err_buf[500];
+    sprintf(err_buf, "[FATAL] Failed to open /dev/copper/copper. Exiting... ");
+    print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    exit(1);
+  }
+
+  int set_regval = 15; // How many events to be stored in COPPER FIFO before request for DMA
+  //    int set_regval=1;
+  ioctl(m_cpr_fd, CPRIOSET_LEF_WA_FF, &set_regval);
+  ioctl(m_cpr_fd, CPRIOSET_LEF_WB_FF, &set_regval);
+  ioctl(m_cpr_fd, CPRIOSET_LEF_WC_FF, &set_regval);
+  ioctl(m_cpr_fd, CPRIOSET_LEF_WD_FF, &set_regval);
+  ioctl(m_cpr_fd, CPRIOSET_FINESSE_STA, &m_use_slot, sizeof(m_use_slot));
+
+  int v = 511 - 32;
+
+  ioctl(m_cpr_fd, CPRIOSET_LEF_WA_AF, &v, sizeof(v));
+  ioctl(m_cpr_fd, CPRIOSET_LEF_WB_AF, &v, sizeof(v));
+  ioctl(m_cpr_fd, CPRIOSET_LEF_WC_AF, &v, sizeof(v));
+  ioctl(m_cpr_fd, CPRIOSET_LEF_WD_AF, &v, sizeof(v));
+
+
+  //  B2INFO("DeSerializerCOPPER: openCOPPER() done.");
+  printf("[DEBUG] DeSerializerCOPPER: openCOPPER() done.\n"); fflush(stdout);
+
+}
+
+
+
+int DesSerCOPPER::readFD(int fd, char* buf, int data_size_byte, int delete_flag)
+{
+
+  int n = 0;
+  int read_size = 0;
+  while (1) {
+    if ((read_size = read(fd, (char*)buf + n, data_size_byte - n)) < 0) {
+      if (errno == EINTR) {
+        continue;
+      } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
+        if (n > 0) {
+          char err_buf[500];
+          sprintf(err_buf, "[FATAL] Return due to EAGAIN in the middle of an event( COPPER driver would't do this.). Exting...");
+          print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+          exit(-1);
+        }
+#ifdef NONSTOP
+        // Check run-pause request from SLC
+        string err_str;
+        try {
+          callCheckRunPause(err_str);
+        } catch (string err_str) {
+          if (delete_flag) {
+            // Delete allocated buffer
+            //            B2WARNING("Delete buffer before going to Run-pause state");
+            printf("[WARNING] Delete buffer before going to Run-pause state\n"); fflush(stdout);
+            delete buf;
+          }
+          throw (err_str);
+        }
+#endif
+        continue;
+      } else {
+#ifdef NONSTOP
+        m_run_error = 1;
+        //        B2ERROR(err_buf);
+        printf("[ERROR] Failed to read data from COPPER. %s %s %d",
+               __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        string err_str = "RUN_ERROR";
+        throw (err_str);
+#endif
+        char err_buf[500];
+        sprintf(err_buf, "[FATAL] Failed to read data from COPPER. %s %s %d",
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        exit(-1);
+      }
+    } else {
+      n += read_size;
+      if (n == data_size_byte)break;
+    }
+  }
+  return n;
+}
diff --git a/ROPCApplications/daq/rawdata/src/DesSerPrePC.cc b/ROPCApplications/daq/rawdata/src/DesSerPrePC.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fff12ba885a337c4bba0131b3dba4fa9a1c2db7e
--- /dev/null
+++ b/ROPCApplications/daq/rawdata/src/DesSerPrePC.cc
@@ -0,0 +1,831 @@
+//+
+// File : DesSerPrePC.cc
+// Description : Module to receive data from eb0 and send it to eb1tx
+//
+// Author : Satoru Yamada Itoh, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+#include <daq/rawdata/DesSerPrePC.h>
+#include <rawdata/dataobjects/RawFTSWFormat_latest.h>
+#include <rawdata/dataobjects/RawTLUFormat.h>
+
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <netinet/tcp.h>
+
+#include <sys/socket.h>
+
+//#define NO_DATA_CHECK
+//#define DUMHSLB
+
+using namespace std;
+using namespace Belle2;
+
+//----------------------------------------------------------------
+//                 Implementation
+//----------------------------------------------------------------
+DesSerPrePC::DesSerPrePC(string host_recv, int port_recv, string host_send, int port_send, int shmflag,
+                         const std::string& nodename, int nodeid)
+{
+
+  for (int i = 0 ; i < m_num_connections; i++) {
+    //  m_hostname_from.push_back( "localhost");
+    m_hostname_from.push_back(host_recv);
+    //  m_port_from.push_back(30000);
+    m_port_from.push_back(port_recv) ;
+    m_socket_recv.push_back(-1);
+  }
+
+  //  m_port_to = 31001;
+  m_port_to = port_send;
+  //  m_hostname_local = "localhost";
+  m_hostname_local = host_send;
+  m_nodename = nodename;
+
+  m_shmflag = shmflag;
+
+  //  B2INFO("DeSerializerPrePC: Constructor done.");
+  printf("[INFO] DeSerializerPrePC: Constructor done.\n"); fflush(stdout);
+}
+
+
+
+DesSerPrePC::~DesSerPrePC()
+{
+}
+
+
+
+int DesSerPrePC::recvFD(int sock, char* buf, int data_size_byte, int flag)
+{
+  int n = 0;
+  int read_size = 0;
+  while (1) {
+    if ((read_size = recv(sock, (char*)buf + n, data_size_byte - n , flag)) < 0) {
+      if (errno == EINTR) {
+        continue;
+      } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
+#ifdef NONSTOP
+        string err_str;
+        callCheckRunPause(err_str);
+#endif
+        continue;
+      } else {
+        perror("[WARNING]");
+        char err_buf[500];
+        sprintf(err_buf, "recv() returned error; ret = %d. : %s %s %d",
+                read_size, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+#ifdef NONSTOP
+        m_run_error = 1;
+        //        B2ERROR(err_buf);
+        printf("[WARNING] %s\n", err_buf); fflush(stdout);
+        string err_str = "RUN_ERROR";
+        printf("AIUEO********************\n"); fflush(stdout);
+        throw (err_str);
+#endif
+        print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        exit(-1);
+      }
+    } else if (read_size == 0) {
+      // Connection is closed ( error )
+      char err_buf[500];
+      sprintf(err_buf, "[WARNING] Connection is closed by peer(%s). readsize = %d %d. : %s %s %d",
+              strerror(errno), read_size, errno, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+#ifdef NONSTOP
+      m_run_error = 1;
+      //      B2ERROR(err_buf);
+      printf("%s\n", err_buf); fflush(stdout);
+      string err_str = "RUN_ERROR";
+      throw (err_str);
+#else
+      print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      exit(-1);
+#endif
+    } else {
+      n += read_size;
+      if (n == data_size_byte)break;
+    }
+  }
+  return n;
+}
+
+
+int DesSerPrePC::Connect()
+{
+
+  for (int i = 0; i < m_num_connections; i++) {
+
+    if (m_socket_recv[ i ] >= 0) continue;   // Already have an established socket
+
+    //
+    // Connect to a downstream node
+    //
+    struct hostent* host;
+    host = gethostbyname(m_hostname_from[ i ].c_str());
+    if (host == NULL) {
+      char err_buf[100];
+      sprintf(err_buf, "[FATAL] hostname(%s) cannot be resolved(%s). Check /etc/hosts. Exiting...", m_hostname_from[ i ].c_str(),
+              strerror(errno));
+      print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      sleep(1234567);
+      exit(1);
+    }
+
+    struct sockaddr_in socPC;
+    socPC.sin_family = AF_INET;
+    socPC.sin_addr.s_addr = *(unsigned int*)host->h_addr_list[0];
+    socPC.sin_port = htons(m_port_from[ i ]);
+    int sd = socket(PF_INET, SOCK_STREAM, 0);
+    int val1 = 0;
+    setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, &val1, sizeof(val1));
+
+    struct timeval timeout;
+    timeout.tv_sec = 1;
+    timeout.tv_usec = 0;
+    setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &timeout, (socklen_t)sizeof(timeout));
+
+    printf("[DEBUG] Connecting to %s port %d\n" , m_hostname_from[ i ].c_str(), m_port_from[ i ]); fflush(stdout);
+
+    while (1) {
+      if (connect(sd, (struct sockaddr*)(&socPC), sizeof(socPC)) < 0) {
+        perror("Failed to connect. Retrying...");
+        usleep(500000);
+      } else {
+        //        B2INFO("Done");
+        printf("[DEBUG] Done\n"); fflush(stdout);
+        break;
+      }
+    }
+    //    m_socket_recv.push_back(sd);
+    m_socket_recv[ i ] = sd;
+
+    // check socket paramters
+    int val, len;
+    len = sizeof(val);
+    getsockopt(m_socket_recv[ i ], SOL_SOCKET, SO_RCVBUF, &val, (socklen_t*)&len);
+    //    B2INFO("SO_RCVBUF" << val);
+    getsockopt(m_socket_recv[ i ], SOL_SOCKET, SO_SNDBUF, &val, (socklen_t*)&len);
+    //    B2DEBUG("SO_SNDBUF" <<  val);
+    getsockopt(m_socket_recv[ i ], IPPROTO_TCP, TCP_MAXSEG, &val, (socklen_t*)&len);
+    //    B2DEBUG("TCP_MAXSEG" <<  val);
+    getsockopt(m_socket_recv[ i ], IPPROTO_TCP, TCP_NODELAY, &val, (socklen_t*)&len);
+    //    B2DEBUG("TCP_NODELAY" <<  val);
+
+    if (m_status.isAvailable()) {
+      sockaddr_in sa;
+      memset(&sa, 0, sizeof(sockaddr_in));
+      socklen_t sa_len = sizeof(sa);
+      if (getsockname(m_socket_recv[i], (struct sockaddr*)&sa, (socklen_t*)&sa_len) == 0) {
+        m_status.setInputPort(ntohs(sa.sin_port));
+        m_status.setInputAddress(sa.sin_addr.s_addr);
+      }
+    }
+
+  }
+  //  B2INFO("[DEBUG] Initialization finished");
+  printf("[DEBUG] Initialization finished\n"); fflush(stdout);
+  return 0;
+}
+
+
+
+int* DesSerPrePC::recvData(int* delete_flag, int* total_buf_nwords, int* num_events_in_sendblock, int* num_nodes_in_sendblock)
+{
+  int* temp_buf = NULL; // buffer for data-body
+  int flag = 0;
+
+  vector <int> each_buf_nwords;
+  each_buf_nwords.clear();
+  vector <int> each_buf_nodes;
+  each_buf_nodes.clear();
+  vector <int> each_buf_events;
+  each_buf_events.clear();
+
+  *total_buf_nwords = 0;
+  *num_nodes_in_sendblock = 0;
+  *num_events_in_sendblock = 0;
+
+  //
+  // Read Header and obtain data size
+  //
+  int send_hdr_buf[ SendHeader::SENDHDR_NWORDS ];
+  int temp_num_events = 0;
+  int temp_num_nodes = 0;
+
+  // Read header
+  for (int i = 0; i < (int)(m_socket_recv.size()); i++) {
+
+    recvFD(m_socket_recv[ i ], (char*)send_hdr_buf, sizeof(int)*SendHeader::SENDHDR_NWORDS, flag);
+
+    SendHeader send_hdr;
+    send_hdr.SetBuffer(send_hdr_buf);
+
+    temp_num_events = send_hdr.GetNumEventsinPacket();
+    temp_num_nodes = send_hdr.GetNumNodesinPacket();
+
+    if (i == 0) {
+      *num_events_in_sendblock = temp_num_events;
+    } else if (*num_events_in_sendblock != temp_num_events) {
+#ifndef NO_DATA_CHECK
+      char err_buf[500];
+      sprintf(err_buf,
+              "[FATAL] CORRUPTED DATA: Different # of events or nodes in SendBlocks( # of eve : %d(socket 0) %d(socket %d), # of nodes: %d(socket 0) %d(socket %d). Exiting...\n",
+              *num_events_in_sendblock , temp_num_events, i,  *num_nodes_in_sendblock , temp_num_nodes, i);
+      print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      sleep(1234567);
+      exit(1);
+#endif
+    }
+
+    *num_nodes_in_sendblock += temp_num_nodes;
+
+    int rawblk_nwords = send_hdr.GetTotalNwords()
+                        - SendHeader::SENDHDR_NWORDS
+                        - SendTrailer::SENDTRL_NWORDS;
+    *total_buf_nwords += rawblk_nwords;
+
+    //
+    // Data size check1
+    //
+    if (rawblk_nwords > (int)(2.5e6) || rawblk_nwords <= 0) {
+      printData(send_hdr_buf, SendHeader::SENDHDR_NWORDS);
+      char err_buf[500];
+      sprintf(err_buf, "CORRUPTED DATA: Too large event : Header %d %d %d %d :block size %d words\n", i, temp_num_events, temp_num_nodes,
+              send_hdr.GetTotalNwords(), rawblk_nwords);
+      print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      sleep(123456);
+      exit(1);
+
+    }
+
+    each_buf_nwords.push_back(rawblk_nwords);
+    each_buf_events.push_back(temp_num_events);
+    each_buf_nodes.push_back(temp_num_nodes);
+
+  }
+
+
+  temp_buf = getNewBuffer(*total_buf_nwords, delete_flag); // this include only data body
+  //
+  // Read body
+  //
+  int total_recvd_byte = 0;
+  for (int i = 0; i < (int)(m_socket_recv.size()); i++) {
+
+    try {
+      total_recvd_byte += recvFD(m_socket_recv[ i ], (char*)temp_buf + total_recvd_byte,
+                                 each_buf_nwords[ i ] * sizeof(int), flag);
+    } catch (string err_str) {
+      if (*delete_flag) {
+        //        B2WARNING("Delete buffer before going to Run-pause state");
+        printf("[WARNING] Delete buffer before going to Run-pause state\n"); fflush(stdout);
+        delete temp_buf;
+      }
+      throw (err_str);
+    }
+    //
+    // Data length check
+    //
+    int temp_length = 0;
+    for (int j = 0; j < each_buf_nodes[ i ] * each_buf_events[ i ]; j++) {
+      int this_length = *((int*)((char*)temp_buf + total_recvd_byte - each_buf_nwords[ i ] * sizeof(int) + temp_length));
+      temp_length += this_length * sizeof(int);
+    }
+    if (temp_length != (int)(each_buf_nwords[ i ] * sizeof(int))) {
+      printf("[DEBUG]*******SENDHDR*********** \n");
+      printData(send_hdr_buf, SendHeader::SENDHDR_NWORDS);
+      printf("[DEBUG]*******BODY***********\n ");
+      printData(temp_buf, (int)(total_recvd_byte / sizeof(int)));
+      char err_buf[500];
+      sprintf(err_buf, "CORRUPTED DATA: Length written on SendHeader(%d) is invalid. Actual data size is %d. Exting...",
+              (int)(*total_buf_nwords * sizeof(int)), temp_length);
+      print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      sleep(1234567);
+      exit(-1);
+    }
+
+  }
+
+  if ((int)(*total_buf_nwords * sizeof(int)) != total_recvd_byte) {
+    char err_buf[500];
+    sprintf(err_buf, "CORRUPTED DATA: Received data size (%d byte) is not same as expected one (%d) from Sendheader. Exting...",
+            total_recvd_byte, (int)(*total_buf_nwords * sizeof(int)));
+    print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    sleep(1234567);
+    exit(-1);
+  }
+
+  // Read Traeiler
+  int send_trl_buf[(unsigned int)(SendTrailer::SENDTRL_NWORDS) ];
+  for (int i = 0; i < (int)(m_socket_recv.size()); i++) {
+    try {
+      recvFD(m_socket_recv[ i ], (char*)send_trl_buf, SendTrailer::SENDTRL_NWORDS * sizeof(int), flag);
+    } catch (string err_str) {
+      if (*delete_flag) {
+        //        B2WARNING("Delete buffer before going to Run-pause state");
+        printf("[WARNING] Delete buffer before going to Run-pause state\n"); fflush(stdout);
+        delete temp_buf;
+      }
+      throw (err_str);
+    }
+  }
+
+  return temp_buf;
+}
+
+
+void DesSerPrePC::setRecvdBuffer(RawDataBlockFormat* temp_raw_datablk, int* delete_flag)
+{
+  //
+  // Get data from socket
+  //
+  int total_buf_nwords = 0 ;
+  int num_events_in_sendblock = 0;
+  int num_nodes_in_sendblock = 0;
+
+  if (m_start_flag == 0) {
+    //    B2INFO("DeSerializerPrePC: Reading the 1st packet from eb0...");
+    printf("DeSerializerPrePC: Reading the 1st packet from eb0...\n"); fflush(stdout);
+  }
+  int* temp_buf = recvData(delete_flag, &total_buf_nwords, &num_events_in_sendblock,
+                           &num_nodes_in_sendblock);
+  if (m_start_flag == 0) {
+    //    B2INFO("DeSerializerPrePC: Done. the size of the 1st packet " << total_buf_nwords << " words");
+    printf("DeSerializerPrePC: Done. the size of the 1st packet %d words\n", total_buf_nwords); fflush(stdout);
+    m_start_flag = 1;
+  }
+  m_recvd_totbytes += total_buf_nwords * sizeof(int);
+
+  temp_raw_datablk->SetBuffer((int*)temp_buf, total_buf_nwords, *delete_flag,
+                              num_events_in_sendblock, num_nodes_in_sendblock);
+
+  //
+  // check even # and node # in one Sendblock
+  //
+  int num_entries = temp_raw_datablk->GetNumEntries();
+  if (num_entries != num_events_in_sendblock * num_nodes_in_sendblock) {
+    char err_buf[500];
+    sprintf(err_buf,
+            "[FATAL] CORRUPTED DATA: Inconsistent SendHeader value. # of nodes(%d) times # of events(%d) differs from # of entries(%d). Exiting...",
+            num_nodes_in_sendblock, num_events_in_sendblock, num_entries);
+    print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    sleep(1234567);
+    exit(-1);
+  }
+  return;
+
+}
+
+
+
+
+void DesSerPrePC::checkData(RawDataBlockFormat* raw_datablk, unsigned int* eve_copper_0)
+{
+  //  int data_size_copper_0 = -1;
+  //  int data_size_copper_1 = -1;
+
+  //
+  // Data check
+  //
+  int* temp_buf = raw_datablk->GetBuffer(0);
+  int cpr_num = 0;
+  unsigned int cur_evenum = 0, cur_copper_ctr = 0;
+  unsigned int eve_array[32]; // # of noeds is less than 17
+  unsigned int utime_array[32];// # of noeds is less than 17
+  unsigned int ctime_type_array[32];// # of noeds is less than 17
+
+#ifdef DUMHSLB
+  unsigned int exp_run_ftsw = 0, ctime_trgtype_ftsw = 0, utime_ftsw = 0;
+#endif
+
+  for (int k = 0; k < raw_datablk->GetNumEvents(); k++) {
+    memset(eve_array, 0, sizeof(eve_array));
+    memset(utime_array, 0, sizeof(utime_array));
+    memset(ctime_type_array, 0, sizeof(ctime_type_array));
+
+    int num_nodes_in_sendblock = raw_datablk->GetNumNodes();
+    for (int l = 0; l < num_nodes_in_sendblock; l++) {
+      int entry_id = l + k * num_nodes_in_sendblock;
+
+      //
+      // RawFTSW
+      //
+      if (raw_datablk->CheckFTSWID(entry_id)) {
+        RawFTSWFormat_latest* temp_rawftsw = new RawFTSWFormat_latest;
+        int block_id = 0;
+        temp_rawftsw->SetBuffer((int*)temp_buf + raw_datablk->GetBufferPos(entry_id),
+                                raw_datablk->GetBlockNwords(entry_id), 0, 1, 1);
+        if (temp_rawftsw->GetEveNo(block_id) < 10) {
+          printf("[DEBUG] ######FTSW#########\n");
+          printData((int*)temp_buf + raw_datablk->GetBufferPos(entry_id), raw_datablk->GetBlockNwords(entry_id));
+        }
+
+#ifdef DUMHSLB
+        exp_run_ftsw = temp_rawftsw->GetExpRunSubrun(block_id);
+        ctime_trgtype_ftsw = temp_rawftsw->GetTTCtimeTRGType(block_id);
+        utime_ftsw = temp_rawftsw->GetTTUtime(block_id);
+#endif
+
+
+#ifndef NO_DATA_CHECK
+        try {
+          temp_rawftsw->CheckData(0, m_prev_evenum, &cur_evenum, m_prev_exprunsubrun_no, &m_exprunsubrun_no);
+          eve_array[ entry_id ] = cur_evenum;
+        } catch (string err_str) {
+          char err_buf[500];
+          strcpy(err_buf, err_str.c_str());
+          print_err.PrintError(err_buf , __FILE__, __PRETTY_FUNCTION__, __LINE__);
+          exit(1);
+        }
+#endif
+        utime_array[ entry_id ] = temp_rawftsw->GetTTUtime(block_id);
+        ctime_type_array[ entry_id ] = temp_rawftsw->GetTTCtimeTRGType(block_id);
+        delete temp_rawftsw;
+
+        //
+        // RawTLU
+        //
+      } else if (raw_datablk->CheckTLUID(entry_id)) {
+
+        RawTLUFormat* temp_rawtlu = new RawTLUFormat;
+        temp_rawtlu->SetBuffer((int*)temp_buf + raw_datablk->GetBufferPos(entry_id),
+                               raw_datablk->GetBlockNwords(entry_id), 0, 1, 1);
+        if (temp_rawtlu->GetEveNo(0) < 10
+           ) {
+          printf("[DEBUG] ######TLU#########\n");
+          printData((int*)temp_buf + raw_datablk->GetBufferPos(entry_id), raw_datablk->GetBlockNwords(entry_id));
+        }
+
+#ifndef NO_DATA_CHECK
+        try {
+          temp_rawtlu->CheckData(0, m_prev_evenum, &cur_evenum);
+          eve_array[ entry_id ] = cur_evenum;
+        } catch (string err_str) {
+          char err_buf[500];
+          strcpy(err_buf, err_str.c_str());
+          print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+          exit(1);
+        }
+#endif
+        delete temp_rawtlu;
+      } else {
+        //
+        // RawCOPPER
+        //
+        PreRawCOPPERFormat_latest* pre_rawcpr_fmt = new PreRawCOPPERFormat_latest;
+        pre_rawcpr_fmt->SetBuffer((int*)temp_buf + raw_datablk->GetBufferPos(entry_id),
+                                  raw_datablk->GetBlockNwords(entry_id), 0, 1, 1);
+
+#ifdef DUMHSLB
+        int block_id = 0;
+        "do not use the following for actual DAQ"
+        (pre_rawcpr_fmt->GetBuffer(block_id))[ RawHeader_latest::POS_EXP_RUN_NO ] = exp_run_ftsw;
+        (pre_rawcpr_fmt->GetBuffer(block_id))[ RawHeader_latest::POS_TTCTIME_TRGTYPE ] = ctime_trgtype_ftsw;
+        (pre_rawcpr_fmt->GetBuffer(block_id))[ RawHeader_latest::POS_TTUTIME ] = utime_ftsw;
+#endif
+
+#ifndef NO_DATA_CHECK
+        try {
+          pre_rawcpr_fmt->CheckData(0, m_prev_evenum, &cur_evenum,
+                                    m_prev_copper_ctr, &cur_copper_ctr,
+                                    m_prev_exprunsubrun_no, &m_exprunsubrun_no);
+          eve_array[ entry_id ] = cur_evenum;
+        } catch (string err_str) {
+          exit(1); // Error in the contents of an event was detected
+        }
+#endif
+
+        utime_array[ entry_id ] = pre_rawcpr_fmt->GetTTUtime(0);
+        ctime_type_array[ entry_id ] = pre_rawcpr_fmt->GetTTCtimeTRGType(0);
+
+        if (cpr_num == 0) {
+          //          data_size_copper_0 = raw_datablk->GetBlockNwords(entry_id);
+          *eve_copper_0 = (raw_datablk->GetBuffer(entry_id))[ 3 ];
+        } else if (cpr_num == 1) {
+          //          data_size_copper_1 = raw_datablk->GetBlockNwords(entry_id);
+        }
+        cpr_num++;
+        delete pre_rawcpr_fmt;
+      }
+    }
+
+#ifndef NO_DATA_CHECK
+    // event #, ctime, utime over nodes
+    for (int l = 1; l < num_nodes_in_sendblock; l++) {
+      if (eve_array[ 0 ] != eve_array[ l ] ||
+          utime_array[ 0 ] != utime_array[ l ] ||
+          ctime_type_array[ 0 ] != ctime_type_array[ l ]) {
+        char err_buf[500];
+        for (int m = 0; m < num_nodes_in_sendblock; m++) {
+          printf("[DEBUG] node %d eve # %d utime %x ctime %x\n",
+                 m,  eve_array[ m ], utime_array[ m ], ctime_type_array[ m ]);
+        }
+        sprintf(err_buf, "[FATAL] CORRUPTED DATA: Event or Time record mismatch. Exiting...");
+        print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        sleep(1234567);
+        exit(-1);
+      }
+    }
+#endif
+
+    // Event # monitor in runchange
+//     if (m_prev_runsubrun_no != m_runsubrun_no) {
+//       printf("[DEBUG] ##############################################\n");
+//       for (int m = 0; m < raw_datablk->GetNumEntries(); m++) {
+//         printf("[DEBUG] %d eve %u prev %u\n", m, eve_array[ m ], m_prev_evenum);
+//       }
+//       printf("[DEBUG] ##############################################\n");
+//       fflush(stderr);
+//     }
+    m_prev_evenum = cur_evenum;
+    m_prev_copper_ctr = cur_copper_ctr;
+    m_prev_exprunsubrun_no = m_exprunsubrun_no;
+  }
+  return;
+}
+
+
+
+void DesSerPrePC::DataAcquisition()
+{
+  // For data check
+  unsigned int eve_copper_0 = 0;
+  //  B2INFO("initializing...");
+  printf("[DEBUG] initializing...\n"); fflush(stdout);
+  initialize();
+
+  //  B2INFO("Done.");
+  printf("[DEBUG] Done.\n"); fflush(stdout);
+
+  if (m_start_flag == 0) {
+    //
+    // Connect to eb0: This should be here because we want Serializer first to accept connection from eb1tx
+    //
+    Connect();
+    if (m_status.isAvailable()) {
+      //      B2INFO("DeSerializerPrePC: Waiting for Start...\n");
+      printf("[DEBUG] DeSerializerPrePC: Waiting for Start...\n"); fflush(stdout);
+      m_status.reportRunning();
+    }
+    m_start_time = getTimeSec();
+    n_basf2evt = 0;
+  }
+
+  //
+  // Main loop
+  //
+  while (1) {
+    //
+    // Stand-by loop
+    //
+#ifdef NONSTOP
+    if (m_run_pause > 0 || m_run_error > 0) {
+      waitResume();
+    }
+#endif
+
+    clearNumUsedBuf();
+    //    RawDataBlock raw_datablk[ NUM_EVT_PER_BASF2LOOP_PC ];
+    RawDataBlockFormat raw_datablk[ NUM_EVT_PER_BASF2LOOP_PC ];
+
+    //
+    // Recv loop
+    //
+    for (int j = 0; j < NUM_EVT_PER_BASF2LOOP_PC; j++) {
+      //
+      // Receive data from COPPER
+      //
+      eve_copper_0 = 0;
+      int delete_flag_from =
+        0; // Delete flag for temp_rawdatablk.It can be set to 1 by setRecvdBuffer if the buffer size is larger than that of pre-allocated buffer.
+      int delete_flag_to =
+        0; // Delete flag for raw_datablk[i]. It can be set to 1 by getNewBuffer if the buffer size is larger than that of pre-allocated buffer.
+      RawDataBlockFormat temp_rawdatablk;
+      try {
+        setRecvdBuffer(&temp_rawdatablk, &delete_flag_from);
+        checkData(&temp_rawdatablk, &eve_copper_0);
+      } catch (string err_str) {
+        printf("Error was detected\n"); fflush(stdout);
+        break;
+      }
+      //     PreRawCOPPERFormat_latest pre_rawcopper_latest;
+      //     pre_rawcopper_latest.SetBuffer((int*)temp_rawdatablk.GetWholeBuffer(), temp_rawdatablk.TotalBufNwords(),
+      //                                    0, temp_rawdatablk.GetNumEvents(), temp_rawdatablk.GetNumNodes());
+      ////     pre_rawcopper_latest.CheckCRC16( 0, 0 );
+
+      int temp_num_events, temp_num_nodes;
+      int temp_nwords_to;
+      int* buf_to = NULL;
+#ifdef REDUCED_RAWCOPPER
+      //
+      // Copy reduced buffer
+      //
+      //      int* buf_to = getNewBuffer(m_pre_rawcpr.CalcReducedDataSize(&temp_rawdatablk), &delete_flag_to); // basf2-dependent style
+      int* temp_bufin = temp_rawdatablk.GetWholeBuffer();
+      int temp_nwords_from = temp_rawdatablk.TotalBufNwords();
+      temp_num_events = temp_rawdatablk.GetNumEvents();
+      temp_num_nodes = temp_rawdatablk.GetNumNodes();
+      int calced_temp_nwords_to = m_pre_rawcpr.CalcReducedDataSize(temp_bufin, temp_nwords_from, temp_num_events, temp_num_nodes);
+      buf_to = getNewBuffer(calced_temp_nwords_to, &delete_flag_to);
+
+      //      m_pre_rawcpr.CopyReducedData(&temp_rawdatablk, buf_to, delete_flag_from); // basf2-dependent style
+      m_pre_rawcpr.CopyReducedData(temp_bufin, temp_nwords_from, temp_num_events, temp_num_nodes, buf_to, &temp_nwords_to);
+      if (calced_temp_nwords_to != temp_nwords_to) {
+        char err_buf[500];
+        sprintf(err_buf,
+                "[FATAL] CORRUPTED DATA: Estimations of reduced event size are inconsistent. CalcReducedDataSize = %d. CopyReducedData = %d. Exiting...",
+                calced_temp_nwords_to, temp_nwords_to);
+        print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        exit(1);
+      }
+      m_status.copyEventHeader(buf_to);
+#else
+      buf_to = temp_rawdatablk.GetWholeBuffer();
+      temp_nwords_to = temp_rawdatablk.TotalBufNwords();
+      temp_num_events = temp_rawdatablk.GetNumEvents();
+      temp_num_nodes = temp_rawdatablk.GetNumNodes();
+      delete_flag_to = delete_flag_from;
+      delete_flag_from = 0; // to avoid double delete
+#endif
+
+      //
+      // Set buffer to the RawData class stored in DataStore
+      //
+//       raw_datablk[ j ].SetBuffer( (int*)temp_rawdatablk.GetWholeBuffer(), temp_rawdatablk.TotalBufNwords(),
+//                                  delete_flag_to, temp_rawdatablk.GetNumEvents(),
+//                                  temp_rawdatablk.GetNumNodes());
+      raw_datablk[ j ].SetBuffer(buf_to, temp_nwords_to, delete_flag_to, temp_num_events, temp_num_nodes);
+
+
+      //
+      // CRC16 check after data reduction
+      //
+#ifdef REDUCED_RAWCOPPER
+      PostRawCOPPERFormat_latest post_rawcopper_latest;
+
+//       post_rawcopper_latest.SetBuffer((int*)temp_rawdatablk.GetWholeBuffer(), temp_rawdatablk.TotalBufNwords(),
+//                                       0, temp_rawdatablk.GetNumEvents(), temp_rawdatablk.GetNumNodes());
+      post_rawcopper_latest.SetBuffer(raw_datablk[ j ].GetWholeBuffer(), raw_datablk[ j ].TotalBufNwords(),
+                                      0, raw_datablk[ j ].GetNumEvents(), raw_datablk[ j ].GetNumNodes());
+
+      for (int i_finesse_num = 0; i_finesse_num < 4; i_finesse_num ++) {
+        int block_num = 0;
+        if (post_rawcopper_latest.GetFINESSENwords(block_num, i_finesse_num) > 0) {
+          post_rawcopper_latest.CheckCRC16(block_num, i_finesse_num);
+        }
+      }
+
+#endif
+    }
+
+#ifdef NONSTOP
+    // Goto Stand-by loop when run is paused or stopped by error
+    if (m_run_pause != 0 || m_run_error != 0) continue;
+#endif
+
+
+    ///////////////////////////////////////////////////////////////
+    // From Serializer.cc
+    //////////////////////////////////////////////////////////////
+    if (m_start_flag == 0) {
+      m_start_time = getTimeSec();
+      n_basf2evt = 0;
+    }
+    //  StoreArray<RawCOPPER> rawcprarray;
+    //  StoreArray<RawDataBlock> raw_dblkarray;
+
+    for (int j = 0; j < NUM_EVT_PER_BASF2LOOP_PC; j++) {
+
+      //
+      // Send data
+      //
+      if (m_start_flag == 0) {
+        //        B2INFO("SerializerPC: Sending the 1st packet...");
+        printf("[DEBUG] SerializerPC: Sending the 1st packet...\n"); fflush(stdout);
+      }
+
+      try {
+        m_sent_totbytes += sendByWriteV(&(raw_datablk[ j ]));
+      } catch (string err_str) {
+#ifdef NONSTOP
+        break;
+#endif
+        print_err.PrintError((char*)err_str.c_str(), __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        exit(1);
+      }
+      if (m_start_flag == 0) {
+        //        B2INFO("Done. ");
+        printf("[DEBUG] Done.\n"); fflush(stdout);
+        m_start_flag = 1;
+      }
+    }
+
+#ifdef NONSTOP
+    // Goto Stand-by loop when run is paused or stopped by error
+    if (m_run_pause != 0 || m_run_error != 0) continue;
+#endif
+
+    //
+    // Monitor
+    //
+    if (max_nevt >= 0 || max_seconds >= 0.) {
+#ifdef AIUEO
+      if (n_basf2evt % 10000 == 0) {
+//     if ((n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC >= max_nevt && max_nevt > 0)
+//         || (getTimeSec() - m_start_time > max_seconds && max_seconds > 0.)) {
+        printf("[DEBUG] RunStop was detected. ( Setting:  Max event # %d MaxTime %lf ) Processed Event %d Elapsed Time %lf[s]\n",
+               max_nevt , max_seconds, n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC, getTimeSec() - m_start_time);
+      }
+#endif
+    }
+
+    if ((n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC) % 100000 == 0) {
+      double interval = cur_time - m_prev_time;
+      double total_time = cur_time - m_start_time;
+      printf("[DEBUG] Event %12d Rate %6.2lf[kHz] Recvd %6.2lf[MB/s] sent %6.2lf[MB/s] RunTime %8.2lf[s] interval %8.4lf[s]\n",
+             n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC,
+             (n_basf2evt  - m_prev_nevt)*NUM_EVT_PER_BASF2LOOP_PC / interval / 1.e3,
+             (m_recvd_totbytes - m_recvd_prev_totbytes) / interval / 1.e6,
+             (m_sent_totbytes - m_sent_prev_totbytes) / interval / 1.e6,
+             total_time,
+             interval);
+      fflush(stdout);
+
+      m_prev_time = cur_time;
+      m_recvd_prev_totbytes = m_recvd_totbytes;
+      m_sent_prev_totbytes = m_sent_totbytes;
+      m_prev_nevt = n_basf2evt;
+      cur_time = getTimeSec();
+    }
+
+    n_basf2evt++;
+
+    if (m_status.isAvailable()) {
+      m_status.setOutputNBytes(m_sent_totbytes);
+      m_status.setOutputCount(n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC);
+    }
+
+  }
+
+  return;
+}
+
+/////////////////////////////////////////////////////
+//   From Serializer.cc
+/////////////////////////////////////////////////////
+
+
+#ifdef NONSTOP
+void DesSerPrePC::waitResume()
+{
+  if (m_run_pause == 0) {
+    while (true) {
+      if (checkRunPause()) break;
+#ifdef NONSTOP_DEBUG
+      printf("\033[31m");
+      printf("###########(DesSerPrePC) Waiting for Runstop()  ###############\n");
+      fflush(stdout);
+      printf("\033[0m");
+#endif
+      sleep(1);
+    }
+  }
+
+  while (true) {
+#ifdef NONSTOP_DEBUG
+    printf("\033[31m");
+    printf("###########(Ser) Waiting for Resume ###############\n");
+    fflush(stdout);
+    printf("\033[0m");
+#endif
+    if (checkRunRecovery()) {
+      m_run_pause = 0;
+      break;
+    }
+    sleep(1);
+  }
+
+
+  printf("Done!\n"); fflush(stdout);
+
+  printf("Checking connection to eb0\n"); fflush(stdout);
+  if (CheckConnection(m_socket_send) < 0) {
+    printf("Trying Accept1\n"); fflush(stdout);
+    Accept();
+    printf("Trying Accept2\n"); fflush(stdout);
+  }
+
+  printf("Checking connection to COPPER\n"); fflush(stdout);
+  for (int i = 0; i < m_num_connections; i++) {
+    if (CheckConnection(m_socket_recv[ i ]) < 0)  m_socket_recv[ i ] = -1;
+  }
+  Connect();
+
+  resumeRun();
+  return;
+}
+
+
+
+#endif
+
diff --git a/ROPCApplications/daq/ropc/Makefile b/ROPCApplications/daq/ropc/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..23647c65ded1e8ce259fcfa73f7fe73f9eff1da2
--- /dev/null
+++ b/ROPCApplications/daq/ropc/Makefile
@@ -0,0 +1,102 @@
+TEMP_LOCAL_DIR=$(PWD)/../../
+
+
+CXX = g++
+INCDIR = ./include
+PCIE40_INCDIR = -I$(TEMP_LOCAL_DIR)/../Pcie40Driver -I$(TEMP_LOCAL_DIR)/../Pcie40Applications
+CFLAGS   = -g -O3 -Wall -fPIC -I${INCDIR} ${PCIE40_INCDIR}
+#LOCALLIB  = CPRROPCDAQ
+LIBFLAG = -lrt -lpthread#-l${LOCALLIB}
+
+RAWDATAPATH=${TEMP_LOCAL_DIR}/rawdata/src:${TEMP_LOCAL_DIR}/rawdata/dataobjects/src
+DAQPATH=${TEMP_LOCAL_DIR}/daq/dataobjects/src:${TEMP_LOCAL_DIR}/daq/rawdata/src
+SLCPATH=${TEMP_LOCAL_DIR}/daq/slc/readout/src:${TEMP_LOCAL_DIR}/daq/slc/system/src:${TEMP_LOCAL_DIR}/daq/slc/base/src
+VPATH = ${RAWDATAPATH}:${DAQPATH}:${SLCPATH}
+
+RAWDATAOBJS = RawDataBlockFormat.o RawCOPPERFormat.o RawCOPPERFormat_latest.o PreRawCOPPERFormat_latest.o PostRawCOPPERFormat_latest.o RawHeader_latest.o RawTrailer_latest.o RawTLUFormat.o RawFTSWFormat.o RawFTSWFormat_latest.o CRCCalculator.o 
+DAQOBJS = DesSer.o DesSerPrePC.o DesSerCOPPER.o CprErrorMessage.o SendHeader.o SendTrailer.o
+SLCOBJS = RunInfoBuffer.o SharedMemory.o MMutex.o MCond.o LogFile.o Mutex.o Date.o ConfigFile.o StringUtil.o
+OBJS = ${RAWDATAOBJS} ${DAQOBJS} ${SLCOBJS}
+
+LIBDIR=$(BELLE2_LOCAL_DIR)/lib
+
+TARGET1=des_ser_ROPC_main
+TARGET2=des_ser_COPPER_main
+
+#
+# PCIe40 libraries
+#
+PCIE40OBJS = ../../../Pcie40Applications/pcie40_ul_lib.out/pcie40_ul_lib.o
+PCIE40_LIBFLAGS = -L../../../Pcie40Libraries/lib -lpcie40 -L../../../Pcie40DriverLibraries/ -lpcie40driver_ecs
+
+
+all: clean link ${TARGET1} ${TARGET2} cleanobj
+
+ropc: clean_ropc link ${TARGET1} cleanobj
+
+copper: clean_copper link ${TARGET2} cleanobj
+	@ echo "!!!!!!! Martin added overrides to reduce cppcheck warnings (https://stash.desy.de/projects/B2/repos/software/pull-requests/2825/overview), which leads to failure of compiling on COPPER. To compile on a COPPER, please run the following commands to remove override in rawdata classes"
+	@ echo "!!!!!!! cd rawdata/dataobjects/include; sed -i -e 's/ override;/;/g' *.h"
+
+
+${TARGET1}: ${TARGET1}.cc ${OBJS} ${PCIE40OBJS}
+	$(CXX) $(CFLAGS) ${LIBFLAG} ${PCIE40_LIBFLAGS} -L./ $^ -o $@ 
+
+${TARGET2}: ${TARGET2}.cc ${OBJS} ${PCIE40OBJS}
+	$(CXX) $(CFLAGS) ${LIBFLAG} ${PCIE40_LIBFLAGS} -L./ $^ -o $@ 
+
+$(OBJS): %.o : %.cc
+	@ echo "<< compiling $@ >>"
+	@ $(CXX) -c $(CFLAGS) $<
+
+
+#${LOCALLIB}: $(OBJS)
+#	@ echo "<< linking shared library $@ >>"
+#	@ $(CXX) -shared $(CFLAGS) $^ -o lib$@.so
+
+#.c.o:
+#	$(CXX) $(CFLAGS) -c ${INC} $<
+
+.PHONY: link
+link:
+	@ echo "<< making smylink $@ >>"
+	@if [ ! -d ${INCDIR} ]; then \
+	mkdir -p include/daq/slc/system ; \
+	mkdir -p include/daq/slc/readout ; \
+	mkdir -p include/daq/slc/base ; \
+	mkdir -p include/daq/rawdata ; \
+	mkdir -p include/rawdata/dataobjects ; \
+	mkdir -p include/daq/rawdata/modules ; \
+	mkdir -p include/daq/dataobjects ; \
+	ln -s ${TEMP_LOCAL_DIR}/rawdata/dataobjects/include/*.h ./include/rawdata/dataobjects/ ; \
+	ln -s ${TEMP_LOCAL_DIR}/rawdata/include/*.h ./include/rawdata/ ; \
+	ln -s ${TEMP_LOCAL_DIR}/daq/rawdata/include/*.h ./include/daq/rawdata/ ; \
+	ln -s ${TEMP_LOCAL_DIR}/daq/rawdata/modules/include/*.h ./include/daq/rawdata/modules/ ; \
+	ln -s ${TEMP_LOCAL_DIR}/daq/dataobjects/include/*.h ./include/daq/dataobjects/ ; \
+	ln -s ${TEMP_LOCAL_DIR}/daq/slc/system/include/*.h ./include/daq/slc/system/ ; \
+	ln -s ${TEMP_LOCAL_DIR}/daq/slc/readout/include/*.h ./include/daq/slc/readout/ ; \
+	ln -s ${TEMP_LOCAL_DIR}/daq/slc/base/include/*.h ./include/daq/slc/base/ ; \
+	fi
+
+.PHONY:	clean
+clean:
+	@ echo "<< clearing directry >>"
+	@ rm -rf ${TARGET1} ${TARGET2} $(OBJS) lib${LOCALLIB}.so *~ .*~ \#*~
+	@ rm -rf ${INCDIR}
+
+.PHONY:	clean_ropc
+clean_ropc:
+	@ echo "<< clearing directry >>"
+	@ rm -rf ${TARGET1} $(OBJS) lib${LOCALLIB}.so *~ .*~ \#*~
+	@ rm -rf ${INCDIR}
+
+.PHONY:	clean_copper
+clean_copper:
+	@ echo "<< clearing directry >>"
+	@ rm -rf ${TARGET2} $(OBJS) lib${LOCALLIB}.so *~ .*~ \#*~
+	@ rm -rf ${INCDIR}
+
+.PHONY:	cleanobj
+cleanobj:
+	@ echo "<< clearing object files >>"
+	@ rm -rf $(OBJS) 
diff --git a/ROPCApplications/daq/ropc/SConscript b/ROPCApplications/daq/ropc/SConscript
new file mode 100644
index 0000000000000000000000000000000000000000..d35e248f87c2f3fb36239cc21a2ea7398fc2173e
--- /dev/null
+++ b/ROPCApplications/daq/ropc/SConscript
@@ -0,0 +1,5 @@
+Import('env')
+
+env['CONTINUE'] = False
+
+Return('env')
diff --git a/ROPCApplications/daq/ropc/des_ser_COPPER_main.cc b/ROPCApplications/daq/ropc/des_ser_COPPER_main.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1be33d931b0b2a8da2c81d162a9b189401cbfb42
--- /dev/null
+++ b/ROPCApplications/daq/ropc/des_ser_COPPER_main.cc
@@ -0,0 +1,59 @@
+//+
+// File : DAQmain.cc
+// Description : Base class for Module to receive data from outside and store it to DataStore
+//
+// Author : Satoru Yamada Itoh, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+//#include <daq/rawdata/modules/DAQConsts.h>
+//#include <daq/rawdata/des_ser_COPPER_main.h>
+#include "des_ser_COPPER_main.h"
+//#include <daq/rawdata/modules/DesSerPrePC.h>
+//#include <daq/rawdata/DesSerPrePC.h>
+#include <daq/rawdata/DesSerCOPPER.h>
+//#define MAXEVTSIZE 400000000
+#include "pcie40_ul_lib.h"
+
+using namespace std;
+using namespace Belle2;
+
+
+int main(int argc, char** argv)
+{
+
+  readout();
+  return 1;
+
+  if (argc != 6) {
+    printf("[FATAL] Usage : %s <COPPER hostname> <COPPER node ID> <bit flag of FINNESEs> <Use NSM(Network Shared Memory)? yes=1/no=0> <NSM nodename>",
+           argv[0]);
+    //      printf("Usage : %s <COPPER hostname> <Use NSM(Network Shared Memory)? yes=1/no=0> <port # to eb0> <NSM nodename>", argv[0]);;
+    exit(1);
+  }
+
+  string host_recv = argv[1];     //! hostname
+  int shmflag = atoi(argv[4]);      //! Use shared memory -> 1; Without shm -> 0
+  int port_send = 30000;      //! port number
+  //    int port_send = atoi(argv[3]);      //! port number
+  string nodename = argv[5];    //! Node name
+  string host_send = "0.0.0.0";    //! hostname
+  int port_recv = 30000;    //! port number
+  int nodeid = atoi(argv[2]);
+  int finesse_bitflag = atoi(argv[3]);
+  DesSerCOPPER des_ser_copper(host_recv, port_recv,
+                              host_send, port_send, shmflag,
+                              nodename, nodeid, finesse_bitflag);
+  des_ser_copper.DataAcquisition();
+
+
+  //
+  // Update EventMetaData
+  //
+//   m_eventMetaDataPtr.create();
+//   m_eventMetaDataPtr->setExperiment(1);
+//   m_eventMetaDataPtr->setRun(1);
+//   m_eventMetaDataPtr->setEvent(1);
+
+}
+//}
+
diff --git a/ROPCApplications/daq/ropc/des_ser_COPPER_main.h b/ROPCApplications/daq/ropc/des_ser_COPPER_main.h
new file mode 100644
index 0000000000000000000000000000000000000000..6a8d0aa342856d5b8fcf6b73b7ef4648ab36b866
--- /dev/null
+++ b/ROPCApplications/daq/ropc/des_ser_COPPER_main.h
@@ -0,0 +1,106 @@
+//+
+// File : des_ser_COPPER_main.h
+// Description : Base class for Module to receive data from outside and store it to DataStore
+//
+// Author : Satoru Yamada Itoh, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef DES_SER_COPPER_MAIN_H
+#define DES_SER_COPPER_MAIN_H
+
+#include <string>
+#include <vector>
+#include <stdlib.h>
+/* #include <sys/time.h> */
+
+/* #include <framework/core/Module.h> */
+/* #include <framework/pcore/EvtMessage.h> */
+/* #include <framework/pcore/MsgHandler.h> */
+/* #include <framework/datastore/DataStore.h> */
+/* #include <framework/datastore/StoreObjPtr.h> */
+/* #include <framework/datastore/StoreArray.h> */
+/* #include <framework/dataobjects/EventMetaData.h> */
+
+/* #include <daq/dataflow/EvtSocket.h> */
+/* #include <daq/slc/readout/RunInfoBuffer.h> */
+/* #include <daq/rawdata/CprErrorMessage.h> */
+/* #include <daq/rawdata/modules/DAQConsts.h> */
+
+
+/* #include <rawdata/dataobjects/RawDataBlock.h> */
+//#include <rawdata/dataobjects/RawCOPPER.h>
+
+/* #include <sys/socket.h> */
+/* #include <sys/types.h> */
+/* #include <arpa/inet.h> */
+/* #include <netinet/in.h> */
+/* #include <netinet/tcp.h> */
+
+/* #include <sys/mman.h> */
+/* #include <sys/stat.h> */
+/* #include <fcntl.h> */
+
+/* using namespace std; */
+/* using namespace Belle2; */
+
+/* namespace Belle2 { */
+
+/*   /\*! A class definition of an input module for Sequential ROOT I/O *\/ */
+
+/*   class des_ser_COPPER_main{ */
+
+/*     // Public functions */
+/*   public: */
+
+/*     //! Constructor / Destructor */
+/*     des_ser_COPPER_mainModule(); */
+/*     virtual ~des_ser_COPPER_mainModule(); */
+
+/*     //! Module functions to be called from main process */
+/*     virtual void initialize(); */
+
+/*     //! Module functions to be called from main process */
+/*     virtual void event(); */
+
+/*   protected : */
+/*     //! hostname */
+/*     string m_host_recv; */
+
+/*     //! hostname */
+/*     string m_host_send; */
+
+/*     //! port number */
+/*     int m_port_recv; */
+
+/*     //! port number */
+/*     int m_port_send; */
+
+/*     //! Messaage handler */
+/*     MsgHandler* m_msghandler; */
+
+/*     //! Compression Level */
+/*     int m_compressionLevel; */
+
+/*     //! Node(PC or COPPER) ID */
+/*     int m_nodeid; */
+
+/*     //! Node name */
+/*     std::string m_nodename; */
+
+/*     //! Use shared memory -> 1; Without shm -> 0 */
+/*     int m_shmflag; */
+
+/*     // Event Meta Data */
+/*     StoreObjPtr<EventMetaData> m_eventMetaDataPtr; */
+
+/*   private: */
+
+
+/*   public: */
+
+/*   }; */
+
+/* } // end namespace Belle2 */
+
+#endif // MODULEHELLO_H
diff --git a/ROPCApplications/daq/ropc/des_ser_ROPC_main.cc b/ROPCApplications/daq/ropc/des_ser_ROPC_main.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e53501b6961f19b1748231278c938f77ad9197a4
--- /dev/null
+++ b/ROPCApplications/daq/ropc/des_ser_ROPC_main.cc
@@ -0,0 +1,49 @@
+//+
+// File : DAQmain.cc
+// Description : Base class for Module to receive data from outside and store it to DataStore
+//
+// Author : Satoru Yamada Itoh, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+//#include <daq/rawdata/modules/DAQConsts.h>
+#include "des_ser_ROPC_main.h"
+//#include <daq/rawdata/modules/DesSerPrePC.h>
+//#include <daq/rawdata/DesSerPrePC.h>
+#include <daq/rawdata/DesSerPrePC.h>
+//#define MAXEVTSIZE 400000000
+
+using namespace std;
+using namespace Belle2;
+
+
+//-----------------------------------------------------------------
+//                 Implementation
+//-----------------------------------------------------------------
+
+int main(int argc, char** argv)
+{
+
+  if (argc != 5) {
+
+    printf("[FATAL] Usage : %s <COPPER hostname> <Use NSM(Network Shared Memory)? yes=1/no=0> <port # to eb0> <NSM nodename>", argv[0]);
+    ;
+    exit(1);
+  }
+
+  string host_recv = argv[1];     //! hostname
+  int shmflag = atoi(argv[2]);      //! Use shared memory -> 1; Without shm -> 0
+  int port_send = atoi(argv[3]);      //! port number
+  string nodename = argv[4];    //! Node name
+
+  string host_send = "0.0.0.0";    //! hostname
+  int port_recv = 30000;    //! port number
+  int nodeid = 0;
+  DesSerPrePC des_ser_prepc(host_recv, port_recv,
+                            host_send, port_send, shmflag,
+                            nodename, nodeid);
+  des_ser_prepc.DataAcquisition();
+
+
+}
+
+
diff --git a/ROPCApplications/daq/ropc/des_ser_ROPC_main.h b/ROPCApplications/daq/ropc/des_ser_ROPC_main.h
new file mode 100644
index 0000000000000000000000000000000000000000..77fda6db80ad8bfe07c74e12570dad7f15fb5c86
--- /dev/null
+++ b/ROPCApplications/daq/ropc/des_ser_ROPC_main.h
@@ -0,0 +1,106 @@
+//+
+// File : des_ser_prePC_main.h
+// Description : Base class for Module to receive data from outside and store it to DataStore
+//
+// Author : Satoru Yamada Itoh, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef DES_SER_PREPC_MAIN_H
+#define DES_SER_PREPC_MAIN_H
+
+#include <string>
+#include <vector>
+#include <stdlib.h>
+/* #include <sys/time.h> */
+
+/* #include <framework/core/Module.h> */
+/* #include <framework/pcore/EvtMessage.h> */
+/* #include <framework/pcore/MsgHandler.h> */
+/* #include <framework/datastore/DataStore.h> */
+/* #include <framework/datastore/StoreObjPtr.h> */
+/* #include <framework/datastore/StoreArray.h> */
+/* #include <framework/dataobjects/EventMetaData.h> */
+
+/* #include <daq/dataflow/EvtSocket.h> */
+/* #include <daq/slc/readout/RunInfoBuffer.h> */
+/* #include <daq/rawdata/CprErrorMessage.h> */
+/* #include <daq/rawdata/modules/DAQConsts.h> */
+
+
+/* #include <rawdata/dataobjects/RawDataBlock.h> */
+//#include <rawdata/dataobjects/RawCOPPER.h>
+
+/* #include <sys/socket.h> */
+/* #include <sys/types.h> */
+/* #include <arpa/inet.h> */
+/* #include <netinet/in.h> */
+/* #include <netinet/tcp.h> */
+
+/* #include <sys/mman.h> */
+/* #include <sys/stat.h> */
+/* #include <fcntl.h> */
+
+/* using namespace std; */
+/* using namespace Belle2; */
+
+/* namespace Belle2 { */
+
+/*   /\*! A class definition of an input module for Sequential ROOT I/O *\/ */
+
+/*   class des_ser_prePC_main{ */
+
+/*     // Public functions */
+/*   public: */
+
+/*     //! Constructor / Destructor */
+/*     des_ser_prePC_mainModule(); */
+/*     virtual ~des_ser_prePC_mainModule(); */
+
+/*     //! Module functions to be called from main process */
+/*     virtual void initialize(); */
+
+/*     //! Module functions to be called from main process */
+/*     virtual void event(); */
+
+/*   protected : */
+/*     //! hostname */
+/*     string m_host_recv; */
+
+/*     //! hostname */
+/*     string m_host_send; */
+
+/*     //! port number */
+/*     int m_port_recv; */
+
+/*     //! port number */
+/*     int m_port_send; */
+
+/*     //! Messaage handler */
+/*     MsgHandler* m_msghandler; */
+
+/*     //! Compression Level */
+/*     int m_compressionLevel; */
+
+/*     //! Node(PC or COPPER) ID */
+/*     int m_nodeid; */
+
+/*     //! Node name */
+/*     std::string m_nodename; */
+
+/*     //! Use shared memory -> 1; Without shm -> 0 */
+/*     int m_shmflag; */
+
+/*     // Event Meta Data */
+/*     StoreObjPtr<EventMetaData> m_eventMetaDataPtr; */
+
+/*   private: */
+
+
+/*   public: */
+
+/*   }; */
+
+/* } // end namespace Belle2 */
+
+#endif // MODULEHELLO_H
diff --git a/ROPCApplications/daq/ropc/scripts/chage_all.sh b/ROPCApplications/daq/ropc/scripts/chage_all.sh
new file mode 100755
index 0000000000000000000000000000000000000000..e6875c2e9d817e5a0aa2e297f5b47aa6122201c7
--- /dev/null
+++ b/ROPCApplications/daq/ropc/scripts/chage_all.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+ssh -XY klm03 'chage b2daq -E -1'
+ssh -XY klm04 'chage b2daq -E -1'
+#ssh -XY svd05 'chage b2daq -E -1'
+#ssh -XY svd06 'chage b2daq -E -1'
+#ssh -XY cdc06 'chage b2daq -E -1'
+#ssh -XY top03 'chage b2daq -E -1'
+#ssh -XY top04 'chage b2daq -E -1'
+#ssh -XY arich02 'chage b2daq -E -1'
+#ssh -XY ecl02 'chage b2daq -E -1'
+#ssh -XY ecl03 'chage b2daq -E -1'
+#ssh -XY ecl05 'chage b2daq -E -1'
+#ssh -XY ecl06 'chage b2daq -E -1'
+
+
+
+
diff --git a/ROPCApplications/daq/ropc/scripts/check_FFSTA_all.sh b/ROPCApplications/daq/ropc/scripts/check_FFSTA_all.sh
new file mode 100755
index 0000000000000000000000000000000000000000..87bbb7bde7395e13803807751fd5f61323cbf74a
--- /dev/null
+++ b/ROPCApplications/daq/ropc/scripts/check_FFSTA_all.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+ssh -XY cpr5001 ~/bin/check_FFSTA.sh
+ssh -XY cpr5002 ~/bin/check_FFSTA.sh
+ssh -XY cpr5003 ~/bin/check_FFSTA.sh
+ssh -XY cpr5004 ~/bin/check_FFSTA.sh
+ssh -XY cpr5005 ~/bin/check_FFSTA.sh
+ssh -XY cpr5006 ~/bin/check_FFSTA.sh
+ssh -XY cpr5007 ~/bin/check_FFSTA.sh
+ssh -XY cpr5008 ~/bin/check_FFSTA.sh
+ssh -XY cpr5009 ~/bin/check_FFSTA.sh
+ssh -XY cpr5010 ~/bin/check_FFSTA.sh
+ssh -XY cpr5011 ~/bin/check_FFSTA.sh
+ssh -XY cpr5012 ~/bin/check_FFSTA.sh
+ssh -XY cpr5013 ~/bin/check_FFSTA.sh
diff --git a/ROPCApplications/daq/ropc/scripts/check_all.sh b/ROPCApplications/daq/ropc/scripts/check_all.sh
new file mode 100755
index 0000000000000000000000000000000000000000..aa2c78b4dd8ad76bf87b42731a5a48dcc5dd5c1e
--- /dev/null
+++ b/ROPCApplications/daq/ropc/scripts/check_all.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+ssh -XY svd01 $1
+ssh -XY svd02 $1
+ssh -XY svd03 $1
+ssh -XY svd04 $1
+ssh -XY svd05 $1
+ssh -XY svd06 $1
+ssh -XY svd07 $1
+ssh -XY svd08 $1
+ssh -XY svd09 $1
+ssh -XY svd10 $1
+ssh -XY svd11 $1
+
+ssh -XY cdc01 $1
+ssh -XY cdc02 $1
+ssh -XY cdc03 $1
+ssh -XY cdc04 $1
+ssh -XY cdc05 $1
+ssh -XY cdc06 $1
+ssh -XY cdc07 $1
+ssh -XY cdc08 $1
+ssh -XY cdc09 $1
+ssh -XY cdc10 $1
+
+ssh -XY top01 $1
+ssh -XY top02 $1
+ssh -XY top03 $1
+ssh -XY top04 $1
+
+ssh -XY arich01 $1
+ssh -XY arich02 $1
+ssh -XY arich03 $1
+
+ssh -XY ecl01 $1
+ssh -XY ecl02 $1
+ssh -XY ecl03 $1
+ssh -XY ecl04 $1
+ssh -XY ecl05 $1
+ssh -XY ecl06 $1
+ssh -XY ecl07 $1
+
+ssh -XY klm01 $1
+ssh -XY klm02 $1
+ssh -XY klm03 $1
+ssh -XY klm04 $1
+
diff --git a/ROPCApplications/daq/ropc/scripts/copy_etcfiles.sh b/ROPCApplications/daq/ropc/scripts/copy_etcfiles.sh
new file mode 100755
index 0000000000000000000000000000000000000000..1ca888ddeacecec2f255fb7376b01877848c820a
--- /dev/null
+++ b/ROPCApplications/daq/ropc/scripts/copy_etcfiles.sh
@@ -0,0 +1,142 @@
+#!/bin/sh
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@klm03:/etc
+scp /etc/openldap/ldap.conf root@klm03:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@klm03:/etc/pam.d
+
+exit
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@svd01:/etc
+scp /etc/openldap/ldap.conf root@svd01:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@svd01:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@svd03:/etc
+scp /etc/openldap/ldap.conf root@svd03:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@svd03:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@svd08:/etc
+scp /etc/openldap/ldap.conf root@svd08:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@svd08:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@arich01:/etc
+scp /etc/openldap/ldap.conf root@arich01:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@arich01:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@arich03:/etc
+scp /etc/openldap/ldap.conf root@arich03:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@arich03:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@ecl07:/etc
+scp /etc/openldap/ldap.conf root@ecl07:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@ecl07:/etc/pam.d
+
+
+exit
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@svd02:/etc
+scp /etc/openldap/ldap.conf root@svd02:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@svd02:/etc/pam.d
+
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@svd03:/etc
+scp /etc/openldap/ldap.conf root@svd03:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@svd03:/etc/pam.d
+
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@cdc01:/etc
+scp /etc/openldap/ldap.conf root@cdc01:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@cdc01:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@cdc02:/etc
+scp /etc/openldap/ldap.conf root@cdc02:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@cdc02:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@cdc03:/etc
+scp /etc/openldap/ldap.conf root@cdc03:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@cdc03:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@cdc05:/etc
+scp /etc/openldap/ldap.conf root@cdc05:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@cdc05:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@cdc07:/etc
+scp /etc/openldap/ldap.conf root@cdc07:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@cdc07:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@cdc08:/etc
+scp /etc/openldap/ldap.conf root@cdc08:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@cdc08:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@cdc09:/etc
+scp /etc/openldap/ldap.conf root@cdc09:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@cdc09:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@cdc10:/etc
+scp /etc/openldap/ldap.conf root@cdc10:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@cdc10:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@top02:/etc
+scp /etc/openldap/ldap.conf root@top02:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@top02:/etc/pam.d
+
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@klm02:/etc
+scp /etc/openldap/ldap.conf root@klm02:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@klm02:/etc/pam.d
+
+exit
+
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@top01:/etc
+scp /etc/openldap/ldap.conf root@top01:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@top01:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@svd04:/etc
+scp /etc/openldap/ldap.conf root@svd04:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@svd04:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@svd05:/etc
+scp /etc/openldap/ldap.conf root@svd05:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@svd05:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@svd06:/etc
+scp /etc/openldap/ldap.conf root@svd06:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@svd06:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@cdc04:/etc
+scp /etc/openldap/ldap.conf root@cdc04:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@cdc04:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@cdc06:/etc
+scp /etc/openldap/ldap.conf root@cdc06:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@cdc06:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@top03:/etc
+scp /etc/openldap/ldap.conf root@top03:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@top03:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@top04:/etc
+scp /etc/openldap/ldap.conf root@top04:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@top04:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@arich02:/etc
+scp /etc/openldap/ldap.conf root@arich02:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@arich02:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@ecl02:/etc
+scp /etc/openldap/ldap.conf root@ecl02:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@ecl02:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@ecl03:/etc
+scp /etc/openldap/ldap.conf root@ecl03:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@ecl03:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@ecl05:/etc
+scp /etc/openldap/ldap.conf root@ecl05:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@ecl05:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@ecl06:/etc
+scp /etc/openldap/ldap.conf root@ecl06:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@ecl06:/etc/pam.d
+
+scp /etc/resolv.conf /etc/exports /etc/rc.local /etc/ntp.conf /etc/yum.conf /etc/ldap.conf /etc/nsswitch.conf root@klm03:/etc
+scp /etc/openldap/ldap.conf root@klm03:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@klm03:/etc/pam.d
diff --git a/ROPCApplications/daq/ropc/scripts/copy_ldap_files.sh b/ROPCApplications/daq/ropc/scripts/copy_ldap_files.sh
new file mode 100755
index 0000000000000000000000000000000000000000..e51b909e48d6d05ba5b1c8543b1ffb7b8d82c6d7
--- /dev/null
+++ b/ROPCApplications/daq/ropc/scripts/copy_ldap_files.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+scp /etc/ldap.conf root@klm02:/etc
+scp /etc/openldap/ldap.conf root@klm02:/etc/openldap
+scp /etc/pam.d/system-auth-ac root@klm02:/etc/pam.d
+scp /etc/nsswitch.conf root@klm02:/etc
diff --git a/ROPCApplications/daq/ropc/scripts/copy_pub_all.sh b/ROPCApplications/daq/ropc/scripts/copy_pub_all.sh
new file mode 100755
index 0000000000000000000000000000000000000000..7139d11be1b7c5ee3737d9da2fe006ab30aa6477
--- /dev/null
+++ b/ROPCApplications/daq/ropc/scripts/copy_pub_all.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+scp ~/.ssh/id_rsa.pub svd01:~/; ssh svd01 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub svd02:~/; ssh svd02 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub svd03:~/; ssh svd03 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub svd04:~/; ssh svd04 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub svd05:~/; ssh svd05 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub svd06:~/; ssh svd06 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub svd07:~/; ssh svd07 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub svd08:~/; ssh svd08 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub svd09:~/; ssh svd09 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub svd10:~/; ssh svd10 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub svd11:~/; ssh svd11 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub cdc01:~/; ssh cdc01 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub cdc02:~/; ssh cdc02 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub cdc03:~/; ssh cdc03 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub cdc04:~/; ssh cdc04 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub cdc05:~/; ssh cdc05 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub cdc06:~/; ssh cdc06 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub cdc07:~/; ssh cdc07 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub cdc08:~/; ssh cdc08 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub cdc09:~/; ssh cdc09 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub cdc10:~/; ssh cdc10 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+
+#scp ~/.ssh/id_rsa.pub top01:~/; ssh top01 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub top02:~/; ssh top02 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub top03:~/; ssh top03 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub top04:~/; ssh top04 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+
+scp ~/.ssh/id_rsa.pub arich01:~/; ssh arich01 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub arich02:~/; ssh arich02 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub arich03:~/; ssh arich03 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub arich04:~/; ssh arich04 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+
+
+scp ~/.ssh/id_rsa.pub ecl01:~/; ssh ecl01 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub ecl02:~/; ssh ecl02 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub ecl03:~/; ssh ecl03 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub ecl04:~/; ssh ecl04 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub ecl05:~/; ssh ecl05 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub ecl06:~/; ssh ecl06 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub ecl07:~/; ssh ecl07 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+
+scp ~/.ssh/id_rsa.pub klm01:~/; ssh klm01 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub klm02:~/; ssh klm02 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub klm03:~/; ssh klm03 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub klm04:~/; ssh klm04 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+
+
diff --git a/ROPCApplications/daq/ropc/scripts/copy_pub_all2.sh b/ROPCApplications/daq/ropc/scripts/copy_pub_all2.sh
new file mode 100755
index 0000000000000000000000000000000000000000..c1fdb48abaf6c6019e9325a4e999232d8bc04177
--- /dev/null
+++ b/ROPCApplications/daq/ropc/scripts/copy_pub_all2.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+scp ~/.ssh/id_rsa.pub klm03:~/; ssh klm03 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+
+exit
+scp ~/.ssh/id_rsa.pub svd01:~/; ssh svd01 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub svd02:~/; ssh svd02 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub svd03:~/; ssh svd03 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub svd04:~/; ssh svd04 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub svd05:~/; ssh svd05 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub svd06:~/; ssh svd06 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub svd07:~/; ssh svd07 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub svd08:~/; ssh svd08 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub svd09:~/; ssh svd09 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub svd10:~/; ssh svd10 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub svd11:~/; ssh svd11 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub cdc01:~/; ssh cdc01 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub cdc02:~/; ssh cdc02 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub cdc03:~/; ssh cdc03 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub cdc04:~/; ssh cdc04 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub cdc05:~/; ssh cdc05 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub cdc06:~/; ssh cdc06 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub cdc07:~/; ssh cdc07 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub cdc08:~/; ssh cdc08 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub cdc09:~/; ssh cdc09 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub cdc10:~/; ssh cdc10 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+
+#scp ~/.ssh/id_rsa.pub top01:~/; ssh top01 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub top02:~/; ssh top02 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub top03:~/; ssh top03 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub top04:~/; ssh top04 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+
+scp ~/.ssh/id_rsa.pub arich01:~/; ssh arich01 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub arich02:~/; ssh arich02 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub arich03:~/; ssh arich03 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub arich04:~/; ssh arich04 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+
+
+#scp ~/.ssh/id_rsa.pub ecl01:~/; ssh ecl01 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub ecl02:~/; ssh ecl02 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub ecl03:~/; ssh ecl03 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub ecl04:~/; ssh ecl04 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub ecl05:~/; ssh ecl05 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub ecl06:~/; ssh ecl06 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+scp ~/.ssh/id_rsa.pub ecl07:~/; ssh ecl07 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+
+#scp ~/.ssh/id_rsa.pub klm01:~/; ssh klm01 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub klm02:~/; ssh klm02 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub klm03:~/; ssh klm03 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+#scp ~/.ssh/id_rsa.pub klm04:~/; ssh klm04 'ssh 172.22.16.4; cat ~/id_rsa.pub > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys;'
+
+
diff --git a/ROPCApplications/daq/ropc/scripts/dist_src.sh b/ROPCApplications/daq/ropc/scripts/dist_src.sh
new file mode 100755
index 0000000000000000000000000000000000000000..5f78eebf2d79772b64e1f79e19dace0a1ce21f8b
--- /dev/null
+++ b/ROPCApplications/daq/ropc/scripts/dist_src.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+#ssh -n -n -XY root@svd04 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y  install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+#ssh -n -n -XY root@svd05  " passwd yamadas;"
+#ssh -n -n -XY root@svd06  " passwd yamadas;"
+#ssh -n -n -XY root@cdc04  " passwd yamadas;"
+#ssh -n -n -XY root@cdc06  " passwd yamadas;"
+#ssh -n -n -XY root@top03  " passwd yamadas;"
+#ssh -n -n -XY root@top04  " passwd yamadas;"
+#ssh -n -n -XY root@arich02  " passwd yamadas;"
+#ssh -n -n -XY root@ecl02  " passwd yamadas;"
+#ssh -n -n -XY root@ecl03  " passwd yamadas;"
+#ssh -n -n -XY root@ecl05  " passwd yamadas;"
+#ssh -n -n -XY root@ecl06  " passwd yamadas;"
+#ssh -n -n -XY root@klm03  " passwd yamadas;"
+
+
+#ssh -n -n -XY root@svd01 "mkdir /home/usr; useradd -m -d /home/usr/yamadas -u 14252 yamadas; useradd -m -d /home/usr/b2daq -u 3001 b2daq;"
+#ssh -n -n -XY root@svd03 "mkdir /home/usr; useradd -m -d /home/usr/yamadas -u 14252 yamadas; useradd -m -d /home/usr/b2daq -u 3001 b2daq;"
+#ssh -n -n -XY root@svd08 "mkdir /home/usr; useradd -m -d /home/usr/yamadas -u 14252 yamadas; useradd -m -d /home/usr/b2daq -u 3001 b2daq;"
+#ssh -n -n -XY root@arich01 "mkdir /home/usr; useradd -m -d /home/usr/yamadas -u 14252 yamadas; useradd -m -d /home/usr/b2daq -u 3001 b2daq;"
+#ssh -n -n -XY root@ecl07 "mkdir /home/usr; useradd -m -d /home/usr/yamadas -u 14252 yamadas; useradd -m -d /home/usr/b2daq -u 3001 b2daq;"
+
+ssh -n -n -XY svd02 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY svd03 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY svd04 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY svd05 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY svd06 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY svd07 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY svd08 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+
+ssh -n -n -XY cdc01 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY cdc02 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY cdc03 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY cdc04 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY cdc05 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY cdc06 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY cdc07 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY cdc08 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY cdc09 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY cdc10 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+
+ssh -n -n -XY top01 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY top02 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY top03 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY top04 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+
+ssh -n -n -XY arich01 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY arich02 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+
+
+ssh -n -n -XY ecl01 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY ecl02 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY ecl03 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY ecl04 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY ecl05 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY ecl06 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+
+ssh -n -n -XY klm01 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY klm02 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY klm03 "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
+ssh -n -n -XY ecl07  "echo \${HOSTNAME}; cd ~/basf2/release/daq/rawdata/src; svn update; g++ -o dummy_data_src dummy_data_src.cc;"
diff --git a/ROPCApplications/daq/ropc/scripts/dummy_start_all.sh b/ROPCApplications/daq/ropc/scripts/dummy_start_all.sh
new file mode 100755
index 0000000000000000000000000000000000000000..458cf1a6d4d7a8b12dc455ee21805bbf758f4bc9
--- /dev/null
+++ b/ROPCApplications/daq/ropc/scripts/dummy_start_all.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+#
+# For KLM, CDC, ECL COPPERs slot A,B
+#
+#    print 'Usage : RecvSendCOPPER.py <COPPER hostname> <COPPER node ID> <bit flag of FINNESEs> <Use NSM(Network Shared Memory)? yes=1/no=0> <NSM nodename>'
+# bit flag of FINESSE
+# slot a : 1, slot b : 2, slot c : 4, slot d : 8
+# e.g. slot abcd -> bitflag=15, slot bd -> bit flag=10
+
+# SVD
+/usr/bin/xterm -fn 7x14 -geometry 40x7+30+30 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh svd01 0x01000001 9001 115 6 1;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+30+150 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh svd02 0x01000007 9001 115 6 1;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+30+270 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh svd03 0x0100000d 9001 115 6 1;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+30+390 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh svd04 0x01000013 9001 115 6 1;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+30+510 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh svd05 0x01000019 9001 115 6 1;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+30+630 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh svd06 0x0100001f 9001 115 6 1;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+340+30 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh svd07 0x01000025 9001 115 6 1;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+340+150 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh svd08 0x0100002b 9001 115 6 1;" &
+#CDC
+/usr/bin/xterm -fn 7x14 -geometry 40x7+340+270 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh cdc01 0x02000001 9001 10 9 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+340+390 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh cdc02 0x0200000a 9001 10 9 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+340+510 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh cdc03 0x02000013 9001 10 9 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+340+630 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh cdc04 0x0200001c 9001 10 8 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+180+30 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh cdc05 0x02000022 9001 10 8 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+180+150 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh cdc06 0x02000028 9001 10 8 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+180+270 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh cdc07 0x0200002e 9001 10 8 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+180+390 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh cdc08 0x02000036 9001 10 8 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+180+510 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh cdc09 0x0200003c 9001 10 8 4;" &
+#TOP
+/usr/bin/xterm -fn 7x14 -geometry 40x7+180+630 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh top01 0x03000001 9001 13 4 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+790+30 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh top02 0x03000005 9001 13 4 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+790+150 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh top03 0x03000009 9001 13 4 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+790+270 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh top04 0x0300000d 9001 13 4 4;" &
+#ARICH
+/usr/bin/xterm -fn 7x14 -geometry 40x7+790+390 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh arich01 0x04000001 9001 12 7 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+790+510 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh arich02 0x04000008 9001 12 7 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+790+630 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh   cdc10 0x0400000f 9001 12 6 4;" &
+#ECL
+/usr/bin/xterm -fn 7x14 -geometry 40x7+655+30 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh ecl01 0x05000001 9001 58 5 2;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+655+150 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh ecl02 0x05000006 9001 58 4 2;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+655+270 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh ecl03 0x0500000a 9001 58 4 2;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+655+390 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh ecl04 0x0500000e 9001 58 5 2;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+655+510 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh ecl05 0x06000001 9001 58 4 2;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+655+630 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh ecl06 0x06000005 9001 58 4 2;" &
+#KLM
+/usr/bin/xterm -fn 7x14 -geometry 40x7+50+100 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh klm01 0x07000001 9001 21 3 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+50+220 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh klm02 0x07000004 9001 21 3 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+50+370 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh klm03 0x08000001 9001 10 5 4;" &
+/usr/bin/xterm -fn 7x14 -geometry 40x7+50+490 -e "/home/usr/yamadas/basf2/release/daq/rawdata/src/dummy_start.sh ecl07 0x08000006 9001 10 4 4;" &
+
+
diff --git a/ROPCApplications/daq/ropc/scripts/kill_dummy_all.sh b/ROPCApplications/daq/ropc/scripts/kill_dummy_all.sh
new file mode 100755
index 0000000000000000000000000000000000000000..28df6ed98727c64733adafeb5c95d60f9babc91e
--- /dev/null
+++ b/ROPCApplications/daq/ropc/scripts/kill_dummy_all.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+#
+# For KLM, CDC, ECL COPPERs slot A,B
+#
+#    print 'Usage : RecvSendCOPPER.py <COPPER hostname> <COPPER node ID> <bit flag of FINNESEs> <Use NSM(Network Shared Memory)? yes=1/no=0> <NSM nodename>'
+# bit flag of FINESSE
+# slot a : 1, slot b : 2, slot c : 4, slot d : 8
+# e.g. slot abcd -> bitflag=15, slot bd -> bit flag=10
+
+ssh svd01 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh svd02 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh svd03 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh svd04 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh svd05 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh svd06 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh svd07 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh svd08 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+
+ssh cdc01 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh cdc02 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh cdc03 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh cdc04 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh cdc05 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh cdc06 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh cdc07 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh cdc08 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh cdc09 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh cdc10 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+
+ssh top01 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh top02 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh top03 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh top04 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+
+ssh arich01 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh arich02 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+
+ssh ecl01 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh ecl02 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh ecl03 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh ecl04 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh ecl05 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh ecl06 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh ecl07 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+
+ssh klm01 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh klm02 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+ssh klm03 "echo \$HOSTNAME;pgrep dummy_data_src | xargs kill -KILL";
+
diff --git a/ROPCApplications/daq/ropc/scripts/make_user_all.sh b/ROPCApplications/daq/ropc/scripts/make_user_all.sh
new file mode 100755
index 0000000000000000000000000000000000000000..76b9fa0906cead5bb3bfad92a6088f00e5f00634
--- /dev/null
+++ b/ROPCApplications/daq/ropc/scripts/make_user_all.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+#ssh -n -n -XY root@svd04 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y  install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+#ssh -n -n -XY root@svd05  " passwd yamadas;"
+#ssh -n -n -XY root@svd06  " passwd yamadas;"
+#ssh -n -n -XY root@cdc04  " passwd yamadas;"
+#ssh -n -n -XY root@cdc06  " passwd yamadas;"
+#ssh -n -n -XY root@top03  " passwd yamadas;"
+#ssh -n -n -XY root@top04  " passwd yamadas;"
+#ssh -n -n -XY root@arich02  " passwd yamadas;"
+#ssh -n -n -XY root@ecl02  " passwd yamadas;"
+#ssh -n -n -XY root@ecl03  " passwd yamadas;"
+#ssh -n -n -XY root@ecl05  " passwd yamadas;"
+#ssh -n -n -XY root@ecl06  " passwd yamadas;"
+#ssh -n -n -XY root@klm03  " passwd yamadas;"
+
+
+#ssh -n -n -XY root@svd01 "mkdir /home/usr; useradd -m -d /home/usr/yamadas -u 14252 yamadas; useradd -m -d /home/usr/b2daq -u 3001 b2daq;"
+#ssh -n -n -XY root@svd03 "mkdir /home/usr; useradd -m -d /home/usr/yamadas -u 14252 yamadas; useradd -m -d /home/usr/b2daq -u 3001 b2daq;"
+#ssh -n -n -XY root@svd08 "mkdir /home/usr; useradd -m -d /home/usr/yamadas -u 14252 yamadas; useradd -m -d /home/usr/b2daq -u 3001 b2daq;"
+#ssh -n -n -XY root@arich01 "mkdir /home/usr; useradd -m -d /home/usr/yamadas -u 14252 yamadas; useradd -m -d /home/usr/b2daq -u 3001 b2daq;"
+#ssh -n -n -XY root@ecl07 "mkdir /home/usr; useradd -m -d /home/usr/yamadas -u 14252 yamadas; useradd -m -d /home/usr/b2daq -u 3001 b2daq;"
+
+ssh -n -n -XY root@svd01 "mkdir /home/usr/yamadas; mkdir /home/usr/b2daq; cd /home/usr; chmod a+rx *;"
+ssh -n -n -XY root@svd03 "mkdir /home/usr/yamadas; mkdir /home/usr/b2daq; cd /home/usr; chmod a+rx *;"
+ssh -n -n -XY root@svd08 "mkdir /home/usr/yamadas; mkdir /home/usr/b2daq; cd /home/usr; chmod a+rx *;"
+ssh -n -n -XY root@arich01 "mkdir /home/usr/yamadas; mkdir /home/usr/b2daq; cd /home/usr; chmod a+rx *;"
+ssh -n -n -XY root@ecl07 "mkdir /home/usr/yamadas; mkdir /home/usr/b2daq; cd /home/usr; chmod a+rx *;"
diff --git a/ROPCApplications/daq/ropc/scripts/rsync_all.sh b/ROPCApplications/daq/ropc/scripts/rsync_all.sh
new file mode 100755
index 0000000000000000000000000000000000000000..eacba548258495e1cbb59b03886ca7672d24b684
--- /dev/null
+++ b/ROPCApplications/daq/ropc/scripts/rsync_all.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+ssh -n -n -XY root@svd04 "rsync -a rsync://172.22.19.61/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@svd05 "rsync -a rsync://172.22.19.61/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@svd06 "rsync -a rsync://172.22.19.61/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@cdc04 "rsync -a rsync://172.22.19.61/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@cdc06 "rsync -a rsync://172.22.19.61/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@top03 "rsync -a rsync://172.22.19.61/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@top04 "rsync -a rsync://172.22.19.61/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@arich02 "rsync -a rsync://172.22.19.61/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@ecl02 "rsync -a rsync://172.22.19.61/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@ecl03 "rsync -a rsync://172.22.19.61/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@ecl05 "rsync -a rsync://172.22.19.61/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@ecl06 "rsync -a rsync://172.22.19.61/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@klm03 "rsync -a rsync://172.22.19.61/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+
diff --git a/ROPCApplications/daq/ropc/scripts/rsync_home_all.sh b/ROPCApplications/daq/ropc/scripts/rsync_home_all.sh
new file mode 100755
index 0000000000000000000000000000000000000000..722f6ed89422e21d6f5a6ef4ec00f78577f38332
--- /dev/null
+++ b/ROPCApplications/daq/ropc/scripts/rsync_home_all.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+ssh -n -n -XY root@svd04 "rsync -avtpog rsync://172.22.19.41/export/home/usr/b2daq /home/usr;rsync -avtpog rsync://172.22.19.41/export/home/usr/yamadas /home/usr"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@svd05 "rsync -avtpog rsync://172.22.19.41/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@svd06 "rsync -avtpog rsync://172.22.19.41/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@cdc04 "rsync -avtpog rsync://172.22.19.41/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@cdc06 "rsync -avtpog rsync://172.22.19.41/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@top03 "rsync -avtpog rsync://172.22.19.41/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@top04 "rsync -avtpog rsync://172.22.19.41/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@arich02 "rsync -avtpog rsync://172.22.19.41/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@ecl02 "rsync -avtpog rsync://172.22.19.41/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@ecl03 "rsync -avtpog rsync://172.22.19.41/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@ecl05 "rsync -avtpog rsync://172.22.19.41/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@ecl06 "rsync -avtpog rsync://172.22.19.41/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+ssh -n -n -XY root@klm03 "rsync -avtpog rsync://172.22.19.41/export/tftpboot /"
+echo "HIT ANY KEY"; read TEMP;
+
diff --git a/ROPCApplications/daq/ropc/scripts/service_start_all.sh b/ROPCApplications/daq/ropc/scripts/service_start_all.sh
new file mode 100755
index 0000000000000000000000000000000000000000..8ebdeba0e813a32ccf6cce4260626073cd9a5ec6
--- /dev/null
+++ b/ROPCApplications/daq/ropc/scripts/service_start_all.sh
@@ -0,0 +1,64 @@
+#!/bin/sh
+ssh -n -n -XY root@klm03 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+exit
+ssh -n -n -XY root@svd01 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+ssh -n -n -XY root@svd03 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+ssh -n -n -XY root@svd08 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+ssh -n -n -XY root@arich01 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+ssh -n -n -XY root@ecl07 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+
+exit
+
+ssh -n -n -XY root@svd02 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+ssh -n -n -XY root@svd03 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+ssh -n -n -XY root@cdc01 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+ssh -n -n -XY root@cdc02 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+ssh -n -n -XY root@cdc03 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+ssh -n -n -XY root@cdc05 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+ssh -n -n -XY root@cdc07 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+ssh -n -n -XY root@cdc08 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+ssh -n -n -XY root@cdc09 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+ssh -n -n -XY root@cdc10 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+ssh -n -n -XY root@top02 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+ssh -n -n -XY root@klm02 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+
+exit
+
+ssh -n -n -XY root@svd05 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on; /sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+ssh -n -n -XY root@svd06 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on; /sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+ssh -n -n -XY root@cdc04 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;
+/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+ssh -n -n -XY root@cdc06 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;
+/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+ssh -n -n -XY root@top03 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;
+/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+ssh -n -n -XY root@top04 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;
+/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+ssh -n -n -XY root@arich02 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;
+/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+ssh -n -n -XY root@ecl02 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;
+/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+ssh -n -n -XY root@ecl03 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;
+/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+ssh -n -n -XY root@ecl05 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;
+/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+ssh -n -n -XY root@ecl06 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
+
+ssh -n -n -XY root@klm03 "http_proxy=http://b2stone.daqnet.kek.jp:8080/; https_proxy=http://b2stone.daqnet.kek.jp:8080/; ftp_proxy=http://b2stone.daqnet.kek.jp:8080/; export http_proxy https_proxy ftp_proxy; yum -y install emacs ; yum -y install openldap-clients ; /sbin/chkconfig ntpd on;
+/sbin/chkconfig tftp on; /sbin/chkconfig nfs on; /sbin/service ntpd restart; /sbin/service xinetd restart;"
diff --git a/ROPCApplications/daq/slc/base/include/AbstractDBObject.h b/ROPCApplications/daq/slc/base/include/AbstractDBObject.h
new file mode 100644
index 0000000000000000000000000000000000000000..e9ad217c60e5ef92b7bdafa0ed02efeeadbdfc2f
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/include/AbstractDBObject.h
@@ -0,0 +1,212 @@
+#ifndef _Belle2_AbstractDBObject_hh
+#define _Belle2_AbstractDBObject_hh
+
+#include <daq/slc/base/FieldProperty.h>
+
+#include <daq/slc/base/Serializable.h>
+
+#include <string>
+#include <stdexcept>
+
+namespace Belle2 {
+
+
+  class AbstractDBObject : public Serializable {
+
+  public:
+    AbstractDBObject();
+    AbstractDBObject(const AbstractDBObject& obj);
+    virtual ~AbstractDBObject();
+
+  public:
+    const std::string& getPath() const { return m_path; }
+    void setPath(const std::string& path) { m_path = path; }
+    int getId() const { return m_id; }
+    void setId(int id) { m_id = id; }
+    const std::string& getName() const { return m_name; }
+    void setName(const std::string& name) { m_name = name; }
+    int getIndex() const { return m_index; }
+    void setIndex(int index) { m_index = index; }
+    DBField::NameList& getFieldNames() { return m_name_v; }
+    const DBField::NameList& getFieldNames() const { return m_name_v; }
+    DBField::Property getProperty(const std::string& name) const;
+    bool hasField(const std::string& name) const;
+    bool hasValue(const std::string& name) const;
+    bool hasText(const std::string& name) const;
+    bool hasObject(const std::string& name) const;
+    void add(const std::string& name, DBField::Property pro);
+    void setValue(const std::string& name, const std::string& value);
+    void setText(const std::string& name, const std::string& value) { addText(name, value); }
+
+  public:
+    bool getBool(const std::string& name, int index = 0) const;
+    char getChar(const std::string& name, int index = 0) const;
+    short getShort(const std::string& name, int index = 0) const;
+    int getInt(const std::string& name, int index = 0) const;
+    long long getLong(const std::string& name, int index = 0) const;
+    float getFloat(const std::string& name, int index = 0) const;
+    double getDouble(const std::string& name, int index = 0) const;
+    void addBool(const std::string& name, bool value);
+    void addChar(const std::string& name, char value);
+    void addShort(const std::string& name, short value);
+    void addInt(const std::string& name, int value);
+    void addLong(const std::string& name, long long value);
+    void addFloat(const std::string& name, float value);
+    void addDouble(const std::string& name, double value);
+    void setBool(const std::string& name, bool value, int index = 0);
+    void setChar(const std::string& name, int value, int index = 0);
+    void setShort(const std::string& name, int value, int index = 0);
+    void setInt(const std::string& name, int value, int index = 0);
+    void setLong(const std::string& name, long long value, int index = 0);
+    void setFloat(const std::string& name, float value, int index = 0);
+    void setDouble(const std::string& name, double value, int index = 0);
+    const std::string getValueText(const std::string& name) const;
+
+  public:
+    virtual const void* getValue(const std::string& name) const = 0;
+    virtual const std::string& getText(const std::string& name) const = 0;
+    virtual void addText(const std::string& name, const std::string& value) = 0;
+    virtual void addValue(const std::string& name, const void* value,
+                          DBField::Type type, int length) = 0;
+    virtual void setValue(const std::string& name, const void* value, int index) = 0;
+    virtual void setValueText(const std::string& name, const std::string& value);
+
+  protected:
+    virtual void reset();
+
+  private:
+    int m_index;
+    std::string m_path;
+    int m_id;
+    std::string m_name;
+    DBField::NameList m_name_v;
+    DBField::PropertyList m_pro_m;
+
+  private:
+    template<typename T>
+    T getD(const std::string& name, int index = 0) const
+    {
+      const void* value = getValue(name);
+      if (value == NULL/* || index >= getProperty(name).getLength()*/) {
+        throw (std::out_of_range(name + " not found"));
+      }
+      DBField::Type type(getProperty(name).getType());
+      if (type == DBField::INT) return (T)(((int*)value)[index]);
+      if (type == DBField::FLOAT) return (T)(((float*)value)[index]);
+      if (type == DBField::DOUBLE) return (T)(((double*)value)[index]);
+      if (type == DBField::SHORT) return (T)(((short*)value)[index]);
+      if (type == DBField::CHAR) return (T)(((char*)value)[index]);
+      if (type == DBField::LONG) return (T)(((long*)value)[index]);
+      return ((T*)value)[index];
+    }
+
+  };
+
+  inline bool AbstractDBObject::getBool(const std::string& name, int index) const
+  {
+    return getD<bool>(name, index);
+  }
+
+  inline char AbstractDBObject::getChar(const std::string& name, int index) const
+  {
+    return getD<char>(name, index);
+  }
+
+  inline short AbstractDBObject::getShort(const std::string& name, int index) const
+  {
+    return getD<short>(name, index);
+  }
+
+  inline int AbstractDBObject::getInt(const std::string& name, int index) const
+  {
+    return getD<int>(name, index);
+  }
+
+  inline long long AbstractDBObject::getLong(const std::string& name, int index) const
+  {
+    return getD<long long>(name, index);
+  }
+
+  inline float AbstractDBObject::getFloat(const std::string& name, int index) const
+  {
+    return getD<float>(name, index);
+  }
+
+  inline double AbstractDBObject::getDouble(const std::string& name, int index) const
+  {
+    return getD<double>(name, index);
+  }
+
+  inline void AbstractDBObject::setBool(const std::string& name, bool value, int index)
+  {
+    setValue(name, &value, index);
+  }
+
+  inline void AbstractDBObject::setChar(const std::string& name, int value, int index)
+  {
+    setValue(name, &value, index);
+  }
+
+  inline void AbstractDBObject::setShort(const std::string& name, int value, int index)
+  {
+    setValue(name, &value, index);
+  }
+
+  inline void AbstractDBObject::setInt(const std::string& name, int value, int index)
+  {
+    setValue(name, &value, index);
+  }
+
+  inline void AbstractDBObject::setLong(const std::string& name, long long value, int index)
+  {
+    setValue(name, &value, index);
+  }
+
+  inline void AbstractDBObject::setFloat(const std::string& name, float value, int index)
+  {
+    setValue(name, &value, index);
+  }
+
+  inline void AbstractDBObject::setDouble(const std::string& name, double value, int index)
+  {
+    setValue(name, &value, index);
+  }
+
+  inline void AbstractDBObject::addBool(const std::string& name, bool value)
+  {
+    addValue(name, &value, DBField::BOOL, 0);
+  }
+
+  inline void AbstractDBObject::addChar(const std::string& name, char value)
+  {
+    addValue(name, &value, DBField::CHAR, 0);
+  }
+
+  inline void AbstractDBObject::addShort(const std::string& name, short value)
+  {
+    addValue(name, &value, DBField::SHORT, 0);
+  }
+
+  inline void AbstractDBObject::addInt(const std::string& name, int value)
+  {
+    addValue(name, &value, DBField::INT, 0);
+  }
+
+  inline void AbstractDBObject::addLong(const std::string& name, long long value)
+  {
+    addValue(name, &value, DBField::LONG, 0);
+  }
+
+  inline void AbstractDBObject::addFloat(const std::string& name, float value)
+  {
+    addValue(name, &value, DBField::FLOAT, 0);
+  }
+
+  inline void AbstractDBObject::addDouble(const std::string& name, double value)
+  {
+    addValue(name, &value, DBField::DOUBLE, 0);
+  }
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/base/include/ConfigFile.h b/ROPCApplications/daq/slc/base/include/ConfigFile.h
new file mode 100644
index 0000000000000000000000000000000000000000..aefac1af5f1f11514b973f3ea648ba4adc373770
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/include/ConfigFile.h
@@ -0,0 +1,75 @@
+#ifndef _Belle2_ConfigFile_h
+#define _Belle2_ConfigFile_h
+
+#include <string>
+#include <map>
+#include <vector>
+#include <istream>
+
+namespace Belle2 {
+
+  class ConfigFile {
+  public:
+    typedef std::map<std::string, std::string> ValueList;
+
+  public:
+    ConfigFile() {}
+    ConfigFile(const std::string& file1)
+    {
+      read(file1, true);
+    }
+    ConfigFile(const std::string& file1, const std::string& file2)
+    {
+      read(file1, true);
+      read(file2, true);
+    }
+    ConfigFile(const std::string& file1,
+               const std::string& file2,
+               const std::string& file3)
+    {
+      read(file1, true);
+      read(file2, true);
+      read(file3, true);
+    }
+    ConfigFile(std::istream& is)
+    {
+      read(is);
+    }
+    ~ConfigFile() {}
+
+  public:
+    void clear();
+    void read(const std::string& filename, bool overload = true);
+    void read(std::istream& is, bool overload = true);
+    bool hasKey(const std::string& label);
+    const std::string get(const std::string& label);
+    int getInt(const std::string& label);
+    bool getBool(const std::string& label);
+    double getFloat(const std::string& label);
+    ValueList& getValues() { return m_value_m; }
+    std::vector<std::string>& getLabels() { return m_label_v; }
+    void add(const std::string& label,
+             const std::string& value, bool overload);
+    void write(const std::string& path);
+    void print();
+
+  private:
+    const std::string getFilePath(const std::string& filename);
+
+  private:
+    ValueList m_value_m;
+    std::vector<std::string> m_label_v;
+    std::string m_dir;
+    std::map<std::string, int> m_count;
+
+  };
+
+  inline bool ConfigFile::hasKey(const std::string& label)
+  {
+    return m_value_m.find((m_dir.size() > 0) ? m_dir + "." + label : label)
+           != m_value_m.end();
+  }
+
+};
+
+#endif
diff --git a/ROPCApplications/daq/slc/base/include/Connection.h b/ROPCApplications/daq/slc/base/include/Connection.h
new file mode 100644
index 0000000000000000000000000000000000000000..9621aa61b6168144b407c97290730edf9c590e57
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/include/Connection.h
@@ -0,0 +1,46 @@
+#ifndef _Belle2_Connection_hh
+#define _Belle2_Connection_hh
+
+#include "daq/slc/base/Enum.h"
+
+namespace Belle2 {
+
+  class Connection : public Enum {
+
+  public:
+    static const Connection ONLINE;
+    static const Connection OFFLINE;
+
+  public:
+    Connection();
+    Connection(const Enum& st) ;
+    Connection(const Connection& st) ;
+    Connection(const std::string& st) { *this = st; }
+    Connection(int id) { *this = id; }
+    ~Connection() ;
+
+  private:
+    Connection(int id, const char* label);
+
+  public:
+    bool operator==(const Connection& st) const;
+    bool operator!=(const Connection& st) const;
+    const Connection& operator=(const std::string& msg);
+    const Connection& operator=(const char* msg);
+    const Connection& operator=(int i);
+
+  };
+
+  inline bool Connection::operator==(const Connection& st) const
+  {
+    return (getId() == st.getId());
+  }
+
+  inline bool Connection::operator!=(const Connection& st) const
+  {
+    return (getId() != st.getId());
+  }
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/base/include/Date.h b/ROPCApplications/daq/slc/base/include/Date.h
new file mode 100644
index 0000000000000000000000000000000000000000..978d002e691399746bd778e51c8534b4f0428338
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/include/Date.h
@@ -0,0 +1,44 @@
+#ifndef _Belle2_Date_hh
+#define _Belle2_Date_hh
+
+#include <time.h>
+
+namespace Belle2 {
+
+  class Date {
+
+  public:
+    Date(time_t time);
+    Date(const Date& date);
+    Date();
+    ~Date();
+
+  public:
+    void set();
+    void set(time_t time);
+    time_t get() const { return m_time; }
+    int getSecond() const;
+    int getMinitue() const;
+    int getHour() const;
+    int getDay() const;
+    int getMonth() const;
+    int getYear() const;
+    const char* toString(const char* format = NULL) const;
+
+  public:
+    const Date& operator=(const Date& date)
+    {
+      set(date.m_time);
+      return *this;
+    }
+
+  private:
+    time_t m_time;
+    struct tm* m_tm;
+    mutable char m_str[31];
+
+  };
+
+};
+
+#endif
diff --git a/ROPCApplications/daq/slc/base/include/ERRORNo.h b/ROPCApplications/daq/slc/base/include/ERRORNo.h
new file mode 100644
index 0000000000000000000000000000000000000000..9edfefeaba6549d6d8fd3042de374ce93f96a59b
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/include/ERRORNo.h
@@ -0,0 +1,39 @@
+#ifndef _Belle2_ERRORNo_hh
+#define _Belle2_ERRORNo_hh
+
+#include "daq/slc/base/Enum.h"
+
+namespace Belle2 {
+
+  class ERRORNo : public Enum {
+
+  public:
+    static const ERRORNo UNKNOWN;
+    static const ERRORNo NSMONLINE;
+    static const ERRORNo NSMSENDREQ;
+    static const ERRORNo NSMMEMOPEN;
+    static const ERRORNo NSMINIT;
+    static const ERRORNo DATABASE;
+
+  public:
+    ERRORNo() {}
+    ERRORNo(const Enum& e) : Enum(e) {}
+    ERRORNo(const ERRORNo& cmd) : Enum(cmd) {}
+    ERRORNo(const char* label) { *this = label; }
+    ERRORNo(int id) { *this = id; }
+    ~ERRORNo() {}
+
+  protected:
+    ERRORNo(int id, const char* label)
+      : Enum(id, label) {}
+
+  public:
+    const ERRORNo& operator=(const std::string& label);
+    const ERRORNo& operator=(const char* label);
+    const ERRORNo& operator=(int id);
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/base/include/Enum.h b/ROPCApplications/daq/slc/base/include/Enum.h
new file mode 100644
index 0000000000000000000000000000000000000000..dcd86ce1860e7ee2acbd99d3cf4db2df2863ff08
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/include/Enum.h
@@ -0,0 +1,67 @@
+#ifndef _Belle2_Enum_hh
+#define _Belle2_Enum_hh
+
+#include <string>
+
+namespace Belle2 {
+
+  class Enum {
+
+  public:
+    const static Enum UNKNOWN;
+
+  public:
+    ~Enum() {}
+
+  protected:
+    Enum(int id, const std::string& label)
+      : m_id(id), m_label(label) {}
+    Enum(const Enum& e) :
+      m_id(e.m_id), m_label(e.m_label) {}
+    Enum() : m_id(UNKNOWN.m_id),
+      m_label(UNKNOWN.m_label) {}
+
+  public:
+    int getId() const { return m_id; }
+    const char* getLabel() const { return m_label.c_str(); }
+    const std::string& getLabelString() const { return m_label; }
+
+  public:
+    bool operator==(const Enum& e) const;
+    bool operator!=(const Enum& e) const;
+    const Enum& operator=(const Enum& e);
+    bool operator==(const std::string& label) const;
+    bool operator!=(const std::string& label) const;
+
+  private:
+    int m_id;
+    std::string m_label;
+
+  };
+
+  inline bool Enum::operator==(const Enum& e) const
+  {
+    return (m_id == e.m_id);
+  }
+  inline bool Enum::operator!=(const Enum& e) const
+  {
+    return (m_id != e.m_id);
+  }
+  inline const Enum& Enum::operator=(const Enum& e)
+  {
+    m_id = e.m_id;
+    m_label = e.m_label;
+    return *this;
+  }
+  inline bool Enum::operator==(const std::string& label) const
+  {
+    return m_label == label;
+  }
+  inline bool Enum::operator!=(const std::string& label) const
+  {
+    return m_label != label;
+  }
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/base/include/Exception.h b/ROPCApplications/daq/slc/base/include/Exception.h
new file mode 100644
index 0000000000000000000000000000000000000000..8e72adfc1c457d4631980d4bc6f4728eeed45a46
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/include/Exception.h
@@ -0,0 +1,37 @@
+#ifndef _Belle2_Exception_hh
+#define _Belle2_Exception_hh
+
+#include <exception>
+#include <string>
+
+namespace Belle2 {
+
+  class Exception : public std::exception {
+
+  public:
+    Exception();
+    Exception(const std::string&);
+    Exception(const std::string&, int err);
+#if __GNUC__ >= 7
+    virtual ~Exception() {}
+#else
+    virtual ~Exception() throw() {}
+#endif
+
+  public:
+#if __GNUC__ >= 7
+    virtual const char* what() const noexcept;
+#else
+    virtual const char* what() const throw();
+#endif
+    int err() const { return m_err; }
+
+  protected:
+    std::string m_comment;
+    int m_err;
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/base/include/FieldProperty.h b/ROPCApplications/daq/slc/base/include/FieldProperty.h
new file mode 100644
index 0000000000000000000000000000000000000000..7ecb6afd358effe9766fe751f0d2b0613d3544c9
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/include/FieldProperty.h
@@ -0,0 +1,88 @@
+#ifndef _Belle2_FieldProperty_hh
+#define _Belle2_FieldProperty_hh
+
+#include <string>
+#include <map>
+#include <vector>
+
+namespace Belle2 {
+
+  namespace DBField {
+
+    enum Type {
+      UNKNOWN = 0,
+      BOOL = 1,
+      CHAR,
+      SHORT,
+      INT,
+      LONG,
+      FLOAT,
+      DOUBLE,
+      TEXT,
+      OBJECT
+    };
+
+    class Property {
+
+    public:
+      Property():  m_type(), m_length(0), m_offset(0) {}
+      Property(Type type, int length, int offset = 0)
+        : m_type(type), m_length(length), m_offset(offset) {}
+      Property(const Property& pro)
+        : m_type(pro.m_type), m_length(pro.m_length), m_offset(pro.m_offset) {}
+      ~Property() {}
+
+    public:
+      Type getType() const { return m_type; }
+      int getLength() const { return m_length; }
+      int getOffset() const { return m_offset; }
+      void setType(Type type) { m_type = type; }
+      void setLength(int length) { m_length = length; }
+
+      int getTypeSize() const
+      {
+        switch (m_type) {
+          case BOOL:   return sizeof(bool);
+          case CHAR:   return sizeof(char);
+          case SHORT:  return sizeof(short);
+          case INT:    return sizeof(int);
+          case LONG:   return sizeof(long long);
+          case FLOAT:  return sizeof(float);
+          case DOUBLE: return sizeof(double);
+          default: break;
+        }
+        return 0;
+      }
+
+      const std::string getTypeText() const
+      {
+        switch (m_type) {
+          case BOOL: return "bool";
+          case CHAR: return "char";
+          case SHORT: return "short";
+          case INT: return "int";
+          case LONG: return "long";
+          case FLOAT: return "float";
+          case DOUBLE: return "double";
+          case TEXT: return "text";
+          case OBJECT: return "object";
+          default: break;
+        }
+        return "";
+      }
+
+    private:
+      Type m_type;
+      int m_length;
+      int m_offset;
+
+    };
+
+    typedef std::vector<std::string> NameList;
+    typedef std::map<std::string, DBField::Property> PropertyList;
+
+  }
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/base/include/IOException.h b/ROPCApplications/daq/slc/base/include/IOException.h
new file mode 100644
index 0000000000000000000000000000000000000000..2204de3574931c407985f9f766c7cfb50fe9b623
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/include/IOException.h
@@ -0,0 +1,24 @@
+#ifndef _Belle2_IOException_hh
+#define _Belle2_IOException_hh
+
+#include "daq/slc/base/Exception.h"
+
+namespace Belle2 {
+
+  class IOException : public Exception {
+
+  public:
+    IOException() {}
+    IOException(const std::string& comment, ...);
+    IOException(int err, const std::string& comment, ...);
+#if __GNUC__ >= 7
+    virtual ~IOException() {}
+#else
+    virtual ~IOException() throw() {}
+#endif
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/base/include/Reader.h b/ROPCApplications/daq/slc/base/include/Reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..aa46197465ced965f7ad2331ca3cdd3d5cc8ba8c
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/include/Reader.h
@@ -0,0 +1,42 @@
+#ifndef _Belle2_Reader_hh
+#define _Belle2_Reader_hh
+
+#include <cstddef>
+#include <string>
+
+namespace Belle2 {
+
+  class Serializable;
+
+  class Reader {
+
+  public:
+    virtual ~Reader() {}
+
+  public:
+    virtual size_t read(void*, size_t) = 0;
+    virtual bool available() = 0;
+
+  protected:
+    void reverse(void* buf, size_t len);
+
+  public:
+    virtual bool readBool();
+    virtual char readChar();
+    virtual short readShort();
+    virtual int readInt();
+    virtual long long readLong();
+    virtual unsigned char readUChar();
+    virtual unsigned short readUShort();
+    virtual unsigned int readUInt();
+    virtual unsigned long long readULong();
+    virtual float readFloat();
+    virtual double readDouble();
+    virtual const std::string readString();
+    virtual void readObject(Serializable&);
+
+  };
+
+};
+
+#endif
diff --git a/ROPCApplications/daq/slc/base/include/Serializable.h b/ROPCApplications/daq/slc/base/include/Serializable.h
new file mode 100644
index 0000000000000000000000000000000000000000..c09c89767b141a21eebf622b8b5b04f97ccd2af8
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/include/Serializable.h
@@ -0,0 +1,22 @@
+#ifndef _Belle2_Serializable_hh
+#define _Belle2_Serializable_hh
+
+namespace Belle2 {
+
+  class Reader;
+  class Writer;
+
+  class Serializable {
+
+  public:
+    virtual ~Serializable() {}
+
+  public:
+    virtual void readObject(Reader&) = 0;
+    virtual void writeObject(Writer&) const = 0;
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/base/include/StringUtil.h b/ROPCApplications/daq/slc/base/include/StringUtil.h
new file mode 100644
index 0000000000000000000000000000000000000000..defe2ad24f03651f7f5830864944e10da788168e
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/include/StringUtil.h
@@ -0,0 +1,33 @@
+#ifndef _Belle2_StringUtil_hh
+#define _Belle2_StringUtil_hh
+
+#include <string>
+#include <vector>
+
+namespace Belle2 {
+
+  typedef std::vector<std::string> StringList;
+
+  struct StringUtil {
+
+    static StringList split(const std::string& str,
+                            const char type, size_t max = 0);
+    static std::string join(StringList str_v, const std::string& s,
+                            size_t start = 0, size_t end = 0);
+    static std::string replace(const std::string& source,
+                               const std::string& pattern,
+                               const std::string& placement);
+    static std::string form(const std::string& string, ...);
+    static std::string toupper(const std::string& str);
+    static std::string tolower(const std::string& str);
+    static int atoi(const std::string str);
+    static double atof(const std::string str);
+    static long long atoll(const std::string str);
+    static bool find(const std::string& s, const std::string& str);
+    static bool isdigit(const std::string& s);
+
+  };
+
+};
+
+#endif
diff --git a/ROPCApplications/daq/slc/base/include/TimeoutException.h b/ROPCApplications/daq/slc/base/include/TimeoutException.h
new file mode 100644
index 0000000000000000000000000000000000000000..27af658d3fd1d2c4dab025f0bceab9d5a4455e73
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/include/TimeoutException.h
@@ -0,0 +1,24 @@
+#ifndef _Belle2_TimeoutException_hh
+#define _Belle2_TimeoutException_hh
+
+#include "daq/slc/base/IOException.h"
+
+namespace Belle2 {
+
+  class TimeoutException : public IOException {
+
+  public:
+    TimeoutException() {}
+    TimeoutException(const std::string& comment, ...);
+    TimeoutException(int err, const std::string& comment, ...);
+#if __GNUC__ >= 7
+    ~TimeoutException() {}
+#else
+    ~TimeoutException() throw() {}
+#endif
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/base/include/Writer.h b/ROPCApplications/daq/slc/base/include/Writer.h
new file mode 100644
index 0000000000000000000000000000000000000000..3241ed7c937fc58d6103ff5fa9ebdc676e1a4fc8
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/include/Writer.h
@@ -0,0 +1,42 @@
+#ifndef _Belle2_Writer_hh
+#define _Belle2_Writer_hh
+
+#include <cstddef>
+#include <string>
+
+namespace Belle2 {
+
+  class Serializable;
+
+  class Writer {
+
+  public:
+    virtual ~Writer() {}
+
+  public:
+    virtual size_t write(const void*, size_t) = 0;
+    virtual bool available() = 0;
+
+  protected:
+    void reverse(void* buf, size_t len);
+
+  public:
+    virtual void writeBool(bool);
+    virtual void writeChar(char);
+    virtual void writeShort(short);
+    virtual void writeInt(int);
+    virtual void writeLong(long long);
+    virtual void writeUChar(unsigned char);
+    virtual void writeUShort(unsigned short);
+    virtual void writeUInt(unsigned int);
+    virtual void writeULong(unsigned long long);
+    virtual void writeFloat(float);
+    virtual void writeDouble(double);
+    virtual void writeString(const std::string&);
+    virtual void writeObject(const Serializable&);
+
+  };
+
+};
+
+#endif
diff --git a/ROPCApplications/daq/slc/base/src/AbstractDBObject.cc b/ROPCApplications/daq/slc/base/src/AbstractDBObject.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9de4ea108ac98530726f2e06f17286a64599ce3c
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/src/AbstractDBObject.cc
@@ -0,0 +1,128 @@
+#include "daq/slc/base/AbstractDBObject.h"
+
+#include <daq/slc/base/StringUtil.h>
+
+#include <cstdlib>
+
+using namespace Belle2;
+
+AbstractDBObject::AbstractDBObject() : m_index(0), m_path(), m_id(0)
+{
+
+}
+
+AbstractDBObject::AbstractDBObject(const AbstractDBObject& obj)
+  : m_index(obj.m_index), m_path(obj.m_path),
+    m_id(obj.m_id),
+    m_name(obj.m_name) {}
+
+AbstractDBObject::~AbstractDBObject()
+{
+  reset();
+}
+
+void AbstractDBObject::reset()
+{
+  m_path = "";
+  m_id = 0;
+  m_index = 0;
+  m_name_v = DBField::NameList();
+  m_pro_m = DBField::PropertyList();
+}
+
+DBField::Property AbstractDBObject::getProperty(const std::string& name) const
+{
+  DBField::PropertyList::const_iterator it = m_pro_m.find(name);
+  if (it != m_pro_m.end()) return it->second;
+  return DBField::Property();
+}
+
+bool AbstractDBObject::hasField(const std::string& name) const
+{
+  DBField::PropertyList::const_iterator it = m_pro_m.find(name);
+  return (it != m_pro_m.end());
+}
+
+bool AbstractDBObject::hasValue(const std::string& name) const
+{
+  DBField::PropertyList::const_iterator it = m_pro_m.find(name);
+  return hasField(name) &&
+         it->second.getType() != DBField::TEXT &&
+         it->second.getType() != DBField::OBJECT;
+}
+
+bool AbstractDBObject::hasText(const std::string& name) const
+{
+  DBField::PropertyList::const_iterator it = m_pro_m.find(name);
+  return hasField(name) && it->second.getType() == DBField::TEXT;
+}
+
+bool AbstractDBObject::hasObject(const std::string& name) const
+{
+  DBField::PropertyList::const_iterator it = m_pro_m.find(name);
+  return hasField(name) &&
+         it->second.getType() == DBField::OBJECT;
+}
+
+void AbstractDBObject::add(const std::string& name, DBField::Property pro)
+{
+  if (!hasField(name)) {
+    m_name_v.push_back(name);
+    m_pro_m.insert(DBField::PropertyList::value_type(name, pro));
+  }
+}
+
+const std::string AbstractDBObject::getValueText(const std::string& name)
+const
+{
+  if (hasField(name)) {
+    switch (getProperty(name).getType()) {
+      case DBField::BOOL:   return getBool(name) ? "true" : "false";
+      case DBField::CHAR:   return StringUtil::form("%d", (int)getChar(name));
+      case DBField::SHORT:  return StringUtil::form("%d", (int)getShort(name));
+      case DBField::INT:    return StringUtil::form("%d", (int)getInt(name));
+      case DBField::LONG:   return StringUtil::form("%ld", getLong(name));
+      case DBField::FLOAT:  return StringUtil::form("%f", getFloat(name));
+      case DBField::DOUBLE: return StringUtil::form("%f", getDouble(name));
+      case DBField::TEXT:   return getText(name);
+      default: break;
+    }
+  }
+  throw (std::out_of_range(name + " not found"));
+}
+
+void AbstractDBObject::setValueText(const std::string& name,
+                                    const std::string& value)
+{
+  if (hasField(name)) {
+    switch (getProperty(name).getType()) {
+      case DBField::BOOL:       setBool(name, value == "true" || value == "t"); break;
+      case DBField::CHAR: {
+        if (StringUtil::find(value, "0x"))
+          setChar(name, (char)strtol(value.c_str(), NULL, 0));
+        else
+          setChar(name, (char)atoi(value.c_str()));
+      } break;
+      case DBField::SHORT: {
+        if (StringUtil::find(value, "0x"))
+          setShort(name, (short)strtol(value.c_str(), NULL, 0));
+        else
+          setShort(name, (short)atoi(value.c_str()));
+      } break;
+      case DBField::INT: {
+        if (StringUtil::find(value, "0x"))
+          setInt(name, (int)strtol(value.c_str(), NULL, 0));
+        else
+          setInt(name, (int)atoi(value.c_str()));
+      } break;
+      case DBField::LONG:       setLong(name, (long long)atoi(value.c_str())); break;
+      case DBField::FLOAT:      setFloat(name, atof(value.c_str())); break;
+      case DBField::DOUBLE:     setDouble(name, atof(value.c_str())); break;
+      case DBField::TEXT:       setText(name, value); break;
+      default: break;
+    }
+    return;
+  }
+  throw (std::out_of_range(name + " not found"));
+}
+
diff --git a/ROPCApplications/daq/slc/base/src/ConfigFile.cc b/ROPCApplications/daq/slc/base/src/ConfigFile.cc
new file mode 100644
index 0000000000000000000000000000000000000000..11b6f85ddbe0bb435c444e17ed74948d6a4e5722
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/src/ConfigFile.cc
@@ -0,0 +1,208 @@
+#include "daq/slc/base/ConfigFile.h"
+
+#include "daq/slc/base/StringUtil.h"
+
+#include <cstdlib>
+#include <cstring>
+#include <fstream>
+#include <iostream>
+#include <sstream>
+
+using namespace Belle2;
+
+const std::string ConfigFile::getFilePath(const std::string& filename_in)
+{
+  std::string filename = filename_in;
+  if (filename == "slowcontrol") {
+    /*
+    char* hostname = getenv("HOSTNAME");
+    if (hostname != NULL && std::string(hostname).find("hlt") != std::string::npos) {
+      filename = "slowcontrol.hlt";
+    }
+    */
+    char* slcfile = getenv("BELLE2_SLC_FILE");
+    if (slcfile != NULL && strlen(slcfile) > 0) {
+      filename = slcfile;
+    }
+  }
+  std::string file_path;
+  if (filename.size() > std::string(".conf").size() + 1 &&
+      StringUtil::find(filename, ".conf")) {
+    return filename;
+  }
+  if (filename.at(0) != '/') {
+    char* path = getenv("BELLE2_DAQ_SLC");
+    if (path == NULL) {
+      path = getenv("BELLE2_LOCAL_DIR");
+      if (path == NULL) {
+        exit(1);
+      }
+      file_path = path;
+      file_path += "/daq/slc/";
+    } else {
+      file_path = path;
+    }
+    if (filename.find("/") == std::string::npos) {
+      file_path += "/data/config/" + filename + ".conf";
+    } else {
+      file_path += "/data/" + filename + ".conf";
+    }
+  } else {
+    file_path = filename;
+  }
+  return file_path;
+}
+
+void ConfigFile::read(const std::string& filename, bool overload)
+{
+  if (filename.size() == 0) return;
+  std::ifstream fin(getFilePath(filename).c_str());
+  read(fin, overload);
+  fin.close();
+}
+
+void ConfigFile::read(std::istream& is, bool overload)
+{
+  std::string s;
+  std::string dir = "";
+  while (is && getline(is, s)) {
+    if (s.size() == 0 || s.at(0) == '#') continue;
+    std::vector<std::string> str_v = StringUtil::split(s, ':');
+    if (str_v.size() >= 2) {
+      std::string label = StringUtil::replace(StringUtil::replace(str_v[0],
+                                                                  " ", ""), "\t", "");
+      if (label.find("[]") != std::string::npos) {
+        if (m_count.find(label) == m_count.end()) {
+          m_count.insert(std::pair<std::string, int>(label, 0));
+        }
+        std::string l = label;
+        label = StringUtil::replace(label, "[]", StringUtil::form("[%d]", m_count[l]));
+        m_count[l] = m_count[l] + 1;
+      }
+      if (str_v.size() > 2) {
+        for (size_t i = 2; i < str_v.size(); i++) {
+          str_v[1].append(":");
+          str_v[1].append(str_v[i]);
+        }
+      }
+      std::string value = "";
+      size_t i = 0;
+      std::stringstream ss;
+      for (; i < str_v[1].size(); i++) {
+        if (str_v[1].at(i) == '#' || str_v[1].at(i) == '\n') break;
+        if (str_v[1].at(i) == ' ' || str_v[1].at(i) == '\t') continue;
+        if (str_v[1].at(i) == '"') {
+          for (i++ ; i < str_v[1].size(); i++) {
+            if (str_v[1].at(i) == '"') break;
+            ss << str_v[1].at(i);
+          }
+          break;
+        }
+        if (str_v[1].at(i) == '$') {
+          i++;
+          if (str_v[1].at(i) == '{') {
+            for (i++ ; i < str_v[1].size(); i++) {
+              if (str_v[1].at(i) == '}') break;
+              ss << str_v[1].at(i);
+            }
+          }
+          std::string tmp = ss.str();
+          const char* env = getenv(tmp.c_str());
+          ss.str("");
+          if (env != NULL) {
+            ss << env;
+          } else if (m_value_m.find(tmp) != m_value_m.end()) {
+            ss << m_value_m[tmp];
+          }
+          continue;
+        }
+        ss << str_v[1].at(i);
+      }
+      add(label, ss.str(), overload);
+    }
+  }
+}
+
+void ConfigFile::clear()
+{
+  m_value_m.clear();
+}
+
+const std::string ConfigFile::get(const std::string& label)
+{
+  if (m_value_m.find(label) != m_value_m.end()) {
+    return m_value_m[label];
+  }
+  return "";
+}
+
+int ConfigFile::getInt(const std::string& label)
+{
+  std::string value = get(label);
+  if (value.size() > 0) return atoi(value.c_str());
+  else return 0;
+}
+
+bool ConfigFile::getBool(const std::string& label)
+{
+  std::string value = get(label);
+  if (value.size() > 0) return StringUtil::tolower(value) == "true";
+  else return false;
+}
+
+double ConfigFile::getFloat(const std::string& label)
+{
+  std::string value = get(label);
+  if (value.size() > 0) return atof(value.c_str());
+  else return 0;
+}
+
+void ConfigFile::add(const std::string& label,
+                     const std::string& value, bool overload)
+{
+  if (m_value_m.find(label) == m_value_m.end()) {
+    m_value_m.insert(ValueList::value_type(label, value));
+    m_label_v.push_back(label);
+  } else if (overload) {
+    m_value_m[label] = value;
+  }
+}
+
+void ConfigFile::write(const std::string& path)
+{
+  std::stringstream ss;
+  ss << "#" << std::endl
+     << "#" << std::endl
+     << "#" << std::endl
+     << "" << std::endl;
+  for (std::vector<std::string>::iterator it = m_label_v.begin();
+       it != m_label_v.end(); it++) {
+    std::string& label(*it);
+    std::string& value(m_value_m[label]);
+    ss << label << " : " << value << std::endl;
+  }
+  ss << "" << std::endl
+     << "#" << std::endl
+     << "#" << std::endl
+     << "#" << std::endl;
+  std::ofstream fout(getFilePath(path).c_str());
+  fout << ss.str();
+}
+
+void ConfigFile::print()
+{
+  std::cout << "#" << std::endl
+            << "#" << std::endl
+            << "#" << std::endl
+            << "" << std::endl;
+  for (std::vector<std::string>::iterator it = m_label_v.begin();
+       it != m_label_v.end(); it++) {
+    std::string& label(*it);
+    std::string& value(m_value_m[label]);
+    std::cout << label << " : " << value << std::endl;
+  }
+  std::cout << "" << std::endl
+            << "#" << std::endl
+            << "#" << std::endl
+            << "#" << std::endl;
+}
diff --git a/ROPCApplications/daq/slc/base/src/Connection.cc b/ROPCApplications/daq/slc/base/src/Connection.cc
new file mode 100644
index 0000000000000000000000000000000000000000..73dd1e21687a091e18fe19be63b59eb0c27dfb26
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/src/Connection.cc
@@ -0,0 +1,58 @@
+#include "daq/slc/base/Connection.h"
+
+using namespace Belle2;
+
+const Connection Connection::ONLINE(10000, "ONLINE");
+const Connection Connection::OFFLINE(20000, "OFFLINE");
+
+Connection::Connection() : Enum()
+{
+
+}
+
+Connection::Connection(const Enum& st)
+  : Enum(st.getId(), st.getLabel())
+{
+
+}
+
+Connection::Connection(const Connection& st)
+  : Enum(st.getId(), st.getLabel())
+{
+
+}
+
+Connection::Connection(int id, const char* label)
+  : Enum(id, label)
+{
+
+}
+
+Connection::~Connection()
+{
+
+}
+
+const Connection& Connection::operator=(const std::string& msg)
+{
+  if (msg == ONLINE.getLabel()) *this = ONLINE;
+  else if (msg == OFFLINE.getLabel()) *this = OFFLINE;
+  else *this = UNKNOWN;
+  return *this;
+}
+
+const Connection& Connection::operator=(const char* msg)
+{
+  if (msg != NULL)  *this = std::string(msg);
+  else *this = UNKNOWN;
+  return *this;
+}
+
+const Connection& Connection::operator=(int i)
+{
+  if (i == ONLINE.getId()) *this = ONLINE;
+  else if (i == OFFLINE.getId()) *this = OFFLINE;
+  else *this = UNKNOWN;
+  return *this;
+}
+
diff --git a/ROPCApplications/daq/slc/base/src/Date.cc b/ROPCApplications/daq/slc/base/src/Date.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b76657c2f9a8643c746ae28420dfc2cc2694f265
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/src/Date.cc
@@ -0,0 +1,75 @@
+#include "daq/slc/base/Date.h"
+
+#include <cstring>
+
+using namespace Belle2;
+
+Date::Date(time_t time)
+{
+  set(time);
+}
+
+Date::Date(const Date& date)
+{
+  set(date.m_time);
+}
+
+Date::Date()
+{
+  set();
+}
+
+Date::~Date() {}
+
+void Date::set()
+{
+  m_time = time(NULL);
+  m_tm = localtime(&m_time);
+}
+
+void Date::set(time_t time)
+{
+  m_time = time;
+  m_tm = localtime(&m_time);
+}
+
+int Date::getSecond() const
+{
+  return m_tm->tm_sec;
+}
+
+int Date::getMinitue() const
+{
+  return m_tm->tm_min;
+}
+
+int Date::getHour() const
+{
+  return m_tm->tm_hour;
+}
+
+int Date::getDay() const
+{
+  return m_tm->tm_mday;
+}
+
+int Date::getMonth() const
+{
+  return m_tm->tm_mon + 1;
+}
+
+int Date::getYear() const
+{
+  return m_tm->tm_year + 1900;
+}
+
+const char* Date::toString(const char* format) const
+{
+  memset(m_str, 0, sizeof(m_str));
+  if (format == NULL) {
+    strftime(m_str, 31, "%Y-%m-%d %H:%M:%S", m_tm);
+  } else {
+    strftime(m_str, 31, format, m_tm);
+  }
+  return m_str;
+}
diff --git a/ROPCApplications/daq/slc/base/src/ERRORNo.cc b/ROPCApplications/daq/slc/base/src/ERRORNo.cc
new file mode 100644
index 0000000000000000000000000000000000000000..963cef5151dda2e32d99001211a6df595371b97b
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/src/ERRORNo.cc
@@ -0,0 +1,51 @@
+#include "daq/slc/base/ERRORNo.h"
+
+using namespace Belle2;
+
+const ERRORNo ERRORNo::UNKNOWN(0, "UNKNOWN");
+const ERRORNo ERRORNo::NSMONLINE(11, "NSMONLINE");
+const ERRORNo ERRORNo::NSMSENDREQ(12, "NSMSENDREQ");
+const ERRORNo ERRORNo::NSMMEMOPEN(13, "SENOPEN");
+const ERRORNo ERRORNo::NSMINIT(14, "NSMINIT");
+const ERRORNo ERRORNo::DATABASE(31, "DATABASE");
+
+const ERRORNo& ERRORNo::operator=(const std::string& label)
+{
+  if (label == NSMSENDREQ.getLabel()) {
+    return NSMSENDREQ;
+  } else if (label == NSMONLINE.getLabel()) {
+    return NSMONLINE;
+  } else if (label == NSMMEMOPEN.getLabel()) {
+    return NSMMEMOPEN;
+  } else if (label == NSMINIT.getLabel()) {
+    return NSMINIT;
+  } else if (label == DATABASE.getLabel()) {
+    return DATABASE;
+  } else {
+    return UNKNOWN;
+  }
+}
+
+const ERRORNo& ERRORNo::operator=(int id)
+{
+  if (id == NSMSENDREQ.getId()) {
+    return NSMSENDREQ;
+  } else if (id == NSMONLINE.getId()) {
+    return NSMONLINE;
+  } else if (id == NSMMEMOPEN.getId()) {
+    return NSMMEMOPEN;
+  } else if (id == NSMINIT.getId()) {
+    return NSMINIT;
+  } else if (id == DATABASE.getId()) {
+    return DATABASE;
+  }
+  return UNKNOWN;
+}
+
+const ERRORNo& ERRORNo::operator=(const char* label)
+{
+  if (label != NULL)  *this = std::string(label);
+  else *this = Enum::UNKNOWN;
+  return *this;
+}
+
diff --git a/ROPCApplications/daq/slc/base/src/Enum.cc b/ROPCApplications/daq/slc/base/src/Enum.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dc8962df990ae96660949ebd961726723fbce360
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/src/Enum.cc
@@ -0,0 +1,5 @@
+#include "daq/slc/base/Enum.h"
+
+using namespace Belle2;
+
+const Enum Enum::UNKNOWN(0, "UNKNOWN");
diff --git a/ROPCApplications/daq/slc/base/src/Exception.cc b/ROPCApplications/daq/slc/base/src/Exception.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e0b3078c9a5dae6d268fc7e7a02771ad417b441b
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/src/Exception.cc
@@ -0,0 +1,28 @@
+#include "daq/slc/base/Exception.h"
+
+using namespace Belle2;
+
+Exception::Exception()
+  : m_comment(""), m_err(0)
+{
+}
+
+Exception::Exception(const std::string& comment)
+  : m_comment(comment), m_err(0)
+{
+}
+
+Exception::Exception(const std::string& comment,
+                     int err)
+  : m_comment(comment), m_err(err)
+{
+}
+
+#if __GNUC__ >= 7
+const char* Exception::what() const noexcept
+#else
+const char* Exception::what() const throw()
+#endif
+{
+  return m_comment.c_str();
+}
diff --git a/ROPCApplications/daq/slc/base/src/IOException.cc b/ROPCApplications/daq/slc/base/src/IOException.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0921af40ec9d6530266f4f81b2bb8f7d48ce9557
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/src/IOException.cc
@@ -0,0 +1,28 @@
+#include "daq/slc/base/IOException.h"
+
+#include <cstdarg>
+#include <cstdio>
+
+using namespace Belle2;
+
+IOException::IOException(const std::string& format, ...)
+{
+  va_list ap;
+  char ss[1024 * 100];
+  va_start(ap, format);
+  vsprintf(ss, format.c_str(), ap);
+  va_end(ap);
+  m_comment = ss;
+}
+
+IOException::IOException(int err, const std::string& format, ...)
+{
+  m_err = err;
+  va_list ap;
+  char ss[1024 * 100];
+  va_start(ap, format);
+  vsprintf(ss, format.c_str(), ap);
+  va_end(ap);
+  m_comment = ss;
+}
+
diff --git a/ROPCApplications/daq/slc/base/src/Reader.cc b/ROPCApplications/daq/slc/base/src/Reader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..99ee127e3de6aa327ae70c7611e3a12b197c1ba8
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/src/Reader.cc
@@ -0,0 +1,139 @@
+#include "daq/slc/base/Reader.h"
+
+#include "daq/slc/base/Serializable.h"
+
+#include <unistd.h>
+
+#define __ENDIAN_L__
+
+using namespace Belle2;
+
+void Reader::reverse(void* buf, size_t len)
+{
+  char tmp;
+  for (int c = 0 ; c < (int)len / 2 ; c ++) {
+    tmp = *((char*)buf + c);
+    *((char*)buf + c) = *((char*)buf + len - 1 - c);
+    *((char*)buf + len - 1 - c) = tmp;
+  }
+}
+
+bool Reader::readBool()
+{
+  bool v;
+  read(&v, sizeof(bool));
+  return v;
+}
+
+char Reader::readChar()
+{
+  char v;
+  read(&v, sizeof(char));
+  return v;
+}
+
+unsigned char Reader::readUChar()
+{
+  unsigned char v;
+  read(&v, sizeof(unsigned char));
+  return v;
+}
+
+short Reader::readShort()
+{
+  short v;
+  read(&v, sizeof(short));
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(short));
+#endif
+  return v;
+}
+
+unsigned short Reader::readUShort()
+{
+  unsigned short v;
+  read(&v, sizeof(unsigned short));
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(unsigned short));
+#endif
+  return v;
+}
+
+int Reader::readInt()
+{
+  int v;
+  read(&v, sizeof(int));
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(int));
+#endif
+  return v;
+}
+
+unsigned int Reader::readUInt()
+{
+  unsigned int v;
+  read(&v, sizeof(unsigned int));
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(unsigned int));
+#endif
+  return v;
+}
+
+long long Reader::readLong()
+{
+  long long v;
+  read(&v, sizeof(long long));
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(long long));
+#endif
+  return v;
+}
+
+unsigned long long Reader::readULong()
+{
+  unsigned long long v;
+  read(&v, sizeof(unsigned long long));
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(unsigned long long));
+#endif
+  return v;
+}
+
+float Reader::readFloat()
+{
+  float v;
+  read(&v, sizeof(float));
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(float));
+#endif
+  return v;
+}
+
+double Reader::readDouble()
+{
+  double v;
+  read(&v, sizeof(double));
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(double));
+#endif
+  return v;
+}
+
+const std::string Reader::readString()
+{
+  int count = readInt();
+  char str[1025];
+  std::string v;
+  while (count > 0) {
+    int c = (count > 1024) ? 1024 : count;
+    read(str, c);
+    v.append(str, 0, c);
+    count -= c;
+  }
+  return v;
+}
+
+void Reader::readObject(Serializable& v)
+{
+  v.readObject(*this);
+}
diff --git a/ROPCApplications/daq/slc/base/src/StringUtil.cc b/ROPCApplications/daq/slc/base/src/StringUtil.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6f3f624d8badd3cafc92c07d5c17e19b1275ff5f
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/src/StringUtil.cc
@@ -0,0 +1,110 @@
+#include "daq/slc/base/StringUtil.h"
+
+#include <cstdarg>
+#include <cstdio>
+#include <sstream>
+#include <cctype>
+#include <algorithm>
+
+using namespace Belle2;
+
+StringList StringUtil::split(const std::string& str, const char type, size_t max)
+{
+  StringList str_v;
+  size_t current = 0, found;
+  while ((found = str.find_first_of(type, current)) != std::string::npos) {
+    str_v.push_back(std::string(str, current, found - current));
+    current = found + 1;
+  }
+  if (str.size() - current > 0) {
+    str_v.push_back(std::string(str, current, str.size() - current));
+  }
+  while (max > 0 && str_v.size() < max) {
+    str_v.push_back("");
+  }
+  return str_v;
+}
+
+std::string StringUtil::join(StringList str_v, const std::string& s, size_t start, size_t end)
+{
+  std::stringstream ss;
+  for (size_t i = start; i < str_v.size();) {
+    ss << str_v[i];
+    i++;
+    if ((end > 0 && i == end) || i == str_v.size()) break;
+    ss << s;
+  }
+  return ss.str();
+}
+
+std::string StringUtil::replace(const std::string& source,
+                                const std::string& pattern,
+                                const std::string& placement)
+{
+  std::string result;
+  std::string::size_type pos_before = 0;
+  std::string::size_type pos = 0;
+  std::string::size_type len = pattern.size();
+  while ((pos = source.find(pattern, pos)) != std::string::npos) {
+    result.append(source, pos_before, pos - pos_before);
+    result.append(placement);
+    pos += len;
+    pos_before = pos;
+  }
+  result.append(source, pos_before, source.size() - pos_before);
+  return result;
+}
+
+std::string StringUtil::form(const std::string& str, ...)
+{
+  va_list ap;
+  static char ss[1024 * 10];
+  va_start(ap, str);
+  vsprintf(ss, str.c_str(), ap);
+  va_end(ap);
+  return ss;
+}
+
+std::string StringUtil::toupper(const std::string& str)
+{
+  std::string s = str;
+  transform(s.begin(), s.end(), s.begin(), ::toupper);
+  return s;
+}
+
+std::string StringUtil::tolower(const std::string& str)
+{
+  std::string s = str;
+  transform(s.begin(), s.end(), s.begin(), ::tolower);
+  return s;
+}
+
+int StringUtil::atoi(const std::string str)
+{
+  return atoi(str.c_str());
+}
+
+double StringUtil::atof(const std::string str)
+{
+  return atof(str.c_str());
+}
+
+long long StringUtil::atoll(const std::string str)
+{
+  return atoll(str.c_str());
+}
+
+bool StringUtil::find(const std::string& s, const std::string& str)
+{
+  return s.find(str) != std::string::npos;
+}
+
+bool StringUtil::isdigit(const std::string& s)
+{
+  if (s.find("0x") == 0) return true;
+  for (size_t i = 0; i < s.size(); i++) {
+    if (i == 0 && s.at(0) == '-') continue;
+    if (!::isdigit(s.at(i))) return false;
+  }
+  return s.size() > 0 && s != "-";
+}
diff --git a/ROPCApplications/daq/slc/base/src/TimeoutException.cc b/ROPCApplications/daq/slc/base/src/TimeoutException.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d43516cfe13d5bae209397d8281c86789e54a675
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/src/TimeoutException.cc
@@ -0,0 +1,28 @@
+#include "daq/slc/base/TimeoutException.h"
+
+#include <cstdarg>
+#include <cstdio>
+
+using namespace Belle2;
+
+TimeoutException::TimeoutException(const std::string& format, ...)
+{
+  va_list ap;
+  char ss[1024 * 100];
+  va_start(ap, format);
+  vsprintf(ss, format.c_str(), ap);
+  va_end(ap);
+  m_comment = ss;
+}
+
+TimeoutException::TimeoutException(int err, const std::string& format, ...)
+{
+  m_err = err;
+  va_list ap;
+  char ss[1024 * 100];
+  va_start(ap, format);
+  vsprintf(ss, format.c_str(), ap);
+  va_end(ap);
+  m_comment = ss;
+}
+
diff --git a/ROPCApplications/daq/slc/base/src/Writer.cc b/ROPCApplications/daq/slc/base/src/Writer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d764e6d9fba331406df1c635f49b87f29e3a6aab
--- /dev/null
+++ b/ROPCApplications/daq/slc/base/src/Writer.cc
@@ -0,0 +1,109 @@
+#include "daq/slc/base/Writer.h"
+
+#include "daq/slc/base/Serializable.h"
+
+#include <unistd.h>
+
+#define __ENDIAN_L__
+
+using namespace Belle2;
+
+void Writer::reverse(void* buf, size_t len)
+{
+  char tmp;
+  for (int c = 0 ; c < (int)len / 2 ; c ++) {
+    tmp = *((char*)buf + c);
+    *((char*)buf + c) = *((char*)buf + len - 1 - c);
+    *((char*)buf + len - 1 - c) = tmp;
+  }
+}
+
+void Writer::writeBool(bool v)
+{
+  write(&v, sizeof(bool));
+}
+
+void Writer::writeChar(char v)
+{
+  write(&v, sizeof(char));
+}
+
+void Writer::writeUChar(unsigned char v)
+{
+  write(&v, sizeof(unsigned char));
+}
+
+void Writer::writeShort(short v)
+{
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(short));
+#endif
+  write(&v, sizeof(short));
+}
+
+void Writer::writeUShort(unsigned short v)
+{
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(unsigned short));
+#endif
+  write(&v, sizeof(unsigned short));
+}
+
+void Writer::writeInt(int v)
+{
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(int));
+#endif
+  write(&v, sizeof(int));
+}
+
+void Writer::writeUInt(unsigned int v)
+{
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(unsigned int));
+#endif
+  write(&v, sizeof(unsigned int));
+}
+
+void Writer::writeLong(long long v)
+{
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(long long));
+#endif
+  write(&v, sizeof(long long));
+}
+
+void Writer::writeULong(unsigned long long v)
+{
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(unsigned long long));
+#endif
+  write(&v, sizeof(unsigned long long));
+}
+
+void Writer::writeFloat(float v)
+{
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(float));
+#endif
+  write(&v, sizeof(float));
+}
+
+void Writer::writeDouble(double v)
+{
+#if defined(__ENDIAN_L__)
+  reverse(&v, sizeof(double));
+#endif
+  write(&v, sizeof(double));
+}
+
+void Writer::writeString(const std::string& v)
+{
+  writeInt((int)v.size());
+  write(v.data(), v.size());
+}
+
+void Writer::writeObject(const Serializable& v)
+{
+  return v.writeObject(*this);
+}
diff --git a/ROPCApplications/daq/slc/readout/include/FlowMonitor.h b/ROPCApplications/daq/slc/readout/include/FlowMonitor.h
new file mode 100644
index 0000000000000000000000000000000000000000..9663de6c87355d188842df6711d88f6e311d807b
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/include/FlowMonitor.h
@@ -0,0 +1,43 @@
+#ifndef _Belle2_FlowMonitor_h
+#define _Belle2_FlowMonitor_h
+
+#include <daq/slc/readout/RunInfoBuffer.h>
+#include <daq/slc/readout/IOInfo.h>
+#include <daq/slc/readout/ronode_status.h>
+
+namespace Belle2 {
+
+  class FlowMonitor {
+
+  public:
+    FlowMonitor()
+    {
+      m_ioinfo.push_back(IOInfo());
+      m_ioinfo.push_back(IOInfo());
+      m_info = NULL;
+      m_status.connection_in = 0;
+      m_status.connection_out = 0;
+    }
+    ~FlowMonitor() {}
+
+  public:
+    bool open(RunInfoBuffer* m_info);
+    bool close();
+    ronode_status& monitor();
+    const ronode_status& getStatus() const { return m_status; }
+    ronode_status& getStatus() { return m_status; }
+    bool isAvailable() const { return m_info != NULL; }
+
+  private:
+    std::string m_nodename;
+    RunInfoBuffer* m_info;
+    std::vector<IOInfo> m_ioinfo;
+    std::string m_ip[2];
+    unsigned long long m_nbyte[2];
+    ronode_status m_status;
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/readout/include/IOInfo.h b/ROPCApplications/daq/slc/readout/include/IOInfo.h
new file mode 100644
index 0000000000000000000000000000000000000000..0c1e2f7728e2d24db4a1a1ee956868c640b8ce91
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/include/IOInfo.h
@@ -0,0 +1,48 @@
+#ifndef _Belle2_IOInfo_h
+#define _Belle2_IOInfo_h
+
+#include <vector>
+
+namespace Belle2 {
+
+  class IOInfo {
+  public:
+    static int checkTCP(std::vector<IOInfo>& info);
+    static int checkTCP(IOInfo& info);
+
+  public:
+    IOInfo() {}
+    ~IOInfo() {}
+
+  public:
+    const char* getLocalIP() const;
+    unsigned int getLocalAddress() const { return m_local_addr; }
+    int getLocalPort() const { return m_local_port; }
+    const char* getRemoteIP() const;
+    unsigned int getRemoteAddress() const { return m_remote_addr; }
+    int getRemotePort() const { return m_remote_port; }
+    int getState() const { return m_state; }
+    int getTXQueue() const { return m_tx_queue; }
+    int getRXQueue() const { return m_rx_queue; }
+    void setLocalAddress(unsigned int addr) { m_local_addr = addr; }
+    void setLocalPort(int port) { m_local_port = port; }
+    void setRemoteAddress(unsigned int addr) { m_remote_addr = addr; }
+    void setRemotePort(int port) { m_remote_port = port; }
+    void setState(int state) { m_state = state; }
+    void setTXQueue(int queue) { m_tx_queue = queue; }
+    void setRXQueue(int queue) { m_rx_queue = queue; }
+
+  private:
+    unsigned int m_local_addr;
+    int m_local_port;
+    unsigned int m_remote_addr;
+    int m_remote_port;
+    int m_state;
+    int m_tx_queue;
+    int m_rx_queue;
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/readout/include/LogListener.h b/ROPCApplications/daq/slc/readout/include/LogListener.h
new file mode 100644
index 0000000000000000000000000000000000000000..0afac538dc532ae2feb3af74a6e8c506bc27241d
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/include/LogListener.h
@@ -0,0 +1,31 @@
+#ifndef _Belle2_LogListener_hh
+#define _Belle2_LogListener_hh
+
+namespace Belle2 {
+
+  class ProcessController;
+
+  class LogListener {
+
+  public:
+    LogListener(ProcessController* con, int pipe[2])
+      : m_con(con)
+    {
+      m_pipe[0] = pipe[0];
+      m_pipe[1] = pipe[1];
+    }
+    ~LogListener() {}
+
+  public:
+    void run();
+
+  private:
+    ProcessController* m_con;
+    int m_pipe[2];
+
+  };
+
+}
+
+#endif
+
diff --git a/ROPCApplications/daq/slc/readout/include/ProcessController.h b/ROPCApplications/daq/slc/readout/include/ProcessController.h
new file mode 100644
index 0000000000000000000000000000000000000000..e0449174e7d11fcbbf0189bbb88b42e30241b347
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/include/ProcessController.h
@@ -0,0 +1,110 @@
+#ifndef _Belle2_ProcessController_h
+#define _Belle2_ProcessController_h
+
+#include "daq/slc/readout/RunInfoBuffer.h"
+
+#include "daq/slc/runcontrol/RCCallback.h"
+
+#include "daq/slc/system/PThread.h"
+#include "daq/slc/system/Process.h"
+#include "daq/slc/system/Mutex.h"
+
+#include <vector>
+#include <sstream>
+
+namespace Belle2 {
+
+  class ProcessController {
+
+    friend class ProcessSubmitter;
+
+  public:
+    ProcessController()
+    {
+      m_callback = NULL;
+    }
+    ProcessController(RCCallback* callback)
+    {
+      m_callback = callback;
+    }
+    ~ProcessController()
+    {
+      m_info.close();
+    }
+
+  public:
+    bool init(const std::string& parname, int nodeid = 0);
+    void clear();
+    bool load(int timeout);
+    bool start(int expno, int runno);
+    bool pause();
+    bool resume();
+    bool stop();
+    bool abort();
+    const std::string& getName() { return m_name; }
+    const std::string& getParName() { return m_parname; }
+    const std::string& getExecutable() { return m_exename; }
+    RunInfoBuffer& getInfo() { return m_info; }
+    RCCallback* getCallback() { return m_callback; }
+    const Process& getProcess() const { return  m_process; }
+    Process& getProcess() { return  m_process; }
+    void setCallback(RCCallback* callback) { m_callback = callback; }
+    void setName(const std::string& name) { m_name = name; }
+    void setExecutable(const std::string& exe) { m_exename = exe; }
+    void addArgument(const std::string& arg) { m_arg_v.push_back(arg); }
+    void addArgument(const char* format, ...);
+    template<typename T>
+    void addArgument(T arg);
+    void clearArguments() { m_arg_v = std::vector<std::string>(); }
+    bool isAlive() { return m_process.isAlive(); }
+    bool waitReady(int timeout);
+
+  public:
+    void lock() { m_mutex.lock(); }
+    void unlock() { m_mutex.unlock(); }
+
+  private:
+    RunInfoBuffer m_info;
+    std::string m_name;
+    std::string m_parname;
+    RCCallback* m_callback;
+    std::string m_exename;
+    std::vector<std::string> m_arg_v;
+    Process m_process;
+    Mutex m_mutex;
+    std::string m_message;
+    PThread m_th_log;
+    PThread m_th_process;
+    int m_iopipe[2];
+
+  };
+
+  template<typename T>
+  inline void ProcessController::addArgument(T arg)
+  {
+    std::stringstream ss; ss << arg;
+    m_arg_v.push_back(ss.str());
+  }
+
+  class ProcessSubmitter {
+
+  public:
+    ProcessSubmitter(ProcessController* con, int iopipe[2])
+      : m_con(con)
+    {
+      m_iopipe[0] = iopipe[0];
+      m_iopipe[1] = iopipe[1];
+    }
+
+  public:
+    void run();
+
+  private:
+    ProcessController* m_con;
+    int m_iopipe[2];
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/readout/include/ProcessListener.h b/ROPCApplications/daq/slc/readout/include/ProcessListener.h
new file mode 100644
index 0000000000000000000000000000000000000000..caae09c66a0f3d19f8d1e426ada7144094e852cf
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/include/ProcessListener.h
@@ -0,0 +1,26 @@
+#ifndef _Belle2_ProcessListener_hh
+#define _Belle2_ProcessListener_hh
+
+namespace Belle2 {
+
+  class ProcessController;
+
+  class ProcessListener {
+
+  public:
+    ProcessListener(ProcessController* con)
+      : m_con(con) {}
+    ~ProcessListener() {}
+
+  public:
+    void run();
+
+  private:
+    ProcessController* m_con;
+
+  };
+
+}
+
+#endif
+
diff --git a/ROPCApplications/daq/slc/readout/include/RunInfoBuffer.h b/ROPCApplications/daq/slc/readout/include/RunInfoBuffer.h
new file mode 100644
index 0000000000000000000000000000000000000000..5359fd950869ba1b0b8ca8e5e68081575e31c111
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/include/RunInfoBuffer.h
@@ -0,0 +1,122 @@
+#ifndef _Belle2_RunInfoBuffer_h
+#define _Belle2_RunInfoBuffer_h
+
+#include "daq/slc/system/SharedMemory.h"
+#include "daq/slc/system/MMutex.h"
+#include "daq/slc/system/MCond.h"
+#include "daq/slc/readout/ronode_info.h"
+
+namespace Belle2 {
+
+  class RunInfoBuffer {
+
+  public:
+    enum State {
+      NOTREADY = 0,
+      READY = 1,
+      RUNNING = 2,
+      PAUSING = 3,
+      PAUSED = 4,
+      RESUMING = 5
+    };
+
+  public:
+    enum EFlag {
+      NOERRO,
+      PROCESS_DOWN = 0x01,
+      SOCKET_BIND = 0x02,
+      SOCKET_IN = 0x04,
+      SOCKET_OUT = 0x08,
+      EVENTFORMAT = 0x10,
+      CPRFIFO_EMPTY = 0x20,
+      CPRFIFO_FULL = 0x40,
+      CPRFIFO_LEF_FULL = 0x80
+    };
+
+  public:
+    RunInfoBuffer()
+    {
+      m_info = NULL;
+    }
+    ~RunInfoBuffer() {}
+
+  public:
+    size_t size() ;
+    bool open(const std::string& nodename,
+              int nodeid = 0, bool recreate = false);
+    bool init();
+    bool close();
+    bool unlink();
+    bool lock() ;
+    bool unlock() ;
+    bool wait() ;
+    bool wait(int time) ;
+    bool notify() ;
+    void clear();
+
+  public:
+    const std::string getName() const  { return m_nodename; }
+    const std::string getPath() const  { return m_path; }
+    bool isAvailable() const  { return m_info != NULL; }
+    ronode_info* get()  { return m_info; }
+    unsigned int getNodeId() const  { return m_info->nodeid; }
+    unsigned int getState() const  { return m_info->state; }
+    unsigned int getErrorFlag() const  { return m_info->eflag; }
+    unsigned int getExpNumber() const  { return m_info->expno; }
+    unsigned int getRunNumber() const  { return m_info->runno; }
+    unsigned int getSubNumber() const  { return m_info->subno; }
+    int getInputPort() const  { return m_info->io[0].port; }
+    int getInputAddress() const  { return m_info->io[0].addr; }
+    unsigned int getInputCount() const  { return m_info->io[0].count; }
+    unsigned long long getInputNBytes() const  { return m_info->io[0].nbyte; }
+    int getOutputPort() const  { return m_info->io[1].port; }
+    int getOutputAddress() const  { return m_info->io[1].addr; }
+    unsigned int getOutputCount() const  { return m_info->io[1].count; }
+    unsigned long long getOutputNBytes() const  { return m_info->io[1].nbyte; }
+    void setNodeId(unsigned int id) { m_info->nodeid = id; }
+    void setState(State state) { m_info->state = (unsigned int)state; }
+    void setErrorFlag(EFlag eflag) { m_info->eflag = (unsigned int)eflag; }
+    void setExpNumber(unsigned int expno) { m_info->expno = expno; }
+    void setRunNumber(unsigned int runno) { m_info->runno = runno; }
+    void setSubNumber(unsigned int subno) { m_info->subno = subno; }
+    void setInputPort(int port) { m_info->io[0].port = port; }
+    void setInputAddress(int addr) { m_info->io[0].addr = addr; }
+    void setInputCount(unsigned int count) { m_info->io[0].count = count; }
+    void setInputNBytes(unsigned long long nbyte) { m_info->io[0].nbyte = nbyte; }
+    void addInputCount(unsigned int count) { m_info->io[0].count += count; }
+    void addInputNBytes(unsigned long long nbyte) { m_info->io[0].nbyte += nbyte; }
+    void setOutputPort(int port) { m_info->io[1].port = port; }
+    void setOutputAddress(int addr) { m_info->io[1].addr = addr; }
+    void setOutputCount(unsigned int count) { m_info->io[1].count = count; }
+    void setOutputNBytes(unsigned long long nbyte) { m_info->io[1].nbyte = nbyte; }
+    void addOutputCount(unsigned int count) { m_info->io[1].count += count; }
+    void addOutputNBytes(unsigned long long nbyte) { m_info->io[1].nbyte += nbyte; }
+    event_header& getEventHeader() { return m_info->header; }
+    void copyEventHeader(int* buf);
+    bool isNotReady()  { return (m_info) && m_info->state == NOTREADY; }
+    bool isReady()  { return (m_info) && m_info->state == READY; }
+    bool isRunning()  { return (m_info) && m_info->state == RUNNING; }
+    bool isPausing()  { return (m_info) && m_info->state == PAUSING; }
+    bool isPaused()  { return (m_info) && m_info->state == PAUSED; }
+    bool isResuming()  { return (m_info) && m_info->state == RESUMING; }
+
+    bool waitRunning(int timeout);
+    bool waitReady(int timeout);
+    bool reportRunning();
+    bool reportError(EFlag eflag);
+    bool reportReady();
+    bool reportNotReady();
+
+  private:
+    std::string m_nodename;
+    std::string m_path;
+    SharedMemory m_memory;
+    ronode_info* m_info;
+    MMutex m_mutex;
+    MCond m_cond;
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/readout/include/mmap_statistics.h b/ROPCApplications/daq/slc/readout/include/mmap_statistics.h
new file mode 100644
index 0000000000000000000000000000000000000000..8764663abf740bbf717199861c42eab9e7b2fdbf
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/include/mmap_statistics.h
@@ -0,0 +1,96 @@
+#ifndef MMAP_STATISTICS_H
+#define MMAP_STATISTICS_H
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <assert.h>
+#include <stdint.h>
+#include <sys/mman.h>
+
+#ifndef O_NOATIME
+#define O_NOATIME 0
+#endif
+
+struct stream_statistics {
+  uint32_t addr;
+  uint32_t port;
+  uint64_t event;
+  uint64_t byte;
+  uint64_t total_byte;
+};
+
+class eb_statistics {
+private:
+  int m_n_u;
+  int m_n_d;
+  int m_fd_u;
+  int m_fd_d;
+  int m_len_u;
+  int m_len_d;
+  stream_statistics* m_stat_u;
+  stream_statistics* m_stat_d;
+
+public:
+  eb_statistics(const char* file_up, int nup, const char* file_down, int ndown)
+  {
+    m_n_u = nup;
+    m_n_d = ndown;
+
+    m_len_u = sizeof(stream_statistics) * m_n_u;
+    m_len_d = sizeof(stream_statistics) * m_n_d;
+
+    m_fd_u = open(file_up,   O_RDWR | O_CREAT | O_NOATIME, 0644);
+    assert(m_fd_u >= 0);
+    m_fd_d = open(file_down, O_RDWR | O_CREAT | O_NOATIME, 0644);
+    assert(m_fd_d >= 0);
+
+    stream_statistics buf_u[m_n_u];
+    stream_statistics buf_d[m_n_d];
+
+    memset(buf_u, 0, m_len_u);
+    memset(buf_d, 0, m_len_d);
+
+    int ret;
+
+    ret = write(m_fd_u, buf_u, m_len_u);
+    assert(ret == m_len_u);
+    ret = write(m_fd_d, buf_d, m_len_d);
+    assert(ret == m_len_d);
+
+    m_stat_u = (stream_statistics*)mmap(0, m_len_u, PROT_READ | PROT_WRITE, MAP_SHARED, m_fd_u, 0);
+    assert(m_stat_u != MAP_FAILED);
+    m_stat_d = (stream_statistics*)mmap(0, m_len_d, PROT_READ | PROT_WRITE, MAP_SHARED, m_fd_d, 0);
+    assert(m_stat_d != MAP_FAILED);
+  };
+
+  ~eb_statistics()
+  {
+    munmap(m_stat_u, m_len_u);
+    munmap(m_stat_d, m_len_d);
+    close(m_fd_u);
+    close(m_fd_d);
+  };
+
+  stream_statistics* up()
+  {
+    return m_stat_u;
+  };
+
+  stream_statistics& up(int i)
+  {
+    return m_stat_u[i];
+  };
+
+  stream_statistics* down()
+  {
+    return m_stat_d;
+  };
+
+  stream_statistics& down(int i)
+  {
+    return m_stat_d[i];
+  };
+};
+
+#endif
diff --git a/ROPCApplications/daq/slc/readout/include/mybuf.h b/ROPCApplications/daq/slc/readout/include/mybuf.h
new file mode 100644
index 0000000000000000000000000000000000000000..9de1446b8dd6362c4516ea924653ac304becfe2e
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/include/mybuf.h
@@ -0,0 +1,28 @@
+#ifndef mybuf_h
+#define mybuf_h
+
+const int mybuf_revision = 3;
+
+struct mybuf {
+  uint32 reserved[300000];
+  uint32 nodeid;
+  uint32 state;
+  uint32 ctime;
+  uint32 eflag;
+  uint32 expno;
+  uint32 runno;
+  uint32 subno;
+  uint32 reserved2[2];
+  struct io_status {
+    uint32 nqueue;
+    uint32 state;
+    uint32 count;
+    uint32 reserved_i;
+    float freq;
+    float evtsize;
+    float rate;
+    float reserved_f;
+  } io[2];
+};
+
+#endif
diff --git a/ROPCApplications/daq/slc/readout/include/ro_summary.h b/ROPCApplications/daq/slc/readout/include/ro_summary.h
new file mode 100644
index 0000000000000000000000000000000000000000..1945f8560699512fac221e731824a6ddc6c0f182
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/include/ro_summary.h
@@ -0,0 +1,50 @@
+#ifndef _Belle2_ro_summary_h
+#define _Belle2_ro_summary_h
+
+extern "C" {
+#include <nsm2/nsm2.h>
+}
+
+namespace Belle2 {
+
+  const int ro_summary_revision = 1;
+
+  struct ro_summary {
+    uint32 nodeid;
+    uint32 state;
+    uint32 eflag;
+    uint32 expno;
+    uint32 runno;
+    uint32 subno;
+    uint32 reserved_i[2];
+    uint32 stime;
+    uint32 ctime;
+    uint32 nevent_in;
+    uint32 nqueue_in;
+    uint32 connection_in;
+    uint32 connection_out;
+    uint32 nevent_out;
+    uint32 nqueue_out;
+    float evtrate_in;
+    float evtsize_in;
+    float flowrate_in;
+    float evtrate_out;
+    float evtsize_out;
+    float flowrate_out;
+    float loadavg;
+    float reserved_f[5];
+    struct event_header {
+      uint32 nword;
+      uint32 format;
+      uint32 exp_run;
+      uint32 evtno;
+      uint32 ctime_trgtype;
+      uint32 utime;
+      uint32 nodeid;
+      uint32 crc_err;
+    } header[25];
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/readout/include/ronode_info.h b/ROPCApplications/daq/slc/readout/include/ronode_info.h
new file mode 100644
index 0000000000000000000000000000000000000000..9292e6283f6088f8ae470931cfdb3787a6f4e06f
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/include/ronode_info.h
@@ -0,0 +1,39 @@
+#ifndef _Belle2_ronode_info_h
+#define _Belle2_ronode_info_h
+
+const int ronode_info_revision = 1;
+
+namespace Belle2 {
+
+  struct event_header {
+    unsigned int nword;
+    unsigned int format;
+    unsigned int exp_run;
+    unsigned int evtno;
+    unsigned int ctime_trgtype;
+    unsigned int utime;
+    unsigned int nodeid;
+    unsigned int crc_err;
+  };
+
+  struct ronode_info {
+    unsigned int nodeid;
+    unsigned int state;
+    unsigned int eflag;
+    unsigned int expno;
+    unsigned int runno;
+    unsigned int subno;
+    unsigned int reserved[2];
+    float reserved_f[5];
+    struct io_info {
+      int port;
+      unsigned int addr;
+      unsigned long long nbyte;
+      unsigned int count;
+    } io[2];
+    event_header header;
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/readout/include/ronode_status.h b/ROPCApplications/daq/slc/readout/include/ronode_status.h
new file mode 100644
index 0000000000000000000000000000000000000000..846ef2b14f0df34664bb850926b1406650a71933
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/include/ronode_status.h
@@ -0,0 +1,50 @@
+#ifndef _Belle2_ronode_status_h
+#define _Belle2_ronode_status_h
+
+extern "C" {
+#include <nsm2/nsm2.h>
+}
+
+namespace Belle2 {
+
+  const int ronode_status_revision = 1;
+
+  struct ronode_status {
+    uint32 nodeid;
+    uint32 state;
+    uint32 eflag;
+    uint32 expno;
+    uint32 runno;
+    uint32 subno;
+    uint32 reserved_i[2];
+    uint32 stime;
+    uint32 ctime;
+    uint32 nevent_in;
+    uint32 nqueue_in;
+    uint32 connection_in;
+    uint32 connection_out;
+    uint32 nevent_out;
+    uint32 nqueue_out;
+    float evtrate_in;
+    float evtsize_in;
+    float flowrate_in;
+    float evtrate_out;
+    float evtsize_out;
+    float flowrate_out;
+    float loadavg;
+    float reserved_f[5];
+    struct event_header {
+      uint32 nword;
+      uint32 format;
+      uint32 exp_run;
+      uint32 evtno;
+      uint32 ctime_trgtype;
+      uint32 utime;
+      uint32 nodeid;
+      uint32 crc_err;
+    } header;
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/readout/src/FlowMonitor.cc b/ROPCApplications/daq/slc/readout/src/FlowMonitor.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2b68d42e2a02981712390f0d75b2c9a7805b16ff
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/src/FlowMonitor.cc
@@ -0,0 +1,98 @@
+#include "daq/slc/readout/FlowMonitor.h"
+
+#include <daq/slc/system/Time.h>
+
+#include <cstring>
+
+using namespace Belle2;
+
+bool FlowMonitor::open(RunInfoBuffer* info)
+{
+  m_info = info;
+  if (m_info->isAvailable()) {
+    m_status.nodeid = m_info->getNodeId();
+    m_nbyte[0] = m_nbyte[1] = 0;
+    m_ioinfo[0].setLocalPort(m_info->getInputPort());
+    m_ioinfo[0].setLocalAddress(m_info->getInputAddress());
+    m_ip[0] = m_ioinfo[0].getLocalIP();
+    m_ioinfo[1].setLocalPort(m_info->getOutputPort());
+    m_ioinfo[1].setLocalAddress(m_info->getOutputAddress());
+    m_ip[1] = m_ioinfo[1].getLocalIP();
+  }
+  return true;
+}
+
+bool FlowMonitor::close()
+{
+  return true;
+}
+
+ronode_status& FlowMonitor::monitor()
+{
+  if (m_info->isAvailable()) {
+    m_ioinfo[0].setLocalAddress(m_info->getInputAddress());
+    m_ioinfo[0].setLocalPort(m_info->getInputPort());
+    m_ioinfo[1].setLocalAddress(m_info->getOutputAddress());
+    m_ioinfo[1].setLocalPort(m_info->getOutputPort());
+    IOInfo::checkTCP(m_ioinfo);
+    unsigned int ctime = Time().getSecond();
+    ronode_info info;
+    memcpy(&info, m_info->get(), sizeof(ronode_info));
+    memcpy(&(m_status.header), &(info.header), sizeof(event_header));
+    double length = ctime - m_status.ctime;
+    m_status.eflag = info.eflag;
+    m_status.state = info.state;
+    m_status.expno = info.expno;
+    m_status.runno = info.runno;
+    m_status.subno = info.subno;
+    m_status.reserved_i[0] = info.reserved[0];
+    m_status.reserved_i[1] = info.reserved[1];
+    m_status.reserved_f[0] = info.reserved_f[0];
+    m_status.reserved_f[1] = info.reserved_f[1];
+    m_status.reserved_f[2] = info.reserved_f[2];
+    m_status.reserved_f[3] = info.reserved_f[3];
+    m_status.ctime = ctime;
+
+    double dcount;
+    double dnbyte;
+    m_status.evtrate_in = 0;
+    m_status.evtsize_in = 0;
+    m_status.flowrate_in = 0;
+    m_status.evtrate_out = 0;
+    m_status.evtsize_out = 0;
+    m_status.flowrate_out = 0;
+    if (m_ioinfo[0].getLocalPort() > 0) {
+      m_status.connection_in = m_ioinfo[0].getState() == 1;
+      m_status.nqueue_in = m_ioinfo[0].getRXQueue();
+    }
+    if (m_ioinfo[1].getLocalPort() > 0) {
+      m_status.connection_out = m_ioinfo[1].getState() == 1;
+      m_status.nqueue_out = m_ioinfo[1].getRXQueue();
+    }
+    if ((dcount = info.io[0].count - m_status.nevent_in) > 0) {
+      dnbyte = info.io[0].nbyte - m_nbyte[0];
+      m_status.evtrate_in = dcount / length / 1000.;
+      m_status.evtsize_in = dnbyte / dcount / 1000.;
+      m_status.flowrate_in = dnbyte / length / 1000000.;
+      m_status.nevent_in = info.io[0].count;
+      m_nbyte[0] = info.io[0].nbyte;
+    } else {
+      m_status.evtrate_in = 0;
+      m_status.evtsize_in = 0;
+      m_status.flowrate_in = 0;
+    }
+    if ((dcount = info.io[1].count - m_status.nevent_out) > 0) {
+      dnbyte = info.io[1].nbyte - m_nbyte[1];
+      m_status.evtrate_out = dcount / length / 1000.;
+      m_status.evtsize_out = dnbyte / dcount / 1000.;
+      m_status.flowrate_out = dnbyte / length / 1000000.;
+      m_status.nevent_out = info.io[1].count;
+      m_nbyte[1] = info.io[1].nbyte;
+    } else {
+      m_status.evtrate_out = 0;
+      m_status.evtsize_out = 0;
+      m_status.flowrate_out = 0;
+    }
+  }
+  return m_status;
+}
diff --git a/ROPCApplications/daq/slc/readout/src/IOInfo.cc b/ROPCApplications/daq/slc/readout/src/IOInfo.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7bbf93dc7cde61f6b510fb2541b439f0ba3e6832
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/src/IOInfo.cc
@@ -0,0 +1,81 @@
+#include "daq/slc/readout/IOInfo.h"
+
+#include <cstdlib>
+#include <cstdio>
+
+#include <fstream>
+#include <sstream>
+#include <arpa/inet.h>
+
+using namespace Belle2;
+
+int IOInfo::checkTCP(IOInfo& info)
+{
+  std::vector<IOInfo> info_v;
+  info_v.push_back(info);
+  int ret = checkTCP(info_v);
+  info = info_v[0];
+  return ret;
+}
+
+int IOInfo::checkTCP(std::vector<IOInfo>& info)
+{
+  size_t count = 0;
+  for (size_t i = 0; i < info.size(); i++) {
+    info[i].setState(0);
+    info[i].setTXQueue(0);
+    info[i].setRXQueue(0);
+  }
+  count = 0;
+  std::string line;
+  std::stringstream ss;
+  std::string sl, local_address, rem_address, st, queue;
+  std::ifstream fin("/proc/net/tcp");
+  getline(fin, line);
+  while (fin && getline(fin, line)) {
+    ss.str("");
+    ss << line;
+    ss >> sl >> local_address >> rem_address >> st >> queue;
+    unsigned int addr = strtoul(local_address.substr(0, 8).c_str(), NULL, 16);
+    int port = strtoul(local_address.substr(9).c_str(), NULL, 16);
+    unsigned int raddr = strtoul(rem_address.substr(0, 8).c_str(), NULL, 16);
+    int rport = strtoul(rem_address.substr(9).c_str(), NULL, 16);
+    for (size_t i = 0; i < info.size(); i++) {
+      if (info[i].getState() > 0) continue;
+      int sti = strtoul(st.substr(0).c_str(), NULL, 16);
+      if (//addr == info[i].getLocalAddress() &&
+        port == info[i].getLocalPort() && sti == 1) {
+        info[i].setRemoteAddress(raddr);
+        info[i].setRemotePort(rport);
+        info[i].setState(sti);
+        info[i].setTXQueue(strtoul(queue.substr(0, 8).c_str(), NULL, 16));
+        info[i].setRXQueue(strtoul(queue.substr(9).c_str(), NULL, 16));
+        count++;
+      } else if (raddr == info[i].getRemoteAddress() &&
+                 rport == info[i].getRemotePort() && sti == 1) {
+        info[i].setLocalAddress(addr);
+        info[i].setLocalPort(port);
+        info[i].setState(sti);
+        info[i].setTXQueue(strtoul(queue.substr(0, 8).c_str(), NULL, 16));
+        info[i].setRXQueue(strtoul(queue.substr(9).c_str(), NULL, 16));
+        count++;
+      }
+      if (count == info.size()) return count;
+    }
+  }
+  return count;
+}
+
+const char* IOInfo::getLocalIP() const
+{
+  sockaddr_in addr;
+  addr.sin_addr.s_addr = m_local_addr;
+  return inet_ntoa(addr.sin_addr);
+}
+
+const char* IOInfo::getRemoteIP() const
+{
+  sockaddr_in addr;
+  addr.sin_addr.s_addr = m_remote_addr;
+  return inet_ntoa(addr.sin_addr);
+}
diff --git a/ROPCApplications/daq/slc/readout/src/LogListener.cc b/ROPCApplications/daq/slc/readout/src/LogListener.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6edd9df2de19c8b854a0c78bd59cda5c28cfa8e0
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/src/LogListener.cc
@@ -0,0 +1,131 @@
+#include "daq/slc/readout/LogListener.h"
+
+#include "daq/slc/readout/ProcessController.h"
+
+#include <daq/slc/runcontrol/RCCallback.h>
+#include <daq/slc/runcontrol/RCCommand.h>
+#include <daq/slc/nsm/NSMCommunicator.h>
+
+#include <daq/slc/system/File.h>
+#include <daq/slc/system/FileReader.h>
+
+#include <daq/slc/base/IOException.h>
+#include <daq/slc/base/StringUtil.h>
+#include <daq/slc/system/LogFile.h>
+
+#include <iostream>
+#include <sstream>
+#include <ctype.h>
+
+namespace Belle2 {
+
+  typedef FileReader<File> PipeReader;
+
+}
+
+using namespace Belle2;
+
+void LogListener::run()
+{
+  File fd(m_pipe[0]);
+  PipeReader preader(fd);
+  char c;
+  std::stringstream ss;
+  std::string s;
+  LogFile::Priority priority = LogFile::UNKNOWN;
+  int count = 0;
+  try {
+    while (true) {
+      c = preader.readChar();
+      if (c != '\n' && iscntrl(c)) continue;
+      if (c == '\n' && count > 0) {
+        s = m_con->getParName() + " : " + ss.str();
+        ss.str("");
+        //m_con->lock();
+        if (priority == LogFile::UNKNOWN) {
+          priority = LogFile::DEBUG;
+        }
+        if (priority > LogFile::DEBUG) {
+          m_con->getCallback()->log(priority, s);
+        } else {
+          LogFile::debug(s);
+        }
+        if (m_con->getCallback()->getNode().getState() == RCState::RUNNING_S) {
+          if (priority == LogFile::ERROR) {
+            // m_con->getCallback()->log(LogFile::ERROR, s);
+          } else if (priority == LogFile::FATAL) {
+            // m_con->getCallback()->log(LogFile::FATAL, s));
+            m_con->getCallback()->setState(RCState::ERROR_ES);
+          }
+        }
+        //m_con->unlock();
+        count = 0;
+        priority = LogFile::UNKNOWN;
+      } else if (isprint(c)) {
+        if (count == 0 && c == '[') {
+          ss << c;
+          while (true) {
+            c = preader.readChar();
+            if (c == ']') {
+              ss << c;
+              s = ss.str();
+              if (s == "[DEBUG]") priority = LogFile::DEBUG;
+              else if (s == "[INFO]") priority = LogFile::INFO;
+              else if (s == "[NOTICE]") priority = LogFile::NOTICE;
+              else if (s == "[WARNING]") priority = LogFile::WARNING;
+              else if (s == "[ERROR]") priority = LogFile::ERROR;
+              else if (s == "[FATAL]") priority = LogFile::FATAL;
+              else if (s.find("STOP") != std::string::npos) {
+                StringList sl = StringUtil::split(s, '=');
+                if (sl.size() > 1) {
+                  std::string nodename = StringUtil::replace(sl[1], "]", "");
+                  try {
+                    NSMCommunicator::send(NSMMessage(NSMNode(nodename), RCCommand::STOP));
+                  } catch (const std::exception& e) {
+                  }
+                }
+                count = 0;
+                ss.str("");
+                break;
+              }
+              if (priority > 0) {
+                count = 0;
+                ss.str("");
+              } else {
+                priority = LogFile::DEBUG;
+              }
+              break;
+            }
+            ss << c;
+          }
+        } else {
+          if (c != ' ' || count > 0) {
+            ss << c;
+            count++;
+          }
+        }
+      }
+    }
+  } catch (const IOException& e) {
+    LogFile::debug(e.what());
+    if (count > 0) {
+      s = m_con->getParName() + " : " + ss.str();
+      ss.str("");
+      //m_con->lock();
+      if (priority == LogFile::UNKNOWN) {
+        priority = LogFile::DEBUG;
+      }
+      m_con->getCallback()->log(priority, s);
+      if (m_con->getCallback()->getNode().getState() == RCState::RUNNING_S) {
+        if (priority == LogFile::ERROR) {
+          //m_con->getCallback()->reply(NSMMessage(NSMCommand::ERROR, s));
+        } else if (priority == LogFile::FATAL) {
+          //m_con->getCallback()->reply(NSMMessage(NSMCommand::ERROR, s));
+          m_con->getCallback()->setState(RCState::ERROR_ES);
+        }
+      }
+      //m_con->unlock();
+    }
+  }
+  close(m_pipe[0]);
+}
diff --git a/ROPCApplications/daq/slc/readout/src/ProcessController.cc b/ROPCApplications/daq/slc/readout/src/ProcessController.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c5ec3219c8bf3bc150cf2e99d4b90c70709bc061
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/src/ProcessController.cc
@@ -0,0 +1,162 @@
+#include "daq/slc/readout/ProcessController.h"
+
+#include "daq/slc/readout/ProcessListener.h"
+#include "daq/slc/readout/LogListener.h"
+#include "daq/slc/runcontrol/RCHandlerException.h"
+
+#include "daq/slc/system/Executor.h"
+#include "daq/slc/system/PThread.h"
+#include "daq/slc/system/LogFile.h"
+
+#include "daq/slc/base/StringUtil.h"
+#include <daq/slc/system/LockGuard.h>
+
+#include <cstdio>
+#include <unistd.h>
+
+
+using namespace Belle2;
+
+bool ProcessController::init(const std::string& parname, int nodeid)
+{
+  m_name = StringUtil::tolower(m_callback->getNode().getName());
+  m_parname = parname;
+  LogFile::open(m_name + "_" + m_parname);
+  if (!m_info.open(m_name + "_" + m_parname, nodeid, true)) {
+    return false;
+  }
+  m_callback->add(new NSMVHandlerInt(m_parname + ".pid", true, false, 0), false, false);
+  return true;
+}
+
+void ProcessController::clear()
+{
+  m_info.clear();
+}
+
+bool ProcessController::waitReady(int timeout)
+{
+  if (!m_info.waitReady(timeout)) {
+    return false;
+  }
+  return true;
+}
+
+bool ProcessController::load(int timeout)
+{
+  m_info.clear();
+  m_process.cancel();
+  m_process.kill(SIGQUIT);
+  if (pipe(m_iopipe) < 0) {
+    perror("pipe");
+    return false;
+  }
+  m_process = Process(new ProcessSubmitter(this, m_iopipe));
+  m_th_log = PThread(new LogListener(this, m_iopipe));
+  m_th_process = PThread(new ProcessListener(this));
+  //close(iopipe[1]);
+  if (timeout > 0) {
+    if (!m_info.waitReady(timeout)) {
+      throw (RCHandlerException("Failed to boot " + m_parname));
+      return false;
+    }
+  }
+  m_callback->set(m_parname + ".pid", m_process.get_id());
+  return true;
+}
+
+bool ProcessController::start(int expno, int runno)
+{
+  GenericLockGuard<RunInfoBuffer> lockGuard(m_info);
+  m_info.setExpNumber(expno);
+  m_info.setRunNumber(runno);
+  m_info.setSubNumber(0);
+  /*
+  if (m_info.getState() != RunInfoBuffer::RUNNING) {
+    throw (RCHandlerException(m_parname + " is not running"));
+  }
+  */
+  return true;
+}
+
+bool ProcessController::stop()
+{
+  GenericLockGuard<RunInfoBuffer> lockGuard(m_info);
+  m_info.setExpNumber(0);
+  m_info.setRunNumber(0);
+  m_info.setSubNumber(0);
+  m_info.setInputCount(0);
+  m_info.setInputNBytes(0);
+  m_info.setOutputCount(0);
+  m_info.setOutputNBytes(0);
+  return true;
+}
+
+bool ProcessController::pause()
+{
+  GenericLockGuard<RunInfoBuffer> lockGuard(m_info);
+  if (m_info.isRunning()) {
+    m_info.setState(RunInfoBuffer::PAUSING);
+  } else {
+    LogFile::warning("Process is not running. Pause request was ignored.");
+  }
+  return true;
+}
+
+bool ProcessController::resume()
+{
+  GenericLockGuard<RunInfoBuffer> lockGuard(m_info);
+  if (m_info.isPaused()) {
+    m_info.setState(RunInfoBuffer::RESUMING);
+  } else {
+    LogFile::warning("Process is not paused. Resume request was ignored.");
+  }
+  return true;
+}
+
+bool ProcessController::abort()
+{
+  m_info.clear();
+  m_process.kill(SIGINT);
+  if (getExecutable() == "basf2") {
+    usleep(100000);
+    m_process.kill(SIGQUIT);
+    m_process.kill(SIGKILL);
+  }
+  if (m_callback != NULL)
+    m_callback->set(m_parname + ".pid", -1);
+  m_process.wait();
+  m_th_log.cancel();
+  m_th_process.cancel();
+  close(m_iopipe[1]);
+  close(m_iopipe[0]);
+  return true;
+}
+
+void ProcessSubmitter::run()
+{
+  //close(1);
+  dup2(m_iopipe[1], 1);
+  //close(2);
+  dup2(m_iopipe[1], 2);
+  close(m_iopipe[0]);
+  Executor executor;
+  if (m_con->getExecutable().size() == 0) {
+    m_con->setExecutable("basf2");
+  }
+  executor.setExecutable(m_con->getExecutable());
+  for (size_t i = 0; i < m_con->m_arg_v.size(); i++) {
+    executor.addArg(m_con->m_arg_v[i]);
+  }
+  executor.execute();
+}
+
+void ProcessController::addArgument(const char* format, ...)
+{
+  va_list ap;
+  static char ss[1024];
+  va_start(ap, format);
+  vsprintf(ss, format, ap);
+  va_end(ap);
+  m_arg_v.push_back(ss);
+}
diff --git a/ROPCApplications/daq/slc/readout/src/ProcessListener.cc b/ROPCApplications/daq/slc/readout/src/ProcessListener.cc
new file mode 100644
index 0000000000000000000000000000000000000000..133ec431f683c8c78c785c6abc87b1d2332cc8a6
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/src/ProcessListener.cc
@@ -0,0 +1,37 @@
+#include "daq/slc/readout/ProcessListener.h"
+#include "daq/slc/readout/ProcessController.h"
+
+#include <daq/slc/runcontrol/RCCallback.h>
+
+#include <daq/slc/system/LogFile.h>
+#include <daq/slc/system/Process.h>
+
+using namespace Belle2;
+
+void ProcessListener::run()
+{
+  Process& process(m_con->getProcess());
+  std::string process_name = m_con->getParName();
+  RCCallback& callback(*(m_con->getCallback()));
+  if (not process.wait()) {
+    callback.log(LogFile::FATAL, "Failed to wait processed process %s",
+                 process_name.c_str());
+    return;
+  }
+  callback.log(LogFile::DEBUG, process_name + " : termineted");
+  callback.log(LogFile::DEBUG, "%s : waitpid_returned %d status = %d", process_name.c_str(), process.waitpid_result(),
+               process.waitpid_status());
+  process.set_id(-1);
+  callback.set(m_con->getParName() + ".pid", -1);
+  /*
+  try {
+    callback.monitor();
+  } catch (const RCHandlerFatalException& e) {
+    callback.log(LogFile::FATAL, e.what());
+  } catch (const RCHandlerException& e) {
+    callback.log(LogFile::ERROR, e.what());
+  } catch (const std::exception& e) {
+    callback.log(LogFile::FATAL, "Unknown exception: %s. terminating process", e.what());
+  }
+  */
+}
diff --git a/ROPCApplications/daq/slc/readout/src/RunInfoBuffer.cc b/ROPCApplications/daq/slc/readout/src/RunInfoBuffer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e15f59dd04e0e33fe67c41a11a6af165edfac00a
--- /dev/null
+++ b/ROPCApplications/daq/slc/readout/src/RunInfoBuffer.cc
@@ -0,0 +1,170 @@
+#include "daq/slc/readout/RunInfoBuffer.h"
+
+#include <daq/slc/system/LogFile.h>
+#include <daq/slc/system/LockGuard.h>
+
+#include <cstring>
+#include <cstdlib>
+
+using namespace Belle2;
+
+size_t RunInfoBuffer::size()
+{
+  return m_mutex.size() + m_cond.size() +
+         sizeof(ronode_info);
+}
+
+bool RunInfoBuffer::open(const std::string& nodename,
+                         int nodeid, bool recreate)
+{
+  m_nodename = nodename;
+  std::string username = getenv("USER");
+  m_path = "/run_info_" + username + "_" + nodename;
+  if (!m_memory.open(m_path, size())) {
+    perror("shm_open");
+    LogFile::fatal("Failed to open %s", m_path.c_str());
+    return false;
+  }
+  char* buf = (char*)m_memory.map(0, size());
+  if (buf == NULL) {
+    return false;
+  }
+  m_mutex = MMutex(buf);
+  buf += m_mutex.size();
+  m_cond = MCond(buf);
+  buf += m_cond.size();
+  m_info = (ronode_info*)buf;
+  if (recreate) init();
+  if (nodeid > 0) setNodeId(nodeid);
+  return true;
+}
+
+bool RunInfoBuffer::init()
+{
+  if (m_info == NULL) return false;
+  m_mutex.init();
+  m_cond.init();
+  memset(m_info, 0, sizeof(ronode_info));
+  LogFile::debug("Initialized %s", m_path.c_str());
+  return true;
+}
+
+void RunInfoBuffer::clear()
+{
+  if (m_info == NULL) return;
+  MLockGuard lockGuard(m_mutex);
+  memset(m_info, 0, sizeof(ronode_info));
+}
+
+bool RunInfoBuffer::close()
+{
+  m_memory.close();
+  return true;
+}
+
+bool RunInfoBuffer::unlink()
+{
+  m_memory.unlink();
+  m_memory.close();
+  return true;
+}
+
+bool RunInfoBuffer::lock()
+{
+  if (m_info == NULL) return false;
+  return m_mutex.lock();
+}
+
+bool RunInfoBuffer::unlock()
+{
+  if (m_info == NULL) return false;
+  return m_mutex.unlock();
+}
+
+bool RunInfoBuffer::wait()
+{
+  if (m_info == NULL) return false;
+  return m_cond.wait(m_mutex);
+}
+
+bool RunInfoBuffer::wait(int time)
+{
+  if (m_info == NULL) return false;
+  return m_cond.wait(m_mutex, time, 0);
+}
+
+bool RunInfoBuffer::notify()
+{
+  if (m_info == NULL) return false;
+  return m_cond.broadcast();
+}
+
+bool RunInfoBuffer::waitRunning(int timeout)
+{
+  if (m_info == NULL) return false;
+  MLockGuard lockGuard(m_mutex);
+  if (getState() != RunInfoBuffer::RUNNING) {
+    if (!wait(timeout)) {
+      return false;
+    }
+  }
+  return true;
+}
+
+bool RunInfoBuffer::waitReady(int timeout)
+{
+  if (m_info == NULL) return false;
+  MLockGuard lockGuard(m_mutex);
+  if (getState() != RunInfoBuffer::READY &&
+      getState() != RunInfoBuffer::RUNNING) {
+    if (!wait(timeout)) {
+      if (getState() != RunInfoBuffer::READY &&
+          getState() != RunInfoBuffer::RUNNING) {
+        return false;
+      }
+    }
+  }
+  return true;
+}
+
+bool RunInfoBuffer::reportRunning()
+{
+  if (m_info == NULL) return false;
+  MLockGuard lockGuard(m_mutex);
+  setState(RunInfoBuffer::RUNNING);
+  notify();
+  return true;
+}
+
+bool RunInfoBuffer::reportError(EFlag eflag)
+{
+  if (m_info == NULL) return false;
+  MLockGuard lockGuard(m_mutex);
+  setErrorFlag(eflag);
+  notify();
+  return true;
+}
+
+bool RunInfoBuffer::reportReady()
+{
+  if (m_info == NULL) return false;
+  MLockGuard lockGuard(m_mutex);
+  setState(RunInfoBuffer::READY);
+  notify();
+  return true;
+}
+
+bool RunInfoBuffer::reportNotReady()
+{
+  if (m_info == NULL) return false;
+  MLockGuard lockGuard(m_mutex);
+  setState(RunInfoBuffer::NOTREADY);
+  notify();
+  return true;
+}
+
+void RunInfoBuffer::copyEventHeader(int* buf)
+{
+  if (m_info == NULL) return;
+  memcpy(&(m_info->header), buf, sizeof(event_header));
+}
diff --git a/ROPCApplications/daq/slc/system/include/Buffer.h b/ROPCApplications/daq/slc/system/include/Buffer.h
new file mode 100644
index 0000000000000000000000000000000000000000..1bffcfee19330f058884eac0c2978e7c5c32b73b
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/Buffer.h
@@ -0,0 +1,38 @@
+#ifndef _Belle2_Buffer_hh
+#define _Belle2_Buffer_hh
+
+#include <cstddef>
+
+namespace Belle2 {
+
+  class Buffer {
+
+    // constructors & destructors
+  public:
+    Buffer();
+    Buffer(unsigned int size, unsigned char* memory = NULL);
+    Buffer(const Buffer& w);
+    virtual ~Buffer();
+
+    // member methods implemented
+  public:
+    unsigned char* ptr() { return m_memory; }
+    const unsigned char* ptr() const { return m_memory; }
+    unsigned int size() const { return m_size; }
+    virtual bool available() { return m_memory != NULL; }
+
+    // operators
+  public:
+    const Buffer& operator = (const Buffer&);
+
+    // member data
+  protected:
+    unsigned char* m_memory;
+    unsigned int m_size;
+    bool m_allocated;
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/BufferedReader.h b/ROPCApplications/daq/slc/system/include/BufferedReader.h
new file mode 100644
index 0000000000000000000000000000000000000000..9884994ccd6a79fbf13ea52eea9fbfcecf35906b
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/BufferedReader.h
@@ -0,0 +1,41 @@
+#ifndef _Belle2_BufferedReader_hh
+#define _Belle2_BufferedReader_hh
+
+#include "daq/slc/base/Reader.h"
+
+namespace Belle2 {
+
+  class BufferedReader : public Reader {
+
+    // constructors & destructors
+  public:
+    BufferedReader();
+    BufferedReader(size_t size, unsigned char* memory = NULL);
+    BufferedReader(const BufferedReader& r);
+    virtual ~BufferedReader();
+
+    // member methods implemented
+  public:
+    void seekTo(size_t pos) { m_pos = pos; }
+    unsigned char* ptr() { return m_memory; }
+    size_t count() const { return m_pos; }
+    size_t size() const { return m_size; }
+    void copy(const void*, size_t);
+    virtual size_t read(void*, size_t);
+    virtual bool available() { return true; }
+
+  public:
+    const BufferedReader& operator = (const BufferedReader&);
+
+    // member data
+  protected:
+    unsigned char* m_memory;
+    size_t m_size;
+    size_t m_pos;
+    bool m_allocated;
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/BufferedWriter.h b/ROPCApplications/daq/slc/system/include/BufferedWriter.h
new file mode 100644
index 0000000000000000000000000000000000000000..7abab62d293c76463980dcbd545568b8fd1a4340
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/BufferedWriter.h
@@ -0,0 +1,41 @@
+#ifndef _Belle2_BufferedWriter_hh
+#define _Belle2_BufferedWriter_hh
+
+#include "daq/slc/base/Writer.h"
+
+namespace Belle2 {
+
+  class BufferedWriter : public Writer {
+
+    // constructors & destructors
+  public:
+    BufferedWriter();
+    BufferedWriter(size_t size, unsigned char* memory = NULL);
+    BufferedWriter(const BufferedWriter& w);
+    virtual ~BufferedWriter();
+
+    // member methods implemented
+  public:
+    void seekTo(size_t pos) { m_pos = pos; }
+    unsigned char* ptr() { return m_memory; }
+    size_t count() const { return m_pos; }
+    size_t size() const { return m_size; }
+    virtual size_t write(const void*, size_t);
+    virtual bool available() { return true; }
+
+    // operators
+  public:
+    const BufferedWriter& operator = (const BufferedWriter&);
+
+    // member data
+  protected:
+    unsigned char* m_memory;
+    size_t m_size;
+    size_t m_pos;
+    bool m_allocated;
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/Cond.h b/ROPCApplications/daq/slc/system/include/Cond.h
new file mode 100644
index 0000000000000000000000000000000000000000..08d2b5bcf01330561b63c2b61d06eb521b48bae4
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/Cond.h
@@ -0,0 +1,29 @@
+#ifndef _Belle2_Cond_hh
+#define _Belle2_Cond_hh
+
+#include "daq/slc/system/Mutex.h"
+
+namespace Belle2 {
+
+  class Cond {
+
+  public:
+    Cond();
+    Cond(const Cond& cond);
+    ~Cond() {};
+
+  public:
+    bool init();
+    bool signal();
+    bool broadcast();
+    bool wait(Mutex& mutex);
+    bool wait(Mutex& mutex, const unsigned int sec,
+              const unsigned int msec = 0);
+    bool destroy();
+
+  private:
+    pthread_cond_t m_cond_t;
+
+  };
+};
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/Daemon.h b/ROPCApplications/daq/slc/system/include/Daemon.h
new file mode 100644
index 0000000000000000000000000000000000000000..397d1eeff28ef79c623e358b07fc2ee027ea136b
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/Daemon.h
@@ -0,0 +1,23 @@
+#ifndef _Daemon_hh
+#define _Daemon_hh
+
+namespace Belle2 {
+
+  class Daemon {
+
+  public:
+    static bool start(const char* title,
+                      int argc, char** argv,
+                      int nargc, const char* msg);
+
+    static bool restart();
+
+  private:
+    static int g_argc;
+    static char** g_argv;
+
+  };
+
+};
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/DynamicLoadException.h b/ROPCApplications/daq/slc/system/include/DynamicLoadException.h
new file mode 100644
index 0000000000000000000000000000000000000000..617dea05a476d7034c69bbe32da5109378098bc1
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/DynamicLoadException.h
@@ -0,0 +1,17 @@
+#ifndef _Belle2_DynamicLoadException_hh
+#define _Belle2_DynamicLoadException_hh
+
+#include "daq/slc/base/Exception.h"
+
+namespace Belle2 {
+
+  class DynamicLoadException : public Exception {
+
+  public:
+    DynamicLoadException(const std::string& format, ...);
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/DynamicLoader.h b/ROPCApplications/daq/slc/system/include/DynamicLoader.h
new file mode 100644
index 0000000000000000000000000000000000000000..4540a4850b03c6f3db9b08b6e9173da99c3c16ab
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/DynamicLoader.h
@@ -0,0 +1,30 @@
+#ifndef _Belle2_DynamicLoader_h
+#define _Belle2_DynamicLoader_h
+
+#include <string>
+
+namespace Belle2 {
+
+  class DynamicLoader {
+
+  public:
+    DynamicLoader() {}
+    DynamicLoader(const std::string& path)
+    {
+      open(path);
+    }
+    ~DynamicLoader();
+
+  public:
+    void* open(const std::string& lib_path);
+    void* load(const std::string& func_name);
+    void close();
+
+  private:
+    void* m_handle;
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/Executor.h b/ROPCApplications/daq/slc/system/include/Executor.h
new file mode 100644
index 0000000000000000000000000000000000000000..5f29f831f76b8cf0d6728194f4c3f68832c9a4a3
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/Executor.h
@@ -0,0 +1,35 @@
+#ifndef _Belle2_Executor_h
+#define _Belle2_Executor_h
+
+#include <string>
+#include <vector>
+
+namespace Belle2 {
+
+  class Executor {
+
+  public:
+    Executor() {}
+    Executor(const std::string& path) : m_path(path) {}
+
+  public:
+    void setExecutable(const char* format, ...);
+    void setExecutable(const std::string& path);
+    void addArg(const char* format, ...);
+    void addArg(const std::string& arg);
+    void addArg(int arg) { addArg("%d", arg); }
+    void addArg(short arg) { addArg("%d", arg); }
+    void addArg(float arg) { addArg("%f", arg); }
+    void addArg(double arg) { addArg("%f", arg); }
+    bool execute(bool isdaemon = false);
+
+  private:
+    std::string m_path;
+    std::vector<std::string> m_arg_v;
+
+  };
+
+}
+
+#endif
+
diff --git a/ROPCApplications/daq/slc/system/include/Fifo.h b/ROPCApplications/daq/slc/system/include/Fifo.h
new file mode 100644
index 0000000000000000000000000000000000000000..6d5e2e03daee3982f4c4d14c2497e727d19677a7
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/Fifo.h
@@ -0,0 +1,31 @@
+#ifndef _Belle2_Fifo_hh
+#define _Belle2_Fifo_hh
+
+#include "daq/slc/system/FileDescriptor.h"
+
+#include <cstddef>
+#include <string>
+
+namespace Belle2 {
+
+  class Fifo : public FileDescriptor {
+
+  public:
+    static Fifo mkfifo(const std::string& path);
+
+  public:
+    Fifo() {}
+    virtual ~Fifo() {}
+
+  public:
+    void open(const std::string& path,
+              const std::string& mode = "r");
+    void unlink(const std::string& path);
+    virtual size_t write(const void* v, size_t count);
+    virtual size_t read(void* v, size_t count);
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/FifoReader.h b/ROPCApplications/daq/slc/system/include/FifoReader.h
new file mode 100644
index 0000000000000000000000000000000000000000..8754372b8ea5bc1bb424e702508fb17606a89e5e
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/FifoReader.h
@@ -0,0 +1,13 @@
+#ifndef _Belle2_FifoReader_hh
+#define _Belle2_FifoReader_hh
+
+#include "daq/slc/system/FileReader.h"
+#include "daq/slc/system/Fifo.h"
+
+namespace Belle2 {
+
+  typedef FileReader<Fifo> FifoReader;
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/FifoWriter.h b/ROPCApplications/daq/slc/system/include/FifoWriter.h
new file mode 100644
index 0000000000000000000000000000000000000000..3f1c23e49e82a25fdd0c0efd244597649955b48e
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/FifoWriter.h
@@ -0,0 +1,13 @@
+#ifndef _Belle2_FifoWriter_hh
+#define _Belle2_FifoWriter_hh
+
+#include "daq/slc/system/FileWriter.h"
+#include "daq/slc/system/Fifo.h"
+
+namespace Belle2 {
+
+  typedef FileWriter<Fifo> FifoWriter;
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/File.h b/ROPCApplications/daq/slc/system/include/File.h
new file mode 100644
index 0000000000000000000000000000000000000000..992edd5d25a3f2756904f4cb8d157102ccacc98c
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/File.h
@@ -0,0 +1,33 @@
+#ifndef _Belle2_File_hh
+#define _Belle2_File_hh
+
+#include "daq/slc/system/FileDescriptor.h"
+
+#include <string>
+
+namespace Belle2 {
+
+  class File : public FileDescriptor {
+
+  public:
+    static bool exist(const std::string& filename);
+
+  public:
+    File() {}
+    File(int fd) : FileDescriptor(fd) {}
+    File(const std::string& path,
+         const std::string& mode = "r") { open(path, mode); }
+    virtual ~File() {}
+
+  public:
+    void open(const std::string& path,
+              const std::string& mode = "r");
+    void unlink(const std::string& path);
+    virtual size_t write(const void* v, size_t count);
+    virtual size_t read(void* v, size_t count);
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/FileDescriptor.h b/ROPCApplications/daq/slc/system/include/FileDescriptor.h
new file mode 100644
index 0000000000000000000000000000000000000000..bc2b123784fcb82e4f4ffbd379c95b0279800d8a
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/FileDescriptor.h
@@ -0,0 +1,27 @@
+#ifndef _Belle2_FileDescriptor_hh
+#define _Belle2_FileDescriptor_hh
+
+namespace Belle2 {
+
+  class FileDescriptor {
+
+  public:
+    FileDescriptor();
+    FileDescriptor(const FileDescriptor&);
+    FileDescriptor(int fd);
+    virtual ~FileDescriptor();
+
+  public:
+    int get_fd() const;
+    bool select(int sec = -1, int usec = -1);
+    bool select2(int sec = -1, int usec = -1);
+    bool close();
+
+  protected:
+    int m_fd;
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/FileReader.h b/ROPCApplications/daq/slc/system/include/FileReader.h
new file mode 100644
index 0000000000000000000000000000000000000000..4842154dc97ddae9e746a14cc4f2d5e55e91cd33
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/FileReader.h
@@ -0,0 +1,27 @@
+#ifndef _Belle2_FileReader_hh
+#define _Belle2_FileReader_hh
+
+#include "daq/slc/base/Reader.h"
+
+namespace Belle2 {
+
+  template <class FD>
+  class FileReader : public Reader {
+
+  public:
+    FileReader() {}
+    FileReader(const FD& fd) : _fd(fd) {}
+    virtual ~FileReader() {}
+
+  public:
+    virtual size_t read(void* v, size_t count) { return _fd.read(v, count); }
+    virtual bool available() { return _fd.select(); }
+
+  private:
+    FD _fd;
+
+  };
+
+};
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/FileWriter.h b/ROPCApplications/daq/slc/system/include/FileWriter.h
new file mode 100644
index 0000000000000000000000000000000000000000..a38d57ab70137b18d7cfaff2d9ec0d22324a9fdd
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/FileWriter.h
@@ -0,0 +1,33 @@
+#ifndef _Belle2_FileWriter_hh
+#define _Belle2_FileWriter_hh
+
+#include "daq/slc/base/Writer.h"
+
+namespace Belle2 {
+
+  template <class FD>
+  class FileWriter : public Writer {
+
+  public:
+    FileWriter() {}
+    FileWriter(const FD& fd) : _fd(fd) {}
+    virtual ~FileWriter() {}
+
+  public:
+    virtual size_t write(const void* v, size_t count)
+    {
+      return _fd.write(v, count);
+    }
+    virtual bool available()
+    {
+      return _fd.select();
+    }
+
+  private:
+    FD _fd;
+
+  };
+
+};
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/Fork.h b/ROPCApplications/daq/slc/system/include/Fork.h
new file mode 100644
index 0000000000000000000000000000000000000000..86b70ce7f674223a41aaee6ea59885a99c894406
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/Fork.h
@@ -0,0 +1,68 @@
+#ifndef _Belle2_Fork_hh
+#define _Belle2_Fork_hh
+
+#include <unistd.h>
+#include <signal.h>
+#include <sys/wait.h>
+#include <stdlib.h>
+
+namespace Belle2 {
+
+  class Fork {
+
+  public:
+    template <class WORKER>
+    static void g_handler_exit(int, void* worker)
+    {
+      delete(WORKER*)worker;
+      exit(0);
+    }
+    static void g_handler_int(int) { exit(0); }
+
+  public:
+    Fork() : m_pid(-1) {}
+
+    template<class WORKER>
+    Fork(WORKER* worker, bool detached = true)
+    {
+      m_pid = fork();
+      if (m_pid == 0) {
+        signal(SIGINT, g_handler_int);
+        if (detached) {
+          on_exit(g_handler_exit<WORKER>, (void*)worker);
+        }
+        worker->run();
+        exit(0);
+      } else if (detached) {
+        delete worker;
+      }
+    }
+    ~Fork() {}
+
+  public:
+    pid_t get_id() const { return m_pid; }
+    void set_id(pid_t id) { m_pid = id; }
+    bool isAlive() const { return kill(0); }
+    bool kill(int signo) const
+    {
+      if (m_pid < 0) return false;
+      return ::kill(m_pid, signo) == 0;
+    }
+    bool wait(int opt = 0)
+    {
+      if (m_pid < 0) return false;
+      if (::waitpid(m_pid, NULL, opt)) {
+        m_pid = -1;
+      }
+      return true;
+    }
+    bool cancel() { return kill(SIGINT); }
+
+  private:
+    pid_t m_pid;
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/Inotify.h b/ROPCApplications/daq/slc/system/include/Inotify.h
new file mode 100644
index 0000000000000000000000000000000000000000..3ff75a9ffe3d3f123cd9173b8bb2bbedf14c0492
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/Inotify.h
@@ -0,0 +1,64 @@
+#ifndef _Belle2_Inotify_hh
+#define _Belle2_Inotify_hh
+
+#include "daq/slc/system/FileDescriptor.h"
+
+#include <string>
+#include <vector>
+
+namespace Belle2 {
+
+  class InotifyEvent {
+
+    friend class Inotify;
+
+  public:
+    InotifyEvent()
+      : m_wd(-1), m_mask(-1), m_name() {}
+    ~InotifyEvent() {}
+
+  private:
+    InotifyEvent(int wd, unsigned long mask, const std::string& name)
+      : m_wd(wd), m_mask(mask), m_name(name) {}
+
+  public:
+    int get_wd() const { return m_wd;}
+    unsigned long getMask() const { return m_mask; }
+    const std::string& getName() const { return m_name; }
+
+  private:
+    int m_wd;
+    unsigned long m_mask;
+    std::string m_name;
+
+  };
+
+  typedef std::vector<InotifyEvent> InotifyEventList;
+
+  class Inotify : public FileDescriptor {
+
+  public:
+    static const unsigned long FILE_CREATE;
+    static const unsigned long FILE_OPEN;
+    static const unsigned long FILE_CLOSE_WRITE;
+    static const unsigned long FILE_CLOSE_NOWRITE;
+    static const unsigned long FILE_DELETE;
+    static const unsigned long FILE_MODIFY;
+    static const unsigned long FILE_ACCESS;
+    static const unsigned long FILE_ATTRIB;
+
+  public:
+    Inotify() {}
+    virtual ~Inotify() {}
+
+  public:
+    void open();
+    int add(const std::string& path, unsigned long mask);
+    void remove(int wd);
+    InotifyEventList wait(int sec);
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/LockGuard.h b/ROPCApplications/daq/slc/system/include/LockGuard.h
new file mode 100644
index 0000000000000000000000000000000000000000..87c4b1af8f86a84cd577a8b2823b2933adf0991d
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/LockGuard.h
@@ -0,0 +1,65 @@
+#ifndef _Belle2_LockGuard_hh
+#define _Belle2_LockGuard_hh
+
+#include <daq/slc/system/Mutex.h>
+#include "MMutex.h"
+
+namespace Belle2 {
+  /**
+   * Lock Guard for a Mutex instance.
+   * If a new instance of this class is generated,
+   * the mutex is locked. On destruction, it is
+   * automatically unlocked.
+   * This allows to write very simple functions with locks, e.g.
+   *
+   *    Mutex m;
+   *
+   *    LockGuard lock(m);
+   *    try {
+   *      throw std::exception();
+   *      // or
+   *      return some_value;
+   *    } catch(...) {
+   *      std::cout << "Some exception" << std::endl;
+   *    }
+   *
+   * without the needs to think about unlocking it, as it is done automatically.
+   * It toughly follows the C++11 lock_guard and RIIA (https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization)
+   *
+   * WARNING: the lock can not be unlocked on uncaught exceptions (because they terminate the program by definition).
+   * This is not a problem with the mutex, as it is released by the operation system on program termination.
+   *
+   * The GenericLockGuard is a templated version of the lock guard. Use the specialised
+   * LockGuard of you want to lock a Mutex or the MLockGuard for an MMutex.
+   */
+  template<class AMutex>
+  class GenericLockGuard {
+  public:
+    /// Construct a new LockGuard locking the mutex
+    explicit GenericLockGuard(AMutex& mutex) : m_mutex(mutex)
+    {
+      m_mutex.lock();
+    }
+
+    /// Automatically release the lock on destruction
+    ~GenericLockGuard()
+    {
+      m_mutex.unlock();
+    }
+
+  private:
+    /// Do not allow to copy a lock guard
+    GenericLockGuard(const GenericLockGuard&);
+
+    /// Do not allow to copy a lock guard
+    GenericLockGuard& operator=(const GenericLockGuard&);
+
+    /// The mutex hold by this lock guard
+    AMutex& m_mutex;
+  };
+
+  typedef GenericLockGuard<Mutex> LockGuard;
+  typedef GenericLockGuard<MMutex> MLockGuard;
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/LogFile.h b/ROPCApplications/daq/slc/system/include/LogFile.h
new file mode 100644
index 0000000000000000000000000000000000000000..35e13f8bed71c1e66e64f3278ef4f24c75bf0167
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/LogFile.h
@@ -0,0 +1,65 @@
+#ifndef _Belle2_LogFile_h
+#define  _Belle2_LogFile_h
+
+#include <daq/slc/system/Mutex.h>
+
+#include <daq/slc/base/Date.h>
+
+#include <string>
+#include <fstream>
+#include <stdarg.h>
+
+namespace Belle2 {
+
+  struct LogFile {
+
+  public:
+    enum Priority {
+      UNKNOWN = 0, DEBUG, INFO, NOTICE, WARNING, ERROR, FATAL
+    };
+
+  public:
+    static Priority getPriority(const std::string& str);
+
+  private:
+    LogFile() {}
+    ~LogFile() {}
+
+  private:
+    static bool g_stderr;
+    static bool g_opened;
+    static std::string g_filepath;
+    static std::string g_linkpath;
+    static std::ofstream g_stream;
+    static unsigned int g_filesize;
+    static Mutex g_mutex;
+    static Priority g_threshold;
+    static std::string g_filename;
+    static Date g_date;
+
+    // member functions
+  public:
+    static void open(const std::string& filename,
+                     Priority priority = UNKNOWN);
+    static void open();
+    static void close();
+    static void debug(const std::string& msg, ...);
+    static void info(const std::string& msg, ...);
+    static void notice(const std::string& msg, ...);
+    static void warning(const std::string& msg, ...);
+    static void error(const std::string& msg, ...);
+    static void fatal(const std::string& msg, ...);
+    static void put(Priority priority, const std::string& msg, ...);
+    static void setStdErr(bool stderr)
+    {
+      g_stderr = stderr;
+    }
+
+  private:
+    static int put_impl(const std::string& msg, Priority priority, va_list ap);
+
+  };
+
+};
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/MCond.h b/ROPCApplications/daq/slc/system/include/MCond.h
new file mode 100644
index 0000000000000000000000000000000000000000..a640958645283a5653d29ff6486e472ff89b6229
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/MCond.h
@@ -0,0 +1,45 @@
+#ifndef _Belle2_MCond_h
+#define _Belle2_MCond_h
+
+#include "daq/slc/system/MMutex.h"
+
+#include <pthread.h>
+
+namespace Belle2 {
+
+  class MCond {
+
+  public:
+    static size_t size() { return sizeof(pthread_cond_t); }
+
+    // constructors and destructor
+  public:
+    MCond();
+    MCond(const MCond&);
+    MCond(void*);
+    ~MCond();
+
+    // member functions;
+  public:
+    bool init(void*);
+    bool init();
+    bool set(void*);
+    bool signal();
+    bool broadcast();
+    bool wait(MMutex& mutex);
+    bool wait(MMutex& mutex, const unsigned int sec,
+              const unsigned int msec = 0);
+    bool destroy();
+
+  public:
+    const MCond& operator=(const MCond&);
+
+    // data members;
+  private:
+    pthread_cond_t* m_cond;
+
+  };
+
+};
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/MMutex.h b/ROPCApplications/daq/slc/system/include/MMutex.h
new file mode 100644
index 0000000000000000000000000000000000000000..48a9cb2033cea92e98bac029f74e113b3a0b3e5b
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/MMutex.h
@@ -0,0 +1,50 @@
+#ifndef _Belle2_MMutex_h
+#define _Belle2_MMutex_h
+
+#include <pthread.h>
+
+#ifdef __CINT__
+#undef __GNUC__
+#define _SYS__SELECT_H_
+struct pthread_cond_t;
+struct pthread_mutex_t;
+#endif
+
+namespace Belle2 {
+
+  class MMutex {
+
+    friend class MCond;
+
+  public:
+    static size_t size() { return sizeof(pthread_mutex_t); }
+
+    // constructors and destructor
+  public:
+    MMutex();
+    MMutex(void*);
+    MMutex(const MMutex&);
+    ~MMutex();
+
+    // member functions;
+  public:
+    bool init(void*);
+    bool init();
+    bool set(void*);
+    bool lock();
+    bool trylock();
+    bool unlock();
+    bool destroy();
+
+  public:
+    const MMutex& operator=(const MMutex&);
+
+    // data members;
+  private:
+    pthread_mutex_t* m_mu;
+
+  };
+
+};
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/Mutex.h b/ROPCApplications/daq/slc/system/include/Mutex.h
new file mode 100644
index 0000000000000000000000000000000000000000..d0ac88760d5c69cd6912576daff5b9d7e6f55a1b
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/Mutex.h
@@ -0,0 +1,31 @@
+#ifndef _Belle2_Mutex_hh
+#define _Belle2_Mutex_hh
+
+#include <pthread.h>
+
+namespace Belle2 {
+
+  class Mutex {
+
+    friend class Cond;
+
+    // constructors & destructors
+  public:
+    Mutex();
+    ~Mutex();
+
+    // member methods
+  public:
+    bool lock();
+    bool unlock();
+
+    // member data
+  private:
+    pthread_mutex_t m_mu;
+    pthread_mutexattr_t m_attr;
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/PThread.h b/ROPCApplications/daq/slc/system/include/PThread.h
new file mode 100644
index 0000000000000000000000000000000000000000..73a818122bfc835bf83a339b4566a39ea907061b
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/PThread.h
@@ -0,0 +1,110 @@
+#ifndef _Belle2_PThread_hh
+#define _Belle2_PThread_hh
+
+#include <daq/slc/system/LogFile.h>
+
+#include <pthread.h>
+#include <signal.h>
+#include <cstdio>
+
+namespace Belle2 {
+
+  class PThread {
+
+  private:
+    template<class WORKER>
+    static void destroy(void* arg)
+    {
+      WORKER* worker = (WORKER*)arg;
+      delete worker;
+      worker = NULL;
+    }
+    template<class WORKER>
+    static void* create_destroy(void* arg)
+    {
+      WORKER* worker = (WORKER*)arg;
+      pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+      pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+      pthread_cleanup_push(PThread::destroy<WORKER>, arg);
+      try {
+        worker->run();
+      } catch (const std::exception& e) {
+        LogFile::fatal(e.what());
+      }
+      pthread_cleanup_pop(1);
+      return NULL;
+    }
+    template<class WORKER>
+    static void* create(void* arg)
+    {
+      WORKER* worker = (WORKER*)arg;
+      pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+      pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+      try {
+        worker->run();
+      } catch (const std::exception& e) {
+        LogFile::fatal(e.what());
+      }
+      return NULL;
+    }
+
+  public:
+    static void exit() { pthread_exit(NULL); }
+
+  public:
+    PThread() : m_th(0) {}
+    template<class WORKER>
+    PThread(WORKER* worker, bool destroyed = true, bool detached = true)
+    {
+      m_th = 0;
+      if (destroyed) {
+        if (pthread_create(&m_th, NULL, PThread::create_destroy<WORKER>,
+                           (void*)worker) != 0) {
+          m_th = 0;
+        }
+      } else {
+        if (pthread_create(&m_th, NULL, PThread::create<WORKER>,
+                           (void*)worker) != 0) {
+          m_th = 0;
+        }
+      }
+      if (detached) {
+        detach();
+        m_th = 0;
+      }
+    }
+    ~PThread() {}
+
+  public:
+    pthread_t id() { return m_th; }
+    pthread_t get_id() { return m_th; }
+    bool kill(int signo)
+    {
+      if (m_th == 0) return false;
+      return ::pthread_kill(m_th, signo) == 0;
+    }
+    bool is_alive() { return this->kill(0); }
+    bool detach()
+    {
+      if (m_th == 0) return false;
+      return ::pthread_detach(m_th) == 0;
+    }
+    bool join()
+    {
+      if (m_th == 0) return false;
+      return ::pthread_join(m_th, NULL) == 0;
+    }
+    bool cancel()
+    {
+      if (m_th == 0) return false;
+      return ::pthread_cancel(m_th) == 0;
+    }
+
+  private:
+    pthread_t m_th;
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/Process.h b/ROPCApplications/daq/slc/system/include/Process.h
new file mode 100644
index 0000000000000000000000000000000000000000..72c242e4e2defd77c9ffada50541a2289459f1ec
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/Process.h
@@ -0,0 +1,79 @@
+#ifndef _Belle2_Process_h
+#define _Belle2_Process_h
+
+#include <unistd.h>
+#include <signal.h>
+#include <sys/wait.h>
+#include <stdlib.h>
+
+namespace Belle2 {
+
+  class Process {
+
+  public:
+    template <class WORKER>
+    static void g_handler_exit(int, void* worker)
+    {
+      delete(WORKER*)worker;
+      exit(0);
+    }
+    static void g_handler_int(int) { exit(0); }
+
+  public:
+    Process() : m_pid(-1) {}
+
+    template<class WORKER>
+    Process(WORKER* worker, bool detached = true)
+    {
+      m_pid = fork();
+      if (m_pid == 0) {
+        signal(SIGINT, g_handler_int);
+        if (detached) {
+          on_exit(g_handler_exit<WORKER>, (void*)worker);
+        }
+        worker->run();
+        exit(0);
+      } else if (detached) {
+        delete worker;
+      }
+    }
+    ~Process() {}
+
+  public:
+    pid_t get_id() const { return m_pid; }
+    pid_t id() const { return m_pid; }
+    void set_id(pid_t id) { m_pid = id; }
+    bool isAlive() const { return kill(0); }
+    bool kill(int signo) const
+    {
+      if (m_pid <= 0) return false;
+      return ::kill(m_pid, signo) == 0;
+    }
+    bool wait(int opt = 0)
+    {
+      if (m_pid < 0) return false;
+      if (m_waitpid_result = ::waitpid(m_pid, &m_waitpid_status, opt)) {
+        m_pid = -1;
+      }
+      return true;
+    }
+    bool cancel() { return kill(SIGINT); }
+    int waitpid_result() const
+    {
+      return m_waitpid_result;
+    };
+    int waitpid_status() const
+    {
+      return m_waitpid_status;
+    };
+
+  private:
+    pid_t m_pid;
+    int m_waitpid_result;
+    int m_waitpid_status;
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/RWLock.h b/ROPCApplications/daq/slc/system/include/RWLock.h
new file mode 100644
index 0000000000000000000000000000000000000000..7f9b823a9f73a871d306844cdbf6aed15188be82
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/RWLock.h
@@ -0,0 +1,37 @@
+#ifndef _Belle2_RWLock_hh
+#define _Belle2_RWLock_hh
+
+#include <pthread.h>
+
+namespace Belle2 {
+
+  class RWLock {
+
+  public:
+    static size_t size()
+    {
+      return sizeof(pthread_rwlock_t);
+    }
+
+    // constructors and destructor
+  public:
+    RWLock();
+    ~RWLock();
+
+    // member functions;
+  public:
+    bool init();
+    bool rdlock();
+    bool wrlock();
+    bool unlock();
+    bool destroy();
+
+    // data members;
+  private:
+    pthread_rwlock_t m_lock;
+
+  };
+
+};
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/SharedMemory.h b/ROPCApplications/daq/slc/system/include/SharedMemory.h
new file mode 100644
index 0000000000000000000000000000000000000000..7e09380570cb7fd33bcd043c5e168407b135532a
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/SharedMemory.h
@@ -0,0 +1,51 @@
+#ifndef _Belle2_SharedMemory_h
+#define _Belle2_SharedMemory_h
+
+#include <string>
+
+namespace Belle2 {
+
+  class SharedMemory {
+
+  public:
+    static bool unlink(const std::string& path);
+
+    // constructors and destructor
+  public:
+    SharedMemory();
+    SharedMemory(const std::string& path, size_t size);
+    SharedMemory(const SharedMemory&);
+    ~SharedMemory();
+
+    // member functions;
+  public:
+    bool open(const std::string& path, size_t size);
+    bool open();
+    void close();
+    bool unlink();
+    bool seekTo(size_t);
+    bool seekBy(size_t);
+    void* map(size_t, size_t);
+    void* map();
+    bool isOpened();
+    const std::string& getPath() const { return m_path; }
+    size_t size() const { return m_size; }
+    int getfd() const { return m_fd; }
+    bool truncate(size_t size);
+
+    // operators
+  public:
+    const SharedMemory& operator=(const SharedMemory&);
+
+    // data members;
+  private:
+    int m_fd;
+    std::string m_path;
+    size_t m_size;
+    void* m_addr;
+
+  };
+
+};
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/StreamSizeCounter.h b/ROPCApplications/daq/slc/system/include/StreamSizeCounter.h
new file mode 100644
index 0000000000000000000000000000000000000000..ebd7dc3fb89730f31a16ad40921c93969aadc43c
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/StreamSizeCounter.h
@@ -0,0 +1,28 @@
+#ifndef _Belle2_StreamSizeCounter_hh
+#define _Belle2_StreamSizeCounter_hh
+
+#include "daq/slc/base//Writer.h"
+
+namespace Belle2 {
+
+  class StreamSizeCounter : public Writer {
+
+  public:
+    StreamSizeCounter() : m_count(0) {}
+    virtual ~StreamSizeCounter() {}
+
+  public:
+    virtual size_t write(const void*, size_t);
+    virtual bool available() { return true; }
+    void reset() { m_count = 0; }
+    int count() const { return m_count; }
+
+  private:
+    size_t m_count;
+
+  };
+
+}
+
+#endif
+
diff --git a/ROPCApplications/daq/slc/system/include/TCPServerSocket.h b/ROPCApplications/daq/slc/system/include/TCPServerSocket.h
new file mode 100644
index 0000000000000000000000000000000000000000..0cc291d524594dd4f715de42c9a1cce21dd08829
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/TCPServerSocket.h
@@ -0,0 +1,36 @@
+#ifndef _B2ARICH_TCPServerSocket_hh_
+#define _B2ARICH_TCPServerSocket_hh_
+
+#include "daq/slc/system/TCPSocket.h"
+#include "daq/slc/system/FileDescriptor.h"
+
+namespace Belle2 {
+
+  class TCPServerSocket : public FileDescriptor {
+
+  public:
+    TCPServerSocket()
+      : m_ip(""), m_port(0) {}
+    TCPServerSocket(const std::string& ip, unsigned short port)
+      : m_ip(ip), m_port(port) {}
+    virtual ~TCPServerSocket() {}
+
+  public:
+    void setIP(const std::string& ip) { m_ip = ip; }
+    void setPort(unsigned short port) { m_port = port; }
+    const std::string& getIP() const { return m_ip; }
+    unsigned short getPort() const { return m_port; }
+    int open(int nqueue = 5);
+    int open(const std::string& ip, unsigned short port, int nqueue = 5);
+    TCPSocket accept();
+
+  private:
+    std::string m_ip;
+    unsigned short m_port;
+
+  };
+
+}
+
+#endif
+
diff --git a/ROPCApplications/daq/slc/system/include/TCPSocket.h b/ROPCApplications/daq/slc/system/include/TCPSocket.h
new file mode 100644
index 0000000000000000000000000000000000000000..9557509a8742ad2616e2ab2875199fdad9106b51
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/TCPSocket.h
@@ -0,0 +1,51 @@
+#ifndef _B2ARICH_TCPSocket_hh_
+#define _B2ARICH_TCPSocket_hh_
+
+#include <string>
+
+#include "daq/slc/system/FileDescriptor.h"
+
+namespace Belle2 {
+
+  class TCPSocket : public FileDescriptor {
+
+    friend class TCPServerSocket;
+
+  public:
+    TCPSocket() : m_ip(""), m_port(0) {}
+    TCPSocket(const std::string& ip, unsigned short port)
+      : m_ip(ip), m_port(port) {}
+    virtual ~TCPSocket() {}
+
+  private:
+    TCPSocket(int fd) : FileDescriptor(fd), m_ip(""), m_port(0) {}
+
+  public:
+    void setIP(const std::string& ip) { m_ip = ip; }
+    void setPort(unsigned short port) { m_port = port; }
+    const std::string& getIP() const { return m_ip; }
+    unsigned short getPort() const { return m_port; }
+    int connect();
+    int connect(const std::string& ip, unsigned short port);
+    void setBufferSize(int size);
+    void print();
+    const std::string getLocalIP();
+    int getLocalAddress();
+    int getLocalPort();
+    unsigned int getAddress();
+
+  public:
+    virtual size_t write(const void* v, size_t count);
+    virtual size_t read(void* v, size_t count);
+    size_t read_once(void* v, size_t count);
+
+  private:
+    std::string m_ip;
+    unsigned short m_port;
+
+  };
+
+}
+
+#endif
+
diff --git a/ROPCApplications/daq/slc/system/include/TCPSocketReader.h b/ROPCApplications/daq/slc/system/include/TCPSocketReader.h
new file mode 100644
index 0000000000000000000000000000000000000000..c1aa6e284105895fa63250dbbaf5f05d750075b1
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/TCPSocketReader.h
@@ -0,0 +1,13 @@
+#ifndef _Belle2_TCPSocketReader_hh
+#define _Belle2_TCPSocketReader_hh
+
+#include "daq/slc/system/FileReader.h"
+#include "daq/slc/system/TCPSocket.h"
+
+namespace Belle2 {
+
+  typedef FileReader<TCPSocket> TCPSocketReader;
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/TCPSocketWriter.h b/ROPCApplications/daq/slc/system/include/TCPSocketWriter.h
new file mode 100644
index 0000000000000000000000000000000000000000..b9fc1a9a525b11731c76d4003f14ad5f7dad9ace
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/TCPSocketWriter.h
@@ -0,0 +1,13 @@
+#ifndef _Belle2_TCPSocketWriter_hh
+#define _Belle2_TCPSocketWriter_hh
+
+#include "daq/slc/system/FileWriter.h"
+#include "daq/slc/system/TCPSocket.h"
+
+namespace Belle2 {
+
+  typedef FileWriter<TCPSocket> TCPSocketWriter;
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/Time.h b/ROPCApplications/daq/slc/system/include/Time.h
new file mode 100644
index 0000000000000000000000000000000000000000..aafc87b5841582de1aa9410e9095149fb9022d3c
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/Time.h
@@ -0,0 +1,54 @@
+#ifndef Time_hh
+#define Time_hh
+
+#include "daq/slc/base/Serializable.h"
+
+#include <string>
+
+namespace Belle2 {
+
+  class Time : public Serializable {
+
+    // constructors & destructors
+  public:
+    explicit Time();
+    Time(const double);
+    Time(const long, const long);
+    ~Time();
+
+    // member methods
+  private:
+    void adjust();
+
+  public:
+    void clear();
+    void set();
+    void set(const double);
+    void set(const long, const long);
+    double get() const;
+    long getSecond() const;
+    long getMicroSecond() const;
+    std::string toString() const;
+
+    // for serialization
+  public:
+    virtual void readObject(Reader&);
+    virtual void writeObject(Writer&) const;
+
+    // operators
+  public:
+    Time& operator = (const Time&);
+    bool operator == (const Time&) const;
+    Time operator + (const Time&) const;
+    Time operator - (const Time&) const;
+
+    // member data
+  private:
+    long m_s;
+    long m_us;
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/daq/slc/system/include/UDPSocket.h b/ROPCApplications/daq/slc/system/include/UDPSocket.h
new file mode 100644
index 0000000000000000000000000000000000000000..c7aac6da020c8c811f377bbc37902ac1679269d0
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/include/UDPSocket.h
@@ -0,0 +1,55 @@
+#ifndef _B2ARICH_UDPSocket_hh_
+#define _B2ARICH_UDPSocket_hh_
+
+#include <string>
+
+#include <netinet/in.h>
+
+#include "daq/slc/system/FileDescriptor.h"
+
+namespace Belle2 {
+
+  class UDPSocket : public FileDescriptor {
+
+    friend class TCPServerSocket;
+
+  public:
+    UDPSocket();
+    UDPSocket(unsigned int port);
+    UDPSocket(unsigned int port,
+              const std::string& hostname,
+              bool boardcast = false);
+    UDPSocket(unsigned int port,
+              unsigned int addr,
+              bool boardcast = false);
+    virtual ~UDPSocket() {}
+
+  public:
+    int bind();
+    int bind(unsigned int port,
+             const std::string& hostname = "",
+             bool broadcast = true);
+    const std::string getHostName() const;
+    unsigned int getPort() const;
+    unsigned int getAddress() const;
+    const std::string getRemoteHostName() const;
+    unsigned int getRemotePort() const;
+    unsigned int getRemoteAddress() const;
+
+  public:
+    virtual size_t write(const void* v, size_t count);
+    virtual size_t read(void* v, size_t count);
+
+  private:
+    struct sockaddr_in m_addr;
+    struct sockaddr_in m_remote_addr;
+
+  private:
+    static unsigned int findSubnet(unsigned int addr);
+
+  };
+
+}
+
+#endif
+
diff --git a/ROPCApplications/daq/slc/system/src/Buffer.cc b/ROPCApplications/daq/slc/system/src/Buffer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a795358d0363848193d1e9153bc6d0584dc8366b
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/Buffer.cc
@@ -0,0 +1,57 @@
+#include "daq/slc/system/Buffer.h"
+
+#include <cstring>
+
+using namespace Belle2;
+
+Buffer::Buffer() : m_memory(NULL), m_size(0), m_allocated(false) {}
+
+Buffer::Buffer(unsigned int size, unsigned char* memory)
+  : m_memory(memory), m_size(size), m_allocated(false)
+{
+  if (memory == NULL && size > 0) {
+    m_memory = new unsigned char[size];
+    ::memset(m_memory, 0, size);
+    m_allocated = true;
+  }
+}
+
+Buffer::Buffer(const Buffer& buf)
+  : m_memory(NULL), m_size(buf.m_size),
+    m_allocated(buf.m_allocated)
+{
+  if (m_allocated) {
+    m_memory = new unsigned char [buf.m_size];
+    ::memset(m_memory, 0, buf.m_size);
+    ::memcpy(m_memory, buf.m_memory, buf.m_size);
+  } else {
+    m_memory = buf.m_memory;
+  }
+  m_size = buf.m_size;
+}
+
+Buffer::~Buffer()
+{
+  if (m_allocated && m_memory != NULL) {
+    delete [] m_memory;
+    m_allocated = false;
+    m_memory = NULL;
+  }
+}
+
+const Buffer& Buffer::operator=(const Buffer& buf)
+{
+  if (m_allocated) {
+    delete [] m_memory;
+  }
+  m_allocated = buf.m_allocated;
+  if (m_allocated) {
+    m_memory = new unsigned char [buf.m_size];
+    ::memset(m_memory, 0, buf.m_size);
+    ::memcpy(m_memory, buf.m_memory, buf.m_size);
+  } else {
+    m_memory = buf.m_memory;
+  }
+  m_size = buf.m_size;
+  return *this;
+}
diff --git a/ROPCApplications/daq/slc/system/src/BufferedReader.cc b/ROPCApplications/daq/slc/system/src/BufferedReader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..62332a0f0d958daf73d9fd3e0cb06d905c062be1
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/BufferedReader.cc
@@ -0,0 +1,80 @@
+#include "daq/slc/system/BufferedReader.h"
+
+#include <daq/slc/base/IOException.h>
+
+#include <cstring>
+
+using namespace Belle2;
+
+BufferedReader::BufferedReader()
+  : m_memory(NULL), m_size(0), m_pos(0), m_allocated(false) {}
+
+BufferedReader::BufferedReader(const BufferedReader& reader)
+  : m_memory(NULL), m_size(reader.m_size),
+    m_pos(reader.m_pos), m_allocated(reader.m_allocated)
+{
+  if (m_allocated) {
+    m_memory = new unsigned char [reader.m_size];
+    ::memcpy(m_memory, reader.m_memory, reader.m_size);
+  } else {
+    m_memory = reader.m_memory;
+  }
+  m_size = reader.m_size;
+  m_pos = reader.m_pos;
+}
+
+BufferedReader::BufferedReader(size_t size, unsigned char* memory)
+  : m_memory(memory), m_size(size), m_pos(0), m_allocated(false)
+{
+  if (memory == NULL) {
+    m_memory = new unsigned char[size];
+    m_allocated = true;
+  }
+}
+
+BufferedReader::~BufferedReader()
+{
+  if (m_allocated && m_memory != NULL) {
+    delete [] m_memory;
+  }
+}
+
+const BufferedReader& BufferedReader::operator=(const BufferedReader& reader)
+{
+  if (m_allocated) {
+    delete [] m_memory;
+  }
+  m_allocated = reader.m_allocated;
+  if (m_allocated) {
+    m_memory = new unsigned char [reader.m_size];
+    ::memcpy(m_memory, reader.m_memory, reader.m_size);
+  } else {
+    m_memory = reader.m_memory;
+  }
+  m_size = reader.m_size;
+  m_pos = reader.m_pos;
+  return *this;
+}
+
+void BufferedReader::copy(const void* buffer, size_t count)
+{
+  if (count < m_size) {
+    memcpy(m_memory, buffer, count);
+    m_pos = 0;
+  } else {
+    throw (IOException("Out of buffer range: %d > %d",
+                       (int)count, (int)m_size));
+  }
+}
+
+size_t BufferedReader::read(void* buf, const size_t count)
+{
+  if (m_pos + count > size()) {
+    throw (IOException("Out of buffer range: %d + %d > %d",
+                       (int)m_pos, (int)count, (int)m_size));
+  }
+  memcpy(buf, (m_memory + m_pos), count);
+  m_pos += count;
+  return count;
+}
+
diff --git a/ROPCApplications/daq/slc/system/src/BufferedWriter.cc b/ROPCApplications/daq/slc/system/src/BufferedWriter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9f9b6a0057be833931701e1d395fc6473337bbe4
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/BufferedWriter.cc
@@ -0,0 +1,67 @@
+#include "daq/slc/system/BufferedWriter.h"
+
+#include <daq/slc/base/IOException.h>
+
+#include <cstring>
+
+using namespace Belle2;
+
+BufferedWriter::BufferedWriter()
+  : m_memory(NULL), m_size(0), m_pos(0), m_allocated(false) {}
+
+BufferedWriter::BufferedWriter(size_t size, unsigned char* memory)
+  : m_memory(memory), m_size(size), m_pos(0), m_allocated(false)
+{
+  if (memory == NULL) {
+    m_memory = new unsigned char[size];
+    m_allocated = true;
+  }
+}
+
+BufferedWriter::BufferedWriter(const BufferedWriter& writer)
+  : m_memory(NULL), m_size(writer.m_size),
+    m_pos(writer.m_pos), m_allocated(writer.m_allocated)
+{
+  if (m_allocated) {
+    m_memory = new unsigned char [writer.m_size];
+    ::memcpy(m_memory, writer.m_memory, writer.m_size);
+  } else {
+    m_memory = writer.m_memory;
+  }
+  m_size = writer.m_size;
+  m_pos = writer.m_pos;
+}
+
+BufferedWriter::~BufferedWriter()
+{
+  if (m_allocated && m_memory != NULL) delete [] m_memory;
+}
+
+const BufferedWriter& BufferedWriter::operator=(const BufferedWriter& writer)
+{
+  if (m_allocated) {
+    delete [] m_memory;
+  }
+  m_allocated = writer.m_allocated;
+  if (m_allocated) {
+    m_memory = new unsigned char [writer.m_size];
+    ::memcpy(m_memory, writer.m_memory, writer.m_size);
+  } else {
+    m_memory = writer.m_memory;
+  }
+  m_size = writer.m_size;
+  m_pos = writer.m_pos;
+  return *this;
+}
+
+size_t BufferedWriter::write(const void* buf, const size_t count)
+{
+  if (m_pos + count > m_size) {
+    throw (IOException("out of buffer range: %d+%d>%d",
+                       (int)m_pos, (int)count, (int)m_size));
+  }
+  memcpy((m_memory + m_pos), buf, count);
+  m_pos += count;
+  return count;
+}
+
diff --git a/ROPCApplications/daq/slc/system/src/Cond.cc b/ROPCApplications/daq/slc/system/src/Cond.cc
new file mode 100644
index 0000000000000000000000000000000000000000..76d3c2beae5d7d6a8b4bfadaf1d2e99bed12f9e2
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/Cond.cc
@@ -0,0 +1,70 @@
+#include "daq/slc/system/Cond.h"
+
+#include <pthread.h>
+#include <sys/time.h>
+
+using namespace Belle2;
+
+Cond::Cond()
+{
+  init();
+}
+
+Cond::Cond(const Cond& cond)
+{
+  m_cond_t = cond.m_cond_t;
+}
+
+bool Cond::init()
+{
+  pthread_condattr_t mattr;
+  pthread_condattr_init(&mattr);
+  pthread_condattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
+  if (pthread_cond_init(&m_cond_t, &mattr) != 0) {
+    return false;
+  }
+  pthread_condattr_destroy(&mattr);
+
+  return true;
+}
+
+bool Cond::signal()
+{
+  if (pthread_cond_signal(&m_cond_t) == 0) return true;
+  else return false;
+}
+
+bool Cond::broadcast()
+{
+  if (pthread_cond_broadcast(&m_cond_t) == 0) return true;
+  else return false;
+}
+
+bool Cond::wait(Mutex& mutex)
+{
+  if (pthread_cond_wait(&m_cond_t, &mutex.m_mu) != 0) {
+    return false;
+  }
+  return true;
+}
+
+bool Cond::wait(Mutex& mutex, const unsigned int sec, const unsigned int msec)
+{
+  struct timeval now;
+  struct timespec timeout;
+
+  gettimeofday(&now, NULL);
+  timeout.tv_sec = now.tv_sec + sec;
+  timeout.tv_nsec = now.tv_usec * 1000 + msec;
+  int stat = 0;
+  if ((stat = pthread_cond_timedwait(&m_cond_t, &mutex.m_mu, &timeout)) != 0) {
+    return false;
+  }
+  return true;
+}
+
+bool Cond::destroy()
+{
+  if (pthread_cond_destroy(&m_cond_t) == 0) return true;
+  else return false;
+}
diff --git a/ROPCApplications/daq/slc/system/src/Daemon.cc b/ROPCApplications/daq/slc/system/src/Daemon.cc
new file mode 100644
index 0000000000000000000000000000000000000000..38f84601535ba2e72fb50ba29c925ba036a0ece9
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/Daemon.cc
@@ -0,0 +1,46 @@
+#include "daq/slc/system/Daemon.h"
+
+#include <daq/slc/system/LogFile.h>
+
+#include <daq/slc/base/StringUtil.h>
+
+#include <unistd.h>
+#include <cstring>
+
+using namespace Belle2;
+
+bool Daemon::start(const char* title,
+                   int argc, char** argv,
+                   int nargc, const char* msg)
+{
+  g_argc = argc;
+  g_argv = argv;
+  bool isdaemon = false;
+  for (int i = 1; i < argc; i++) {
+    if (strcmp(argv[i], "-d") == 0) {
+      isdaemon = true;
+      nargc++;
+    } else if (strcmp(argv[i], "-h") == 0) {
+      LogFile::debug("Usage : %s %s [-d]", argv[0], msg);
+      return false;
+    }
+  }
+  if (argc < nargc + 1) {
+    LogFile::debug("Usage : %s %s [-d]", argv[0], msg);
+    return false;
+  }
+  LogFile::open(StringUtil::form("%s/%s", argv[0], title));
+  if (isdaemon) {
+    daemon(0, 0);
+  }
+  return true;
+}
+
+
+bool Daemon::restart()
+{
+  return execv(g_argv[0], g_argv) != -1;
+}
+
+int Daemon::g_argc = 0;
+char** Daemon::g_argv = NULL;
diff --git a/ROPCApplications/daq/slc/system/src/DynamicLoadException.cc b/ROPCApplications/daq/slc/system/src/DynamicLoadException.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0fcf2eacd5eea0b373b32669372adfd418874163
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/DynamicLoadException.cc
@@ -0,0 +1,17 @@
+#include "daq/slc/system/DynamicLoadException.h"
+
+#include <cstdarg>
+#include <cstdio>
+
+using namespace Belle2;
+
+DynamicLoadException::DynamicLoadException(const std::string& format, ...)
+{
+  va_list ap;
+  char ss[1024 * 100];
+  va_start(ap, format);
+  vsprintf(ss, format.c_str(), ap);
+  va_end(ap);
+  m_comment = ss;
+}
+
diff --git a/ROPCApplications/daq/slc/system/src/DynamicLoader.cc b/ROPCApplications/daq/slc/system/src/DynamicLoader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..62be20d0c3a3a7c3699d2d91564584c3331f47d7
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/DynamicLoader.cc
@@ -0,0 +1,38 @@
+#include "daq/slc/system/DynamicLoader.h"
+#include "daq/slc/system/DynamicLoadException.h"
+
+#include <dlfcn.h>
+
+using namespace Belle2;
+
+DynamicLoader::~DynamicLoader()
+{
+}
+
+void DynamicLoader::close()
+{
+  if (m_handle != NULL) {
+    dlclose(m_handle);
+    m_handle = NULL;
+  }
+}
+
+void* DynamicLoader::open(const std::string& lib_path)
+{
+  void* handle = dlopen(lib_path.c_str(), RTLD_LAZY);
+  if (!handle) {
+    throw (DynamicLoadException("dlopen: %s", dlerror()));
+  }
+  m_handle = handle;
+  return handle;
+}
+
+void* DynamicLoader::load(const std::string& funcname)
+{
+  char* error = NULL;
+  void* func = dlsym(m_handle, funcname.c_str());
+  if ((error = dlerror()) != NULL) {
+    throw (DynamicLoadException("dlopen: %s", error));
+  }
+  return func;
+}
diff --git a/ROPCApplications/daq/slc/system/src/Executor.cc b/ROPCApplications/daq/slc/system/src/Executor.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4c48b6c3a80094a57713c0e24ae2885a86c2dac7
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/Executor.cc
@@ -0,0 +1,59 @@
+#include "daq/slc/system/Executor.h"
+#include "daq/slc/system/LogFile.h"
+
+#include <iostream>
+#include <cstdarg>
+#include <cstdio>
+#include <unistd.h>
+
+using namespace Belle2;
+
+void Executor::setExecutable(const char* format, ...)
+{
+  va_list ap;
+  static char ss[1024];
+  va_start(ap, format);
+  vsprintf(ss, format, ap);
+  va_end(ap);
+  m_path = ss;
+}
+
+void Executor::setExecutable(const std::string& path)
+{
+  m_path = path;
+}
+
+void Executor::addArg(const char* format, ...)
+{
+  va_list ap;
+  static char ss[1024];
+  va_start(ap, format);
+  vsprintf(ss, format, ap);
+  va_end(ap);
+  m_arg_v.push_back(ss);
+}
+
+void Executor::addArg(const std::string& arg)
+{
+  m_arg_v.push_back(arg);
+}
+
+bool Executor::execute(bool isdaemon)
+{
+  char* argv[256];
+  argv[0] = (char*)m_path.c_str();
+  std::cerr << "" << argv[0] << " ";
+  for (size_t i = 0; i < m_arg_v.size(); i++) {
+    argv[i + 1] = (char*)m_arg_v[i].c_str();
+    std::cerr << "" << argv[i + 1] << " ";
+  }
+  std::cerr << std::endl;
+  argv[m_arg_v.size() + 1] = NULL;
+  if (isdaemon) daemon(0, 0);
+  if (execvp(m_path.c_str(), argv) == -1) {
+    LogFile::error("Faield to start %s", argv[0]);
+    return false;
+  }
+
+  return true;
+}
diff --git a/ROPCApplications/daq/slc/system/src/Fifo.cc b/ROPCApplications/daq/slc/system/src/Fifo.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ac3836059ce6b4dda8a3c01990be263fb3dc40ba
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/Fifo.cc
@@ -0,0 +1,52 @@
+#include "daq/slc/system/Fifo.h"
+
+#include <daq/slc/base/IOException.h>
+
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <cstdio>
+
+using namespace Belle2;
+
+Fifo Fifo::mkfifo(const std::string& path)
+{
+  ::mkfifo(path.c_str(), 0666);
+  Fifo fifo;
+  fifo.open(path.c_str());
+  return fifo;
+}
+
+void Fifo::open(const std::string& path, const std::string& mode_s)
+{
+  int mode = O_RDONLY;
+  if (mode_s.find("w") != std::string::npos) {
+    mode = O_WRONLY;
+    if (mode_s.find("r") != std::string::npos) {
+      mode = O_RDWR;
+    }
+  }
+  if ((m_fd = ::open(path.c_str(), mode)) < 0) {
+    perror("open");
+    throw (IOException("Failed to open fifo."));
+  }
+}
+
+void Fifo::unlink(const std::string& path)
+{
+  if ((::unlink(path.c_str())) < 0) {
+    perror("unlink");
+  }
+  close();
+}
+
+size_t Fifo::write(const void* buf, size_t count)
+{
+  return ::write(m_fd, buf, count);
+}
+
+size_t Fifo::read(void* buf, size_t count)
+{
+  return ::read(m_fd, buf, count);
+}
diff --git a/ROPCApplications/daq/slc/system/src/File.cc b/ROPCApplications/daq/slc/system/src/File.cc
new file mode 100644
index 0000000000000000000000000000000000000000..53e14be70861a54b9331d25581e8e35d6e949019
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/File.cc
@@ -0,0 +1,97 @@
+#include "daq/slc/system/File.h"
+
+#include <daq/slc/base/IOException.h>
+
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <cstdio>
+
+using namespace Belle2;
+
+void File::open(const std::string& path, const std::string& mode_s)
+{
+  int mode = O_RDONLY;
+  if (mode_s.find("w") != std::string::npos) {
+    mode = O_WRONLY;
+    if (mode_s.find("r") != std::string::npos) {
+      mode = O_RDWR;
+    } else {
+      mode |= O_CREAT;
+    }
+  }
+  if ((m_fd = ::open(path.c_str(), mode, 0666)) < 0) {
+    perror("open");
+    throw (IOException("Failed to open file : %s", path.c_str()));
+  }
+}
+
+void File::unlink(const std::string& path)
+{
+  if ((::unlink(path.c_str())) < 0) {
+    perror("unlink");
+  }
+  close();
+}
+
+size_t File::write(const void* buf, size_t count)
+{
+  size_t c = 0;
+  int ret;
+  while (c < count) {
+    errno = 0;
+    ret = ::write(m_fd, ((unsigned char*)buf + c), (count - c));
+    if (ret <= 0) {
+      switch (errno) {
+        case EINTR: continue;
+        case ENETUNREACH:
+        case EHOSTUNREACH:
+        case ETIMEDOUT:
+          usleep(500);
+          continue;
+        default:
+          throw (IOException("Error while writing"));
+      }
+    }
+    c += ret;
+  }
+  return c;
+}
+
+size_t File::read(void* buf, size_t count)
+{
+  size_t c = 0;
+  int ret;
+  while (c < count) {
+    errno = 0;
+    ret = ::read(m_fd, ((unsigned char*)buf + c), (count - c));
+    if (ret <= 0) {
+      switch (errno) {
+        case EINTR: continue;
+        case EAGAIN: continue;
+        default:
+          throw (IOException("Error while reading. %d", errno));
+      }
+    }
+    c += ret;
+  }
+  return c;
+}
+
+bool File::exist(const std::string& filename)
+{
+  struct stat st;
+  if (stat(filename.c_str(), &st) != 0) {
+    return false;
+  } else {
+    mode_t m = st.st_mode;
+    if (S_ISDIR(m)) {
+      return false;
+    } else {
+      return true;
+    }
+  }
+  return false;
+}
diff --git a/ROPCApplications/daq/slc/system/src/FileDescriptor.cc b/ROPCApplications/daq/slc/system/src/FileDescriptor.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c5550ad85900a568861ce86198416c0ac3210229
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/FileDescriptor.cc
@@ -0,0 +1,97 @@
+#include "daq/slc/system/FileDescriptor.h"
+
+#include <daq/slc/base/IOException.h>
+
+#include <unistd.h>
+#include <sys/select.h>
+#include <stdio.h>
+
+using namespace Belle2;
+
+FileDescriptor::FileDescriptor()
+{
+  m_fd = -1;
+}
+
+FileDescriptor::FileDescriptor(const FileDescriptor& fd)
+{
+  m_fd = fd.m_fd;
+}
+
+FileDescriptor::FileDescriptor(int fd)
+{
+  m_fd = fd;
+}
+
+FileDescriptor::~FileDescriptor()
+{
+
+}
+
+int FileDescriptor::get_fd() const
+{
+  return m_fd;
+}
+
+bool FileDescriptor::select(int sec, int usec)
+{
+  if (m_fd <= 0) {
+    return false;
+  }
+  fd_set fds;
+  FD_ZERO(&fds);
+  FD_SET(m_fd, &fds);
+  int ret;
+  if (sec >= 0 && usec >= 0) {
+    timeval t = {sec, usec};
+    ret = ::select(FD_SETSIZE, &fds, NULL, NULL, &t);
+  } else {
+    ret = ::select(FD_SETSIZE, &fds, NULL, NULL, NULL);
+  }
+  if (ret < 0) {
+    perror("select");
+    throw (IOException("Failed to select"));
+  }
+  if (FD_ISSET(m_fd, &fds)) {
+    return true;
+  } else {
+    return false;
+  }
+}
+
+bool FileDescriptor::select2(int sec, int usec)
+{
+  if (m_fd <= 0) {
+    return false;
+  }
+  fd_set fds;
+  FD_ZERO(&fds);
+  FD_SET(m_fd, &fds);
+  int ret;
+  if (sec >= 0 && usec >= 0) {
+    timeval t = {sec, usec};
+    ret = ::select(FD_SETSIZE, NULL, &fds, NULL, &t);
+  } else {
+    ret = ::select(FD_SETSIZE, NULL, &fds, NULL, NULL);
+  }
+  if (ret < 0) {
+    perror("select");
+    throw (IOException("Failed to select"));
+  }
+  if (FD_ISSET(m_fd, &fds)) {
+    return true;
+  } else {
+    return false;
+  }
+}
+
+bool FileDescriptor::close()
+{
+  if (m_fd > 0) {
+    if (::close(m_fd) != 0) {
+      return false;
+    }
+  }
+  m_fd = -1;
+  return true;
+}
diff --git a/ROPCApplications/daq/slc/system/src/Inotify.cc b/ROPCApplications/daq/slc/system/src/Inotify.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3a200a49566ae74c9302c87670f1295aa9a146e3
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/Inotify.cc
@@ -0,0 +1,62 @@
+#include "daq/slc/system/Inotify.h"
+
+#include <daq/slc/base/IOException.h>
+
+#include <sys/inotify.h>
+#include <unistd.h>
+
+using namespace Belle2;
+
+const unsigned long Inotify::FILE_CREATE(IN_CREATE);
+const unsigned long Inotify::FILE_OPEN(IN_OPEN);
+const unsigned long Inotify::FILE_CLOSE_WRITE(IN_CLOSE_WRITE);
+const unsigned long Inotify::FILE_CLOSE_NOWRITE(IN_CLOSE_NOWRITE);
+const unsigned long Inotify::FILE_DELETE(IN_DELETE);
+const unsigned long Inotify::FILE_MODIFY(IN_MODIFY);
+const unsigned long Inotify::FILE_ACCESS(IN_ACCESS);
+const unsigned long Inotify::FILE_ATTRIB(IN_ATTRIB);
+
+void Inotify::open()
+{
+  if ((m_fd = ::inotify_init()) < 0) {
+    throw (IOException("Failed to initialize inotify."));
+  }
+}
+
+int Inotify::add(const std::string& path, unsigned long mask)
+{
+  int wd = inotify_add_watch(m_fd, path.c_str(), mask);
+  if (wd < 0) {
+    throw (IOException("Failed to add a path"));
+  }
+  return wd;
+}
+
+void Inotify::remove(int wd)
+{
+  if (::inotify_rm_watch(m_fd, wd) < 0) {
+    throw (IOException("Failed to remove a path"));
+  }
+}
+
+InotifyEventList Inotify::wait(int sec)
+{
+  InotifyEventList ievent_v;
+  //try {
+  if (select(sec, 0)) {
+    char buf[16384];
+    int r = read(m_fd, buf, 16384);
+    if (r <= 0) return ievent_v;
+    int index = 0;
+    while (index < r) {
+      inotify_event* ev = (inotify_event*)&buf[index];
+      int event_size =  sizeof(inotify_event) + ev->len;
+      index += event_size;
+      ievent_v.push_back(InotifyEvent(ev->wd, ev->mask, ev->name));
+    }
+  }
+  //} catch (const IOException& e) {
+  //std::cerr << "Failed to select" << std::endl;
+  //}
+  return ievent_v;
+}
diff --git a/ROPCApplications/daq/slc/system/src/LogFile.cc b/ROPCApplications/daq/slc/system/src/LogFile.cc
new file mode 100644
index 0000000000000000000000000000000000000000..98f45356138126d963cb83b921ba632d7cac96b0
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/LogFile.cc
@@ -0,0 +1,180 @@
+#include "daq/slc/system/LogFile.h"
+
+#include <daq/slc/base/ConfigFile.h>
+#include <daq/slc/base/StringUtil.h>
+
+#include <iostream>
+#include <sstream>
+#include <cstdio>
+
+#include <sys/stat.h>
+#include <cstdlib>
+#include <daq/slc/system/LockGuard.h>
+
+using namespace Belle2;
+
+bool LogFile::g_stderr = true;
+bool LogFile::g_opened = false;
+std::string LogFile::g_filepath;
+std::string LogFile::g_linkpath;
+std::ofstream LogFile::g_stream;
+unsigned int LogFile::g_filesize = 0;
+Mutex LogFile::g_mutex;
+LogFile::Priority LogFile::g_threshold;
+std::string LogFile::g_filename;
+Date LogFile::g_date;
+
+LogFile::Priority LogFile::getPriority(const std::string& str)
+{
+  const std::string s = StringUtil::toupper(str);
+  if (s == "DEBUG") {
+    return DEBUG;
+  } else if (s == "INFO") {
+    return INFO;
+  } else if (s == "NOTICE") {
+    return NOTICE;
+  } else if (s == "WARNING") {
+    return WARNING;
+  } else if (s == "ERROR") {
+    return ERROR;
+  } else if (s == "FATAL") {
+    return FATAL;
+  }
+  return UNKNOWN;
+}
+
+void LogFile::open(const std::string& filename, Priority threshold)
+{
+  if (!g_opened) {
+    ConfigFile config("slowcontrol");
+    std::string path = config.get("log.dir");
+    //if (path.size() == 0) path = config.get("logfile.dir");
+    system(("mkdir -p " + path + "/" + filename).c_str());
+    g_filename = filename;
+    g_date = Date();
+    g_filepath = path + StringUtil::form("/%s/%s.log", filename.c_str(), g_date.toString("%Y.%m.%d"));
+    g_linkpath = path + StringUtil::form("/%s/latest.log", filename.c_str());
+    //"/latest.log";
+    g_threshold = threshold;
+    g_opened = true;
+    open();
+  }
+}
+
+void LogFile::open()
+{
+  if (!g_opened) return;
+  struct stat st;
+  if (stat(g_filepath.c_str(), &st) == 0) {
+    g_filesize = st.st_size;
+    g_stream.open(g_filepath.c_str(), std::ios::out | std::ios::app);
+  } else {
+    g_filesize = 0;
+    g_stream.open(g_filepath.c_str(), std::ios::out);
+  }
+  debug("/* ---------- log file opened ---------- */");
+  debug("log file : %s (%d) ", g_filepath.c_str(), g_filesize);
+  std::string cmd = "ln -sf " + g_filepath + " " + g_linkpath;
+  system(cmd.c_str());
+  debug("sym link : %s", g_linkpath.c_str());
+}
+
+void LogFile::close()
+{
+  if (!g_opened) return;
+  g_stream.close();
+  g_opened = false;
+}
+
+void LogFile::debug(const std::string& msg, ...)
+{
+  va_list ap;
+  va_start(ap, msg);
+  put_impl(msg, DEBUG, ap);
+  va_end(ap);
+}
+
+void LogFile::info(const std::string& msg, ...)
+{
+  va_list ap;
+  va_start(ap, msg);
+  put_impl(msg, INFO, ap);
+  va_end(ap);
+}
+
+void LogFile::notice(const std::string& msg, ...)
+{
+  va_list ap;
+  va_start(ap, msg);
+  put_impl(msg, NOTICE, ap);
+  va_end(ap);
+}
+
+void LogFile::warning(const std::string& msg, ...)
+{
+  va_list ap;
+  va_start(ap, msg);
+  put_impl(msg, WARNING, ap);
+  va_end(ap);
+}
+
+void LogFile::error(const std::string& msg, ...)
+{
+  va_list ap;
+  va_start(ap, msg);
+  put_impl(msg, ERROR, ap);
+  va_end(ap);
+}
+
+void LogFile::fatal(const std::string& msg, ...)
+{
+  va_list ap;
+  va_start(ap, msg);
+  put_impl(msg, FATAL, ap);
+  va_end(ap);
+}
+
+
+void LogFile::put(Priority priority, const std::string& msg, ...)
+{
+  va_list ap;
+  va_start(ap, msg);
+  put_impl(msg, priority, ap);
+  va_end(ap);
+}
+
+int LogFile::put_impl(const std::string& msg, Priority priority, va_list ap)
+{
+  LockGuard lockGuard(g_mutex);
+  if (g_threshold > priority) {
+    return 0;
+  }
+  Date date;
+  if (g_date.getDay() != date.getDay()) {
+    g_stream.close();
+    open();
+  }
+  std::stringstream ss;
+  ss << "[" << date.toString();
+  std::string color = "\x1b[49m\x1b[39m";
+  switch (priority) {
+    case DEBUG:   color = "\x1b[49m\x1b[39m"; ss << "] [DEBUG] "; break;
+    case INFO:    color = "\x1b[49m\x1b[32m"; ss << "] [INFO] "; break;
+    case NOTICE:  color = "\x1b[49m\x1b[34m"; ss << "] [NOTICE] "; break;
+    case WARNING: color = "\x1b[49m\x1b[35m"; ss << "] [WARNING] "; break;
+    case ERROR:   color = "\x1b[49m\x1b[31m"; ss << "] [ERROR] "; break;
+    case FATAL:   color = "\x1b[41m\x1b[37m"; ss << "] [FATAL] "; break;
+    default:                 ss << "] [UNKNOWN] "; break;
+  }
+  static char* s = new char[1024 * 1024 * 5];
+  vsprintf(s, msg.c_str(), ap);
+  ss << s << std::endl;
+  std::string str = ss.str();
+  std::cerr << color << str << "\x1b[49m\x1b[39m";
+  if (g_opened) {
+    g_stream << str;
+    g_stream.flush();
+    g_filesize += str.size();
+  }
+  return (int) str.size();
+}
diff --git a/ROPCApplications/daq/slc/system/src/MCond.cc b/ROPCApplications/daq/slc/system/src/MCond.cc
new file mode 100644
index 0000000000000000000000000000000000000000..32a898455e24ad0ba5ba57d54885e03a4587b671
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/MCond.cc
@@ -0,0 +1,89 @@
+#include "daq/slc/system/MCond.h"
+
+#include <sys/time.h>
+
+using namespace Belle2;
+
+MCond::MCond() {}
+
+MCond::MCond(const MCond& cond)
+{
+  *this = cond;
+}
+
+MCond::MCond(void* addr)
+{
+  set((pthread_cond_t*)addr);
+}
+
+MCond::~MCond() {}
+
+bool MCond::init(void* addr)
+{
+  set(addr);
+  init();
+  return true;
+}
+
+bool MCond::init()
+{
+  pthread_condattr_t attr;
+  pthread_condattr_init(&attr);
+  pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+  pthread_cond_init(m_cond, &attr);
+  pthread_condattr_destroy(&attr);
+  return true;
+}
+
+bool MCond::set(void* addr)
+{
+  m_cond = (pthread_cond_t*)addr;
+  return true;
+}
+
+bool MCond::destroy()
+{
+  pthread_cond_destroy(m_cond);
+  return true;
+}
+
+bool MCond::signal()
+{
+  if (pthread_cond_signal(m_cond) == 0) return true;
+  else return false;
+}
+
+bool MCond::broadcast()
+{
+  if (pthread_cond_broadcast(m_cond) == 0) return true;
+  else return false;
+}
+
+bool MCond::wait(MMutex& cond)
+{
+  if (pthread_cond_wait(m_cond, cond.m_mu) != 0) {
+    return false;
+  }
+  return true;
+}
+
+bool MCond::wait(MMutex& mutex, const unsigned int sec,
+                 const unsigned int msec)
+{
+  struct timeval now;
+  struct timespec timeout;
+
+  gettimeofday(&now, NULL);
+  timeout.tv_sec = now.tv_sec + sec;
+  timeout.tv_nsec = now.tv_usec * 1000 + msec;
+  if (pthread_cond_timedwait(m_cond, mutex.m_mu, &timeout) != 0) {
+    return false;
+  }
+  return true;
+}
+
+const MCond& MCond::operator=(const MCond& cond)
+{
+  m_cond = cond.m_cond;
+  return *this;
+}
diff --git a/ROPCApplications/daq/slc/system/src/MMutex.cc b/ROPCApplications/daq/slc/system/src/MMutex.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c7262d83b525c82c68ac4059daf402e36b5d8784
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/MMutex.cc
@@ -0,0 +1,81 @@
+#include "daq/slc/system/MMutex.h"
+
+using namespace Belle2;
+
+MMutex::MMutex() {}
+
+MMutex::MMutex(const MMutex& mutex)
+{
+  *this = mutex;
+}
+
+MMutex::MMutex(void* addr)
+{
+  set((pthread_mutex_t*)addr);
+}
+
+MMutex::~MMutex() {}
+
+bool MMutex::init(void* addr)
+{
+  set(addr);
+  init();
+  return true;
+}
+
+bool MMutex::init()
+{
+  pthread_mutexattr_t attr;
+  pthread_mutexattr_init(&attr);
+  pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+  pthread_mutex_init(m_mu, &attr);
+  pthread_mutexattr_destroy(&attr);
+  return true;
+}
+
+bool MMutex::set(void* addr)
+{
+  m_mu = (pthread_mutex_t*)addr;
+  return true;
+}
+
+bool MMutex::lock()
+{
+  if (pthread_mutex_lock(m_mu) != 0) {
+    return false;
+  } else {
+    return true;
+  }
+}
+
+bool MMutex::trylock()
+{
+  if (pthread_mutex_lock(m_mu) != 0) {
+    return false;
+  }
+  return true;
+}
+
+bool MMutex::unlock()
+{
+  if (pthread_mutex_unlock(m_mu) != 0) {
+    return true;
+  } else {
+    return false;
+  }
+}
+
+bool MMutex::destroy()
+{
+  if (pthread_mutex_destroy(m_mu) != 0) {
+    return true;
+  } else {
+    return false;
+  }
+}
+
+const MMutex& MMutex::operator=(const MMutex& mutex)
+{
+  m_mu = mutex.m_mu;
+  return *this;
+}
diff --git a/ROPCApplications/daq/slc/system/src/Mutex.cc b/ROPCApplications/daq/slc/system/src/Mutex.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5d79b22dddb982faaa4c293f6127d7b9d2f3b1e7
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/Mutex.cc
@@ -0,0 +1,29 @@
+#include "daq/slc/system/Mutex.h"
+
+using namespace Belle2;
+
+Mutex::Mutex()
+{
+  pthread_mutexattr_init(&m_attr);
+  pthread_mutex_init(&m_mu, &m_attr);
+}
+
+Mutex::~Mutex()
+{
+}
+
+bool Mutex::lock()
+{
+  if (pthread_mutex_lock(&m_mu) != 0) {
+    return false;
+  }
+  return true;
+}
+
+bool Mutex::unlock()
+{
+  if (pthread_mutex_unlock(&m_mu) != 0) {
+    return false;
+  }
+  return true;
+}
diff --git a/ROPCApplications/daq/slc/system/src/RWLock.cc b/ROPCApplications/daq/slc/system/src/RWLock.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b6697bd43b72261e160679614de1668c7781c0cb
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/RWLock.cc
@@ -0,0 +1,53 @@
+#include "daq/slc/system/RWLock.h"
+
+using namespace Belle2;
+
+RWLock::RWLock() : m_lock() {}
+
+RWLock::~RWLock() {}
+
+bool RWLock::init()
+{
+  pthread_rwlockattr_t attr;
+  pthread_rwlockattr_init(&attr);
+  pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+  pthread_rwlock_init(&m_lock, &attr);
+  pthread_rwlockattr_destroy(&attr);
+  return true;
+}
+
+bool RWLock::rdlock()
+{
+  if (pthread_rwlock_rdlock(&m_lock) != 0) {
+    return false;
+  } else {
+    return true;
+  }
+}
+
+bool RWLock::wrlock()
+{
+  if (pthread_rwlock_wrlock(&m_lock) != 0) {
+    return false;
+  }
+  return true;
+}
+
+bool RWLock::unlock()
+{
+  if (pthread_rwlock_unlock(&m_lock) != 0) {
+    return true;
+  } else {
+    return false;
+  }
+}
+
+bool RWLock::destroy()
+{
+  if (pthread_rwlock_destroy(&m_lock) != 0) {
+    return true;
+  } else {
+    return false;
+  }
+}
+
diff --git a/ROPCApplications/daq/slc/system/src/SharedMemory.cc b/ROPCApplications/daq/slc/system/src/SharedMemory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c04e3fab17e1805e81b5c7cbb0433a067b215819
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/SharedMemory.cc
@@ -0,0 +1,130 @@
+#include "daq/slc/system/SharedMemory.h"
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <errno.h>
+
+using namespace Belle2;
+
+bool SharedMemory::unlink(const std::string& path)
+{
+  return (::shm_unlink(path.c_str()) == -1);
+}
+
+SharedMemory::SharedMemory()
+  : m_fd(-1), m_path(), m_size(0), m_addr(NULL) {}
+
+SharedMemory::SharedMemory(const std::string& path, size_t size)
+  : m_fd(-1), m_path(path), m_size(size), m_addr(NULL)
+{
+}
+
+SharedMemory::SharedMemory(const SharedMemory& file)
+  : m_fd(file.m_fd),  m_path(file.m_path),
+    m_size(file.m_size), m_addr(file.m_addr) {}
+
+SharedMemory::~SharedMemory() {}
+
+bool SharedMemory::open(const std::string& path, size_t size)
+{
+  errno = 0;
+  int fd = ::shm_open(path.c_str(), O_CREAT | O_EXCL | O_RDWR, 0666);
+  if (fd < 0) {
+    if (errno != EEXIST) {
+      perror("shm_oepn");
+      return false;
+    }
+    fd = ::shm_open(path.c_str(), O_CREAT | O_RDWR, 0666);
+    if (fd < 0) {
+      perror("shm_oepn");
+      return false;
+    }
+  }
+  m_fd = fd;
+  m_path = path;
+  truncate(size);
+  return true;
+}
+
+bool SharedMemory::open()
+{
+  return open(m_path, m_size);
+}
+
+void SharedMemory::close()
+{
+  if (m_fd > 0) {
+    if (m_addr != NULL) munmap(m_addr, m_size);
+    ::close(m_fd);
+    m_fd = 0;
+  }
+}
+
+bool SharedMemory::truncate(size_t size)
+{
+  if (size > 0) {
+    ::ftruncate(m_fd, size);
+    m_size = size;
+    return true;
+  } else {
+    struct stat st;
+    fstat(m_fd, &st);
+    m_size = st.st_size;
+  }
+  return false;
+}
+
+
+void* SharedMemory::map(size_t offset, size_t size)
+{
+  errno = 0;
+  void* addr = ::mmap(NULL, size, PROT_READ | PROT_WRITE,
+                      MAP_SHARED, m_fd, offset);
+  if (addr == MAP_FAILED) {
+    perror("mmap");
+    addr = NULL;
+  }
+  m_addr = addr;
+  m_size = size;
+  return addr;
+}
+
+void* SharedMemory::map()
+{
+  if (m_addr == NULL) m_addr = map(0, m_size);
+  return m_addr;
+}
+
+bool SharedMemory::unlink()
+{
+  close();
+  return (unlink(m_path));
+}
+
+bool SharedMemory::seekTo(size_t offset)
+{
+  return (lseek(m_fd, offset, SEEK_SET) == -1);
+}
+
+bool SharedMemory::seekBy(size_t offset)
+{
+  return (lseek(m_fd, offset, SEEK_CUR) == -1);
+}
+
+bool SharedMemory::isOpened()
+{
+  return (m_fd != 0);
+}
+
+const SharedMemory& SharedMemory::operator=(const SharedMemory& file)
+{
+  m_fd = file.m_fd;
+  m_path = file.m_path;
+  m_size = file.m_size;
+  m_addr = file.m_addr;
+  return *this;
+}
+
diff --git a/ROPCApplications/daq/slc/system/src/StreamSizeCounter.cc b/ROPCApplications/daq/slc/system/src/StreamSizeCounter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6828bd474c20240f3dd6c356ae4c5bbca591ad73
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/StreamSizeCounter.cc
@@ -0,0 +1,9 @@
+#include "daq/slc/system/StreamSizeCounter.h"
+
+using namespace Belle2;
+
+size_t StreamSizeCounter::write(const void*, size_t count)
+{
+  m_count += count;
+  return count;
+}
diff --git a/ROPCApplications/daq/slc/system/src/TCPServerSocket.cc b/ROPCApplications/daq/slc/system/src/TCPServerSocket.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d1bc9aa0a863617fe3f5f7c57893af28db90c880
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/TCPServerSocket.cc
@@ -0,0 +1,97 @@
+#include "daq/slc/system/TCPServerSocket.h"
+
+#include <daq/slc/base/IOException.h>
+
+#include <cstdio>
+#include <cstring>
+
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <errno.h>
+
+#include <netinet/in.h>
+#include <netdb.h>
+
+using namespace Belle2;
+
+int TCPServerSocket::open(const std::string& ip, unsigned short port,
+                          int nqueue)
+{
+  m_ip = ip;
+  m_port = port;
+  return open(nqueue);
+}
+
+int TCPServerSocket::open(int nqueue)
+{
+  if (m_fd > 0) {
+    throw (IOException("Socket is working already."));
+  }
+  sockaddr_in addr;
+  memset(&addr, 0, sizeof(sockaddr_in));
+  addr.sin_family = AF_INET;
+  addr.sin_addr.s_addr = INADDR_ANY;
+  addr.sin_port = htons(m_port);
+
+  m_fd = socket(PF_INET, SOCK_STREAM, 0);
+  if (m_fd == -1) {
+    m_fd = 0;
+    throw (IOException("Fail to create a server socket."));
+  }
+  int enable = 1;
+  if (setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) == -1) {
+    m_fd = 0;
+    throw (IOException("Fail to set resue address for the socket."));
+  }
+  struct hostent* host = NULL;
+  host = gethostbyname(m_ip.c_str());
+  if (host == NULL) {
+    unsigned long ip_address = inet_addr(m_ip.c_str());
+    if ((signed long) ip_address < 0) {
+      throw (std::exception());
+      throw (IOException("Wrong host name or ip"));
+    } else {
+      host = gethostbyaddr((char*)&ip_address, sizeof(ip_address), AF_INET);
+    }
+  }
+  if (host == NULL) {
+    throw (IOException("Fail to get host ip: %s", m_ip.c_str()));
+  }
+  addr.sin_addr.s_addr = (*(unsigned long*)host->h_addr_list[0]);
+
+  if (bind(m_fd, (const sockaddr*) & (addr), sizeof(sockaddr_in)) != 0) {
+    throw (IOException("Fail to bind the socket. %s:%d", m_ip.c_str(), m_port));
+  }
+  if (listen(m_fd, nqueue) != 0) {
+    throw (IOException("Fail to listen to the socket."));
+  }
+  return m_fd;
+}
+
+TCPSocket TCPServerSocket::accept()
+{
+  socklen_t len = sizeof(sockaddr_in);
+  sockaddr_in addr;
+  memset(&addr, 0, sizeof(sockaddr_in));
+  addr.sin_family = AF_INET;
+  addr.sin_addr.s_addr = INADDR_ANY;
+  addr.sin_port = htons(m_port);
+  int fd;
+  errno = 0;
+  while (true) {
+    if ((fd = ::accept(m_fd, (sockaddr*) & (addr), &len)) == -1) {
+      switch (errno) {
+        case EINTR: continue;
+        case EAGAIN: continue;
+        default:
+          perror("accept");
+          throw (IOException("Fail to accept."));
+      }
+    }
+    break;
+  }
+  TCPSocket s(fd);
+  s.m_ip = inet_ntoa(addr.sin_addr);
+  s.m_port = ntohs(addr.sin_port);
+  return s;
+}
diff --git a/ROPCApplications/daq/slc/system/src/TCPSocket.cc b/ROPCApplications/daq/slc/system/src/TCPSocket.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7974c1ff2b900d1064888cddc0af20d9286595b3
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/TCPSocket.cc
@@ -0,0 +1,199 @@
+#include "daq/slc/system/TCPSocket.h"
+
+#include <daq/slc/base/IOException.h>
+
+#include <cstdio>
+#include <cstring>
+
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+#include <unistd.h>
+#include <netinet/in.h>
+#include <errno.h>
+#include <netdb.h>
+
+using namespace Belle2;
+
+int TCPSocket::connect(const std::string& ip, unsigned short port)
+{
+  m_ip = ip;
+  m_port = port;
+  return connect();
+}
+
+int TCPSocket::connect()
+{
+  if (m_fd > 0) {
+    throw (IOException("Socket is working already."));
+  }
+  sockaddr_in addr;
+  memset(&addr, 0, sizeof(sockaddr_in));
+  addr.sin_family = AF_INET;
+  addr.sin_addr.s_addr = INADDR_ANY;
+  addr.sin_port = htons(m_port);
+
+  if ((m_fd = ::socket(PF_INET, SOCK_STREAM, 0)) < 0) {
+    throw (IOException("Failed to create socket"));
+  }
+  struct hostent* host = NULL;
+  host = gethostbyname(m_ip.c_str());
+  if (host == NULL) {
+    unsigned long ip_address = inet_addr(m_ip.c_str());
+    if ((signed long) ip_address < 0) {
+      throw (IOException("Wrong host name or ip"));
+    } else {
+      host = gethostbyaddr((char*)&ip_address, sizeof(ip_address), AF_INET);
+    }
+  }
+  if (host == NULL) {
+    close();
+    throw (IOException("Failed to connect host %s:%d",
+                       m_ip.c_str(), m_port));
+  }
+  addr.sin_addr.s_addr = (*(unsigned long*) host->h_addr_list[0]);
+
+  if (::connect(m_fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
+    close();
+    throw (IOException("Failed to connect host %s:%d",
+                       m_ip.c_str(), m_port));
+  }
+
+  return m_fd;
+}
+
+void TCPSocket::setBufferSize(int size)
+{
+  if (size > 0) {
+    if (setsockopt(m_fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) != 0) {
+      throw (IOException("failed to SO_SNDBUF: %s\n", strerror(errno)));
+    }
+    if (setsockopt(m_fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)) != 0) {
+      throw (IOException("error on SO_RCVBUF: %s\n", strerror(errno)));
+    }
+  }
+}
+
+size_t TCPSocket::write(const void* buf, size_t count)
+{
+  size_t c = 0;
+  int ret;
+  while (c < count) {
+    errno = 0;
+    ret = send(m_fd, ((unsigned char*)buf + c), (count - c), MSG_NOSIGNAL);
+    if (ret <= 0) {
+      switch (errno) {
+        case EINTR: continue;
+        case ENETUNREACH:
+        case EHOSTUNREACH:
+        case ETIMEDOUT:
+          usleep(500);
+          continue;
+        default:
+          throw (IOException("Error while writing"));
+      }
+    }
+    c += ret;
+  }
+  return c;
+}
+
+size_t TCPSocket::read(void* buf, size_t count)
+{
+  size_t c = 0;
+  int ret;
+  while (c < count) {
+    errno = 0;
+    ret = recv(m_fd, ((unsigned char*)buf + c), (count - c), 0);
+    if (ret <= 0) {
+      switch (errno) {
+        case EINTR: continue;
+        case EAGAIN: continue;
+        default:
+          throw (IOException("TCPSocket::read Error while reading."));
+      }
+    }
+    c += ret;
+  }
+  return c;
+}
+
+size_t TCPSocket::read_once(void* buf, size_t count)
+{
+  int ret;
+  errno = 0;
+  while (true) {
+    ret = recv(m_fd, buf, count, 0);
+    if (ret <= 0) {
+      switch (errno) {
+        case EINTR: continue;
+        case EAGAIN: continue;
+        default:
+          throw (IOException("TCPSocket::read_once Error while reading."));
+      }
+    }
+    break;
+  }
+  return ret;
+}
+
+void TCPSocket::print()
+{
+  sockaddr_in sa;
+  memset(&sa, 0, sizeof(sockaddr_in));
+  socklen_t sa_len = sizeof(sa);
+  if (getsockname(m_fd, (struct sockaddr*)&sa, (socklen_t*)&sa_len) != 0) {
+    perror("getsockname");
+  }
+  printf("Local IP address is: %s\n", inet_ntoa(sa.sin_addr));
+  printf("Local port is: %d\n", (int) ntohs(sa.sin_port));
+}
+
+const std::string TCPSocket::getLocalIP()
+{
+  sockaddr_in sa;
+  memset(&sa, 0, sizeof(sockaddr_in));
+  socklen_t sa_len = sizeof(sa);
+  if (getsockname(m_fd, (struct sockaddr*)&sa, (socklen_t*)&sa_len) != 0) {
+    return "";
+  }
+  return inet_ntoa(sa.sin_addr);
+}
+
+int TCPSocket::getLocalAddress()
+{
+  sockaddr_in sa;
+  memset(&sa, 0, sizeof(sockaddr_in));
+  socklen_t sa_len = sizeof(sa);
+  if (getsockname(m_fd, (struct sockaddr*)&sa, (socklen_t*)&sa_len) != 0) {
+    return 0;
+  }
+  return sa.sin_addr.s_addr;
+}
+
+int TCPSocket::getLocalPort()
+{
+  sockaddr_in sa;
+  memset(&sa, 0, sizeof(sockaddr_in));
+  socklen_t sa_len = sizeof(sa);
+  if (getsockname(m_fd, (struct sockaddr*)&sa, (socklen_t*)&sa_len) != 0) {
+    return 0;
+  }
+  return ntohs(sa.sin_port);
+}
+
+unsigned int TCPSocket::getAddress()
+{
+  struct hostent* host = NULL;
+  host = gethostbyname(m_ip.c_str());
+  if (host == NULL) {
+    unsigned long ip_address = inet_addr(m_ip.c_str());
+    if ((signed long) ip_address < 0) {
+      throw (std::exception());
+      throw (IOException("Wrong host name or ip"));
+    } else {
+      host = gethostbyaddr((char*)&ip_address, sizeof(ip_address), AF_INET);
+    }
+  }
+  return (*(unsigned long*) host->h_addr_list[0]);
+}
diff --git a/ROPCApplications/daq/slc/system/src/Time.cc b/ROPCApplications/daq/slc/system/src/Time.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8d4d066a8a7e64414cc0509cbab9bef010c8f8a7
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/Time.cc
@@ -0,0 +1,145 @@
+#include "daq/slc/system/Time.h"
+
+#include "daq/slc/base/Reader.h"
+#include "daq/slc/base/Writer.h"
+
+#include <sys/time.h>
+
+#include <cmath>
+#include <cstdlib>
+#include <sstream>
+
+using namespace Belle2;
+
+#define MEGA 1000000
+
+Time::Time()
+{
+  timeval tv;
+  gettimeofday(&tv, 0);
+  m_s = tv.tv_sec;
+  m_us = tv.tv_usec;
+}
+
+Time::Time(const double t)
+{
+  set(t);
+}
+
+Time::Time(const long s, const long us)
+  : m_s(s), m_us(us)
+{
+  adjust();
+}
+
+Time::~Time()
+{
+}
+
+void Time::adjust()
+{
+  if (MEGA <= labs(m_us)) {
+    m_s += m_us / MEGA;
+    m_us = m_us - (m_us / MEGA) * MEGA;
+  }
+  if (0 < m_s && m_us < 0) {
+    m_s--;
+    m_us += MEGA;
+  }
+  if (m_s < 0 && 0 < m_us) {
+    m_s++;
+    m_us -= MEGA;
+  }
+}
+
+void Time::clear()
+{
+  m_s = m_us = 0;
+}
+
+void Time::set()
+{
+  timeval tv;
+  gettimeofday(&tv, 0);
+  m_s = tv.tv_sec;
+  m_us = tv.tv_usec;
+}
+
+void Time::set(const double t)
+{
+  double s, us;
+  us = modf(t, &s);
+  m_s = (long)s;
+  m_us = (long)(us * 1000000);
+  adjust();
+}
+
+void Time::set(const long s, const long us)
+{
+  m_s = s;
+  m_us = us;
+  adjust();
+}
+
+double Time::get() const
+{
+  return (double)m_s + ((double)m_us) / 1000000.;
+}
+
+long Time::getSecond() const
+{
+  return m_s;
+}
+
+long Time::getMicroSecond() const
+{
+  return m_us;
+}
+
+std::string Time::toString() const
+{
+  std::stringstream ss;
+  ss << m_s << "." << m_us;
+  return ss.str();
+}
+
+void Time::readObject(Reader& r)
+{
+  m_s = r.readLong();
+  m_us = r.readLong();
+}
+
+void Time::writeObject(Writer& w) const
+{
+  w.writeLong(m_s);
+  w.writeLong(m_us);
+}
+
+Time& Time::operator = (const Time& t)
+{
+  m_s =  t.m_s;
+  m_us =  t.m_us;
+  return *this;
+}
+
+bool Time::operator == (const Time& t) const
+{
+  return (m_s == t.m_s) && (m_us == t.m_us);
+}
+
+Time Time::operator + (const Time& t) const
+{
+  Time tt = *this;
+  tt.m_s += t.m_s;
+  tt.m_us += t.m_us;
+  return tt;
+}
+
+Time Time::operator - (const Time& t) const
+{
+  Time tt = *this;
+  tt.m_s -= t.m_s;
+  tt.m_us -= t.m_us;
+  return tt;
+}
+
diff --git a/ROPCApplications/daq/slc/system/src/UDPSocket.cc b/ROPCApplications/daq/slc/system/src/UDPSocket.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d85817e0c3afed3a017c9e26f1eca87b4151b4ae
--- /dev/null
+++ b/ROPCApplications/daq/slc/system/src/UDPSocket.cc
@@ -0,0 +1,225 @@
+#include "daq/slc/system/UDPSocket.h"
+
+#include <daq/slc/base/IOException.h>
+
+#include <cstdio>
+#include <cstring>
+
+#include <unistd.h>
+#include <errno.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+#include <ifaddrs.h>
+
+using namespace Belle2;
+
+unsigned int UDPSocket::findSubnet(unsigned int addr)
+{
+  struct ifaddrs* ifa_list;
+  struct ifaddrs* ifa;
+  char addrstr[256], netmaskstr[256];
+  if (getifaddrs(&ifa_list) != 0) return 0;
+  for (ifa = ifa_list; ifa != NULL; ifa = ifa->ifa_next) {
+    memset(addrstr, 0, sizeof(addrstr));
+    memset(netmaskstr, 0, sizeof(netmaskstr));
+    if (ifa->ifa_addr->sa_family == AF_INET &&
+        addr == ((struct sockaddr_in*)ifa->ifa_addr)->sin_addr.s_addr) {
+      addr |= ~(((struct sockaddr_in*)ifa->ifa_netmask)->sin_addr.s_addr);
+    }
+  }
+  freeifaddrs(ifa_list);
+  return addr;
+}
+
+UDPSocket::UDPSocket()
+{
+  m_addr.sin_family = AF_INET;
+  m_addr.sin_addr.s_addr = INADDR_ANY;
+}
+
+UDPSocket::UDPSocket(unsigned int port)
+{
+  m_addr.sin_port = htons(port);
+  m_addr.sin_family = AF_INET;
+  m_addr.sin_addr.s_addr = INADDR_ANY;
+  if ((m_fd = ::socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+    throw (IOException("Failed to create socket"));
+  }
+}
+
+UDPSocket::UDPSocket(unsigned int port,
+                     const std::string& hostname,
+                     bool boardcast)
+{
+  m_addr.sin_port = htons(port);
+  m_addr.sin_family = AF_INET;
+  if (hostname.size() > 0) {
+    struct hostent* host = NULL;
+    host = gethostbyname(hostname.c_str());
+    if (host == NULL) {
+      unsigned long addr = inet_addr(hostname.c_str());
+      if ((signed long) addr < 0) {
+        throw (std::exception());
+        throw (IOException("Wrong host name or ip"));
+      } else {
+        host = gethostbyaddr((char*)&addr, sizeof(addr), AF_INET);
+      }
+    }
+    m_addr.sin_addr.s_addr = (*(unsigned long*) host->h_addr_list[0]);
+  }
+  if ((m_fd = ::socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+    throw (IOException("Failed to create socket"));
+  }
+  if (boardcast) {
+    unsigned int addr = m_addr.sin_addr.s_addr;
+    if ((addr = findSubnet(addr)) > 0) {
+      m_addr.sin_addr.s_addr = addr;
+    }
+    int yes = 1;
+    setsockopt(m_fd, SOL_SOCKET, SO_BROADCAST,
+               (char*)&yes, sizeof(yes));
+  }
+}
+
+UDPSocket::UDPSocket(unsigned int port,
+                     unsigned int addr,
+                     bool boardcast)
+{
+  m_addr.sin_port = htons(port);
+  m_addr.sin_family = AF_INET;
+  m_addr.sin_addr.s_addr = addr;
+  if ((m_fd = ::socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+    throw (IOException("Failed to create socket"));
+  }
+  if (boardcast) {
+    addr = m_addr.sin_addr.s_addr;
+    if ((addr = findSubnet(addr)) > 0) {
+      m_addr.sin_addr.s_addr = addr;
+    }
+    int yes = 1;
+    setsockopt(m_fd, SOL_SOCKET, SO_BROADCAST,
+               (char*)&yes, sizeof(yes));
+  }
+}
+
+int UDPSocket::bind(unsigned int port,
+                    const std::string& hostname, bool broadcast)
+{
+  if (m_fd <= 0 && (m_fd = ::socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+    throw (IOException("Failed to create socket"));
+  }
+  m_addr.sin_port = htons(port);
+  if (hostname.size() > 0) {
+    struct hostent* host = NULL;
+    host = gethostbyname(hostname.c_str());
+    if (host == NULL) {
+      unsigned long addr = inet_addr(hostname.c_str());
+      if ((signed long) addr < 0) {
+        throw (std::exception());
+        throw (IOException("Wrong host name or ip"));
+      } else {
+        host = gethostbyaddr((char*)&addr, sizeof(addr), AF_INET);
+      }
+    }
+    m_addr.sin_addr.s_addr = (*(unsigned long*) host->h_addr_list[0]);
+    if (broadcast) {
+      unsigned int addr = m_addr.sin_addr.s_addr;
+      if ((addr = findSubnet(addr)) > 0) {
+        m_addr.sin_addr.s_addr = addr;
+      }
+    }
+  }
+  return bind();
+}
+
+int UDPSocket::bind()
+{
+  if (::bind(m_fd, (struct sockaddr*)&m_addr, sizeof(m_addr)) < 0) {
+    close();
+    throw (IOException("Failed to bind socket port=%d",
+                       ntohs(m_addr.sin_port)));
+  }
+  return m_fd;
+}
+
+size_t UDPSocket::write(const void* buf, size_t count)
+{
+  size_t c = 0;
+  int ret;
+  while (c < count) {
+    errno = 0;
+    ret = sendto(m_fd, ((unsigned char*)buf + c),
+                 (count - c), 0,
+                 (struct sockaddr*)&m_addr, sizeof(m_addr));
+    if (ret <= 0) {
+      switch (errno) {
+        case EINTR: continue;
+        case ENETUNREACH:
+        case EHOSTUNREACH:
+        case ETIMEDOUT:
+          usleep(500);
+          continue;
+        default:
+          throw (IOException("Error while writing"));
+      }
+    }
+    c += ret;
+  }
+  return c;
+}
+
+size_t UDPSocket::read(void* buf, size_t count)
+{
+  size_t c = 0;
+  int ret;
+  socklen_t addrlen = sizeof(m_remote_addr);
+  while (true) {
+    errno = 0;
+    ret = recvfrom(m_fd, ((unsigned char*)buf + c), (count - c), 0,
+                   (struct sockaddr*)&m_remote_addr, &addrlen);
+    if (ret <= 0) {
+      switch (errno) {
+        case EINTR: continue;
+        case EAGAIN: continue;
+        default:
+          throw (IOException("Error while reading."));
+      }
+    }
+    c += ret;
+    break;
+  }
+  return c;
+}
+
+const std::string UDPSocket::getHostName() const
+{
+  return inet_ntoa(m_addr.sin_addr);
+}
+
+unsigned int UDPSocket::getAddress() const
+{
+  return m_addr.sin_addr.s_addr;
+}
+
+unsigned int UDPSocket::getPort() const
+{
+  return ntohs(m_addr.sin_port);
+}
+
+const std::string UDPSocket::getRemoteHostName() const
+{
+  return inet_ntoa(m_remote_addr.sin_addr);
+}
+
+unsigned int UDPSocket::getRemoteAddress() const
+{
+  return m_remote_addr.sin_addr.s_addr;
+}
+
+unsigned int UDPSocket::getRemotePort() const
+{
+  return ntohs(m_remote_addr.sin_port);
+}
diff --git a/ROPCApplications/rawdata/dataobjects/SConscript b/ROPCApplications/rawdata/dataobjects/SConscript
new file mode 100644
index 0000000000000000000000000000000000000000..d688e8ce5d70876d7a361e77f28ab30fd603738c
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/SConscript
@@ -0,0 +1,5 @@
+Import('env')
+
+env['LIBS'] = ['framework', 'rawdata', 'Core']
+
+Return('env')
diff --git a/ROPCApplications/rawdata/dataobjects/include/PostRawCOPPERFormat_latest.h b/ROPCApplications/rawdata/dataobjects/include/PostRawCOPPERFormat_latest.h
new file mode 100644
index 0000000000000000000000000000000000000000..ff8b5d2b5d4168a008899396e5833b511afd253d
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/PostRawCOPPERFormat_latest.h
@@ -0,0 +1,347 @@
+//+
+// File : PostRawCOPPERFormat_latest.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef POSTRAWCOPPERFORMAT_LATEST_H
+#define POSTRAWCOPPERFORMAT_LATEST_H
+
+// Includes
+/* #include <stdio.h> */
+/* #include <stdlib.h> */
+/* #include <string> */
+/* #include <sys/time.h> */
+
+#include <rawdata/dataobjects/RawCOPPERFormat_latest.h>
+#include <rawdata/CRCCalculator.h>
+
+//#include <framework/datastore/DataStore.h>
+//#include <TObject.h>
+
+// version #
+#define POST_RAWCOPPER_FORMAT_VER1 1
+
+//#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+
+namespace Belle2 {
+
+  /**
+   * The Raw COPPER class ver.1 ( the latest version since May, 2014 )
+   * This class stores data received by COPPER via belle2linkt
+   * Data from all detectors except PXD are stored in this class
+   */
+  class PostRawCOPPERFormat_latest : public RawCOPPERFormat_latest {
+  public:
+    //! Default constructor
+    PostRawCOPPERFormat_latest();
+
+    //! Constructor using existing pointer to raw data buffer
+    //PostRawCOPPERFormat_latest(int* bufin, int nwords);
+    //! Destructor
+    virtual ~PostRawCOPPERFormat_latest();
+
+    //
+    // Get position of or pointer to data
+    //
+    ///////////////////////////////////////////////////////////////////////////////////////
+    // POINTER TO "DETECTOR BUFFER"
+    //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+    //! get Detector buffer length
+    int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17;
+
+    //! get Detector buffer of slot A
+    int* Get1stDetectorBuffer(int n) OVERRIDE_CPP17;
+
+    //! get Detector Buffer of slot B
+    int* Get2ndDetectorBuffer(int n) OVERRIDE_CPP17;
+
+    //! get Detector Buffer of slot C
+    int* Get3rdDetectorBuffer(int n) OVERRIDE_CPP17;
+
+    //! get Detector Buffer of slot D
+    int* Get4thDetectorBuffer(int n) OVERRIDE_CPP17;
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+    //! get posistion of COPPER block in unit of word
+    //    virtual int GetBufferPos(int n);
+
+    //
+    // Get information from 13words "COPPER header" attached by COPPER board
+    //
+    //! get COPPER counter(not event number)
+    unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
+
+    //! get # of offset words for FINESSE slot A buffer position
+    int GetOffset1stFINESSE(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE buffer
+    int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17;
+
+    //
+    // Get information from "B2link(attached by FEE and HLSB) header"
+    //
+    //! get b2l block from "FEE b2link header"
+    //    virtual int* GetFTSW2Words(int n);
+
+    //! get b2l block from "FEE b2link header"
+    virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
+
+    //! get b2l block from "FEE b2link header"
+    virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
+
+    //
+    // read magic word to check data
+    //
+    //! get magic word of  COPPER driver header
+    unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
+
+    //! get magic word of  COPPER FPGA header
+    unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
+
+    //! get magic word of  COPPER FPGA trailer
+    unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
+
+    //! get magic word of  COPPER driver trailer
+    unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
+
+    //! Get checksum in RawTrailer
+    unsigned int GetTrailerChksum(int  n) OVERRIDE_CPP17;
+
+    //! Get CRC16 value for an event
+    int GetEventCRC16Value(int n, int finesse_num) OVERRIDE_CPP17;
+
+    //! Check if COPPER Magic words are correct
+    bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
+
+    //! should be called by DeSerializerCOPPER.cc and fill contents in RawHeader
+    unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
+                                       unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
+
+    //! read COPPER driver's checksum value
+    unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
+
+    //! calc COPPER driver's checksum value
+    unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
+
+    //! check data contents
+    void CheckData(int n,
+                   unsigned int prev_evenum, unsigned int* cur_evenum,
+                   unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
+                   unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
+
+    //! check data contents
+    void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
+
+    //! check magic words
+    int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
+
+    //! check magic words
+    int CheckCRC16(int n, int finesse_num);
+
+    //! Pack data (format ver. = -1 -> Select the latest format version)
+    int* PackDetectorBuf(int* packed_buf_nwords,
+                         int* detector_buf_1st, int nwords_1st,
+                         int* detector_buf_2nd, int nwords_2nd,
+                         int* detector_buf_3rd, int nwords_3rd,
+                         int* detector_buf_4th, int nwords_4th,
+                         RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
+
+    //
+    // size of "COPPER front header" and "COPPER trailer"
+    //
+    //! Copper data words = ( total_data_length in COPPER header ) + COPPER_HEADER_TRAILER_NWORDS
+
+    enum {
+      SIZE_COPPER_DRIVER_HEADER = 0,
+      SIZE_COPPER_DRIVER_TRAILER = 0
+    };
+
+    // Data Format : "COPPER header"
+    enum {
+      SIZE_COPPER_HEADER = 0
+    };
+
+    // Data Format : "COPPER Trailer"
+    enum {
+      SIZE_COPPER_TRAILER = 0
+    };
+
+    // Data Format : "B2Link HSLB Header"
+    enum {
+      POS_B2LHSLB_MAGIC = 0,
+      SIZE_B2LHSLB_HEADER = 1
+    };
+
+
+    // Data Format : "B2Link FEE Header"
+    enum {
+      POS_B2L_CTIME = 0,
+      SIZE_B2LFEE_HEADER = 1
+    };
+
+    // Data Format : B2Link FEE Trailer
+    enum {
+      POS_B2LFEE_ERRCNT_CRC16 = 0,
+      SIZE_B2LFEE_TRAILER = 1
+    };
+
+    //
+    // Data Format : "B2Link HSLB Trailer"
+    //
+    enum {
+      SIZE_B2LHSLB_TRAILER = 0
+    };
+
+
+
+  protected :
+    ///ver.2 Change FEE format as presented at B2GM in Nov.2013 ( Nov.20, 2013)
+    //    ClassDefOverride(PostRawCOPPERFormat_latest, 2);
+
+  };
+
+  inline int PostRawCOPPERFormat_latest::GetOffset1stFINESSE(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
+    return pos_nwords;
+  }
+
+  inline int* PostRawCOPPERFormat_latest::Get1stDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get1stFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PostRawCOPPERFormat_latest::Get2ndDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get2ndFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset2ndFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PostRawCOPPERFormat_latest::Get3rdDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get3rdFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset3rdFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PostRawCOPPERFormat_latest::Get4thDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get4thFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset4thFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PostRawCOPPERFormat_latest::GetExpRunSubrunBuf(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.POS_EXP_RUN_NO;
+    return &(m_buffer[ pos_nwords ]);
+    /* #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2 */
+    /*     CheckB2LFEEHeaderVersion(n); */
+    /* #endif */
+    /*     int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN; */
+    /*     return &(m_buffer[ pos_nwords ]); */
+  }
+
+  inline unsigned int PostRawCOPPERFormat_latest::GetDriverChkSum(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
+                     - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
+    return m_buffer[ pos_nwords ];
+  }
+
+
+  inline unsigned int PostRawCOPPERFormat_latest::GetCOPPERCounter(int n)
+  {
+    char err_buf[500];
+    sprintf(err_buf, "[FATAL] This data format does not have COPPER counter.(block %d) Exiting...\n %s %s %d\n",
+            n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf);
+    std::string err_str = err_buf; throw (err_str);
+    return 0;
+  }
+
+  inline unsigned int PostRawCOPPERFormat_latest::GetMagicDriverHeader(int n)
+  {
+    char err_buf[500];
+    sprintf(err_buf, "[FATAL] This function is not supported. (block %d) Exiting...\n %s %s %d\n",
+            n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf);
+    std::string err_str = err_buf; throw (err_str);
+    return 0;
+  }
+
+  inline unsigned int PostRawCOPPERFormat_latest::GetMagicFPGAHeader(int n)
+  {
+    char err_buf[500];
+    sprintf(err_buf, "[FATAL] This function is not supported. (block %d) Exiting...\n %s %s %d\n",
+            n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf);
+    std::string err_str = err_buf; throw (err_str);
+    return 0;
+  }
+
+
+  inline unsigned int PostRawCOPPERFormat_latest::GetMagicFPGATrailer(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
+
+    //    printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), tmp_trailer.GetTrlNwords());
+
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+  inline unsigned int PostRawCOPPERFormat_latest::GetMagicDriverTrailer(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+
+  inline unsigned int PostRawCOPPERFormat_latest::GetTrailerChksum(int  n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+  inline int PostRawCOPPERFormat_latest::GetEventCRC16Value(int n, int finesse_num)
+  {
+    int fin_nwords = GetFINESSENwords(n, finesse_num);
+    if (fin_nwords > 0) {
+      int* buf = GetFINESSEBuffer(n, finesse_num) +  fin_nwords
+                 - ((SIZE_B2LFEE_TRAILER - POS_B2LFEE_ERRCNT_CRC16) + SIZE_B2LHSLB_TRAILER) ;
+      return (int)(*buf & 0xffff);
+    }
+    return -1;
+  }
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/PostRawCOPPERFormat_v1.h b/ROPCApplications/rawdata/dataobjects/include/PostRawCOPPERFormat_v1.h
new file mode 100644
index 0000000000000000000000000000000000000000..f404a141f8e90dedcc9ee3ee6d1ad5677b75f536
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/PostRawCOPPERFormat_v1.h
@@ -0,0 +1,333 @@
+//+
+// File : PostRawCOPPERFormat_v1.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef POSTRAWCOPPERFORMAT_V1_H
+#define POSTRAWCOPPERFORMAT_V1_H
+
+// Includes
+#include <stdio.h>
+#include <stdlib.h>
+#include <string>
+#include <sys/time.h>
+
+#include <rawdata/dataobjects/RawCOPPERFormat_v1.h>
+#include <rawdata/CRCCalculator.h>
+
+
+#include <TObject.h>
+
+// version #
+#define POST_RAWCOPPER_FORMAT_VER1 1
+
+//#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+
+namespace Belle2 {
+
+  /**
+   * The Raw COPPER class ver.1 ( the latest version since May, 2014 )
+   * This class stores data received by COPPER via belle2linkt
+   * Data from all detectors except PXD are stored in this class
+   */
+  class PostRawCOPPERFormat_v1 : public RawCOPPERFormat_v1 {
+  public:
+    //! Default constructor
+    PostRawCOPPERFormat_v1();
+
+    //! Constructor using existing pointer to raw data buffer
+    //PostRawCOPPERFormat_v1(int* bufin, int nwords);
+    //! Destructor
+    virtual ~PostRawCOPPERFormat_v1();
+
+    //
+    // Get position of or pointer to data
+    //
+    ///////////////////////////////////////////////////////////////////////////////////////
+    // POINTER TO "DETECTOR BUFFER"
+    //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+    //! get Detector buffer length
+    int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17;
+
+    //! get Detector buffer of slot A
+    int* Get1stDetectorBuffer(int n) OVERRIDE_CPP17;
+
+    //! get Detector Buffer of slot B
+    int* Get2ndDetectorBuffer(int n) OVERRIDE_CPP17;
+
+    //! get Detector Buffer of slot C
+    int* Get3rdDetectorBuffer(int n) OVERRIDE_CPP17;
+
+    //! get Detector Buffer of slot D
+    int* Get4thDetectorBuffer(int n) OVERRIDE_CPP17;
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+    //! get posistion of COPPER block in unit of word
+    //    virtual int GetBufferPos(int n);
+
+    //
+    // Get information from 13words "COPPER header" attached by COPPER board
+    //
+    //! get COPPER counter(not event number)
+    unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
+
+    //! get # of offset words for FINESSE slot A buffer position
+    int GetOffset1stFINESSE(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE buffer
+    int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17;
+
+    //
+    // Get information from "B2link(attached by FEE and HLSB) header"
+    //
+    //! get b2l block from "FEE b2link header"
+    //    virtual int* GetFTSW2Words(int n);
+
+    //! get b2l block from "FEE b2link header"
+    virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
+
+    //! get b2l block from "FEE b2link header"
+    virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
+
+    //
+    // read magic word to check data
+    //
+    //! get magic word of  COPPER driver header
+    unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
+
+    //! get magic word of  COPPER FPGA header
+    unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
+
+    //! get magic word of  COPPER FPGA trailer
+    unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
+
+    //! get magic word of  COPPER driver trailer
+    unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
+
+    //! Get checksum in RawTrailer
+    unsigned int GetTrailerChksum(int  n) OVERRIDE_CPP17;
+
+    //! Check if COPPER Magic words are correct
+    bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
+
+    //! should be called by DeSerializerCOPPER.cc and fill contents in RawHeader
+    unsigned int FillTopBlockRawHeader(unsigned int m_node_id, unsigned int prev_eve32,
+                                       unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
+
+    //! read COPPER driver's checksum value
+    unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
+
+    //! calc COPPER driver's checksum value
+    unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
+
+    //! check data contents
+    void CheckData(int n,
+                   unsigned int prev_evenum, unsigned int* cur_evenum,
+                   unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
+                   unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
+
+    //! check data contents
+    void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
+
+    //! check magic words
+    int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
+
+    //! check magic words
+    int CheckCRC16(int n, int finesse_num);
+
+    //! Pack data (format ver. = -1 -> Select the latest format version)
+    int* PackDetectorBuf(int* packed_buf_nwords,
+                         int* detector_buf_1st, int nwords_1st,
+                         int* detector_buf_2nd, int nwords_2nd,
+                         int* detector_buf_3rd, int nwords_3rd,
+                         int* detector_buf_4th, int nwords_4th,
+                         RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
+
+    //
+    // size of "COPPER front header" and "COPPER trailer"
+    //
+    //! Copper data words = ( total_data_length in COPPER header ) + COPPER_HEADER_TRAILER_NWORDS
+
+    enum {
+      SIZE_COPPER_DRIVER_HEADER = 0,
+      SIZE_COPPER_DRIVER_TRAILER = 0
+    };
+
+    // Data Format : "COPPER header"
+    enum {
+      SIZE_COPPER_HEADER = 0
+    };
+
+    // Data Format : "COPPER Trailer"
+    enum {
+      SIZE_COPPER_TRAILER = 0
+    };
+
+    // Data Format : "B2Link HSLB Header"
+    enum {
+      POS_B2LHSLB_MAGIC = 0,
+      SIZE_B2LHSLB_HEADER = 1
+    };
+
+
+    // Data Format : "B2Link FEE Header"
+    enum {
+      POS_B2L_CTIME = 0,
+      SIZE_B2LFEE_HEADER = 1
+    };
+
+    // Data Format : B2Link FEE Trailer
+    enum {
+      POS_B2LFEE_CRC16 = 0,
+      SIZE_B2LFEE_TRAILER = 1
+    };
+
+    //
+    // Data Format : "B2Link HSLB Trailer"
+    //
+    enum {
+      SIZE_B2LHSLB_TRAILER = 0
+    };
+
+
+
+  protected :
+    ///ver.2 Change FEE format as presented at B2GM in Nov.2013 ( Nov.20, 2013)
+    //    ClassDefOverride(PostRawCOPPERFormat_v1, 2);
+
+  };
+
+  inline int PostRawCOPPERFormat_v1::GetOffset1stFINESSE(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
+    return pos_nwords;
+  }
+
+  inline int* PostRawCOPPERFormat_v1::Get1stDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get1stFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PostRawCOPPERFormat_v1::Get2ndDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get2ndFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset2ndFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PostRawCOPPERFormat_v1::Get3rdDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get3rdFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset3rdFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PostRawCOPPERFormat_v1::Get4thDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get4thFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset4thFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PostRawCOPPERFormat_v1::GetExpRunSubrunBuf(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.POS_EXP_RUN_NO;
+    return &(m_buffer[ pos_nwords ]);
+    /* #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2 */
+    /*     CheckB2LFEEHeaderVersion(n); */
+    /* #endif */
+    /*     int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN; */
+    /*     return &(m_buffer[ pos_nwords ]); */
+  }
+
+  inline unsigned int PostRawCOPPERFormat_v1::GetDriverChkSum(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
+                     - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
+    return m_buffer[ pos_nwords ];
+  }
+
+
+  inline unsigned int PostRawCOPPERFormat_v1::GetCOPPERCounter(int n)
+  {
+    char err_buf[500];
+    sprintf(err_buf, "This data format does not have COPPER counter.(block %d) Exiting...\n %s %s %d\n",
+            n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    std::string err_str = err_buf; throw (err_str);
+    return 0;
+  }
+
+  inline unsigned int PostRawCOPPERFormat_v1::GetMagicDriverHeader(int n)
+  {
+    char err_buf[500];
+    sprintf(err_buf, "This function is not supported. (block %d) Exiting...\n %s %s %d\n",
+            n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    std::string err_str = err_buf; throw (err_str);
+    return 0;
+  }
+
+  inline unsigned int PostRawCOPPERFormat_v1::GetMagicFPGAHeader(int n)
+  {
+    char err_buf[500];
+    sprintf(err_buf, "This function is not supported. (block %d) Exiting...\n %s %s %d\n",
+            n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    std::string err_str = err_buf; throw (err_str);
+    return 0;
+  }
+
+
+  inline unsigned int PostRawCOPPERFormat_v1::GetMagicFPGATrailer(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
+
+    //    printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), tmp_trailer.GetTrlNwords());
+
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+  inline unsigned int PostRawCOPPERFormat_v1::GetMagicDriverTrailer(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+
+  inline unsigned int PostRawCOPPERFormat_v1::GetTrailerChksum(int  n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+
+
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/PreRawCOPPERFormat_latest.h b/ROPCApplications/rawdata/dataobjects/include/PreRawCOPPERFormat_latest.h
new file mode 100644
index 0000000000000000000000000000000000000000..d8b34e905ec0ae250498c8ed7b12f0a898670a57
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/PreRawCOPPERFormat_latest.h
@@ -0,0 +1,396 @@
+//+
+// File : PreRawCOPPERFormat_latest.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef PRERAWCOPPERFORMAT_LATEST_H
+#define PRERAWCOPPERFORMAT_LATEST_H
+
+// Includes
+//#include <framework/datastore/DataStore.h>
+//#include <rawdata/dataobjects/RawDataBlock.h>
+#include <rawdata/dataobjects/PostRawCOPPERFormat_latest.h>
+#include <rawdata/CRCCalculator.h>
+
+//#include <TObject.h>
+//#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+
+
+namespace Belle2 {
+
+  /**
+   * The Raw COPPER class ver.1 ( the latest version since May, 2014 )
+   * This class stores data received by COPPER via belle2linkt
+   * Data from all detectors except PXD are stored in this class
+   */
+  class PreRawCOPPERFormat_latest : public RawCOPPERFormat_latest {
+  public:
+    //! Default constructor
+    PreRawCOPPERFormat_latest();
+
+    //! Constructor using existing pointer to raw data buffer
+    //PreRawCOPPERFormat_latest(int* bufin, int nwords);
+    //! Destructor
+    virtual ~PreRawCOPPERFormat_latest();
+
+    //
+    // Get position of or pointer to data
+    //
+    ///////////////////////////////////////////////////////////////////////////////////////
+    // POINTER TO "DETECTOR BUFFER"
+    //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+
+    //! get Detector buffer length
+    int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17;
+
+    //! get Detector buffer of slot A
+    int* Get1stDetectorBuffer(int n) OVERRIDE_CPP17;
+
+    //! get Detector Buffer of slot B
+    int* Get2ndDetectorBuffer(int n) OVERRIDE_CPP17;
+
+    //! get Detector Buffer of slot C
+    int* Get3rdDetectorBuffer(int n) OVERRIDE_CPP17;
+
+    //! get Detector Buffer of slot D
+    int* Get4thDetectorBuffer(int n) OVERRIDE_CPP17;
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+    //! get posistion of COPPER block in unit of word
+    //    virtual int GetBufferPos(int n);
+
+    //
+    // Get information from 13words "COPPER header" attached by COPPER board
+    //
+    //! get COPPER counter(not event number)
+    unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
+
+    //! get # of offset words for FINESSE slot A buffer position
+    int GetOffset1stFINESSE(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE buffer
+    int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17;
+
+    //
+    // Get information from "B2link(attached by FEE and HLSB) header"
+    //
+    //! get b2l block from "FEE b2link header"
+    //    virtual int* GetFTSW2Words(int n);
+
+    //! get b2l block from "FEE b2link header"
+    virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
+
+    //! get b2l block from "FEE b2link header"
+    virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
+
+    //
+    // read magic word to check data
+    //
+    //! get magic word of  COPPER driver header
+    unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
+
+    //! get magic word of  COPPER FPGA header
+    unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
+
+    //! get magic word of  COPPER FPGA trailer
+    unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
+
+    //! get magic word of  COPPER driver trailer
+    unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
+
+    //! get a checksum on trailer
+    unsigned int GetTrailerChksum(int  n) OVERRIDE_CPP17;
+
+    //! Check if COPPER Magic words are correct
+    bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
+
+    //! should be called by DeSerializerCOPPER.cc and fill contents in RawHeader
+    unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
+                                       unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
+
+    //! read COPPER driver's checksum value
+    unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
+
+    //! calc COPPER driver's checksum value
+    unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
+
+    //! check data contents
+    void CheckData(int n,
+                   unsigned int prev_evenum, unsigned int* cur_evenum,
+                   unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
+                   unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
+
+    //! check data contents
+    void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
+
+    //! check magic words of B2link HSLB header/trailer
+    int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
+
+    //! reduce and merge header/trailer
+    int CalcReducedDataSize(int* bufin, int nwords, int num_events, int num_nodes);
+    //    int CalcReducedDataSize(RawDataBlock* raw_datablk);
+
+    //! reduce and merge header/trailer
+    void CopyReducedData(int* bufin, int nwords, int num_events, int num_nodes, int* buf_to, int* nwords_to);
+    //    void CopyReducedData(RawDataBlock* raw_datablk, int* buf_to, int delete_flag_from);
+
+    //! calculate reduced data size
+    int CalcReducedNwords(int n);
+
+    //! copy data to reduced buffer
+    int CopyReducedBuffer(int n, int* buf_to);
+
+    //! check CRC16 in B2LFEE trailer
+    int CheckCRC16(int n, int finesse_num);
+
+    //! Pack data (format ver. = -1 -> Select the latest format version)
+    int* PackDetectorBuf(int* packed_buf_nwords,
+                         int* detector_buf_1st, int nwords_1st,
+                         int* detector_buf_2nd, int nwords_2nd,
+                         int* detector_buf_3rd, int nwords_3rd,
+                         int* detector_buf_4th, int nwords_4th,
+                         RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
+
+    //! Copy one datablock to buffer
+
+
+    //
+    // size of "COPPER front header" and "COPPER trailer"
+    //
+    //! Copper data words = ( total_data_length in COPPER header ) + COPPER_HEADER_TRAILER_NWORDS
+    enum {
+      SIZE_COPPER_DRIVER_HEADER = 7,
+      SIZE_COPPER_DRIVER_TRAILER = 2
+    };
+
+    //
+    // Data Format : "COPPER header"
+    //
+    enum {
+      POS_MAGIC_COPPER_1 = 0,
+      POS_EVE_NUM_COPPER = 1,
+      POS_SUBSYSTEM_ID = 2,
+      POS_CRATE_ID = 3,
+      POS_SLOT_ID = 4,
+      POS_MAGIC_COPPER_2 = 7,
+      POS_DATA_LENGTH = 8,
+      POS_CH_A_DATA_LENGTH = 9,
+      POS_CH_B_DATA_LENGTH = 10,
+      POS_CH_C_DATA_LENGTH = 11,
+      POS_CH_D_DATA_LENGTH = 12,
+
+      SIZE_COPPER_HEADER = 13
+    };
+
+
+
+    //
+    // Data Format : "COPPER Trailer"
+    //
+    enum {
+      POS_MAGIC_COPPER_3 = 0,
+      POS_CHKSUM_COPPER = 1,
+      POS_MAGIC_COPPER_4 = 2,
+
+      SIZE_COPPER_TRAILER = 3
+    };
+
+    //
+    // Data Format : "B2Link HSLB Header"
+    //
+    enum {
+      POS_MAGIC_B2LHSLB = 0,
+      //      POS_EVE_CNT_B2LHSLB = 1,
+      SIZE_B2LHSLB_HEADER = 1
+    };
+
+    // Data Format : "B2Link FEE Header"
+    // modified by Nov. 21, 2013, Nakao-san's New firmware?
+    enum {
+      POS_TT_CTIME_TYPE = 0,
+      POS_TT_TAG = 1,
+      POS_TT_UTIME = 2,
+      POS_EXP_RUN = 3,
+      POS_B2L_CTIME = 4,
+      SIZE_B2LFEE_HEADER = 5
+    };
+
+
+    //
+    // Data Format : B2Link FEE Trailer
+    //
+    enum {
+      POS_TT_CTIME_B2LFEE = 0,
+      POS_CHKSUM_B2LFEE = 1,
+      SIZE_B2LFEE_TRAILER = 2
+    };
+
+
+    //
+    // Data Format : "B2Link HSLB Trailer"
+    //
+    enum {
+      POS_CHKSUM_B2LHSLB = 0,
+      SIZE_B2LHSLB_TRAILER = 1
+    };
+
+
+
+    //
+    // COPPER magic words
+    //
+    enum {
+      COPPER_MAGIC_DRIVER_HEADER = 0x7FFF0008,
+      COPPER_MAGIC_FPGA_HEADER = 0xFFFFFAFA,
+      COPPER_MAGIC_FPGA_TRAILER = 0xFFFFF5F5,
+      COPPER_MAGIC_DRIVER_TRAILER = 0x7FFF0009
+    };
+
+
+    //
+    // magic words attached by HSLB
+    //
+    enum {
+      B2LHSLB_HEADER_MAGIC = 0xFFAA0000,
+      B2LHSLB_TRAILER_MAGIC = 0xFF550000
+    };
+
+    //! data fromat after size reduction
+    PostRawCOPPERFormat_latest m_reduced_rawcpr; //! not record
+
+  protected :
+    ///ver.2 Change FEE format as presented at B2GM in Nov.2013 ( Nov.20, 2013)
+    //    ClassDefOverride(PreRawCOPPERFormat_latest, 2);
+
+  };
+
+
+  inline int PreRawCOPPERFormat_latest::GetOffset1stFINESSE(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
+    return pos_nwords;
+  }
+
+
+
+  inline int* PreRawCOPPERFormat_latest::Get1stDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get1stFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PreRawCOPPERFormat_latest::Get2ndDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get2ndFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset2ndFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PreRawCOPPERFormat_latest::Get3rdDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get3rdFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset3rdFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PreRawCOPPERFormat_latest::Get4thDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get4thFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset4thFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PreRawCOPPERFormat_latest::GetExpRunSubrunBuf(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN;
+    return &(m_buffer[ pos_nwords ]);
+  }
+
+
+
+  inline unsigned int PreRawCOPPERFormat_latest::GetMagicDriverHeader(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_MAGIC_COPPER_1;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+  inline unsigned int PreRawCOPPERFormat_latest::GetMagicFPGAHeader(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_MAGIC_COPPER_2;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+  inline unsigned int PreRawCOPPERFormat_latest::GetMagicFPGATrailer(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
+
+    //    printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), trl.GetTrlNwords());
+
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+  inline unsigned int PreRawCOPPERFormat_latest::GetMagicDriverTrailer(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+
+  inline unsigned int PreRawCOPPERFormat_latest::GetDriverChkSum(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
+                     - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
+    return m_buffer[ pos_nwords ];
+  }
+
+
+  inline unsigned int PreRawCOPPERFormat_latest::GetCOPPERCounter(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + POS_EVE_NUM_COPPER + tmp_header.RAWHEADER_NWORDS;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+
+
+
+  inline unsigned int PreRawCOPPERFormat_latest::GetTrailerChksum(int  n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+
+
+
+
+}
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/PreRawCOPPERFormat_v1.h b/ROPCApplications/rawdata/dataobjects/include/PreRawCOPPERFormat_v1.h
new file mode 100644
index 0000000000000000000000000000000000000000..be05a78feb286af32696b0ff011e14782373ec26
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/PreRawCOPPERFormat_v1.h
@@ -0,0 +1,393 @@
+//+
+// File : PreRawCOPPERFormat_v1.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef PRERAWCOPPERFORMAT_V1_H
+#define PRERAWCOPPERFORMAT_V1_H
+
+// Includes
+//#include <framework/datastore/DataStore.h>
+//#include <rawdata/dataobjects/RawDataBlock.h>
+#include <rawdata/dataobjects/PostRawCOPPERFormat_v1.h>
+#include <rawdata/CRCCalculator.h>
+
+//#include <TObject.h>
+//#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+
+
+namespace Belle2 {
+
+  /**
+   * The Raw COPPER class ver.1 ( the latest version since May, 2014 )
+   * This class stores data received by COPPER via belle2linkt
+   * Data from all detectors except PXD are stored in this class
+   */
+  class PreRawCOPPERFormat_v1 : public RawCOPPERFormat_v1 {
+  public:
+    //! Default constructor
+    PreRawCOPPERFormat_v1();
+
+    //! Constructor using existing pointer to raw data buffer
+    //PreRawCOPPERFormat_v1(int* bufin, int nwords);
+    //! Destructor
+    virtual ~PreRawCOPPERFormat_v1();
+
+    //
+    // Get position of or pointer to data
+    //
+    ///////////////////////////////////////////////////////////////////////////////////////
+    // POINTER TO "DETECTOR BUFFER"
+    //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+
+    //! get Detector buffer length
+    int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17;
+
+    //! get Detector buffer of slot A
+    int* Get1stDetectorBuffer(int n) OVERRIDE_CPP17;
+
+    //! get Detector Buffer of slot B
+    int* Get2ndDetectorBuffer(int n) OVERRIDE_CPP17;
+
+    //! get Detector Buffer of slot C
+    int* Get3rdDetectorBuffer(int n) OVERRIDE_CPP17;
+
+    //! get Detector Buffer of slot D
+    int* Get4thDetectorBuffer(int n) OVERRIDE_CPP17;
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+    //! get posistion of COPPER block in unit of word
+    //    virtual int GetBufferPos(int n);
+
+    //
+    // Get information from 13words "COPPER header" attached by COPPER board
+    //
+    //! get COPPER counter(not event number)
+    unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
+
+    //! get # of offset words for FINESSE slot A buffer position
+    int GetOffset1stFINESSE(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE buffer
+    int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17;
+
+    //
+    // Get information from "B2link(attached by FEE and HLSB) header"
+    //
+    //! get b2l block from "FEE b2link header"
+    //    virtual int* GetFTSW2Words(int n);
+
+    //! get b2l block from "FEE b2link header"
+    virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
+
+    //! get b2l block from "FEE b2link header"
+    virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
+
+    //
+    // read magic word to check data
+    //
+    //! get magic word of  COPPER driver header
+    unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
+
+    //! get magic word of  COPPER FPGA header
+    unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
+
+    //! get magic word of  COPPER FPGA trailer
+    unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
+
+    //! get magic word of  COPPER driver trailer
+    unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
+
+    //! get a checksum on trailer
+    unsigned int GetTrailerChksum(int  n) OVERRIDE_CPP17;
+
+    //! Check if COPPER Magic words are correct
+    bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
+
+    //! should be called by DeSerializerCOPPER.cc and fill contents in RawHeader
+    unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
+                                       unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
+
+    //! read COPPER driver's checksum value
+    unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
+
+    //! calc COPPER driver's checksum value
+    unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
+
+    //! check data contents
+    void CheckData(int n,
+                   unsigned int prev_evenum, unsigned int* cur_evenum,
+                   unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
+                   unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
+
+    //! check data contents
+    void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
+
+    //! check magic words of B2link HSLB header/trailer
+    int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
+
+    //! reduce and merge header/trailer
+    int CalcReducedDataSize(int* bufin, int nwords, int num_events, int num_nodes);
+    //    int CalcReducedDataSize(RawDataBlock* raw_datablk);
+
+    //! reduce and merge header/trailer
+    void CopyReducedData(int* bufin, int nwords, int num_events, int num_nodes, int* buf_to, int* nwords_to);
+    //    void CopyReducedData(RawDataBlock* raw_datablk, int* buf_to, int delete_flag_from);
+
+    //! calculate reduced data size
+    int CalcReducedNwords(int n);
+
+    //! copy data to reduced buffer
+    int CopyReducedBuffer(int n, int* buf_to);
+
+    //! check CRC16 in B2LFEE trailer
+    int CheckCRC16(int n, int finesse_num);
+
+    //! Pack data (format ver. = -1 -> Select the latest format version)
+    int* PackDetectorBuf(int* packed_buf_nwords,
+                         int* detector_buf_1st, int nwords_1st,
+                         int* detector_buf_2nd, int nwords_2nd,
+                         int* detector_buf_3rd, int nwords_3rd,
+                         int* detector_buf_4th, int nwords_4th,
+                         RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
+
+    //
+    // size of "COPPER front header" and "COPPER trailer"
+    //
+    //! Copper data words = ( total_data_length in COPPER header ) + COPPER_HEADER_TRAILER_NWORDS
+    enum {
+      SIZE_COPPER_DRIVER_HEADER = 7,
+      SIZE_COPPER_DRIVER_TRAILER = 2
+    };
+
+    //
+    // Data Format : "COPPER header"
+    //
+    enum {
+      POS_MAGIC_COPPER_1 = 0,
+      POS_EVE_NUM_COPPER = 1,
+      POS_SUBSYSTEM_ID = 2,
+      POS_CRATE_ID = 3,
+      POS_SLOT_ID = 4,
+      POS_MAGIC_COPPER_2 = 7,
+      POS_DATA_LENGTH = 8,
+      POS_CH_A_DATA_LENGTH = 9,
+      POS_CH_B_DATA_LENGTH = 10,
+      POS_CH_C_DATA_LENGTH = 11,
+      POS_CH_D_DATA_LENGTH = 12,
+
+      SIZE_COPPER_HEADER = 13
+    };
+
+
+
+    //
+    // Data Format : "COPPER Trailer"
+    //
+    enum {
+      POS_MAGIC_COPPER_3 = 0,
+      POS_CHKSUM_COPPER = 1,
+      POS_MAGIC_COPPER_4 = 2,
+
+      SIZE_COPPER_TRAILER = 3
+    };
+
+    //
+    // Data Format : "B2Link HSLB Header"
+    //
+    enum {
+      POS_MAGIC_B2LHSLB = 0,
+      //      POS_EVE_CNT_B2LHSLB = 1,
+      SIZE_B2LHSLB_HEADER = 1
+    };
+
+    // Data Format : "B2Link FEE Header"
+    // modified by Nov. 21, 2013, Nakao-san's New firmware?
+    enum {
+      POS_TT_CTIME_TYPE = 0,
+      POS_TT_TAG = 1,
+      POS_TT_UTIME = 2,
+      POS_EXP_RUN = 3,
+      POS_B2L_CTIME = 4,
+      SIZE_B2LFEE_HEADER = 5
+    };
+
+
+    //
+    // Data Format : B2Link FEE Trailer
+    //
+    enum {
+      POS_TT_CTIME_B2LFEE = 0,
+      POS_CHKSUM_B2LFEE = 1,
+      SIZE_B2LFEE_TRAILER = 2
+    };
+
+
+    //
+    // Data Format : "B2Link HSLB Trailer"
+    //
+    enum {
+      POS_CHKSUM_B2LHSLB = 0,
+      SIZE_B2LHSLB_TRAILER = 1
+    };
+
+
+
+    //
+    // COPPER magic words
+    //
+    enum {
+      COPPER_MAGIC_DRIVER_HEADER = 0x7FFF0008,
+      COPPER_MAGIC_FPGA_HEADER = 0xFFFFFAFA,
+      COPPER_MAGIC_FPGA_TRAILER = 0xFFFFF5F5,
+      COPPER_MAGIC_DRIVER_TRAILER = 0x7FFF0009
+    };
+
+
+    //
+    // magic words attached by HSLB
+    //
+    enum {
+      B2LHSLB_HEADER_MAGIC = 0xFFAA0000,
+      B2LHSLB_TRAILER_MAGIC = 0xFF550000
+    };
+
+    //! data fromat after size reduction
+    PostRawCOPPERFormat_v1 m_reduced_rawcpr; //! not record
+
+  protected :
+    ///ver.2 Change FEE format as presented at B2GM in Nov.2013 ( Nov.20, 2013)
+    //    ClassDefOverride(PreRawCOPPERFormat_v1, 2);
+
+  };
+
+
+  inline int PreRawCOPPERFormat_v1::GetOffset1stFINESSE(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
+    return pos_nwords;
+  }
+
+
+
+  inline int* PreRawCOPPERFormat_v1::Get1stDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get1stFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PreRawCOPPERFormat_v1::Get2ndDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get2ndFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset2ndFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PreRawCOPPERFormat_v1::Get3rdDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get3rdFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset3rdFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PreRawCOPPERFormat_v1::Get4thDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get4thFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset4thFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* PreRawCOPPERFormat_v1::GetExpRunSubrunBuf(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN;
+    return &(m_buffer[ pos_nwords ]);
+  }
+
+
+
+  inline unsigned int PreRawCOPPERFormat_v1::GetMagicDriverHeader(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_MAGIC_COPPER_1;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+  inline unsigned int PreRawCOPPERFormat_v1::GetMagicFPGAHeader(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_MAGIC_COPPER_2;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+  inline unsigned int PreRawCOPPERFormat_v1::GetMagicFPGATrailer(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
+
+    //    printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), trl.GetTrlNwords());
+
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+  inline unsigned int PreRawCOPPERFormat_v1::GetMagicDriverTrailer(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+
+  inline unsigned int PreRawCOPPERFormat_v1::GetDriverChkSum(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
+                     - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
+    return m_buffer[ pos_nwords ];
+  }
+
+
+  inline unsigned int PreRawCOPPERFormat_v1::GetCOPPERCounter(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + POS_EVE_NUM_COPPER + tmp_header.RAWHEADER_NWORDS;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+
+
+
+  inline unsigned int PreRawCOPPERFormat_v1::GetTrailerChksum(int  n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+
+
+
+
+}
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawARICH.h b/ROPCApplications/rawdata/dataobjects/include/RawARICH.h
new file mode 100644
index 0000000000000000000000000000000000000000..20129446ac54e90f19f1da04b91ff73c1553c6e4
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawARICH.h
@@ -0,0 +1,39 @@
+//+
+// File : RawCOPPER.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWARICH_H
+#define RAWARICH_H
+
+// Includes
+#include <stdio.h>
+#include <stdlib.h>
+#include <rawdata/dataobjects/RawCOPPER.h>
+#include <framework/datastore/DataStore.h>
+
+#include <TObject.h>
+
+namespace Belle2 {
+
+  /**
+   * The Raw ARICH class
+   * Class for RawCOPPER class data taken by ARICH
+   * Currently, this class is almost same as RawCOPPER class.
+   */
+
+  class RawARICH : public RawCOPPER {
+  public:
+    //! Default constructor
+    RawARICH();
+    //! Destructor
+    virtual ~RawARICH();
+    /// To derive from TObject
+    ClassDef(RawARICH, 1);
+  };
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawCDC.h b/ROPCApplications/rawdata/dataobjects/include/RawCDC.h
new file mode 100644
index 0000000000000000000000000000000000000000..423bc0bb9919d4369f2a944ccd8e623d5bef2bd6
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawCDC.h
@@ -0,0 +1,39 @@
+//+
+// File : RawCOPPER.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWCDC_H
+#define RAWCDC_H
+
+// Includes
+#include <stdio.h>
+#include <stdlib.h>
+#include <rawdata/dataobjects/RawCOPPER.h>
+#include <framework/datastore/DataStore.h>
+
+#include <TObject.h>
+
+namespace Belle2 {
+
+  /**
+   * The Raw CDC class
+   * Class for RawCOPPER class data taken by CDC
+   * Currently, this class is almost same as RawCOPPER class.
+   */
+
+  class RawCDC : public RawCOPPER {
+  public:
+    //! Default constructor
+    RawCDC();
+    //! Destructor
+    virtual ~RawCDC();
+    /// To derive from TObject
+    ClassDef(RawCDC, 1);
+  };
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawCOPPER.h b/ROPCApplications/rawdata/dataobjects/include/RawCOPPER.h
new file mode 100644
index 0000000000000000000000000000000000000000..efc88e08b1ba380e30e2f96fcdcfed0c8c838e9b
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawCOPPER.h
@@ -0,0 +1,743 @@
+//+
+// File : RawCOPPER.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWCOPPER_H
+#define RAWCOPPER_H
+
+// Includes
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+
+#include <rawdata/dataobjects/RawDataBlock.h>
+#include <rawdata/dataobjects/RawDataBlockFormat.h>
+#include <rawdata/dataobjects/RawCOPPERFormat.h>
+#include <rawdata/dataobjects/RawCOPPERFormat_latest.h>
+#include <rawdata/dataobjects/RawCOPPERFormat_v0.h>
+#include <rawdata/dataobjects/RawCOPPERFormat_v1.h>
+#include <rawdata/dataobjects/PreRawCOPPERFormat_v1.h>
+#include <rawdata/dataobjects/PreRawCOPPERFormat_latest.h>
+#include <rawdata/RawCOPPERPackerInfo.h>
+#include <TObject.h>
+
+//#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+
+
+// Divide ECL and KLM to barrel and endcap categories from Itoh-san's suggestion
+// Updated on May 9, 2014
+
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//
+// The latest DAQformat version number
+#define LATEST_POSTREDUCTION_FORMAT_VER 2 // Since Apr. 21, 2015
+//
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+
+namespace Belle2 {
+
+  /**
+   * The Raw COPPER class
+   * This class stores data received by COPPER via belle2linkt
+   * Data from all detectors except PXD are stored in this class
+   */
+  class RawCOPPER : public RawDataBlock {
+  public:
+    //! Default constructor
+    RawCOPPER();
+
+    //! Constructor using existing pointer to raw data buffer
+    //RawCOPPER(int* bufin, int nwords);
+    //! Destructor
+    virtual ~RawCOPPER();
+
+    //
+    // Get position of or pointer to data
+    //
+
+    //! set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
+    void SetBuffer(int* bufin, int nwords, int delete_flag, int num_events, int num_nodes) OVERRIDE_CPP17;
+
+    ///////////////////////////////////////////////////////////////////////////////////////
+    // POINTER TO "DETECTOR BUFFER"
+    //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
+    ///////////////////////////////////////////////////////////////////////////////////////
+    //! get Detector buffer length
+    int GetDetectorNwords(int n, int finesse_num);
+
+    //! get Detector buffer length of slot A
+    int Get1stDetectorNwords(int n);
+
+    //! get Detector buffer length of slot B
+    int Get2ndDetectorNwords(int n);
+
+    //! get Detector buffer length of slot C
+    int Get3rdDetectorNwords(int n);
+
+    //! get Detector buffer length of slot D
+    int Get4thDetectorNwords(int n);
+
+    //! get Detector buffer
+    int* GetDetectorBuffer(int n, int finesse_num);
+
+    //! get Detector buffer of slot A
+    int* Get1stDetectorBuffer(int n);
+
+    //! get Detector Buffer of slot B
+    int* Get2ndDetectorBuffer(int n);
+
+    //! get Detector Buffer of slot C
+    int* Get3rdDetectorBuffer(int n);
+
+    //! get Detector Buffer of slot D
+    int* Get4thDetectorBuffer(int n);
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+    //! get posistion of COPPER block in unit of word
+    virtual int GetBufferPos(int n) OVERRIDE_CPP17;
+
+    //! get buffer pointer of rawcopper header(Currently same as GetBufferPos)
+    virtual int* GetRawHdrBufPtr(int n);
+
+    //! get buffer pointer of rawcopper trailer
+    virtual int* GetRawTrlBufPtr(int n);
+
+    //! get FINESSE buffer pointer
+    int* GetFINESSEBuffer(int n, int finesse_num);
+
+    //! get FINESSE buffer pointer for slot A
+    int* Get1stFINESSEBuffer(int n);
+
+    //! get FINESSE buffer pointer for slot B
+    int* Get2ndFINESSEBuffer(int n);
+
+    //! get FINESSE buffer pointer for slot C
+    int* Get3rdFINESSEBuffer(int n);
+
+    //! get FINESSE buffer pointer for slot D
+    int* Get4thFINESSEBuffer(int n);
+
+
+    //
+    // Get information from "RawCOPPER header" attached by DAQ software
+    //
+
+    //! get Experimental # from header
+    int GetExpNo(int n);    //! get Experimental # from header
+
+    unsigned int GetExpRunSubrun(int n);    //! Exp# (10bit) run# (14bit) restart # (8bit)
+
+    int GetRunNo(int n);    //! get run # (14bit)
+
+    int GetSubRunNo(int n);    //! get subrun #(8bit)
+
+    unsigned int GetEveNo(int n);    //! get contents of header
+
+    int GetDataType(int n);    //! get contents of header
+
+    int GetTruncMask(int n);    //! get contents of header
+
+    //! Get Detected Error bitflag
+    unsigned int GetErrorBitFlag(int n);
+
+    //! Get Detected Error bitflag
+    void AddErrorBitFlag(int n, unsigned int error_bit_flag);
+
+
+    //! check CRC packet Error
+    int GetPacketCRCError(int n);
+
+    //! check CRC event Error
+    int GetEventCRCError(int n);
+
+    //! Get Event CRC16 value
+    int GetEventCRC16Value(int n, int finesse_num);
+
+    //! get node-ID from data
+    unsigned int GetNodeID(int n);
+
+    //
+    // Get information from 13words "COPPER header" attached by COPPER board
+    //
+    //! get COPPER counter(not event number)
+    virtual unsigned int GetCOPPERCounter(int n);
+
+    //! get # of FINNESEs which contains data
+    virtual int GetNumFINESSEBlock(int n);
+
+    //! get # of offset words
+    int GetOffsetFINESSE(int n, int finesse);
+
+    //! get # of offset words for FINESSE slot A buffer position
+    int GetOffset1stFINESSE(int n);
+
+    //! get # of offset words for FINESSE slot B buffer position
+    int GetOffset2ndFINESSE(int n);
+
+    //! get # of offset words for FINESSE slot C buffer position
+    int GetOffset3rdFINESSE(int n);
+
+    //! get # of offset words for FINESSE slot D buffer position
+    int GetOffset4thFINESSE(int n);
+
+    //! get data size of  FINESSE buffer
+    int GetFINESSENwords(int n, int finesse);
+
+    //! get data size of  FINESSE slot A buffer
+    int Get1stFINESSENwords(int n);
+
+    //! get data size of  FINESSE slot B buffer
+    int Get2ndFINESSENwords(int n);
+
+    //! get data size of  FINESSE slot C buffer
+    int Get3rdFINESSENwords(int n);
+
+    //! get data size of  FINESSE slot D buffer
+    int Get4thFINESSENwords(int n);
+
+    //! For copying FTSW word1 (FEE header)
+    unsigned int GetB2LHeaderWord(int n, int finesse_buffer_pos);
+
+    //
+    // Get information from "B2link(attached by FEE and HLSB) header"
+    //
+    //! get b2l block from "FEE b2link header"
+    //    virtual int* GetFTSW2Words(int n);
+
+    //! get b2l block from "FEE b2link header"
+    virtual int* GetExpRunSubrunBuf(int n);
+
+    //! get b2l block from "FEE b2link header"
+    virtual unsigned int GetB2LFEE32bitEventNumber(int n);
+
+    //
+    // read magic word to check data
+    //
+    //! get magic word of  COPPER driver header
+    unsigned int GetMagicDriverHeader(int n);
+
+    //! get magic word of  COPPER FPGA header
+    unsigned int GetMagicFPGAHeader(int n);
+
+    //! get magic word of  COPPER FPGA trailer
+    unsigned int GetMagicFPGATrailer(int n);
+
+    //! get magic word of  COPPER driver trailer
+    unsigned int GetMagicDriverTrailer(int n);
+
+    //! Get checksum in RawTrailer
+    unsigned int GetTrailerChksum(int  n);
+
+    //! Check if COPPER Magic words are correct
+    bool CheckCOPPERMagic(int n);
+
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    //! Check B2LFEE header version
+    void CheckB2LFEEHeaderVersion(int  n);
+#endif
+
+    //! Check if COPPER Magic words are correct
+    unsigned int GetTTCtimeTRGType(int n);
+
+    //! Check if COPPER Magic words are correct
+    unsigned int GetTTUtime(int n);
+
+    //! should be called by DeSerializerCOPPER.cc and fill contents in RawHeader
+    unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
+                                       unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no);
+
+    //! read COPPER driver's checksum value
+    unsigned int GetDriverChkSum(int n);
+
+    //! calc COPPER driver's checksum value
+    unsigned int CalcDriverChkSum(int n);
+
+    //! calc XOR checksum
+    unsigned int CalcXORChecksum(int* buf, int nwords);
+
+    //! check data contents
+    void CheckData(int n,
+                   unsigned int prev_evenum, unsigned int* cur_evenum,
+                   unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
+                   unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no);
+
+    //! check data contents
+    void CheckUtimeCtimeTRGType(int n);
+
+    //! Get ctime
+    int GetTTCtime(int n);
+
+    //! Get trgtype
+    int GetTRGType(int n);
+
+    //! Get timeval
+    void GetTTTimeVal(int n, struct timeval* tv);
+
+    //! read data, detect and set the version number of the data format
+    void SetVersion();
+
+    //! Get timeval
+    void SetVersion(std::string class_name);
+
+    //! Check the version number of data format
+    void CheckVersionSetBuffer();
+
+    //! show m_buffer
+    void ShowBuffer();
+
+    //! Packer for RawCOPPER class
+    //! Pack data (format ver. = -1 -> Select the latest format version)
+    void PackDetectorBuf(int* detector_buf_1st, int nwords_1st,
+                         int* detector_buf_2nd, int nwords_2nd,
+                         int* detector_buf_3rd, int nwords_3rd,
+                         int* detector_buf_4th, int nwords_4th,
+                         RawCOPPERPackerInfo rawcprpacker_info);
+
+    //! Pack dummy data (format ver. = -1 -> Select the latest format version)
+    void PackDetectorBuf4DummyData(int* detector_buf_1st, int nwords_1st,
+                                   int* detector_buf_2nd, int nwords_2nd,
+                                   int* detector_buf_3rd, int nwords_3rd,
+                                   int* detector_buf_4th, int nwords_4th,
+                                   RawCOPPERPackerInfo rawcprpacker_info);
+
+
+    /** Return a short summary of this object's contents in HTML format. */
+    std::string getInfoHTML() const;
+
+    enum {
+      POS_FORMAT_VERSION = 1,
+      FORMAT_MASK = 0x0000FF00
+    };
+
+    //! class to access
+    RawCOPPERFormat* m_access; //! do not record
+
+    /// Version of the format
+    int m_version; //! do not record
+
+  protected :
+    ///ver.2 Change FEE format as presented at B2GM in Nov.2013 ( Nov.20, 2013)
+    ///ver.3 Change FEE format as presented at B2GM in Nov.2013 ( May 1, 2014)
+    ///ver.4 Do not record m_access pointer ( Dec 19, 2014)
+    ClassDefOverride(RawCOPPER, 3);
+
+  };
+
+
+  inline int* RawCOPPER::GetRawHdrBufPtr(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetRawHdrBufPtr(n);
+  }
+
+  inline int* RawCOPPER::GetRawTrlBufPtr(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetRawTrlBufPtr(n);
+  }
+
+  inline unsigned int RawCOPPER::GetDriverChkSum(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetDriverChkSum(n);
+  }
+
+  inline int RawCOPPER::GetExpNo(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetExpNo(n);
+  }
+
+  inline unsigned int RawCOPPER::GetExpRunSubrun(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetExpRunSubrun(n);
+  }
+
+  inline int RawCOPPER::GetRunNo(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetRunNo(n);
+  }
+
+
+  inline int RawCOPPER::GetSubRunNo(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetSubRunNo(n);
+  }
+
+  inline unsigned int RawCOPPER::GetEveNo(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetEveNo(n);
+  }
+
+
+  inline unsigned int RawCOPPER::GetNodeID(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetNodeID(n);
+  }
+
+
+  inline int RawCOPPER::GetDataType(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetDataType(n);
+  }
+
+  inline int RawCOPPER::GetTruncMask(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetTruncMask(n);
+  }
+
+  inline unsigned int RawCOPPER::GetErrorBitFlag(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetErrorBitFlag(n);
+  }
+
+  inline void RawCOPPER::AddErrorBitFlag(int n, unsigned int error_bit_flag)
+  {
+    CheckVersionSetBuffer();
+    return m_access->AddErrorBitFlag(n, error_bit_flag);
+  }
+
+  inline int RawCOPPER::GetPacketCRCError(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetPacketCRCError(n);
+  }
+
+  inline int RawCOPPER::GetEventCRCError(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetEventCRCError(n);
+  }
+
+  inline int RawCOPPER::GetEventCRC16Value(int n, int finesse_num)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetEventCRC16Value(n, finesse_num);
+  }
+
+  inline unsigned int RawCOPPER::GetCOPPERCounter(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetCOPPERCounter(n);
+  }
+
+  inline int RawCOPPER::Get1stDetectorNwords(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get1stDetectorNwords(n);
+  }
+
+  inline int RawCOPPER::Get2ndDetectorNwords(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get2ndDetectorNwords(n);
+  }
+
+  inline int RawCOPPER::Get3rdDetectorNwords(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get3rdDetectorNwords(n);
+  }
+
+  inline int RawCOPPER::Get4thDetectorNwords(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get4thDetectorNwords(n);
+  }
+
+  inline int RawCOPPER::Get1stFINESSENwords(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get1stFINESSENwords(n);
+  }
+
+  inline int RawCOPPER::Get2ndFINESSENwords(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get2ndFINESSENwords(n);
+  }
+
+  inline int RawCOPPER::Get3rdFINESSENwords(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get3rdFINESSENwords(n);
+  }
+
+  inline int RawCOPPER::Get4thFINESSENwords(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get4thFINESSENwords(n);
+  }
+
+  inline int RawCOPPER::GetOffset1stFINESSE(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetOffset1stFINESSE(n);
+  }
+
+  inline int RawCOPPER::GetOffset2ndFINESSE(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetOffset2ndFINESSE(n);
+  }
+
+  inline int RawCOPPER::GetOffset3rdFINESSE(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetOffset3rdFINESSE(n);
+  }
+
+  inline int RawCOPPER::GetOffset4thFINESSE(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetOffset4thFINESSE(n);
+  }
+
+  inline int* RawCOPPER::Get1stFINESSEBuffer(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get1stFINESSEBuffer(n);
+  }
+
+  inline int* RawCOPPER::Get2ndFINESSEBuffer(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get2ndFINESSEBuffer(n);
+  }
+
+  inline int* RawCOPPER::Get3rdFINESSEBuffer(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get3rdFINESSEBuffer(n);
+  }
+
+  inline int* RawCOPPER::Get4thFINESSEBuffer(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get4thFINESSEBuffer(n);
+  }
+
+  inline int* RawCOPPER::Get1stDetectorBuffer(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get1stDetectorBuffer(n);
+  }
+
+  inline int* RawCOPPER::Get2ndDetectorBuffer(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get2ndDetectorBuffer(n);
+  }
+
+  inline int* RawCOPPER::Get3rdDetectorBuffer(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get3rdDetectorBuffer(n);
+  }
+
+  inline int* RawCOPPER::Get4thDetectorBuffer(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->Get4thDetectorBuffer(n);
+  }
+
+  inline int* RawCOPPER::GetExpRunSubrunBuf(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetExpRunSubrunBuf(n);
+  }
+
+  inline unsigned int RawCOPPER::GetMagicDriverHeader(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetMagicDriverHeader(n);
+  }
+
+  inline unsigned int RawCOPPER::GetMagicFPGAHeader(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetMagicFPGAHeader(n);
+  }
+
+  inline unsigned int RawCOPPER::GetMagicFPGATrailer(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetMagicFPGATrailer(n);
+  }
+
+  inline unsigned int RawCOPPER::GetMagicDriverTrailer(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetMagicDriverTrailer(n);
+  }
+
+  inline unsigned int RawCOPPER::GetTrailerChksum(int  n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetTrailerChksum(n);
+  }
+
+  inline unsigned int RawCOPPER::GetTTCtimeTRGType(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetTTCtimeTRGType(n);
+  }
+
+  inline unsigned int RawCOPPER::GetTTUtime(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetTTUtime(n);
+  }
+
+  inline int RawCOPPER::GetTTCtime(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetTTCtime(n);
+  }
+
+  inline int RawCOPPER::GetTRGType(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetTRGType(n);
+  }
+
+  inline void RawCOPPER::GetTTTimeVal(int n, struct timeval* tv)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetTTTimeVal(n, tv);
+  }
+
+  inline int RawCOPPER::GetBufferPos(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetBufferPos(n);
+  }
+
+  inline   unsigned int RawCOPPER::CalcDriverChkSum(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->CalcDriverChkSum(n);
+  }
+
+
+  inline  int RawCOPPER::GetNumFINESSEBlock(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetNumFINESSEBlock(n);
+  }
+
+  inline  int RawCOPPER::GetDetectorNwords(int n, int finesse_num)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetDetectorNwords(n, finesse_num);
+  }
+
+  inline  int RawCOPPER::GetFINESSENwords(int n, int finesse_num)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetFINESSENwords(n, finesse_num);
+  }
+
+  inline  int RawCOPPER::GetOffsetFINESSE(int n, int finesse_num)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetOffsetFINESSE(n, finesse_num);
+  }
+
+  inline  int* RawCOPPER::GetFINESSEBuffer(int n, int finesse_num)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetFINESSEBuffer(n, finesse_num);
+  }
+
+  inline  int* RawCOPPER::GetDetectorBuffer(int n, int finesse_num)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetDetectorBuffer(n, finesse_num);
+  }
+
+  inline  unsigned int RawCOPPER::GetB2LFEE32bitEventNumber(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetB2LFEE32bitEventNumber(n);
+  }
+
+  inline  unsigned int RawCOPPER::CalcXORChecksum(int* buf, int nwords)
+  {
+    CheckVersionSetBuffer();
+    return m_access->CalcXORChecksum(buf, nwords);
+  }
+
+  inline  void RawCOPPER::CheckData(int n,
+                                    unsigned int prev_evenum, unsigned int* cur_evenum_rawcprhdr,
+                                    unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
+                                    unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+  {
+
+    CheckVersionSetBuffer();
+    m_access->CheckData(n,
+                        prev_evenum, cur_evenum_rawcprhdr,
+                        prev_copper_ctr, cur_copper_ctr,
+                        prev_exprunsubrun_no,  cur_exprunsubrun_no);
+    return;
+  }
+
+  inline  bool RawCOPPER::CheckCOPPERMagic(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->CheckCOPPERMagic(n);
+  }
+
+  inline  void RawCOPPER::CheckUtimeCtimeTRGType(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->CheckUtimeCtimeTRGType(n);
+  }
+
+  inline  unsigned int RawCOPPER::GetB2LHeaderWord(int n, int finesse_buffer_pos)
+  {
+    CheckVersionSetBuffer();
+    return m_access->GetB2LHeaderWord(n, finesse_buffer_pos);
+  }
+
+  inline  unsigned int RawCOPPER::FillTopBlockRawHeader(unsigned int m_node_id, unsigned int prev_eve32,
+                                                        unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+  {
+    CheckVersionSetBuffer();
+    return m_access->FillTopBlockRawHeader(m_node_id, prev_eve32,
+                                           prev_exprunsubrun_no, cur_exprunsubrun_no);
+  }
+
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+  inline  void RawCOPPER::CheckB2LFEEHeaderVersion(int n)
+  {
+    CheckVersionSetBuffer();
+    return m_access->CheckB2LFEEHeaderVersion(n);
+  }
+#endif
+
+  inline void RawCOPPER::CheckVersionSetBuffer()
+  {
+    if (((m_buffer[ POS_FORMAT_VERSION ] & FORMAT_MASK) >> 8)  != m_version
+        || m_access == NULL) {
+      SetVersion();
+    }
+    m_access->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+  }
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawCOPPERFormat.h b/ROPCApplications/rawdata/dataobjects/include/RawCOPPERFormat.h
new file mode 100644
index 0000000000000000000000000000000000000000..df69a53043c06a743126630db7119fce564f0fb7
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawCOPPERFormat.h
@@ -0,0 +1,434 @@
+//+
+// File : RawCOPPERFormat.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+#ifndef RAWCOPPERFORMAT_H
+#define RAWCOPPERFORMAT_H
+
+// Includes
+#include <stdio.h>
+#include <string>
+#include <stdlib.h>
+#include <sys/time.h>
+
+#include <rawdata/RawCOPPERPackerInfo.h>
+#include <rawdata/dataobjects/RawDataBlockFormat.h>
+
+/* #include <framework/datastore/DataStore.h> */
+/* #include <TObject.h> */
+
+//#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+
+#define DETECTOR_MASK 0xFF000000 // tentative
+#define COPPERID_MASK 0x00FFFFFF // tentative
+#define SVD_ID  0x01000000 // tentative
+#define CDC_ID  0x02000000 // tentative
+#define TOP_ID 0x03000000 // tentative
+#define ARICH_ID 0x04000000 // tentative
+#define BECL_ID  0x05000000 // tentative
+#define EECL_ID  0x06000000 // tentative
+#define BKLM_ID  0x07000000 // tentative
+#define EKLM_ID  0x08000000 // tentative
+#define TRGDATA_ID  0x10000000 // tentative
+#define CDCTRGDATA_ID  0x11000000 // tentative
+#define TOPTRGDATA_ID  0x12000000 // tentative
+#define ECLTRGDATA_ID  0x13000000 // tentative
+#define KLMTRGDATA_ID  0x14000000 // tentative
+#define GDLTRGDATA_ID  0x15000000 // tentative
+
+
+namespace Belle2 {
+
+  /**
+   * The Raw COPPER class
+   * This class stores data received by COPPER via belle2linkt
+   * Data from all detectors except PXD are stored in this class
+   */
+  //  class RawCOPPERFormat : public TObject {
+  class RawCOPPERFormat : public RawDataBlockFormat {
+  public:
+    /*     //! Default constructor */
+    RawCOPPERFormat();
+
+    //! Constructor using existing pointer to raw data buffer
+    //RawCOPPERFormat(int* bufin, int nwords);
+    //! Destructor
+    virtual ~RawCOPPERFormat() {}
+
+    //
+    // Functions for  RawDataBlock
+    //
+    //! set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
+    /*     void SetBuffer(int* bufin, int nwords, int delete_flag, int num_events, int num_nodes); */
+
+    /*     //! Get total length of m_buffer */
+    /*     virtual int TotalBufNwords(); */
+
+    /*     //! get nth buffer pointer */
+    /*     virtual int* GetBuffer(int n); */
+
+    /*     //! get pointer to  buffer(m_buffer) */
+    /*     virtual int* GetWholeBuffer(); */
+
+    /*     //! get # of data blocks = (# of nodes)*(# of events) */
+    /*     virtual int GetNumEntries() { return m_num_events * m_num_nodes; } */
+
+    /*     //! get # of data sources(e.g. # of COPPER boards) in m_buffer */
+    /*     virtual int GetNumNodes() { return m_num_nodes; } */
+
+    /*     //! get # of events in m_buffer */
+    /*     virtual int GetNumEvents() { return m_num_events; } */
+
+    /*     //! get size of a data block */
+    /*     virtual int GetBlockNwords(int n); */
+
+    /*      //! print out data  */
+    /*     virtual void PrintData(int* buf, int nwords); */
+
+    /*     enum { */
+    /*       POS_NWORDS = 0, */
+    /*       POS_NODE_ID = 6 */
+    /*     }; */
+
+    /*     enum { */
+    /*       // Tentatively needed to distinguish new and old FTSW format, which will be changed in Nov. 2013 */
+    /*       POS_FTSW_ID_OLD = 5, */
+    /*       TEMP_POS_NWORDS_HEADER = 1, */
+    /*       OLD_FTSW_NWORDS_HEADER = 6 */
+    /*     }; */
+
+    //
+    // Functions for RawCOPPER
+    //
+
+    // POINTER TO "DETECTOR BUFFER"
+    //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
+
+    //! get Detector buffer length
+    virtual int GetDetectorNwords(int n, int finesse_num) = 0;
+
+    //! get Detector buffer length of slot A
+    virtual int Get1stDetectorNwords(int n) = 0;
+
+    //! get Detector buffer length of slot B
+    virtual int Get2ndDetectorNwords(int n) = 0;
+
+    //! get Detector buffer length of slot C
+    virtual int Get3rdDetectorNwords(int n) = 0;
+
+    //! get Detector buffer length of slot D
+    virtual int Get4thDetectorNwords(int n) = 0;
+
+    //! get Detector buffer
+    virtual int* GetDetectorBuffer(int n, int finesse_num);
+
+    //! get Detector buffer of slot A
+    virtual int* Get1stDetectorBuffer(int n) = 0;
+
+    //! get Detector Buffer of slot B
+    virtual int* Get2ndDetectorBuffer(int n) = 0;
+
+    //! get Detector Buffer of slot C
+    virtual int* Get3rdDetectorBuffer(int n) = 0;
+
+    //! get Detector Buffer of slot D
+    virtual int* Get4thDetectorBuffer(int n) = 0;
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+    /*     //! get posistion of COPPER block in unit of word */
+    /*     virtual int GetBufferPos(int n) = 0; */
+
+    //! get buffer pointer of rawcopper header(Currently same as GetBufferPos)
+    virtual int* GetRawHdrBufPtr(int n);
+
+    //! get buffer pointer of rawcopper trailer
+    virtual int* GetRawTrlBufPtr(int n) = 0;
+
+    //! get FINESSE buffer pointer
+    virtual int* GetFINESSEBuffer(int n, int finesse_num);
+
+    //! get FINESSE buffer pointer for slot A
+    virtual int* Get1stFINESSEBuffer(int n);
+
+    //! get FINESSE buffer pointer for slot B
+    virtual int* Get2ndFINESSEBuffer(int n);
+
+    //! get FINESSE buffer pointer for slot C
+    virtual int* Get3rdFINESSEBuffer(int n);
+
+    //! get FINESSE buffer pointer for slot D
+    virtual int* Get4thFINESSEBuffer(int n);
+
+
+
+    //
+    // Get information from "RawCOPPERFormat header" attached by DAQ software
+    //
+
+    /// get Experimental # from header
+    virtual int GetExpNo(int n) = 0;    //! get Experimental # from header
+
+    virtual unsigned int GetExpRunSubrun(int n) = 0;    //! Exp# (10bit) run# (14bit) restart # (8bit)
+
+    virtual int GetRunNo(int n) = 0;    //! get run # (14bit)
+
+    virtual int GetSubRunNo(int n) = 0;    //! get subrun #(8bit)
+
+    virtual unsigned int GetEveNo(int n) = 0;    //! get contents of header
+
+    virtual int GetDataType(int n) = 0;    //! get contents of header
+
+    virtual int GetTruncMask(int n) = 0;    //! get contents of header
+
+    //! Get Detected Error bitflag
+    virtual unsigned int GetErrorBitFlag(int n) = 0;
+
+    //! Add Detected Error bitflag
+    virtual void AddErrorBitFlag(int n, unsigned int error_bit_flag) = 0;
+
+    //! check CRC packet Error
+    virtual int GetPacketCRCError(int n);
+
+    //! check CRC event Error
+    virtual int GetEventCRCError(int n);
+
+    //! Get Event CRC16 value
+    virtual int GetEventCRC16Value(int n, int finesse_num);
+
+    //! get node-ID from data
+    virtual unsigned int GetNodeID(int n) = 0;
+
+    //
+    // Get information from 13words "COPPER header" attached by COPPER board
+    //
+    //! get COPPER counter(not event number)
+    virtual unsigned int GetCOPPERCounter(int n) = 0;
+
+    //! get # of FINNESEs which contains data
+    virtual int GetNumFINESSEBlock(int n) = 0;
+
+    //! get # of offset words
+    virtual int GetOffsetFINESSE(int n, int finesse);
+
+    //! get # of offset words for FINESSE slot A buffer position
+    virtual int GetOffset1stFINESSE(int n) = 0;
+
+    //! get # of offset words for FINESSE slot B buffer position
+    virtual int GetOffset2ndFINESSE(int n);
+
+    //! get # of offset words for FINESSE slot C buffer position
+    virtual int GetOffset3rdFINESSE(int n);
+
+    //! get # of offset words for FINESSE slot D buffer position
+    virtual int GetOffset4thFINESSE(int n);
+
+    //! get data size of  FINESSE buffer
+    virtual int GetFINESSENwords(int n, int finesse) = 0;
+
+    //! get data size of  FINESSE slot A buffer
+    virtual int Get1stFINESSENwords(int n) = 0;
+
+    //! get data size of  FINESSE slot B buffer
+    virtual int Get2ndFINESSENwords(int n) = 0;
+
+    //! get data size of  FINESSE slot C buffer
+    virtual int Get3rdFINESSENwords(int n) = 0;
+
+    //! get data size of  FINESSE slot D buffer
+    virtual int Get4thFINESSENwords(int n) = 0;
+
+    //! For copying FTSW word1 (FEE header)
+    virtual unsigned int GetB2LHeaderWord(int n, int finesse_buffer_pos);
+
+    //
+    // Get information from "B2link(attached by FEE and HLSB) header"
+    //
+    //! get b2l block from "FEE b2link header"
+    //    virtual int* GetFTSW2Words(int n) = 0;
+
+    //! get b2l block from "FEE b2link header"
+    virtual int* GetExpRunSubrunBuf(int n) = 0;
+
+    //! get b2l block from "FEE b2link header"
+    virtual unsigned int GetB2LFEE32bitEventNumber(int n) = 0;
+
+    //
+    // read magic word to check data
+    //
+    //! get magic word of  COPPER driver header
+    virtual unsigned int GetMagicDriverHeader(int n) = 0;
+
+    //! get magic word of  COPPER FPGA header
+    virtual unsigned int GetMagicFPGAHeader(int n) = 0;
+
+    //! get magic word of  COPPER FPGA trailer
+    virtual unsigned int GetMagicFPGATrailer(int n) = 0;
+
+    //! get magic word of  COPPER driver trailer
+    virtual unsigned int GetMagicDriverTrailer(int n) = 0;
+
+    //! Get checksum in RawTrailer
+    virtual unsigned int GetTrailerChksum(int  n) = 0 ;
+
+    //! Check if COPPER Magic words are correct
+    virtual bool CheckCOPPERMagic(int n) = 0;
+
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    //! Check B2LFEE header version
+    virtual void CheckB2LFEEHeaderVersion(int  n) = 0;
+#endif
+
+    //! Check if COPPER Magic words are correct
+    virtual unsigned int GetTTCtimeTRGType(int n) = 0;
+
+    //! Check if COPPER Magic words are correct
+    virtual unsigned int GetTTUtime(int n) = 0;
+
+    //! should be called by DeSerializerCOPPER.cc and fill contents in RawHeader
+    virtual unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
+                                               unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) = 0;
+
+    //! read COPPER driver's checksum value
+    virtual unsigned int GetDriverChkSum(int n) = 0;
+
+    //! calc COPPER driver's checksum value
+    virtual unsigned int CalcDriverChkSum(int n) = 0;
+
+
+    //! check data contents
+    virtual void CheckData(int n,
+                           unsigned int prev_evenum, unsigned int* cur_evenum,
+                           unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
+                           unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) = 0;
+
+    //! check data contents
+    virtual void CheckUtimeCtimeTRGType(int n) = 0;
+
+    //! Get ctime
+    virtual int GetTTCtime(int n) = 0;
+
+    //! Get trgtype
+    virtual int GetTRGType(int n) = 0;
+
+    //! Get timeval
+    virtual void GetTTTimeVal(int n, struct timeval* tv) = 0;
+
+    //! calc XOR checksum
+    virtual unsigned int CalcXORChecksum(int* buf, int nwords);
+
+    //! Pack data (format ver. = -1 -> Select the latest format version)
+    virtual int* PackDetectorBuf(int* packed_buf_nwords,
+                                 int* detector_buf_1st, int nwords_1st,
+                                 int* detector_buf_2nd, int nwords_2nd,
+                                 int* detector_buf_3rd, int nwords_3rd,
+                                 int* detector_buf_4th, int nwords_4th,
+                                 RawCOPPERPackerInfo rawcprpacker_info) = 0;
+
+  protected :
+
+    /*     /// number of words of buffer */
+    /*     int m_nwords; */
+
+    /*     /// number of nodes in this object */
+    /*     int m_num_nodes; */
+
+    /*     /// number of events in this object */
+    /*     int m_num_events; */
+
+    /*     /// Buffer to access data */
+    /*     int* m_buffer; //! not recorded */
+
+    ///ver.3 : Separate from RawDataBLock to avoid a memory leak ( July 24, 2014)
+    //    ClassDef(RawCOPPERFormat, 3);
+
+  };
+
+
+
+  inline int* RawCOPPERFormat::GetRawHdrBufPtr(int n)
+  {
+    int pos_nwords = GetBufferPos(n);
+    return &(m_buffer[ pos_nwords ]);
+  }
+
+
+  inline int RawCOPPERFormat::GetOffset2ndFINESSE(int n)
+  {
+    return GetOffset1stFINESSE(n) + Get1stFINESSENwords(n);
+  }
+
+  inline int RawCOPPERFormat::GetOffset3rdFINESSE(int n)
+  {
+    return GetOffset2ndFINESSE(n) + Get2ndFINESSENwords(n);
+  }
+
+  inline int RawCOPPERFormat::GetOffset4thFINESSE(int n)
+  {
+    return GetOffset3rdFINESSE(n) + Get3rdFINESSENwords(n);
+  }
+
+
+
+  inline int* RawCOPPERFormat::Get1stFINESSEBuffer(int n)
+  {
+    int pos_nwords = GetOffset1stFINESSE(n);
+    if (pos_nwords >= m_nwords) {
+      printf("[DEBUG] Data size(0x%.8x) is smaller than data position info(0x%.8x). Exiting...\n",  m_nwords, pos_nwords);
+      for (int i = 0; i < m_nwords; i++) {
+        printf("%.8x ", m_buffer[ i ]);
+        if ((i % 10) == 9) printf("\n");
+      }
+      B2FATAL("Data size is smaller than data position info. Exiting...");
+    }
+    return &(m_buffer[ pos_nwords]);
+  }
+
+  inline int* RawCOPPERFormat::Get2ndFINESSEBuffer(int n)
+  {
+    int pos_nwords = GetOffset2ndFINESSE(n);
+    if (pos_nwords >= m_nwords) {
+      printf("[DEBUG] Data size(0x%.8x) is smaller than data position info(0x%.8x). Exiting...\n",  m_nwords, pos_nwords);
+      for (int i = 0; i < m_nwords; i++) {
+        printf("%.8x ", m_buffer[ i ]);
+        if ((i % 10) == 9) printf("\n");
+      }
+      B2FATAL("Data size is smaller than data position info. Exiting...");
+    }
+    return &(m_buffer[ pos_nwords]);
+  }
+
+  inline int* RawCOPPERFormat::Get3rdFINESSEBuffer(int n)
+  {
+    int pos_nwords = GetOffset3rdFINESSE(n);
+    if (pos_nwords >= m_nwords) {
+      printf("[DEBUG] Data size(0x%.8x) is smaller than data position info(0x%.8x). Exiting...\n",  m_nwords, pos_nwords);
+      for (int i = 0; i < m_nwords; i++) {
+        printf("%.8x ", m_buffer[ i ]);
+        if ((i % 10) == 9) printf("\n");
+      }
+      B2FATAL("Data size is smaller than data position info. Exiting...");
+    }
+    return &(m_buffer[ pos_nwords]);
+  }
+
+  inline int* RawCOPPERFormat::Get4thFINESSEBuffer(int n)
+  {
+    int pos_nwords = GetOffset4thFINESSE(n);
+    if (pos_nwords >= m_nwords) {
+      printf("[DEBUG] Data size(0x%.8x) is smaller than data position info(0x%.8x). Exiting...\n",  m_nwords, pos_nwords);
+      for (int i = 0; i < m_nwords; i++) {
+        printf("%.8x ", m_buffer[ i ]);
+        if ((i % 10) == 9) printf("\n");
+      }
+      B2FATAL("Data size is smaller than data position info. Exiting...");
+    }
+    return &(m_buffer[ pos_nwords]);
+  }
+
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawCOPPERFormat_latest.h b/ROPCApplications/rawdata/dataobjects/include/RawCOPPERFormat_latest.h
new file mode 100644
index 0000000000000000000000000000000000000000..9668291ff9e86d84f34490fac6b39255074f2cc7
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawCOPPERFormat_latest.h
@@ -0,0 +1,335 @@
+//+
+// File : RawCOPPERFormat_latest.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWCOPPERFORMAT_LATEST_H
+#define RAWCOPPERFORMAT_LATEST_H
+
+// Includes
+#include <rawdata/dataobjects/RawCOPPERFormat.h>
+#include <rawdata/dataobjects/RawHeader_latest.h>
+#include <rawdata/dataobjects/RawTrailer_latest.h>
+#include <rawdata/CRCCalculator.h>
+
+/* #include <framework/datastore/DataStore.h> */
+/* #include <TObject.h> */
+
+//#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+
+
+namespace Belle2 {
+
+  /**
+   * The Raw COPPER class ver.1 ( the latest version since May, 2014 )
+   * This class stores data received by COPPER via belle2linkt
+   * Data from all detectors except PXD are stored in this class
+   */
+
+  class RawCOPPERFormat_latest : public RawCOPPERFormat {
+  public:
+    //! Default constructor
+    RawCOPPERFormat_latest();
+
+    //! Constructor using existing pointer to raw data buffer
+    //RawCOPPERFormat_latest(int* bufin, int nwords);
+    //! Destructor
+    virtual ~RawCOPPERFormat_latest();
+
+    //
+    // Get position of or pointer to data
+    //
+    ///////////////////////////////////////////////////////////////////////////////////////
+    // POINTER TO "DETECTOR BUFFER"
+    //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+
+    //! get Detector buffer length of slot A
+    int Get1stDetectorNwords(int n) OVERRIDE_CPP17;
+
+    //! get Detector buffer length of slot B
+    int Get2ndDetectorNwords(int n) OVERRIDE_CPP17;
+
+    //! get Detector buffer length of slot C
+    int Get3rdDetectorNwords(int n) OVERRIDE_CPP17;
+
+    //! get Detector buffer length of slot D
+    int Get4thDetectorNwords(int n) OVERRIDE_CPP17;
+
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+    //! get buffer pointer of rawcopper trailer
+    int* GetRawTrlBufPtr(int n) OVERRIDE_CPP17;
+
+    //
+    // Get information from "RawCOPPERFormat_latest header" attached by DAQ software
+    //
+
+    int GetExpNo(int n) OVERRIDE_CPP17;    //! get Experimental # from header
+
+    unsigned int GetExpRunSubrun(int n) OVERRIDE_CPP17;    //! Exp# (10bit) run# (14bit) restart # (8bit)
+
+    int GetRunNo(int n) OVERRIDE_CPP17;    //! get run # (14bit)
+
+    int GetSubRunNo(int n) OVERRIDE_CPP17;    //! get subrun #(8bit)
+
+    unsigned int GetEveNo(int n) OVERRIDE_CPP17;    //! get contents of header
+
+    int GetDataType(int n) OVERRIDE_CPP17;    //! get contents of header
+
+    int GetTruncMask(int n) OVERRIDE_CPP17;    //! get contents of header
+
+    //! Get Detected Error bitflag
+    unsigned int GetErrorBitFlag(int n) OVERRIDE_CPP17;
+
+    //! Add Detected Error bitflag
+    void AddErrorBitFlag(int n, unsigned int error_bit_flag) OVERRIDE_CPP17;
+
+    //! check CRC packet Error
+    int GetPacketCRCError(int n) OVERRIDE_CPP17;
+
+    //! check CRC event Error
+    int GetEventCRCError(int n) OVERRIDE_CPP17;
+
+    //! get node-ID from data
+    unsigned int GetNodeID(int n) OVERRIDE_CPP17;
+
+    //
+    // Get information from 13words "COPPER header" attached by COPPER board
+    //
+
+    //! get # of FINNESEs which contains data
+    virtual int GetNumFINESSEBlock(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE slot A buffer
+    int Get1stFINESSENwords(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE slot B buffer
+    int Get2ndFINESSENwords(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE slot C buffer
+    int Get3rdFINESSENwords(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE slot D buffer
+    int Get4thFINESSENwords(int n) OVERRIDE_CPP17;
+
+    //
+    // Get information from "B2link(attached by FEE and HLSB) header"
+    //
+    //! get b2l block from "FEE b2link header"
+    //    virtual int* GetFTSW2Words(int n);
+
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    //! Check B2LFEE header version
+    void CheckB2LFEEHeaderVersion(int  n) OVERRIDE_CPP17;
+#endif
+
+    //! Check if COPPER Magic words are correct
+    unsigned int GetTTCtimeTRGType(int n) OVERRIDE_CPP17;
+
+    //! Check if COPPER Magic words are correct
+    unsigned int GetTTUtime(int n) OVERRIDE_CPP17;
+
+    /*     //! calc COPPER driver's checksum value */
+    /*     virtual unsigned int CalcDriverChkSum(int n) = 0; */
+
+
+    //! Get ctime
+    int GetTTCtime(int n) OVERRIDE_CPP17;
+
+    //! Get trgtype
+    int GetTRGType(int n) OVERRIDE_CPP17;
+
+    //! Get timeval
+    void GetTTTimeVal(int n, struct timeval* tv) OVERRIDE_CPP17;
+
+    /// Format version number
+    enum {
+      DATA_FORMAT_VERSION = 2
+    };
+
+    //! header ( not recorded )
+    RawHeader_latest tmp_header;
+
+    //! trailer ( not recorded )
+    RawTrailer_latest tmp_trailer;
+
+
+  protected :
+    ///ver.2 Change FEE format as presented at B2GM in Nov.2013 ( Nov.20, 2013)
+    //    ClassDefOverride(RawCOPPERFormat_latest, 2);
+  };
+
+
+
+
+  inline int* RawCOPPERFormat_latest::GetRawTrlBufPtr(int n)
+  {
+    int pos_nwords;
+    if (n == (m_num_events * m_num_nodes) - 1) {
+      pos_nwords = m_nwords - tmp_trailer.GetTrlNwords();
+    } else {
+      pos_nwords = GetBufferPos(n + 1) - tmp_trailer.GetTrlNwords();
+    }
+    return &(m_buffer[ pos_nwords ]);
+  }
+
+  inline int RawCOPPERFormat_latest::GetExpNo(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetExpNo();
+  }
+
+
+  inline unsigned int RawCOPPERFormat_latest::GetExpRunSubrun(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetExpRunSubrun();
+  }
+
+
+  inline int RawCOPPERFormat_latest::GetRunNo(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetRunNo();
+  }
+
+
+  inline int RawCOPPERFormat_latest::GetSubRunNo(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetSubRunNo();
+  }
+
+  inline unsigned int RawCOPPERFormat_latest::GetEveNo(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetEveNo();
+  }
+
+
+  inline unsigned int RawCOPPERFormat_latest::GetNodeID(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetNodeID();
+  }
+
+
+  inline int RawCOPPERFormat_latest::GetDataType(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetDataType();
+  }
+
+  inline int RawCOPPERFormat_latest::GetTruncMask(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetTruncMask();
+  }
+
+  inline unsigned int RawCOPPERFormat_latest::GetErrorBitFlag(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetErrorBitFlag();
+  }
+
+  inline void RawCOPPERFormat_latest::AddErrorBitFlag(int n, unsigned int error_bit_flag)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    tmp_header.AddErrorBitFlag(error_bit_flag);
+    return;
+  }
+
+  inline int RawCOPPERFormat_latest::GetPacketCRCError(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetPacketCRCError();
+  }
+
+  inline int RawCOPPERFormat_latest::GetEventCRCError(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetEventCRCError();
+  }
+
+
+  inline int RawCOPPERFormat_latest::Get1stDetectorNwords(int n)
+  {
+    return GetDetectorNwords(n, 0);
+  }
+
+  inline int RawCOPPERFormat_latest::Get2ndDetectorNwords(int n)
+  {
+    return GetDetectorNwords(n, 1);
+  }
+
+  inline int RawCOPPERFormat_latest::Get3rdDetectorNwords(int n)
+  {
+    return GetDetectorNwords(n, 2);
+  }
+
+  inline int RawCOPPERFormat_latest::Get4thDetectorNwords(int n)
+  {
+    return GetDetectorNwords(n, 3);
+  }
+
+
+
+  inline int RawCOPPERFormat_latest::Get1stFINESSENwords(int n)
+  {
+    return GetFINESSENwords(n, 0);
+  }
+
+  inline int RawCOPPERFormat_latest::Get2ndFINESSENwords(int n)
+  {
+    return GetFINESSENwords(n, 1);
+  }
+
+  inline int RawCOPPERFormat_latest::Get3rdFINESSENwords(int n)
+  {
+    return GetFINESSENwords(n, 2);
+  }
+
+  inline int RawCOPPERFormat_latest::Get4thFINESSENwords(int n)
+  {
+    return GetFINESSENwords(n, 3);
+  }
+
+
+
+  inline unsigned int RawCOPPERFormat_latest::GetTTCtimeTRGType(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetTTCtimeTRGType();
+  }
+
+  inline unsigned int RawCOPPERFormat_latest::GetTTUtime(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetTTUtime();
+  }
+
+  inline int RawCOPPERFormat_latest::GetTTCtime(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetTTCtime();
+  }
+
+  inline int RawCOPPERFormat_latest::GetTRGType(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetTRGType();
+  }
+
+  inline void RawCOPPERFormat_latest::GetTTTimeVal(int n, struct timeval* tv)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    tmp_header.GetTTTimeVal(tv);
+    return ;
+  }
+}
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawCOPPERFormat_v0.h b/ROPCApplications/rawdata/dataobjects/include/RawCOPPERFormat_v0.h
new file mode 100644
index 0000000000000000000000000000000000000000..ebf95e33635f79765f6a57ac89f45aa6964fc656
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawCOPPERFormat_v0.h
@@ -0,0 +1,635 @@
+//+
+// File : RawCOPPERFormat_v0.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWCOPPERFORMAT_V0_H
+#define RAWCOPPERFORMAT_V0_H
+
+// Includes
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+
+#include <rawdata/dataobjects/RawCOPPERFormat.h>
+#include <rawdata/dataobjects/RawHeader_v0.h>
+#include <rawdata/dataobjects/RawTrailer_v0.h>
+
+/* #include <framework/datastore/DataStore.h> */
+/* #include <TObject.h> */
+
+//#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+
+namespace Belle2 {
+
+  /**
+   * The Raw COPPER class ver.0 ( from August, 2013 to April, 2014 )
+   * This class stores data received by COPPER via belle2linkt
+   * Data from all detectors except PXD are stored in this class
+   */
+  class RawCOPPERFormat_v0 : public RawCOPPERFormat {
+  public:
+    //! Default constructor
+    RawCOPPERFormat_v0();
+
+    //! Constructor using existing pointer to raw data buffer
+    //RawCOPPERFormat_v0(int* bufin, int nwords);
+    //! Destructor
+    virtual ~RawCOPPERFormat_v0();
+
+    //
+    // Get position of or pointer to data
+    //
+    ///////////////////////////////////////////////////////////////////////////////////////
+    // POINTER TO "DETECTOR BUFFER"
+    //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+
+    //! get Detector buffer length
+    int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17;
+
+    //! get Detector buffer length of slot A
+    int Get1stDetectorNwords(int n) OVERRIDE_CPP17;
+
+    //! get Detector buffer length of slot B
+    int Get2ndDetectorNwords(int n) OVERRIDE_CPP17;
+
+    //! get Detector buffer length of slot C
+    int Get3rdDetectorNwords(int n) OVERRIDE_CPP17;
+
+    //! get Detector buffer length of slot D
+    int Get4thDetectorNwords(int n) OVERRIDE_CPP17;
+
+    //! get Detector buffer of slot A
+    int* Get1stDetectorBuffer(int n) OVERRIDE_CPP17;
+
+    //! get Detector Buffer of slot B
+    int* Get2ndDetectorBuffer(int n) OVERRIDE_CPP17;
+
+    //! get Detector Buffer of slot C
+    int* Get3rdDetectorBuffer(int n) OVERRIDE_CPP17;
+
+    //! get Detector Buffer of slot D
+    int* Get4thDetectorBuffer(int n) OVERRIDE_CPP17;
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+    /*     //! get posistion of COPPER block in unit of word */
+    /*     virtual int GetBufferPos(int n); */
+
+    //! get buffer pointer of rawcopper trailer
+    virtual int* GetRawTrlBufPtr(int n) OVERRIDE_CPP17;
+
+    //
+    // Get information from "RawCOPPERFormat_v0 header" attached by DAQ software
+    //
+
+    int GetExpNo(int n) OVERRIDE_CPP17;    //! get Experimental # from header
+
+    unsigned int GetExpRunSubrun(int n) OVERRIDE_CPP17;    //! Exp# (10bit) run# (14bit) restart # (8bit)
+
+    int GetRunNo(int n) OVERRIDE_CPP17;    //! get run # (14bit)
+
+    int GetSubRunNo(int n) OVERRIDE_CPP17;    //! get subrun #(8bit)
+
+    unsigned int GetEveNo(int n) OVERRIDE_CPP17;    //! get contents of header
+
+    int GetDataType(int n) OVERRIDE_CPP17;    //! get contents of header
+
+    int GetTruncMask(int n) OVERRIDE_CPP17;    //! get contents of header
+
+    //! Get Detected Error bitflag
+    unsigned int GetErrorBitFlag(int n) OVERRIDE_CPP17;
+
+    //! Add Detected Error bitflag
+    void AddErrorBitFlag(int n, unsigned int error_bit_flag) OVERRIDE_CPP17;
+
+    //! get node-ID from data
+    unsigned int GetNodeID(int n) OVERRIDE_CPP17;
+
+    //
+    // Get information from 13words "COPPER header" attached by COPPER board
+    //
+    //! get COPPER counter(not event number)
+    virtual unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
+
+    //! get # of FINNESEs which contains data
+    virtual int GetNumFINESSEBlock(int n) OVERRIDE_CPP17;
+
+    //! get # of offset words for FINESSE slot A buffer position
+    int GetOffset1stFINESSE(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE buffer
+    int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE slot A buffer
+    int Get1stFINESSENwords(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE slot B buffer
+    int Get2ndFINESSENwords(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE slot C buffer
+    int Get3rdFINESSENwords(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE slot D buffer
+    int Get4thFINESSENwords(int n) OVERRIDE_CPP17;
+
+    //
+    // Get information from "B2link(attached by FEE and HLSB) header"
+    //
+    //! get b2l block from "FEE b2link header"
+    //    virtual int* GetFTSW2Words(int n);
+
+    //! get b2l block from "FEE b2link header"
+    virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
+
+    //! get b2l block from "FEE b2link header"
+    virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
+
+    //
+    // read magic word to check data
+    //
+    //! get magic word of  COPPER driver header
+    unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
+
+    //! get magic word of  COPPER FPGA header
+    unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
+
+    //! get magic word of  COPPER FPGA trailer
+    unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
+
+    //! get magic word of  COPPER driver trailer
+    unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
+
+    //! Get checksum in RawTrailer
+    unsigned int GetTrailerChksum(int  n) OVERRIDE_CPP17;
+
+    //! Check if COPPER Magic words are correct
+    bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
+
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    //! Check B2LFEE header version
+    void CheckB2LFEEHeaderVersion(int  n) OVERRIDE_CPP17;
+#endif
+
+    //! Check if COPPER Magic words are correct
+    unsigned int GetTTCtimeTRGType(int n) OVERRIDE_CPP17;
+
+    //! Check if COPPER Magic words are correct
+    unsigned int GetTTUtime(int n) OVERRIDE_CPP17;
+
+    //! should be called by DeSerializerCOPPER.cc and fill contents in RawHeader
+    unsigned int FillTopBlockRawHeader(unsigned int m_node_id, unsigned int prev_eve32,
+                                       unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
+
+    //! read COPPER driver's checksum value
+    unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
+
+    //! calc COPPER driver's checksum value
+    unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
+
+    //! check data contents
+    void CheckData(int n,
+                   unsigned int prev_evenum, unsigned int* cur_evenum,
+                   unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
+                   unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
+
+    //! check data contents
+    void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
+
+    //! Get ctime
+    int GetTTCtime(int n) OVERRIDE_CPP17;
+
+    //! Get trgtype
+    int GetTRGType(int n) OVERRIDE_CPP17;
+
+    //! Get timeval
+    void GetTTTimeVal(int n, struct timeval* tv) OVERRIDE_CPP17;
+
+    //! Pack data (format ver. = -1 -> Select the latest format version)
+    int* PackDetectorBuf(int* packed_buf_nwords,
+                         int* detector_buf_1st, int nwords_1st,
+                         int* detector_buf_2nd, int nwords_2nd,
+                         int* detector_buf_3rd, int nwords_3rd,
+                         int* detector_buf_4th, int nwords_4th,
+                         RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
+
+    enum {
+      DATA_FORMAT_VERSION = 0
+    };
+
+    //
+    // size of "COPPER front header" and "COPPER trailer"
+    //
+    //! Copper data words = ( total_data_length in COPPER header ) + COPPER_HEADER_TRAILER_NWORDS
+    enum {
+      SIZE_COPPER_DRIVER_HEADER = 7,
+      SIZE_COPPER_DRIVER_TRAILER = 2
+    };
+
+    //
+    // Data Format : "COPPER header"
+    //
+    enum {
+      POS_MAGIC_COPPER_1 = 0,
+      POS_EVE_NUM_COPPER = 1,
+      POS_SUBSYSTEM_ID = 2,
+      POS_CRATE_ID = 3,
+      POS_SLOT_ID = 4,
+      POS_MAGIC_COPPER_2 = 7,
+      POS_DATA_LENGTH = 8,
+      POS_CH_A_DATA_LENGTH = 9,
+      POS_CH_B_DATA_LENGTH = 10,
+      POS_CH_C_DATA_LENGTH = 11,
+      POS_CH_D_DATA_LENGTH = 12,
+
+      SIZE_COPPER_HEADER = 13
+    };
+
+
+
+    //
+    // Data Format : "COPPER Trailer"
+    //
+    enum {
+      POS_MAGIC_COPPER_3 = 0,
+      POS_CHKSUM_COPPER = 1,
+      POS_MAGIC_COPPER_4 = 2,
+
+      SIZE_COPPER_TRAILER = 3
+    };
+
+    //
+    // Data Format : "B2Link HSLB Header"
+    //
+    enum {
+      POS_MAGIC_B2LHSLB = 0,
+      //      POS_EVE_CNT_B2LHSLB = 1,
+      SIZE_B2LHSLB_HEADER = 1
+    };
+
+    //
+    // Data Format : "B2Link HSLB Trailer"
+    //
+    enum {
+      POS_CHKSUM_B2LHSLB = 0,
+      SIZE_B2LHSLB_TRAILER = 1
+    };
+
+
+    // Data Format : "B2Link FEE Header"
+    // modified by Nov. 21, 2013, Nakao-san's New firmware?
+    enum {
+      POS_TT_CTIME_TYPE = 0,
+      POS_TT_TAG = 1,
+      POS_TT_UTIME = 2,
+      POS_EXP_RUN = 3,
+      POS_B2L_CTIME = 4,
+      SIZE_B2LFEE_HEADER = 5
+    };
+
+
+    //
+    // Data Format : B2Link FEE Trailer
+    //
+    enum {
+      POS_CHKSUM_B2LFEE = 0,
+      SIZE_B2LFEE_TRAILER = 1
+    };
+
+    //
+    // COPPER magic words
+    //
+    enum {
+      COPPER_MAGIC_DRIVER_HEADER = 0x7FFF0008,
+      COPPER_MAGIC_FPGA_HEADER = 0xFFFFFAFA,
+      COPPER_MAGIC_FPGA_TRAILER = 0xFFFFF5F5,
+      COPPER_MAGIC_DRIVER_TRAILER = 0x7FFF0009
+    };
+
+    //! header ( not recorded )
+    RawHeader_v0 tmp_header;
+
+    //! trailer ( not recorded )
+    RawTrailer_v0 tmp_trailer;
+
+  protected :
+    ///ver.2 Change FEE format as presented at B2GM in Nov.2013 ( Nov.20, 2013)
+    //    ClassDefOverride(RawCOPPERFormat_v0, 2);
+
+  };
+
+
+
+
+  inline int* RawCOPPERFormat_v0::GetRawTrlBufPtr(int n)
+  {
+    int pos_nwords;
+    if (n == (m_num_events * m_num_nodes) - 1) {
+      pos_nwords = m_nwords - tmp_trailer.GetTrlNwords();
+    } else {
+      pos_nwords = GetBufferPos(n + 1) - tmp_trailer.GetTrlNwords();
+    }
+    return &(m_buffer[ pos_nwords ]);
+  }
+
+  inline unsigned int RawCOPPERFormat_v0::GetDriverChkSum(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
+                     - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
+    return m_buffer[ pos_nwords ];
+  }
+
+  inline int RawCOPPERFormat_v0::GetExpNo(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetExpNo();
+  }
+
+  inline unsigned int RawCOPPERFormat_v0::GetExpRunSubrun(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetExpRunSubrun();
+  }
+
+  inline int RawCOPPERFormat_v0::GetRunNo(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetRunNo();
+  }
+
+
+  inline int RawCOPPERFormat_v0::GetSubRunNo(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetSubRunNo();
+  }
+
+  inline unsigned int RawCOPPERFormat_v0::GetEveNo(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetEveNo();
+  }
+
+
+  inline unsigned int RawCOPPERFormat_v0::GetNodeID(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetNodeID();
+  }
+
+
+  inline int RawCOPPERFormat_v0::GetDataType(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetDataType();
+  }
+
+  inline int RawCOPPERFormat_v0::GetTruncMask(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetTruncMask();
+  }
+
+  inline unsigned int RawCOPPERFormat_v0::GetErrorBitFlag(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetErrorBitFlag();
+  }
+
+  inline void RawCOPPERFormat_v0::AddErrorBitFlag(int n, unsigned int error_bit_flag)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    tmp_header.AddErrorBitFlag(error_bit_flag);
+    return;
+  }
+
+  inline unsigned int RawCOPPERFormat_v0::GetCOPPERCounter(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + POS_EVE_NUM_COPPER + tmp_header.RAWHEADER_NWORDS;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+
+
+
+  inline int RawCOPPERFormat_v0::Get1stDetectorNwords(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    int nwords = 0;
+    if (Get1stFINESSENwords(n) > 0) {
+      nwords = Get1stFINESSENwords(n) -  SIZE_B2LHSLB_HEADER - SIZE_B2LFEE_HEADER
+               - SIZE_B2LFEE_TRAILER - SIZE_B2LHSLB_TRAILER;
+    }
+    return nwords;
+  }
+
+  inline int RawCOPPERFormat_v0::Get2ndDetectorNwords(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    int nwords = 0;
+    if (Get2ndFINESSENwords(n) > 0) {
+      nwords = Get2ndFINESSENwords(n) -  SIZE_B2LHSLB_HEADER -
+               SIZE_B2LFEE_HEADER - SIZE_B2LFEE_TRAILER - SIZE_B2LHSLB_TRAILER;
+    }
+    return nwords;
+  }
+
+  inline int RawCOPPERFormat_v0::Get3rdDetectorNwords(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    int nwords = 0;
+    if (Get3rdFINESSENwords(n) > 0) {
+      nwords = Get3rdFINESSENwords(n) -  SIZE_B2LHSLB_HEADER -
+               SIZE_B2LFEE_HEADER - SIZE_B2LFEE_TRAILER - SIZE_B2LHSLB_TRAILER;
+    }
+    return nwords;
+  }
+
+  inline int RawCOPPERFormat_v0::Get4thDetectorNwords(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    int nwords = 0;
+    if (Get4thFINESSENwords(n) > 0) {
+      nwords = Get4thFINESSENwords(n) -  SIZE_B2LHSLB_HEADER -
+               SIZE_B2LFEE_HEADER - SIZE_B2LFEE_TRAILER - SIZE_B2LHSLB_TRAILER;
+    }
+    return nwords;
+  }
+
+
+
+  inline int RawCOPPERFormat_v0::Get1stFINESSENwords(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_CH_A_DATA_LENGTH;
+    return m_buffer[ pos_nwords ];
+  }
+
+  inline int RawCOPPERFormat_v0::Get2ndFINESSENwords(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_CH_B_DATA_LENGTH;
+    return m_buffer[ pos_nwords ];
+  }
+
+  inline int RawCOPPERFormat_v0::Get3rdFINESSENwords(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_CH_C_DATA_LENGTH;
+    return m_buffer[ pos_nwords ];
+  }
+
+  inline int RawCOPPERFormat_v0::Get4thFINESSENwords(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_CH_D_DATA_LENGTH;
+    return m_buffer[ pos_nwords ];
+  }
+
+
+  inline int RawCOPPERFormat_v0::GetOffset1stFINESSE(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
+    return pos_nwords;
+  }
+
+
+  inline int* RawCOPPERFormat_v0::Get1stDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get1stFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* RawCOPPERFormat_v0::Get2ndDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get2ndFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset2ndFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* RawCOPPERFormat_v0::Get3rdDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get3rdFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset3rdFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* RawCOPPERFormat_v0::Get4thDetectorBuffer(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    if (Get4thFINESSENwords(n) > 0) {
+      int pos_nwords = GetOffset4thFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
+      return &(m_buffer[ pos_nwords ]);
+    }
+    return NULL;
+  }
+
+  inline int* RawCOPPERFormat_v0::GetExpRunSubrunBuf(int n)
+  {
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    CheckB2LFEEHeaderVersion(n);
+#endif
+    int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN;
+    return &(m_buffer[ pos_nwords ]);
+  }
+
+
+
+  inline unsigned int RawCOPPERFormat_v0::GetMagicDriverHeader(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_MAGIC_COPPER_1;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+  inline unsigned int RawCOPPERFormat_v0::GetMagicFPGAHeader(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_MAGIC_COPPER_2;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+  inline unsigned int RawCOPPERFormat_v0::GetMagicFPGATrailer(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
+
+    //    printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), tmp_trailer.GetTrlNwords());
+
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+  inline unsigned int RawCOPPERFormat_v0::GetMagicDriverTrailer(int n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+
+  inline unsigned int RawCOPPERFormat_v0::GetTrailerChksum(int  n)
+  {
+    int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
+    return (unsigned int)(m_buffer[ pos_nwords ]);
+  }
+
+
+  inline unsigned int RawCOPPERFormat_v0::GetTTCtimeTRGType(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetTTCtimeTRGType();
+  }
+
+  inline unsigned int RawCOPPERFormat_v0::GetTTUtime(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetTTUtime();
+  }
+
+
+  inline int RawCOPPERFormat_v0::GetTTCtime(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetTTCtime();
+  }
+
+  inline int RawCOPPERFormat_v0::GetTRGType(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetTRGType();
+  }
+
+  inline void RawCOPPERFormat_v0::GetTTTimeVal(int n, struct timeval* tv)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    tmp_header.GetTTTimeVal(tv);
+    return ;
+  }
+
+
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawCOPPERFormat_v1.h b/ROPCApplications/rawdata/dataobjects/include/RawCOPPERFormat_v1.h
new file mode 100644
index 0000000000000000000000000000000000000000..6f57f44105a8e5bc7bd030aa2061344eb0b14d20
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawCOPPERFormat_v1.h
@@ -0,0 +1,313 @@
+//+
+// File : RawCOPPERFormat_v1.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWCOPPERFORMAT_V1_H
+#define RAWCOPPERFORMAT_V1_H
+
+// Includes
+#include <rawdata/dataobjects/RawCOPPERFormat.h>
+#include <rawdata/dataobjects/RawHeader_v1.h>
+#include <rawdata/dataobjects/RawTrailer_v1.h>
+#include <rawdata/CRCCalculator.h>
+
+/* #include <framework/datastore/DataStore.h> */
+/* #include <TObject.h> */
+
+//#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+
+
+namespace Belle2 {
+
+  /**
+   * The Raw COPPER class ver.1 ( the latest version since May, 2014 )
+   * This class stores data received by COPPER via belle2linkt
+   * Data from all detectors except PXD are stored in this class
+   */
+  class RawCOPPERFormat_v1 : public RawCOPPERFormat {
+  public:
+    //! Default constructor
+    RawCOPPERFormat_v1();
+
+    //! Constructor using existing pointer to raw data buffer
+    //RawCOPPERFormat_v1(int* bufin, int nwords);
+    //! Destructor
+    virtual ~RawCOPPERFormat_v1();
+
+    //
+    // Get position of or pointer to data
+    //
+    ///////////////////////////////////////////////////////////////////////////////////////
+    // POINTER TO "DETECTOR BUFFER"
+    //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+
+    //! get Detector buffer length of slot A
+    int Get1stDetectorNwords(int n) OVERRIDE_CPP17;
+
+    //! get Detector buffer length of slot B
+    int Get2ndDetectorNwords(int n) OVERRIDE_CPP17;
+
+    //! get Detector buffer length of slot C
+    int Get3rdDetectorNwords(int n) OVERRIDE_CPP17;
+
+    //! get Detector buffer length of slot D
+    int Get4thDetectorNwords(int n) OVERRIDE_CPP17;
+
+    ///////////////////////////////////////////////////////////////////////////////////////
+
+    //! get buffer pointer of rawcopper trailer
+    int* GetRawTrlBufPtr(int n) OVERRIDE_CPP17;
+
+    //
+    // Get information from "RawCOPPERFormat_v1 header" attached by DAQ software
+    //
+
+    int GetExpNo(int n) OVERRIDE_CPP17;    //! get Experimental # from header
+
+    unsigned int GetExpRunSubrun(int n) OVERRIDE_CPP17;    //! Exp# (10bit) run# (14bit) restart # (8bit)
+
+    int GetRunNo(int n) OVERRIDE_CPP17;    //! get run # (14bit)
+
+    int GetSubRunNo(int n) OVERRIDE_CPP17;    //! get subrun #(8bit)
+
+    unsigned int GetEveNo(int n) OVERRIDE_CPP17;    //! get contents of header
+
+    int GetDataType(int n) OVERRIDE_CPP17;    //! get contents of header
+
+    int GetTruncMask(int n) OVERRIDE_CPP17;    //! get contents of header
+
+    //! Get Detected Error bitflag
+    unsigned int GetErrorBitFlag(int n) OVERRIDE_CPP17;
+
+    //! Add Detected Error bitflag
+    void AddErrorBitFlag(int n, unsigned int error_bit_flag) OVERRIDE_CPP17;
+
+    //! get node-ID from data
+    unsigned int GetNodeID(int n) OVERRIDE_CPP17;
+
+    //
+    // Get information from 13words "COPPER header" attached by COPPER board
+    //
+
+    //! get # of FINNESEs which contains data
+    virtual int GetNumFINESSEBlock(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE slot A buffer
+    int Get1stFINESSENwords(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE slot B buffer
+    int Get2ndFINESSENwords(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE slot C buffer
+    int Get3rdFINESSENwords(int n) OVERRIDE_CPP17;
+
+    //! get data size of  FINESSE slot D buffer
+    int Get4thFINESSENwords(int n) OVERRIDE_CPP17;
+
+    //
+    // Get information from "B2link(attached by FEE and HLSB) header"
+    //
+    //! get b2l block from "FEE b2link header"
+    //    virtual int* GetFTSW2Words(int n);
+
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+    //! Check B2LFEE header version
+    void CheckB2LFEEHeaderVersion(int  n) OVERRIDE_CPP17;
+#endif
+
+    //! Check if COPPER Magic words are correct
+    unsigned int GetTTCtimeTRGType(int n) OVERRIDE_CPP17;
+
+    //! Check if COPPER Magic words are correct
+    unsigned int GetTTUtime(int n) OVERRIDE_CPP17;
+
+    /*     //! calc COPPER driver's checksum value */
+    /*     virtual unsigned int CalcDriverChkSum(int n) = 0; */
+
+
+    //! Get ctime
+    int GetTTCtime(int n) OVERRIDE_CPP17;
+
+    //! Get trgtype
+    int GetTRGType(int n) OVERRIDE_CPP17;
+
+    //! Get timeval
+    void GetTTTimeVal(int n, struct timeval* tv) OVERRIDE_CPP17;
+
+    /// Format version number
+    enum {
+      DATA_FORMAT_VERSION = 1
+    };
+
+    //! header ( not recorded )
+    RawHeader_v1 tmp_header;
+
+    //! trailer ( not recorded )
+    RawTrailer_v1 tmp_trailer;
+
+
+  protected :
+    ///ver.2 Change FEE format as presented at B2GM in Nov.2013 ( Nov.20, 2013)
+    //    ClassDefOverride(RawCOPPERFormat_v1, 2);
+  };
+
+
+
+
+  inline int* RawCOPPERFormat_v1::GetRawTrlBufPtr(int n)
+  {
+    int pos_nwords;
+    if (n == (m_num_events * m_num_nodes) - 1) {
+      pos_nwords = m_nwords - tmp_trailer.GetTrlNwords();
+    } else {
+      pos_nwords = GetBufferPos(n + 1) - tmp_trailer.GetTrlNwords();
+    }
+    return &(m_buffer[ pos_nwords ]);
+  }
+
+  inline int RawCOPPERFormat_v1::GetExpNo(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetExpNo();
+  }
+
+  inline unsigned int RawCOPPERFormat_v1::GetExpRunSubrun(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetExpRunSubrun();
+  }
+
+  inline int RawCOPPERFormat_v1::GetRunNo(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetRunNo();
+  }
+
+
+  inline int RawCOPPERFormat_v1::GetSubRunNo(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetSubRunNo();
+  }
+
+  inline unsigned int RawCOPPERFormat_v1::GetEveNo(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetEveNo();
+  }
+
+
+  inline unsigned int RawCOPPERFormat_v1::GetNodeID(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetNodeID();
+  }
+
+
+  inline int RawCOPPERFormat_v1::GetDataType(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetDataType();
+  }
+
+  inline int RawCOPPERFormat_v1::GetTruncMask(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetTruncMask();
+  }
+
+  inline unsigned int RawCOPPERFormat_v1::GetErrorBitFlag(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetErrorBitFlag();
+  }
+
+  inline void RawCOPPERFormat_v1::AddErrorBitFlag(int n, unsigned int error_bit_flag)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    tmp_header.AddErrorBitFlag(error_bit_flag);
+    return;
+  }
+
+  inline int RawCOPPERFormat_v1::Get1stDetectorNwords(int n)
+  {
+    return GetDetectorNwords(n, 0);
+  }
+
+  inline int RawCOPPERFormat_v1::Get2ndDetectorNwords(int n)
+  {
+    return GetDetectorNwords(n, 1);
+  }
+
+  inline int RawCOPPERFormat_v1::Get3rdDetectorNwords(int n)
+  {
+    return GetDetectorNwords(n, 2);
+  }
+
+  inline int RawCOPPERFormat_v1::Get4thDetectorNwords(int n)
+  {
+    return GetDetectorNwords(n, 3);
+  }
+
+
+
+  inline int RawCOPPERFormat_v1::Get1stFINESSENwords(int n)
+  {
+    return GetFINESSENwords(n, 0);
+  }
+
+  inline int RawCOPPERFormat_v1::Get2ndFINESSENwords(int n)
+  {
+    return GetFINESSENwords(n, 1);
+  }
+
+  inline int RawCOPPERFormat_v1::Get3rdFINESSENwords(int n)
+  {
+    return GetFINESSENwords(n, 2);
+  }
+
+  inline int RawCOPPERFormat_v1::Get4thFINESSENwords(int n)
+  {
+    return GetFINESSENwords(n, 3);
+  }
+
+
+
+  inline unsigned int RawCOPPERFormat_v1::GetTTCtimeTRGType(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetTTCtimeTRGType();
+  }
+
+  inline unsigned int RawCOPPERFormat_v1::GetTTUtime(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetTTUtime();
+  }
+
+  inline int RawCOPPERFormat_v1::GetTTCtime(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetTTCtime();
+  }
+
+  inline int RawCOPPERFormat_v1::GetTRGType(int n)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    return tmp_header.GetTRGType();
+  }
+
+  inline void RawCOPPERFormat_v1::GetTTTimeVal(int n, struct timeval* tv)
+  {
+    tmp_header.SetBuffer(GetBuffer(n));
+    tmp_header.GetTTTimeVal(tv);
+    return ;
+  }
+}
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawDataBlock.h b/ROPCApplications/rawdata/dataobjects/include/RawDataBlock.h
new file mode 100644
index 0000000000000000000000000000000000000000..c73bea9609730ac5ed268cf8f2067c0cae9069f9
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawDataBlock.h
@@ -0,0 +1,165 @@
+//+
+// File : RawDataBlock.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWDATABLOCK_H
+#define RAWDATABLOCK_H
+
+// Includes
+#include <stdio.h>
+#include <stdlib.h>
+#include <framework/datastore/DataStore.h>
+#include <TObject.h>
+#include <rawdata/dataobjects/RawDataBlockFormat.h>
+
+
+namespace Belle2 {
+
+  /**
+   * The RawDataBlock class
+   * Base class for rawdata handling
+   */
+  class RawDataBlock : public TObject {
+  public:
+    //! Default constructor
+    RawDataBlock();
+
+    //! Destructor
+    virtual ~RawDataBlock();
+
+    //! set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
+    virtual void SetBuffer(int* bufin, int nwords, int delete_flag, int num_events, int num_nodes);
+
+    //! Get total length of m_buffer
+    virtual int TotalBufNwords()
+    {
+      m_access_dblk->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access_dblk->TotalBufNwords();
+    }
+
+    //! get position of data block in word
+    virtual int GetBufferPos(int n)
+    {
+      m_access_dblk->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access_dblk->GetBufferPos(n);
+    }
+
+    //! get nth buffer pointer
+    virtual int* GetBuffer(int n)
+    {
+      m_access_dblk->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access_dblk->GetBuffer(n);
+    }
+
+    //! get pointer to  buffer(m_buffer)
+    virtual int* GetWholeBuffer()
+    {
+      m_access_dblk->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access_dblk->GetWholeBuffer();
+    }
+
+    //! get # of data blocks = (# of nodes)*(# of events)
+    virtual int GetNumEntries()
+    {
+      m_access_dblk->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access_dblk->GetNumEntries();
+    }
+
+    //! get # of data sources(e.g. # of COPPER boards) in m_buffer
+    virtual int GetNumNodes()
+    {
+      m_access_dblk->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access_dblk->GetNumNodes();
+    }
+
+    //! get # of events in m_buffer
+    virtual int GetNumEvents()
+    {
+      m_access_dblk->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access_dblk->GetNumEvents();
+    }
+
+    //! get malloc_flag
+    virtual int GetPreAllocFlag()
+    {
+      return m_use_prealloc_buf;
+    }
+
+    //! get size of a data block
+    virtual int GetBlockNwords(int n)
+    {
+      m_access_dblk->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access_dblk->GetBlockNwords(n);
+    }
+
+    //! get FTSW ID to check whether this data block is FTSW data or not
+    virtual int CheckFTSWID(int n)
+    {
+      m_access_dblk->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access_dblk->CheckFTSWID(n);
+    }
+
+    //! get FTSW ID to check whether this data block is FTSW data or not
+    virtual int CheckTLUID(int n)
+    {
+      m_access_dblk->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access_dblk->CheckTLUID(n);
+    }
+
+    //! Copy one datablock to buffer
+    virtual void CopyBlock(int n, int* buf_to)
+    {
+      m_access_dblk->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access_dblk->CopyBlock(n, buf_to);
+    }
+
+    //! print data
+    virtual void PrintData(int* buf, int nwords)
+    {
+      m_access_dblk->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access_dblk->PrintData(buf, nwords);
+    }
+
+    /*     enum { */
+    /*       POS_NWORDS = 0, */
+    /*       POS_NODE_ID = 6 */
+    /*     }; */
+
+    /*     enum { */
+    /*       // Tentatively needed to distinguish new and old FTSW format, which will be changed in Nov. 2013 */
+    /*       POS_FTSW_ID_OLD = 5, */
+    /*       TEMP_POS_NWORDS_HEADER = 1, */
+    /*       OLD_FTSW_NWORDS_HEADER = 6 */
+    /*     }; */
+
+    //! class to access
+    RawDataBlockFormat* m_access_dblk; //! do not record
+
+  protected :
+    /// number of words of buffer
+    int m_nwords;
+
+    /// number of nodes in this object
+    int m_num_nodes;
+
+    /// number of events in this object
+    int m_num_events;
+
+    /// Buffer
+    int* m_buffer; //[m_nwords]
+
+    //! flag for deleting m_buffer in destructer( 0:delete, 1: not delete)
+    //! When using pre-allocated buffer, the buffer should be reused and not deleted in the destructer
+    int m_use_prealloc_buf; //! not record
+
+    /// To drive from TObject
+    ClassDef(RawDataBlock, 3);
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawDataBlockFormat.h b/ROPCApplications/rawdata/dataobjects/include/RawDataBlockFormat.h
new file mode 100644
index 0000000000000000000000000000000000000000..13a6a774170b1c28e7b61dab3ce650df2fef1d0b
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawDataBlockFormat.h
@@ -0,0 +1,110 @@
+//+
+// File : RawDataBlockFormat.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWDATABLOCKFORMAT_H
+#define RAWDATABLOCKFORMAT_H
+
+// Includes
+#include <stdio.h>
+#include <stdlib.h>
+#include <string>
+#include <string.h>
+#include <rawdata/switch_basf2_standalone.h>
+
+namespace Belle2 {
+
+  /**
+   * The RawDataBlockFormat class
+   * Format information for rawdata handling
+   */
+  class RawDataBlockFormat  {
+  public:
+    //! Default constructor
+    RawDataBlockFormat();
+
+    //! Destructor
+    virtual ~RawDataBlockFormat();
+
+    //! set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
+    virtual void SetBuffer(int* bufin, int nwords, int delete_flag, int num_events, int num_nodes);
+
+    //! Get total length of m_buffer
+    virtual int TotalBufNwords();
+
+    //! get position of data block in word
+    virtual int GetBufferPos(int n);
+
+    //! get nth buffer pointer
+    virtual int* GetBuffer(int n);
+
+    //! get pointer to  buffer(m_buffer)
+    virtual int* GetWholeBuffer();
+
+    //! get # of data blocks = (# of nodes)*(# of events)
+    virtual int GetNumEntries() { return m_num_events * m_num_nodes; }
+
+    //! get # of data sources(e.g. # of COPPER boards) in m_buffer
+    virtual int GetNumNodes() { return m_num_nodes; }
+
+    //! get # of events in m_buffer
+    virtual int GetNumEvents() { return m_num_events; }
+
+    //! get malloc_flag
+    virtual int GetPreAllocFlag() { return m_use_prealloc_buf; }
+
+    //! get size of a data block
+    virtual int GetBlockNwords(int n);
+
+    //! get FTSW ID to check whether this data block is FTSW data or not
+    virtual int CheckFTSWID(int n);
+
+    //! get FTSW ID to check whether this data block is FTSW data or not
+    virtual int CheckTLUID(int n);
+
+    //! Copy one datablock to buffer
+    virtual void CopyBlock(int n, int* buf_to);
+
+    //! print data
+    virtual void PrintData(int* buf, int nwords);
+
+    enum {
+      POS_NWORDS = 0,
+      POS_NODE_ID = 6
+    };
+
+    enum {
+      // Tentatively needed to distinguish new and old FTSW format, which will be changed in Nov. 2013
+      POS_FTSW_ID_OLD = 5,
+      TEMP_POS_NWORDS_HEADER = 1,
+      OLD_FTSW_NWORDS_HEADER = 6
+    };
+
+  protected :
+    /// number of words of buffer
+    int m_nwords;
+
+    /// number of nodes in this object
+    int m_num_nodes;
+
+    /// number of events in this object
+    int m_num_events;
+
+    /// Buffer
+    int* m_buffer; //! not recorded
+
+    //! flag for deleting m_buffer in destructer( 0:delete, 1: not delete)
+    //! When using pre-allocated buffer, the buffer should be reused and not deleted in the destructer
+    int m_use_prealloc_buf; //! not record
+
+    /*     /// To drive from TObject */
+    /*     ClassDef(RawDataBlockFormat, 1); */
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawECL.h b/ROPCApplications/rawdata/dataobjects/include/RawECL.h
new file mode 100644
index 0000000000000000000000000000000000000000..5402604e9c02fb4fd8ca2f0ec6b8586b4df47123
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawECL.h
@@ -0,0 +1,38 @@
+//+
+// File : RawCOPPER.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWECL_H
+#define RAWECL_H
+
+// Includes
+#include <stdio.h>
+#include <stdlib.h>
+#include <rawdata/dataobjects/RawCOPPER.h>
+#include <framework/datastore/DataStore.h>
+
+#include <TObject.h>
+
+namespace Belle2 {
+
+  /**
+   * The Raw ECL class
+   * Class for RawCOPPER class data taken by ECL
+   * Currently, this class is almost same as RawCOPPER class.
+   */
+  class RawECL : public RawCOPPER {
+  public:
+    //! Default constructor
+    RawECL();
+    //! Destructor
+    virtual ~RawECL();
+    /// To derive from TObject
+    ClassDef(RawECL, 1);
+  };
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawFTSW.h b/ROPCApplications/rawdata/dataobjects/include/RawFTSW.h
new file mode 100644
index 0000000000000000000000000000000000000000..64c82d773917cbc4820f90fe0a1c665d1506ec90
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawFTSW.h
@@ -0,0 +1,253 @@
+//+
+// File : RawFTSW.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWFTSW_H
+#define RAWFTSW_H
+
+// Includes
+#include <rawdata/dataobjects/RawDataBlock.h>
+#include <rawdata/dataobjects/RawFTSWFormat.h>
+#include <rawdata/dataobjects/RawFTSWFormat_v1.h>
+#include <rawdata/dataobjects/RawFTSWFormat_v2.h>
+#include <rawdata/dataobjects/RawFTSWFormat_latest.h>
+
+namespace Belle2 {
+
+  /**
+   * The Raw FTSW class.
+   *
+   * This class stores the RAW data containing FTSW data(event #, trg time ).
+   */
+  class RawFTSW : public RawDataBlock {
+  public:
+    //! Default constructor
+    RawFTSW();
+
+    //! Constructor using existing pointer to raw data buffer
+    //RawFTSW(int* bufin, int nwords);
+    //! Destructor
+    virtual ~RawFTSW();
+
+    //! set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
+    void SetBuffer(int* bufin, int nwords, int delete_flag, int num_events, int num_nodes) OVERRIDE_CPP17;
+
+    //! read data, detect and set the version number of the data format
+    void SetVersion();
+
+    //! Check the version number of data format
+    void CheckVersionSetBuffer();
+
+    //! Get # of words of header
+    int GetNwordsHeader(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetNwordsHeader(n);
+    }
+
+    //! Get Node # ( should be "TTD " )
+    unsigned int GetFTSWNodeID(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetFTSWNodeID(n);
+    }
+
+    //! Get event #
+    unsigned int GetEveNo(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetEveNo(n);
+    }
+
+    //! Get a word containing ctime and trigger type info
+    unsigned int GetTTCtimeTRGType(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetTTCtimeTRGType(n);
+    }
+
+    //! get unixtime of the trigger
+    unsigned int GetTTUtime(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetTTUtime(n);
+    }
+
+    //! Get ctime of the trigger
+    int GetTTCtime(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetTTCtime(n);
+    }
+
+    //! Get trgtype
+    int GetTRGType(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetTRGType(n);
+    }
+
+    //! Get timeval from ctime and utime
+    void GetTTTimeVal(int n, struct timeval* tv)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetTTTimeVal(n, tv);
+    }
+
+    //! Get timeval obtained from gettimeval()
+    void GetPCTimeVal(int n, struct timeval* tv)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetPCTimeVal(n, tv);
+    }
+
+    //! Get magic number for data corruption check
+    unsigned int GetMagicTrailer(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetMagicTrailer(n);
+    }
+
+    //! check the data contents
+    void CheckData(int n,
+                   unsigned int prev_evenum, unsigned int* cur_evenum,
+                   unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+    {
+      CheckVersionSetBuffer();
+      return m_access->CheckData(n, prev_evenum, cur_evenum, prev_exprunsubrun_no, cur_exprunsubrun_no);
+    }
+
+    //! Exp# (10bit) run# (14bit) restart # (8bit)
+    unsigned int GetExpRunSubrun(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetExpRunSubrun(n);
+    }
+
+    //! Get run #
+    int GetRunNo(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetRunNo(n);
+    }
+
+
+    //! Get subrun #
+    int GetSubRunNo(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetSubRunNo(n);
+    }
+
+    //! get a word cotaining run # and subrun #
+    int GetRunNoSubRunNo(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetRunNoSubRunNo(n);
+    }
+
+    //! Get Exp #
+    int GetExpNo(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetExpNo(n);
+    }
+
+    //! DESY test only
+    int Get15bitTLUTag(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->Get15bitTLUTag(n);
+    }
+
+    //! HER injection = 1 or LER injection = 0
+    int GetIsHER(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetIsHER(n);
+    }
+
+    //! Get time since the last injection
+    unsigned int GetTimeSinceLastInjection(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetTimeSinceLastInjection(n);
+    }
+
+    //! Get time since the previous trigger
+    unsigned int GetTimeSincePrevTrigger(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetTimeSincePrevTrigger(n);
+    }
+
+    //! Get a bunch number
+    unsigned int GetBunchNumber(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetBunchNumber(n);
+    }
+
+    //! Get a frame count
+    unsigned int GetFrameCount(int n)
+    {
+      CheckVersionSetBuffer();
+      return m_access->GetFrameCount(n);
+    }
+
+    enum {
+      /// Added to distinguish different version.
+      /// ver.0 : early DESY-beam-test version( Node ID 0x545444** is at 5th word (0,1,2,..5)
+      ///       : Please ask Nakao-san about his e-mail ( [daq-experts:8055] FEE data header and FTSW data format)
+      /// ver.1 : late DESY-beam-test version( Node ID 0x545444** was moved to 6th word (0,1,2,..5)
+      ///       : header size is ? words ( I need to ask Nakao-san because it will be used for distinguish between 0,1, and 2
+      /// ver 2 : phase II ? version
+      ///       : header size is 8 words
+      ///       : Format is written by Nakao-san in ver.26(as of 2019.3.1 ) of https://confluence.desy.de/pages/viewpage.action?spaceKey=BI&title=DAQ+TimingDistribution#DAQTimingDistribution-InformationsentfromTTDtodatastream
+      //! 0x545452?? up to ver.2 this number is more or less same. So, it cannot be used to distinguish different version numbers
+      POS_NODE_FORMAT_ID = 6,  // Position of format ID in header
+      FTSW_FORMAT_MASK = 0x000000FF,
+
+      FORMAT_ID_VER_0TO2 = 0x54544420,
+      FORMAT_ID_VER_0TO3 = 0x54544431,
+
+      POS_HEADER_SIZE = 1, //! The same number of this information must appear in RawFTSWFormat*.h. Information should be placed in one place but I need to put this number in RawFTSW.h because it is used to distinguish different version numbers.
+      // header size is used to distinguish different version number for ver. 0, 1, and 2
+      VER_0_HEADER_SIZE = 0, //! Unpacker for ver.0(early DESY version) is not available.
+      VER_1_HEADER_SIZE = 0, // ! Unpacker for ver.1(late DESY version) is available but it is unlikely for a user to read this ver. Until there is a request to read ver.1, it is closed.
+      VER_2_HEADER_SIZE = 8,
+      VER_3_HEADER_SIZE = 8
+    };
+
+    //! class to access
+    RawFTSWFormat* m_access{}; //! do not record
+
+    /// Version of the format
+    int m_version = -1; //! do not record
+
+  protected :
+    /// To derive from TObject
+    /// ver.2 Remove m_FTSW_header and introduce a new data format on Nov. 20, 2013
+    /// ver.3 Add m_access on Mar. 7 2016 but Classded stays 2 for some(?) reason
+    /// ver.4 Add m_version on Feb. 18 2019 for the new format version defined by Nakao-san
+    /// Reason to stay at *2* is that the persistent content did *not change*
+    /// If necessary: be aware that we have to change this in online and offline at the same time!
+    ClassDef(RawFTSW, 2);
+  };
+
+  inline void RawFTSW::CheckVersionSetBuffer()
+  {
+    if (m_version < 0  || m_access == NULL) {
+      // Since both ver.0, 1 and ver.2 will show m_buffer[ POS_NODE_ID ] & FORMAT_MASK == 0x0, I need to ignore the check for ver.0 and 1
+      SetVersion();
+    }
+    m_access->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+  }
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawFTSWFormat.h b/ROPCApplications/rawdata/dataobjects/include/RawFTSWFormat.h
new file mode 100644
index 0000000000000000000000000000000000000000..7644092327f59db31549ff1d0d5e2c452510a11c
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawFTSWFormat.h
@@ -0,0 +1,115 @@
+//+
+// File : RawFTSWFormat.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 7 - Mar - 2016
+//-
+
+#ifndef RAWFTSWFORMAT_H
+#define RAWFTSWFORMAT_H
+#include <rawdata/dataobjects/RawDataBlockFormat.h>
+
+namespace Belle2 {
+
+  /**
+   * The Raw FTSW class.
+   *
+   * This class stores the RAW data containing FTSW data(event #, trg time ).
+   */
+  class RawFTSWFormat : public RawDataBlockFormat {
+  public:
+
+    //! Default constructor
+    RawFTSWFormat();
+    //! Constructor using existing pointer to raw data buffer
+    //RawFTSWFormat(int* bufin, int nwords);
+    //! Destructor
+    virtual ~RawFTSWFormat();
+
+    /*     //! Get # of words in this buffer */
+    /*     int GetNwords(int n); */
+
+    //! Get # of words of header
+    virtual int GetNwordsHeader(int n) = 0;
+
+    //! Get Node # ( should be "TTD " )
+    virtual unsigned int GetFTSWNodeID(int n) = 0;
+
+    //! Get event #
+    virtual unsigned int GetEveNo(int n) = 0;
+
+    //! Get a word containing ctime and trigger type info
+    virtual unsigned int GetTTCtimeTRGType(int n) = 0;
+
+    //! get unixtime of the trigger
+    virtual unsigned int GetTTUtime(int n) = 0;
+
+    //! Get ctime of the trigger
+    virtual int GetTTCtime(int n) = 0;
+
+    //! Get trgtype
+    virtual int GetTRGType(int n) = 0;
+
+    //! Get timeval from ctime and utime
+    virtual void GetTTTimeVal(int n, struct timeval* tv) = 0;
+
+    //! Get timespec from ctime and utime
+    virtual void GetTTTimeSpec(int n, struct timespec* ts) = 0;
+
+    //! Get time in ns since epoch from ctime and utime
+    virtual unsigned long long int GetTTTimeNs(int n) = 0;
+
+    //! Get magic number for data corruption check
+    virtual unsigned int GetMagicTrailer(int n) = 0;
+
+    //! Get stored information of getimeofday in a PC
+    virtual void GetPCTimeVal(int n, struct timeval* tv);
+
+
+
+    //! check the data contents
+    virtual void CheckData(int n,
+                           unsigned int prev_evenum, unsigned int* cur_evenum,
+                           unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) = 0;
+
+    //! Exp# (10bit) run# (14bit) restart # (8bit)
+    virtual unsigned int GetExpRunSubrun(int n) = 0;
+
+    //! Get run #
+    virtual int GetRunNo(int n) = 0;
+
+    //! Get subrun #
+    virtual int GetSubRunNo(int n) = 0;
+
+    //! get a word cotaining run # and subrun #
+    virtual int GetRunNoSubRunNo(int n) = 0;
+
+    //! Get Exp #
+    virtual int GetExpNo(int n) = 0;
+
+    //! DESY test only (ver.1)
+    virtual int Get15bitTLUTag(int n);
+
+    //! HER injection = 1 or LER injection = 0
+    virtual int GetIsHER(int n);
+
+    //! Get time since the last injection
+    virtual unsigned int GetTimeSinceLastInjection(int n);
+
+    //! Get time since the previous trigger
+    virtual unsigned int GetTimeSincePrevTrigger(int n);
+
+    //! Get a bunch number
+    virtual unsigned int GetBunchNumber(int n);
+
+    //! Get a frame count
+    virtual unsigned int GetFrameCount(int n);
+
+  protected :
+
+  };
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawFTSWFormat_latest.h b/ROPCApplications/rawdata/dataobjects/include/RawFTSWFormat_latest.h
new file mode 100644
index 0000000000000000000000000000000000000000..01fbd943e182000373f45a0fa02c911c7feebefa
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawFTSWFormat_latest.h
@@ -0,0 +1,198 @@
+//+
+// File : RawFTSWFormat_latest.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 7 - Mar - 2016
+//-
+
+#ifndef RAWFTSWFORMAT_LATEST_H
+#define RAWFTSWFORMAT_LATEST_H
+#include <rawdata/dataobjects/RawFTSWFormat.h>
+
+namespace Belle2 {
+
+  /**
+   * The Raw FTSW class 3 ( 2019.8.20 )
+   *
+   * This class stores the RAW data containing FTSW data(event #, trg time ).
+   */
+  class RawFTSWFormat_latest : public RawFTSWFormat {
+  public:
+
+    //! Default constructor
+    RawFTSWFormat_latest();
+    //! Constructor using existing pointer to raw data buffer
+    //RawFTSWFormat_latest(int* bufin, int nwords);
+    //! Destructor
+    virtual ~RawFTSWFormat_latest();
+
+    /*     //! Get # of words in this buffer */
+    /*     int GetNwords(int n); */
+
+    //! Get # of words of header
+    int GetNwordsHeader(int n) OVERRIDE_CPP17;
+
+    //! Get Node # ( should be "TTD " )
+    unsigned int GetFTSWNodeID(int n) OVERRIDE_CPP17;
+
+    //! Get event #
+    unsigned int GetEveNo(int n) OVERRIDE_CPP17;
+
+    //! Get a word containing ctime and trigger type info
+    unsigned int GetTTCtimeTRGType(int n) OVERRIDE_CPP17;
+
+    //! get unixtime of the trigger
+    unsigned int GetTTUtime(int n) OVERRIDE_CPP17;
+
+    //! Get ctime of the trigger
+    int GetTTCtime(int n) OVERRIDE_CPP17;
+
+    //! Get trgtype
+    int GetTRGType(int n) OVERRIDE_CPP17;
+
+    //! Get timeval from ctime and utime
+    void GetTTTimeVal(int n, struct timeval* tv) OVERRIDE_CPP17;
+
+    //! Get timespec from ctime and utime
+    void GetTTTimeSpec(int n, struct timespec* ts) OVERRIDE_CPP17;
+
+    //! Get time in ns since epoch from ctime and utime
+    unsigned long long int GetTTTimeNs(int n) OVERRIDE_CPP17;
+
+    //! Get magic number for data corruption check
+    unsigned int GetMagicTrailer(int n) OVERRIDE_CPP17;
+
+    //! Get stored information of getimeofday in a PC
+    void GetPCTimeVal(int n, struct timeval* tv) OVERRIDE_CPP17;
+
+    //! check the data contents
+    void CheckData(int n,
+                   unsigned int prev_evenum, unsigned int* cur_evenum,
+                   unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
+
+    //! Exp# (10bit) run# (14bit) restart # (8bit)
+    unsigned int GetExpRunSubrun(int n) OVERRIDE_CPP17;
+
+    //! Get run #
+    int GetRunNo(int n) OVERRIDE_CPP17;
+
+
+    //! Get subrun #
+    int GetSubRunNo(int n) OVERRIDE_CPP17;
+
+    //! get a word cotaining run # and subrun #
+    int GetRunNoSubRunNo(int n) OVERRIDE_CPP17;
+
+    //! Get Exp #
+    int GetExpNo(int n) OVERRIDE_CPP17;
+
+    //! HER injection = 1 or LER injection = 0
+    int GetIsHER(int n) OVERRIDE_CPP17;
+
+    //! Get time since the last injection
+    unsigned int GetTimeSinceLastInjection(int n) OVERRIDE_CPP17;
+
+    //! Get time since the previous trigger
+    unsigned int GetTimeSincePrevTrigger(int n) OVERRIDE_CPP17;
+
+    //! Get a bunch number
+    unsigned int GetBunchNumber(int n) OVERRIDE_CPP17;
+
+    //! Get a frame count
+    unsigned int GetFrameCount(int n) OVERRIDE_CPP17;
+
+    //!header format
+    enum {
+      POS_NWORDS = 0, // same as v.1( late-DESY ver.)
+      POS_HDR_NWORDS = 1, // same as v.1
+      POS_NUMEVE_NUMNODES = 2, // same as v.1
+      POS_EXP_RUN_NO = 3, // same as v.1
+      POS_EVE_NO_1 = 4, // same as v.1
+      POS_NA_1 = 5, // same as v.1
+      POS_NODE_ID = 6, // same as v.1
+      POS_NA_2 = 7 // same as v.1
+    };
+
+    //!data format
+    enum {
+      POS_TT_CTIME_TRGTYPE = 8, // same as v.1
+      POS_TT_UTIME = 9, // same as v.1
+      POS_EVE_NO_2 = 10,
+      POS_FRAME_COUNT = 11,
+      POS_TIME_SINCE_PREV_TRG = 12,
+      POS_INJECTION_INFO = 13,
+      POS_BUNCH_NUM = 14,
+      POS_TVSEC_FROM_PC = 15,
+      POS_TVUSEC_FROM_PC = 16
+    };
+
+    //!trailer format
+    enum {
+      POS_RSVD_1 = 20, // same as v.1 but position is shifted
+      POS_MAGIC_1 = 21 // same as v.1 but position is shifted
+    };
+
+    enum {
+      INJ_HER_LER_MASK = 0x80000000,
+      INJ_HER_LER_SHIFT = 31,
+      INJ_TIME_MASK = 0x7FFFFFFF,
+      INJ_TIME_SHIFT = 0,
+      INJ_BUNCH_MASK = 0x000007FF,
+      INJ_BUNCH_SHIFT = 0,
+      EXP_MASK = 0xFFC00000,
+      EXP_SHIFT = 22,
+      RUNNO_MASK = 0x003FFF00,
+      RUNNO_SHIFT = 8,
+      SUBRUNNO_MASK = 0x000000FF,
+      TTCTIME_MASK = 0x7FFFFFF0,
+      TTCTIME_SHIFT = 4,
+      TRGTYPE_MASK = 0xF
+    };
+
+    enum {
+      SIZE_FTSW_PACKET = 22
+    };
+    //#endif
+
+    enum {
+      FTSW_MAGIC_TRAILER = 0x7FFF0000
+    };
+
+  protected :
+
+  };
+
+  inline unsigned int RawFTSWFormat_latest::GetExpRunSubrun(int n)
+  {
+    return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_EXP_RUN_NO ]);
+
+  }
+
+
+  inline int RawFTSWFormat_latest::GetRunNo(int n)
+  {
+    return (((unsigned int)(m_buffer[ GetBufferPos(n) + POS_EXP_RUN_NO ]) & RUNNO_MASK)
+            >> RUNNO_SHIFT);
+  }
+
+  inline int RawFTSWFormat_latest::GetSubRunNo(int n)
+  {
+    return (m_buffer[ GetBufferPos(n) + POS_EXP_RUN_NO ] & SUBRUNNO_MASK);
+  }
+
+  inline int RawFTSWFormat_latest::GetRunNoSubRunNo(int n)
+  {
+    return ((unsigned int)(m_buffer[ GetBufferPos(n) + POS_EXP_RUN_NO ]) &
+            (RUNNO_MASK | SUBRUNNO_MASK));
+  }
+
+  inline int RawFTSWFormat_latest::GetExpNo(int n)
+  {
+    return (((unsigned int)(m_buffer[ GetBufferPos(n) + POS_EXP_RUN_NO ]) & EXP_MASK)
+            >> EXP_SHIFT);
+  }
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawFTSWFormat_v1.h b/ROPCApplications/rawdata/dataobjects/include/RawFTSWFormat_v1.h
new file mode 100644
index 0000000000000000000000000000000000000000..e371f4a935a1052eb44be992e3a6a087b8fa5f63
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawFTSWFormat_v1.h
@@ -0,0 +1,163 @@
+//+
+// File : RawFTSWFormat_v1.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 7 - Mar - 2016
+//-
+
+#ifndef RAWFTSWFORMAT_V1_H
+#define RAWFTSWFORMAT_V1_H
+#include <rawdata/dataobjects/RawFTSWFormat.h>
+
+namespace Belle2 {
+
+  /**
+   * The Raw FTSW class ver.1 .
+   *
+   * This class stores the RAW data containing FTSW data(event #, trg time ).
+   */
+  class RawFTSWFormat_v1 : public RawFTSWFormat {
+  public:
+
+    //! Default constructor
+    RawFTSWFormat_v1();
+    //! Constructor using existing pointer to raw data buffer
+    //RawFTSWFormat_v1(int* bufin, int nwords);
+    //! Destructor
+    virtual ~RawFTSWFormat_v1();
+
+    /*     //! Get # of words in this buffer */
+    /*     int GetNwords(int n); */
+
+    //! Get # of words of header
+    int GetNwordsHeader(int n)  OVERRIDE_CPP17;
+
+    //! Get Node # ( should be "TTD " )
+    unsigned int GetFTSWNodeID(int n) OVERRIDE_CPP17;
+
+    //! Get event #
+    unsigned int GetEveNo(int n) OVERRIDE_CPP17;
+
+    //! Get a word containing ctime and trigger type info
+    unsigned int GetTTCtimeTRGType(int n) OVERRIDE_CPP17;
+
+    //! get unixtime of the trigger
+    unsigned int GetTTUtime(int n) OVERRIDE_CPP17;
+
+    //! Get ctime of the trigger
+    int GetTTCtime(int n) OVERRIDE_CPP17;
+
+    //! Get trgtype
+    int GetTRGType(int n) OVERRIDE_CPP17;
+
+    //! Get timeval from ctime and utime
+    void GetTTTimeVal(int n, struct timeval* tv) OVERRIDE_CPP17;
+
+    //! Get timespec from ctime and utime
+    void GetTTTimeSpec(int n, struct timespec* ts) OVERRIDE_CPP17;
+
+    //! Get time in ns since epoch from ctime and utime
+    unsigned long long int GetTTTimeNs(int n) OVERRIDE_CPP17;
+
+    //! Get magic number for data corruption check
+    unsigned int GetMagicTrailer(int n) OVERRIDE_CPP17;
+
+    //! check the data contents
+    void CheckData(int n,
+                   unsigned int prev_evenum, unsigned int* cur_evenum,
+                   unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
+
+    //! Exp# (10bit) run# (14bit) restart # (8bit)
+    unsigned int GetExpRunSubrun(int n) OVERRIDE_CPP17;
+
+    //! Get run #
+    int GetRunNo(int n) OVERRIDE_CPP17;
+
+
+    //! Get subrun #
+    int GetSubRunNo(int n) OVERRIDE_CPP17;
+
+    //! get a word cotaining run # and subrun #
+    int GetRunNoSubRunNo(int n) OVERRIDE_CPP17;
+
+    //! Get Exp #
+    int GetExpNo(int n) OVERRIDE_CPP17;
+
+    //! DESY test only
+    int Get15bitTLUTag(int n) OVERRIDE_CPP17;
+
+    enum {
+      POS_NWORDS = 0,
+      POS_HDR_NWORDS = 1,
+      POS_NUMEVE_NUMNODES = 2,
+      POS_EXP_RUN_NO = 3,
+      POS_EVE_NO = 4,
+      POS_NA_1 = 5,
+      POS_NODE_ID = 6,
+      POS_NA_2 = 7,
+      POS_TT_CTIME_TRGTYPE = 8,
+      POS_TT_UTIME = 9,
+      POS_FTSW_3 = 10,
+      POS_FTSW_4 = 11,
+      POS_RSVD_1 = 12,
+      POS_MAGIC_1 = 13
+    };
+
+    enum {
+      EXP_MASK = 0xFFC00000,
+      EXP_SHIFT = 22,
+      RUNNO_MASK = 0x003FFF00,
+      RUNNO_SHIFT = 8,
+      SUBRUNNO_MASK = 0x000000FF,
+      TTCTIME_MASK = 0x7FFFFFF0,
+      TTCTIME_SHIFT = 4,
+      TRGTYPE_MASK = 0xF
+    };
+
+    enum {
+      SIZE_FTSW_PACKET = 14
+    };
+    //#endif
+
+    enum {
+      FTSW_MAGIC_TRAILER = 0x7FFF0000
+    };
+
+  protected :
+
+  };
+
+  inline unsigned int RawFTSWFormat_v1::GetExpRunSubrun(int n)
+  {
+    return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_EXP_RUN_NO ]);
+
+  }
+
+
+  inline int RawFTSWFormat_v1::GetRunNo(int n)
+  {
+    return (((unsigned int)(m_buffer[ GetBufferPos(n) + POS_EXP_RUN_NO ]) & RUNNO_MASK)
+            >> RUNNO_SHIFT);
+  }
+
+  inline int RawFTSWFormat_v1::GetSubRunNo(int n)
+  {
+    return (m_buffer[ GetBufferPos(n) + POS_EXP_RUN_NO ] & SUBRUNNO_MASK);
+  }
+
+  inline int RawFTSWFormat_v1::GetRunNoSubRunNo(int n)
+  {
+    return ((unsigned int)(m_buffer[ GetBufferPos(n) + POS_EXP_RUN_NO ]) &
+            (RUNNO_MASK | SUBRUNNO_MASK));
+  }
+
+  inline int RawFTSWFormat_v1::GetExpNo(int n)
+  {
+    return (((unsigned int)(m_buffer[ GetBufferPos(n) + POS_EXP_RUN_NO ]) & EXP_MASK)
+            >> EXP_SHIFT);
+  }
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawFTSWFormat_v2.h b/ROPCApplications/rawdata/dataobjects/include/RawFTSWFormat_v2.h
new file mode 100644
index 0000000000000000000000000000000000000000..17bd9f068a3a71820d3246ad09cc7b914bce5743
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawFTSWFormat_v2.h
@@ -0,0 +1,196 @@
+//+
+// File : RawFTSWFormat_v2.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 7 - Mar - 2016
+//-
+
+#ifndef RAWFTSWFORMAT_V2_H
+#define RAWFTSWFORMAT_V2_H
+#include <rawdata/dataobjects/RawFTSWFormat.h>
+#include "rawdata/switch_basf2_standalone.h"
+
+namespace Belle2 {
+
+  /**
+   * The Raw FTSW class ver.2 .
+   *
+   * Nakao-san will add additional data in FTSW format
+   */
+  class RawFTSWFormat_v2 : public RawFTSWFormat {
+  public:
+
+    //! Default constructor
+    RawFTSWFormat_v2();
+    //! Constructor using existing pointer to raw data buffer
+    //RawFTSWFormat_v2(int* bufin, int nwords);
+    //! Destructor
+    virtual ~RawFTSWFormat_v2();
+
+    /*     //! Get # of words in this buffer */
+    /*     int GetNwords(int n); */
+
+    //! Get # of words of header
+    int GetNwordsHeader(int n) OVERRIDE_CPP17;
+
+    //! Get Node # ( should be "TTD " )
+    unsigned int GetFTSWNodeID(int n) OVERRIDE_CPP17;
+
+    //! Get event #
+    unsigned int GetEveNo(int n) OVERRIDE_CPP17;
+
+    //! Get a word containing ctime and trigger type info
+    unsigned int GetTTCtimeTRGType(int n) OVERRIDE_CPP17;
+
+    //! get unixtime of the trigger
+    unsigned int GetTTUtime(int n) OVERRIDE_CPP17;
+
+    //! Get ctime of the trigger
+    int GetTTCtime(int n) OVERRIDE_CPP17;
+
+    //! Get trgtype
+    int GetTRGType(int n) OVERRIDE_CPP17;
+
+    //! Get timeval from ctime and utime
+    void GetTTTimeVal(int n, struct timeval* tv) OVERRIDE_CPP17;
+
+    //! Get timespec from ctime and utime
+    void GetTTTimeSpec(int n, struct timespec* ts) OVERRIDE_CPP17;
+
+    //! Get time in ns since epoch from ctime and utime
+    unsigned long long int GetTTTimeNs(int n) OVERRIDE_CPP17;
+
+    //! Get magic number for data corruption check
+    unsigned int GetMagicTrailer(int n) OVERRIDE_CPP17;
+
+
+
+    //! check the data contents
+    void CheckData(int n,
+                   unsigned int prev_evenum, unsigned int* cur_evenum,
+                   unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
+
+    //! Exp# (10bit) run# (14bit) restart # (8bit)
+    unsigned int GetExpRunSubrun(int n) OVERRIDE_CPP17;
+
+    //! Get run #
+    int GetRunNo(int n) OVERRIDE_CPP17;
+
+
+    //! Get subrun #
+    int GetSubRunNo(int n) OVERRIDE_CPP17;
+
+    //! get a word cotaining run # and subrun #
+    int GetRunNoSubRunNo(int n) OVERRIDE_CPP17;
+
+    //! Get Exp #
+    int GetExpNo(int n) OVERRIDE_CPP17;
+
+    //! HER injection = 1 or LER injection = 0
+    int GetIsHER(int n) OVERRIDE_CPP17;
+
+    //! Get time since the last injection
+    unsigned int GetTimeSinceLastInjection(int n) OVERRIDE_CPP17;
+
+    //! Get time since the previous trigger
+    unsigned int GetTimeSincePrevTrigger(int n) OVERRIDE_CPP17;
+
+    //! Get a bunch number
+    unsigned int GetBunchNumber(int n) OVERRIDE_CPP17;
+
+    //! Get a frame count
+    unsigned int GetFrameCount(int n) OVERRIDE_CPP17;
+
+    //!header format
+    enum {
+      POS_NWORDS = 0, // same as v.1( late-DESY ver.)
+      POS_HDR_NWORDS = 1, // same as v.1
+      POS_NUMEVE_NUMNODES = 2, // same as v.1
+      POS_EXP_RUN_NO = 3, // same as v.1
+      POS_EVE_NO_1 = 4, // same as v.1
+      POS_NA_1 = 5, // same as v.1
+      POS_NODE_ID = 6, // same as v.1
+      POS_NA_2 = 7 // same as v.1
+    };
+
+    //!data format
+    enum {
+      POS_TT_CTIME_TRGTYPE = 8, // same as v.1
+      POS_TT_UTIME = 9, // same as v.1
+      POS_EVE_NO_2 = 10,
+      POS_FRAME_COUNT = 11,
+      POS_TIME_SINCE_PREV_TRG = 12,
+      POS_INJECTION_INFO = 13,
+      POS_BUNCH_NUM = 14
+    };
+
+    //!trailer format
+    enum {
+      POS_RSVD_1 = 20, // same as v.1 but position is shifted
+      POS_MAGIC_1 = 21 // same as v.1 but position is shifted
+    };
+
+    enum {
+      INJ_HER_LER_MASK = 0x80000000,
+      INJ_HER_LER_SHIFT = 31,
+      INJ_TIME_MASK = 0x7FFFFFFF,
+      INJ_TIME_SHIFT = 0,
+      INJ_BUNCH_MASK = 0x000007FF,
+      INJ_BUNCH_SHIFT = 0,
+      EXP_MASK = 0xFFC00000,
+      EXP_SHIFT = 22,
+      RUNNO_MASK = 0x003FFF00,
+      RUNNO_SHIFT = 8,
+      SUBRUNNO_MASK = 0x000000FF,
+      TTCTIME_MASK = 0x7FFFFFF0,
+      TTCTIME_SHIFT = 4,
+      TRGTYPE_MASK = 0xF
+    };
+
+    enum {
+      SIZE_FTSW_PACKET = 22
+    };
+    //#endif
+
+    enum {
+      FTSW_MAGIC_TRAILER = 0x7FFF0000
+    };
+
+  protected :
+
+  };
+
+  inline unsigned int RawFTSWFormat_v2::GetExpRunSubrun(int n)
+  {
+    return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_EXP_RUN_NO ]);
+
+  }
+
+
+  inline int RawFTSWFormat_v2::GetRunNo(int n)
+  {
+    return (((unsigned int)(m_buffer[ GetBufferPos(n) + POS_EXP_RUN_NO ]) & RUNNO_MASK)
+            >> RUNNO_SHIFT);
+  }
+
+  inline int RawFTSWFormat_v2::GetSubRunNo(int n)
+  {
+    return (m_buffer[ GetBufferPos(n) + POS_EXP_RUN_NO ] & SUBRUNNO_MASK);
+  }
+
+  inline int RawFTSWFormat_v2::GetRunNoSubRunNo(int n)
+  {
+    return ((unsigned int)(m_buffer[ GetBufferPos(n) + POS_EXP_RUN_NO ]) &
+            (RUNNO_MASK | SUBRUNNO_MASK));
+  }
+
+  inline int RawFTSWFormat_v2::GetExpNo(int n)
+  {
+    return (((unsigned int)(m_buffer[ GetBufferPos(n) + POS_EXP_RUN_NO ]) & EXP_MASK)
+            >> EXP_SHIFT);
+  }
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawHeader_latest.h b/ROPCApplications/rawdata/dataobjects/include/RawHeader_latest.h
new file mode 100644
index 0000000000000000000000000000000000000000..4e468443ec63471e0f7b46f4735313f6626af6b5
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawHeader_latest.h
@@ -0,0 +1,526 @@
+//+
+// File : RawHeader_latest.h
+// Description : Module to handle RawHeader_latest attached to raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWHEADER_LATEST_H
+#define RAWHEADER_LATEST_H
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+//#include <TObject.h>
+#include <rawdata/switch_basf2_standalone.h>
+
+//#include <framework/datastore/DataStore.h>
+
+
+//#define HEADER_SIZE 16
+
+namespace Belle2 {
+
+  /**
+   * The Raw Header class ver.1 ( the latest version since May, 2014 )
+   * This class defines the format of the header of RawCOPPER class data
+   * and used for extracting header info from RawCOPPER object
+   */
+
+  //  class RawHeader_latest : public TObject {
+  class RawHeader_latest {
+  public:
+    //! Default constructor
+    RawHeader_latest();
+
+    //! Constructor using existing pointer to raw data buffer
+    RawHeader_latest(int*);
+
+    //! Destructor
+    ~RawHeader_latest();
+
+    //! Get header contents
+    int* GetBuffer() { return m_buffer; }
+
+    //! set buffer
+    void SetBuffer(int* bufin) { m_buffer = bufin; }
+
+    //! initialize header
+    void CheckSetBuffer();
+
+    //! check if m_buffer exists
+    void CheckGetBuffer();
+
+    //! set contents of header
+    void SetNwords(int nwords);
+
+    //! set contents of header
+    void SetEveNo(unsigned int eve_no);
+
+    //! set contents of header
+    void SetNodeID(unsigned int node_id);
+
+    //! set contents of header
+    void SetDataType(int data_type);
+
+    //! set contents of header
+    void SetTruncMask(int trunc_mask);
+
+    //    void SetB2LFEEHdrPart(unsigned int word1, unsigned int word2);   //! set contents of header
+    //     void SetFTSW2Words(int* ftsw_buf);
+
+    /// Set values of FTSW info( trigger timing)
+    void SetFTSW2Words(unsigned int word1, unsigned int word2);
+
+    /// Set a word consists of exp #, run # and subrun #
+    void SetExpRunNumber(int* exprun_buf);
+
+    //! set contents of header
+    void SetOffset1stFINESSE(int offset_1st_FINESSE);    //! set contents of header
+
+    void SetOffset2ndFINESSE(int offset_2nd_FINESSE);    //! set contents of header
+
+    void SetOffset3rdFINESSE(int offset_3rd_FINESSE);    //! set contents of header
+
+    void SetOffset4thFINESSE(int offset_4th_FINESSE);    //! set contents of header
+
+    //    void SetMagicWordEntireHeader(); //! set magic words;
+
+    /// Add nodeinfo in trace area
+    //    int AddNodeInfo(int node_id);
+
+    int GetNwords();  //! get contents of header
+
+    int GetHdrNwords();  //! get contents of header
+
+    unsigned int GetExpRunSubrun(); //! get a run/exp number combined word
+
+    int GetExpNo();  //! get contents of header
+
+    int GetRunNo();    //! get run # (14bit)
+
+    int GetSubRunNo();    //! get restart #(8bit)
+
+    unsigned int GetEveNo();  //! get contents of header
+
+    unsigned int GetNodeID();  //! get contents of header
+
+    int GetDataType();  //! get contents of header
+
+    int GetTruncMask();  //! get contents of header
+
+    //! Get Detected Error bitflag
+    unsigned int GetErrorBitFlag();
+
+    //! Add Detected Error bitflag
+    void AddErrorBitFlag(unsigned int error_bit_flag);
+
+    //! Get Packet CRC error flag
+    int GetPacketCRCError();
+
+    //! Get Detected Error bitflag
+    int GetEventCRCError();
+
+    //! get contents of header
+    int GetOffset1stFINESSE();
+
+    //! get contents of header
+    int GetOffset2ndFINESSE();
+
+    //! get contents of header
+    int GetOffset3rdFINESSE();
+
+    //! get contents of header
+    int GetOffset4thFINESSE();
+
+    //    int GetNumNodes();  //! get contents of header
+
+    //    int GetNodeInfo(int node_no, int* node_id);    //! get contents of header
+
+    //! get contents of header
+    unsigned int GetTTCtimeTRGType();
+
+    //! get contents of header
+    int GetTTCtime();
+
+    //! get TRGType
+    int GetTRGType();
+
+    //! get contents of header
+    unsigned int GetTTUtime();
+
+    //! get contents of header
+    void GetTTTimeVal(struct  timeval* tv);
+
+    /// Get magic word to check the data corruption
+    //    unsigned int GetMagicWordEntireHeader();
+
+    //! check the contents of header
+    void CheckHeader(int* buf);
+
+    /*
+      Experimental(10bit) #, Run#(14bit), restat# bit mask(8bit)
+    */
+    enum {
+      MAGIC_WORD = 0x7F7F0000,
+      MAGIC_MASK = 0xFFFF0000,
+      MAGIC_SHIFT = 16,
+      FORMAT_VERSION__MASK = 0x0000FF00,
+      FORMAT_VERSION_SHIFT = 8
+    };
+
+    enum {
+      EXP_MASK = 0xFFC00000,
+      EXP_SHIFT = 22,
+      RUNNO_MASK = 0x003FFF00,
+      RUNNO_SHIFT = 8,
+      SUBRUNNO_MASK = 0x000000FF
+    };
+
+    enum {
+      RAWHEADER_NWORDS = 12
+    };
+
+    enum {
+      HDR_NWORDS_MASK = 0x000000FF
+    };
+
+    /* Data Format : Fixed length part*/
+    enum {
+      POS_NWORDS = 0,
+      POS_VERSION_HDRNWORDS = 1,
+      POS_EXP_RUN_NO = 2,
+      POS_EVE_NO = 3,
+      POS_TTCTIME_TRGTYPE = 4,
+      POS_TTUTIME = 5,
+      POS_NODE_ID = 6,
+      POS_TRUNC_MASK_DATATYPE = 7,
+      POS_OFFSET_1ST_FINESSE = 8,
+      POS_OFFSET_2ND_FINESSE = 9,
+      POS_OFFSET_3RD_FINESSE = 10,
+      POS_OFFSET_4TH_FINESSE = 11,
+    };
+
+
+    /* Data Format : Node info */
+    /*     enum { */
+    /*       NUM_MAX_NODES = 4   /\* (NUM_MAX_NODES + 1) slots are available in m_buffer. */
+    /*          (NUM_MAX_NODES +1 )th slot is filled with -1, when the number of total nodes */
+    /*          exceeds NUM_MAX_NODES *\/ */
+    /*     }; */
+
+    /*     /\* Data Format : Magic word *\/ */
+    /*     enum { */
+    /*       MAGIC_WORD_TERM_HEADER = 0x7fff0005 */
+    /*     }; */
+
+
+
+    /* To extract ctime */
+    enum {
+      TTCTIME_MASK = 0x7FFFFFF0,
+      TTCTIME_SHIFT = 4,
+      TRGTYPE_MASK = 0xF
+    };
+
+    /* Error bit in POS_TRUNC_MASK_DATATYPE */
+    /* Changed from the position of error bit to actual error value ( 0 -> 0x1, 1 -> 0x2 ) */
+    enum {
+      B2LINK_PACKET_CRC_ERROR = 0x1,
+      B2LINK_EVENT_CRC_ERROR = 0x2
+    };
+
+  private:
+    //! do not record buffer ( RawCOPPER includes buffer of RawHeader_latest and RawTrailer )
+    int* m_buffer; //! do not record
+
+    /// To derive from TObject
+    // ver.2 Do not record m_buffer pointer. (Dec.19, 2014)
+    //    ClassDef(RawHeader_latest, 1);
+  };
+
+
+  inline void RawHeader_latest::CheckSetBuffer()
+  {
+    if (m_buffer == NULL) {
+      B2FATAL("m_buffer is NULL. Exiting...");
+    }
+  }
+
+  inline void RawHeader_latest::CheckGetBuffer()
+  {
+    if (m_buffer == NULL) {
+      B2FATAL("m_buffer is NULL. Data is corrupted or header info has not yet filled. Exiting...");
+//  } else if (m_buffer[ POS_TERM_HEADER ] != MAGIC_WORD_TERM_HEADER) {
+//    B2FATAL("magic word is invalid(0x"<< std::hex() << m_buffer[ POS_TERM_HEADER ] <<"). Data is corrupted or header info has not yet filled. Exiting...");
+    }
+  }
+
+
+  inline void RawHeader_latest::SetNwords(int nwords)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_NWORDS ] = nwords;
+
+  }
+
+  inline void RawHeader_latest::SetEveNo(unsigned int eve_no)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_EVE_NO ] = eve_no;
+  }
+
+  inline void RawHeader_latest::SetNodeID(unsigned int node_id)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_NODE_ID ] = (int)node_id;
+  }
+
+  inline void RawHeader_latest::SetDataType(int data_type)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_TRUNC_MASK_DATATYPE ] =
+      (data_type & 0x7FFFFFFF) | (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x80000000);
+  }
+
+  inline void RawHeader_latest::SetTruncMask(int trunc_mask)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_TRUNC_MASK_DATATYPE ] = (trunc_mask << 31) | (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x7FFFFFFF);
+  }
+
+  /*   inline void RawHeader_latest::SetB2LFEEHdrPart(unsigned int word1, unsigned int word2) */
+  /*   { */
+  /*     m_buffer[ POS_HSLB_1 ] = word1; */
+  /*     m_buffer[ POS_HSLB_2 ] = word2; */
+  /*   } */
+
+
+  inline void RawHeader_latest::SetOffset1stFINESSE(int offset_1st_FINESSE)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_OFFSET_1ST_FINESSE ] = offset_1st_FINESSE;
+  }
+
+  inline void RawHeader_latest::SetOffset2ndFINESSE(int offset_2nd_FINESSE)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_OFFSET_2ND_FINESSE ] = offset_2nd_FINESSE;
+  }
+
+  inline void RawHeader_latest::SetOffset3rdFINESSE(int offset_3rd_FINESSE)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_OFFSET_3RD_FINESSE ] = offset_3rd_FINESSE;
+  }
+
+  inline void RawHeader_latest::SetOffset4thFINESSE(int offset_4th_FINESSE)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_OFFSET_4TH_FINESSE ] = offset_4th_FINESSE;
+  }
+
+  /*   inline void RawHeader_latest::SetFTSW2Words(int* ftsw_buf) */
+  /*   { */
+  /*     CheckSetBuffer(); */
+  /*     memcpy(&(m_buffer[ POS_HSLB_1 ]), (char*)ftsw_buf, sizeof(int) * 2); */
+  /*     return; */
+  /*   } */
+
+  inline void RawHeader_latest::SetFTSW2Words(unsigned int word1,
+                                              unsigned int word2)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_TTCTIME_TRGTYPE ] = word1;
+    m_buffer[ POS_TTUTIME ] = word2;
+    return;
+  }
+
+
+  inline void RawHeader_latest::SetExpRunNumber(int* exprun_buf)
+  {
+    CheckSetBuffer();
+    memcpy(&(m_buffer[ POS_EXP_RUN_NO ]), (char*)exprun_buf, sizeof(int) * 1);
+    return;
+  }
+
+
+//
+// Obtain info
+//
+
+  inline int RawHeader_latest::GetNwords()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_NWORDS ];
+  }
+
+  inline int RawHeader_latest::GetHdrNwords()
+  {
+
+    //    CheckGetBuffer();
+    //    return m_buffer[ POS_HDR_NWORDS ];
+    return RAWHEADER_NWORDS;
+  }
+
+  inline int RawHeader_latest::GetExpNo()
+  {
+    CheckGetBuffer();
+    return (((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]) & EXP_MASK)
+            >> EXP_SHIFT);
+  }
+
+
+  inline int RawHeader_latest::GetRunNo()
+  {
+    CheckGetBuffer();
+    return (((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]) & RUNNO_MASK)
+            >> RUNNO_SHIFT);
+  }
+
+  inline int RawHeader_latest::GetSubRunNo()
+  {
+    CheckGetBuffer();
+    return (m_buffer[ POS_EXP_RUN_NO ] & SUBRUNNO_MASK);
+  }
+
+  inline unsigned int RawHeader_latest::GetExpRunSubrun()
+  {
+    CheckGetBuffer();
+    return ((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]));
+  }
+
+
+  inline unsigned int RawHeader_latest::GetEveNo()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_EVE_NO ];
+  }
+
+  inline unsigned int RawHeader_latest::GetNodeID()
+  {
+    CheckGetBuffer();
+    return (unsigned int)m_buffer[ POS_NODE_ID ];
+  }
+
+  inline int RawHeader_latest::GetDataType()
+  {
+    CheckGetBuffer();
+    return (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x7FFFFFFF);
+  }
+
+  inline int RawHeader_latest::GetTruncMask()
+  {
+    CheckGetBuffer();
+    return (m_buffer[ POS_TRUNC_MASK_DATATYPE ] >> 23) & 0x1;
+  }
+
+  inline unsigned int RawHeader_latest::GetErrorBitFlag()
+  {
+    CheckGetBuffer();
+    return (unsigned int)(m_buffer[ POS_TRUNC_MASK_DATATYPE ]);
+  }
+
+  inline void RawHeader_latest::AddErrorBitFlag(unsigned int error_bit_flag)
+  {
+    CheckGetBuffer();
+    m_buffer[ POS_TRUNC_MASK_DATATYPE ] |= (int)error_bit_flag;
+    return;
+  }
+
+  inline int RawHeader_latest::GetPacketCRCError()
+  {
+    CheckGetBuffer();
+    unsigned int temp_err_flag = GetErrorBitFlag();
+    if ((temp_err_flag & B2LINK_PACKET_CRC_ERROR) == 0) {
+      return 0;
+    }
+    return 1;
+  }
+
+  inline int RawHeader_latest::GetEventCRCError()
+  {
+    CheckGetBuffer();
+    unsigned int temp_err_flag = GetErrorBitFlag();
+    if ((temp_err_flag & B2LINK_EVENT_CRC_ERROR) == 0) {
+      return 0;
+    }
+    return 1;
+  }
+
+  inline int RawHeader_latest::GetOffset1stFINESSE()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_OFFSET_1ST_FINESSE ];
+  }
+
+  inline int RawHeader_latest::GetOffset2ndFINESSE()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_OFFSET_2ND_FINESSE ];
+  }
+
+  inline int RawHeader_latest::GetOffset3rdFINESSE()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_OFFSET_3RD_FINESSE ];
+  }
+
+  inline int RawHeader_latest::GetOffset4thFINESSE()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_OFFSET_4TH_FINESSE ];
+  }
+
+  /*   inline int RawHeader_latest::GetNumNodes() */
+  /*   { */
+  /*     CheckGetBuffer(); */
+  /*     return m_buffer[ POS_NUM_NODES ]; */
+  /*   } */
+
+  inline unsigned int RawHeader_latest::GetTTCtimeTRGType()
+  {
+    CheckGetBuffer();
+    return (unsigned int)(m_buffer[ POS_TTCTIME_TRGTYPE ]);
+  }
+
+  inline int RawHeader_latest::GetTTCtime()
+  {
+    CheckGetBuffer();
+    return (int)((GetTTCtimeTRGType() & TTCTIME_MASK) >> TTCTIME_SHIFT);
+  }
+
+  inline int RawHeader_latest::GetTRGType()
+  {
+    CheckGetBuffer();
+    return (int)(GetTTCtimeTRGType() & TRGTYPE_MASK);
+  }
+
+  inline unsigned int RawHeader_latest::GetTTUtime()
+  {
+    CheckGetBuffer();
+    return (unsigned int)(m_buffer[ POS_TTUTIME ]);
+  }
+
+  inline void RawHeader_latest::GetTTTimeVal(struct timeval* tv)
+  {
+    tv->tv_sec = GetTTUtime();
+    tv->tv_usec = (int)(((double)GetTTCtime()) / 127.216);
+    return ;
+  }
+
+
+  /*   inline unsigned int RawHeader_latest::GetMagicWordEntireHeader() */
+  /*   { */
+  /*     CheckGetBuffer(); */
+  /*     return m_buffer[ POS_TERM_HEADER ]; */
+  /*   } */
+
+
+
+
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawHeader_v0.h b/ROPCApplications/rawdata/dataobjects/include/RawHeader_v0.h
new file mode 100644
index 0000000000000000000000000000000000000000..eb942b3d6be78e50837e4b9eae30f16b09565914
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawHeader_v0.h
@@ -0,0 +1,511 @@
+//+
+// File : RawHeader_v0.h
+// Description : Module to handle RawHeader_v0 attached to raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWHEADER_V0_H
+#define RAWHEADER_V0_H
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+//#include <TObject.h>
+#include <rawdata/switch_basf2_standalone.h>
+
+//#include <framework/datastore/DataStore.h>
+
+
+//#define HEADER_SIZE 16
+
+namespace Belle2 {
+
+  /**
+   * The Raw Header class ver.0 ( from August, 2013 to April, 2014 )
+   * This class defines the format of the header of RawCOPPER class data
+   * and used for extracting header info from RawCOPPER object
+   */
+
+  //  class RawHeader_v0 : public TObject {
+  class RawHeader_v0  {
+  public:
+    //! Default constructor
+    RawHeader_v0();
+
+    //! Constructor using existing pointer to raw data buffer
+    RawHeader_v0(int*);
+
+    //! Destructor
+    ~RawHeader_v0();
+
+    //! Get header contents
+    int* GetBuffer() { return m_buffer; }
+
+    //! set buffer
+    void SetBuffer(int* bufin) { m_buffer = bufin; }
+
+    //! initialize header
+    void CheckSetBuffer();
+
+    //! check if m_buffer exists
+    void CheckGetBuffer();
+
+    //! initialize header
+    void Initialize();
+
+    //! set contents of header
+    void SetNwords(int nwords);
+
+    //! set contents of header
+    void SetEveNo(unsigned int eve_no);    //! set contents of header
+
+    void SetNodeID(unsigned int node_id);    //! set contents of header
+
+    void SetDataType(int data_type);    //! set contents of header
+
+    void SetTruncMask(int trunc_mask);    //! set contents of header
+
+    //    void SetB2LFEEHdrPart(unsigned int word1, unsigned int word2);   //! set contents of header
+    //     void SetFTSW2Words(int* ftsw_buf);
+
+    /// Set values of FTSW info( trigger timing)
+    void SetFTSW2Words(unsigned int word1, unsigned int word2);
+
+    /// Set a word consists of exp #, run # and subrun #
+    void SetExpRunNumber(int* exprun_buf);
+
+    //! set contents of header
+    void SetOffset1stFINESSE(int offset_1st_FINESSE);    //! set contents of header
+
+    void SetOffset2ndFINESSE(int offset_2nd_FINESSE);    //! set contents of header
+
+    void SetOffset3rdFINESSE(int offset_3rd_FINESSE);    //! set contents of header
+
+    void SetOffset4thFINESSE(int offset_4th_FINESSE);    //! set contents of header
+
+    void SetMagicWordEntireHeader(); //! set magic words;
+
+    /// Add nodeinfo in trace area
+    int AddNodeInfo(int node_id);
+
+    //! get contents of header
+    int GetNwords();  //! get contents of header
+
+    int GetHdrNwords();  //! get contents of header
+
+    unsigned int GetExpRunSubrun(); //! get a run/exp number combined word
+
+    int GetExpNo();  //! get contents of header
+
+    int GetRunNo();    //! get run # (14bit)
+
+    int GetSubRunNo();    //! get restart #(8bit)
+
+    unsigned int GetEveNo();  //! get contents of header
+
+    unsigned int GetNodeID();  //! get contents of header
+
+    int GetDataType();  //! get contents of header
+
+    int GetTruncMask();  //! get contents of header
+
+    //! Get Detected Error bitflag
+    unsigned int GetErrorBitFlag();
+
+    //! Add Detected Error bitflag
+    void AddErrorBitFlag(unsigned int error_bit_flag);
+
+    //! get contents of header
+    int GetOffset1stFINESSE();
+
+    //! get contents of header
+    int GetOffset2ndFINESSE();
+
+    //! get contents of header
+    int GetOffset3rdFINESSE();
+
+    //! get contents of header
+    int GetOffset4thFINESSE();
+
+    //! get contents of header
+    int GetNumNodes();
+
+    //! get contents of header
+    int GetNodeInfo(int node_no, int* node_id);
+
+    //! get contents of header
+    unsigned int GetTTCtimeTRGType();
+
+    //! get contents of header
+    int GetTTCtime();
+
+    //! get TRGType
+    int GetTRGType();
+
+    //! get contents of header
+    unsigned int GetTTUtime();
+
+    //! get contents of header
+    void GetTTTimeVal(struct  timeval* tv);
+
+    /// Get magic word to check the data corruption
+    unsigned int GetMagicWordEntireHeader();
+
+    /*
+      Experimental(10bit) #, Run#(14bit), restat# bit mask(8bit)
+    */
+    enum {
+      FORMAT_VERSION__MASK = 0x0000FF00,
+      FORMAT_VERSION_SHIFT = 8
+    };
+
+    enum {
+      EXP_MASK = 0xFFC00000,
+      EXP_SHIFT = 22,
+      RUNNO_MASK = 0x003FFF00,
+      RUNNO_SHIFT = 8,
+      SUBRUNNO_MASK = 0x000000FF
+    };
+
+    enum {
+      RAWHEADER_NWORDS = 20
+    };
+
+    /* Data Format : Fixed length part*/
+    enum {
+      POS_NWORDS = 0,
+      POS_HDR_NWORDS = 1,
+      POS_EXP_RUN_NO = 2,
+      POS_EVE_NO = 3,
+      POS_TTCTIME_TRGTYPE = 4,
+      POS_TTUTIME = 5,
+      POS_NODE_ID = 6,
+      POS_TRUNC_MASK_DATATYPE = 7,
+      POS_OFFSET_1ST_FINESSE = 8,
+      POS_OFFSET_2ND_FINESSE = 9,
+      POS_OFFSET_3RD_FINESSE = 10,
+      POS_OFFSET_4TH_FINESSE = 11,
+      POS_RESVD_1 = 12,
+      POS_RESVD_2 = 13,
+      POS_NUM_NODES = 14,
+      POS_NODES_1 = 15,
+      POS_NODES_2 = 16,
+      POS_NODES_3 = 17,
+      POS_NODES_4 = 18,
+      POS_TERM_HEADER = 19
+    };
+    /* Data Format : Node info */
+    enum {
+      NUM_MAX_NODES = 4   /* (NUM_MAX_NODES + 1) slots are available in m_buffer.
+         (NUM_MAX_NODES +1 )th slot is filled with -1, when the number of total nodes
+         exceeds NUM_MAX_NODES */
+    };
+
+    /* Data Format : Magic word */
+    enum {
+      MAGIC_WORD_TERM_HEADER = 0x7fff0005
+    };
+
+    /* To extract ctime */
+    enum {
+      TTCTIME_MASK = 0x7FFFFFF0,
+      TTCTIME_SHIFT = 4,
+      TRGTYPE_MASK = 0xF
+    };
+
+  private:
+    //! do not record buffer ( RawCOPPER includes buffer of RawHeader_v0 and RawTrailer )
+    int* m_buffer; //! do not record
+
+    /// To derive from TObject
+    // ver.2 Do not record m_buffer pointer. (Dec.19, 2014)
+    //    ClassDef(RawHeader_v0, 2);
+  };
+
+
+  inline void RawHeader_v0::CheckSetBuffer()
+  {
+    if (m_buffer == NULL) {
+      B2FATAL("m_buffer is NULL. Exiting...");
+    }
+  }
+
+  inline void RawHeader_v0::CheckGetBuffer()
+  {
+    if (m_buffer == NULL) {
+      B2FATAL("m_buffer is NULL. Data is corrupted or header info has not yet filled. Exiting...");
+    } else if (m_buffer[ POS_TERM_HEADER ] != MAGIC_WORD_TERM_HEADER) {
+      B2FATAL("magic word is invalid(0x" << std::hex << m_buffer[ POS_TERM_HEADER ] << "," << m_buffer << " pos " << std::dec <<
+              POS_TERM_HEADER
+              << "). Data is corrupted or header info has not yet filled. Exiting...");
+    }
+  }
+
+
+
+//
+// Set info.
+//
+  inline void RawHeader_v0::Initialize()
+  {
+    CheckSetBuffer();
+    memset(m_buffer, 0, sizeof(int)*RAWHEADER_NWORDS);
+    m_buffer[ POS_HDR_NWORDS ] = RAWHEADER_NWORDS;
+    m_buffer[ POS_NUM_NODES ] = 0;
+
+  }
+
+  inline void RawHeader_v0::SetMagicWordEntireHeader()
+  {
+    m_buffer[ POS_TERM_HEADER ] = MAGIC_WORD_TERM_HEADER;
+  }
+
+  inline void RawHeader_v0::SetNwords(int nwords)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_NWORDS ] = nwords;
+
+  }
+
+  inline void RawHeader_v0::SetEveNo(unsigned int eve_no)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_EVE_NO ] = eve_no;
+  }
+
+  inline void RawHeader_v0::SetNodeID(unsigned int node_id)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_NODE_ID ] = node_id;
+  }
+
+  inline void RawHeader_v0::SetDataType(int data_type)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_TRUNC_MASK_DATATYPE ] =
+      (data_type & 0x7FFFFFFF) | (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x80000000);
+  }
+
+  inline void RawHeader_v0::SetTruncMask(int trunc_mask)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_TRUNC_MASK_DATATYPE ] = (trunc_mask << 31) | (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x7FFFFFFF);
+  }
+
+  /*   inline void RawHeader_v0::SetB2LFEEHdrPart(unsigned int word1, unsigned int word2) */
+  /*   { */
+  /*     m_buffer[ POS_HSLB_1 ] = word1; */
+  /*     m_buffer[ POS_HSLB_2 ] = word2; */
+  /*   } */
+
+
+  inline void RawHeader_v0::SetOffset1stFINESSE(int offset_1st_FINESSE)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_OFFSET_1ST_FINESSE ] = offset_1st_FINESSE;
+  }
+
+  inline void RawHeader_v0::SetOffset2ndFINESSE(int offset_2nd_FINESSE)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_OFFSET_2ND_FINESSE ] = offset_2nd_FINESSE;
+  }
+
+  inline void RawHeader_v0::SetOffset3rdFINESSE(int offset_3rd_FINESSE)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_OFFSET_3RD_FINESSE ] = offset_3rd_FINESSE;
+  }
+
+  inline void RawHeader_v0::SetOffset4thFINESSE(int offset_4th_FINESSE)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_OFFSET_4TH_FINESSE ] = offset_4th_FINESSE;
+  }
+
+  /*   inline void RawHeader_v0::SetFTSW2Words(int* ftsw_buf) */
+  /*   { */
+  /*     CheckSetBuffer(); */
+  /*     memcpy(&(m_buffer[ POS_HSLB_1 ]), (char*)ftsw_buf, sizeof(int) * 2); */
+  /*     return; */
+  /*   } */
+
+  inline void RawHeader_v0::SetFTSW2Words(unsigned int word1,
+                                          unsigned int word2)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_TTCTIME_TRGTYPE ] = word1;
+    m_buffer[ POS_TTUTIME ] = word2;
+    return;
+  }
+
+
+  inline void RawHeader_v0::SetExpRunNumber(int* exprun_buf)
+  {
+    CheckSetBuffer();
+    memcpy(&(m_buffer[ POS_EXP_RUN_NO ]), (char*)exprun_buf, sizeof(int) * 1);
+    return;
+  }
+
+
+//
+// Obtain info
+//
+
+  inline int RawHeader_v0::GetNwords()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_NWORDS ];
+  }
+
+  inline int RawHeader_v0::GetHdrNwords()
+  {
+
+    CheckGetBuffer();
+
+    return m_buffer[ POS_HDR_NWORDS ];
+  }
+
+  inline int RawHeader_v0::GetExpNo()
+  {
+    CheckGetBuffer();
+    return (((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]) & EXP_MASK)
+            >> EXP_SHIFT);
+  }
+
+
+  inline int RawHeader_v0::GetRunNo()
+  {
+    CheckGetBuffer();
+    return (((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]) & RUNNO_MASK)
+            >> RUNNO_SHIFT);
+  }
+
+  inline int RawHeader_v0::GetSubRunNo()
+  {
+    CheckGetBuffer();
+    return (m_buffer[ POS_EXP_RUN_NO ] & SUBRUNNO_MASK);
+  }
+
+  inline unsigned int RawHeader_v0::GetExpRunSubrun()
+  {
+    CheckGetBuffer();
+    return ((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]));
+  }
+
+
+  inline unsigned int RawHeader_v0::GetEveNo()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_EVE_NO ];
+  }
+
+  inline unsigned int RawHeader_v0::GetNodeID()
+  {
+    CheckGetBuffer();
+    return (unsigned int)(m_buffer[ POS_NODE_ID ]);
+  }
+
+  inline int RawHeader_v0::GetDataType()
+  {
+    CheckGetBuffer();
+    return (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x7FFFFFFF);
+  }
+
+  inline int RawHeader_v0::GetTruncMask()
+  {
+    CheckGetBuffer();
+    return (m_buffer[ POS_TRUNC_MASK_DATATYPE ] >> 23) & 0x1;
+  }
+
+  inline unsigned int RawHeader_v0::GetErrorBitFlag()
+  {
+    CheckGetBuffer();
+    return (unsigned int)(m_buffer[ POS_TRUNC_MASK_DATATYPE ]);
+  }
+
+  inline void RawHeader_v0::AddErrorBitFlag(unsigned int error_bit_flag)
+  {
+    CheckGetBuffer();
+    m_buffer[ POS_TRUNC_MASK_DATATYPE ] |= (int)error_bit_flag;
+    return;
+  }
+
+  inline int RawHeader_v0::GetOffset1stFINESSE()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_OFFSET_1ST_FINESSE ];
+  }
+
+  inline int RawHeader_v0::GetOffset2ndFINESSE()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_OFFSET_2ND_FINESSE ];
+  }
+
+  inline int RawHeader_v0::GetOffset3rdFINESSE()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_OFFSET_3RD_FINESSE ];
+  }
+
+  inline int RawHeader_v0::GetOffset4thFINESSE()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_OFFSET_4TH_FINESSE ];
+  }
+
+  inline int RawHeader_v0::GetNumNodes()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_NUM_NODES ];
+  }
+
+  inline unsigned int RawHeader_v0::GetTTCtimeTRGType()
+  {
+    CheckGetBuffer();
+    return (unsigned int)(m_buffer[ POS_TTCTIME_TRGTYPE ]);
+  }
+
+  inline int RawHeader_v0::GetTTCtime()
+  {
+    CheckGetBuffer();
+    return (int)((GetTTCtimeTRGType() & TTCTIME_MASK) >> TTCTIME_SHIFT);
+  }
+
+  inline int RawHeader_v0::GetTRGType()
+  {
+    CheckGetBuffer();
+    return (int)(GetTTCtimeTRGType() & TRGTYPE_MASK);
+  }
+
+
+  inline unsigned int RawHeader_v0::GetTTUtime()
+  {
+    CheckGetBuffer();
+    return (unsigned int)(m_buffer[ POS_TTUTIME ]);
+  }
+
+  inline void RawHeader_v0::GetTTTimeVal(struct timeval* tv)
+  {
+    tv->tv_sec = GetTTUtime();
+    tv->tv_usec = (int)(((double)GetTTCtime()) / 127.216);
+    return ;
+  }
+
+
+  inline unsigned int RawHeader_v0::GetMagicWordEntireHeader()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_TERM_HEADER ];
+  }
+
+
+
+
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawHeader_v1.h b/ROPCApplications/rawdata/dataobjects/include/RawHeader_v1.h
new file mode 100644
index 0000000000000000000000000000000000000000..1d08da328fecf48a8a25c0ebcc154c3b01d609fc
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawHeader_v1.h
@@ -0,0 +1,491 @@
+//+
+// File : RawHeader_v1.h
+// Description : Module to handle RawHeader_v1 attached to raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWHEADER_V1_H
+#define RAWHEADER_V1_H
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+//#include <TObject.h>
+#include <rawdata/switch_basf2_standalone.h>
+
+//#include <framework/datastore/DataStore.h>
+
+
+//#define HEADER_SIZE 16
+
+namespace Belle2 {
+
+  /**
+   * The Raw Header class ver.1 ( the latest version since May, 2014 )
+   * This class defines the format of the header of RawCOPPER class data
+   * and used for extracting header info from RawCOPPER object
+   */
+
+  class RawHeader_v1  {
+    //  class RawHeader_v1 : public TObject {
+  public:
+    //! Default constructor
+    RawHeader_v1();
+
+    //! Constructor using existing pointer to raw data buffer
+    RawHeader_v1(int*);
+
+    //! Destructor
+    ~RawHeader_v1();
+
+    //! Get header contents
+    int* GetBuffer() { return m_buffer; }
+
+    //! set buffer
+    void SetBuffer(int* bufin) { m_buffer = bufin; }
+
+    //! initialize header
+    void CheckSetBuffer();
+
+    //! check if m_buffer exists
+    void CheckGetBuffer();
+
+    //! set contents of header
+    void SetNwords(int nwords);
+
+    //! set contents of header
+    void SetEveNo(unsigned int eve_no);
+
+    //! set contents of header
+    void SetNodeID(unsigned int node_id);
+
+    //! set contents of header
+    void SetDataType(int data_type);
+
+    //! set contents of header
+    void SetTruncMask(int trunc_mask);
+
+    //    void SetB2LFEEHdrPart(unsigned int word1, unsigned int word2);   //! set contents of header
+    //     void SetFTSW2Words(int* ftsw_buf);
+
+    /// Set values of FTSW info( trigger timing)
+    void SetFTSW2Words(unsigned int word1, unsigned int word2);
+
+    /// Set a word consists of exp #, run # and subrun #
+    void SetExpRunNumber(int* exprun_buf);
+
+    //! set contents of header
+    void SetOffset1stFINESSE(int offset_1st_FINESSE);    //! set contents of header
+
+    void SetOffset2ndFINESSE(int offset_2nd_FINESSE);    //! set contents of header
+
+    void SetOffset3rdFINESSE(int offset_3rd_FINESSE);    //! set contents of header
+
+    void SetOffset4thFINESSE(int offset_4th_FINESSE);    //! set contents of header
+
+    //    void SetMagicWordEntireHeader(); //! set magic words;
+
+    /// Add nodeinfo in trace area
+    //    int AddNodeInfo(int node_id);
+
+    int GetNwords();  //! get contents of header
+
+    int GetHdrNwords();  //! get contents of header
+
+    unsigned int GetExpRunSubrun(); //! get a run/exp number combined word
+
+    int GetExpNo();  //! get contents of header
+
+    int GetRunNo();    //! get run # (14bit)
+
+    int GetSubRunNo();    //! get restart #(8bit)
+
+    unsigned int GetEveNo();  //! get contents of header
+
+    unsigned int GetNodeID();  //! get contents of header
+
+    int GetDataType();  //! get contents of header
+
+    int GetTruncMask();  //! get contents of header
+
+    //! Get Detected Error bitflag
+    unsigned int GetErrorBitFlag();
+
+    //! Add Detected Error bitflag
+    void AddErrorBitFlag(unsigned int error_bit_flag);
+
+    //! get contents of header
+    int GetOffset1stFINESSE();
+
+    //! get contents of header
+    int GetOffset2ndFINESSE();
+
+    //! get contents of header
+    int GetOffset3rdFINESSE();
+
+    //! get contents of header
+    int GetOffset4thFINESSE();
+
+    //    int GetNumNodes();  //! get contents of header
+
+    //    int GetNodeInfo(int node_no, int* node_id);    //! get contents of header
+
+    //! get contents of header
+    unsigned int GetTTCtimeTRGType();
+
+    //! get contents of header
+    int GetTTCtime();
+
+    //! get TRGType
+    int GetTRGType();
+
+    //! get contents of header
+    unsigned int GetTTUtime();
+
+    //! get contents of header
+    void GetTTTimeVal(struct  timeval* tv);
+
+    /// Get magic word to check the data corruption
+    //    unsigned int GetMagicWordEntireHeader();
+
+    //! check the contents of header
+    void CheckHeader(int* buf);
+
+    /*
+      Experimental(10bit) #, Run#(14bit), restat# bit mask(8bit)
+    */
+    enum {
+      MAGIC_WORD = 0x7F7F0000,
+      MAGIC_MASK = 0xFFFF0000,
+      MAGIC_SHIFT = 16,
+      FORMAT_VERSION__MASK = 0x0000FF00,
+      FORMAT_VERSION_SHIFT = 8
+    };
+
+    enum {
+      EXP_MASK = 0xFFC00000,
+      EXP_SHIFT = 22,
+      RUNNO_MASK = 0x003FFF00,
+      RUNNO_SHIFT = 8,
+      SUBRUNNO_MASK = 0x000000FF
+    };
+
+    enum {
+      RAWHEADER_NWORDS = 12
+    };
+
+    enum {
+      HDR_NWORDS_MASK = 0x000000FF
+    };
+
+    /* Data Format : Fixed length part*/
+    enum {
+      POS_NWORDS = 0,
+      POS_VERSION_HDRNWORDS = 1,
+      POS_EXP_RUN_NO = 2,
+      POS_EVE_NO = 3,
+      POS_TTCTIME_TRGTYPE = 4,
+      POS_TTUTIME = 5,
+      POS_NODE_ID = 6,
+      POS_TRUNC_MASK_DATATYPE = 7,
+      POS_OFFSET_1ST_FINESSE = 8,
+      POS_OFFSET_2ND_FINESSE = 9,
+      POS_OFFSET_3RD_FINESSE = 10,
+      POS_OFFSET_4TH_FINESSE = 11,
+    };
+    /* Data Format : Node info */
+    /*     enum { */
+    /*       NUM_MAX_NODES = 4   /\* (NUM_MAX_NODES + 1) slots are available in m_buffer. */
+    /*          (NUM_MAX_NODES +1 )th slot is filled with -1, when the number of total nodes */
+    /*          exceeds NUM_MAX_NODES *\/ */
+    /*     }; */
+
+    /*     /\* Data Format : Magic word *\/ */
+    /*     enum { */
+    /*       MAGIC_WORD_TERM_HEADER = 0x7fff0005 */
+    /*     }; */
+
+    /* To extract ctime */
+    enum {
+      TTCTIME_MASK = 0x7FFFFFF0,
+      TTCTIME_SHIFT = 4,
+      TRGTYPE_MASK = 0xF
+    };
+
+  private:
+    //! do not record buffer ( RawCOPPER includes buffer of RawHeader_v1 and RawTrailer )
+    int* m_buffer; //! do not record
+
+    /// To derive from TObject
+    // ver.2 Do not record m_buffer pointer. (Dec.19, 2014)
+    //    ClassDef(RawHeader_v1, 1);
+  };
+
+
+  inline void RawHeader_v1::CheckSetBuffer()
+  {
+    if (m_buffer == NULL) {
+      B2FATAL("m_buffer is NULL. Exiting...");
+    }
+  }
+
+  inline void RawHeader_v1::CheckGetBuffer()
+  {
+
+    if (m_buffer == NULL) {
+      B2FATAL("m_buffer is NULL. Data is corrupted or header info has not yet filled. Exiting...");
+//  } else if (m_buffer[ POS_TERM_HEADER ] != MAGIC_WORD_TERM_HEADER) { */
+//    B2FATAL("[DEBUG]  magic word is invalid(0x" << hex() << m_buffer[ POS_TERM_HEADER ] << "). Data is corrupted or header info has not yet filled. Exiting...");
+    }
+
+
+
+  }
+
+  inline void RawHeader_v1::SetNwords(int nwords)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_NWORDS ] = nwords;
+
+  }
+
+  inline void RawHeader_v1::SetEveNo(unsigned int eve_no)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_EVE_NO ] = eve_no;
+  }
+
+  inline void RawHeader_v1::SetNodeID(unsigned int node_id)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_NODE_ID ] = (int)node_id;
+  }
+
+  inline void RawHeader_v1::SetDataType(int data_type)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_TRUNC_MASK_DATATYPE ] =
+      (data_type & 0x7FFFFFFF) | (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x80000000);
+  }
+
+  inline void RawHeader_v1::SetTruncMask(int trunc_mask)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_TRUNC_MASK_DATATYPE ] = (trunc_mask << 31) | (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x7FFFFFFF);
+  }
+
+  /*   inline void RawHeader_v1::SetB2LFEEHdrPart(unsigned int word1, unsigned int word2) */
+  /*   { */
+  /*     m_buffer[ POS_HSLB_1 ] = word1; */
+  /*     m_buffer[ POS_HSLB_2 ] = word2; */
+  /*   } */
+
+
+  inline void RawHeader_v1::SetOffset1stFINESSE(int offset_1st_FINESSE)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_OFFSET_1ST_FINESSE ] = offset_1st_FINESSE;
+  }
+
+  inline void RawHeader_v1::SetOffset2ndFINESSE(int offset_2nd_FINESSE)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_OFFSET_2ND_FINESSE ] = offset_2nd_FINESSE;
+  }
+
+  inline void RawHeader_v1::SetOffset3rdFINESSE(int offset_3rd_FINESSE)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_OFFSET_3RD_FINESSE ] = offset_3rd_FINESSE;
+  }
+
+  inline void RawHeader_v1::SetOffset4thFINESSE(int offset_4th_FINESSE)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_OFFSET_4TH_FINESSE ] = offset_4th_FINESSE;
+  }
+
+  /*   inline void RawHeader_v1::SetFTSW2Words(int* ftsw_buf) */
+  /*   { */
+  /*     CheckSetBuffer(); */
+  /*     memcpy(&(m_buffer[ POS_HSLB_1 ]), (char*)ftsw_buf, sizeof(int) * 2); */
+  /*     return; */
+  /*   } */
+
+  inline void RawHeader_v1::SetFTSW2Words(unsigned int word1,
+                                          unsigned int word2)
+  {
+    CheckSetBuffer();
+    m_buffer[ POS_TTCTIME_TRGTYPE ] = word1;
+    m_buffer[ POS_TTUTIME ] = word2;
+    return;
+  }
+
+
+  inline void RawHeader_v1::SetExpRunNumber(int* exprun_buf)
+  {
+    CheckSetBuffer();
+    memcpy(&(m_buffer[ POS_EXP_RUN_NO ]), (char*)exprun_buf, sizeof(int) * 1);
+    return;
+  }
+
+
+//
+// Obtain info
+//
+
+  inline int RawHeader_v1::GetNwords()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_NWORDS ];
+  }
+
+  inline int RawHeader_v1::GetHdrNwords()
+  {
+
+    //    CheckGetBuffer();
+    //    return m_buffer[ POS_HDR_NWORDS ];
+    return RAWHEADER_NWORDS;
+  }
+
+  inline int RawHeader_v1::GetExpNo()
+  {
+    CheckGetBuffer();
+    return (((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]) & EXP_MASK)
+            >> EXP_SHIFT);
+  }
+
+  inline int RawHeader_v1::GetRunNo()
+  {
+    CheckGetBuffer();
+    return (((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]) & RUNNO_MASK)
+            >> RUNNO_SHIFT);
+  }
+
+  inline int RawHeader_v1::GetSubRunNo()
+  {
+    CheckGetBuffer();
+    return (m_buffer[ POS_EXP_RUN_NO ] & SUBRUNNO_MASK);
+  }
+
+  inline unsigned int RawHeader_v1::GetExpRunSubrun()
+  {
+    CheckGetBuffer();
+    return ((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]));
+  }
+
+
+  inline unsigned int RawHeader_v1::GetEveNo()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_EVE_NO ];
+  }
+
+  inline unsigned int RawHeader_v1::GetNodeID()
+  {
+    CheckGetBuffer();
+    return (unsigned int)m_buffer[ POS_NODE_ID ];
+  }
+
+  inline int RawHeader_v1::GetDataType()
+  {
+    CheckGetBuffer();
+    return (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x7FFFFFFF);
+  }
+
+  inline int RawHeader_v1::GetTruncMask()
+  {
+    CheckGetBuffer();
+    return (m_buffer[ POS_TRUNC_MASK_DATATYPE ] >> 23) & 0x1;
+  }
+
+  inline unsigned int RawHeader_v1::GetErrorBitFlag()
+  {
+    CheckGetBuffer();
+    return (unsigned int)(m_buffer[ POS_TRUNC_MASK_DATATYPE ]);
+  }
+
+  inline void RawHeader_v1::AddErrorBitFlag(unsigned int error_bit_flag)
+  {
+    CheckGetBuffer();
+    m_buffer[ POS_TRUNC_MASK_DATATYPE ] |= (int)error_bit_flag;
+    return;
+  }
+
+  inline int RawHeader_v1::GetOffset1stFINESSE()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_OFFSET_1ST_FINESSE ];
+  }
+
+  inline int RawHeader_v1::GetOffset2ndFINESSE()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_OFFSET_2ND_FINESSE ];
+  }
+
+  inline int RawHeader_v1::GetOffset3rdFINESSE()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_OFFSET_3RD_FINESSE ];
+  }
+
+  inline int RawHeader_v1::GetOffset4thFINESSE()
+  {
+    CheckGetBuffer();
+    return m_buffer[ POS_OFFSET_4TH_FINESSE ];
+  }
+
+  /*   inline int RawHeader_v1::GetNumNodes() */
+  /*   { */
+  /*     CheckGetBuffer(); */
+  /*     return m_buffer[ POS_NUM_NODES ]; */
+  /*   } */
+
+  inline unsigned int RawHeader_v1::GetTTCtimeTRGType()
+  {
+    CheckGetBuffer();
+    return (unsigned int)(m_buffer[ POS_TTCTIME_TRGTYPE ]);
+  }
+
+  inline int RawHeader_v1::GetTTCtime()
+  {
+    CheckGetBuffer();
+    return (int)((GetTTCtimeTRGType() & TTCTIME_MASK) >> TTCTIME_SHIFT);
+  }
+
+  inline int RawHeader_v1::GetTRGType()
+  {
+    CheckGetBuffer();
+    return (int)(GetTTCtimeTRGType() & TRGTYPE_MASK);
+  }
+
+  inline unsigned int RawHeader_v1::GetTTUtime()
+  {
+    CheckGetBuffer();
+    return (unsigned int)(m_buffer[ POS_TTUTIME ]);
+  }
+
+  inline void RawHeader_v1::GetTTTimeVal(struct timeval* tv)
+  {
+    tv->tv_sec = GetTTUtime();
+    tv->tv_usec = (int)(((double)GetTTCtime()) / 127.216);
+    return ;
+  }
+
+
+  /*   inline unsigned int RawHeader_v1::GetMagicWordEntireHeader() */
+  /*   { */
+  /*     CheckGetBuffer(); */
+  /*     return m_buffer[ POS_TERM_HEADER ]; */
+  /*   } */
+
+
+
+
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawKLM.h b/ROPCApplications/rawdata/dataobjects/include/RawKLM.h
new file mode 100644
index 0000000000000000000000000000000000000000..8c88c6430fb2511951476a8e1dd732acdbcf0e56
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawKLM.h
@@ -0,0 +1,39 @@
+//+
+// File : RawCOPPER.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWKLM_H
+#define RAWKLM_H
+
+// Includes
+#include <stdio.h>
+#include <stdlib.h>
+#include <rawdata/dataobjects/RawCOPPER.h>
+#include <framework/datastore/DataStore.h>
+
+#include <TObject.h>
+
+namespace Belle2 {
+
+  /**
+   * The Raw KLM class
+   * Class for RawCOPPER class data taken by KLM.
+   * Currently, this class is almost same as RawCOPPER class.
+   */
+
+  class RawKLM : public RawCOPPER {
+  public:
+    //! Default constructor
+    RawKLM();
+    //! Destructor
+    virtual ~RawKLM();
+    /// To derive from TObject
+    ClassDef(RawKLM, 1);
+  };
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawPXD.h b/ROPCApplications/rawdata/dataobjects/include/RawPXD.h
new file mode 100644
index 0000000000000000000000000000000000000000..fa4277a218b6ba94a8b74b522f933cf3f671e0b5
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawPXD.h
@@ -0,0 +1,68 @@
+//+
+// File : RawPXD.h
+// Description : pseudo raw data of PXD for test
+//
+// Author : Bjoern Spruck / Klemens Lautenbach
+// Date : 13 - Jul - 2013
+// Updated 17.7.2015
+//-
+
+#ifndef RAWPXD_H
+#define RAWPXD_H
+
+#include <TObject.h>
+
+namespace Belle2 {
+
+  /**
+   * The Raw PXD class.
+   *
+   * This class stores the RAW data received from the ONSEN system.
+   * This data is then decoded by the pxdUnpacker module.
+   * For system simulation, pxdPacker writes out in this objects.
+   */
+  class RawPXD : public TObject {
+  public:
+
+    //! Default constructor
+    RawPXD();
+
+    //! Constructor using existing pointer to raw data buffer which needs to be _copied_
+    RawPXD(int*, int);
+
+    //! Constructor using existing data which needs to be _copied_ to a new raw data buffer, only used by PXDPacker
+    RawPXD(const std::vector <unsigned int>& header, const std::vector <std::vector <unsigned char>>& payload);
+
+    //! Destructor
+    virtual ~RawPXD();
+
+    //! get size of buffer in 32 Bit words
+    virtual int size() const;
+    /*at the moment not used
+        //! allocate buffer
+        virtual int* allocate_buffer(int nwords);
+
+        //! set data size in 32 Bit words
+        virtual void data(int nwords, int*);
+    */
+    //! get pointer to data
+    virtual int* data(void);
+
+    /** Return a short summary of this object's contents in HTML format. */
+    std::string getInfoHTML() const;
+
+  private:
+    int m_nwords;/**< Number of (32bit) Words stored in the buffer. There might be unsused bytes in the last word.*/
+    /// Raw dump of ONSEN data. buffer of size m_nwords (32bit int)
+    int* m_buffer; //[m_nwords] /**< Buffer of size m_nwords  */
+
+    //! Endian swap a int32
+    static unsigned int endian_swap(unsigned int x);
+
+    ClassDef(RawPXD, 2)
+  }; // class RawPXD
+
+
+} // end namespace Belle2
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawSVD.h b/ROPCApplications/rawdata/dataobjects/include/RawSVD.h
new file mode 100644
index 0000000000000000000000000000000000000000..477710d1f28c3c2a60a923794d404b1a56c900f7
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawSVD.h
@@ -0,0 +1,38 @@
+//+
+// File : RawCOPPER.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWSVD_H
+#define RAWSVD_H
+
+// Includes
+#include <stdio.h>
+#include <stdlib.h>
+#include <rawdata/dataobjects/RawCOPPER.h>
+#include <framework/datastore/DataStore.h>
+
+#include <TObject.h>
+
+namespace Belle2 {
+
+  /**
+   * The Raw SVD class
+   * Class for RawCOPPER class data taken by SVD
+   * Currently, this class is almost same as RawCOPPER class.
+   */
+  class RawSVD : public RawCOPPER {
+  public:
+    //! Default constructor
+    RawSVD();
+    //! Destructor
+    virtual ~RawSVD();
+    /// To derive from TObject
+    ClassDef(RawSVD, 1);
+  };
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawTLU.h b/ROPCApplications/rawdata/dataobjects/include/RawTLU.h
new file mode 100644
index 0000000000000000000000000000000000000000..d56aed58078127202d7acfa2ed080e708643f1bd
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawTLU.h
@@ -0,0 +1,101 @@
+//+
+// File : RawTLU.h
+// Description : Module to handle raw data from TLU(for the telescope beam test)
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Jan - 2014
+//-
+
+#ifndef RAWTLU_H
+#define RAWTLU_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+
+#include <rawdata/dataobjects/RawDataBlock.h>
+#include <rawdata/dataobjects/RawTLUFormat.h>
+#include <framework/datastore/DataStore.h>
+
+#include <TObject.h>
+
+namespace Belle2 {
+
+  /**
+   * The Raw TLU class
+   * Class for data from DAQ PC for TLU(Trigger Logic Unit)
+   * It is supposed to be used only in the DESY beam test
+   */
+
+  class RawTLU : public RawDataBlock {
+  public:
+    //! Default constructor
+    RawTLU();
+
+    //! Destructor
+    virtual ~RawTLU();
+
+    /*     //! Get # of words in this data packet */
+    /*     int GetNwords(int n); */
+
+    //!Get the size of the header
+    int GetNwordsHeader(int n)
+    {
+      m_access->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access->GetNwordsHeader(n);
+    }
+
+    //! Get Node ID
+    unsigned int GetNodeID(int n)
+    {
+      m_access->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access->GetNodeID(n);
+    }
+
+    //! Get Event #
+    unsigned int GetEveNo(int n)
+    {
+      m_access->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access->GetEveNo(n);
+    }
+
+    //! Get Magic Trailer #
+    unsigned int GetMagicTrailer(int n)
+    {
+      m_access->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access->GetMagicTrailer(n);
+    }
+
+    //! Get Run #
+    int GetRunNo(int n)
+    {
+      m_access->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access->GetRunNo(n);
+    }
+
+    //! Get TLU event tag
+    unsigned int GetTLUEventTag(int n)
+    {
+      m_access->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access->GetTLUEventTag(n);
+    }
+
+    //! check data contents
+    void CheckData(int n, unsigned int prev_evenum, unsigned int* cur_evenum)
+    {
+      m_access->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+      return m_access->CheckData(n, prev_evenum, cur_evenum);
+    }
+
+    //! class to access
+    RawTLUFormat* m_access; //! do not record
+
+  protected :
+
+    /// To derive from TObject
+    ClassDef(RawTLU, 1);
+
+  };
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawTLUFormat.h b/ROPCApplications/rawdata/dataobjects/include/RawTLUFormat.h
new file mode 100644
index 0000000000000000000000000000000000000000..cb399840f77c34345dd02098a3eef5d76b8a2b50
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawTLUFormat.h
@@ -0,0 +1,83 @@
+//+
+// File : RawTLUFormat.h
+// Description : Module to handle raw data from TLU(for the telescope beam test)
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Jan - 2014
+//-
+
+#ifndef RAWTLUFORMAT_H
+#define RAWTLUFORMAT_H
+#include <rawdata/dataobjects/RawDataBlockFormat.h>
+
+namespace Belle2 {
+
+  /**
+   * The Raw TLU class
+   * Class for data from DAQ PC for TLU(Trigger Logic Unit)
+   * It is supposed to be used only in the DESY beam test
+   */
+
+  class RawTLUFormat : public RawDataBlockFormat {
+  public:
+    //! Default constructor
+    RawTLUFormat();
+
+    //! Destructor
+    virtual ~RawTLUFormat();
+
+    /*     //! Get # of words in this data packet */
+    /*     int GetNwords(int n); */
+
+    //!Get the size of the header
+    int GetNwordsHeader(int n);
+
+    //! Get Node ID
+    unsigned int GetNodeID(int n);
+
+    //! Get Event #
+    unsigned int GetEveNo(int n);
+
+    //! Get Magic Trailer #
+    unsigned int GetMagicTrailer(int n);
+
+    //! Get Run #
+    int GetRunNo(int n);
+
+    //! Get TLU event tag
+    unsigned int GetTLUEventTag(int n);
+
+    //! check data contents
+    void CheckData(int n, unsigned int prev_evenum, unsigned int* cur_evenum);
+
+
+    enum {
+      POS_NWORDS = 0,
+      POS_HDR_NWORDS = 1,
+      POS_NUMEVE_NUMNODES = 2,
+      POS_RUN_NO = 3,
+      POS_EVE_NO = 4,
+      POS_NA_1 = 5,
+      POS_NODE_ID = 6,
+      POS_NA_2 = 7,
+      POS_TLU_EVENTTAG = 8,
+      POS_NA_3 = 9,
+      POS_TLU_TIME_1 = 10,
+      POS_TLU_TIME_2 = 11,
+      POS_RSVD_1 = 12,
+      POS_MAGIC_1 = 13
+    };
+
+    enum {
+      SIZE_TLU_PACKET = 14
+    };
+
+    enum {
+      TLU_MAGIC_TRAILER = 0x7FFF0000
+    };
+
+  protected :
+  };
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawTOP.h b/ROPCApplications/rawdata/dataobjects/include/RawTOP.h
new file mode 100644
index 0000000000000000000000000000000000000000..d07d8b11725f0c72ba0f3d9cb05abfff761c4274
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawTOP.h
@@ -0,0 +1,41 @@
+//+
+// File : RawCOPPER.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWTOP_H
+#define RAWTOP_H
+
+// Includes
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <rawdata/dataobjects/RawCOPPER.h>
+#include <framework/datastore/DataStore.h>
+
+#include <TObject.h>
+
+namespace Belle2 {
+
+  /**
+   * The Raw TOP class
+   * Class for RawCOPPER class data taken by TOP
+   * Currently, this class is almost same as RawCOPPER class.
+   */
+
+  class RawTOP : public RawCOPPER {
+  public:
+    //! Default constructor
+    RawTOP();
+    //! Destructor
+    virtual ~RawTOP();
+
+    /// To derive from TObject
+    ClassDef(RawTOP, 1);
+  };
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawTRG.h b/ROPCApplications/rawdata/dataobjects/include/RawTRG.h
new file mode 100644
index 0000000000000000000000000000000000000000..795b3c125657148b53ff562db46ed7ec3ede202c
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawTRG.h
@@ -0,0 +1,41 @@
+//+
+// File : RawTRG.h
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWTRG_H
+#define RAWTRG_H
+
+// Includes
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <rawdata/dataobjects/RawCOPPER.h>
+#include <framework/datastore/DataStore.h>
+
+#include <TObject.h>
+
+namespace Belle2 {
+
+  /**
+   * The Raw TOP class
+   * Class for RawCOPPER class data taken by TOP
+   * Currently, this class is almost same as RawCOPPER class.
+   */
+
+  class RawTRG : public RawCOPPER {
+  public:
+    //! Default constructor
+    RawTRG();
+    //! Destructor
+    virtual ~RawTRG();
+
+    /// To derive from TObject
+    ClassDef(RawTRG, 1);
+  };
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawTrailer_latest.h b/ROPCApplications/rawdata/dataobjects/include/RawTrailer_latest.h
new file mode 100644
index 0000000000000000000000000000000000000000..0c7456c15d745a0ec2c13d80e0b9653aa1088cd0
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawTrailer_latest.h
@@ -0,0 +1,140 @@
+//+
+// File : RawTrailer_latest.cc
+// Description : Module to handle RawTraeiler attached to raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWTRAILER_LATEST_H
+#define RAWTRAILER_LATEST_H
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+/* #include <framework/datastore/DataStore.h> */
+/* #include <TObject.h> */
+#include <rawdata/switch_basf2_standalone.h>
+
+//#define TRAILER_SIZE 16
+/* #define   POS_CHKSUM 0 */
+/* #define        POS_TERM_WORD 1 */
+/* #define        RAWCOPPER_TRAILER_SIZE 2 */
+/* #define        MAGIC_WORD_TERM_TRAILER 0x7fff0006 */
+
+namespace Belle2 {
+
+  /**
+   * The Raw Trailer class ver.1 ( the latest version since May, 2014 )
+   * This class defines the format of the trailer of RawCOPPER class data
+   * and used for extracting trailer info from RawCOPPER object
+   */
+  //  class RawTrailer_latest : public TObject {
+  class RawTrailer_latest {
+  public:
+    //! Default constructor
+    RawTrailer_latest();
+
+    //! Destructor
+    ~RawTrailer_latest();
+
+    //! set buffer
+    void CheckBuffer(); //! set buffer
+
+    int* GetBuffer(); //! return buffer
+
+    void SetBuffer(int* bufin); //! set buffer
+
+    void Initialize(); //! set buffer
+
+    void SetChksum(int chksum);   //! initialize header
+
+    void SetMagicWord(); //! Set magic word
+
+    int GetTrlNwords(); //! Set # of trailer words
+
+    unsigned int GetChksum();   //! initialize header
+
+    int GetMagicWord(); //! Get magic word
+
+    enum {
+      RAWTRAILER_NWORDS = 2
+    };
+
+    enum {
+      MAGIC_WORD_TERM_TRAILER = 0x7fff0006
+    };
+
+    enum {
+      POS_CHKSUM = 0,
+      POS_TERM_WORD = 1
+    };
+
+  private:
+    //! do not record buffer ( RawCOPPER includes buffer of RawHeader and RawTrailer_latest )
+    int* m_buffer; //! do not record
+
+    /// To derive from TObject
+    // ver.2 Do not record m_buffer pointer. (Dec.19, 2014)
+    //    ClassDef(RawTrailer_latest, 1);
+  };
+
+
+  inline void RawTrailer_latest::CheckBuffer()
+  {
+    if (m_buffer == NULL) {
+      B2FATAL("m_buffer is NULL. Exiting...");
+    }
+  }
+
+  inline int* RawTrailer_latest::GetBuffer()
+  {
+    return m_buffer;
+  }
+
+  inline void RawTrailer_latest::SetBuffer(int* bufin)
+  {
+    m_buffer = bufin;
+  }
+
+  inline void RawTrailer_latest::Initialize()
+  {
+    SetMagicWord();
+  }
+
+  inline void RawTrailer_latest::SetChksum(int chksum)
+  {
+    CheckBuffer();
+    m_buffer[ POS_CHKSUM ] = chksum;
+  }
+
+  inline void RawTrailer_latest::SetMagicWord()
+  {
+    CheckBuffer();
+    m_buffer[ POS_TERM_WORD ] = MAGIC_WORD_TERM_TRAILER;
+  }
+
+  inline int RawTrailer_latest::GetMagicWord()
+  {
+    CheckBuffer();
+    return m_buffer[ POS_TERM_WORD ];
+  }
+
+  inline unsigned int RawTrailer_latest::GetChksum()
+  {
+    CheckBuffer();
+    return (unsigned int)(m_buffer[ POS_CHKSUM ]);
+  }
+
+  inline int RawTrailer_latest::GetTrlNwords()
+  {
+    return RAWTRAILER_NWORDS;
+  }
+
+
+
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawTrailer_v0.h b/ROPCApplications/rawdata/dataobjects/include/RawTrailer_v0.h
new file mode 100644
index 0000000000000000000000000000000000000000..c5ce476fa7f42845aa8d3325064a640206d11f50
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawTrailer_v0.h
@@ -0,0 +1,137 @@
+//+
+// File : RawTrailer_v0.cc
+// Description : Module to handle RawTraeiler attached to raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWTRAILER_V0_H
+#define RAWTRAILER_V0_H
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <rawdata/switch_basf2_standalone.h>
+
+/* #include <framework/datastore/DataStore.h> */
+/* #include <TObject.h> */
+
+//#define TRAILER_SIZE 16
+/* #define   POS_CHKSUM 0 */
+/* #define        POS_TERM_WORD 1 */
+/* #define        RAWCOPPER_TRAILER_SIZE 2 */
+/* #define        MAGIC_WORD_TERM_TRAILER 0x7fff0006 */
+
+namespace Belle2 {
+
+  /**
+   * The Raw Trailer class ver.0 ( from August, 2013 to April, 2014 )
+   * This class defines the format of the trailer of RawCOPPER class data
+   * and used for extracting trailer info from RawCOPPER object
+   */
+  //  class RawTrailer_v0 : public TObject {
+  class RawTrailer_v0  {
+  public:
+    RawTrailer_v0();     /// Default constructor
+
+    ~RawTrailer_v0();     /// Destructor
+
+    void CheckBuffer(); //! set buffer
+
+    int* GetBuffer(); //! return buffer
+
+    void SetBuffer(int* bufin); //! set buffer
+
+    void Initialize(); //! set buffer
+
+    void SetChksum(int chksum);   //! initialize header
+
+    void SetMagicWord(); //! Set magic word
+
+    int GetTrlNwords(); //! Set # of trailer words
+
+    unsigned int GetChksum();   //! initialize header
+
+    int GetMagicWord(); //! Get magic word
+
+    enum {
+      RAWTRAILER_NWORDS = 2
+    };
+
+    enum {
+      MAGIC_WORD_TERM_TRAILER = 0x7fff0006
+    };
+
+    enum {
+      POS_CHKSUM = 0,
+      POS_TERM_WORD = 1
+    };
+
+  private:
+    //! do not record buffer ( RawCOPPER includes buffer of RawHeader and RawTrailer_v0 )
+    int* m_buffer; //! do not record
+
+    /// To derive from TObject
+    // ver.2 Do not record m_buffer pointer. (Dec.19, 2014)
+    //    ClassDef(RawTrailer_v0, 2);
+  };
+
+
+  inline void RawTrailer_v0::CheckBuffer()
+  {
+    if (m_buffer == NULL) {
+      B2FATAL("m_buffer is NULL. Exiting...");
+    }
+  }
+
+  inline int* RawTrailer_v0::GetBuffer()
+  {
+    return m_buffer;
+  }
+
+  inline void RawTrailer_v0::SetBuffer(int* bufin)
+  {
+    m_buffer = bufin;
+  }
+
+  inline void RawTrailer_v0::Initialize()
+  {
+    SetMagicWord();
+  }
+
+  inline void RawTrailer_v0::SetChksum(int chksum)
+  {
+    CheckBuffer();
+    m_buffer[ POS_CHKSUM ] = chksum;
+  }
+
+  inline void RawTrailer_v0::SetMagicWord()
+  {
+    CheckBuffer();
+    m_buffer[ POS_TERM_WORD ] = MAGIC_WORD_TERM_TRAILER;
+  }
+
+  inline int RawTrailer_v0::GetMagicWord()
+  {
+    CheckBuffer();
+    return m_buffer[ POS_TERM_WORD ];
+  }
+
+  inline unsigned int RawTrailer_v0::GetChksum()
+  {
+    CheckBuffer();
+    return (unsigned int)(m_buffer[ POS_CHKSUM ]);
+  }
+
+  inline int RawTrailer_v0::GetTrlNwords()
+  {
+    return RAWTRAILER_NWORDS;
+  }
+
+
+
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/RawTrailer_v1.h b/ROPCApplications/rawdata/dataobjects/include/RawTrailer_v1.h
new file mode 100644
index 0000000000000000000000000000000000000000..f9d31ff1569b478713dda705ea9b1f5b64532e2d
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/RawTrailer_v1.h
@@ -0,0 +1,140 @@
+//+
+// File : RawTrailer_v1.cc
+// Description : Module to handle RawTraeiler attached to raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#ifndef RAWTRAILER_V1_H
+#define RAWTRAILER_V1_H
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <rawdata/switch_basf2_standalone.h>
+
+/* #include <framework/datastore/DataStore.h> */
+/* #include <TObject.h> */
+
+//#define TRAILER_SIZE 16
+/* #define   POS_CHKSUM 0 */
+/* #define        POS_TERM_WORD 1 */
+/* #define        RAWCOPPER_TRAILER_SIZE 2 */
+/* #define        MAGIC_WORD_TERM_TRAILER 0x7fff0006 */
+
+namespace Belle2 {
+
+  /**
+   * The Raw Trailer class ver.1 ( the latest version since May, 2014 )
+   * This class defines the format of the trailer of RawCOPPER class data
+   * and used for extracting trailer info from RawCOPPER object
+   */
+  //  class RawTrailer_v1 : public TObject {
+  class RawTrailer_v1  {
+  public:
+    //! Default constructor
+    RawTrailer_v1();
+
+    //! Destructor
+    ~RawTrailer_v1();
+
+    //! set buffer
+    void CheckBuffer(); //! set buffer
+
+    int* GetBuffer(); //! return buffer
+
+    void SetBuffer(int* bufin); //! set buffer
+
+    void Initialize(); //! set buffer
+
+    void SetChksum(int chksum);   //! initialize header
+
+    void SetMagicWord(); //! Set magic word
+
+    int GetTrlNwords(); //! Set # of trailer words
+
+    unsigned int GetChksum();   //! initialize header
+
+    int GetMagicWord(); //! Get magic word
+
+    enum {
+      RAWTRAILER_NWORDS = 2
+    };
+
+    enum {
+      MAGIC_WORD_TERM_TRAILER = 0x7fff0006
+    };
+
+    enum {
+      POS_CHKSUM = 0,
+      POS_TERM_WORD = 1
+    };
+
+  private:
+    //! do not record buffer ( RawCOPPER includes buffer of RawHeader and RawTrailer_v1 )
+    int* m_buffer; //! do not record
+
+    /// To derive from TObject
+    // ver.2 Do not record m_buffer pointer. (Dec.19, 2014)
+    //    ClassDef(RawTrailer_v1, 1);
+  };
+
+
+  inline void RawTrailer_v1::CheckBuffer()
+  {
+    if (m_buffer == NULL) {
+      B2FATAL("m_buffer is NULL. Exiting...");
+    }
+  }
+
+  inline int* RawTrailer_v1::GetBuffer()
+  {
+    return m_buffer;
+  }
+
+  inline void RawTrailer_v1::SetBuffer(int* bufin)
+  {
+    m_buffer = bufin;
+  }
+
+  inline void RawTrailer_v1::Initialize()
+  {
+    SetMagicWord();
+  }
+
+  inline void RawTrailer_v1::SetChksum(int chksum)
+  {
+    CheckBuffer();
+    m_buffer[ POS_CHKSUM ] = chksum;
+  }
+
+  inline void RawTrailer_v1::SetMagicWord()
+  {
+    CheckBuffer();
+    m_buffer[ POS_TERM_WORD ] = MAGIC_WORD_TERM_TRAILER;
+  }
+
+  inline int RawTrailer_v1::GetMagicWord()
+  {
+    CheckBuffer();
+    return m_buffer[ POS_TERM_WORD ];
+  }
+
+  inline unsigned int RawTrailer_v1::GetChksum()
+  {
+    CheckBuffer();
+    return (unsigned int)(m_buffer[ POS_CHKSUM ]);
+  }
+
+  inline int RawTrailer_v1::GetTrlNwords()
+  {
+    return RAWTRAILER_NWORDS;
+  }
+
+
+
+
+}
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/include/linkdef.h b/ROPCApplications/rawdata/dataobjects/include/linkdef.h
new file mode 100644
index 0000000000000000000000000000000000000000..222cce688e3d5ec50d973333dd4556b2dee1a72e
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/include/linkdef.h
@@ -0,0 +1,36 @@
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+#pragma link C++ nestedclasses;
+
+#pragma link C++ class Belle2::RawCOPPERFormat+;
+#pragma link C++ class Belle2::RawCOPPERFormat_v0+;
+#pragma link C++ class Belle2::RawCOPPERFormat_v1+;
+#pragma link C++ class Belle2::RawCOPPERFormat_latest+;
+#pragma link C++ class Belle2::PreRawCOPPERFormat_v1+;
+#pragma link C++ class Belle2::PreRawCOPPERFormat_latest+;
+#pragma link C++ class Belle2::PostRawCOPPERFormat_v1+;
+#pragma link C++ class Belle2::PostRawCOPPERFormat_latest+;
+#pragma link C++ class Belle2::RawHeader_v0+;
+#pragma link C++ class Belle2::RawHeader_v1+;
+#pragma link C++ class Belle2::RawHeader_latest+;
+#pragma link C++ class Belle2::RawTrailer_v0+;
+#pragma link C++ class Belle2::RawTrailer_v1+;
+#pragma link C++ class Belle2::RawTrailer_latest+;
+
+#pragma link C++ class Belle2::RawDataBlock+;
+#pragma link C++ class Belle2::RawCOPPER+;
+#pragma link C++ class Belle2::RawCDC+;
+#pragma link C++ class Belle2::RawSVD+;
+#pragma link C++ class Belle2::RawECL+;
+#pragma link C++ class Belle2::RawTOP+;
+#pragma link C++ class Belle2::RawARICH+;
+#pragma link C++ class Belle2::RawKLM+;
+#pragma link C++ class Belle2::RawFTSW+;
+#pragma link C++ class Belle2::RawTLU+;
+#pragma link C++ class Belle2::RawPXD+;
+#pragma link C++ class Belle2::RawTRG+;
+
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/src/PostRawCOPPERFormat_latest.cc b/ROPCApplications/rawdata/dataobjects/src/PostRawCOPPERFormat_latest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0362bc83488a4177ebbc7b13e8374f7c00a8756a
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/PostRawCOPPERFormat_latest.cc
@@ -0,0 +1,416 @@
+//+
+// File : RawCOPPERFormat_latest.cc
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/PostRawCOPPERFormat_latest.h>
+
+
+using namespace std;
+using namespace Belle2;
+
+//#define DESY
+//#define NO_ERROR_STOP
+//ClassImp(PostRawCOPPERFormat_latest);
+
+PostRawCOPPERFormat_latest::PostRawCOPPERFormat_latest()
+{
+}
+
+PostRawCOPPERFormat_latest::~PostRawCOPPERFormat_latest()
+{
+}
+
+
+int PostRawCOPPERFormat_latest::GetDetectorNwords(int n, int finesse_num)
+{
+  int nwords = 0;
+  if (GetFINESSENwords(n, finesse_num) > 0) {
+    nwords = GetFINESSENwords(n, finesse_num)
+             - (SIZE_B2LHSLB_HEADER + SIZE_B2LHSLB_TRAILER +  SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER);
+  }
+  return nwords;
+}
+
+
+unsigned int PostRawCOPPERFormat_latest::CalcDriverChkSum(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
+          n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("[DEBUG] %s\n", err_buf);
+  B2FATAL(err_buf);
+  return 0;
+}
+
+
+int PostRawCOPPERFormat_latest::GetFINESSENwords(int n, int finesse_num)
+{
+  int pos_nwords_0, pos_nwords_1;
+  int nwords;
+  switch (finesse_num) {
+    case 0 :
+      pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_1ST_FINESSE;
+      pos_nwords_1 = GetBufferPos(n) + tmp_header.POS_OFFSET_2ND_FINESSE;
+      nwords = m_buffer[ pos_nwords_1 ] - m_buffer[ pos_nwords_0 ];
+      break;
+    case 1 :
+      pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_2ND_FINESSE;
+      pos_nwords_1 = GetBufferPos(n) + tmp_header.POS_OFFSET_3RD_FINESSE;
+      nwords = m_buffer[ pos_nwords_1 ] - m_buffer[ pos_nwords_0 ];
+      break;
+    case 2 :
+      pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_3RD_FINESSE;
+      pos_nwords_1 = GetBufferPos(n) + tmp_header.POS_OFFSET_4TH_FINESSE;
+      nwords = m_buffer[ pos_nwords_1 ] - m_buffer[ pos_nwords_0 ];
+      break;
+    case 3 :
+      pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_4TH_FINESSE;
+      {
+        int nwords_1 = GetBlockNwords(n)
+                       - SIZE_COPPER_DRIVER_TRAILER
+                       - tmp_trailer.GetTrlNwords();
+        nwords = nwords_1 - m_buffer[ pos_nwords_0 ];
+      }
+      break;
+    default :
+      char err_buf[500];
+      sprintf(err_buf, "[FATAL] Invalid finesse # : %s %s %d\n",
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("[DEBUG] %s\n", err_buf);
+      B2FATAL(err_buf);
+  }
+
+  if (nwords < 0 || nwords > 1e6) {
+    char err_buf[500];
+    sprintf(err_buf, "[FATAL] ERROR_EVENT : # of words is strange. %d : eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
+            nwords,
+            GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("[DEBUG] %s\n", err_buf);
+    B2FATAL(err_buf);
+  }
+
+  return nwords;
+
+}
+
+
+
+
+unsigned int PostRawCOPPERFormat_latest::GetB2LFEE32bitEventNumber(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf,
+          "[FATAL] ERROR_EVENT : No event # in B2LFEE header. (block %d) Exiting... : eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
+          n,
+          GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("[DEBUG] %s\n", err_buf);
+  B2FATAL(err_buf);
+  return 0;
+}
+
+
+
+void PostRawCOPPERFormat_latest::CheckData(int n,
+                                           unsigned int prev_evenum, unsigned int* cur_evenum_rawcprhdr,
+                                           unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
+                                           unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+{
+  char err_buf[500];
+  int err_flag = 0;
+
+  //
+  // Check incrementation of event #
+  //
+  *cur_evenum_rawcprhdr = GetEveNo(n);
+  *cur_exprunsubrun_no = GetExpRunSubrun(n);
+
+  if (prev_exprunsubrun_no == *cur_exprunsubrun_no) {
+    if ((unsigned int)(prev_evenum + 1) != *cur_evenum_rawcprhdr) {
+      sprintf(err_buf, "CORRUPTED DATA: Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n%s %s %d\n",
+              n, prev_evenum, *cur_evenum_rawcprhdr,
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      err_flag = 1;
+    }
+  }
+
+
+  //
+  // Check checksum calculated by DeSerializerCOPPER()
+  //
+  tmp_trailer.SetBuffer(GetRawTrlBufPtr(n));
+  unsigned int xor_chksum = CalcXORChecksum(GetBuffer(n), GetBlockNwords(n) - tmp_trailer.GetTrlNwords());
+  if (tmp_trailer.GetChksum() != xor_chksum) {
+    sprintf(err_buf,
+            "[FATAL] ERROR_EVENT : checksum error : block %d : length %d eve 0x%x : Trailer chksum 0x%.8x : calcd. now 0x%.8x : eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
+            n, GetBlockNwords(n), *cur_evenum_rawcprhdr, tmp_trailer.GetChksum(), xor_chksum,
+            GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    err_flag = 1;
+  }
+
+
+  if (err_flag == 1) {
+    printf("[DEBUG] %s\n", err_buf);
+    printf("[DEBUG] ========== dump a data blcok : block # %d==========\n", n);
+    PrintData(GetBuffer(n), GetBlockNwords(n));
+    printf("Print out variables to reduce unused-variables-warnings : %u %u\n", prev_copper_ctr, *cur_copper_ctr);
+    B2FATAL(err_buf);
+  }
+
+  return;
+
+}
+
+bool PostRawCOPPERFormat_latest::CheckCOPPERMagic(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf,
+          "[FATAL] ERROR_EVENT : No magic word # in COPPER header (block %d). Exiting...: eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
+          n,
+          GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("[DEBUG] %s\n", err_buf);
+  B2FATAL(err_buf);
+  return false;
+}
+
+void PostRawCOPPERFormat_latest::CheckUtimeCtimeTRGType(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf, "[FATAL] This function is not supported (block %d). Exiting...\n%s %s %d\n",
+          n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("[DEBUG] %s\n", err_buf);
+  B2FATAL(err_buf);
+}
+
+unsigned int PostRawCOPPERFormat_latest::FillTopBlockRawHeader(unsigned int m_node_id, unsigned int prev_eve32,
+    unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+
+{
+  char err_buf[500];
+  sprintf(err_buf, "[FATAL] This function should be called by PrePostRawCOPPERFormat_***. Exiting...\n %s %s %d\n",
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("Print out variables to reduce unused-variables-warnings : %u %u %u %u\n",
+         m_node_id,  prev_eve32, prev_exprunsubrun_no, *cur_exprunsubrun_no);
+  printf("[DEBUG] %s\n", err_buf);
+  B2FATAL(err_buf);
+}
+
+
+int PostRawCOPPERFormat_latest::CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords)
+{
+  char err_buf[500];
+  sprintf(err_buf, "[FATAL] This function should be called by PrePostRawCOPPERFormat_***. Exiting...\n %s %s %d\n",
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("Print out variables to reduce unused-variables-warnings : %p %d\n", finesse_buf, finesse_nwords);
+  printf("[DEBUG] %s\n", err_buf);
+  B2FATAL(err_buf);
+}
+
+int PostRawCOPPERFormat_latest::CheckCRC16(int n, int finesse_num)
+{
+
+  //
+  // Calculate CRC16
+  //
+  int finesse_nwords = GetFINESSENwords(n, finesse_num);
+  if (finesse_nwords <= 0) {
+    char err_buf[500];
+    sprintf(err_buf,
+            "[FATAL] ERROR_EVENT : The specified finesse(%c) seems to be empty(nwords = %d). Cannot calculate CRC16. Exiting...: eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
+            65 + finesse_num, finesse_nwords,
+            GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  int* copper_buf = GetBuffer(n);
+
+
+  unsigned short temp_crc16 = CalcCRC16LittleEndian(0xffff, &(copper_buf[ tmp_header.POS_TTCTIME_TRGTYPE ]), 1);
+  temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(copper_buf[ tmp_header.POS_EVE_NO ]), 1);
+  temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(copper_buf[ tmp_header.POS_TTUTIME ]), 1);
+  temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(copper_buf[ tmp_header.POS_EXP_RUN_NO ]), 1);
+  int* buf = GetFINESSEBuffer(n, finesse_num) +  SIZE_B2LHSLB_HEADER + POS_B2L_CTIME;
+  int pos_nwords = finesse_nwords - (SIZE_B2LHSLB_HEADER + POS_B2L_CTIME + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER);
+  temp_crc16 = CalcCRC16LittleEndian(temp_crc16, buf, pos_nwords);
+
+  //
+  // Compare CRC16 with B2LCRC16
+  //
+  buf = GetFINESSEBuffer(n, finesse_num) +  GetFINESSENwords(n,
+                                                             finesse_num) - ((SIZE_B2LFEE_TRAILER - POS_B2LFEE_ERRCNT_CRC16) + SIZE_B2LHSLB_TRAILER) ;
+
+  if (GetEveNo(n) % 100000 == 0) {
+    printf("#### PostRawCOPPER : Eve %.8x block %d finesse %d B2LCRC16 %.8x calculated CRC16 %.8x\n", GetEveNo(n), n, finesse_num,
+           *buf, temp_crc16);
+  }
+
+  //  if ( false ) {
+  if ((unsigned short)(*buf & 0xFFFF) != temp_crc16) {
+
+    // dump an event
+    int copper_nwords = copper_buf[ tmp_header.POS_NWORDS ];
+    PrintData(copper_buf, copper_nwords);
+    // Check whether packet-CRC error has occcured or not.
+    if (copper_buf[ tmp_header.POS_TRUNC_MASK_DATATYPE ] & tmp_header.B2LINK_PACKET_CRC_ERROR) {
+      //
+      // Do not stop data
+      //
+      char err_buf[500];
+      sprintf(err_buf,
+              "[FATAL] POST B2link event CRC16 error with B2link Packet CRC error. data(%x) calc(%x) fns nwords %d type 0x%.8x : slot%c eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
+              *buf , temp_crc16, GetFINESSENwords(n, finesse_num), copper_buf[ tmp_header.POS_TRUNC_MASK_DATATYPE ],
+              65 + finesse_num, GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      PrintData(GetFINESSEBuffer(n, finesse_num), GetFINESSENwords(n, finesse_num));
+#ifndef NO_ERROR_STOP
+      B2FATAL(err_buf);
+#endif
+    } else {
+      //
+      // Stop taking data
+      //
+      char err_buf[500];
+      sprintf(err_buf,
+              "[FATAL] ERROR_EVENT : POST B2link event CRC16 error without B2link Packet CRC error. data(%x) calc(%x) fns nwords %d type 0x%.8x: slot%c eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
+              *buf , temp_crc16, GetFINESSENwords(n, finesse_num), copper_buf[ tmp_header.POS_TRUNC_MASK_DATATYPE ],
+              65 + finesse_num, GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      PrintData(GetFINESSEBuffer(n, finesse_num), GetFINESSENwords(n, finesse_num));
+#ifndef NO_ERROR_STOP
+      B2FATAL(err_buf);
+#endif
+    }
+    // Modify XOR checksum due to adding a bit flag
+    copper_buf[ copper_nwords - tmp_trailer.RAWTRAILER_NWORDS + tmp_trailer.POS_CHKSUM ]
+    ^= copper_buf[ tmp_header.POS_TRUNC_MASK_DATATYPE ];
+    copper_buf[ tmp_header.POS_TRUNC_MASK_DATATYPE ] |= tmp_header.B2LINK_EVENT_CRC_ERROR;
+    copper_buf[ copper_nwords - tmp_trailer.RAWTRAILER_NWORDS + tmp_trailer.POS_CHKSUM ]
+    ^= copper_buf[ tmp_header.POS_TRUNC_MASK_DATATYPE ];
+  }
+
+  return 1;
+
+
+}
+
+
+int* PostRawCOPPERFormat_latest::PackDetectorBuf(int* packed_buf_nwords,
+                                                 int* detector_buf_1st,  int nwords_1st,
+                                                 int* detector_buf_2nd,  int nwords_2nd,
+                                                 int* detector_buf_3rd,  int nwords_3rd,
+                                                 int* detector_buf_4th,  int nwords_4th,
+                                                 RawCOPPERPackerInfo rawcpr_info)
+{
+  int* packed_buf = NULL;
+
+  int poswords_to = 0;
+  int* detector_buf[ 4 ] = { detector_buf_1st, detector_buf_2nd, detector_buf_3rd, detector_buf_4th };
+  int nwords[ 4 ] = { nwords_1st, nwords_2nd, nwords_3rd, nwords_4th };
+
+  // calculate the event length
+  int length_nwords = tmp_header.GetHdrNwords() + SIZE_COPPER_HEADER + SIZE_COPPER_TRAILER + tmp_trailer.GetTrlNwords();
+
+  for (int i = 0; i < 4; i++) {
+    if (detector_buf[ i ] == NULL || nwords[ i ] <= 0) continue;    // for an empty FINESSE slot
+    length_nwords += nwords[ i ];
+    length_nwords += SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER
+                     + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
+  }
+
+  // allocate buffer
+  packed_buf = new int[ length_nwords ];
+  memset(packed_buf, 0, sizeof(int) * length_nwords);
+
+  //
+  // Fill RawHeader
+  //
+  tmp_header.SetBuffer(packed_buf);
+
+  packed_buf[ tmp_header.POS_NWORDS ] = length_nwords; // total length
+  packed_buf[ tmp_header.POS_VERSION_HDRNWORDS ] =
+    0x7f7f0000
+    | ((DATA_FORMAT_VERSION << tmp_header.FORMAT_VERSION_SHIFT) & tmp_header.FORMAT_VERSION__MASK)
+    | tmp_header.RAWHEADER_NWORDS; // ver.#, header length
+  packed_buf[ tmp_header.POS_EXP_RUN_NO ] = (rawcpr_info.exp_num << 22)
+                                            | (rawcpr_info.run_subrun_num & 0x003FFFFF);   // exp. and run #
+  packed_buf[ tmp_header.POS_EVE_NO ] = rawcpr_info.eve_num; // eve #
+  packed_buf[ tmp_header.POS_TTCTIME_TRGTYPE ] = (rawcpr_info.tt_ctime & 0x7FFFFFF) << 4;   // tt_ctime
+  packed_buf[ tmp_header.POS_TTUTIME ] = rawcpr_info.tt_utime; // tt_utime
+  packed_buf[ tmp_header.POS_NODE_ID ] = rawcpr_info.node_id; // node ID
+
+  // fill the positions of finesse buffers
+  packed_buf[ tmp_header.POS_OFFSET_1ST_FINESSE ] = tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
+
+  packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_1ST_FINESSE ];
+  if (nwords[ 0 ] > 0) {
+    packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ] +=
+      nwords[ 0 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER  + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
+  }
+
+  packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ];
+  if (nwords[ 1 ] > 0) {
+    packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ] +=
+      nwords[ 1 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER  + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
+  }
+
+  packed_buf[ tmp_header.POS_OFFSET_4TH_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ];
+  if (nwords[ 2 ] > 0) {
+    packed_buf[ tmp_header.POS_OFFSET_4TH_FINESSE ] += nwords[ 2 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER  + SIZE_B2LFEE_TRAILER +
+                                                       SIZE_B2LHSLB_TRAILER;
+  }
+  poswords_to += tmp_header.GetHdrNwords();
+
+  // Fill COPPER header
+  poswords_to += SIZE_COPPER_HEADER;
+
+  // Fill FINESSE buffer
+  for (int i = 0; i < 4; i++) {
+
+    if (detector_buf[ i ] == NULL || nwords[ i ] <= 0) continue;     // for an empty FINESSE slot
+
+    // Fill b2link HSLB header
+    packed_buf[ poswords_to + POS_B2LHSLB_MAGIC ] = 0xffaa0000 | (0xffff & rawcpr_info.eve_num);
+    poswords_to += SIZE_B2LHSLB_HEADER;
+
+    // Fill b2link FEE header
+    packed_buf[ poswords_to + POS_B2L_CTIME ] = (rawcpr_info.b2l_ctime & 0x7FFFFFF) << 4;
+    poswords_to += SIZE_B2LFEE_HEADER;
+
+    // copy the 1st Detector Buffer
+    memcpy(packed_buf + poswords_to, detector_buf[ i ], nwords[ i ]*sizeof(int));
+    poswords_to += nwords[ i ];
+
+    // Fill b2link FEE trailer
+    unsigned int crc16 = 0;
+    packed_buf[ poswords_to + POS_B2LFEE_ERRCNT_CRC16 ] =  crc16 &
+                                                           0xffff; // Error count is stored in this buffer for ver.2 format but it is set to zero here.
+    poswords_to += SIZE_B2LFEE_TRAILER;
+
+    // Fill b2link HSLB trailer
+    poswords_to += SIZE_B2LHSLB_TRAILER;
+
+  }
+
+  // Fill COPPER trailer
+  poswords_to += SIZE_COPPER_TRAILER;
+
+  // Fill RawTrailer
+  packed_buf[ poswords_to + tmp_trailer.POS_TERM_WORD ] = tmp_trailer.MAGIC_WORD_TERM_TRAILER;
+  poswords_to += tmp_trailer.GetTrlNwords();
+
+  *packed_buf_nwords = poswords_to;
+
+  return packed_buf;
+}
+
diff --git a/ROPCApplications/rawdata/dataobjects/src/PostRawCOPPERFormat_v1.cc b/ROPCApplications/rawdata/dataobjects/src/PostRawCOPPERFormat_v1.cc
new file mode 100644
index 0000000000000000000000000000000000000000..49dbb6bfa5fe515eb8bfa297843341550b725a4d
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/PostRawCOPPERFormat_v1.cc
@@ -0,0 +1,426 @@
+//+
+// File : RawCOPPERFormat_v1.cc
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/PostRawCOPPERFormat_v1.h>
+
+
+using namespace std;
+using namespace Belle2;
+
+//#define DESY
+//#define NO_DATA_CHECK
+//#define WO_FIRST_EVENUM_CHECK
+
+//ClassImp(PostRawCOPPERFormat_v1);
+
+PostRawCOPPERFormat_v1::PostRawCOPPERFormat_v1()
+{
+}
+
+PostRawCOPPERFormat_v1::~PostRawCOPPERFormat_v1()
+{
+}
+
+// int PostRawCOPPERFormat_v1::GetBufferPos(int n)
+// {
+//   if (m_buffer == NULL || m_nwords <= 0) {
+//     char err_buf[500];
+//     sprintf(err_buf, "[DEBUG] [ERROR] RawPacket buffer(%p) is not available or length(%d) is not set.\n %s %s %d\n",
+//             m_buffer, m_nwords, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     string err_str = err_buf;     throw (err_str);
+//   }
+
+//   if (n >= (m_num_events * m_num_nodes)) {
+//     char err_buf[500];
+//     sprintf(err_buf, "[DEBUG] Invalid COPPER block No. (%d : max %d ) is specified. Exiting... \n %s %s %d\n",
+//             n, (m_num_events * m_num_nodes), __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     string err_str = err_buf;     throw (err_str);
+//   }
+//   int pos_nwords = 0;
+
+
+//   for (int i = 1; i <= n ; i++) {
+//     tmp_header.SetBuffer(&m_buffer[ pos_nwords ]);
+//     pos_nwords += tmp_header.GetNwords();
+
+//     if (pos_nwords >= m_nwords) {
+//       char err_buf[500];
+//       sprintf(err_buf, "CORRUPTED DATA: value of pos_nwords(%d) is larger than m_nwords(%d). Exiting...\n %s %s %d\n",
+//               pos_nwords, m_nwords, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//       string err_str = err_buf;     throw (err_str);
+//       //      exit(1);
+//     }
+//   }
+//   return pos_nwords;
+// }
+
+
+int PostRawCOPPERFormat_v1::GetDetectorNwords(int n, int finesse_num)
+{
+
+  int nwords = 0;
+  if (GetFINESSENwords(n, finesse_num) > 0) {
+    nwords = GetFINESSENwords(n, finesse_num)
+             - (SIZE_B2LHSLB_HEADER + SIZE_B2LHSLB_TRAILER +  SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER);
+  }
+  return nwords;
+
+}
+
+
+unsigned int PostRawCOPPERFormat_v1::CalcDriverChkSum(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf, "This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
+          n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+  return 0;
+}
+
+
+int PostRawCOPPERFormat_v1::GetFINESSENwords(int n, int finesse_num)
+{
+  int pos_nwords_0, pos_nwords_1;
+  int nwords;
+  switch (finesse_num) {
+    case 0 :
+      pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_1ST_FINESSE;
+      pos_nwords_1 = GetBufferPos(n) + tmp_header.POS_OFFSET_2ND_FINESSE;
+      nwords = m_buffer[ pos_nwords_1 ] - m_buffer[ pos_nwords_0 ];
+      break;
+    case 1 :
+      pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_2ND_FINESSE;
+      pos_nwords_1 = GetBufferPos(n) + tmp_header.POS_OFFSET_3RD_FINESSE;
+      nwords = m_buffer[ pos_nwords_1 ] - m_buffer[ pos_nwords_0 ];
+      break;
+    case 2 :
+      pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_3RD_FINESSE;
+      pos_nwords_1 = GetBufferPos(n) + tmp_header.POS_OFFSET_4TH_FINESSE;
+      nwords = m_buffer[ pos_nwords_1 ] - m_buffer[ pos_nwords_0 ];
+      break;
+    case 3 :
+      pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_4TH_FINESSE;
+      {
+        int nwords_1 = GetBlockNwords(n)
+                       - SIZE_COPPER_DRIVER_TRAILER
+                       - tmp_trailer.GetTrlNwords();
+        nwords = nwords_1 - m_buffer[ pos_nwords_0 ];
+      }
+      break;
+    default :
+      char err_buf[500];
+      sprintf(err_buf, "Invalid finesse # : %s %s %d\n",
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      B2FATAL(err_buf);
+  }
+
+  if (nwords < 0 || nwords > 1e6) {
+    char err_buf[500];
+    sprintf(err_buf, "# of words is strange. %d : %s %s %d\n", nwords,
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  return nwords;
+
+}
+
+
+
+
+unsigned int PostRawCOPPERFormat_v1::GetB2LFEE32bitEventNumber(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf, "No event # in B2LFEE header. (block %d) Exiting...\n%s %s %d\n",
+          n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+  return 0;
+}
+
+
+
+void PostRawCOPPERFormat_v1::CheckData(int n,
+                                       unsigned int prev_evenum, unsigned int* cur_evenum_rawcprhdr,
+                                       unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
+                                       unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+{
+
+  char err_buf[500];
+  sprintf(err_buf,
+          "This function for format ver.1 is not supported. (n %d preveve %u eve %u  prectr %u ctr %u prevrun %u run %u) Exiting...\n %s %s %d\n",
+          n, prev_evenum, *cur_evenum_rawcprhdr, prev_copper_ctr, *cur_copper_ctr,
+          prev_exprunsubrun_no, *cur_exprunsubrun_no,
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+
+//   char err_buf[500];
+//   int err_flag = 0;
+//   //
+//   // Check incrementation of event #
+//   //
+//   *cur_evenum_rawcprhdr = GetEveNo(n);
+//   *cur_exprunsubrun_no = GetExpRunSubrun(n);
+//   if (
+//       prev_exprunsubrun_no == *cur_exprunsubrun_no
+// #ifdef WO_FIRST_EVENUM_CHECK
+//      && prev_evenum != 0xFFFFFFFF && *cur_evenum_rawcprhdr != 0
+// #endif
+//   ) {
+//     if ((unsigned int)(prev_evenum + 1) != *cur_evenum_rawcprhdr) {
+//       sprintf(err_buf, "CORRUPTED DATA: Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n%s %s %d\n",
+//               n, prev_evenum, *cur_evenum_rawcprhdr,
+//               __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//       err_flag = 1;
+//     }
+//   }
+
+
+//   //
+//   // Check checksum calculated by DeSerializerCOPPER()
+//   //
+//   tmp_trailer.SetBuffer(GetRawTrlBufPtr(n));
+//   unsigned int xor_chksum = CalcXORChecksum(GetBuffer(n), GetBlockNwords(n) - tmp_trailer.GetTrlNwords());
+//   if (tmp_trailer.GetChksum() != xor_chksum) {
+//     sprintf(err_buf,
+//             "CORRUPTED DATA: checksum error : block %d : length %d eve 0x%x : Trailer chksum 0x%.8x : calcd. now 0x%.8x\n %s %s %d\n",
+//             n, GetBlockNwords(n), *cur_evenum_rawcprhdr, tmp_trailer.GetChksum(), xor_chksum,
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     err_flag = 1;
+//   }
+
+
+//   if (err_flag == 1) {
+//     printf("[DEBUG] ========== dump a data blcok : block # %d==========\n", n);
+//     PrintData(GetBuffer(n), GetBlockNwords(n));
+//     printf("Print out variables to reduce unused-variables-warnings : %u %u\n", prev_copper_ctr, *cur_copper_ctr);
+//     string err_str = err_buf;
+//     throw (err_str);
+
+//     //     sleep(1234567);
+//     //     exit(-1);
+//   }
+
+  return;
+
+}
+
+bool PostRawCOPPERFormat_v1::CheckCOPPERMagic(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf, "No magic word # in COPPER header (block %d). Exiting...\n%s %s %d\n",
+          n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+  return false;
+}
+
+void PostRawCOPPERFormat_v1::CheckUtimeCtimeTRGType(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf, "This function is not supported (block %d). Exiting...\n%s %s %d\n",
+          n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+}
+
+
+unsigned int PostRawCOPPERFormat_v1::FillTopBlockRawHeader(unsigned int m_node_id, unsigned int prev_eve32,
+                                                           unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+{
+  char err_buf[500];
+  sprintf(err_buf, "This function should be called by PrePostRawCOPPERFormat_***. Exiting...\n %s %s %d\n",
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("Print out variables to reduce unused-variables-warnings : %u %u %u %u\n",
+         m_node_id,  prev_eve32, prev_exprunsubrun_no, *cur_exprunsubrun_no);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+}
+
+
+int PostRawCOPPERFormat_v1::CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords)
+{
+  char err_buf[500];
+  sprintf(err_buf, "This function should be called by PrePostRawCOPPERFormat_***. Exiting...\n %s %s %d\n",
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("Print out variables to reduce unused-variables-warnings : %p %d\n", finesse_buf, finesse_nwords);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+}
+
+int PostRawCOPPERFormat_v1::CheckCRC16(int n, int finesse_num)
+{
+
+  //
+  // Calculate CRC16
+  //
+  int finesse_nwords = GetFINESSENwords(n, finesse_num);
+  if (finesse_nwords <= 0) {
+    char err_buf[500];
+    sprintf(err_buf, "The specified finesse(%d) seems to be empty(nwords = %d). Cannot calculate CRC16. Exiting...\n %s %s %d\n",
+            finesse_num, finesse_nwords, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+  unsigned short temp_crc16 = CalcCRC16LittleEndian(0xffff, &(m_buffer[ tmp_header.POS_TTCTIME_TRGTYPE ]), 1);
+  temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(m_buffer[ tmp_header.POS_EVE_NO ]), 1);
+  temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(m_buffer[ tmp_header.POS_TTUTIME ]), 1);
+  temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(m_buffer[ tmp_header.POS_EXP_RUN_NO ]), 1);
+  int* buf = GetFINESSEBuffer(n, finesse_num) +  SIZE_B2LHSLB_HEADER + POS_B2L_CTIME;
+  int pos_nwords = finesse_nwords - (SIZE_B2LHSLB_HEADER + POS_B2L_CTIME + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER);
+  temp_crc16 = CalcCRC16LittleEndian(temp_crc16, buf, pos_nwords);
+
+  //
+  // Compare CRC16 with B2LCRC16
+  //
+  buf = GetFINESSEBuffer(n, finesse_num) +  GetFINESSENwords(n,
+                                                             finesse_num) - ((SIZE_B2LFEE_TRAILER - POS_B2LFEE_CRC16) + SIZE_B2LHSLB_TRAILER) ;
+
+  if (GetEveNo(n) % 10000 == 0) {
+    printf("#### PostRawCOPPER : Eve %.8x block %d finesse %d B2LCRC16 %.8x calculated CRC16 %.8x\n", GetEveNo(n), n, finesse_num,
+           *buf, temp_crc16);
+  }
+  if ((unsigned short)(*buf & 0xFFFF) != temp_crc16) {
+    //  if ( false ) {
+    PrintData(m_buffer, m_nwords);
+    printf("POST CRC16 error %x %x %d\n", *buf , temp_crc16, GetFINESSENwords(n, finesse_num));
+    printf("\n");
+    int* temp_buf = GetFINESSEBuffer(n, finesse_num);
+    printf("%.8x ", 0);
+    for (int k = 0; k <  GetFINESSENwords(n, finesse_num); k++) {
+      printf("%.8x ", temp_buf[ k ]);
+      if ((k + 1) % 10 == 0) printf("\n%.8x : ", k);
+    }
+    printf("\n");
+    fflush(stdout);
+    char err_buf[500];
+    sprintf(err_buf,
+            "[DEBUG] [ERROR] B2LCRC16 (%.4x) differs from one ( %.4x) calculated by PostRawCOPPERfromat class. Exiting...\n %s %s %d\n",
+            (unsigned short)(*buf & 0xFFFF), temp_crc16, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    B2FATAL(err_buf);
+  }
+
+  return 1;
+
+
+}
+
+
+int* PostRawCOPPERFormat_v1::PackDetectorBuf(int* packed_buf_nwords,
+                                             int* detector_buf_1st,  int nwords_1st,
+                                             int* detector_buf_2nd,  int nwords_2nd,
+                                             int* detector_buf_3rd,  int nwords_3rd,
+                                             int* detector_buf_4th,  int nwords_4th,
+                                             RawCOPPERPackerInfo rawcpr_info)
+{
+  int* packed_buf = NULL;
+
+  int poswords_to = 0;
+  int* detector_buf[ 4 ] = { detector_buf_1st, detector_buf_2nd, detector_buf_3rd, detector_buf_4th };
+  int nwords[ 4 ] = { nwords_1st, nwords_2nd, nwords_3rd, nwords_4th };
+
+  // calculate the event length
+  int length_nwords = tmp_header.GetHdrNwords() + SIZE_COPPER_HEADER + SIZE_COPPER_TRAILER + tmp_trailer.GetTrlNwords();
+
+  for (int i = 0; i < 4; i++) {
+    if (detector_buf[ i ] == NULL || nwords[ i ] <= 0) continue;    // for an empty FINESSE slot
+    length_nwords += nwords[ i ];
+    length_nwords += SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER
+                     + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
+  }
+
+  // allocate buffer
+  packed_buf = new int[ length_nwords ];
+  memset(packed_buf, 0, sizeof(int) * length_nwords);
+
+  //
+  // Fill RawHeader
+  //
+  tmp_header.SetBuffer(packed_buf);
+  packed_buf[ tmp_header.POS_NWORDS ] = length_nwords; // total length
+
+  packed_buf[ tmp_header.POS_VERSION_HDRNWORDS ] =
+    0x7f7f0000
+    | ((DATA_FORMAT_VERSION << tmp_header.FORMAT_VERSION_SHIFT) & tmp_header.FORMAT_VERSION__MASK)
+    | tmp_header.RAWHEADER_NWORDS; // ver.#, header length
+
+  packed_buf[ tmp_header.POS_EXP_RUN_NO ] = (rawcpr_info.exp_num << 22)
+                                            | (rawcpr_info.run_subrun_num & 0x003FFFFF);   // exp. and run #
+  packed_buf[ tmp_header.POS_EVE_NO ] = rawcpr_info.eve_num; // eve #
+  packed_buf[ tmp_header.POS_TTCTIME_TRGTYPE ] = (rawcpr_info.tt_ctime & 0x7FFFFFF) << 4;   // tt_ctime
+  packed_buf[ tmp_header.POS_TTUTIME ] = rawcpr_info.tt_utime; // tt_utime
+  packed_buf[ tmp_header.POS_NODE_ID ] = rawcpr_info.node_id; // node ID
+
+  // fill the positions of finesse buffers
+  packed_buf[ tmp_header.POS_OFFSET_1ST_FINESSE ] = tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
+
+  packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_1ST_FINESSE ];
+  if (nwords[ 0 ] > 0) {
+    packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ] +=
+      nwords[ 0 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER  + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
+  }
+
+  packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ];
+  if (nwords[ 1 ] > 0) {
+    packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ] +=
+      nwords[ 1 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER  + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
+  }
+
+  packed_buf[ tmp_header.POS_OFFSET_4TH_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ];
+  if (nwords[ 2 ] > 0) {
+    packed_buf[ tmp_header.POS_OFFSET_4TH_FINESSE ] += nwords[ 2 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER  + SIZE_B2LFEE_TRAILER +
+                                                       SIZE_B2LHSLB_TRAILER;
+  }
+  poswords_to += tmp_header.GetHdrNwords();
+
+  // Fill COPPER header
+  poswords_to += SIZE_COPPER_HEADER;
+
+  // Fill FINESSE buffer
+  for (int i = 0; i < 4; i++) {
+
+    if (detector_buf[ i ] == NULL || nwords[ i ] <= 0) continue;     // for an empty FINESSE slot
+
+    // Fill b2link HSLB header
+    packed_buf[ poswords_to + POS_B2LHSLB_MAGIC ] = 0xffaa0000 | (0xffff & rawcpr_info.eve_num);
+    poswords_to += SIZE_B2LHSLB_HEADER;
+
+    // Fill b2link FEE header
+    packed_buf[ poswords_to + POS_B2L_CTIME ] = (rawcpr_info.b2l_ctime & 0x7FFFFFF) << 4;
+    poswords_to += SIZE_B2LFEE_HEADER;
+
+    // copy the 1st Detector Buffer
+    memcpy(packed_buf + poswords_to, detector_buf[ i ], nwords[ i ]*sizeof(int));
+    poswords_to += nwords[ i ];
+
+    // Fill b2link FEE trailer
+    unsigned int crc16 = 0;
+    packed_buf[ poswords_to + POS_B2LFEE_CRC16 ] = ((0xffff & rawcpr_info.eve_num) << 16) | (crc16 & 0xffff);
+    poswords_to += SIZE_B2LFEE_TRAILER;
+
+    // Fill b2link HSLB trailer
+    poswords_to += SIZE_B2LHSLB_TRAILER;
+
+  }
+
+  // Fill COPPER trailer
+  poswords_to += SIZE_COPPER_TRAILER;
+
+  // Fill RawTrailer
+  packed_buf[ poswords_to + tmp_trailer.POS_TERM_WORD ] = tmp_trailer.MAGIC_WORD_TERM_TRAILER;
+  poswords_to += tmp_trailer.GetTrlNwords();
+
+  *packed_buf_nwords = poswords_to;
+
+  return packed_buf;
+}
+
diff --git a/ROPCApplications/rawdata/dataobjects/src/PreRawCOPPERFormat_latest.cc b/ROPCApplications/rawdata/dataobjects/src/PreRawCOPPERFormat_latest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f5c09ecfc718c93ff6768d5539df689e76e0a252
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/PreRawCOPPERFormat_latest.cc
@@ -0,0 +1,1428 @@
+//+
+// File : PreRawCOPPERFormat_latest.cc
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/PreRawCOPPERFormat_latest.h>
+
+
+using namespace std;
+using namespace Belle2;
+
+//#define NO_ERROR_STOP
+//#define WO_FIRST_EVENUM_CHECK
+
+//ClassImp(PreRawCOPPERFormat_latest);
+
+PreRawCOPPERFormat_latest::PreRawCOPPERFormat_latest()
+{
+}
+
+PreRawCOPPERFormat_latest::~PreRawCOPPERFormat_latest()
+{
+}
+
+unsigned int PreRawCOPPERFormat_latest::CalcDriverChkSum(int n)
+{
+  int min = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS;
+  int max = GetBufferPos(n) + GetBlockNwords(n)
+            - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
+  unsigned int chksum = 0;
+  for (int i = min; i < max; i++) {
+    chksum ^= m_buffer[ i ];
+  }
+  return chksum;
+}
+
+
+
+int PreRawCOPPERFormat_latest::GetDetectorNwords(int n, int finesse_num)
+{
+
+  int nwords = 0;
+  if (GetFINESSENwords(n, finesse_num) > 0) {
+    nwords = GetFINESSENwords(n, finesse_num)
+             - (SIZE_B2LHSLB_HEADER + SIZE_B2LHSLB_TRAILER +  SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER);
+  }
+  return nwords;
+
+}
+
+
+int PreRawCOPPERFormat_latest::GetFINESSENwords(int n, int finesse_num)
+{
+  if (!CheckCOPPERMagic(n)) {
+    char err_buf[500];
+    sprintf(err_buf,
+            "[FATAL] ERROR_EVENT : COPPER's magic word is invalid. Exiting... Maybe it is due to data corruption or different version of the data format. : slot%c eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
+            65 + finesse_num, GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("[DEBUG] %s", err_buf); fflush(stdout);
+    PrintData(m_buffer, m_nwords);
+
+    for (int i = 0; i < 4; i++) {
+      printf("[DEBUG] ========== CRC check : block # %d finesse %d ==========\n", n, i);
+      if (GetFINESSENwords(n, i) > 0) {
+        CheckCRC16(n, i);
+      }
+    }
+    printf("[DEBUG] ========== No CRC error. : block %d =========\n", n);
+    // string err_str = err_buf;   throw (err_str);
+    B2FATAL(err_buf); // to reduce multiple error messages
+  }
+  int pos_nwords;
+  switch (finesse_num) {
+    case 0 :
+      pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_CH_A_DATA_LENGTH;
+      break;
+    case 1 :
+      pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_CH_B_DATA_LENGTH;
+      break;
+    case 2 :
+      pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_CH_C_DATA_LENGTH;
+      break;
+    case 3 :
+      pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_CH_D_DATA_LENGTH;
+      break;
+    default :
+      char err_buf[500];
+      sprintf(err_buf,
+              "[FATAL] ERROR_EVENT : Specifined FINESSE number( = %d ) is invalid. Exiting... : slot%c eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
+              finesse_num,
+              65 + finesse_num, GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      //      string err_str = err_buf;    throw (err_str);
+      B2FATAL(err_buf); // to reduce multiple error messages
+  }
+  return m_buffer[ pos_nwords ];
+
+}
+
+
+unsigned int PreRawCOPPERFormat_latest::GetB2LFEE32bitEventNumber(int n)
+{
+
+#ifndef READ_OLD_B2LFEE_FORMAT_FILE
+
+  int err_flag = 0;
+  unsigned int eve_num = 0;
+  int flag = 0;
+  unsigned int eve[4];
+  for (int i = 0; i < 4 ; i++) {
+    eve[ i ] = 0xbaadf00d;
+    if (GetFINESSENwords(n, i) > 0) {
+      int pos_nwords = GetOffsetFINESSE(n, i) + SIZE_B2LHSLB_HEADER + POS_TT_TAG;
+      eve[ i ] = m_buffer[ pos_nwords ];
+      if (flag != 1) eve_num = eve[ i ];
+      if (eve_num != eve[ i ]) err_flag = 1;
+      flag = 1;
+    }
+  }
+
+  if (flag == 0) {
+    PrintData(m_buffer, m_nwords);
+    char err_buf[500];
+    sprintf(err_buf, "[FATAL] ERROR_EVENT : No HSLB data in COPPER data. Exiting... : eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
+            GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    //    string err_str = err_buf; throw (err_str);
+    B2FATAL(err_buf); // to reduce multiple error messages
+  }
+
+  if (err_flag == 1) {
+
+    char err_buf[500];
+    sprintf(err_buf,
+            "[FATAL] ERROR_EVENT : CORRUPTED DATA: Different event number over HSLBs : slot A 0x%.8x : B 0x%.8x :C 0x%.8x : D 0x%.8x : eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
+            eve[ 0 ], eve[ 1 ], eve[ 2 ], eve[ 3 ],
+            GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("[DEBUG] %s\n", err_buf);
+    PrintData(m_buffer, m_nwords);
+    for (int i = 0; i < 4; i++) {
+      printf("[DEBUG] ========== CRC check : block # %d finesse %d ==========\n", n, i);
+      if (GetFINESSENwords(n, i) > 0) {
+        CheckCRC16(n, i);
+      }
+    }
+    printf("[DEBUG] ========== No CRC error. : block %d =========\n", n);
+#ifndef NO_ERROR_STOP
+    //    string err_str = err_buf; throw (err_str);
+    B2FATAL(err_buf); // to reduce multiple error messages
+#endif //NO_ERROR_STOP
+  }
+  return eve_num;
+
+#else // READ_OLD_B2LFEE_FORMAT_FILE
+
+  char err_buf[500];
+  sprintf(err_buf, "[FATAL] You need comment out READ_OLD_B2LFEE_FORMAT_FILE if you are handling a new data format\n%s %s %d\n",
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf); // to reduce multiple error messages
+#endif // READ_OLD_B2LFEE_FORMAT_FILE
+
+}
+
+
+void PreRawCOPPERFormat_latest::CheckData(int n,
+                                          unsigned int prev_evenum, unsigned int* cur_evenum_rawcprhdr,
+                                          unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
+                                          unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+{
+
+  char err_buf[500];
+  int err_flag = 0;
+  //
+  // check Magic words
+  //
+  if (!CheckCOPPERMagic(n)) {
+    sprintf(err_buf,
+            "[FATAL] ERROR_EVENT : Invalid Magic word 0x7FFFF0008=%u 0xFFFFFAFA=%u 0xFFFFF5F5=%u 0x7FFF0009=%u : eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
+            GetMagicDriverHeader(n), GetMagicFPGAHeader(n), GetMagicFPGATrailer(n), GetMagicDriverTrailer(n),
+            GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    err_flag = 1;
+  }
+
+  //
+  // Event # check
+  //
+  *cur_evenum_rawcprhdr = GetEveNo(n);
+  unsigned int evenum_feehdr = GetB2LFEE32bitEventNumber(n);
+  if (*cur_evenum_rawcprhdr != evenum_feehdr) {
+    sprintf(err_buf,
+            "[FATAL] ERROR_EVENT : Event # in PreRawCOPPERFormat_latest header and FEE header is different : cprhdr 0x%x feehdr 0x%x : Exiting... : eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
+            *cur_evenum_rawcprhdr, evenum_feehdr,
+            GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    err_flag = 1;
+  }
+
+  //
+  // Check incrementation of event #
+  //
+  *cur_exprunsubrun_no = GetExpRunSubrun(n);
+  *cur_copper_ctr = GetCOPPERCounter(n);
+  if (prev_exprunsubrun_no == *cur_exprunsubrun_no) {
+    if ((unsigned int)(prev_evenum + 1) != *cur_evenum_rawcprhdr) {
+      sprintf(err_buf,
+              "[FATAL] ERROR_EVENT : Event # jump : i %d prev 0x%x cur 0x%x : prevrun %.8x currun %.8x: Exiting... : eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
+              n, prev_evenum, *cur_evenum_rawcprhdr, prev_exprunsubrun_no, *cur_exprunsubrun_no,
+              GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      err_flag = 1;
+    }
+    if ((unsigned int)(prev_copper_ctr + 1) != *cur_copper_ctr) {
+      sprintf(err_buf, "[FATAL] ERROR_EVENT : COPPER counter jump : i %d prev 0x%x cur 0x%x : eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
+              n, prev_copper_ctr, *cur_copper_ctr,
+              GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      err_flag = 1;
+    }
+  } else {
+    printf("[DEBUG] New run started. cur run %.8x prev. run %.8x cur eve %.8x prev eve %8.x : eve 0x%x exp %d run %d sub %d\n",
+           *cur_exprunsubrun_no, prev_exprunsubrun_no , *cur_evenum_rawcprhdr, prev_evenum,
+           GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n));
+
+    // Check if the first event of a run is zero.
+    if ((unsigned int)GetRunNo(n) != (prev_exprunsubrun_no & RawHeader_latest::RUNNO_MASK) >> RawHeader_latest::RUNNO_SHIFT) {
+      if (*cur_evenum_rawcprhdr != 0) {
+
+        unsigned int eve[4];
+        for (int i = 0; i < 4 ; i++) {
+          eve[ i ] = 0xbaadf00d;
+          if (GetFINESSENwords(n, i) > 0) {
+            int pos_nwords = GetOffsetFINESSE(n, i) + SIZE_B2LHSLB_HEADER + POS_TT_TAG;
+            eve[ i ] = m_buffer[ pos_nwords ];
+          }
+        }
+        sprintf(err_buf,
+                "[FATAL] ERROR_EVENT : Invalid Event # at the beginning of the run (It should be zero.): preveve 0x%x cureve 0x%x : prev(exp %u run %d sub %u ) cur(exp %u run %d sub %u ) ( A:0x%.8x B:0x%.8x C:0x%.8x D:0x%.8x ) Exiting... : eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
+                prev_evenum, *cur_evenum_rawcprhdr,
+                prev_exprunsubrun_no >> 22 , (prev_exprunsubrun_no >> 8) & 0x3FFF, prev_exprunsubrun_no & 0xFF,
+                *cur_exprunsubrun_no >> 22 , (*cur_exprunsubrun_no >> 8) & 0x3FFF, *cur_exprunsubrun_no & 0xFF,
+                eve[ 0 ], eve[ 1 ], eve[ 2 ], eve[ 3 ],
+                GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        err_flag = 1;
+      }
+    }
+
+  }
+
+
+
+  //
+  // Check is utime and ctime_trgtype same over different FINESSE data
+  //
+  CheckUtimeCtimeTRGType(n);
+
+  //
+  // Check checksum calculated by COPPER driver
+  //
+  if (GetDriverChkSum(n) != CalcDriverChkSum(n)) {
+    sprintf(err_buf,
+            "[FATAL] ERROR_EVENT : COPPER driver checkSum error : block %d : length %d eve 0x%x : Trailer chksum 0x%.8x : calcd. now 0x%.8x : eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
+            n, GetBlockNwords(n), *cur_evenum_rawcprhdr, GetDriverChkSum(n), CalcDriverChkSum(n),
+            GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    err_flag = 1;
+  }
+
+  //
+  // Check checksum calculated by DeSerializerCOPPER()
+  //
+  tmp_trailer.SetBuffer(GetRawTrlBufPtr(n));
+  unsigned int xor_chksum = CalcXORChecksum(GetBuffer(n), GetBlockNwords(n) - tmp_trailer.GetTrlNwords());
+  if (tmp_trailer.GetChksum() != xor_chksum) {
+    sprintf(err_buf,
+            "[FATAL] ERROR_EVENT : PreRawCOPPERFormat_latest checksum error : block %d : length %d eve 0x%x : Trailer chksum 0x%.8x : calcd. now 0x%.8x : eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
+            n, GetBlockNwords(n), *cur_evenum_rawcprhdr, tmp_trailer.GetChksum(), xor_chksum,
+            GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    err_flag = 1;
+  }
+
+  if (err_flag == 1) {
+    printf("%s", err_buf); fflush(stdout);
+    printf("[DEBUG] ========== dump a data blcok : block # %d==========\n", n);
+    PrintData(GetBuffer(n), GetBlockNwords(n));
+    for (int i = 0; i < 4; i++) {
+      printf("[DEBUG] ========== CRC check : block # %d finesse %d ==========\n", n, i);
+      if (GetFINESSENwords(n, i) > 0) {
+        CheckCRC16(n, i);
+      }
+    }
+    printf("[DEBUG] ========== No CRC error : block %d =========\n", n);
+    //    string err_str = err_buf;    throw (err_str);
+    B2FATAL(err_buf); // to reduce multiple error messages
+  }
+
+  return;
+
+}
+
+bool PreRawCOPPERFormat_latest::CheckCOPPERMagic(int n)
+{
+  if (GetMagicDriverHeader(n) != COPPER_MAGIC_DRIVER_HEADER) {
+    return false;
+  } else if (GetMagicFPGAHeader(n) != COPPER_MAGIC_FPGA_HEADER) {
+    return false;
+  } else if (GetMagicFPGATrailer(n) != COPPER_MAGIC_FPGA_TRAILER) {
+    return false;
+  } else if (GetMagicDriverTrailer(n) != COPPER_MAGIC_DRIVER_TRAILER) {
+    return false;
+  }
+  return true;
+}
+
+void PreRawCOPPERFormat_latest::CheckUtimeCtimeTRGType(int n)
+{
+
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+  CheckB2LFEEHeaderVersion(n);
+#endif
+  int err_flag = 0;
+  int flag = 0;
+  unsigned int temp_utime = 0, temp_ctime_trgtype = 0, temp_eve = 0, temp_exprun = 0;
+  unsigned int temp_ctime_trgtype_footer = 0, temp_eve_footer = 0;
+  unsigned int utime[4], ctime_trgtype[4], eve[4], exprun[4];
+  char err_buf[500];
+
+  memset(utime, 0, sizeof(utime));
+  memset(ctime_trgtype, 0, sizeof(ctime_trgtype));
+  memset(eve, 0, sizeof(eve));
+  memset(exprun, 0, sizeof(exprun));
+
+
+  for (int i = 0; i < 4; i++) {
+    int finesse_nwords = GetFINESSENwords(n, i);
+    if (finesse_nwords > 0) {
+      int offset_finesse = GetOffsetFINESSE(n, i);
+      ctime_trgtype[ i ] = m_buffer[ offset_finesse + SIZE_B2LHSLB_HEADER + POS_TT_CTIME_TYPE ];
+      utime[ i ] = m_buffer[ offset_finesse + SIZE_B2LHSLB_HEADER + POS_TT_UTIME ];
+      eve[ i ] = m_buffer[ offset_finesse + SIZE_B2LHSLB_HEADER + POS_TT_TAG ];
+      exprun[ i ] = m_buffer[ offset_finesse + SIZE_B2LHSLB_HEADER + POS_EXP_RUN ];
+      temp_ctime_trgtype_footer =
+        m_buffer[ offset_finesse + finesse_nwords - (SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER) + POS_TT_CTIME_B2LFEE ];
+      temp_eve_footer =
+        m_buffer[ offset_finesse + finesse_nwords - (SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER) + POS_CHKSUM_B2LFEE ];
+
+      if (flag == 0) {
+        temp_ctime_trgtype = ctime_trgtype[ i ];
+        temp_utime = utime[ i ];
+        temp_eve = eve[ i ];
+        temp_exprun = exprun[ i ];
+        flag = 1;
+      } else {
+        if (temp_ctime_trgtype != ctime_trgtype[ i ] || temp_utime != utime[ i ] ||
+            temp_eve != eve[ i ] || temp_exprun != exprun[ i ]) {
+          if (err_flag == 0) {
+            for (int j = 0; j < 4; j++) {
+              printf("[DEBUG] FINESSE #=%d buffsize %d ctimeTRGtype 0x%.8x utime 0x%.8x eve 0x%.8x exprun 0x%.8x\n",
+                     j, GetFINESSENwords(n, j), ctime_trgtype[ j ], utime[ j ], eve[ j ], exprun[ j ]);
+            }
+          }
+          sprintf(err_buf, "[FATAL] ERROR_EVENT : mismatch header value over FINESSEs. Exiting...\n %s %s %d\n",
+                  __FILE__, __PRETTY_FUNCTION__, __LINE__);
+          printf("%s", err_buf); fflush(stdout);
+
+          err_flag = 1;
+          break;
+        } else if (temp_ctime_trgtype != temp_ctime_trgtype_footer ||
+                   (temp_eve & 0xffff) != ((temp_eve_footer >> 16) & 0xffff)) {
+          sprintf(err_buf,
+                  "[FATAL] ERROR_EVENT : mismatch(finesse %d) between header(ctime %.8x eve %.8x) and footer(ctime %.8x eve_crc16 %.8x). Exiting...\n %s %s %d\n",
+                  i,  temp_ctime_trgtype,  temp_eve, temp_ctime_trgtype_footer, temp_eve_footer,
+                  __FILE__, __PRETTY_FUNCTION__, __LINE__);
+          printf("%s", err_buf); fflush(stdout);
+          err_flag = 1;
+        }
+      }
+    }
+  }
+
+  if (err_flag != 0) {
+    for (int i = 0; i < 4; i++) {
+      if (GetFINESSENwords(n, i) > 0) {
+        printf("[DEBUG] ========== CRC check : block # %d finesse %d ==========\n", n, i);
+        CheckCRC16(n, i);
+        printf("[DEBUG] ========== CRC check is done. : block %d =========\n", n);
+      }
+    }
+#ifndef NO_ERROR_STOP
+    //    string err_str = err_buf; throw (err_str);
+    B2FATAL(err_buf); // to reduce multiple error messages
+#endif
+  }
+  return;
+}
+
+unsigned int PreRawCOPPERFormat_latest::FillTopBlockRawHeader(unsigned int m_node_id, unsigned int prev_eve32,
+    unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+{
+  const int datablock_id = 0;
+  //  m_temp_value = 12345678;
+  //
+  // This function only fills RawHeader contents for the first datablock.
+  // # of block should be 1
+  if (m_num_nodes * m_num_events != 1) {
+    char err_buf[500];
+    sprintf(err_buf,
+            "[FATAL] This function should be used for PreRawCOPPERFormat_latest containing only one datablock, while. this object has num_nodes of %d and num_events of %d\n %s %s %d\n",
+            m_num_nodes, m_num_events,  __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    //    string err_str = err_buf;    throw (err_str);
+    B2FATAL(err_buf); // to reduce multiple error messages
+  }
+
+  //////////////////////////////////////////////////
+  //
+  // Fill info in RawHeader
+  //
+  //////////////////////////////////////////////////
+
+  //
+  // Initialize a RawHeader part
+  //
+  memset(m_buffer, 0, sizeof(int) * tmp_header.RAWHEADER_NWORDS);
+  m_buffer[ tmp_header.POS_VERSION_HDRNWORDS ] = tmp_header.RAWHEADER_NWORDS & tmp_header.HDR_NWORDS_MASK;
+  m_buffer[ tmp_header.POS_VERSION_HDRNWORDS ] |= (DATA_FORMAT_VERSION << tmp_header.FORMAT_VERSION_SHIFT) &
+                                                  tmp_header.FORMAT_VERSION__MASK;
+  m_buffer[ tmp_header.POS_VERSION_HDRNWORDS ] |= (0x80 << tmp_header.FORMAT_VERSION_SHIFT);   // PreFormat
+  m_buffer[ tmp_header.POS_VERSION_HDRNWORDS ] |= tmp_header.MAGIC_WORD;
+
+  //
+  // Check FINESSEs which containes data
+  //
+  int* copper_buf = &(m_buffer[ tmp_header.RAWHEADER_NWORDS ]);
+  if (copper_buf[ POS_CH_A_DATA_LENGTH ] == 0 &&
+      copper_buf[ POS_CH_B_DATA_LENGTH ] == 0 &&
+      copper_buf[ POS_CH_C_DATA_LENGTH ] == 0 &&
+      copper_buf[ POS_CH_D_DATA_LENGTH ] == 0) {
+    char err_buf[500];
+    sprintf(err_buf,
+            "[FATAL] ERROR_EVENT : No FINESSE data in a copper data block. Exiting...\n %s %s %d\n",
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    //    string err_str = err_buf; throw (err_str);
+    B2FATAL(err_buf); // to reduce multiple error messages
+  }
+
+  //
+  //   Set total words info
+  //
+  int datablock_nwords =
+    tmp_header.RAWHEADER_NWORDS +
+    (copper_buf[ POS_DATA_LENGTH ]
+     + SIZE_COPPER_DRIVER_HEADER
+     + SIZE_COPPER_DRIVER_TRAILER)
+    + tmp_trailer.RAWTRAILER_NWORDS;
+  m_buffer[ tmp_header.POS_NWORDS ] = datablock_nwords;
+
+
+  //
+  // Check the consistency between data length and length in RawHeader
+  //
+  if (m_buffer[ tmp_header.POS_NWORDS ] != m_nwords) {
+    char err_buf[500];
+    sprintf(err_buf,
+            "[FATAL] ERROR_EVENT : Data length is inconsistent m_nwords %d : nwords from COPPER data %d\n %s %s %d\n",
+            m_nwords, m_buffer[ tmp_header.POS_NWORDS ],
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    //    string err_str = err_buf; throw (err_str);
+    B2FATAL(err_buf); // to reduce multiple error messages
+  }
+
+  //
+  // Fill offset values
+  //
+  int offset_1st_finesse =  tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
+  int offset_2nd_finesse = offset_1st_finesse + copper_buf[ POS_CH_A_DATA_LENGTH ];
+  int offset_3rd_finesse = offset_2nd_finesse + copper_buf[ POS_CH_B_DATA_LENGTH ];
+  int offset_4th_finesse = offset_3rd_finesse + copper_buf[ POS_CH_C_DATA_LENGTH ];
+  m_buffer[ tmp_header.POS_OFFSET_1ST_FINESSE ] = offset_1st_finesse;
+  m_buffer[ tmp_header.POS_OFFSET_2ND_FINESSE ] = offset_2nd_finesse;
+  m_buffer[ tmp_header.POS_OFFSET_3RD_FINESSE ] = offset_3rd_finesse;
+  m_buffer[ tmp_header.POS_OFFSET_4TH_FINESSE ] = offset_4th_finesse;
+
+  //
+  // Fill Exp/Run value
+  //
+  int* finesse_buf = &
+                     (m_buffer[ offset_1st_finesse ]); // In any finesse implementations, the top finesse buffer should be at offset_1st_finesse;
+  m_buffer[ tmp_header.POS_EXP_RUN_NO ] = finesse_buf[ SIZE_B2LHSLB_HEADER + POS_EXP_RUN ];
+
+
+  //
+  // Fill event #
+  //
+  unsigned int cur_ftsw_eve32 =  finesse_buf[ SIZE_B2LHSLB_HEADER + POS_TT_TAG ];
+  m_buffer[ tmp_header.POS_EVE_NO ] = cur_ftsw_eve32;
+
+  //
+  // Copy FTSW words from B2LFEE header
+  //
+  m_buffer[ tmp_header.POS_TTCTIME_TRGTYPE ] = finesse_buf[ SIZE_B2LHSLB_HEADER + POS_TT_CTIME_TYPE ];
+  m_buffer[ tmp_header.POS_TTUTIME ] = finesse_buf[ SIZE_B2LHSLB_HEADER + POS_TT_UTIME ];
+
+  //
+  // Set node ID, trunc_mask, data_type
+  //
+  m_buffer[ tmp_header.POS_NODE_ID ] = m_node_id;
+
+  //
+  // Check error counts of b2link-packet CRC
+  //
+  //  m_buffer[ tmp_header.POS_TRUNC_MASK_DATATYPE ] = ((m_trunc_mask << 31) & 0x80000000) | (m_data_type & 0x7FFFFFFF);
+  //   printf("%.8x %.8x %.8x %.8x : %.8x\n",
+  //   copper_buf[ POS_CH_A_DATA_LENGTH ], copper_buf[ POS_CH_B_DATA_LENGTH ],
+  //   copper_buf[ POS_CH_C_DATA_LENGTH ], copper_buf[ POS_CH_D_DATA_LENGTH ], m_buffer[ offset_3rd_finesse + copper_buf[ POS_CH_C_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ] );
+
+  m_buffer[ tmp_header.POS_TRUNC_MASK_DATATYPE ] = 0;
+  unsigned int ff55_higher_bits = 0, ff55_lower_bits = 0;
+
+  if (copper_buf[ POS_CH_A_DATA_LENGTH ] != 0) {
+    ff55_higher_bits = (unsigned int)(m_buffer[ offset_1st_finesse + copper_buf[ POS_CH_A_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ]) &
+                       0xFFFF0000;
+    ff55_lower_bits = m_buffer[ offset_1st_finesse + copper_buf[ POS_CH_A_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ] & 0xFFFF;
+
+    if (ff55_higher_bits != 0xff550000) {
+      char err_buf[500];
+      sprintf(err_buf,
+              "[FATAL] ERROR_EVENT : HSLB slotA's trailer magic word(0xff55) is invalid. :  : eve %8u run %d foooter %.8x : %s %s %d\n",
+              cur_ftsw_eve32, (m_buffer[ tmp_header.POS_EXP_RUN_NO ] >> 8) & 0x3FFF,
+              m_buffer[ offset_1st_finesse + copper_buf[ POS_CH_A_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ],
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      PrintData(m_buffer, m_nwords); fflush(stdout);
+      B2FATAL(err_buf);
+    }
+
+    if (ff55_lower_bits != 0) {
+      const int linkdown_bit = 15;
+      //      const int packet_crcerr_bit = 8;
+      char err_buf[500];
+      if ((ff55_lower_bits & (1 << linkdown_bit)) != 0) {
+        sprintf(err_buf, "[FATAL] B2link down on slot A eve %8u foooter %.8x : %s %s %d\n", cur_ftsw_eve32,
+                m_buffer[ offset_1st_finesse + copper_buf[ POS_CH_A_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ],
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      } else {
+        m_buffer[ tmp_header.POS_TRUNC_MASK_DATATYPE ] |= tmp_header.B2LINK_PACKET_CRC_ERROR;
+        sprintf(err_buf, "[FATAL] B2link packet CRC error slot A eve %8u foooter %.8x : %s %s %d\n", cur_ftsw_eve32,
+                m_buffer[ offset_1st_finesse + copper_buf[ POS_CH_A_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ],
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      }
+      printf("%s", err_buf); fflush(stdout);
+      PrintData(m_buffer, m_nwords);
+      fflush(stdout);
+      B2FATAL(err_buf);
+    }
+  }
+
+  if (copper_buf[ POS_CH_B_DATA_LENGTH ] != 0) {
+    ff55_higher_bits = (unsigned int)(m_buffer[ offset_2nd_finesse + copper_buf[ POS_CH_B_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ]) &
+                       0xFFFF0000;
+    ff55_lower_bits = (m_buffer[ offset_2nd_finesse + copper_buf[ POS_CH_B_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ] & 0xFFFF);
+
+    if (ff55_higher_bits != 0xff550000) {
+      char err_buf[500];
+      sprintf(err_buf,
+              "[FATAL] ERROR_EVENT : HSLB slotB's trailer magic word(0xff55) is invalid. :  : eve %8u run %d foooter %.8x : %s %s %d\n",
+              cur_ftsw_eve32, (m_buffer[ tmp_header.POS_EXP_RUN_NO ] >> 8) & 0x3FFF,
+              m_buffer[ offset_2nd_finesse + copper_buf[ POS_CH_B_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ],
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      PrintData(m_buffer, m_nwords); fflush(stdout);
+      B2FATAL(err_buf);
+    }
+
+    if (ff55_lower_bits != 0) {
+      char err_buf[500];
+      const int linkdown_bit = 15;
+      //      const int packet_crcerr_bit = 8;
+      if ((ff55_lower_bits & (1 << linkdown_bit)) != 0) {
+        sprintf(err_buf, "[FATAL] B2link down on slot B eve %8u foooter %.8x : %s %s %d\n",  cur_ftsw_eve32,
+                m_buffer[ offset_2nd_finesse + copper_buf[ POS_CH_B_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ],
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      } else {
+        m_buffer[ tmp_header.POS_TRUNC_MASK_DATATYPE ] |= tmp_header.B2LINK_PACKET_CRC_ERROR;
+        sprintf(err_buf, "[FATAL] B2link packet CRC error slot B eve %8u foooter %.8x : %s %s %d\n",  cur_ftsw_eve32,
+                m_buffer[ offset_2nd_finesse + copper_buf[ POS_CH_B_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ],
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      }
+      printf("%s", err_buf); fflush(stdout);
+      PrintData(m_buffer, m_nwords);     fflush(stdout);
+      B2FATAL(err_buf);
+    }
+  }
+
+  if (copper_buf[ POS_CH_C_DATA_LENGTH ] != 0) {
+    ff55_higher_bits = (unsigned int)(m_buffer[ offset_3rd_finesse + copper_buf[ POS_CH_C_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ]) &
+                       0xFFFF0000;
+    ff55_lower_bits = (m_buffer[ offset_3rd_finesse + copper_buf[ POS_CH_C_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ] & 0xFFFF);
+
+    if (ff55_higher_bits != 0xff550000) {
+      char err_buf[500];
+      sprintf(err_buf,
+              "[FATAL] ERROR_EVENT : HSLB slotC's trailer magic word(0xff55) is invalid. :  : eve %8u run %d foooter %.8x : %s %s %d\n",
+              cur_ftsw_eve32, (m_buffer[ tmp_header.POS_EXP_RUN_NO ] >> 8) & 0x3FFF,
+              m_buffer[ offset_2nd_finesse + copper_buf[ POS_CH_C_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ],
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      PrintData(m_buffer, m_nwords); fflush(stdout);
+      B2FATAL(err_buf);
+    }
+
+    if (ff55_lower_bits != 0) {
+      char err_buf[500];
+      const int linkdown_bit = 15;
+      //      const int packet_crcerr_bit = 8;
+      if ((ff55_lower_bits & (1 << linkdown_bit)) != 0) {
+        sprintf(err_buf, "[FATAL] B2link down on slot C eve %8u foooter %.8x : %s %s %d\n",  cur_ftsw_eve32,
+                m_buffer[ offset_3rd_finesse + copper_buf[ POS_CH_C_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ],
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      } else {
+        m_buffer[ tmp_header.POS_TRUNC_MASK_DATATYPE ] |= tmp_header.B2LINK_PACKET_CRC_ERROR;
+        sprintf(err_buf, "[FATAL] B2link packet CRC error slot C eve %8u foooter %.8x : %s %s %d\n",  cur_ftsw_eve32,
+                m_buffer[ offset_3rd_finesse + copper_buf[ POS_CH_C_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ],
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      }
+      printf("%s", err_buf); fflush(stdout);
+      PrintData(m_buffer, m_nwords);     fflush(stdout);
+      B2FATAL(err_buf);
+    }
+  }
+
+  if (copper_buf[ POS_CH_D_DATA_LENGTH ] != 0) {
+    ff55_higher_bits = (unsigned int)(m_buffer[ offset_4th_finesse + copper_buf[ POS_CH_D_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ]) &
+                       0xFFFF0000;
+    ff55_lower_bits = (m_buffer[ offset_4th_finesse + copper_buf[ POS_CH_D_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ] & 0xFFFF);
+
+    if (ff55_higher_bits != 0xff550000) {
+      char err_buf[500];
+      sprintf(err_buf,
+              "[FATAL] ERROR_EVENT : HSLB slotD's trailer magic word(0xff55) is invalid. :  : eve %8u run %d foooter %.8x : %s %s %d\n",
+              cur_ftsw_eve32, (m_buffer[ tmp_header.POS_EXP_RUN_NO ] >> 8) & 0x3FFF,
+              m_buffer[ offset_4th_finesse + copper_buf[ POS_CH_D_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ],
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      PrintData(m_buffer, m_nwords); fflush(stdout);
+      B2FATAL(err_buf);
+    }
+
+    if (ff55_lower_bits != 0) {
+      char err_buf[500];
+      const int linkdown_bit = 15;
+      if ((ff55_lower_bits & (1 << linkdown_bit)) != 0) {
+        sprintf(err_buf, "[FATAL] B2link down on slot D eve %8u foooter %.8x : %s %s %d\n",  cur_ftsw_eve32,
+                m_buffer[ offset_4th_finesse + copper_buf[ POS_CH_D_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ],
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      } else {
+        sprintf(err_buf, "[FATAL] B2link packet CRC error slot D eve %8u foooter %.8x : %s %s %d\n",  cur_ftsw_eve32,
+                m_buffer[ offset_4th_finesse + copper_buf[ POS_CH_D_DATA_LENGTH ] - SIZE_B2LHSLB_HEADER ],
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      }
+      printf("%s", err_buf); fflush(stdout);
+      PrintData(m_buffer, m_nwords); fflush(stdout);
+      B2FATAL(err_buf);
+    }
+  }
+
+
+  //////////////////////////////////////////////////
+  //
+  // Fill info in RawTrailer
+  //
+  //////////////////////////////////////////////////
+
+  //
+  // Calculate XOR checksum
+  //
+  unsigned int chksum_top = 0, chksum_body = 0, chksum_bottom = 0;
+
+  int top_end = tmp_header.RAWHEADER_NWORDS;
+  for (int i = 0; i < top_end; i++) {
+    chksum_top ^= m_buffer[ i ];
+  }
+  int body_end = datablock_nwords - SIZE_COPPER_DRIVER_TRAILER - tmp_trailer.RAWTRAILER_NWORDS;
+  for (int i = top_end; i < body_end; i++) {
+    chksum_body ^= m_buffer[ i ];
+  }
+
+  int bottom_end = datablock_nwords - tmp_trailer.RAWTRAILER_NWORDS;
+  for (int i = body_end; i < bottom_end; i++) {
+    chksum_bottom ^= m_buffer[ i ];
+  }
+
+  //
+  // check COPPER driver checksum
+  //
+  if (chksum_body != (unsigned int)(m_buffer[ body_end ])) {
+    char err_buf[500];
+    sprintf(err_buf, "[FATAL] ERROR_EVENT : COPPER driver checksum is not consistent.: calcd. %.8x data %.8x\n %s %s %d\n",
+            chksum_body, m_buffer[ body_end ],
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf); // to reduce multiple error messages
+  }
+
+  //
+  // Fill trailer info (checksum, magic word)
+  //
+  unsigned int chksum = chksum_top ^ chksum_body ^ chksum_bottom;
+  int* trl = &(m_buffer[ datablock_nwords - tmp_trailer.RAWTRAILER_NWORDS ]);
+  trl[ tmp_trailer.POS_CHKSUM ] = chksum;
+  trl[ tmp_trailer.POS_TERM_WORD ] = tmp_trailer.MAGIC_WORD_TERM_TRAILER;
+
+
+  //////////////////////////////////////////////////
+  //
+  // Data check ( magic word, event incrementation )
+  //
+  //////////////////////////////////////////////////
+
+
+  //
+  // check magic words
+  //
+  int* fpga_trailer_magic = trl - (SIZE_COPPER_TRAILER - POS_MAGIC_COPPER_3);
+  int* driver_trailer_magic = trl - (SIZE_COPPER_TRAILER - POS_MAGIC_COPPER_4);
+  int err_flag = 0;
+  if ((unsigned int)(copper_buf[ POS_MAGIC_COPPER_1 ]) != COPPER_MAGIC_DRIVER_HEADER) {
+    err_flag = 1;
+  } else if ((unsigned int)(copper_buf[ POS_MAGIC_COPPER_2 ]) != COPPER_MAGIC_FPGA_HEADER) {
+    err_flag = 1;
+  } else if ((unsigned int)(*fpga_trailer_magic) != COPPER_MAGIC_FPGA_TRAILER) {
+    err_flag = 1;
+  } else if ((unsigned int)(*driver_trailer_magic) != COPPER_MAGIC_DRIVER_TRAILER) {
+    err_flag = 1;
+  }
+  if (err_flag == 1) {
+    char err_buf[500];
+    sprintf(err_buf, "[FATAL] ERROR_EVENT : Invalid Magic word 0x7FFFF0008=%u 0xFFFFFAFA=%u 0xFFFFF5F5=%u 0x7FFF0009=%u\n %s %s %d\n",
+            GetMagicDriverHeader(datablock_id),
+            GetMagicFPGAHeader(datablock_id),
+            GetMagicFPGATrailer(datablock_id),
+            GetMagicDriverTrailer(datablock_id),
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("[DEBUG] %s\n", err_buf);
+#ifndef NO_ERROR_STOP
+    B2FATAL(err_buf); // to reduce multiple error messages
+#endif
+  }
+
+  //
+  // check incrementation of event #
+  //
+
+
+  *cur_exprunsubrun_no = GetExpRunSubrun(datablock_id);
+
+//   if ((unsigned int)cur_ftsw_eve32 < 50) {
+//     printf("EVENT OUTPUT ########## %u\n", cur_ftsw_eve32);
+//     PrintData(GetBuffer(datablock_id), TotalBufNwords());
+//   }
+  if (prev_exprunsubrun_no == *cur_exprunsubrun_no) {
+    if (prev_eve32 + 1 != cur_ftsw_eve32) {
+      unsigned int eve[4] = {0xbaadf00d, 0xbaadf00d, 0xbaadf00d, 0xbaadf00d };
+#ifndef NO_ERROR_STOP
+      if (m_num_nodes * m_num_events != 1) {
+        char err_buf[500];
+        sprintf(err_buf,
+                "[FATAL] This function should be used for PreRawCOPPERFormat_latest containing only one datablock, while. this object has num_nodes of %d and num_events of %d\n %s %s %d\n",
+                m_num_nodes, m_num_events,  __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        printf("%s", err_buf); fflush(stdout);
+        //    string err_str = err_buf;    throw (err_str);
+        B2FATAL(err_buf); // to reduce multiple error messages
+      } else {
+        for (int i = 0; i < 4 ; i++) {
+          // Only one block is in this m_buffer[] when m_num_nodes*m_num_events=1
+          // 0 is specified as a block number
+          if (GetFINESSENwords(0 , i) > 0) {
+            int pos_nwords = GetOffsetFINESSE(0, i) + SIZE_B2LHSLB_HEADER + POS_TT_TAG;
+            eve[ i ] = m_buffer[ pos_nwords ];
+          }
+        }
+      }
+
+      char err_buf[500];
+      sprintf(err_buf,
+              "[FATAL] ERROR_EVENT : Invalid event_number. Exiting...: cur 32bit eve %u preveve %u ( A:0x%.8x B:0x%.8x C:0x%.8x D:0x%.8x ) prun %u crun %u\n %s %s %d\n",
+              cur_ftsw_eve32, prev_eve32,
+              eve[ 0 ], eve[ 1 ], eve[ 2 ], eve[ 3 ],
+              prev_exprunsubrun_no, *cur_exprunsubrun_no,
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("[DEBUG] %s\n", err_buf);
+
+      string err_str = err_buf;
+      printf("[DEBUG] i= %d : num entries %d : Tot words %d\n", 0 , GetNumEntries(), TotalBufNwords());
+      PrintData(GetBuffer(datablock_id), TotalBufNwords());
+
+      for (int i = 0; i < 4; i++) {
+        printf("[DEBUG] ========== CRC check : block # %d finesse %d ==========\n", datablock_id, i);
+        if (GetFINESSENwords(datablock_id, i) > 0) {
+          CheckCRC16(datablock_id, i);
+        }
+      }
+      printf("[DEBUG] ========== No CRC error : block %d =========\n", datablock_id);
+      //      throw (err_str);
+      B2FATAL(err_buf); // to reduce multiple error messages
+#endif
+
+    }
+  }
+
+  return cur_ftsw_eve32;
+
+}
+
+
+
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+void PreRawCOPPERFormat_latest::CheckB2LFEEHeaderVersion(int n)
+{
+  int* temp_buf;
+  for (int i = 0; i < 4; i++) {
+    if (GetFINESSENwords(n, i) > 0) {
+      temp_buf = GetFINESSEBuffer(n, i);
+      if ((temp_buf[ 3 ] & 0x40000000) == 0) {
+#ifdef TEMP
+        // this word for exp/run
+        // old one (ver.1) used for SPring8 test in 2013
+        printf("[DEBUG] \033[31m");
+        printf("[DEBUG] ===Firmware ver. ERROR===\n ");
+        printf("[DEBUG] FTSW and b2tt firmwares was updated on Nov.22, 2013 and the header format attached by B2link was changed in the new firmwares.\n");
+        printf("[DEBUG] If you are going to take data now, Please update the firmware.\n");
+        printf("[DEBUG] For details, please see Nakao-san's e-mail [b2link_ml:0111] Re: [daq2ml:0159] beta version of trigger timing receiver firmware (b2tt) on bdaq SVN\n");
+        printf("[DEBUG] Or if you are going to read data taken before the update, please use basf2 software before svn revision 7419\n");
+        printf("[DEBUG] About the format please see Nakao-san's B2GM slides(p. 13 and 15) http://kds.kek.jp/getFile.py/access?contribId=143&sessionId=38&resId=0&materialId=slides&confId=13911.\n");
+        printf("[DEBUG] Sorry for inconvenience.\n");
+        printf("[DEBUG] \033[0m");
+        fflush(stderr);
+        char err_buf[500];
+        sprintf(err_buf, "[FATAL] ERROR_EVENT : FTSW and b2tt firmwares are old. Exiting...\n %s %s %d\n",
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        B2FATAL(err_buf);
+#endif
+      } else {
+        // this word for 32bit unixtime
+        // new one (ver.2)
+        break;
+      }
+    }
+
+    if (i == 3) {
+#ifdef TEMP
+      char err_buf[500];
+      sprintf(err_buf, "[FATAL] ERROR_EVENT : PreRawCOPPERFormat_latest contains no FINESSE data. Exiting...\n %s %s %d\n",
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      //      string err_str = err_buf; throw (err_str);
+      B2FATAL(err_buf); // to reduce multiple error messages
+#endif
+    }
+  }
+  return;
+}
+#endif
+
+//int PreRawCOPPERFormat_latest::CalcReducedDataSize(RawDataBlock* raw_datablk)
+int PreRawCOPPERFormat_latest::CalcReducedDataSize(int* bufin, int nwords, int num_events, int num_nodes)
+{
+  //
+  // Calculate reduced length for a total RawDataBlock (containing multiple data blocks)
+  //
+  RawDataBlockFormat radblk_fmt;
+  int delete_flag = 0;
+  radblk_fmt.SetBuffer(bufin, nwords, delete_flag, num_events, num_nodes);
+
+  int reduced_nwords = 0;
+  for (int k = 0; k < radblk_fmt.GetNumEvents(); k++) {
+    int num_nodes_in_sendblock = radblk_fmt.GetNumNodes();
+    for (int l = 0; l < num_nodes_in_sendblock; l++) {
+      int entry_id = l + k * num_nodes_in_sendblock;
+
+      if (radblk_fmt.CheckFTSWID(entry_id) || radblk_fmt.CheckTLUID(entry_id)) {
+        reduced_nwords += radblk_fmt.GetBlockNwords(entry_id);
+      } else {
+        PreRawCOPPERFormat_latest temp_prerawcpr;
+        int temp_delete_flag = 0, temp_num_eve = 1, temp_num_nodes = 1;
+
+        // Call CalcReducedNwords
+        temp_prerawcpr.SetBuffer(radblk_fmt.GetBuffer(entry_id),
+                                 radblk_fmt.GetBlockNwords(entry_id),
+                                 temp_delete_flag, temp_num_eve,
+                                 temp_num_nodes);
+        reduced_nwords += temp_prerawcpr.CalcReducedNwords(0);
+      }
+    }
+  }
+  return reduced_nwords;
+
+}
+
+//void PreRawCOPPERFormat_latest::CopyReducedData(RawDataBlock* raw_datablk, int* buf_to, int delete_flag_from)
+void PreRawCOPPERFormat_latest::CopyReducedData(int* bufin, int nwords, int num_events, int num_nodes, int* buf_to, int* nwords_to)
+{
+  //
+  // Make a reduced buffer a total RawDataBlock (containing multiple data blocks)
+  //
+  RawDataBlockFormat radblk_fmt;
+  int delete_flag = 0;
+  radblk_fmt.SetBuffer(bufin, nwords, delete_flag, num_events, num_nodes);
+
+  int pos_nwords_to = 0;
+  for (int k = 0; k < radblk_fmt.GetNumEvents(); k++) {
+    int num_nodes_in_sendblock = radblk_fmt.GetNumNodes();
+    for (int l = 0; l < num_nodes_in_sendblock; l++) {
+      int entry_id = l + k * num_nodes_in_sendblock;
+      if (radblk_fmt.CheckFTSWID(entry_id) ||
+          radblk_fmt.CheckTLUID(entry_id)) {
+        radblk_fmt.CopyBlock(entry_id, buf_to + pos_nwords_to);
+        pos_nwords_to += radblk_fmt.GetBlockNwords(entry_id);
+
+      } else {
+        SetBuffer(radblk_fmt.GetBuffer(entry_id),
+                  radblk_fmt.GetBlockNwords(entry_id), 0, 1, 1);
+
+        pos_nwords_to += CopyReducedBuffer(0, buf_to + pos_nwords_to);
+
+
+      }
+    }
+  }
+
+  *nwords_to = pos_nwords_to;
+
+  return ;
+}
+
+
+int PreRawCOPPERFormat_latest::CalcReducedNwords(int n)
+{
+  //
+  // Calculate reduced length for one data block which is a part of a RawDataBlock
+  //
+
+  int nwords_to = 0;
+
+  //RawCOPPER header
+  nwords_to += tmp_header.RAWHEADER_NWORDS;
+
+  for (int j = 0; j < 4; j++) {
+
+    int finesse_nwords = GetFINESSENwords(n, j);
+    if (finesse_nwords > 0) {
+      //
+      // B2L(HSLB/FEE) header and trailers are resized
+      // m_reduced_rawcpr should be PostRawCOPPERFormat_latest
+      //
+      nwords_to +=
+        finesse_nwords
+        - (SIZE_B2LHSLB_HEADER -  m_reduced_rawcpr.SIZE_B2LHSLB_HEADER)
+        - (SIZE_B2LFEE_HEADER -   m_reduced_rawcpr.SIZE_B2LFEE_HEADER)
+        - (SIZE_B2LFEE_TRAILER -  m_reduced_rawcpr.SIZE_B2LFEE_TRAILER)
+        - (SIZE_B2LHSLB_TRAILER - m_reduced_rawcpr.SIZE_B2LHSLB_TRAILER);
+    }
+
+  }
+
+  //RawCOPPER Trailer
+  nwords_to += tmp_trailer.GetTrlNwords();
+
+  return nwords_to;
+}
+
+
+
+
+
+
+int PreRawCOPPERFormat_latest::CopyReducedBuffer(int n, int* buf_to)
+{
+  //
+  // Make a reduced buffer for one data block which is a part of a RawDataBlock
+  //
+
+  int* buf_from = NULL;
+  int nwords_buf_to = CalcReducedNwords(n);
+  int pos_nwords_to = 0;
+  int copy_nwords = 0;
+
+  unsigned int removed_xor_chksum = 0;
+
+  // copyt to ReducedRawCOPPER
+  //  ReducedRawCOPPER m_reduced_rawcpr;
+  //Header copy
+  copy_nwords = tmp_header.RAWHEADER_NWORDS;
+  buf_from = GetBuffer(n);
+  copyData(buf_to, &pos_nwords_to, buf_from, copy_nwords, nwords_buf_to);
+
+
+  //calcurate XOR checksum diff.( depends on data-format )
+  removed_xor_chksum ^= buf_from[ tmp_header.POS_VERSION_HDRNWORDS ];
+
+  // Unset the PreFormat bit ( 15th bit )
+  buf_to[ tmp_header.POS_VERSION_HDRNWORDS ] &= 0xFFFF7FFF;
+
+  //calcurate XOR checksum diff.( depends on data-format )
+  removed_xor_chksum ^=  buf_to[ tmp_header.POS_VERSION_HDRNWORDS ];
+  for (int i = 0; i < SIZE_COPPER_HEADER; i++) {
+    removed_xor_chksum ^=  buf_from[ tmp_header.RAWHEADER_NWORDS + i ];
+  }
+
+  //Check Header
+  //  m_reduced_rawcpr.tmp_header.CheckHeader(buf_to + pos_nwords_to - copy_nwords);
+
+
+  // copy FINESSE buffer
+  int pos_nwords_finesse[ 4 ];
+  for (int j = 0; j < 4; j++) {
+    pos_nwords_finesse[ j ] = pos_nwords_to;
+    if (GetFINESSENwords(n, j) > 0) {
+      int* finesse_buf = GetFINESSEBuffer(n, j);
+      int finesse_nwords = GetFINESSENwords(n, j);
+
+
+      CheckB2LHSLBMagicWords(finesse_buf, finesse_nwords);
+      // copy the whole B2LHSLB header (1word)
+      buf_to[ pos_nwords_to ] = finesse_buf[ POS_MAGIC_B2LHSLB ];
+      pos_nwords_to++;
+
+      // copy the last word of B2LFEE and body( DetectorBuffer )
+      buf_from =
+        finesse_buf
+        + SIZE_B2LHSLB_HEADER
+        + POS_B2L_CTIME; //the last word of B2LFEE
+
+
+      // check finesse buffer size : ( When dumhslb was used, this type of error
+      // occured and RecvStream0.py died by Segmentation Fault. ) 2014.12.01.
+      if (finesse_nwords - SIZE_B2LHSLB_HEADER - SIZE_B2LFEE_HEADER
+          - SIZE_B2LFEE_TRAILER - SIZE_B2LHSLB_TRAILER < 0) {
+        char err_buf[500];
+        sprintf(err_buf,
+                "[FATAL] ERROR_EVENT : Finesse buffer size is too small( %d words < %d words). May be the data are corrupted. Exiting...\n %s %s %d\n",
+                finesse_nwords, SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER,
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        printf("%s", err_buf); fflush(stdout);
+        //        string err_str = err_buf;     throw (err_str);
+        B2FATAL(err_buf); // to reduce multiple error messages
+      }
+
+      //calcurate XOR checksum diff.( depends on data-format )
+      for (int k = 1; k <= 4 ; k++) {
+        removed_xor_chksum ^=  finesse_buf[ k ];
+      }
+
+      copy_nwords =
+        finesse_nwords
+        - SIZE_B2LHSLB_HEADER // already copied
+        - POS_B2L_CTIME // only one word copied ( SIZE_B2LFEE_HEADER - 1 = POS_B2L_CTIME )
+        - SIZE_B2LFEE_TRAILER // will be copied later
+        - SIZE_B2LHSLB_TRAILER; // Not copied
+      copyData(buf_to, &pos_nwords_to, buf_from, copy_nwords, nwords_buf_to);
+      //      printf("pos %d nwords %d  nwords to %d\n", pos_nwords_to, copy_nwords, nwords_buf_to );
+
+      //copy B2LFEE trailer(CRC info)
+      buf_to[ pos_nwords_to ] = 0xffff & finesse_buf[ finesse_nwords - SIZE_B2LHSLB_TRAILER - (SIZE_B2LFEE_TRAILER - POS_CHKSUM_B2LFEE) ];
+      //copy B2LHSLB trailer(packet CRC error count)
+      buf_to[ pos_nwords_to ] |= (finesse_buf[ finesse_nwords - (SIZE_B2LHSLB_TRAILER - POS_MAGIC_B2LHSLB) ] << 16) & 0xFFFF0000;
+
+      //calcurate XOR checksum diff. ( depends on data-format )
+      for (int k = 0; k <= 2 ; k++) {
+        removed_xor_chksum ^=  finesse_buf[ finesse_nwords - SIZE_B2LFEE_TRAILER - SIZE_B2LHSLB_TRAILER + k ];
+      }
+      removed_xor_chksum ^=  buf_to[ pos_nwords_to ];
+
+      pos_nwords_to++;
+
+      // check CRC data
+      //      CheckCRC16( n, j );
+    }
+  }
+
+  // copy RawCOPPER trailer
+  buf_from =
+    GetBuffer(n)
+    + GetBlockNwords(n)
+    - tmp_trailer.GetTrlNwords();
+  copy_nwords = tmp_trailer.GetTrlNwords();
+  copyData(buf_to, &pos_nwords_to, buf_from, copy_nwords, nwords_buf_to);
+
+  //calcurate XOR checksum diff.( depends on data-format )
+  unsigned int old_rawcopper_chksum = buf_from[ tmp_trailer.POS_CHKSUM ];
+  for (int i = 0; i < SIZE_COPPER_TRAILER; i++) {
+    removed_xor_chksum ^= (unsigned int) * (buf_from - SIZE_COPPER_TRAILER + i);
+  }
+
+
+  // length check
+  if (pos_nwords_to != nwords_buf_to) {
+    char err_buf[500];
+    sprintf(err_buf, "Buffer overflow. Exiting... %d %d\n", pos_nwords_to, nwords_buf_to);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+
+  // Recalculate XOR checksum in a RawCOPPER trailer
+  removed_xor_chksum ^= *(buf_to + m_reduced_rawcpr.tmp_header.POS_NWORDS);
+  removed_xor_chksum ^= *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_1ST_FINESSE);
+  removed_xor_chksum ^= *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_2ND_FINESSE);
+  removed_xor_chksum ^= *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_3RD_FINESSE);
+  removed_xor_chksum ^= *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_4TH_FINESSE);
+
+  //
+  // Apply changes followed by data size reduction
+  //
+  *(buf_to + m_reduced_rawcpr.tmp_header.POS_NWORDS) = nwords_buf_to;
+  *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_1ST_FINESSE) = pos_nwords_finesse[ 0 ];
+  *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_2ND_FINESSE) = pos_nwords_finesse[ 1 ];
+  *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_3RD_FINESSE) = pos_nwords_finesse[ 2 ];
+  *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_4TH_FINESSE) = pos_nwords_finesse[ 3 ];
+
+  // Recalculate XOR checksum in a RawCOPPER trailer
+  removed_xor_chksum ^= *(buf_to + m_reduced_rawcpr.tmp_header.POS_NWORDS);
+  removed_xor_chksum ^= *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_1ST_FINESSE);
+  removed_xor_chksum ^= *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_2ND_FINESSE);
+  removed_xor_chksum ^= *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_3RD_FINESSE);
+  removed_xor_chksum ^= *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_4TH_FINESSE);
+
+  // Recalculate XOR checksum in a RawCOPPER trailer
+  unsigned int new_rawcopper_chksum = CalcXORChecksum(buf_to, pos_nwords_to - tmp_trailer.GetTrlNwords());
+
+
+  if ((old_rawcopper_chksum ^ removed_xor_chksum) != new_rawcopper_chksum) {
+    char err_buf[500];
+    sprintf(err_buf,
+            "[FATAL] ERROR_EVENT : RawCOPPER XOR checksum is inconsistent between before/after data reduction.(%.8x != %.8x ^ %.8x = %.8x ) Exiting...\n %s %s %d\n",
+            new_rawcopper_chksum,  old_rawcopper_chksum, removed_xor_chksum, old_rawcopper_chksum ^ removed_xor_chksum,
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf); // to reduce multiple error messages
+  }
+
+  *(buf_to + pos_nwords_to - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM) = new_rawcopper_chksum;
+
+
+
+  //
+  // data block # check
+  //
+  m_reduced_rawcpr.SetBuffer(buf_to, nwords_buf_to, 0, GetNumEvents(), GetNumNodes());
+  if (m_reduced_rawcpr.GetNumEvents() * m_reduced_rawcpr.GetNumNodes() <= 0) {
+    char err_buf[500];
+    sprintf(err_buf, "Invalid data block numbers.(# of events %d, # of nodes %d) Exiting...\n",
+            m_reduced_rawcpr.GetNumEvents(), m_reduced_rawcpr.GetNumNodes());
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  //
+  // check no-data buffer
+  //
+  for (int i = 0; i < m_reduced_rawcpr.GetNumEvents() * m_reduced_rawcpr.GetNumNodes(); i++) {
+    int nonzero_finesse_buf = 0;
+    for (int j = 0; j < 4; j++) {
+
+      if (GetFINESSENwords(n, j) > 0) {
+        //        m_reduced_rawcpr.CheckCRC16(i, j);
+        nonzero_finesse_buf++;
+      }
+    }
+    if (nonzero_finesse_buf == 0) {
+      char err_buf[500];
+      sprintf(err_buf, "No non-zero FINESSE buffer. Exiting...\n");
+      printf("%s", err_buf); fflush(stdout);
+      B2FATAL(err_buf);
+    }
+  }
+
+  //    post_rawcopper_latest.CheckCRC16(0, 0);
+  //       printf("fROM =======================================\n");
+  //       for (int k = 0; k < nwords_buf_to; k++) {
+  //  printf(" %.8x", GetBuffer(n)[ k ]);
+  //  if ( ( k + 1 ) % 10 == 0) {
+  //    printf("\n");
+  //  }
+  //       }
+  //       printf("\n");
+
+  //       printf("tO   =======================================\n");
+  //       for (int k = 0; k < nwords_buf_to; k++) {
+  //  printf(" %.8x", buf_to[ k ]);
+  //  if ( ( k + 1 ) % 10 == 0) {
+  //    printf("\n");
+  //  }
+  //       }
+  //       printf("\n");
+  //       printf("=============================================\n");
+  return pos_nwords_to;
+}
+
+
+int PreRawCOPPERFormat_latest::CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords)
+{
+
+  if ((finesse_buf[ POS_MAGIC_B2LHSLB ] & 0xFFFF0000) == B2LHSLB_HEADER_MAGIC &&
+      ((finesse_buf[ finesse_nwords - SIZE_B2LHSLB_TRAILER + POS_CHKSUM_B2LHSLB ] & 0xFFFF0000)
+       == B2LHSLB_TRAILER_MAGIC)) {
+    return 1;
+  } else {
+    PrintData(m_buffer, m_nwords);
+    char err_buf[500];
+    sprintf(err_buf,
+            "Invalid B2LHSLB magic words : header 0x%x (= should be ffaa**** ) or trailer 0x%x (= should be ff55**** ). Exiting... :%s %s %d\n",
+            finesse_buf[ POS_MAGIC_B2LHSLB ],
+            finesse_buf[ finesse_nwords - SIZE_B2LHSLB_TRAILER + POS_CHKSUM_B2LHSLB ],
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+#ifndef NO_ERROR_STOP
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+#endif
+  }
+}
+
+
+
+int PreRawCOPPERFormat_latest::CheckCRC16(int n, int finesse_num)
+{
+  //
+  // Calculate CRC16
+  //
+  int* buf = GetFINESSEBuffer(n, finesse_num) +  SIZE_B2LHSLB_HEADER;
+  int nwords = GetFINESSENwords(n, finesse_num) - (SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER);
+  unsigned short temp_crc16 = CalcCRC16LittleEndian(0xffff, buf, nwords);
+
+  //
+  // Compare CRC16 with B2LCRC16
+  //
+  buf = GetFINESSEBuffer(n, finesse_num) +  GetFINESSENwords(n, finesse_num)
+        - ((SIZE_B2LFEE_TRAILER - POS_CHKSUM_B2LFEE) + SIZE_B2LHSLB_TRAILER) ;
+
+  if ((unsigned short)(*buf & 0xFFFF) != temp_crc16) {
+    PrintData(GetBuffer(n), *(GetBuffer(n) + tmp_header.POS_NWORDS));
+    printf("[FATAL] ERROR_EVENT : PRE CRC16 error : slot %c B2LCRC16 %x Calculated CRC16 %x : Nwords of FINESSE buf %d\n",
+           65 + finesse_num, *buf , temp_crc16, GetFINESSENwords(n, finesse_num));
+    int* temp_buf = GetFINESSEBuffer(n, finesse_num);
+    for (int k = 0; k <  GetFINESSENwords(n, finesse_num); k++) {
+      printf("%.8x ", temp_buf[ k ]);
+      if ((k + 1) % 10 == 0) {
+        printf("\n");
+      }
+    }
+    printf("\n");
+    fflush(stdout);
+    char err_buf[500];
+    sprintf(err_buf,
+            "[FATAL] ERROR_EVENT : B2LCRC16 (%.4x) differs from one ( %.4x) calculated by PreRawCOPPERfromat class. Exiting...\n %s %s %d\n",
+            (unsigned short)(*buf & 0xFFFF), temp_crc16,
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf); // to reduce multiple error messages
+  }
+  return 1;
+
+}
+
+int* PreRawCOPPERFormat_latest::PackDetectorBuf(int* packed_buf_nwords,
+                                                int* detector_buf_1st, int nwords_1st,
+                                                int* detector_buf_2nd, int nwords_2nd,
+                                                int* detector_buf_3rd, int nwords_3rd,
+                                                int* detector_buf_4th, int nwords_4th,
+                                                RawCOPPERPackerInfo rawcpr_info)
+{
+  int* packed_buf = NULL;
+
+  int poswords_to = 0;
+  int* detector_buf[ 4 ] = { detector_buf_1st, detector_buf_2nd, detector_buf_3rd, detector_buf_4th };
+  int nwords[ 4 ] = { nwords_1st, nwords_2nd, nwords_3rd, nwords_4th };
+
+  // calculate the event length
+  int length_nwords = tmp_header.GetHdrNwords() + SIZE_COPPER_HEADER + SIZE_COPPER_TRAILER + tmp_trailer.GetTrlNwords();
+
+  for (int i = 0; i < 4; i++) {
+    if (detector_buf[ i ] == NULL || nwords[ i ] <= 0) continue;    // for an empty FINESSE slot
+    length_nwords += nwords[ i ];
+    length_nwords += SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER
+                     + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
+  }
+
+  // allocate buffer
+  packed_buf = new int[ length_nwords ];
+  memset(packed_buf, 0, sizeof(int) * length_nwords);
+
+  //
+  // Fill RawHeader
+  //
+  tmp_header.SetBuffer(packed_buf);
+
+  packed_buf[ tmp_header.POS_NWORDS ] = length_nwords; // total length
+  packed_buf[ tmp_header.POS_VERSION_HDRNWORDS ] = 0x7f7f8000
+                                                   | ((DATA_FORMAT_VERSION << tmp_header.FORMAT_VERSION_SHIFT) & tmp_header.FORMAT_VERSION__MASK)
+                                                   | tmp_header.RAWHEADER_NWORDS; // ver.#, header length
+  packed_buf[ tmp_header.POS_EXP_RUN_NO ] = (rawcpr_info.exp_num << tmp_header.EXP_SHIFT)
+                                            | (rawcpr_info.run_subrun_num & 0x003FFFFF);   // exp. and run #
+  packed_buf[ tmp_header.POS_EVE_NO ] = rawcpr_info.eve_num; // eve #
+  packed_buf[ tmp_header.POS_TTCTIME_TRGTYPE ] = (rawcpr_info.tt_ctime & 0x7FFFFFF) << 4;   // tt_ctime
+  packed_buf[ tmp_header.POS_TTUTIME ] = rawcpr_info.tt_utime; // tt_utime
+  packed_buf[ tmp_header.POS_NODE_ID ] = rawcpr_info.node_id; // node ID
+
+
+
+
+  // fill the positions of finesse buffers
+  packed_buf[ tmp_header.POS_OFFSET_1ST_FINESSE ] = tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
+
+  packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_1ST_FINESSE ];
+  if (nwords[ 0 ] > 0) {
+    packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ] +=
+      nwords[ 0 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER  + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
+  }
+
+  packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ];
+  if (nwords[ 1 ] > 0) {
+    packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ] +=
+      nwords[ 1 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER  + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
+  }
+
+  packed_buf[ tmp_header.POS_OFFSET_4TH_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ];
+  if (nwords[ 2 ] > 0) {
+    packed_buf[ tmp_header.POS_OFFSET_4TH_FINESSE ] += nwords[ 2 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER  + SIZE_B2LFEE_TRAILER +
+                                                       SIZE_B2LHSLB_TRAILER;
+  }
+  poswords_to += tmp_header.GetHdrNwords();
+
+  // Fill COPPER header
+  packed_buf[ poswords_to + POS_MAGIC_COPPER_1 ] = COPPER_MAGIC_DRIVER_HEADER;
+  packed_buf[ poswords_to + POS_MAGIC_COPPER_2 ] = COPPER_MAGIC_FPGA_HEADER;
+  packed_buf[ poswords_to + POS_EVE_NUM_COPPER ] = rawcpr_info.eve_num;
+
+  int size_b2l_hdrtrl = SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
+  if (nwords[ 0 ] != 0)  packed_buf[ poswords_to + POS_CH_A_DATA_LENGTH ] = nwords[ 0 ] + size_b2l_hdrtrl;
+  if (nwords[ 1 ] != 0)  packed_buf[ poswords_to + POS_CH_B_DATA_LENGTH ] = nwords[ 1 ] + size_b2l_hdrtrl;
+  if (nwords[ 2 ] != 0)  packed_buf[ poswords_to + POS_CH_C_DATA_LENGTH ] = nwords[ 2 ] + size_b2l_hdrtrl;
+  if (nwords[ 3 ] != 0)  packed_buf[ poswords_to + POS_CH_D_DATA_LENGTH ] = nwords[ 3 ] + size_b2l_hdrtrl;
+
+  packed_buf[ poswords_to + POS_DATA_LENGTH ] =
+    packed_buf[ poswords_to + POS_CH_A_DATA_LENGTH ] +
+    packed_buf[ poswords_to + POS_CH_B_DATA_LENGTH ] +
+    packed_buf[ poswords_to + POS_CH_C_DATA_LENGTH ] +
+    packed_buf[ poswords_to + POS_CH_D_DATA_LENGTH ] +
+    (SIZE_COPPER_HEADER - SIZE_COPPER_DRIVER_HEADER) +
+    (SIZE_COPPER_TRAILER - SIZE_COPPER_DRIVER_TRAILER);
+
+  poswords_to += SIZE_COPPER_HEADER;
+
+  // Fill FINESSE buffer
+  for (int i = 0; i < 4; i++) {
+
+    if (detector_buf[ i ] == NULL || nwords[ i ] <= 0) continue;     // for an empty FINESSE slot
+
+    // Fill b2link HSLB header
+    packed_buf[ poswords_to + POS_MAGIC_B2LHSLB ] = 0xffaa0000 | (0xffff & rawcpr_info.eve_num);
+    poswords_to += SIZE_B2LHSLB_HEADER;
+    int* crc16_start = &(packed_buf[ poswords_to ]);
+
+    // Fill b2link FEE header
+
+    packed_buf[ poswords_to + POS_TT_CTIME_TYPE ] = (rawcpr_info.tt_ctime & 0x7FFFFFF) << 4;
+    unsigned int temp_ctime_type = packed_buf[ poswords_to + POS_TT_CTIME_TYPE ];
+    packed_buf[ poswords_to + POS_TT_TAG ] = rawcpr_info.eve_num;
+    packed_buf[ poswords_to + POS_TT_UTIME ] = rawcpr_info.tt_utime;
+    packed_buf[ poswords_to + POS_EXP_RUN ] = (rawcpr_info.exp_num << tmp_header.EXP_SHIFT) | (rawcpr_info.run_subrun_num &
+                                              0x003FFFFF);   // exp. and run #
+    packed_buf[ poswords_to + POS_B2L_CTIME ] = (rawcpr_info.b2l_ctime & 0x7FFFFFF) << 4;
+    poswords_to += SIZE_B2LFEE_HEADER;
+
+    // copy the 1st Detector Buffer
+    memcpy(packed_buf + poswords_to, detector_buf[ i ], nwords[ i ]*sizeof(int));
+    poswords_to += nwords[ i ];
+
+    // Fill b2link b2tt-tag trailer
+    packed_buf[ poswords_to + POS_TT_CTIME_B2LFEE ] = temp_ctime_type;
+
+    // Fill b2link FEE trailer
+    unsigned short crc16 = CalcCRC16LittleEndian(0xffff, crc16_start, nwords[ i ] + SIZE_B2LFEE_HEADER);
+    packed_buf[ poswords_to + POS_CHKSUM_B2LFEE ] = ((0xffff & rawcpr_info.eve_num) << 16) | (crc16 & 0xffff);
+    poswords_to += SIZE_B2LFEE_TRAILER;
+
+    // Fill b2link HSLB trailer
+    packed_buf[ poswords_to + POS_CHKSUM_B2LHSLB ] = 0xff550000;
+    poswords_to += SIZE_B2LHSLB_TRAILER;
+
+  }
+
+  // Fill COPPER trailer
+  packed_buf[ poswords_to + POS_MAGIC_COPPER_3 ] = COPPER_MAGIC_FPGA_TRAILER;
+  packed_buf[ poswords_to + POS_MAGIC_COPPER_4 ] = COPPER_MAGIC_DRIVER_TRAILER;
+  unsigned int chksum = 0;
+  for (int i = tmp_header.GetHdrNwords(); i < poswords_to + (SIZE_COPPER_TRAILER - SIZE_COPPER_DRIVER_TRAILER); i++) {
+    chksum ^= packed_buf[ i ];
+  }
+  packed_buf[ poswords_to + POS_CHKSUM_COPPER ] = chksum;
+  poswords_to += SIZE_COPPER_TRAILER;
+
+  // Calculate RawCOPPER checksum and fill RawTrailer
+  chksum = 0;
+  for (int i = 0; i < poswords_to; i++) {
+    chksum ^= packed_buf[ i ];
+  }
+  packed_buf[ poswords_to + tmp_trailer.POS_CHKSUM ] = chksum;
+
+  packed_buf[ poswords_to + tmp_trailer.POS_TERM_WORD ] = tmp_trailer.MAGIC_WORD_TERM_TRAILER;
+  poswords_to += tmp_trailer.GetTrlNwords();
+
+  *packed_buf_nwords = poswords_to;
+  return packed_buf;
+}
+
diff --git a/ROPCApplications/rawdata/dataobjects/src/PreRawCOPPERFormat_v1.cc b/ROPCApplications/rawdata/dataobjects/src/PreRawCOPPERFormat_v1.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6239e82a5c3978ac363ca32c7d4365b21e71e6aa
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/PreRawCOPPERFormat_v1.cc
@@ -0,0 +1,1216 @@
+//+
+// File : PreRawCOPPERFormat_v1.cc
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/PreRawCOPPERFormat_v1.h>
+
+
+using namespace std;
+using namespace Belle2;
+
+//#define DESY
+//#define NO_DATA_CHECK
+//#define WO_FIRST_EVENUM_CHECK
+
+//ClassImp(PreRawCOPPERFormat_v1);
+
+PreRawCOPPERFormat_v1::PreRawCOPPERFormat_v1()
+{
+}
+
+PreRawCOPPERFormat_v1::~PreRawCOPPERFormat_v1()
+{
+}
+
+
+// int PreRawCOPPERFormat_v1::GetBufferPos(int n)
+// {
+//   if (m_buffer == NULL || m_nwords <= 0) {
+//     char err_buf[500];
+//     sprintf(err_buf, "[DEBUG] [ERROR] RawPacket buffer(%p) is not available or length(%d) is not set.\n %s %s %d\n",
+//             m_buffer, m_nwords, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     printf("%s", err_buf); fflush(stdout);
+//     string err_str = err_buf;     throw (err_str);
+//   }
+
+//   if (n >= (m_num_events * m_num_nodes)) {
+//     char err_buf[500];
+//     sprintf(err_buf, "[DEBUG] Invalid COPPER block No. (%d : max %d ) is specified. Exiting... \n %s %s %d\n",
+//             n, (m_num_events * m_num_nodes), __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     printf("%s", err_buf); fflush(stdout);
+//     string err_str = err_buf;     throw (err_str);
+
+//   }
+//   int pos_nwords = 0;
+//   for (int i = 1; i <= n ; i++) {
+//     int size = tmp_header.RAWHEADER_NWORDS
+//                + m_buffer[ pos_nwords + tmp_header.RAWHEADER_NWORDS + POS_DATA_LENGTH ]
+//                + SIZE_COPPER_DRIVER_HEADER
+//                + SIZE_COPPER_DRIVER_TRAILER
+//                + tmp_trailer.RAWTRAILER_NWORDS;
+//     // COPPER's data length include one word from COPPER trailer. so -1 is needed.
+//     pos_nwords +=  size;
+//     if (pos_nwords >= m_nwords) {
+//       char err_buf[500];
+
+//       sprintf(err_buf, "CORRUPTED DATA: value of pos_nwords(%d) is larger than m_nwords(%d). Exiting...\n %s %s %d\n",
+//               pos_nwords, m_nwords, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//       printf("%s", err_buf); fflush(stdout);
+//       string err_str = err_buf;     throw (err_str);
+//       //      exit(1);
+//     }
+//   }
+//   return pos_nwords;
+// }
+
+
+
+unsigned int PreRawCOPPERFormat_v1::CalcDriverChkSum(int n)
+{
+  int min = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS;
+  int max = GetBufferPos(n) + GetBlockNwords(n)
+            - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
+  unsigned int chksum = 0;
+  for (int i = min; i < max; i++) {
+    chksum ^= m_buffer[ i ];
+  }
+  return chksum;
+}
+
+
+
+int PreRawCOPPERFormat_v1::GetDetectorNwords(int n, int finesse_num)
+{
+
+  int nwords = 0;
+  if (GetFINESSENwords(n, finesse_num) > 0) {
+    nwords = GetFINESSENwords(n, finesse_num)
+             - (SIZE_B2LHSLB_HEADER + SIZE_B2LHSLB_TRAILER +  SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER);
+  }
+  return nwords;
+
+}
+
+
+int PreRawCOPPERFormat_v1::GetFINESSENwords(int n, int finesse_num)
+{
+  if (!CheckCOPPERMagic(n)) {
+    char err_buf[500];
+    PrintData(m_buffer, m_nwords);
+    sprintf(err_buf,
+            "[ERROR] COPPER's magic word is invalid. Exiting... Maybe it is due to data corruption or different version of the data format.\n %s %s %d\n",
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+  int pos_nwords;
+  switch (finesse_num) {
+    case 0 :
+      pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_CH_A_DATA_LENGTH;
+      break;
+    case 1 :
+      pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_CH_B_DATA_LENGTH;
+      break;
+    case 2 :
+      pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_CH_C_DATA_LENGTH;
+      break;
+    case 3 :
+      pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_CH_D_DATA_LENGTH;
+      break;
+    default :
+      char err_buf[500];
+      sprintf(err_buf, "Specifined FINESSE number( = %d ) is invalid. Exiting...\n %s %s %d\n",
+              finesse_num, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      B2FATAL(err_buf);
+  }
+  return m_buffer[ pos_nwords ];
+
+}
+
+
+unsigned int PreRawCOPPERFormat_v1::GetB2LFEE32bitEventNumber(int n)
+{
+
+#ifndef READ_OLD_B2LFEE_FORMAT_FILE
+
+  int err_flag = 0;
+  unsigned int eve_num = 0;
+  int flag = 0;
+  unsigned int eve[4];
+  for (int i = 0; i < 4 ; i++) {
+    eve[ i ] = 12345678;
+    if (GetFINESSENwords(n, i) > 0) {
+      int pos_nwords = GetOffsetFINESSE(n, i) + SIZE_B2LHSLB_HEADER + POS_TT_TAG;
+      eve[ i ] = m_buffer[ pos_nwords ];
+      if (flag != 1) eve_num = eve[ i ];
+      if (eve_num != eve[ i ]) err_flag = 1;
+      flag = 1;
+    }
+  }
+
+  if (flag == 0) {
+    PrintData(m_buffer, m_nwords);
+    char err_buf[500];
+    sprintf(err_buf, "No HSLB data in COPPER data. Exiting...\n%s %s %d\n",
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  if (err_flag == 1) {
+    PrintData(m_buffer, m_nwords);
+    char err_buf[500];
+    sprintf(err_buf, "CORRUPTED DATA: Different event number over HSLBs : slot A 0x%x : B 0x%x :C 0x%x : D 0x%x\n%s %s %d\n",
+            eve[ 0 ], eve[ 1 ], eve[ 2 ], eve[ 3 ],
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("[DEBUG] [ERROR] %s\n", err_buf); fflush(stdout);
+#ifndef NO_DATA_CHECK
+    B2FATAL(err_buf);
+#endif //NO_DATA_CHECK
+  }
+  return eve_num;
+
+#else // READ_OLD_B2LFEE_FORMAT_FILE
+
+  char err_buf[500];
+  sprintf(err_buf, "You need comment out READ_OLD_B2LFEE_FORMAT_FILE if you are handling a new data format\n%s %s %d\n",
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+
+#endif // READ_OLD_B2LFEE_FORMAT_FILE
+
+}
+
+
+void PreRawCOPPERFormat_v1::CheckData(int n,
+                                      unsigned int prev_evenum, unsigned int* cur_evenum_rawcprhdr,
+                                      unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
+                                      unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+{
+
+  char err_buf[500];
+  sprintf(err_buf,
+          "This function for format ver.1 is not supported. (n %d preveve %u eve %u  prectr %u ctr %u prevrun %u run %u) Exiting...\n %s %s %d\n",
+          n, prev_evenum, *cur_evenum_rawcprhdr, prev_copper_ctr, *cur_copper_ctr,
+          prev_exprunsubrun_no, *cur_exprunsubrun_no,
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+
+//   char err_buf[500];
+//   int err_flag = 0;
+//   //
+//   // check Magic words
+//   //
+//   if (!CheckCOPPERMagic(n)) {
+//     sprintf(err_buf, "CORRUPTED DATA: Invalid Magic word 0x7FFFF0008=%u 0xFFFFFAFA=%u 0xFFFFF5F5=%u 0x7FFF0009=%u\n%s %s %d\n",
+//             GetMagicDriverHeader(n),
+//             GetMagicFPGAHeader(n),
+//             GetMagicFPGATrailer(n),
+//             GetMagicDriverTrailer(n),
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     err_flag = 1;
+//   }
+
+//   //
+//   // Event # check
+//   //
+//   *cur_evenum_rawcprhdr = GetEveNo(n);
+//   unsigned int evenum_feehdr = GetB2LFEE32bitEventNumber(n);
+//   if (*cur_evenum_rawcprhdr != evenum_feehdr) {
+//     sprintf(err_buf,
+//             "CORRUPTED DATA: Event # in PreRawCOPPERFormat_v1 header and FEE header is different : cprhdr 0x%x feehdr 0x%x : Exiting...\n%s %s %d\n",
+//             *cur_evenum_rawcprhdr, evenum_feehdr,
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     err_flag = 1;
+//   }
+
+//   //
+//   // Check incrementation of event #
+//   //
+//   *cur_runsubrun_no = GetRunNoSubRunNo(n);
+//   if (
+// #ifdef WO_FIRST_EVENUM_CHECK
+//     prev_evenum != 0xFFFFFFFF && *cur_evenum_rawcprhdr != 0
+// #else
+//     prev_runsubrun_no == *cur_runsubrun_no && prev_runsubrun_no >= 0
+// #endif
+//   ) {
+//     if ((unsigned int)(prev_evenum + 1) != *cur_evenum_rawcprhdr) {
+//       sprintf(err_buf, "CORRUPTED DATA: Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n%s %s %d\n",
+//               n, prev_evenum, *cur_evenum_rawcprhdr,
+//               __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//       err_flag = 1;
+//     }
+//   }
+
+
+//   *cur_copper_ctr = GetCOPPERCounter(n);
+//   if (
+// #ifdef WO_FIRST_EVENUM_CHECK
+//     prev_copper_ctr != 0xFFFFFFFF
+// #else
+//     true
+// #endif
+//   ) {
+//     if ((unsigned int)(prev_copper_ctr + 1) != *cur_copper_ctr) {
+//       sprintf(err_buf, "COPPER counter jump : i %d prev 0x%x cur 0x%x :\n%s %s %d\n",
+//               n, prev_copper_ctr, *cur_copper_ctr,
+//               __FILE__, __PRETTY_FUNCTION__, __LINE__);
+
+// #ifdef DESY
+//       //
+//       // In DESY test, we ignore this error
+//       //
+//       printf("[DEBUG] [INFO] %s", err_buf);
+// #else
+//       err_flag = 1;
+// #endif
+
+//     }
+//   }
+
+//   //
+//   // Check is utime and ctime_trgtype same over different FINESSE data
+//   //
+//   CheckUtimeCtimeTRGType(n);
+
+
+//   //
+//   // Check checksum calculated by COPPER driver
+//   //
+//   if (GetDriverChkSum(n) != CalcDriverChkSum(n)) {
+//     sprintf(err_buf,
+//             "CORRUPTED DATA: COPPER driver checkSum error : block %d : length %d eve 0x%x : Trailer chksum 0x%.8x : calcd. now 0x%.8x\n%s %s %d\n",
+//             n,
+//             GetBlockNwords(n),
+//             *cur_evenum_rawcprhdr,
+//             GetDriverChkSum(n),
+//             CalcDriverChkSum(n),
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     err_flag = 1;
+//   }
+
+
+//   //
+//   // Check checksum calculated by DeSerializerCOPPER()
+//   //
+//   tmp_trailer.SetBuffer(GetRawTrlBufPtr(n));
+//   unsigned int xor_chksum = CalcXORChecksum(GetBuffer(n), GetBlockNwords(n) - tmp_trailer.GetTrlNwords());
+//   if (tmp_trailer.GetChksum() != xor_chksum) {
+//     sprintf(err_buf,
+//             "CORRUPTED DATA: PreRawCOPPERFormat_v1 checksum error : block %d : length %d eve 0x%x : Trailer chksum 0x%.8x : calcd. now 0x%.8x\n %s %s %d\n",
+//             n, GetBlockNwords(n), *cur_evenum_rawcprhdr, tmp_trailer.GetChksum(), xor_chksum,
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     err_flag = 1;
+//   }
+
+
+// #ifdef DEBUG
+//   printf("[DEBUG] eve %d %d %d %d %d\n",
+//          GetEveNo(n),
+//          Get1stDetectorNwords(n),
+//          Get2ndDetectorNwords(n),
+//          Get3rdDetectorNwords(n),
+//          Get4thDetectorNwords(n)
+//         );
+//   printf("[DEBUG] ===COPPER BLOCK==============\n");
+//   printData(GetBuffer(n), GetBlockNwords(n));
+
+//   printf("[DEBUG] ===FINNESSE A ==============\n");
+//   printData(Get1stDetectorBuffer(n), Get1stDetectorNwords(n));
+
+//   printf("[DEBUG] ===FINNESSE B ==============\n");
+//   printData(Get2ndDetectorBuffer(n), Get2ndDetectorNwords(n));
+
+//   printf("[DEBUG] ===FINNESSE C ==============\n");
+//   printData(Get3rdDetectorBuffer(n), Get3rdDetectorNwords(n));
+
+//   printf("[DEBUG] ===FINNESSE D ==============\n");
+//   printData(Get4thDetectorBuffer(n), Get4thDetectorNwords(n));
+//   printf("[DEBUG] === END ==============\n");
+
+// #endif
+
+//   if (err_flag == 1) {
+//     printf("[DEBUG] ========== dump a data blcok : block # %d==========\n", n);
+//     PrintData(GetBuffer(n), GetBlockNwords(n));
+//     printf("%s", err_buf); fflush(stdout);
+//     string err_str = err_buf;
+//     throw (err_str);
+
+//     //     sleep(1234567);
+//     //     exit(-1);
+//   }
+
+  return;
+
+}
+
+bool PreRawCOPPERFormat_v1::CheckCOPPERMagic(int n)
+{
+  if (GetMagicDriverHeader(n) != COPPER_MAGIC_DRIVER_HEADER) {
+    return false;
+  } else if (GetMagicFPGAHeader(n) != COPPER_MAGIC_FPGA_HEADER) {
+    return false;
+  } else if (GetMagicFPGATrailer(n) != COPPER_MAGIC_FPGA_TRAILER) {
+    return false;
+  } else if (GetMagicDriverTrailer(n) != COPPER_MAGIC_DRIVER_TRAILER) {
+    return false;
+  }
+  return true;
+}
+
+void PreRawCOPPERFormat_v1::CheckUtimeCtimeTRGType(int n)
+{
+
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+  CheckB2LFEEHeaderVersion(n);
+#endif
+  int err_flag = 0;
+  int flag = 0;
+  unsigned int temp_utime = 0, temp_ctime_trgtype = 0;
+  unsigned int utime[4], ctime_trgtype[4];
+  memset(utime, 0, sizeof(utime));
+  memset(ctime_trgtype, 0, sizeof(ctime_trgtype));
+
+  for (int i = 0; i < 4; i++) {
+    if (GetFINESSENwords(n, i) > 0) {
+      ctime_trgtype[ i ] = m_buffer[ GetOffsetFINESSE(n, i) +
+                                     SIZE_B2LHSLB_HEADER + POS_TT_CTIME_TYPE ];
+      utime[ i ] = m_buffer[ GetOffsetFINESSE(n, i) +
+                             SIZE_B2LHSLB_HEADER + POS_TT_UTIME ];
+      if (flag == 0) {
+        temp_ctime_trgtype = ctime_trgtype[ i ];
+        temp_utime = utime[ i ];
+        flag = 1;
+      } else {
+        if (temp_ctime_trgtype != ctime_trgtype[ i ]
+            || temp_utime != utime[ i ]) {
+          err_flag = 1;
+        }
+      }
+    }
+  }
+
+  if (err_flag != 0) {
+    for (int i = 0; i < 4; i++) {
+      printf("[DEBUG] FINESSE #=%d buffsize %d ctimeTRGtype 0x%.8x utime 0x%.8x\n",
+             i, GetFINESSENwords(n, i), ctime_trgtype[ i ], utime[ i ]);
+    }
+    char err_buf[500];
+    sprintf(err_buf, "CORRUPTED DATA: mismatch over FINESSEs. Exiting...\n %s %s %d\n",
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+  return;
+}
+
+
+unsigned int PreRawCOPPERFormat_v1::FillTopBlockRawHeader(unsigned int m_node_id, unsigned int prev_eve32,
+                                                          unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+{
+
+  char err_buf[500];
+  sprintf(err_buf,
+          "This function for format ver.1 is not supported. (node %.8x preveve %u prevrun %u currun %u ) Exiting...\n %s %s %d\n",
+          m_node_id, prev_eve32, prev_exprunsubrun_no, *cur_exprunsubrun_no,
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+
+  return 0xffffffff;
+
+//   const int datablock_id = 0;
+//   //  m_temp_value = 12345678;
+//   //
+//   // This function only fills RawHeader contents for the first datablock.
+//   // # of block should be 1
+//   if (m_num_nodes * m_num_events != 1) {
+//     char err_buf[500];
+//     sprintf(err_buf,
+//             "This function should be used for PreRawCOPPERFormat_v1 containing only one datablock, while. this object has num_nodes of %d and num_events of %d\n %s %s %d\n",
+//             m_num_nodes, m_num_events,  __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     printf("%s", err_buf); fflush(stdout);
+//     string err_str = err_buf;    throw (err_str);
+
+//   }
+
+//   //////////////////////////////////////////////////
+//   //
+//   // Fill info in RawHeader
+//   //
+//   //////////////////////////////////////////////////
+
+//   //
+//   // Initialize a RawHeader part
+//   //
+//   memset(m_buffer, 0, sizeof(int) * tmp_header.RAWHEADER_NWORDS);
+//   m_buffer[ tmp_header.POS_VERSION_HDRNWORDS ] = tmp_header.RAWHEADER_NWORDS & tmp_header.HDR_NWORDS_MASK;
+//   m_buffer[ tmp_header.POS_VERSION_HDRNWORDS ] |= (DATA_FORMAT_VERSION << tmp_header.FORMAT_VERSION_SHIFT) &
+//                                                   tmp_header.FORMAT_VERSION__MASK;
+//   m_buffer[ tmp_header.POS_VERSION_HDRNWORDS ] |= (0x80 << tmp_header.FORMAT_VERSION_SHIFT);   // PreFormat
+//   m_buffer[ tmp_header.POS_VERSION_HDRNWORDS ] |= tmp_header.MAGIC_WORD;
+
+//   //
+//   // Check FINESSEs which containes data
+//   //
+//   int* copper_buf = &(m_buffer[ tmp_header.RAWHEADER_NWORDS ]);
+//   if (copper_buf[ POS_CH_A_DATA_LENGTH ] == 0 &&
+//       copper_buf[ POS_CH_B_DATA_LENGTH ] == 0 &&
+//       copper_buf[ POS_CH_C_DATA_LENGTH ] == 0 &&
+//       copper_buf[ POS_CH_D_DATA_LENGTH ] == 0) {
+//     char err_buf[500];
+//     sprintf(err_buf,
+//             "No FINESSE data in a copper data block. Exiting...\n %s %s %d\n",
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     printf("%s", err_buf); fflush(stdout);
+//     string err_str = err_buf; throw (err_str);
+//     //     sleep(12345678);
+//     //     exit(-1);
+//   }
+
+//   //
+//   //   Set total words info
+//   //
+//   int datablock_nwords =
+//     tmp_header.RAWHEADER_NWORDS +
+//     (copper_buf[ POS_DATA_LENGTH ]
+//      + SIZE_COPPER_DRIVER_HEADER
+//      + SIZE_COPPER_DRIVER_TRAILER)
+//     + tmp_trailer.RAWTRAILER_NWORDS;
+//   m_buffer[ tmp_header.POS_NWORDS ] = datablock_nwords;
+
+
+//   //
+//   // Check the consistency between data length and length in RawHeader
+//   //
+//   if (m_buffer[ tmp_header.POS_NWORDS ] != m_nwords) {
+//     char err_buf[500];
+//     sprintf(err_buf,
+//             "CORRUPTED DATA: Data length is inconsistent m_nwords %d : nwords from COPPER data %d\n %s %s %d\n",
+//             m_nwords, m_buffer[ tmp_header.POS_NWORDS ],
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     printf("%s", err_buf); fflush(stdout);
+//     string err_str = err_buf; throw (err_str);
+//     //     sleep(12345678);
+//     //     exit(-1);
+//   }
+
+//   //
+//   // Fill offset values
+//   //
+//   int offset_1st_finesse =  tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
+//   int offset_2nd_finesse = offset_1st_finesse + copper_buf[ POS_CH_A_DATA_LENGTH ];
+//   int offset_3rd_finesse = offset_2nd_finesse + copper_buf[ POS_CH_B_DATA_LENGTH ];
+//   int offset_4th_finesse = offset_3rd_finesse + copper_buf[ POS_CH_C_DATA_LENGTH ];
+//   m_buffer[ tmp_header.POS_OFFSET_1ST_FINESSE ] = offset_1st_finesse;
+//   m_buffer[ tmp_header.POS_OFFSET_2ND_FINESSE ] = offset_2nd_finesse;
+//   m_buffer[ tmp_header.POS_OFFSET_3RD_FINESSE ] = offset_3rd_finesse;
+//   m_buffer[ tmp_header.POS_OFFSET_4TH_FINESSE ] = offset_4th_finesse;
+
+//   //
+//   // Fill Exp/Run value
+//   //
+//   int* finesse_buf = &
+//                      (m_buffer[ offset_1st_finesse ]); // In any finesse implementations, the top finesse buffer should be at offset_1st_finesse;
+//   m_buffer[ tmp_header.POS_EXP_RUN_NO ] = finesse_buf[ SIZE_B2LHSLB_HEADER + POS_EXP_RUN ];
+
+
+//   //
+//   // Fill event #
+//   //
+//   unsigned int cur_ftsw_eve32 =  finesse_buf[ SIZE_B2LHSLB_HEADER + POS_TT_TAG ];
+//   m_buffer[ tmp_header.POS_EVE_NO ] = cur_ftsw_eve32;
+
+//   //
+//   // Copy FTSW words from B2LFEE header
+//   //
+//   m_buffer[ tmp_header.POS_TTCTIME_TRGTYPE ] = finesse_buf[ SIZE_B2LHSLB_HEADER + POS_TT_CTIME_TYPE ];
+//   m_buffer[ tmp_header.POS_TTUTIME ] = finesse_buf[ SIZE_B2LHSLB_HEADER + POS_TT_UTIME ];
+
+//   //
+//   // Set node ID, trunc_mask, data_type
+//   //
+//   m_buffer[ tmp_header.POS_NODE_ID ] = m_node_id;
+//   m_buffer[ tmp_header.POS_TRUNC_MASK_DATATYPE ] = ((m_trunc_mask << 31) & 0x80000000) | (m_data_type & 0x7FFFFFFF);
+
+
+//   //////////////////////////////////////////////////
+//   //
+//   // Fill info in RawTrailer
+//   //
+//   //////////////////////////////////////////////////
+
+//   //
+//   // Calculate XOR checksum
+//   //
+//   unsigned int chksum_top = 0, chksum_body = 0, chksum_bottom = 0;
+
+//   int top_end = tmp_header.RAWHEADER_NWORDS;
+//   for (int i = 0; i < top_end; i++) {
+//     chksum_top ^= m_buffer[ i ];
+//   }
+//   int body_end = datablock_nwords - SIZE_COPPER_DRIVER_TRAILER - tmp_trailer.RAWTRAILER_NWORDS;
+//   for (int i = top_end; i < body_end; i++) {
+//     chksum_body ^= m_buffer[ i ];
+//   }
+
+//   int bottom_end = datablock_nwords - tmp_trailer.RAWTRAILER_NWORDS;
+//   for (int i = body_end; i < bottom_end; i++) {
+//     chksum_bottom ^= m_buffer[ i ];
+//   }
+
+//   //
+//   // check COPPER driver checksum
+//   //
+//   if (chksum_body != (unsigned int)(m_buffer[ body_end ])) {
+//     char err_buf[500];
+//     sprintf(err_buf, "CORRUPTED DATA: COPPER driver checksum is not consistent.: calcd. %.8x data %.8x\n %s %s %d\n",
+//             chksum_body, m_buffer[ body_end ],
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     printf("%s", err_buf); fflush(stdout);
+//     string err_str = err_buf; throw (err_str);
+//     //     sleep(12345678);
+//     //     exit(-1);
+//   }
+
+//   //
+//   // Fill trailer info (checksum, magic word)
+//   //
+//   unsigned int chksum = chksum_top ^ chksum_body ^ chksum_bottom;
+//   int* trl = &(m_buffer[ datablock_nwords - tmp_trailer.RAWTRAILER_NWORDS ]);
+//   trl[ tmp_trailer.POS_CHKSUM ] = chksum;
+//   trl[ tmp_trailer.POS_TERM_WORD ] = tmp_trailer.MAGIC_WORD_TERM_TRAILER;
+
+
+//   //////////////////////////////////////////////////
+//   //
+//   // Data check ( magic word, event incrementation )
+//   //
+//   //////////////////////////////////////////////////
+
+
+//   //
+//   // check magic words
+//   //
+//   int* fpga_trailer_magic = trl - (SIZE_COPPER_TRAILER - POS_MAGIC_COPPER_3);
+//   int* driver_trailer_magic = trl - (SIZE_COPPER_TRAILER - POS_MAGIC_COPPER_4);
+//   int err_flag = 0;
+//   if ((unsigned int)(copper_buf[ POS_MAGIC_COPPER_1 ]) != COPPER_MAGIC_DRIVER_HEADER) {
+//     err_flag = 1;
+//   } else if ((unsigned int)(copper_buf[ POS_MAGIC_COPPER_2 ]) != COPPER_MAGIC_FPGA_HEADER) {
+//     err_flag = 1;
+//   } else if ((unsigned int)(*fpga_trailer_magic) != COPPER_MAGIC_FPGA_TRAILER) {
+//     err_flag = 1;
+//   } else if ((unsigned int)(*driver_trailer_magic) != COPPER_MAGIC_DRIVER_TRAILER) {
+//     err_flag = 1;
+//   }
+//   if (err_flag == 1) {
+//     char err_buf[500];
+//     sprintf(err_buf, "CORRUPTED DATA: Invalid Magic word 0x7FFFF0008=%u 0xFFFFFAFA=%u 0xFFFFF5F5=%u 0x7FFF0009=%u\n %s %s %d\n",
+//             GetMagicDriverHeader(datablock_id),
+//             GetMagicFPGAHeader(datablock_id),
+//             GetMagicFPGATrailer(datablock_id),
+//             GetMagicDriverTrailer(datablock_id),
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     printf("[DEBUG] [ERROR] %s\n", err_buf);
+// #ifndef NO_DATA_CHECK
+//     string err_str = err_buf; throw (err_str);
+
+//     //     sleep(12345678);
+//     //     exit(-1);
+// #endif
+//   }
+
+//   //
+//   // check incrementation of event #
+//   //
+
+//   if ((unsigned int)(prev_eve32 + 1) < 50) {
+// //     printf("#################EVE cur %.8x prev %.8x\n", cur_ftsw_eve32, prev_eve32);
+// //     fflush(stdout);
+//   }
+
+
+//   *cur_runsubrun_no = GetRunNoSubRunNo(datablock_id);
+//   if (prev_runsubrun_no == *cur_runsubrun_no && prev_runsubrun_no >= 0) {
+//     if (
+// #ifdef WO_FIRST_EVENUM_CHECK
+//       (prev_eve32 + 1 != cur_ftsw_eve32) && (prev_eve32 != 0xFFFFFFFF && cur_ftsw_eve32 != 0)
+// #else
+//       prev_eve32 + 1 != cur_ftsw_eve32
+// #endif
+//     ) {
+// #ifndef NO_DATA_CHECK
+//       char err_buf[500];
+//       sprintf(err_buf, "CORRUPTED DATA: Invalid event_number. Exiting...: cur 32bit eve %u preveve %u prun %d crun %d\n %s %s %d\n",
+//               cur_ftsw_eve32, prev_eve32,
+//               prev_runsubrun_no, *cur_runsubrun_no,
+//               __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//       printf("[DEBUG] [ERROR] %s\n", err_buf);
+
+//       string err_str = err_buf;
+//       printf("[DEBUG] i= %d : num entries %d : Tot words %d\n", 0 , GetNumEntries(), TotalBufNwords());
+//       PrintData(GetBuffer(datablock_id), TotalBufNwords());
+
+//       throw (err_str);
+//       //      exit(-1);
+// #endif
+
+//     }
+//   }
+
+//  return cur_ftsw_eve32;
+
+}
+
+
+
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+void PreRawCOPPERFormat_v1::CheckB2LFEEHeaderVersion(int n)
+{
+  int* temp_buf;
+  for (int i = 0; i < 4; i++) {
+    if (GetFINESSENwords(n, i) > 0) {
+      temp_buf = GetFINESSEBuffer(n, i);
+      if ((temp_buf[ 3 ] & 0x40000000) == 0) {
+#ifdef TEMP
+        // this word for exp/run
+        // old one (ver.1) used for SPring8 test in 2013
+        printf("[DEBUG] \033[31m");
+        printf("[DEBUG] ===Firmware ver. ERROR===\n ");
+        printf("[DEBUG] FTSW and b2tt firmwares was updated on Nov.22, 2013 and the header format attached by B2link was changed in the new firmwares.\n");
+        printf("[DEBUG] If you are going to take data now, Please update the firmware.\n");
+        printf("[DEBUG] For details, please see Nakao-san's e-mail [b2link_ml:0111] Re: [daq2ml:0159] beta version of trigger timing receiver firmware (b2tt) on bdaq SVN\n");
+        printf("[DEBUG] Or if you are going to read data taken before the update, please use basf2 software before svn rev. 7419\n");
+        printf("[DEBUG] About the format please see Nakao-san's B2GM slides(p. 13 and 15) http://kds.kek.jp/getFile.py/access?contribId=143&sessionId=38&resId=0&materialId=slides&confId=13911.\n");
+        printf("[DEBUG] Sorry for inconvenience.\n");
+        printf("[DEBUG] \033[0m");
+        fflush(stderr);
+        char err_buf[500];
+        sprintf(err_buf, "FTSW and b2tt firmwares are old. Exiting...\n %s %s %d\n",
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        printf("%s", err_buf); fflush(stdout);
+        B2FATAL(err_buf);
+#endif
+      } else {
+        // this word for 32bit unixtime
+        // new one (ver.2)
+        break;
+      }
+    }
+
+    if (i == 3) {
+#ifdef TEMP
+      char err_buf[500];
+      sprintf(err_buf, "PreRawCOPPERFormat_v1 contains no FINESSE data. Exiting...\n %s %s %d\n",
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      B2FATAL(err_buf);
+#endif
+    }
+  }
+  return;
+}
+#endif
+
+
+//int PreRawCOPPERFormat_v1::CalcReducedDataSize(RawDataBlock* raw_datablk)
+int PreRawCOPPERFormat_v1::CalcReducedDataSize(int* bufin, int nwords, int num_events, int num_nodes)
+{
+  //
+  // Calculate reduced length for a total RawDataBlock (containing multiple data blocks)
+  //
+  PreRawCOPPERFormat_v1 rawcpr_fmt;
+  int delete_flag = 0;
+  rawcpr_fmt.SetBuffer(bufin, nwords, delete_flag, num_events, num_nodes);
+
+  int reduced_nwords = 0;
+  for (int k = 0; k < rawcpr_fmt.GetNumEvents(); k++) {
+    int num_nodes_in_sendblock = rawcpr_fmt.GetNumNodes();
+    for (int l = 0; l < num_nodes_in_sendblock; l++) {
+      int entry_id = l + k * num_nodes_in_sendblock;
+      if (rawcpr_fmt.CheckFTSWID(entry_id) || rawcpr_fmt.CheckTLUID(entry_id)) {
+        // No size reduction for non-COPPER data ( FTSW and TLU data blocks )
+        reduced_nwords += rawcpr_fmt.GetBlockNwords(entry_id);
+      } else {
+        PreRawCOPPERFormat_v1 temp_prerawcpr;
+        int temp_delete_flag = 0, temp_num_eve = 1, temp_num_nodes = 1;
+
+        // Call CalcReducedNwords
+        temp_prerawcpr.SetBuffer(rawcpr_fmt.GetBuffer(entry_id),
+                                 rawcpr_fmt.GetBlockNwords(entry_id),
+                                 temp_delete_flag, temp_num_eve,
+                                 temp_num_nodes);
+        reduced_nwords += temp_prerawcpr.CalcReducedNwords(0);
+      }
+    }
+  }
+  return reduced_nwords;
+
+}
+
+//void PreRawCOPPERFormat_v1::CopyReducedData(RawDataBlock* raw_datablk, int* buf_to, int delete_flag_from)
+void PreRawCOPPERFormat_v1::CopyReducedData(int* bufin, int nwords, int num_events, int num_nodes, int* buf_to, int* nwords_to)
+{
+  //
+  // Make a reduced buffer a total RawDataBlock (containing multiple data blocks)
+  //
+  PreRawCOPPERFormat_v1 rawcpr_fmt;
+  int delete_flag = 0;
+  rawcpr_fmt.SetBuffer(bufin, nwords, delete_flag, num_events, num_nodes);
+
+  int pos_nwords_to = 0;
+  for (int k = 0; k < rawcpr_fmt.GetNumEvents(); k++) {
+    int num_nodes_in_sendblock = rawcpr_fmt.GetNumNodes();
+    for (int l = 0; l < num_nodes_in_sendblock; l++) {
+      int entry_id = l + k * num_nodes_in_sendblock;
+      if (rawcpr_fmt.CheckFTSWID(entry_id) ||
+          rawcpr_fmt.CheckTLUID(entry_id)) {
+        rawcpr_fmt.CopyBlock(entry_id, buf_to + pos_nwords_to);
+        pos_nwords_to += rawcpr_fmt.GetBlockNwords(entry_id);
+
+      } else {
+        SetBuffer(rawcpr_fmt.GetBuffer(entry_id),
+                  rawcpr_fmt.GetBlockNwords(entry_id), 0, 1, 1);
+
+        pos_nwords_to += CopyReducedBuffer(0, buf_to + pos_nwords_to);
+
+
+      }
+    }
+  }
+
+//   int* buf_from = raw_datablk->GetWholeBuffer();
+//   raw_datablk->SetBuffer(buf_to, pos_nwords_to, 0,
+//                          raw_datablk->GetNumEvents(), raw_datablk->GetNumNodes());
+//   if (delete_flag_from == 1) { delete[] buf_from;}
+  *nwords_to = pos_nwords_to;
+  return ;
+}
+
+
+int PreRawCOPPERFormat_v1::CalcReducedNwords(int n)
+{
+  //
+  // Calculate reduced length for one data block which is a part of a RawDataBlock
+  //
+
+  int nwords_to = 0;
+
+  //RawCOPPER header
+  nwords_to += tmp_header.RAWHEADER_NWORDS;
+
+  for (int j = 0; j < 4; j++) {
+
+    int finesse_nwords = GetFINESSENwords(n, j);
+    if (finesse_nwords > 0) {
+      //
+      // B2L(HSLB/FEE) header and trailers are resized
+      // m_reduced_rawcpr should be PostRawCOPPERFormat_v1
+      //
+      nwords_to +=
+        finesse_nwords
+        - (SIZE_B2LHSLB_HEADER -  m_reduced_rawcpr.SIZE_B2LHSLB_HEADER)
+        - (SIZE_B2LFEE_HEADER -   m_reduced_rawcpr.SIZE_B2LFEE_HEADER)
+        - (SIZE_B2LFEE_TRAILER -  m_reduced_rawcpr.SIZE_B2LFEE_TRAILER)
+        - (SIZE_B2LHSLB_TRAILER - m_reduced_rawcpr.SIZE_B2LHSLB_TRAILER);
+    }
+
+  }
+
+  //RawCOPPER Trailer
+  nwords_to += tmp_trailer.GetTrlNwords();
+
+  return nwords_to;
+}
+
+
+
+
+
+
+int PreRawCOPPERFormat_v1::CopyReducedBuffer(int n, int* buf_to)
+{
+  //
+  // Make a reduced buffer for one data block which is a part of a RawDataBlock
+  //
+
+  int* buf_from = NULL;
+  int nwords_buf_to = CalcReducedNwords(n);
+  int pos_nwords_to = 0;
+  int copy_nwords = 0;
+
+  // copyt to ReducedRawCOPPER
+  //  ReducedRawCOPPER m_reduced_rawcpr;
+  //Header copy
+  copy_nwords = tmp_header.RAWHEADER_NWORDS;
+  buf_from = GetBuffer(n);
+  copyData(buf_to, &pos_nwords_to, buf_from, copy_nwords, nwords_buf_to);
+
+  // Unset the PreFormat bit ( 15th bit )
+  buf_to[ tmp_header.POS_VERSION_HDRNWORDS ] &= 0xFFFF7FFF;
+
+  //Check Header
+  //  m_reduced_rawcpr.tmp_header.CheckHeader(buf_to + pos_nwords_to - copy_nwords);
+
+
+  // copy FINESSE buffer
+  int pos_nwords_finesse[ 4 ];
+  for (int j = 0; j < 4; j++) {
+    pos_nwords_finesse[ j ] = pos_nwords_to;
+    if (GetFINESSENwords(n, j) > 0) {
+      int* finesse_buf = GetFINESSEBuffer(n, j);
+      int finesse_nwords = GetFINESSENwords(n, j);
+
+
+      CheckB2LHSLBMagicWords(finesse_buf, finesse_nwords);
+      // copy the whole B2LHSLB header (1word)
+      buf_to[ pos_nwords_to ] = finesse_buf[ POS_MAGIC_B2LHSLB ];
+      pos_nwords_to++;
+
+      // copy the last word of B2LFEE and body( DetectorBuffer )
+      buf_from =
+        finesse_buf
+        + SIZE_B2LHSLB_HEADER
+        + POS_B2L_CTIME; //the last word of B2LFEE
+
+      // check finesse buffer size : ( When dumhslb was used, this type of error occured and RecvStream0.py died by Segmentation Fault. ) 2014.12.01.
+      if (finesse_nwords - SIZE_B2LHSLB_HEADER - SIZE_B2LFEE_HEADER
+          - SIZE_B2LFEE_TRAILER - SIZE_B2LHSLB_TRAILER < 0) {
+        char err_buf[500];
+        sprintf(err_buf,
+                "[ERROR] Finesse buffer size is too small( %d words < %d words). May be the data are corrupted. Exiting...\n %s %s %d\n",
+                finesse_nwords, SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER,
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        printf("%s", err_buf); fflush(stdout);
+        B2FATAL(err_buf);
+      }
+
+      copy_nwords =
+        finesse_nwords
+        - SIZE_B2LHSLB_HEADER // already copied
+        - POS_B2L_CTIME // only one word copied ( SIZE_B2LFEE_HEADER - 1 = POS_B2L_CTIME )
+        - SIZE_B2LFEE_TRAILER // will be copied later
+        - SIZE_B2LHSLB_TRAILER; // Not copied
+
+      //      printf("pos %d nwords %d  nwords to %d\n", pos_nwords_to, copy_nwords, nwords_buf_to );
+      copyData(buf_to, &pos_nwords_to, buf_from, copy_nwords, nwords_buf_to);
+
+      //copy B2LFEE trailer(CRC info)
+      buf_to[ pos_nwords_to ] =
+        finesse_buf[ finesse_nwords - SIZE_B2LHSLB_TRAILER
+                     - (SIZE_B2LFEE_TRAILER - POS_CHKSUM_B2LFEE) ];
+      pos_nwords_to++;
+
+      // check CRC data
+      //      CheckCRC16( n, j );
+    }
+  }
+
+  // copy RawCOPPER trailer
+  buf_from =
+    GetBuffer(n)
+    + GetBlockNwords(n)
+    - tmp_trailer.GetTrlNwords();
+  copy_nwords = tmp_trailer.GetTrlNwords();
+  copyData(buf_to, &pos_nwords_to, buf_from, copy_nwords, nwords_buf_to);
+
+  // length check
+  if (pos_nwords_to != nwords_buf_to) {
+    char err_buf[500];
+    sprintf(err_buf, "Buffer overflow. Exiting... %d %d\n", pos_nwords_to, nwords_buf_to);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  //
+  // Apply changes followed by data size reduction
+  //
+  *(buf_to + m_reduced_rawcpr.tmp_header.POS_NWORDS) = nwords_buf_to;
+  *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_1ST_FINESSE) = pos_nwords_finesse[ 0 ];
+  *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_2ND_FINESSE) = pos_nwords_finesse[ 1 ];
+  *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_3RD_FINESSE) = pos_nwords_finesse[ 2 ];
+  *(buf_to + m_reduced_rawcpr.tmp_header.POS_OFFSET_4TH_FINESSE) = pos_nwords_finesse[ 3 ];
+
+
+  // Recalculate XOR checksum in a RawCOPPER trailer
+  *(buf_to + pos_nwords_to - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM) =
+    CalcXORChecksum(buf_to, pos_nwords_to - tmp_trailer.GetTrlNwords());
+
+  //
+  // data block # check
+  //
+  m_reduced_rawcpr.SetBuffer(buf_to, nwords_buf_to, 0, GetNumEvents(), GetNumNodes());
+  if (m_reduced_rawcpr.GetNumEvents() * m_reduced_rawcpr.GetNumNodes() <= 0) {
+    char err_buf[500];
+    sprintf(err_buf, "Invalid data block numbers.(# of events %d, # of nodes %d) Exiting...\n",
+            m_reduced_rawcpr.GetNumEvents(), m_reduced_rawcpr.GetNumNodes());
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  //
+  // check no-data buffer
+  //
+  for (int i = 0; i < m_reduced_rawcpr.GetNumEvents() * m_reduced_rawcpr.GetNumNodes(); i++) {
+    int nonzero_finesse_buf = 0;
+    for (int j = 0; j < 4; j++) {
+
+      if (GetFINESSENwords(n, j) > 0) {
+        //        m_reduced_rawcpr.CheckCRC16(i, j);
+        nonzero_finesse_buf++;
+      }
+    }
+    if (nonzero_finesse_buf == 0) {
+      char err_buf[500];
+      sprintf(err_buf, "No non-zero FINESSE buffer. Exiting...\n");
+      printf("%s", err_buf); fflush(stdout);
+      B2FATAL(err_buf);
+    }
+  }
+
+  //    post_rawcopper_v1.CheckCRC16(0, 0);
+  //       printf("fROM =======================================\n");
+  //       for (int k = 0; k < nwords_buf_to; k++) {
+  //  printf(" %.8x", GetBuffer(n)[ k ]);
+  //  if ( ( k + 1 ) % 10 == 0) {
+  //    printf("\n");
+  //  }
+  //       }
+  //       printf("\n");
+
+  //       printf("tO   =======================================\n");
+  //       for (int k = 0; k < nwords_buf_to; k++) {
+  //  printf(" %.8x", buf_to[ k ]);
+  //  if ( ( k + 1 ) % 10 == 0) {
+  //    printf("\n");
+  //  }
+  //       }
+  //       printf("\n");
+  //       printf("=============================================\n");
+  return pos_nwords_to;
+}
+
+
+int PreRawCOPPERFormat_v1::CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords)
+{
+
+  if ((finesse_buf[ POS_MAGIC_B2LHSLB ] & 0xFFFF0000) == B2LHSLB_HEADER_MAGIC &&
+      ((finesse_buf[ finesse_nwords - SIZE_B2LHSLB_TRAILER + POS_CHKSUM_B2LHSLB ] & 0xFFFF0000)
+       == B2LHSLB_TRAILER_MAGIC)) {
+    return 1;
+  } else {
+    PrintData(m_buffer, m_nwords);
+    char err_buf[500];
+    sprintf(err_buf, "Invalid B2LHSLB magic words 0x%x 0x%x. Exiting... :%s %s %d\n",
+            finesse_buf[ POS_MAGIC_B2LHSLB ],
+            finesse_buf[ finesse_nwords - SIZE_B2LHSLB_TRAILER + POS_CHKSUM_B2LHSLB ],
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+    return -1;
+  }
+}
+
+
+
+int PreRawCOPPERFormat_v1::CheckCRC16(int n, int finesse_num)
+{
+  //
+  // Calculate CRC16
+  //
+  int* buf = GetFINESSEBuffer(n, finesse_num) +  SIZE_B2LHSLB_HEADER;
+  int nwords = GetFINESSENwords(n, finesse_num) - (SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER);
+  unsigned short temp_crc16 = CalcCRC16LittleEndian(0xffff, buf, nwords);
+
+  //
+  // Compare CRC16 with B2LCRC16
+  //
+  buf = GetFINESSEBuffer(n, finesse_num) +  GetFINESSENwords(n, finesse_num)
+        - ((SIZE_B2LFEE_TRAILER - POS_CHKSUM_B2LFEE) + SIZE_B2LHSLB_TRAILER) ;
+
+  //  printf("PreRawCOPPER  : Eve %.8x B2LCRC16 %.8x calculated CRC16 %.8x\n", GetEveNo(n), *buf, temp_crc16 );
+
+  if ((unsigned short)(*buf & 0xFFFF) != temp_crc16) {
+    printf("PRE CRC16 error : B2LCRC16 %x Calculated CRC16 %x : Nwords of FINESSE buf %d\n",
+           *buf , temp_crc16, GetFINESSENwords(n, finesse_num));
+    int* temp_buf = GetFINESSEBuffer(n, finesse_num);
+    for (int k = 0; k <  GetFINESSENwords(n, finesse_num); k++) {
+      printf("%.8x ", temp_buf[ k ]);
+      if ((k + 1) % 10 == 0) {
+        printf("\n");
+      }
+    }
+    printf("\n");
+    fflush(stdout);
+
+    char err_buf[500];
+    sprintf(err_buf,
+            "[DEBUG] [ERROR] B2LCRC16 (%.4x) differs from one ( %.4x) calculated by PreRawCOPPERfromat class. Exiting...\n %s %s %d\n",
+            (unsigned short)(*buf & 0xFFFF), temp_crc16,
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+  return 1;
+
+}
+
+int* PreRawCOPPERFormat_v1::PackDetectorBuf(int* packed_buf_nwords,
+                                            int* detector_buf_1st, int nwords_1st,
+                                            int* detector_buf_2nd, int nwords_2nd,
+                                            int* detector_buf_3rd, int nwords_3rd,
+                                            int* detector_buf_4th, int nwords_4th,
+                                            RawCOPPERPackerInfo rawcpr_info)
+{
+  int* packed_buf = NULL;
+
+  int poswords_to = 0;
+  int* detector_buf[ 4 ] = { detector_buf_1st, detector_buf_2nd, detector_buf_3rd, detector_buf_4th };
+  int nwords[ 4 ] = { nwords_1st, nwords_2nd, nwords_3rd, nwords_4th };
+
+  // calculate the event length
+  int length_nwords = tmp_header.GetHdrNwords() + SIZE_COPPER_HEADER + SIZE_COPPER_TRAILER + tmp_trailer.GetTrlNwords();
+
+  for (int i = 0; i < 4; i++) {
+    if (detector_buf[ i ] == NULL || nwords[ i ] <= 0) continue;    // for an empty FINESSE slot
+    length_nwords += nwords[ i ];
+    length_nwords += SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER
+                     + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
+  }
+
+  // allocate buffer
+  packed_buf = new int[ length_nwords ];
+  memset(packed_buf, 0, sizeof(int) * length_nwords);
+
+  //
+  // Fill RawHeader
+  //
+  tmp_header.SetBuffer(packed_buf);
+
+  packed_buf[ tmp_header.POS_NWORDS ] = length_nwords; // total length
+  packed_buf[ tmp_header.POS_VERSION_HDRNWORDS ] = 0x7f7f8000
+                                                   | ((DATA_FORMAT_VERSION << tmp_header.FORMAT_VERSION_SHIFT) & tmp_header.FORMAT_VERSION__MASK)
+                                                   | tmp_header.RAWHEADER_NWORDS; // ver.#, header length
+
+  packed_buf[ tmp_header.POS_EXP_RUN_NO ] = (rawcpr_info.exp_num << 22)
+                                            | (rawcpr_info.run_subrun_num & 0x003FFFFF);   // exp. and run #
+  packed_buf[ tmp_header.POS_EVE_NO ] = rawcpr_info.eve_num; // eve #
+  packed_buf[ tmp_header.POS_TTCTIME_TRGTYPE ] = (rawcpr_info.tt_ctime & 0x7FFFFFF) << 4;   // tt_ctime
+  packed_buf[ tmp_header.POS_TTUTIME ] = rawcpr_info.tt_utime; // tt_utime
+  packed_buf[ tmp_header.POS_NODE_ID ] = rawcpr_info.node_id; // node ID
+
+
+
+
+  // fill the positions of finesse buffers
+  packed_buf[ tmp_header.POS_OFFSET_1ST_FINESSE ] = tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
+
+  packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_1ST_FINESSE ];
+  if (nwords[ 0 ] > 0) {
+    packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ] +=
+      nwords[ 0 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER  + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
+  }
+
+  packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ];
+  if (nwords[ 1 ] > 0) {
+    packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ] +=
+      nwords[ 1 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER  + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
+  }
+
+  packed_buf[ tmp_header.POS_OFFSET_4TH_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ];
+  if (nwords[ 2 ] > 0) {
+    packed_buf[ tmp_header.POS_OFFSET_4TH_FINESSE ] += nwords[ 2 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER  + SIZE_B2LFEE_TRAILER +
+                                                       SIZE_B2LHSLB_TRAILER;
+  }
+  poswords_to += tmp_header.GetHdrNwords();
+
+  // Fill COPPER header
+  packed_buf[ poswords_to + POS_MAGIC_COPPER_1 ] = COPPER_MAGIC_DRIVER_HEADER;
+  packed_buf[ poswords_to + POS_MAGIC_COPPER_2 ] = COPPER_MAGIC_FPGA_HEADER;
+  packed_buf[ poswords_to + POS_EVE_NUM_COPPER ] = rawcpr_info.eve_num;
+
+  int size_b2l_hdrtrl = SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
+  if (nwords[ 0 ] != 0)  packed_buf[ poswords_to + POS_CH_A_DATA_LENGTH ] = nwords[ 0 ] + size_b2l_hdrtrl;
+  if (nwords[ 1 ] != 0)  packed_buf[ poswords_to + POS_CH_B_DATA_LENGTH ] = nwords[ 1 ] + size_b2l_hdrtrl;
+  if (nwords[ 2 ] != 0)  packed_buf[ poswords_to + POS_CH_C_DATA_LENGTH ] = nwords[ 2 ] + size_b2l_hdrtrl;
+  if (nwords[ 3 ] != 0)  packed_buf[ poswords_to + POS_CH_D_DATA_LENGTH ] = nwords[ 3 ] + size_b2l_hdrtrl;
+
+  packed_buf[ poswords_to + POS_DATA_LENGTH ] =
+    packed_buf[ poswords_to + POS_CH_A_DATA_LENGTH ] +
+    packed_buf[ poswords_to + POS_CH_B_DATA_LENGTH ] +
+    packed_buf[ poswords_to + POS_CH_C_DATA_LENGTH ] +
+    packed_buf[ poswords_to + POS_CH_D_DATA_LENGTH ] +
+    (SIZE_COPPER_HEADER - SIZE_COPPER_DRIVER_HEADER) +
+    (SIZE_COPPER_TRAILER - SIZE_COPPER_DRIVER_TRAILER);
+
+  poswords_to += SIZE_COPPER_HEADER;
+
+  // Fill FINESSE buffer
+  for (int i = 0; i < 4; i++) {
+
+    if (detector_buf[ i ] == NULL || nwords[ i ] <= 0) continue;     // for an empty FINESSE slot
+
+    // Fill b2link HSLB header
+    packed_buf[ poswords_to + POS_MAGIC_B2LHSLB ] = 0xffaa0000 | (0xffff & rawcpr_info.eve_num);
+    poswords_to += SIZE_B2LHSLB_HEADER;
+    int* crc16_start = &(packed_buf[ poswords_to ]);
+
+    // Fill b2link FEE header
+
+    packed_buf[ poswords_to + POS_TT_CTIME_TYPE ] = (rawcpr_info.tt_ctime & 0x7FFFFFF) << 4;
+    packed_buf[ poswords_to + POS_TT_TAG ] = rawcpr_info.eve_num;
+    packed_buf[ poswords_to + POS_TT_UTIME ] = rawcpr_info.tt_utime;
+    packed_buf[ poswords_to + POS_EXP_RUN ] = (rawcpr_info.exp_num << 22) | (rawcpr_info.run_subrun_num &
+                                              0x003FFFFF);   // exp. and run #
+    packed_buf[ poswords_to + POS_B2L_CTIME ] = (rawcpr_info.b2l_ctime & 0x7FFFFFF) << 4;
+    poswords_to += SIZE_B2LFEE_HEADER;
+
+    // copy the 1st Detector Buffer
+    memcpy(packed_buf + poswords_to, detector_buf[ i ], nwords[ i ]*sizeof(int));
+    poswords_to += nwords[ i ];
+
+    // Fill b2link FEE trailer
+    unsigned short crc16 = CalcCRC16LittleEndian(0xffff, crc16_start, nwords[ i ] + SIZE_B2LFEE_HEADER);
+    packed_buf[ poswords_to + POS_CHKSUM_B2LFEE ] = ((0xffff & rawcpr_info.eve_num) << 16) | (crc16 & 0xffff);
+    poswords_to += SIZE_B2LFEE_TRAILER;
+
+    // Fill b2link HSLB trailer
+    packed_buf[ poswords_to + POS_CHKSUM_B2LHSLB ] = 0xff550000;
+    poswords_to += SIZE_B2LHSLB_TRAILER;
+
+  }
+
+  // Fill COPPER trailer
+  packed_buf[ poswords_to + POS_MAGIC_COPPER_3 ] = COPPER_MAGIC_FPGA_TRAILER;
+  packed_buf[ poswords_to + POS_MAGIC_COPPER_4 ] = COPPER_MAGIC_DRIVER_TRAILER;
+  unsigned int chksum = 0;
+  for (int i = tmp_header.GetHdrNwords(); i < poswords_to + (SIZE_COPPER_TRAILER - SIZE_COPPER_DRIVER_TRAILER); i++) {
+    chksum ^= packed_buf[ i ];
+  }
+  packed_buf[ poswords_to + POS_CHKSUM_COPPER ] = chksum;
+  poswords_to += SIZE_COPPER_TRAILER;
+
+  // Calculate RawCOPPER checksum and fill RawTrailer
+  chksum = 0;
+  for (int i = 0; i < poswords_to; i++) {
+    chksum ^= packed_buf[ i ];
+  }
+  packed_buf[ poswords_to + tmp_trailer.POS_CHKSUM ] = chksum;
+
+  packed_buf[ poswords_to + tmp_trailer.POS_TERM_WORD ] = tmp_trailer.MAGIC_WORD_TERM_TRAILER;
+  poswords_to += tmp_trailer.GetTrlNwords();
+
+  *packed_buf_nwords = poswords_to;
+  return packed_buf;
+}
+
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawARICH.cc b/ROPCApplications/rawdata/dataobjects/src/RawARICH.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d19e180a2927626ed8cfe2b65bb58ac982d1aa47
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawARICH.cc
@@ -0,0 +1,20 @@
+//+
+// File : RawCOPPER.cc
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawARICH.h>
+
+using namespace std;
+using namespace Belle2;
+
+RawARICH::RawARICH()
+{
+}
+
+RawARICH::~RawARICH()
+{
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawCDC.cc b/ROPCApplications/rawdata/dataobjects/src/RawCDC.cc
new file mode 100644
index 0000000000000000000000000000000000000000..645ec5e924b4e22b194e68117eaeacc3d22011d4
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawCDC.cc
@@ -0,0 +1,20 @@
+//+
+// File : RawCOPPER.cc
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawCDC.h>
+
+using namespace std;
+using namespace Belle2;
+
+RawCDC::RawCDC()
+{
+}
+
+RawCDC::~RawCDC()
+{
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawCOPPER.cc b/ROPCApplications/rawdata/dataobjects/src/RawCOPPER.cc
new file mode 100644
index 0000000000000000000000000000000000000000..40b6bc21b6b05c1f91dfab2906394e1b838fa47a
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawCOPPER.cc
@@ -0,0 +1,267 @@
+//+
+// File : RawCOPPER.cc
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawCOPPER.h>
+
+#include <framework/utilities/HTML.h>
+#include <sstream>
+
+
+using namespace std;
+using namespace Belle2;
+
+//#define DESY
+//#define NO_DATA_CHECK
+//#define WO_FIRST_EVENUM_CHECK
+
+RawCOPPER::RawCOPPER()
+{
+  m_access = NULL;
+  m_version = -1;
+}
+
+RawCOPPER::~RawCOPPER()
+{
+  if (m_access != NULL) delete m_access;
+  m_access = NULL;
+}
+
+void RawCOPPER::SetVersion()
+{
+
+  if (m_buffer == NULL) {
+    char err_buf[500];
+    sprintf(err_buf, "m_buffer is NULL. Exiting...");
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  if (m_access != NULL) {
+    delete m_access;
+  }
+
+  m_version = ((m_buffer[ POS_FORMAT_VERSION ]) & FORMAT_MASK) >> 8;
+  switch (m_version) {
+    case LATEST_POSTREDUCTION_FORMAT_VER :
+      m_access = new PostRawCOPPERFormat_latest;
+      //            printf("Calling PostRawCOPPERFormat_latest\n");
+      break;
+    case (0x80 + LATEST_POSTREDUCTION_FORMAT_VER) :
+      m_access = new PreRawCOPPERFormat_latest;
+      //            printf("Calling PreRawCOPPERFormat_latest\n");
+      break;
+    case 0x1 :
+      m_access = new PostRawCOPPERFormat_v1;
+      //      printf("Calling RawCOPPERFormat_v1\n");
+      break;
+    case (0x80 + 0x1) :
+      m_access = new PreRawCOPPERFormat_v1;
+      //            printf("Calling PreRawCOPPERFormat_latest\n");
+      break;
+    case 0 :
+      m_access = new RawCOPPERFormat_v0;
+      //      printf("Calling RawCOPPERFormat_v0\n");
+      break;
+    default : {
+      char err_buf[500];
+      sprintf(err_buf, "[FATAL] ERROR_EVENT : Invalid version of a data format(0x%.8x = 0x7f7f**..). Exiting...\n %s %s %d\n",
+              m_buffer[ POS_FORMAT_VERSION ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      B2FATAL(err_buf); // to reduce multiple error messages
+    }
+  }
+
+  m_access->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+
+
+
+}
+
+void RawCOPPER::SetVersion(string class_name)
+{
+
+  if (m_access != NULL) {
+    delete m_access;
+  }
+
+  if (class_name == "PostRawCOPPERFormat_latest") {
+    m_access = new PostRawCOPPERFormat_latest;
+    m_version = (0 << 7) | LATEST_POSTREDUCTION_FORMAT_VER;
+  } else if (class_name == "PreRawCOPPERFormat_latest") {
+    m_access = new PreRawCOPPERFormat_latest;
+    m_version = (1 << 7) | LATEST_POSTREDUCTION_FORMAT_VER;
+  } else if (class_name == "PostRawCOPPERFormat_v1") {
+    m_access = new PostRawCOPPERFormat_v1;
+    m_version = (0 << 7) | 1;
+  } else if (class_name == "PreRawCOPPERFormat_v1") {
+    m_access = new PreRawCOPPERFormat_v1;
+    m_version = (1 << 7) | 1;
+  } else if (class_name == "RawCOPPERFormat_v0") {
+    m_access = new RawCOPPERFormat_v0;
+    m_version = (0 << 7) | 0;
+  } else {
+    char err_buf[500];
+    sprintf(err_buf, "Invalid name of a data format class (%s). Exiting...\n %s %s %d\n",
+            class_name.c_str(), __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+//   if( class_name == "RawCOPPERFormat_v0" ){
+//     m_access = new RawCOPPERFormat_v0;
+//     m_version = ( 0 << 7 ) | 0;
+//   }else if( class_name == "PreRawCOPPERFormat_v0" ){
+//     m_access = new PreRawCOPPERFormat_v0;
+//     m_version = ( 1 << 7 ) | 0;
+//   }else if( class_name == "RawCOPPERFormat_v2" ){
+//     m_access = new RawCOPPERFormat_v2;
+//     m_version = ( 0 << 7 ) | 2;
+//   }else if( class_name == "PreRawCOPPERFormat_v2" ){
+//     m_access = new PreRawCOPPERFormat_v2;
+//     m_version = ( 1 << 7 ) | 2;
+//   }
+  m_access->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+
+}
+
+void RawCOPPER::SetBuffer(int* bufin, int nwords, int delete_flag, int num_events, int num_nodes)
+{
+  if (bufin == NULL) {
+    char err_buf[500];
+    sprintf(err_buf, "[DEBUG] bufin is NULL. Exting...\n");
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  if (!m_use_prealloc_buf && m_buffer != NULL) delete[] m_buffer;
+
+  if (delete_flag == 0) {
+    m_use_prealloc_buf = true;
+  } else {
+    m_use_prealloc_buf = false;
+  }
+
+  m_nwords = nwords;
+  m_buffer = bufin;
+
+  m_num_nodes = num_nodes;
+  m_num_events = num_events;
+
+  SetVersion();
+
+}
+
+
+void RawCOPPER::ShowBuffer()
+{
+
+  printf("\n");
+  printf("POINTER %p\n", m_buffer);
+  for (int k = 0; k < 100; k++) {
+    printf("%.8x ", m_buffer[ k ]);
+    if ((k + 1) % 10 == 0) printf("\n%.8x : ", k);
+  }
+  printf("\n");
+
+}
+
+
+void RawCOPPER::PackDetectorBuf(
+  int* detector_buf_1st, int nwords_1st,
+  int* detector_buf_2nd, int nwords_2nd,
+  int* detector_buf_3rd, int nwords_3rd,
+  int* detector_buf_4th, int nwords_4th,
+  RawCOPPERPackerInfo rawcprpacker_info)
+{
+
+  if (m_access != NULL) {
+    delete m_access;
+  }
+  m_access = new PostRawCOPPERFormat_latest;
+  m_version = LATEST_POSTREDUCTION_FORMAT_VER;
+  m_num_events = 1;
+  m_num_nodes = 1;
+
+  int* packed_buf = NULL;
+  packed_buf = m_access->PackDetectorBuf(&m_nwords,
+                                         detector_buf_1st, nwords_1st,
+                                         detector_buf_2nd, nwords_2nd,
+                                         detector_buf_3rd, nwords_3rd,
+                                         detector_buf_4th, nwords_4th,
+                                         rawcprpacker_info);
+
+  int delete_flag = 1; // Not use preallocated buffer. Delete m_buffer when destructer is called.
+  SetBuffer(packed_buf, m_nwords, delete_flag, m_num_events, m_num_nodes);
+
+  delete_flag = 0; // For m_access, need not to delete m_buffer
+  m_access->SetBuffer(m_buffer, m_nwords, delete_flag, m_num_events, m_num_nodes);
+
+  return;
+}
+
+
+void RawCOPPER::PackDetectorBuf4DummyData(
+  int* detector_buf_1st, int nwords_1st,
+  int* detector_buf_2nd, int nwords_2nd,
+  int* detector_buf_3rd, int nwords_3rd,
+  int* detector_buf_4th, int nwords_4th,
+  RawCOPPERPackerInfo rawcprpacker_info)
+{
+
+  if (m_access != NULL) {
+    delete m_access;
+  }
+  m_access = new PreRawCOPPERFormat_latest;
+  m_version = LATEST_POSTREDUCTION_FORMAT_VER;
+  m_num_events = 1;
+  m_num_nodes = 1;
+
+  int* packed_buf = NULL;
+  packed_buf = m_access->PackDetectorBuf(&m_nwords,
+                                         detector_buf_1st, nwords_1st,
+                                         detector_buf_2nd, nwords_2nd,
+                                         detector_buf_3rd, nwords_3rd,
+                                         detector_buf_4th, nwords_4th,
+                                         rawcprpacker_info);
+
+  int delete_flag = 1; // Not use preallocated buffer. Delete m_buffer when destructer is called.
+  SetBuffer(packed_buf, m_nwords, delete_flag, m_num_events, m_num_nodes);
+
+  delete_flag = 0; // For m_access, need not to delete m_buffer
+  m_access->SetBuffer(m_buffer, m_nwords, delete_flag, m_num_events, m_num_nodes);
+
+  return;
+}
+
+std::string RawCOPPER::getInfoHTML() const
+{
+  std::stringstream s;
+  //TODO: All these methods should be const instead.
+  RawCOPPER* nonconst_this = const_cast<RawCOPPER*>(this);
+  nonconst_this->CheckVersionSetBuffer();
+
+  const int nEntries = nonconst_this->GetNumEntries();
+  s << "Entries: " << nEntries;
+  s << ", Total size (32bit words): " << m_nwords << "<br>";
+
+  s << "COPPER format version: " << m_version;
+
+  const char a = 'A'; //finesses are counted from A to D
+  for (int iEntry = 0; iEntry < nEntries; ++iEntry) {
+    s << "<h4>Entry " << iEntry << "</h4>";
+    s << "Node ID: 0x" << std::hex << nonconst_this->GetNodeID(iEntry) << std::dec;
+    for (int iFinesse = 0; iFinesse < 4; iFinesse++) {
+      const int nWords = nonconst_this->GetDetectorNwords(iEntry, iFinesse);
+      const int* buf = nonconst_this->GetDetectorBuffer(iEntry, iFinesse);
+      s << "<p>Finesse " << char(a + iFinesse) << " (Size: " << nWords << ")</p>";
+      s << HTML::getHexDump(buf, nWords) << "<br>";
+    }
+  }
+
+  return s.str();
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawCOPPERFormat.cc b/ROPCApplications/rawdata/dataobjects/src/RawCOPPERFormat.cc
new file mode 100644
index 0000000000000000000000000000000000000000..262afe5c41a83892a74d4eaeb0fd7dbaeef27e8f
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawCOPPERFormat.cc
@@ -0,0 +1,195 @@
+//+
+// File : RawCOPPERFormat.cc
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 3 - July - 2014
+//-
+
+#include <rawdata/dataobjects/RawCOPPERFormat.h>
+
+using namespace std;
+using namespace Belle2;
+//ClassImp(RawCOPPERFormat);
+
+
+RawCOPPERFormat::RawCOPPERFormat()
+{
+//   m_nwords = 0;
+//   m_num_nodes = 0;
+//   m_num_events = 0;
+//   m_buffer = NULL;
+}
+
+unsigned int  RawCOPPERFormat::CalcXORChecksum(int* buf, int nwords)
+{
+  unsigned int checksum = 0;
+  for (int i = 0; i < nwords; i++) {
+    checksum = checksum ^ buf[ i ];
+  }
+  return checksum;
+}
+
+
+
+
+int RawCOPPERFormat::GetOffsetFINESSE(int n, int finesse_num)
+{
+  switch (finesse_num) {
+    case 0 :
+      return GetOffset1stFINESSE(n);
+      break;
+    case 1 :
+      return GetOffset2ndFINESSE(n);
+      break;
+    case 2 :
+      return GetOffset3rdFINESSE(n);
+      break;
+    case 3 :
+      return GetOffset4thFINESSE(n);
+      break;
+    default :
+      break;
+  }
+
+  char err_buf[500];
+  sprintf(err_buf, "[FATAL] Specifined FINESSE number( = %d ) is invalid. Exiting...\n%s %s %d\n", finesse_num,
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+}
+
+
+
+
+int* RawCOPPERFormat::GetFINESSEBuffer(int n, int finesse_num)
+{
+  switch (finesse_num) {
+    case 0 :
+      return Get1stFINESSEBuffer(n);
+      break;
+    case 1 :
+      return Get2ndFINESSEBuffer(n);
+      break;
+    case 2 :
+      return Get3rdFINESSEBuffer(n);
+      break;
+    case 3 :
+      return Get4thFINESSEBuffer(n);
+      break;
+    default :
+      break;
+  }
+
+  char err_buf[500];
+  sprintf(err_buf, "[FATAL] Specifined FINESSE number( = %d ) is invalid. Exiting...\n%s %s %d\n", finesse_num,
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+}
+
+
+
+
+int* RawCOPPERFormat::GetDetectorBuffer(int n, int finesse_num)
+{
+  switch (finesse_num) {
+    case 0 :
+      return Get1stDetectorBuffer(n);
+      break;
+    case 1 :
+      return Get2ndDetectorBuffer(n);
+      break;
+    case 2 :
+      return Get3rdDetectorBuffer(n);
+      break;
+    case 3 :
+      return Get4thDetectorBuffer(n);
+      break;
+    default :
+      break;
+  }
+
+  char err_buf[500];
+  sprintf(err_buf, "[FATAL] Specifined FINESSE number( = %d ) is invalid. Exiting...\n%s %s %d\n", finesse_num,
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+}
+
+
+
+unsigned int RawCOPPERFormat::GetB2LHeaderWord(int n, int finesse_buffer_pos)
+{
+  unsigned int word[4];
+  unsigned int ret_word = 0;
+  int flag = 0, err_flag = 0;
+
+  for (int i = 0; i < 4; i++) {
+    if (GetFINESSENwords(n, i) > 0) {
+      word[ i ] = m_buffer[ GetOffsetFINESSE(n, i) + finesse_buffer_pos ];
+      if (flag != 0 && (ret_word != word[ i ])) {
+        err_flag = 1;
+      }
+      ret_word = word[ i ];
+      flag = 1;
+    }
+  }
+
+  if (flag == 0) {
+    char err_buf[500];
+    sprintf(err_buf, "[FATAL] ERROR_EVENT : No HSLB data in COPPER data. Exiting...\n %s %s %d\n",
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  if (err_flag == 1) {
+    char err_buf[500];
+    sprintf(err_buf, "[FATAL] ERROR_EVENT : Different event number over HSLBs : slot A 0x%x : B 0x%x :C 0x%x : D 0x%x\n %s %s %d\n",
+            word[ 0 ], word[ 1 ], word[ 2 ], word[ 3 ],
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("[DEBUG] %s\n", err_buf);
+#ifndef NO_DATA_CHECK
+    B2FATAL(err_buf);
+#endif
+  }
+  return ret_word;
+}
+
+
+// This function is available after RawCOPPER/Header ver.2
+int RawCOPPERFormat::GetPacketCRCError(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf,
+          "[FATAL] This function is not supported in the version of  RawCOPPER format that you're using. n=%d : %s %s %d: Exiting...\n",
+          n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s\n", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+  return -1;
+}
+
+// This function is available after RawCOPPER/Header ver.2
+int RawCOPPERFormat::GetEventCRCError(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf,
+          "[FATAL] This function is not supported in the version of  RawCOPPER format that you're using. n=%d : %s %s %d: Exiting...\n",
+          n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s\n", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+  return -1;
+}
+
+int RawCOPPERFormat::GetEventCRC16Value(int n, int finesse_num)
+{
+  char err_buf[500];
+  sprintf(err_buf,
+          "[FATAL] This function is not supported in the version of  RawCOPPER format that you're using. n=%d fin=%d : %s %s %d: Exiting...\n",
+          n, finesse_num, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s\n", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+  return -1;
+}
+
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawCOPPERFormat_latest.cc b/ROPCApplications/rawdata/dataobjects/src/RawCOPPERFormat_latest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..33f759c21b6c130a59ee020e05b6fd45b451190d
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawCOPPERFormat_latest.cc
@@ -0,0 +1,88 @@
+//+
+// File : RawCOPPERFormat_latest.cc
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawCOPPERFormat_latest.h>
+
+
+using namespace std;
+using namespace Belle2;
+
+//#define DESY
+//#define NO_DATA_CHECK
+//#define WO_FIRST_EVENUM_CHECK
+
+//ClassImp(RawCOPPERFormat_latest);
+
+RawCOPPERFormat_latest::RawCOPPERFormat_latest()
+{
+}
+
+RawCOPPERFormat_latest::~RawCOPPERFormat_latest()
+{
+}
+
+int RawCOPPERFormat_latest::GetNumFINESSEBlock(int n)
+{
+  int cnt = 0;
+  for (int i = 0; i < 4; i++) {
+    if (GetFINESSENwords(n, i) > 0) {
+      cnt++;
+    }
+  }
+  return cnt;
+}
+
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+void RawCOPPERFormat_latest::CheckB2LFEEHeaderVersion(int n)
+{
+
+  int* temp_buf;
+
+  for (int i = 0; i < 4; i++) {
+    if (GetFINESSENwords(n, i) > 0) {
+      temp_buf = GetFINESSEBuffer(n, i);
+      if ((temp_buf[ 3 ] & 0x40000000) == 0) {
+#ifdef TEMP
+        // this word for exp/run
+        // old one (ver.1) used for SPring8 test in 2013
+        printf("[DEBUG] \033[31m");
+        printf("[DEBUG] ===Firmware ver. ERROR===\n ");
+        printf("[DEBUG] FTSW and b2tt firmwares was updated on Nov.22, 2013 and the header format attached by B2link was changed in the new firmwares.\n");
+        printf("[DEBUG] If you are going to take data now, Please update the firmware.\n");
+        printf("[DEBUG] For details, please see Nakao-san's e-mail [b2link_ml:0111] Re: [daq2ml:0159] beta version of trigger timing receiver firmware (b2tt) on bdaq SVN\n");
+        printf("[DEBUG] Or if you are going to read data taken before the update, please use basf2 software before svn rev. 7419\n");
+        printf("[DEBUG] About the format please see Nakao-san's B2GM slides(p. 13 and 15) http://kds.kek.jp/getFile.py/access?contribId=143&sessionId=38&resId=0&materialId=slides&confId=13911.\n");
+        printf("[DEBUG] Sorry for inconvenience.\n");
+        printf("[DEBUG] \033[0m");
+        fflush(stderr);
+        char err_buf[500];
+        sprintf(err_buf, "FTSW and b2tt firmwares are old. Exiting...\n %s %s %d\n",
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        printf("%s\n", err_buf); fflush(stdout);
+        B2FATAL(err_buf);
+#endif
+      } else {
+        // this word for 32bit unixtime
+        // new one (ver.2)
+        break;
+      }
+    }
+
+    if (i == 3) {
+#ifdef TEMP
+      char err_buf[500];
+      sprintf(err_buf, "RawCOPPERFormat_latest contains no FINESSE data. Exiting...\n %s %s %d\n",
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s\n", err_buf); fflush(stdout);
+      B2FATAL(err_buf);
+#endif
+    }
+  }
+  return;
+}
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawCOPPERFormat_v0.cc b/ROPCApplications/rawdata/dataobjects/src/RawCOPPERFormat_v0.cc
new file mode 100644
index 0000000000000000000000000000000000000000..580ff25d9d1aec04d07798e27a2a0e1e92441d49
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawCOPPERFormat_v0.cc
@@ -0,0 +1,716 @@
+//+
+// File : RawCOPPERFormat_v0.cc
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawCOPPERFormat_v0.h>
+
+
+using namespace std;
+using namespace Belle2;
+
+//#define DESY
+//#define NO_DATA_CHECK
+//#define WO_FIRST_EVENUM_CHECK
+
+//ClassImp(RawCOPPERFormat_v0);
+
+RawCOPPERFormat_v0::RawCOPPERFormat_v0()
+{
+}
+
+RawCOPPERFormat_v0::~RawCOPPERFormat_v0()
+{
+}
+
+unsigned int RawCOPPERFormat_v0::CalcDriverChkSum(int n)
+{
+  int min = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS;
+  int max = GetBufferPos(n) + GetBlockNwords(n)
+            - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
+  unsigned int chksum = 0;
+  for (int i = min; i < max; i++) {
+    chksum ^= m_buffer[ i ];
+  }
+  return chksum;
+}
+
+
+int RawCOPPERFormat_v0::GetNumFINESSEBlock(int n)
+{
+
+  int cnt = 0;
+  int pos_nwords = GetBufferPos(n) + POS_CH_A_DATA_LENGTH + tmp_header.RAWHEADER_NWORDS;
+  if (m_buffer[ pos_nwords ] > 0) cnt++;
+  pos_nwords = GetBufferPos(n) + POS_CH_B_DATA_LENGTH + tmp_header.RAWHEADER_NWORDS;
+  if (m_buffer[ pos_nwords ] > 0) cnt++;
+  pos_nwords = GetBufferPos(n) + POS_CH_C_DATA_LENGTH + tmp_header.RAWHEADER_NWORDS;
+  if (m_buffer[ pos_nwords ] > 0) cnt++;
+  pos_nwords = GetBufferPos(n) + POS_CH_D_DATA_LENGTH + tmp_header.RAWHEADER_NWORDS;
+  if (m_buffer[ pos_nwords ] > 0) cnt++;
+  return cnt;
+}
+
+int RawCOPPERFormat_v0::GetDetectorNwords(int n, int finesse_num)
+{
+  switch (finesse_num) {
+    case 0 :
+      return Get1stDetectorNwords(n);
+      break;
+    case 1 :
+      return Get2ndDetectorNwords(n);
+      break;
+    case 2 :
+      return Get3rdDetectorNwords(n);
+      break;
+    case 3 :
+      return Get4thDetectorNwords(n);
+      break;
+    default :
+      break;
+  }
+
+  char err_buf[500];
+  sprintf(err_buf, "Specifined FINESSE number( = %d ) is invalid. Exiting...\n %s %s %d\n", finesse_num,
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s\n", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+}
+
+
+int RawCOPPERFormat_v0::GetFINESSENwords(int n, int finesse_num)
+{
+  switch (finesse_num) {
+    case 0 :
+      return Get1stFINESSENwords(n);
+      break;
+    case 1 :
+      return Get2ndFINESSENwords(n);
+      break;
+    case 2 :
+      return Get3rdFINESSENwords(n);
+      break;
+    case 3 :
+      return Get4thFINESSENwords(n);
+      break;
+    default :
+      break;
+  }
+
+  char err_buf[500];
+  sprintf(err_buf, "Specifined FINESSE number( = %d ) is invalid. Exiting...\n %s %s %d\n",
+          finesse_num, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s\n", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+}
+
+
+
+
+
+
+
+
+unsigned int RawCOPPERFormat_v0::GetB2LFEE32bitEventNumber(int n)
+{
+
+#ifndef READ_OLD_B2LFEE_FORMAT_FILE
+
+  int err_flag = 0;
+  unsigned int eve_num = 0;
+  int flag = 0;
+  unsigned int eve[4];
+  for (int i = 0; i < 4 ; i++) {
+    eve[ i ] = 12345678;
+    if (GetFINESSENwords(n, i) > 0) {
+      int pos_nwords = GetOffsetFINESSE(n, i) + SIZE_B2LHSLB_HEADER + POS_TT_TAG;
+      eve[ i ] = m_buffer[ pos_nwords ];
+      if (flag != 1) eve_num = eve[ i ];
+      if (eve_num != eve[ i ]) err_flag = 1;
+      flag = 1;
+    }
+  }
+
+  if (flag == 0) {
+    char err_buf[500];
+    sprintf(err_buf, "No HSLB data in COPPER data. Exiting...\n%s %s %d\n",
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s\n", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  if (err_flag == 1) {
+
+    char err_buf[500];
+    sprintf(err_buf, "CORRUPTED DATA: Different event number over HSLBs : slot A 0x%x : B 0x%x :C 0x%x : D 0x%x\n%s %s %d\n",
+            eve[ 0 ], eve[ 1 ], eve[ 2 ], eve[ 3 ],
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("[DEBUG] [ERROR] %s\n", err_buf);
+#ifndef NO_DATA_CHECK
+    B2FATAL(err_buf);
+#endif //NO_DATA_CHECK
+  }
+  return eve_num;
+
+#else // READ_OLD_B2LFEE_FORMAT_FILE
+
+  char err_buf[500];
+  sprintf(err_buf, "You need comment out READ_OLD_B2LFEE_FORMAT_FILE if you are handling a new data format\n%s %s %d\n",
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+#endif // READ_OLD_B2LFEE_FORMAT_FILE
+
+}
+
+
+
+
+void RawCOPPERFormat_v0::CheckData(int n,
+                                   unsigned int prev_evenum, unsigned int* cur_evenum_rawcprhdr,
+                                   unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
+                                   unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+{
+
+  char err_buf[500];
+  sprintf(err_buf,
+          "This function for format ver.0 is not supported. (n %d preveve %u eve %u  prectr %u ctr %u prevrun %u run %u) Exiting...\n %s %s %d\n",
+          n, prev_evenum, *cur_evenum_rawcprhdr, prev_copper_ctr, *cur_copper_ctr,
+          prev_exprunsubrun_no, *cur_exprunsubrun_no,
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+
+//   char err_buf[500];
+//   int err_flag = 0;
+//   //
+//   // check Magic words
+//   //
+//   if (!CheckCOPPERMagic(n)) {
+//     sprintf(err_buf, "CORRUPTED DATA: Invalid Magic word 0x7FFFF0008=%u 0xFFFFFAFA=%u 0xFFFFF5F5=%u 0x7FFF0009=%u\n%s %s %d\n",
+//             GetMagicDriverHeader(n),
+//             GetMagicFPGAHeader(n),
+//             GetMagicFPGATrailer(n),
+//             GetMagicDriverTrailer(n),
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     err_flag = 1;
+//   }
+//   //
+//   // Event # check
+//   //
+//   *cur_evenum_rawcprhdr = GetEveNo(n);
+//   unsigned int evenum_feehdr = GetB2LFEE32bitEventNumber(n);
+//   if (*cur_evenum_rawcprhdr != evenum_feehdr) {
+//     sprintf(err_buf,
+//             "CORRUPTED DATA: Event # in RawCOPPERFormat_v0 header and FEE header is different : cprhdr 0x%x feehdr 0x%x : Exiting...\n%s %s %d\n",
+//             *cur_evenum_rawcprhdr, evenum_feehdr,
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     err_flag = 1;
+//   }
+
+//   //
+//   // Check incrementation of event #
+//   //
+//   *cur_runsubrun_no = GetRunNoSubRunNo(n);
+//   if (
+// #ifdef WO_FIRST_EVENUM_CHECK
+//     prev_evenum != 0xFFFFFFFF && *cur_evenum_rawcprhdr != 0
+// #else
+//     prev_runsubrun_no == *cur_runsubrun_no && prev_runsubrun_no >= 0
+// #endif
+//   ) {
+//     if ((unsigned int)(prev_evenum + 1) != *cur_evenum_rawcprhdr) {
+//       sprintf(err_buf, "CORRUPTED DATA: Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n%s %s %d\n",
+//               n, prev_evenum, *cur_evenum_rawcprhdr,
+//               __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//       err_flag = 1;
+//     }
+//   }
+
+
+//   *cur_copper_ctr = GetCOPPERCounter(n);
+//   if (
+// #ifdef WO_FIRST_EVENUM_CHECK
+//     prev_copper_ctr != 0xFFFFFFFF
+// #else
+//     true
+// #endif
+//   ) {
+//     if ((unsigned int)(prev_copper_ctr + 1) != *cur_copper_ctr) {
+//       sprintf(err_buf, "COPPER counter jump : i %d prev 0x%x cur 0x%x :\n%s %s %d\n",
+//               n, prev_copper_ctr, *cur_copper_ctr,
+//               __FILE__, __PRETTY_FUNCTION__, __LINE__);
+
+// #ifdef DESY
+//       //
+//       // In DESY test, we ignore this error
+//       //
+//       printf("[DEBUG] [INFO] %s", err_buf);
+// #else
+//       err_flag = 1;
+// #endif
+
+//     }
+//   }
+
+//   //
+//   // Check is utime and ctime_trgtype same over different FINESSE data
+//   //
+//   CheckUtimeCtimeTRGType(n);
+
+
+//   //
+//   // Check checksum calculated by COPPER driver
+//   //
+//   if (GetDriverChkSum(n) != CalcDriverChkSum(n)) {
+//     sprintf(err_buf,
+//             "CORRUPTED DATA: COPPER driver checkSum error : block %d : length %d eve 0x%x : Trailer chksum 0x%.8x : calcd. now 0x%.8x\n%s %s %d\n",
+//             n,
+//             GetBlockNwords(n),
+//             *cur_evenum_rawcprhdr,
+//             GetDriverChkSum(n),
+//             CalcDriverChkSum(n),
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     err_flag = 1;
+//   }
+
+
+//   //
+//   // Check checksum calculated by DeSerializerCOPPER()
+//   //
+
+//   tmp_trailer.SetBuffer(GetRawTrlBufPtr(n));
+//   unsigned int xor_chksum = CalcXORChecksum(GetBuffer(n), GetBlockNwords(n) - tmp_trailer.GetTrlNwords());
+//   if (tmp_trailer.GetChksum() != xor_chksum) {
+//     sprintf(err_buf,
+//             "CORRUPTED DATA: RawCOPPERFormat_v0 checksum error : block %d : length %d eve 0x%x : Trailer chksum 0x%.8x : calcd. now 0x%.8x\n %s %s %d\n",
+//             n, GetBlockNwords(n), *cur_evenum_rawcprhdr, tmp_trailer.GetChksum(), xor_chksum,
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     err_flag = 1;
+//   }
+
+
+// #ifdef DEBUG
+//   printf("[DEBUG] eve %u %d %d %d %d\n",
+//          GetEveNo(n),
+//          Get1stDetectorNwords(n),
+//          Get2ndDetectorNwords(n),
+//          Get3rdDetectorNwords(n),
+//          Get4thDetectorNwords(n)
+//         );
+//   printf("[DEBUG] ===COPPER BLOCK==============\n");
+//   printData(GetBuffer(n), GetBlockNwords(n));
+
+//   printf("[DEBUG] ===FINNESSE A ==============\n");
+//   printData(Get1stDetectorBuffer(n), Get1stDetectorNwords(n));
+
+//   printf("[DEBUG] ===FINNESSE B ==============\n");
+//   printData(Get2ndDetectorBuffer(n), Get2ndDetectorNwords(n));
+
+//   printf("[DEBUG] ===FINNESSE C ==============\n");
+//   printData(Get3rdDetectorBuffer(n), Get3rdDetectorNwords(n));
+
+//   printf("[DEBUG] ===FINNESSE D ==============\n");
+//   printData(Get4thDetectorBuffer(n), Get4thDetectorNwords(n));
+//   printf("[DEBUG] === END ==============\n");
+
+// #endif
+
+//   if (err_flag == 1) {
+//     printf("[DEBUG] ========== dump a data blcok : block # %d==========\n", n);
+//     PrintData(GetBuffer(n), GetBlockNwords(n));
+//     string err_str = err_buf;
+//     throw (err_str);
+//     //     sleep(1234567);
+//     //     exit(-1);
+//   }
+
+  return;
+
+}
+
+bool RawCOPPERFormat_v0::CheckCOPPERMagic(int n)
+{
+  if (GetMagicDriverHeader(n) != COPPER_MAGIC_DRIVER_HEADER) {
+    return false;
+  } else if (GetMagicFPGAHeader(n) != COPPER_MAGIC_FPGA_HEADER) {
+    return false;
+  } else if (GetMagicFPGATrailer(n) != COPPER_MAGIC_FPGA_TRAILER) {
+    return false;
+  } else if (GetMagicDriverTrailer(n) != COPPER_MAGIC_DRIVER_TRAILER) {
+    return false;
+  }
+  return true;
+}
+
+void RawCOPPERFormat_v0::CheckUtimeCtimeTRGType(int n)
+{
+
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+  CheckB2LFEEHeaderVersion(n);
+#endif
+  int err_flag = 0;
+  int flag = 0;
+  unsigned int temp_utime = 0, temp_ctime_trgtype = 0;
+  unsigned int utime[4], ctime_trgtype[4];
+  memset(utime, 0, sizeof(utime));
+  memset(ctime_trgtype, 0, sizeof(ctime_trgtype));
+
+  for (int i = 0; i < 4; i++) {
+    if (GetFINESSENwords(n, i) > 0) {
+      ctime_trgtype[ i ] = m_buffer[ GetOffsetFINESSE(n, i) +
+                                     SIZE_B2LHSLB_HEADER + POS_TT_CTIME_TYPE ];
+      utime[ i ] = m_buffer[ GetOffsetFINESSE(n, i) +
+                             SIZE_B2LHSLB_HEADER + POS_TT_UTIME ];
+      if (flag == 0) {
+        temp_ctime_trgtype = ctime_trgtype[ i ];
+        temp_utime = utime[ i ];
+        flag = 1;
+      } else {
+        if (temp_ctime_trgtype != ctime_trgtype[ i ]
+            || temp_utime != utime[ i ]) {
+          err_flag = 1;
+        }
+      }
+    }
+  }
+
+  if (err_flag != 0) {
+    for (int i = 0; i < 4; i++) {
+      printf("[DEBUG] FINESSE #=%d buffsize %d ctimeTRGtype 0x%.8x utime 0x%.8x\n",
+             i, GetFINESSENwords(n, i), ctime_trgtype[ i ], utime[ i ]);
+    }
+    char err_buf[500];
+    sprintf(err_buf, "CORRUPTED DATA: mismatch over FINESSEs. Exiting...\n %s %s %d\n",
+            __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+  return;
+}
+
+
+unsigned int RawCOPPERFormat_v0::FillTopBlockRawHeader(unsigned int m_node_id, unsigned int prev_eve32,
+                                                       unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+{
+
+  char err_buf[500];
+  sprintf(err_buf,
+          "This function for format ver.0 is not supported. (node %.8x preveve %u prevrun %u currun %u ) Exiting...\n %s %s %d\n",
+          m_node_id,  prev_eve32, prev_exprunsubrun_no, *cur_exprunsubrun_no,
+          __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+  return 0;
+
+//   const int cpr_id = 0;
+//   //  m_temp_value = 12345678;
+//   //
+//   // This function only fills RawHeader contents for the first datablock.
+//   // # of block should be 1
+//   if (m_num_nodes * m_num_events != 1) {
+//     char err_buf[500];
+//     sprintf(err_buf,
+//             "This function should be used for RawCOPPERFormat_v0 containing only one datablock, while. this object has num_nodes of %d and num_events of %d\n %s %s %d\n",
+//             m_num_nodes, m_num_events,  __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     string err_str = err_buf;    throw (err_str);
+//   }
+
+//   //////////////////////////////////////////////////
+//   //
+//   // Fill info in RawHeader
+//   //
+//   //////////////////////////////////////////////////
+
+//   //
+//   // Initialize a RawHeader part
+//   //
+//   memset(m_buffer, 0, sizeof(int) * tmp_header.RAWHEADER_NWORDS);
+//   m_buffer[ tmp_header.POS_HDR_NWORDS ] = tmp_header.RAWHEADER_NWORDS;
+
+//   //
+//   // Check FINESSEs which containes data
+//   //
+//   int* copper_buf = &(m_buffer[ tmp_header.RAWHEADER_NWORDS ]);
+//   if (copper_buf[ POS_CH_A_DATA_LENGTH ] == 0 &&
+//       copper_buf[ POS_CH_B_DATA_LENGTH ] == 0 &&
+//       copper_buf[ POS_CH_C_DATA_LENGTH ] == 0 &&
+//       copper_buf[ POS_CH_D_DATA_LENGTH ] == 0) {
+//     char err_buf[500];
+//     sprintf(err_buf,
+//             "No FINESSE data in a copper data block. Exiting...\n %s %s %d\n",
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     string err_str = err_buf; throw (err_str);
+//     //     sleep(12345678);
+//     //     exit(-1);
+//   }
+
+//   //
+//   //   Set total words info
+//   //
+//   int datablock_nwords =
+//     tmp_header.RAWHEADER_NWORDS +
+//     (copper_buf[ POS_DATA_LENGTH ]
+//      + SIZE_COPPER_DRIVER_HEADER
+//      + SIZE_COPPER_DRIVER_TRAILER)
+//     + tmp_trailer.RAWTRAILER_NWORDS;
+//   m_buffer[ tmp_header.POS_NWORDS ] = datablock_nwords;
+
+//   //
+//   // Check the consistency between data length and length in RawHeader
+//   //
+//   if (m_buffer[ tmp_header.POS_NWORDS ] != m_nwords) {
+//     char err_buf[500];
+//     sprintf(err_buf,
+//             "CORRUPTED DATA: Data length is inconsistent m_nwords %d : nwords from COPPER data %d\n %s %s %d\n",
+//             m_nwords, m_buffer[ tmp_header.POS_NWORDS ],
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     string err_str = err_buf; throw (err_str);
+//     //     sleep(12345678);
+//     //     exit(-1);
+//   }
+
+//   //
+//   // Fill offset values
+//   //
+//   int offset_1st_finesse =  tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
+//   int offset_2nd_finesse = offset_1st_finesse + copper_buf[ POS_CH_A_DATA_LENGTH ];
+//   int offset_3rd_finesse = offset_2nd_finesse + copper_buf[ POS_CH_B_DATA_LENGTH ];
+//   int offset_4th_finesse = offset_3rd_finesse + copper_buf[ POS_CH_C_DATA_LENGTH ];
+//   m_buffer[ tmp_header.POS_OFFSET_1ST_FINESSE ] = offset_1st_finesse;
+//   m_buffer[ tmp_header.POS_OFFSET_2ND_FINESSE ] = offset_2nd_finesse;
+//   m_buffer[ tmp_header.POS_OFFSET_3RD_FINESSE ] = offset_3rd_finesse;
+//   m_buffer[ tmp_header.POS_OFFSET_4TH_FINESSE ] = offset_4th_finesse;
+
+//   //
+//   // Fill Exp/Run value
+//   //
+//   int* finesse_buf = &
+//                      (m_buffer[ offset_1st_finesse ]); // In any finesse implementations, the top finesse buffer should be at offset_1st_finesse;
+//   m_buffer[ tmp_header.POS_EXP_RUN_NO ] = finesse_buf[ SIZE_B2LHSLB_HEADER + POS_EXP_RUN ];
+
+
+//   //
+//   // Fill event #
+//   //
+//   unsigned int cur_ftsw_eve32 =  finesse_buf[ SIZE_B2LHSLB_HEADER + POS_TT_TAG ];
+//   m_buffer[ tmp_header.POS_EVE_NO ] = cur_ftsw_eve32;
+
+//   //
+//   // Copy FTSW words from B2LFEE header
+//   //
+//   m_buffer[ tmp_header.POS_TTCTIME_TRGTYPE ] = finesse_buf[ SIZE_B2LHSLB_HEADER + POS_TT_CTIME_TYPE ];
+//   m_buffer[ tmp_header.POS_TTUTIME ] = finesse_buf[ SIZE_B2LHSLB_HEADER + POS_TT_UTIME ];
+
+//   //
+//   // Set node ID, trunc_mask, data_type
+//   //
+//   m_buffer[ tmp_header.POS_NODE_ID ] = m_node_id;
+//   m_buffer[ tmp_header.POS_TRUNC_MASK_DATATYPE ] = ((m_trunc_mask << 31) & 0x80000000) | (m_data_type & 0x7FFFFFFF);
+
+//   //
+//   // Set RawHeader magic word
+//   //
+//   m_buffer[ tmp_header.POS_TERM_HEADER ] = tmp_header.MAGIC_WORD_TERM_HEADER;
+
+
+//   //
+//   // Add node-info
+//   //
+//   if (m_buffer[ tmp_header.POS_NUM_NODES ] < tmp_header.NUM_MAX_NODES) {
+//     m_buffer[ tmp_header.POS_NODES_1 + m_buffer[ tmp_header.POS_NUM_NODES ] ] = m_node_id;
+//   }
+//   m_buffer[ tmp_header.POS_NUM_NODES ]++;
+
+
+
+//   //////////////////////////////////////////////////
+//   //
+//   // Fill info in RawTrailer
+//   //
+//   //////////////////////////////////////////////////
+
+//   //
+//   // Calculate XOR checksum
+//   //
+//   unsigned int chksum_top = 0, chksum_body = 0, chksum_bottom = 0;
+
+//   int top_end = tmp_header.RAWHEADER_NWORDS;
+//   for (int i = 0; i < top_end; i++) {
+//     chksum_top ^= m_buffer[ i ];
+//   }
+//   int body_end = datablock_nwords - SIZE_COPPER_DRIVER_TRAILER - tmp_trailer.RAWTRAILER_NWORDS;
+//   for (int i = top_end; i < body_end; i++) {
+//     chksum_body ^= m_buffer[ i ];
+//   }
+
+//   int bottom_end = datablock_nwords - tmp_trailer.RAWTRAILER_NWORDS;
+//   for (int i = body_end; i < bottom_end; i++) {
+//     chksum_bottom ^= m_buffer[ i ];
+//   }
+
+//   //
+//   // check COPPER driver checksum
+//   //
+//   if (chksum_body != (unsigned int)(m_buffer[ body_end ])) {
+//     char err_buf[500];
+//     sprintf(err_buf, "CORRUPTED DATA: COPPER driver checksum is not consistent.: calcd. %.8x data %.8x\n %s %s %d\n",
+//             chksum_body, m_buffer[ body_end ],
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     string err_str = err_buf; throw (err_str);
+//     //     sleep(12345678);
+//     //     exit(-1);
+//   }
+
+//   //
+//   // Fill trailer info (checksum, magic word)
+//   //
+//   unsigned int chksum = chksum_top ^ chksum_body ^ chksum_bottom;
+//   int* trl = &(m_buffer[ datablock_nwords - tmp_trailer.RAWTRAILER_NWORDS ]);
+//   trl[ tmp_trailer.POS_CHKSUM ] = chksum;
+//   trl[ tmp_trailer.POS_TERM_WORD ] = tmp_trailer.MAGIC_WORD_TERM_TRAILER;
+
+
+//   //////////////////////////////////////////////////
+//   //
+//   // Data check ( magic word, event incrementation )
+//   //
+//   //////////////////////////////////////////////////
+
+
+//   //
+//   // check magic words
+//   //
+//   int* fpga_trailer_magic = trl - 3;
+//   int* driver_trailer_magic = trl - 1;
+//   int err_flag = 0;
+//   if ((unsigned int)(copper_buf[ POS_MAGIC_COPPER_1 ]) != COPPER_MAGIC_DRIVER_HEADER) {
+//     err_flag = 1;
+//   } else if ((unsigned int)(copper_buf[ POS_MAGIC_COPPER_2 ]) != COPPER_MAGIC_FPGA_HEADER) {
+//     err_flag = 1;
+//   } else if ((unsigned int)(*fpga_trailer_magic) != COPPER_MAGIC_FPGA_TRAILER) {
+//     err_flag = 1;
+//   } else if ((unsigned int)(*driver_trailer_magic) != COPPER_MAGIC_DRIVER_TRAILER) {
+//     err_flag = 1;
+//   }
+//   if (err_flag == 1) {
+//     char err_buf[500];
+//     sprintf(err_buf, "CORRUPTED DATA: Invalid Magic word 0x7FFFF0008=%u 0xFFFFFAFA=%u 0xFFFFF5F5=%u 0x7FFF0009=%u\n %s %s %d\n",
+//             GetMagicDriverHeader(cpr_id),
+//             GetMagicFPGAHeader(cpr_id),
+//             GetMagicFPGATrailer(cpr_id),
+//             GetMagicDriverTrailer(cpr_id),
+//             __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//     printf("[DEBUG] [ERROR] %s\n", err_buf);
+// #ifndef NO_DATA_CHECK
+//     string err_str = err_buf; throw (err_str);
+
+//     //     sleep(12345678);
+//     //     exit(-1);
+// #endif
+//   }
+
+//   //
+//   // check incrementation of event #
+//   //
+//   *cur_runsubrun_no = GetRunNoSubRunNo(cpr_id);
+//   if (prev_runsubrun_no == *cur_runsubrun_no && prev_runsubrun_no >= 0) {
+//     if (
+// #ifdef WO_FIRST_EVENUM_CHECK
+//       (prev_eve32 + 1 != cur_ftsw_eve32) && (prev_eve32 != 0xFFFFFFFF && cur_ftsw_eve32 != 0)
+// #else
+//       prev_eve32 + 1 != cur_ftsw_eve32
+// #endif
+//     ) {
+
+// #ifndef NO_DATA_CHECK
+//       char err_buf[500];
+//       sprintf(err_buf, "CORRUPTED DATA: Invalid event_number. Exiting...: cur 32bit eve %u preveve %u prun %d crun %d\n %s %s %d\n",
+//               cur_ftsw_eve32, prev_eve32,
+//               prev_runsubrun_no, *cur_runsubrun_no,
+//               __FILE__, __PRETTY_FUNCTION__, __LINE__);
+//       printf("[DEBUG] [ERROR] %s\n", err_buf);
+
+//       string err_str = err_buf;
+//       printf("[DEBUG] i= %d : num entries %d : Tot words %d\n", 0 , GetNumEntries(), TotalBufNwords());
+//       PrintData(GetBuffer(cpr_id), TotalBufNwords());
+//       throw (err_str);
+//       //      exit(-1);
+// #endif
+
+//     }
+//   }
+
+//   return cur_ftsw_eve32;
+
+}
+
+
+
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+void RawCOPPERFormat_v0::CheckB2LFEEHeaderVersion(int n)
+{
+
+  int* temp_buf;
+
+  for (int i = 0; i < 4; i++) {
+    if (GetFINESSENwords(n, i) > 0) {
+      temp_buf = GetFINESSEBuffer(n, i);
+      if ((temp_buf[ 3 ] & 0x40000000) == 0) {
+#ifdef TEMP
+        // this word for exp/run
+        // old one (ver.1) used for SPring8 test in 2013
+        printf("[DEBUG] \033[31m");
+        printf("[DEBUG] ===Firmware ver. ERROR===\n ");
+        printf("[DEBUG] FTSW and b2tt firmwares was updated on Nov.22, 2013 and the header format attached by B2link was changed in the new firmwares.\n");
+        printf("[DEBUG] If you are going to take data now, Please update the firmware.\n");
+        printf("[DEBUG] For details, please see Nakao-san's e-mail [b2link_ml:0111] Re: [daq2ml:0159] beta version of trigger timing receiver firmware (b2tt) on bdaq SVN\n");
+        printf("[DEBUG] Or if you are going to read data taken before the update, please use basf2 software before rev. 7419\n");
+        printf("[DEBUG] About the format please see Nakao-san's B2GM slides(p. 13 and 15) http://kds.kek.jp/getFile.py/access?contribId=143&sessionId=38&resId=0&materialId=slides&confId=13911.\n");
+        printf("[DEBUG] Sorry for inconvenience.\n");
+        printf("[DEBUG] \033[0m");
+        fflush(stderr);
+        char err_buf[500];
+        sprintf(err_buf, "FTSW and b2tt firmwares are old. Exiting...\n %s %s %d\n",
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        printf("%s", err_buf); fflush(stdout);
+        B2FATAL(err_buf);
+#endif
+      } else {
+        // this word for 32bit unixtime
+        // new one (ver.2)
+        break;
+      }
+    }
+
+    if (i == 3) {
+#ifdef TEMP
+      char err_buf[500];
+      sprintf(err_buf, "RawCOPPERFormat_v0 contains no FINESSE data. Exiting...\n %s %s %d\n",
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      B2FATAL(err_buf);
+#endif
+    }
+  }
+  return;
+}
+#endif
+
+int* RawCOPPERFormat_v0::PackDetectorBuf(int* packed_buf_nwords,
+                                         int* detector_buf_1st, int nwords_1st,
+                                         int* detector_buf_2nd, int nwords_2nd,
+                                         int* detector_buf_3rd, int nwords_3rd,
+                                         int* detector_buf_4th, int nwords_4th,
+                                         RawCOPPERPackerInfo rawcprpacker_info)
+{
+  char err_buf[500];
+  sprintf(err_buf, "This function is not supported (%p %p %d %p %d %p %d %p %d %p ) Exiting...\n%s %s %d\n"
+          , packed_buf_nwords, detector_buf_1st, nwords_1st, detector_buf_2nd, nwords_2nd, detector_buf_3rd,
+          nwords_3rd, detector_buf_4th, nwords_4th, &rawcprpacker_info, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawCOPPERFormat_v1.cc b/ROPCApplications/rawdata/dataobjects/src/RawCOPPERFormat_v1.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4c28debc3fbe0b0f177bb4a4fca364f85245b676
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawCOPPERFormat_v1.cc
@@ -0,0 +1,88 @@
+//+
+// File : RawCOPPERFormat_v1.cc
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawCOPPERFormat_v1.h>
+
+
+using namespace std;
+using namespace Belle2;
+
+//#define DESY
+//#define NO_DATA_CHECK
+//#define WO_FIRST_EVENUM_CHECK
+
+//ClassImp(RawCOPPERFormat_v1);
+
+RawCOPPERFormat_v1::RawCOPPERFormat_v1()
+{
+}
+
+RawCOPPERFormat_v1::~RawCOPPERFormat_v1()
+{
+}
+
+int RawCOPPERFormat_v1::GetNumFINESSEBlock(int n)
+{
+  int cnt = 0;
+  for (int i = 0; i < 4; i++) {
+    if (GetFINESSENwords(n, i) > 0) {
+      cnt++;
+    }
+  }
+  return cnt;
+}
+
+#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
+void RawCOPPERFormat_v1::CheckB2LFEEHeaderVersion(int n)
+{
+
+  int* temp_buf;
+
+  for (int i = 0; i < 4; i++) {
+    if (GetFINESSENwords(n, i) > 0) {
+      temp_buf = GetFINESSEBuffer(n, i);
+      if ((temp_buf[ 3 ] & 0x40000000) == 0) {
+#ifdef TEMP
+        // this word for exp/run
+        // old one (ver.1) used for SPring8 test in 2013
+        printf("[DEBUG] \033[31m");
+        printf("[DEBUG] ===Firmware ver. ERROR===\n ");
+        printf("[DEBUG] FTSW and b2tt firmwares was updated on Nov.22, 2013 and the header format attached by B2link was changed in the new firmwares.\n");
+        printf("[DEBUG] If you are going to take data now, Please update the firmware.\n");
+        printf("[DEBUG] For details, please see Nakao-san's e-mail [b2link_ml:0111] Re: [daq2ml:0159] beta version of trigger timing receiver firmware (b2tt) on bdaq SVN\n");
+        printf("[DEBUG] Or if you are going to read data taken before the update, please use basf2 software before rev. 7419\n");
+        printf("[DEBUG] About the format please see Nakao-san's B2GM slides(p. 13 and 15) http://kds.kek.jp/getFile.py/access?contribId=143&sessionId=38&resId=0&materialId=slides&confId=13911.\n");
+        printf("[DEBUG] Sorry for inconvenience.\n");
+        printf("[DEBUG] \033[0m");
+        fflush(stderr);
+        char err_buf[500];
+        sprintf(err_buf, "FTSW and b2tt firmwares are old. Exiting...\n %s %s %d\n",
+                __FILE__, __PRETTY_FUNCTION__, __LINE__);
+        printf("%s", err_buf); fflush(stdout);
+        B2FATAL(err_buf);
+#endif
+      } else {
+        // this word for 32bit unixtime
+        // new one (ver.2)
+        break;
+      }
+    }
+
+    if (i == 3) {
+#ifdef TEMP
+      char err_buf[500];
+      sprintf(err_buf, "RawCOPPERFormat_v1 contains no FINESSE data. Exiting...\n %s %s %d\n",
+              __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      B2FATAL(err_buf);
+#endif
+    }
+  }
+  return;
+}
+#endif
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawDataBlock.cc b/ROPCApplications/rawdata/dataobjects/src/RawDataBlock.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b8bd56264788f72ec766ce155d94341cbb8bd1e8
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawDataBlock.cc
@@ -0,0 +1,69 @@
+//+
+// File : RawDataBlock.cc
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawDataBlock.h>
+
+using namespace std;
+using namespace Belle2;
+
+RawDataBlock::RawDataBlock()
+{
+  m_access_dblk = new RawDataBlockFormat;
+
+  m_nwords = 0;
+  m_use_prealloc_buf = 0;
+  m_buffer = NULL;
+  m_num_nodes = 0;
+  m_num_events = 0;
+}
+
+RawDataBlock::~RawDataBlock()
+{
+  if (m_access_dblk != NULL) delete m_access_dblk;
+  m_access_dblk = NULL;
+
+  if (!m_use_prealloc_buf && m_buffer != NULL) {
+    delete[] m_buffer;
+  }
+}
+
+void RawDataBlock::SetBuffer(int* bufin, int nwords, int delete_flag, int num_events, int num_nodes)
+{
+
+  if (bufin == NULL) {
+    char err_buf[500];
+    sprintf(err_buf, "[DEBUG] bufin is NULL. Exting...\n");
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  if (!m_use_prealloc_buf && m_buffer != NULL) delete[] m_buffer;
+
+  if (delete_flag == 0) {
+    m_use_prealloc_buf = true;
+  } else {
+    m_use_prealloc_buf = false;
+  }
+  //  m_nwords = bufin[0];
+  m_nwords = nwords;
+  m_buffer = bufin;
+
+  m_num_nodes = num_nodes;
+  m_num_events = num_events;
+
+  // Set to access class
+  m_access_dblk->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+
+  // Set length at the first word of the buffer
+  //
+  // Assign header and trailer
+  //
+  //   m_header.SetBuffer(&(bufin[ 0 ]));
+  //   m_trailer.SetBuffer(&(bufin[ m_nwords - m_trailer.GetTrlNwords() ]));
+
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawDataBlockFormat.cc b/ROPCApplications/rawdata/dataobjects/src/RawDataBlockFormat.cc
new file mode 100644
index 0000000000000000000000000000000000000000..57080678d5d5e93fbd91cf9db44d183c87cd2e8a
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawDataBlockFormat.cc
@@ -0,0 +1,177 @@
+//+
+// File : RawDataBlockFormat.cc
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawDataBlockFormat.h>
+
+using namespace std;
+using namespace Belle2;
+
+RawDataBlockFormat::RawDataBlockFormat()
+{
+  m_nwords = 0;
+  m_use_prealloc_buf = 0;
+  m_buffer = NULL;
+  m_num_nodes = 0;
+  m_num_events = 0;
+}
+
+RawDataBlockFormat::~RawDataBlockFormat()
+{
+  if (!m_use_prealloc_buf && m_buffer != NULL) {
+    delete[] m_buffer;
+  }
+}
+
+int RawDataBlockFormat::GetBufferPos(int n)
+{
+  if (m_buffer == NULL || m_nwords <= 0) {
+    char err_buf[500];
+    sprintf(err_buf, "[FATAL] RawPacket buffer(%p) is not available or length(%d) is not set.\n %s %s %d\n",
+            m_buffer, m_nwords, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  if (n >= (m_num_events * m_num_nodes)) {
+    char err_buf[500];
+    sprintf(err_buf, "[FATAL] Invalid COPPER block No. (%d : max %d ) is specified. Exiting... \n %s %s %d\n",
+            n, (m_num_events * m_num_nodes), __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  int pos_nwords = 0;
+  for (int i = 1; i <= n ; i++) {
+    if (m_buffer[ pos_nwords ] <= 0) {
+      char err_buf[500];
+      sprintf(err_buf,
+              "[FATAL] ERROR_EVENT : length of this data block is strange ( %d words ). Maybe data is corrupted or RawHeader info has not been filled yet. Exiting...",
+              m_buffer[ pos_nwords ]);
+      printf("%s", err_buf);
+      B2FATAL(err_buf);
+    } else {
+      pos_nwords +=      m_buffer[ pos_nwords ];
+    }
+    if (pos_nwords >= m_nwords) {
+      char err_buf[500];
+      sprintf(err_buf, "[FATAL] ERROR_EVENT : value of pos_nwords(%d) is larger than m_nwords(%d). Exiting...\n %s %s %d\n",
+              pos_nwords, m_nwords, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      B2FATAL(err_buf); // to reduce multiple error messages
+    }
+  }
+  return pos_nwords;
+
+}
+
+
+int RawDataBlockFormat::CheckFTSWID(int n)
+{
+  int pos = POS_NODE_ID;
+  if (m_buffer[ GetBufferPos(n) + TEMP_POS_NWORDS_HEADER ] == OLD_FTSW_NWORDS_HEADER) {
+    pos =  POS_FTSW_ID_OLD;
+  }
+
+  if ((m_buffer[ GetBufferPos(n) + pos ] & 0xffffff00) == 0x54544400) {     // "TTD" + format version ( 0x20=DESY, 0x31=2018/7/11)
+    return 1;
+  } else {
+    return 0;
+  }
+}
+
+
+int RawDataBlockFormat::CheckTLUID(int n)
+{
+  int pos = POS_NODE_ID;
+  if (m_buffer[ GetBufferPos(n) + TEMP_POS_NWORDS_HEADER ] == OLD_FTSW_NWORDS_HEADER) {
+    pos =  POS_FTSW_ID_OLD;
+  }
+  if (m_buffer[ GetBufferPos(n) + pos ] == 0x544c5520) { // "TLU "
+    return 1;
+  } else {
+    return 0;
+  }
+}
+
+int RawDataBlockFormat::TotalBufNwords()
+{
+  return m_nwords;
+}
+
+
+int RawDataBlockFormat::GetBlockNwords(int n)
+{
+  int size;
+  if (n == (m_num_events * m_num_nodes) - 1) {
+    size =  m_nwords - GetBufferPos(n);
+  } else {
+    size = GetBufferPos(n + 1) - GetBufferPos(n);
+  }
+  return size;
+}
+
+
+int* RawDataBlockFormat::GetWholeBuffer()
+{
+  return m_buffer;
+}
+
+int* RawDataBlockFormat::GetBuffer(int n)
+{
+  int pos_nwords = GetBufferPos(n);
+  return &(m_buffer[ pos_nwords ]);
+}
+
+
+void RawDataBlockFormat::SetBuffer(int* bufin, int nwords, int delete_flag, int num_events, int num_nodes)
+{
+
+  if (bufin == NULL) {
+    char err_buf[500];
+    sprintf(err_buf, "[DEBUG] bufin is NULL. Exting...\n");
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  if (!m_use_prealloc_buf && m_buffer != NULL) delete[] m_buffer;
+
+  if (delete_flag == 0) {
+    m_use_prealloc_buf = true;
+  } else {
+    m_use_prealloc_buf = false;
+  }
+
+  m_nwords = nwords;
+  m_buffer = bufin;
+
+  m_num_nodes = num_nodes;
+  m_num_events = num_events;
+
+  return;
+
+}
+
+
+
+void RawDataBlockFormat::PrintData(int* buf, int nwords)
+{
+  printf("[DEBUG] ");
+  for (int i = 0; i < nwords; i++) {
+    printf("%.8x ", buf[ i ]);
+    if (i % 10 == 9) printf("\n[DEBUG] ");
+  }
+  printf("\n[DEBUG] ");
+  printf("\n");
+  return;
+}
+
+void RawDataBlockFormat::CopyBlock(int n, int* buf_to)
+{
+  memcpy(buf_to, GetBuffer(n), GetBlockNwords(n) * sizeof(int));
+  return;
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawECL.cc b/ROPCApplications/rawdata/dataobjects/src/RawECL.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7cc2a4eb958dd9a149256585479d239d6bac8bff
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawECL.cc
@@ -0,0 +1,20 @@
+//+
+// File : RawCOPPER.cc
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawECL.h>
+
+using namespace std;
+using namespace Belle2;
+
+RawECL::RawECL()
+{
+}
+
+RawECL::~RawECL()
+{
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawFTSW.cc b/ROPCApplications/rawdata/dataobjects/src/RawFTSW.cc
new file mode 100644
index 0000000000000000000000000000000000000000..725d0a2e40a5674d79258701f39403aebac33986
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawFTSW.cc
@@ -0,0 +1,132 @@
+//+
+// File : RawFTSW.cc
+// Description : Module to handle raw data from FTSW
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawFTSW.h>
+using namespace std;
+using namespace Belle2;
+
+RawFTSW::RawFTSW()
+{
+  m_access = NULL;
+  m_version = -1;
+}
+
+RawFTSW::~RawFTSW()
+{
+  if (m_access != NULL) delete m_access;
+  m_access = NULL;
+}
+
+void RawFTSW::SetVersion()
+{
+  if (m_buffer == NULL) {
+    char err_buf[500];
+    sprintf(err_buf, "m_buffer is NULL. Exiting...");
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  if (m_access != NULL) {
+    delete m_access;
+    m_access = nullptr;
+  }
+
+  //
+  // Assign unpacker
+  //
+  // Special treatment is required because Nakao-san did not set verision number in ver.0,1, and 2 header.
+  // I'm using the size of header which is stored the 1st word (0,1,..)
+  //
+  int temp_version = m_version;
+  if (m_buffer[ POS_HEADER_SIZE ] == VER_0_HEADER_SIZE) {
+    char err_buf[500];
+    sprintf(err_buf,
+            "[FATAL] Ver.0 of RawFTSW( so-called early DESYtest format ) is detected but not supported. (header size = 0x%.8x ) Exiting...\n %s %s %d\n",
+            m_buffer[ POS_HEADER_SIZE ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  } else if (m_buffer[ POS_NODE_FORMAT_ID ] == FORMAT_ID_VER_0TO2) {
+    if (m_buffer[ POS_HEADER_SIZE ] == VER_2_HEADER_SIZE) {
+      m_access = new RawFTSWFormat_v2;
+      m_version = 2; // as of 2019.3.2, the latest version is 2.
+    } else if (m_buffer[ POS_HEADER_SIZE ] == VER_1_HEADER_SIZE) {
+      m_access = new RawFTSWFormat_v1;
+      m_version = 1;
+    } else {
+      char err_buf[500];
+      sprintf(err_buf, "[FATAL] ERROR_EVENT : Invalid RawFTSW header size of FTSW data format(= 0x%.8x words). Exiting...\n %s %s %d\n",
+              m_buffer[ POS_HEADER_SIZE ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf); fflush(stdout);
+      B2FATAL(err_buf);
+    }
+  } else if (m_buffer[ POS_NODE_FORMAT_ID ] == FORMAT_ID_VER_0TO3 ||
+             m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544432 ||
+             m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544433 ||
+             m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544434 ||
+             m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544435 ||
+             m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544436 ||
+             m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544437 ||
+             m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544438 ||
+             m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544439) {
+    // Request from Nakao-san in Oct. 15, 2019
+    // - FORMAT_ID_VER_0TO3 should be changed to x"54544431" from x"5454421"
+    // - RawFTSWFormat_latest should accept newer format versions(= larger version number), so that this unpacker
+    //    will not stop due to version error, when Nakao-san updated version number in RawFTSW data.
+    // -- Since the latest format is basically the addition of some variables in RawFTSW data, probably it won't cause the problem.
+    m_access = new RawFTSWFormat_latest;
+    m_version = 3; // as of 2019.3.20 the latest version is 3.
+  } else {
+    char err_buf[500];
+    sprintf(err_buf,
+            "[FATAL] ERROR_EVENT : Invalid RawFTSW header size(= 0x%.8x words) or version number.(=0x%.8x) Exiting...\n %s %s %d\n",
+            m_buffer[ POS_HEADER_SIZE ], m_buffer[ POS_NODE_FORMAT_ID ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+
+  if (temp_version >= 0 && temp_version != m_version) {
+    char err_buf[500];
+    sprintf(err_buf,
+            "[FATAL] Already assigned RawFTSW format version (= %.8x) is different from the one (= 0x%.8x) from the current event. Exiting...\n %s %s %d\n",
+            temp_version, m_version, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  m_access->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
+}
+
+
+// I copied this from RawCOPPER.cc, since SetVersion() is necessary for RawFTSW after ver.2 is included.
+void RawFTSW::SetBuffer(int* bufin, int nwords, int delete_flag, int num_events, int num_nodes)
+{
+
+  if (bufin == NULL) {
+    char err_buf[500];
+    sprintf(err_buf, "[FATAL] bufin is NULL. Exting...\n");
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+  if (!m_use_prealloc_buf && m_buffer != NULL) delete[] m_buffer;
+
+  if (delete_flag == 0) {
+    m_use_prealloc_buf = true;
+  } else {
+    m_use_prealloc_buf = false;
+  }
+
+  m_nwords = nwords;
+  m_buffer = bufin;
+
+  m_num_nodes = num_nodes;
+  m_num_events = num_events;
+
+  SetVersion();
+
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawFTSWFormat.cc b/ROPCApplications/rawdata/dataobjects/src/RawFTSWFormat.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dcab7dcb6029a9efac1cb6d69dc940261432fc84
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawFTSWFormat.cc
@@ -0,0 +1,102 @@
+//+
+// File : RawFTSWFormat.cc
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+#include <rawdata/dataobjects/RawFTSWFormat.h>
+
+
+using namespace std;
+using namespace Belle2;
+
+RawFTSWFormat::RawFTSWFormat()
+{
+}
+
+RawFTSWFormat::~RawFTSWFormat()
+{
+}
+
+// This function is only available in RawFTSW ver.1 (for DESY test)
+int RawFTSWFormat::Get15bitTLUTag(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf,
+          "[FATAL] This function is not supported in the version of RawFTSW format that you're using. n=%d : %s %s %d: Exiting...\n",
+          n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s\n", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+  return -1;
+}
+
+// This function is only available in RawFTSW ver.2
+int RawFTSWFormat::GetIsHER(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf,
+          "[FATAL] This function is not supported in the version of RawFTSW format that you're using. n=%d : %s %s %d: Exiting...\n",
+          n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s\n", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+  return -1;
+}
+
+
+
+unsigned int RawFTSWFormat::GetTimeSinceLastInjection(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf,
+          "[FATAL] This function is not supported in the version of RawFTSW format that you're using. n=%d : %s %s %d: Exiting...\n",
+          n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s\n", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+  return -1;
+
+}
+
+unsigned int RawFTSWFormat::GetTimeSincePrevTrigger(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf,
+          "[FATAL] This function is not supported in the version of RawFTSW format that you're using. n=%d : %s %s %d: Exiting...\n",
+          n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s\n", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+  return -1;
+}
+
+unsigned int RawFTSWFormat::GetBunchNumber(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf,
+          "[FATAL] This function is not supported in the version of RawFTSW format that you're using. n=%d : %s %s %d: Exiting...\n",
+          n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s\n", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+  return -1;
+}
+
+unsigned int RawFTSWFormat::GetFrameCount(int n)
+{
+  char err_buf[500];
+  sprintf(err_buf,
+          "[FATAL] This function is not supported in the version of RawFTSW format that you're using. n=%d : %s %s %d: Exiting...\n",
+          n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+  printf("%s\n", err_buf); fflush(stdout);
+  B2FATAL(err_buf);
+  return -1;
+}
+
+void RawFTSWFormat::GetPCTimeVal(int n, struct timeval* tv)
+{
+  // According to Nakao-san's comment at DAQ meeting on Feb.28, 2020. If one calls this function for older data, just returning 0 values is fine.
+  // No need to either end up with FATAL message or issue any WARNING messages (Actually, WARNING messages would be issued in every event when implemented.)
+  tv->tv_sec = 0;
+  tv->tv_usec = 0;
+
+  return;
+
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawFTSWFormat_latest.cc b/ROPCApplications/rawdata/dataobjects/src/RawFTSWFormat_latest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2b727b298402d59b2cbc13ccb0828ee8845a4234
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawFTSWFormat_latest.cc
@@ -0,0 +1,179 @@
+//+
+// File : RawFTSWFormat_latest.cc
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 18 - Feb - 2019
+//-
+#include <rawdata/dataobjects/RawFTSWFormat_latest.h>
+
+
+using namespace std;
+using namespace Belle2;
+
+RawFTSWFormat_latest::RawFTSWFormat_latest()
+{
+}
+
+RawFTSWFormat_latest::~RawFTSWFormat_latest()
+{
+}
+
+
+unsigned int RawFTSWFormat_latest::GetTTCtimeTRGType(int n)
+{
+  return (unsigned int)(m_buffer[ GetBufferPos(n) +  POS_TT_CTIME_TRGTYPE ]);
+}
+
+
+
+int RawFTSWFormat_latest::GetTTCtime(int n)
+{
+  return (int)((GetTTCtimeTRGType(n) & TTCTIME_MASK) >> TTCTIME_SHIFT);
+}
+
+int RawFTSWFormat_latest::GetTRGType(int n)
+{
+  return (int)(GetTTCtimeTRGType(n) & TRGTYPE_MASK);
+}
+
+unsigned int RawFTSWFormat_latest::GetTTUtime(int n)
+{
+  return (unsigned int)(m_buffer[ GetBufferPos(n) +  POS_TT_UTIME ]);
+}
+
+void RawFTSWFormat_latest::GetTTTimeVal(int n, struct timeval* tv)
+{
+  tv->tv_sec = GetTTUtime(n);
+  tv->tv_usec = (int)(((double)GetTTCtime(n)) / 127.216);
+
+  return ;
+}
+
+void RawFTSWFormat_latest::GetTTTimeSpec(int n, struct timespec* ts)
+{
+  ts->tv_sec = GetTTUtime(n);
+  ts->tv_nsec = (long)(((double)GetTTCtime(n)) / 0.127216);
+
+  return ;
+}
+
+void RawFTSWFormat_latest::GetPCTimeVal(int n, struct timeval* tv)
+{
+  tv->tv_sec = (unsigned int)(m_buffer[ GetBufferPos(n) +  POS_TVSEC_FROM_PC ]);
+  tv->tv_usec = (unsigned int)(m_buffer[ GetBufferPos(n) +  POS_TVUSEC_FROM_PC ]);
+  return ;
+}
+
+
+unsigned long long int RawFTSWFormat_latest::GetTTTimeNs(int n)
+{
+  return (unsigned long long int)GetTTUtime(n) * 1e9 + (long)((double)GetTTCtime(n) / 0.127216);
+}
+
+int RawFTSWFormat_latest::GetNwordsHeader(int n)
+{
+  return  m_buffer[ GetBufferPos(n) +  POS_HDR_NWORDS ];
+}
+
+
+unsigned int RawFTSWFormat_latest::GetFTSWNodeID(int n)
+{
+  return (unsigned int)(m_buffer[ GetBufferPos(n) +  POS_NODE_ID ]);
+}
+
+unsigned int RawFTSWFormat_latest::GetEveNo(int n)
+{
+  return m_buffer[  GetBufferPos(n) + POS_EVE_NO_1 ];
+}
+
+unsigned int RawFTSWFormat_latest::GetMagicTrailer(int n)
+{
+  return m_buffer[  GetBufferPos(n) + POS_MAGIC_1 ];
+}
+
+int RawFTSWFormat_latest::GetIsHER(int n)
+{
+  int* buffer = GetBuffer(n);
+  int ret = (buffer[ POS_INJECTION_INFO ] & INJ_HER_LER_MASK) >> INJ_HER_LER_SHIFT;
+  return ret; // 1 -> HER, 0 -> LER
+}
+
+
+unsigned int RawFTSWFormat_latest::GetTimeSinceLastInjection(int n)
+{
+  unsigned int* buffer = (unsigned int*) GetBuffer(n);
+  unsigned int ret = (buffer[ POS_INJECTION_INFO ] & INJ_TIME_MASK) >> INJ_TIME_SHIFT;
+  return ret;
+}
+
+unsigned int RawFTSWFormat_latest::GetTimeSincePrevTrigger(int n)
+{
+  unsigned int* buffer = (unsigned int*) GetBuffer(n);
+  unsigned int ret = buffer[ POS_TIME_SINCE_PREV_TRG ];
+  return ret;
+}
+
+unsigned int RawFTSWFormat_latest::GetBunchNumber(int n)
+{
+  unsigned int* buffer = (unsigned int*) GetBuffer(n);
+  unsigned int ret = (buffer[ POS_BUNCH_NUM ] & INJ_BUNCH_MASK) >> INJ_BUNCH_SHIFT;
+  return ret;
+}
+
+unsigned int RawFTSWFormat_latest::GetFrameCount(int n)
+{
+  unsigned int* buffer = (unsigned int*) GetBuffer(n);
+  unsigned int ret = buffer[ POS_FRAME_COUNT ];
+  return ret;
+}
+
+
+void RawFTSWFormat_latest::CheckData(int n,
+                                     unsigned int prev_evenum, unsigned int* cur_evenum,
+                                     unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+{
+  int err_flag = 0;
+  char err_buf[500];
+  *cur_evenum = GetEveNo(n);
+  *cur_exprunsubrun_no = GetExpRunSubrun(n);
+
+
+#ifndef NO_DATA_CHECK
+  if (prev_exprunsubrun_no == *cur_exprunsubrun_no) {
+    if ((unsigned int)(prev_evenum + 1) != *cur_evenum) {
+      sprintf(err_buf, "[FATAL] ERROR_EVENT : Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n %s %s %d\n",
+              n, prev_evenum, *cur_evenum, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf);
+      err_flag = 1;
+    }
+  }
+#endif
+
+  if (GetBlockNwords(n) != SIZE_FTSW_PACKET) {
+    sprintf(err_buf, "[FATAL] ERROR_EVENT : invalid FTSW packet length : block %d nwords %d must be %d : Exiting...\n %s %s %d\n",
+            n, GetBlockNwords(n), SIZE_FTSW_PACKET, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf);
+    err_flag = 1;
+  }
+
+  if (GetMagicTrailer(n) != FTSW_MAGIC_TRAILER) {
+    sprintf(err_buf, "[FATAL] ERROR_EVENT : invalid magic word : block %d magic word 0x%x must be 0x%x : Exiting...\n %s %s %d\n",
+            n, GetMagicTrailer(n), FTSW_MAGIC_TRAILER, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    err_flag = 1;
+  }
+
+  if (err_flag == 1) {
+    printf("[DEBUG] ========== dump a data block : block # %d==========\n", n);
+    printf("[DEBUG] ");
+    for (int k = 0 ; k < GetBlockNwords(n); k++) {
+      printf("0x%.8x ", (GetBuffer(n))[k]);
+      if (k % 10 == 9) printf("\n[DEBUG] ");
+    }
+    fflush(stderr);
+    B2FATAL(err_buf);
+  }
+
+  return;
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawFTSWFormat_v1.cc b/ROPCApplications/rawdata/dataobjects/src/RawFTSWFormat_v1.cc
new file mode 100644
index 0000000000000000000000000000000000000000..14e1f29a849f748559907b99810c1b3db5fa3dc4
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawFTSWFormat_v1.cc
@@ -0,0 +1,139 @@
+//+
+// File : RawFTSWFormat_v1.cc
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+#include <rawdata/dataobjects/RawFTSWFormat_v1.h>
+
+
+using namespace std;
+using namespace Belle2;
+
+RawFTSWFormat_v1::RawFTSWFormat_v1()
+{
+}
+
+RawFTSWFormat_v1::~RawFTSWFormat_v1()
+{
+}
+
+
+int RawFTSWFormat_v1::Get15bitTLUTag(int n)
+{
+  return (int)((unsigned int)(m_buffer[ GetBufferPos(n) +  POS_FTSW_4 ]) & 0x00007FFF);
+}
+
+unsigned int RawFTSWFormat_v1::GetTTCtimeTRGType(int n)
+{
+  return (unsigned int)(m_buffer[ GetBufferPos(n) +  POS_TT_CTIME_TRGTYPE ]);
+}
+
+
+
+int RawFTSWFormat_v1::GetTTCtime(int n)
+{
+  return (int)((GetTTCtimeTRGType(n) & TTCTIME_MASK) >> TTCTIME_SHIFT);
+}
+
+int RawFTSWFormat_v1::GetTRGType(int n)
+{
+  return (int)(GetTTCtimeTRGType(n) & TRGTYPE_MASK);
+}
+
+unsigned int RawFTSWFormat_v1::GetTTUtime(int n)
+{
+  return (unsigned int)(m_buffer[ GetBufferPos(n) +  POS_TT_UTIME ]);
+}
+
+void RawFTSWFormat_v1::GetTTTimeVal(int n, struct timeval* tv)
+{
+  tv->tv_sec = GetTTUtime(n);
+  tv->tv_usec = (int)(((double)GetTTCtime(n)) / 127.216);
+
+  return ;
+}
+
+void RawFTSWFormat_v1::GetTTTimeSpec(int n, struct timespec* ts)
+{
+  ts->tv_sec = GetTTUtime(n);
+  ts->tv_nsec = (long)(((double)GetTTCtime(n)) / 0.127216);
+
+  return ;
+}
+
+unsigned long long int RawFTSWFormat_v1::GetTTTimeNs(int n)
+{
+  return (unsigned long long int)GetTTUtime(n) * 1e9 + (long)((double)GetTTCtime(n) / 0.127216);
+}
+
+int RawFTSWFormat_v1::GetNwordsHeader(int n)
+{
+  return  m_buffer[ GetBufferPos(n) +  POS_HDR_NWORDS ];
+}
+
+
+unsigned int RawFTSWFormat_v1::GetFTSWNodeID(int n)
+{
+  return (unsigned int)(m_buffer[ GetBufferPos(n) +  POS_NODE_ID ]);
+}
+
+unsigned int RawFTSWFormat_v1::GetEveNo(int n)
+{
+  return m_buffer[  GetBufferPos(n) + POS_EVE_NO ];
+}
+
+unsigned int RawFTSWFormat_v1::GetMagicTrailer(int n)
+{
+  return m_buffer[  GetBufferPos(n) + POS_MAGIC_1 ];
+}
+
+void RawFTSWFormat_v1::CheckData(int n,
+                                 unsigned int prev_evenum, unsigned int* cur_evenum,
+                                 unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+{
+  int err_flag = 0;
+  char err_buf[500];
+  *cur_evenum = GetEveNo(n);
+  *cur_exprunsubrun_no = GetExpRunSubrun(n);
+
+
+#ifndef NO_DATA_CHECK
+  if (prev_exprunsubrun_no == *cur_exprunsubrun_no) {
+    if ((unsigned int)(prev_evenum + 1) != *cur_evenum) {
+      sprintf(err_buf, "[FATAL] ERROR_EVENT : Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n %s %s %d\n",
+              n, prev_evenum, *cur_evenum, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf);
+      err_flag = 1;
+    }
+  }
+#endif
+
+  if (GetBlockNwords(n) != SIZE_FTSW_PACKET) {
+    sprintf(err_buf, "[FATAL] ERROR_EVENT : invalid FTSW packet length : block %d nwords %d must be %d : Exiting...\n %s %s %d\n",
+            n, GetBlockNwords(n), SIZE_FTSW_PACKET, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf);
+    err_flag = 1;
+  }
+
+  if (GetMagicTrailer(n) != FTSW_MAGIC_TRAILER) {
+    sprintf(err_buf, "[FATAL] ERROR_EVENT : invalid magic word : block %d magic word 0x%x must be 0x%x : Exiting...\n %s %s %d\n",
+            n, GetMagicTrailer(n), FTSW_MAGIC_TRAILER, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf);
+    err_flag = 1;
+  }
+
+  if (err_flag == 1) {
+    printf("[DEBUG] ========== dump a data block : block # %d==========\n", n);
+    printf("[DEBUG] ");
+    for (int k = 0 ; k < GetBlockNwords(n); k++) {
+      printf("0x%.8x ", (GetBuffer(n))[k]);
+      if (k % 10 == 9) printf("\n[DEBUG] ");
+    }
+    fflush(stderr);
+    B2FATAL(err_buf);
+  }
+
+  return;
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawFTSWFormat_v2.cc b/ROPCApplications/rawdata/dataobjects/src/RawFTSWFormat_v2.cc
new file mode 100644
index 0000000000000000000000000000000000000000..90108611f3eab0e8df057102eafc6dd0f5dff573
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawFTSWFormat_v2.cc
@@ -0,0 +1,172 @@
+//+
+// File : RawFTSWFormat_v2.cc
+// Description : Module to handle raw data from COPPER.
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 18 - Feb - 2019
+//-
+#include <rawdata/dataobjects/RawFTSWFormat_v2.h>
+
+
+using namespace std;
+using namespace Belle2;
+
+RawFTSWFormat_v2::RawFTSWFormat_v2()
+{
+}
+
+RawFTSWFormat_v2::~RawFTSWFormat_v2()
+{
+}
+
+
+unsigned int RawFTSWFormat_v2::GetTTCtimeTRGType(int n)
+{
+  return (unsigned int)(m_buffer[ GetBufferPos(n) +  POS_TT_CTIME_TRGTYPE ]);
+}
+
+
+
+int RawFTSWFormat_v2::GetTTCtime(int n)
+{
+  return (int)((GetTTCtimeTRGType(n) & TTCTIME_MASK) >> TTCTIME_SHIFT);
+}
+
+int RawFTSWFormat_v2::GetTRGType(int n)
+{
+  return (int)(GetTTCtimeTRGType(n) & TRGTYPE_MASK);
+}
+
+unsigned int RawFTSWFormat_v2::GetTTUtime(int n)
+{
+  return (unsigned int)(m_buffer[ GetBufferPos(n) +  POS_TT_UTIME ]);
+}
+
+void RawFTSWFormat_v2::GetTTTimeVal(int n, struct timeval* tv)
+{
+  tv->tv_sec = GetTTUtime(n);
+  tv->tv_usec = (int)(((double)GetTTCtime(n)) / 127.216);
+
+  return ;
+}
+
+void RawFTSWFormat_v2::GetTTTimeSpec(int n, struct timespec* ts)
+{
+  ts->tv_sec = GetTTUtime(n);
+  ts->tv_nsec = (long)(((double)GetTTCtime(n)) / 0.127216);
+
+  return ;
+}
+
+unsigned long long int RawFTSWFormat_v2::GetTTTimeNs(int n)
+{
+  return (unsigned long long int)GetTTUtime(n) * 1e9 + (long)((double)GetTTCtime(n) / 0.127216);
+}
+
+int RawFTSWFormat_v2::GetNwordsHeader(int n)
+{
+  return  m_buffer[ GetBufferPos(n) +  POS_HDR_NWORDS ];
+}
+
+
+unsigned int RawFTSWFormat_v2::GetFTSWNodeID(int n)
+{
+  return (unsigned int)(m_buffer[ GetBufferPos(n) +  POS_NODE_ID ]);
+}
+
+unsigned int RawFTSWFormat_v2::GetEveNo(int n)
+{
+  return m_buffer[  GetBufferPos(n) + POS_EVE_NO_1 ];
+}
+
+unsigned int RawFTSWFormat_v2::GetMagicTrailer(int n)
+{
+  return m_buffer[  GetBufferPos(n) + POS_MAGIC_1 ];
+}
+
+int RawFTSWFormat_v2::GetIsHER(int n)
+{
+  int* buffer = GetBuffer(n);
+  int ret = (buffer[ POS_INJECTION_INFO ] & INJ_HER_LER_MASK) >> INJ_HER_LER_SHIFT;
+  return ret; // 1 -> HER, 0 -> LER
+}
+
+
+unsigned int RawFTSWFormat_v2::GetTimeSinceLastInjection(int n)
+{
+  unsigned int* buffer = (unsigned int*) GetBuffer(n);
+  unsigned int ret = (buffer[ POS_INJECTION_INFO ] & INJ_TIME_MASK) >> INJ_TIME_SHIFT;
+  return ret;
+}
+
+unsigned int RawFTSWFormat_v2::GetTimeSincePrevTrigger(int n)
+{
+  unsigned int* buffer = (unsigned int*) GetBuffer(n);
+  unsigned int ret = buffer[ POS_TIME_SINCE_PREV_TRG ];
+  return ret;
+}
+
+unsigned int RawFTSWFormat_v2::GetBunchNumber(int n)
+{
+  unsigned int* buffer = (unsigned int*) GetBuffer(n);
+  unsigned int ret = (buffer[ POS_BUNCH_NUM ] & INJ_BUNCH_MASK) >> INJ_BUNCH_SHIFT;
+  return ret;
+}
+
+unsigned int RawFTSWFormat_v2::GetFrameCount(int n)
+{
+  unsigned int* buffer = (unsigned int*) GetBuffer(n);
+  unsigned int ret = buffer[ POS_FRAME_COUNT ];
+  return ret;
+}
+
+
+void RawFTSWFormat_v2::CheckData(int n,
+                                 unsigned int prev_evenum, unsigned int* cur_evenum,
+                                 unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
+{
+  int err_flag = 0;
+  char err_buf[500];
+  *cur_evenum = GetEveNo(n);
+  *cur_exprunsubrun_no = GetExpRunSubrun(n);
+
+
+#ifndef NO_DATA_CHECK
+  if (prev_exprunsubrun_no == *cur_exprunsubrun_no) {
+    if ((unsigned int)(prev_evenum + 1) != *cur_evenum) {
+      sprintf(err_buf, "[FATAL] ERROR_EVENT : Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n %s %s %d\n",
+              n, prev_evenum, *cur_evenum, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      printf("%s", err_buf);
+      err_flag = 1;
+    }
+  }
+#endif
+
+  if (GetBlockNwords(n) != SIZE_FTSW_PACKET) {
+    sprintf(err_buf, "[FATAL] ERROR_EVENT : invalid FTSW packet length : block %d nwords %d must be %d : Exiting...\n %s %s %d\n",
+            n, GetBlockNwords(n), SIZE_FTSW_PACKET, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf);
+    err_flag = 1;
+  }
+
+  if (GetMagicTrailer(n) != FTSW_MAGIC_TRAILER) {
+    sprintf(err_buf, "[FATAL] ERROR_EVENT : invalid magic word : block %d magic word 0x%x must be 0x%x : Exiting...\n %s %s %d\n",
+            n, GetMagicTrailer(n), FTSW_MAGIC_TRAILER, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf);
+    err_flag = 1;
+  }
+
+  if (err_flag == 1) {
+    printf("[DEBUG] ========== dump a data block : block # %d==========\n", n);
+    printf("[DEBUG] ");
+    for (int k = 0 ; k < GetBlockNwords(n); k++) {
+      printf("0x%.8x ", (GetBuffer(n))[k]);
+      if (k % 10 == 9) printf("\n[DEBUG] ");
+    }
+    fflush(stderr);
+    string err_str = err_buf; throw (err_str);
+
+  }
+
+  return;
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawHeader_latest.cc b/ROPCApplications/rawdata/dataobjects/src/RawHeader_latest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a96d510b369148eb88b88c68782784d73c584cf4
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawHeader_latest.cc
@@ -0,0 +1,134 @@
+//+
+// File : RawHeader_latest.cc
+// Description : Module to handle RawHeader_latest attached to raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawHeader_latest.h>
+
+
+using namespace Belle2;
+
+//ClassImp(RawHeader_latest);
+
+RawHeader_latest::RawHeader_latest()
+{
+  m_buffer = NULL;
+  //  initialize();
+  //  cout << "RawHeader_latest NULL constructor" << endl;
+}
+
+RawHeader_latest::RawHeader_latest(int* buffer)
+{
+  m_buffer = buffer;
+}
+
+RawHeader_latest::~RawHeader_latest()
+{
+}
+
+
+// int RawHeader_latest::AddNodeInfo(int node_id)
+// {
+//   CheckSetBuffer();
+//   // When the number of total nodes exceeds NUM_MAX_NODES
+//   if (GetNumNodes() >= NUM_MAX_NODES) {
+//     m_buffer[ POS_NUM_NODES ]++;
+//     return -1;
+//   }
+
+//   m_buffer[ POS_NODES_1 + m_buffer[ POS_NUM_NODES ] ] = node_id;
+//   m_buffer[ POS_NUM_NODES ]++;
+//   return 0;
+// }
+
+// int RawHeader_latest::GetNodeInfo(int node_no, int* node_id)
+// {
+//   CheckGetBuffer();
+//   if (node_no >= GetNumNodes()) {
+//     return -1;
+//   }
+//   *node_id = m_buffer[ POS_NODES_1 + node_no ];
+
+//   return 0;
+// }
+
+
+
+
+void RawHeader_latest::CheckHeader(int* buf)
+{
+
+  // # of words
+  if (buf[ POS_NWORDS ] > 2.5e7 || buf[ POS_NWORDS ] < RAWHEADER_NWORDS) {
+    char err_buf[500];
+    sprintf(err_buf, "data size error %d words. Exiting... : %s %s %d\n",
+            buf[ POS_NWORDS ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  // # of words in this block
+  if ((buf[ POS_VERSION_HDRNWORDS ] & HDR_NWORDS_MASK) != RAWHEADER_NWORDS) {
+    char err_buf[500];
+    sprintf(err_buf, "Invalid header size %d words should be %d. Exiting... : %s %s %d\n",
+            buf[ buf[ POS_VERSION_HDRNWORDS ] & HDR_NWORDS_MASK ],
+            RAWHEADER_NWORDS, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  //  exp. run #
+
+  //  utime( 2010 1/1 - 2050 1/1 )
+  if ((unsigned int)(buf[ POS_TTUTIME ]) < (unsigned int)0x4b3cbc70 ||
+      (unsigned int)0x9679f770 < (unsigned int)(buf[ POS_TTUTIME ])) {
+    char err_buf[500];
+    sprintf(err_buf, "Invalid utime %d . Exiting...: %s %s %d\n",
+            buf[ POS_TTUTIME ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  // truncation mask
+
+  // offset
+  if (buf[ POS_OFFSET_1ST_FINESSE ] < RAWHEADER_NWORDS) {
+    char err_buf[500];
+    sprintf(err_buf, "Invalid data offset for 1st finesse buffer(%d). Exiting...: %s %s %d\n",
+            buf[ POS_OFFSET_1ST_FINESSE ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  if (buf[ POS_OFFSET_2ND_FINESSE ] < buf[ POS_OFFSET_1ST_FINESSE ]) {
+    char err_buf[500];
+    sprintf(err_buf, "Invalid data offset for 2nd finesse buffer(%d). Exiting...: %s %s %d\n",
+            buf[ POS_OFFSET_2ND_FINESSE ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  if (buf[ POS_OFFSET_3RD_FINESSE ] < buf[ POS_OFFSET_2ND_FINESSE ]) {
+    char err_buf[500];
+    sprintf(err_buf, "Invalid data offset for 3rd finesse buffer(%d). Exiting...: %s %s %d\n",
+            buf[ POS_OFFSET_3RD_FINESSE ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  if (buf[ POS_OFFSET_4TH_FINESSE ] < buf[ POS_OFFSET_3RD_FINESSE ] ||
+      buf[ POS_OFFSET_4TH_FINESSE ] > buf[ POS_NWORDS ]) {
+    char err_buf[500];
+    sprintf(err_buf, "Invalid data offset for 4th finesse buffer(%d). Exiting...: %s %s %d\n",
+            buf[ POS_OFFSET_4TH_FINESSE ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  return;
+
+
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawHeader_v0.cc b/ROPCApplications/rawdata/dataobjects/src/RawHeader_v0.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3e44ad9bb7c838a90abf4816f588c41f8ffeeb08
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawHeader_v0.cc
@@ -0,0 +1,57 @@
+//+
+// File : RawHeader_v0.cc
+// Description : Module to handle RawHeader_v0 attached to raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawHeader_v0.h>
+
+
+
+using namespace Belle2;
+
+//ClassImp(RawHeader_v0);
+
+RawHeader_v0::RawHeader_v0()
+{
+  m_buffer = NULL;
+  //  initialize();
+  //  cout << "RawHeader_v0 NULL constructor" << endl;
+}
+
+RawHeader_v0::RawHeader_v0(int* buffer)
+{
+  m_buffer = buffer;
+}
+
+RawHeader_v0::~RawHeader_v0()
+{
+}
+
+
+int RawHeader_v0::AddNodeInfo(int node_id)
+{
+  CheckSetBuffer();
+  // When the number of total nodes exceeds NUM_MAX_NODES
+  if (GetNumNodes() >= NUM_MAX_NODES) {
+    m_buffer[ POS_NUM_NODES ]++;
+    return -1;
+  }
+
+  m_buffer[ POS_NODES_1 + m_buffer[ POS_NUM_NODES ] ] = node_id;
+  m_buffer[ POS_NUM_NODES ]++;
+  return 0;
+}
+
+int RawHeader_v0::GetNodeInfo(int node_no, int* node_id)
+{
+  CheckGetBuffer();
+  if (node_no >= GetNumNodes()) {
+    return -1;
+  }
+  *node_id = m_buffer[ POS_NODES_1 + node_no ];
+
+  return 0;
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawHeader_v1.cc b/ROPCApplications/rawdata/dataobjects/src/RawHeader_v1.cc
new file mode 100644
index 0000000000000000000000000000000000000000..517a50bbbc78fb065b09b2648f5d094c8068e571
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawHeader_v1.cc
@@ -0,0 +1,136 @@
+//+
+// File : RawHeader_v1.cc
+// Description : Module to handle RawHeader_v1 attached to raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawHeader_v1.h>
+
+
+
+using namespace Belle2;
+
+//ClassImp(RawHeader_v1);
+
+RawHeader_v1::RawHeader_v1()
+{
+  m_buffer = NULL;
+  //  initialize();
+  //  cout << "RawHeader_v1 NULL constructor" << endl;
+}
+
+RawHeader_v1::RawHeader_v1(int* buffer)
+{
+  m_buffer = buffer;
+}
+
+RawHeader_v1::~RawHeader_v1()
+{
+}
+
+
+// int RawHeader_v1::AddNodeInfo(int node_id)
+// {
+//   CheckSetBuffer();
+//   // When the number of total nodes exceeds NUM_MAX_NODES
+//   if (GetNumNodes() >= NUM_MAX_NODES) {
+//     m_buffer[ POS_NUM_NODES ]++;
+//     return -1;
+//   }
+
+//   m_buffer[ POS_NODES_1 + m_buffer[ POS_NUM_NODES ] ] = node_id;
+//   m_buffer[ POS_NUM_NODES ]++;
+//   return 0;
+// }
+
+// int RawHeader_v1::GetNodeInfo(int node_no, int* node_id)
+// {
+//   CheckGetBuffer();
+//   if (node_no >= GetNumNodes()) {
+//     return -1;
+//   }
+//   *node_id = m_buffer[ POS_NODES_1 + node_no ];
+
+//   return 0;
+// }
+
+
+
+
+void RawHeader_v1::CheckHeader(int* buf)
+{
+
+  // # of words
+  if (buf[ POS_NWORDS ] > 2.5e7 ||
+      buf[ POS_NWORDS ] < RAWHEADER_NWORDS) {
+    char err_buf[500];
+    sprintf(err_buf, "data size error %d words. Exiting... : %s %s %d\n",
+            buf[ POS_NWORDS ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  // # of words in this block
+  if ((buf[ POS_VERSION_HDRNWORDS ] & HDR_NWORDS_MASK) != RAWHEADER_NWORDS) {
+    char err_buf[500];
+    sprintf(err_buf, "Invalid header size %d words should be %d. Exiting... : %s %s %d\n",
+            buf[ buf[ POS_VERSION_HDRNWORDS ] & HDR_NWORDS_MASK ],
+            RAWHEADER_NWORDS, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  //  exp. run #
+
+  //  utime( 2010 1/1 - 2050 1/1 )
+  if ((unsigned int)(buf[ POS_TTUTIME ]) < (unsigned int)0x4b3cbc70 ||
+      (unsigned int)0x9679f770 < (unsigned int)(buf[ POS_TTUTIME ])) {
+    char err_buf[500];
+    sprintf(err_buf, "Invalid utime %d . Exiting...: %s %s %d\n",
+            buf[ POS_TTUTIME ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  // truncation mask
+
+  // offset
+  if (buf[ POS_OFFSET_1ST_FINESSE ] < RAWHEADER_NWORDS) {
+    char err_buf[500];
+    sprintf(err_buf, "Invalid data offset for 1st finesse buffer(%d). Exiting...: %s %s %d\n",
+            buf[ POS_OFFSET_1ST_FINESSE ], __FILE__, __PRETTY_FUNCTION__, __LINE__); fflush(stdout);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  if (buf[ POS_OFFSET_2ND_FINESSE ] < buf[ POS_OFFSET_1ST_FINESSE ]) {
+    char err_buf[500];
+    sprintf(err_buf, "Invalid data offset for 2nd finesse buffer(%d). Exiting...: %s %s %d\n",
+            buf[ POS_OFFSET_2ND_FINESSE ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  if (buf[ POS_OFFSET_3RD_FINESSE ] < buf[ POS_OFFSET_2ND_FINESSE ]) {
+    char err_buf[500];
+    sprintf(err_buf, "Invalid data offset for 3rd finesse buffer(%d). Exiting...: %s %s %d\n",
+            buf[ POS_OFFSET_3RD_FINESSE ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  if (buf[ POS_OFFSET_4TH_FINESSE ] < buf[ POS_OFFSET_3RD_FINESSE ] ||
+      buf[ POS_OFFSET_4TH_FINESSE ] > buf[ POS_NWORDS ]) {
+    char err_buf[500];
+    sprintf(err_buf, "Invalid data offset for 4th finesse buffer(%d). Exiting...: %s %s %d\n",
+            buf[ POS_OFFSET_4TH_FINESSE ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    B2FATAL(err_buf);
+  }
+
+  return;
+
+
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawKLM.cc b/ROPCApplications/rawdata/dataobjects/src/RawKLM.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b866c31eff1ad29c923d13d1e4713ab439b59d74
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawKLM.cc
@@ -0,0 +1,20 @@
+//+
+// File : RawCOPPER.cc
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawKLM.h>
+
+using namespace std;
+using namespace Belle2;
+
+RawKLM::RawKLM()
+{
+}
+
+RawKLM::~RawKLM()
+{
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawPXD.cc b/ROPCApplications/rawdata/dataobjects/src/RawPXD.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1571db423ee76a64bdb1997151f33000a1896dc4
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawPXD.cc
@@ -0,0 +1,96 @@
+//+
+// File : RawPXD.cc
+// Description : RawPXD Data format
+//
+// Author : Bjoern Spruck / Klemens Lautenbach
+// Date : 13 - Aug - 2013
+//-
+
+#include "rawdata/dataobjects/RawPXD.h"
+#include "framework/logging/Logger.h"
+#include <framework/utilities/HTML.h>
+
+using namespace std;
+using namespace Belle2;
+
+RawPXD::RawPXD() : m_nwords(0), m_buffer(NULL)
+{
+}
+
+RawPXD::RawPXD(int* buffer, int length_in_Bytes)
+  : m_nwords(0), m_buffer(NULL)
+{
+  m_nwords = (length_in_Bytes + 3) / 4;
+  m_buffer = new int[m_nwords];
+  memcpy(m_buffer, buffer, m_nwords * sizeof(int));
+}
+
+unsigned int RawPXD::endian_swap(unsigned int x)
+{
+  x = (x >> 24) |
+      ((x << 8) & 0x00FF0000) |
+      ((x >> 8) & 0x0000FF00) |
+      (x << 24);
+  return x;
+}
+
+RawPXD::RawPXD(const std::vector <unsigned int>& header, const std::vector <std::vector <unsigned char>>& payload)
+  : m_nwords(0), m_buffer(NULL)
+{
+  // This function is only used by the PXDPacker in simulations. Does not make sense for other cases
+  // Now create header from payload , this can be done with less loops, but speed is not the issue here
+  int nr_frames = header.size();
+  int payload_size = 0; // in 32 bit words
+  for (auto& it : header) {
+    payload_size += (it + 3) / 4; // in 32 bit word, rounded up
+  }
+
+  m_nwords = 2 + nr_frames + payload_size; // 321 bit words
+
+  m_buffer = new int[m_nwords];
+
+  B2DEBUG(20, "RawPXD Frames " << header.size() << " Data " << payload_size << " (32 bitword)");
+
+  // now we know the actual payload length
+  int offset = 0;
+  m_buffer[offset++] = 0xBEBAFECA ; // 0xCAFEBABEu;
+  m_buffer[offset++] = endian_swap(nr_frames);
+  // and now append the frame length table
+  for (auto& it : payload) {
+    m_buffer[offset++] = endian_swap(it.size()); // in chars, rounded up to 32 bit boundary
+  }
+  // and now append the actual paylaod data
+  unsigned char* data = (unsigned char*) &m_buffer[offset];
+  for (auto& it : payload) {
+    memcpy(data, it.data(), it.size());
+    data += (it.size() + 3) & 0xFFFFFFFC; // in chars, rounded up to 32 bit boundary
+  }
+  // done
+}
+
+RawPXD::~RawPXD()
+{
+  if (m_buffer != NULL) delete[] m_buffer;
+}
+
+int RawPXD::size() const
+{
+  return m_nwords;
+}
+
+int* RawPXD::data(void)
+{
+  int* ptr = &m_buffer[0];
+  return ptr;
+}
+
+std::string RawPXD::getInfoHTML() const
+{
+  std::string s;
+  if (m_nwords >= 2)
+    s += "Frames: " + std::to_string(endian_swap(m_buffer[1])) + ", ";
+
+  s += "Size (32bit words): " + std::to_string(m_nwords) + "<br /><br />";
+  s += HTML::getHexDump(m_buffer, m_nwords);
+  return s;
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawSVD.cc b/ROPCApplications/rawdata/dataobjects/src/RawSVD.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9954e8b5f6cc609586c5504691aa3bcd4fa0b75e
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawSVD.cc
@@ -0,0 +1,20 @@
+//+
+// File : RawCOPPER.cc
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawSVD.h>
+
+using namespace std;
+using namespace Belle2;
+
+RawSVD::RawSVD()
+{
+}
+
+RawSVD::~RawSVD()
+{
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawTLU.cc b/ROPCApplications/rawdata/dataobjects/src/RawTLU.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a5bf184a86f33518e66fba92be7a3eea5dad716c
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawTLU.cc
@@ -0,0 +1,22 @@
+//+
+// File : RawTLU.cc
+// Description : Module to handle raw data from TLU(for the telescope beam test)
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Jan - 2014
+//-
+
+#include <rawdata/dataobjects/RawTLU.h>
+using namespace std;
+using namespace Belle2;
+
+RawTLU::RawTLU()
+{
+  m_access = new RawTLUFormat;
+}
+
+RawTLU::~RawTLU()
+{
+  if (m_access != NULL) delete m_access;
+  m_access = NULL;
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawTLUFormat.cc b/ROPCApplications/rawdata/dataobjects/src/RawTLUFormat.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d3f5bd961e01c4c49c4f1d48698a95060cee4903
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawTLUFormat.cc
@@ -0,0 +1,108 @@
+//+
+// File : RawTLUFormat.cc
+// Description : Module to handle raw data from TLU(for the telescope beam test)
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Jan - 2014
+//-
+
+#include <rawdata/dataobjects/RawTLUFormat.h>
+using namespace std;
+using namespace Belle2;
+
+RawTLUFormat::RawTLUFormat()
+{
+}
+
+RawTLUFormat::~RawTLUFormat()
+{
+}
+
+// int RawTLUFormat::GetNwords(int n)
+// {
+//   return  m_buffer[ GetBufferPos(n) +  POS_NWORDS ];
+// }
+
+int RawTLUFormat::GetNwordsHeader(int n)
+{
+  return  m_buffer[ GetBufferPos(n) +  POS_HDR_NWORDS ];
+}
+
+
+unsigned int RawTLUFormat::GetNodeID(int n)
+{
+  return (unsigned int)(m_buffer[ GetBufferPos(n) +  POS_NODE_ID ]);
+}
+
+unsigned int RawTLUFormat::GetEveNo(int n)
+{
+  return m_buffer[  GetBufferPos(n) + POS_EVE_NO ];
+}
+
+
+int RawTLUFormat::GetRunNo(int n)
+{
+  return m_buffer[  GetBufferPos(n) + POS_RUN_NO ];
+}
+
+
+unsigned int RawTLUFormat::GetMagicTrailer(int n)
+{
+  return m_buffer[  GetBufferPos(n) + POS_MAGIC_1 ];
+}
+
+unsigned int RawTLUFormat::GetTLUEventTag(int n)
+{
+  return m_buffer[  GetBufferPos(n) + POS_TLU_EVENTTAG ];
+}
+
+
+void RawTLUFormat::CheckData(int n,
+                             unsigned int prev_evenum, unsigned int* cur_evenum)
+{
+  int err_flag = 0;
+  char err_buf[500];
+  *cur_evenum = GetEveNo(n);
+
+#ifndef NO_DATA_CHECK
+  if (prev_evenum != 0xFFFFFFFF && *cur_evenum != 0) {
+    if ((unsigned int)(prev_evenum + 1) != *cur_evenum) {
+      sprintf(err_buf, "Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n %s %s %d\n",
+              n, prev_evenum, *cur_evenum, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+      err_flag = 1;
+    }
+  }
+#endif
+
+  if (GetEveNo(n) != GetTLUEventTag(n)) {
+    sprintf(err_buf, "invalid TLU event tag : blodk %d header eve # %u TLU tag %u. Exiting...\n %s %s %d\n",
+            n, GetEveNo(n), GetTLUEventTag(n), __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    err_flag = 1;
+  }
+
+
+  if (GetBlockNwords(n) != SIZE_TLU_PACKET) {
+    sprintf(err_buf, "invalid TLU packet length : block %d nwords %d must be %d : Exiting...\n %s %s %d\n",
+            n, GetBlockNwords(n), SIZE_TLU_PACKET, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    err_flag = 1;
+  }
+
+  if (GetMagicTrailer(n) != TLU_MAGIC_TRAILER) {
+    sprintf(err_buf, "invalid magic word : block %d magic word 0x%x must be 0x%x : Exiting...\n %s %s %d\n",
+            n, GetMagicTrailer(n), TLU_MAGIC_TRAILER, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    err_flag = 1;
+  }
+
+  if (err_flag == 1) {
+    printf("[DEBUG] ========== dump a data block : block # %d==========\n", n);
+    printf("[DEBUG] ");
+    for (int k = 0 ; k < GetBlockNwords(n); k++) {
+      printf("0x%.8x ", (GetBuffer(n))[k]);
+      if (k % 10 == 9) printf("\n[DEBUG] ");
+    }
+    fflush(stderr);
+    B2FATAL(err_buf);
+  }
+
+  return;
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawTOP.cc b/ROPCApplications/rawdata/dataobjects/src/RawTOP.cc
new file mode 100644
index 0000000000000000000000000000000000000000..34cdf87b77baa7f36236360627fd84a9985aed1b
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawTOP.cc
@@ -0,0 +1,20 @@
+//+
+// File : RawCOPPER.cc
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawTOP.h>
+
+using namespace std;
+using namespace Belle2;
+
+RawTOP::RawTOP()
+{
+}
+
+RawTOP::~RawTOP()
+{
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawTRG.cc b/ROPCApplications/rawdata/dataobjects/src/RawTRG.cc
new file mode 100644
index 0000000000000000000000000000000000000000..518c6831cef63391a019ce6c489f5035ebbcfc0f
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawTRG.cc
@@ -0,0 +1,22 @@
+//+
+// File : RawTRG.cc
+// Description : Module to handle raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawTRG.h>
+
+using namespace std;
+using namespace Belle2;
+
+RawTRG::RawTRG()
+{
+}
+
+RawTRG::~RawTRG()
+{
+}
+
+
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawTrailer_latest.cc b/ROPCApplications/rawdata/dataobjects/src/RawTrailer_latest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..12ec673cb58ffda8e8f4d936018af8e070611b99
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawTrailer_latest.cc
@@ -0,0 +1,22 @@
+//+
+// File : RawTrailer_latest.cc
+// Description : Module to handle RawTraeiler attached to raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawTrailer_latest.h>
+
+using namespace Belle2;
+
+//ClassImp(RawTrailer_latest);
+
+RawTrailer_latest::RawTrailer_latest()
+{
+  m_buffer = NULL;
+}
+
+RawTrailer_latest::~RawTrailer_latest()
+{
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawTrailer_v0.cc b/ROPCApplications/rawdata/dataobjects/src/RawTrailer_v0.cc
new file mode 100644
index 0000000000000000000000000000000000000000..935528bab3b7606d2b99a3cc316fbcf56be0f128
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawTrailer_v0.cc
@@ -0,0 +1,22 @@
+//+
+// File : RawTrailer_v0.cc
+// Description : Module to handle RawTraeiler attached to raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawTrailer_v0.h>
+
+using namespace Belle2;
+
+//ClassImp(RawTrailer_v0);
+
+RawTrailer_v0::RawTrailer_v0()
+{
+  m_buffer = NULL;
+}
+
+RawTrailer_v0::~RawTrailer_v0()
+{
+}
diff --git a/ROPCApplications/rawdata/dataobjects/src/RawTrailer_v1.cc b/ROPCApplications/rawdata/dataobjects/src/RawTrailer_v1.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ebdecededc23cbf246a0ea40f70bbd1b5f496796
--- /dev/null
+++ b/ROPCApplications/rawdata/dataobjects/src/RawTrailer_v1.cc
@@ -0,0 +1,22 @@
+//+
+// File : RawTrailer_v1.cc
+// Description : Module to handle RawTraeiler attached to raw data from COPPER
+//
+// Author : Satoru Yamada, IPNS, KEK
+// Date : 2 - Aug - 2013
+//-
+
+#include <rawdata/dataobjects/RawTrailer_v1.h>
+
+using namespace Belle2;
+
+//ClassImp(RawTrailer_v1);
+
+RawTrailer_v1::RawTrailer_v1()
+{
+  m_buffer = NULL;
+}
+
+RawTrailer_v1::~RawTrailer_v1()
+{
+}
diff --git a/ROPCApplications/rawdata/include/CRCCalculator.h b/ROPCApplications/rawdata/include/CRCCalculator.h
new file mode 100644
index 0000000000000000000000000000000000000000..f3f6dcd0f86fcc418dce4d366e7bbbe62f2178ca
--- /dev/null
+++ b/ROPCApplications/rawdata/include/CRCCalculator.h
@@ -0,0 +1,30 @@
+#ifndef CRCCALCULATOR_H
+#define CRCCALCULATOR_H
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <cstddef>
+
+
+//namespace Belle2 {
+
+/**
+ * Function to calculate CRC16 (polynomial 0x1021, initial value=0xffff)
+ * Belle2link(HSLB/FEE) trailers.are supposed to contain CRC information.
+ * This function will be used to check them in DAQ system if CPU power allows.
+ */
+unsigned short CalcCRC16LittleEndian(unsigned short crc16, const int buf[], int nwords);
+
+/**
+ * Function to copy data
+ * Just copy data from buf_from to (buf_to + pos_nwords_to)
+ * It also check buffer overflow by using nwords_buf_to
+ */
+void copyData(int* buf_to, int* pos_nwords_to, const int* buf_from,
+              const int copy_nwords, const int nwords_buf_to);
+
+
+
+//}
+#endif
diff --git a/ROPCApplications/rawdata/include/RawCOPPERPackerInfo.h b/ROPCApplications/rawdata/include/RawCOPPERPackerInfo.h
new file mode 100644
index 0000000000000000000000000000000000000000..cf36177023e44d488fcac03e98a53520d68e5c68
--- /dev/null
+++ b/ROPCApplications/rawdata/include/RawCOPPERPackerInfo.h
@@ -0,0 +1,54 @@
+#ifndef RAWCOPPERPACKERINFO_H
+#define RAWCOPPERPACKERINFO_H
+
+namespace Belle2 {
+  /**
+   * struct to contain header information used by RawCOPPERFormat::Packer()
+   */
+  class RawCOPPERPackerInfo {
+  public :
+
+    /// Experiment number (10bit)
+    unsigned int exp_num; /// Experiment number (10bit)
+
+    unsigned int run_subrun_num; /// Run # and subrun # ( 22bit )
+
+    unsigned int eve_num; /// Event Number (32bit)
+
+    unsigned int node_id; /// Node ID (32bit)
+
+    unsigned int
+    tt_ctime; /// 27bit clock ticks at trigger timing distributed by FTSW. For details, see Nakao-san's belle2link user guide
+
+    unsigned int
+    tt_utime; /// 32bit unitx time at trigger timing distributed by FTSW. For details, see Nakao-san's belle2link user guide
+
+    unsigned int
+    b2l_ctime; /// 27bit clock ticks at trigger timing measured by HSLB on COPPER. For details, see Nakao-san's belle2link user guide
+
+    unsigned int
+    hslb_crc16_error_bit; /// 4bit errorflag for CRC errors in data transfer via b2link. ( bit0,1,2,3 -> finesse slot a,b,c,d)
+
+    unsigned int truncation_mask; /// Not defined yet
+
+    unsigned int type_of_data; /// Not defined yet
+
+
+    //! struct of information to fill in a header
+    RawCOPPERPackerInfo()
+    {
+      exp_num = 0;
+      run_subrun_num = 0;
+      eve_num = 0;
+      node_id = 0x00000000; // See RawCOPPERFormat.h
+      tt_ctime = 0;
+      tt_utime = 0;
+      b2l_ctime = 0;
+      hslb_crc16_error_bit = 0x0;
+      truncation_mask = 0;
+      type_of_data = 0;
+    }
+
+  };
+}
+#endif
diff --git a/ROPCApplications/rawdata/include/switch_basf2_standalone.h b/ROPCApplications/rawdata/include/switch_basf2_standalone.h
new file mode 100644
index 0000000000000000000000000000000000000000..46cb91259a8bbabbbe5974a3a4167aab87d20c28
--- /dev/null
+++ b/ROPCApplications/rawdata/include/switch_basf2_standalone.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#define NOBASF2 
+
+#ifndef B2FATAL
+
+#ifdef NOBASF2
+#include <iostream>
+#define B2FATAL(a) {std::cerr << a << std::endl; exit(1);}
+#else
+#include <framework/logging/Logger.h>
+#endif
+
+#endif
+
+// To compile DAQ program on COPPER(SL5.7)
+#ifndef OVERRIDE_CPP17
+#ifndef NOBASF2
+#define OVERRIDE_CPP17 override
+#else
+#define OVERRIDE_CPP17
+#endif
+#endif
diff --git a/ROPCApplications/rawdata/src/CRCCalculator.cc b/ROPCApplications/rawdata/src/CRCCalculator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a59c998280e890efd98695092f5ae6614c8229da
--- /dev/null
+++ b/ROPCApplications/rawdata/src/CRCCalculator.cc
@@ -0,0 +1,92 @@
+#include <rawdata/CRCCalculator.h>
+#include <rawdata/switch_basf2_standalone.h>
+#include <string>
+using namespace std;
+
+
+
+unsigned short CalcCRC16LittleEndian(unsigned short crc16, const int buf[], int nwords)
+{
+
+  if (nwords < 0) {
+    char err_buf[500];
+    sprintf(err_buf, "nwords value(%d) is invalid. Cannot calculate CRC16. Exiting...\n %s %s %d\n",
+            nwords, __FILE__, __PRETTY_FUNCTION__, __LINE__);
+    printf("%s", err_buf); fflush(stdout);
+    string err_str = err_buf;
+    throw (err_str);
+  }
+
+  const unsigned short CRC16Table0x1021[ 256 ] = {
+    0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
+    0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
+    0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
+    0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
+    0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
+    0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
+    0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
+    0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
+
+    0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
+    0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
+    0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
+    0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
+    0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
+    0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
+    0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
+    0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
+
+    0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
+    0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
+    0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
+    0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
+    0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
+    0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
+    0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
+    0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
+
+    0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
+    0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
+    0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
+    0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
+    0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
+    0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
+    0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
+    0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
+  };
+
+  int cnt = 0, nints = 0;
+  //  printf("### %.8x %.4x\n", buf[ 0 ], crc16);
+  while (nwords != 0) {
+
+    unsigned char temp_buf = *((unsigned char*)(buf + nints) + (-(cnt % 4) + 3));
+    crc16 = CRC16Table0x1021[(crc16 >> (16 - CHAR_BIT)) ^ temp_buf ] ^ (crc16 << CHAR_BIT);
+    //    printf("%.2x %.4x\n", temp_buf, crc16);
+    if ((cnt % 4) == 3) {
+      nwords--;
+      nints++;
+      //      printf("### %.8x\n", buf[ nints ] );
+    }
+
+    cnt++;
+  }
+
+
+  return crc16;
+
+}
+
+
+void copyData(int* buf_to, int* pos_nwords_to, const int* buf_from,
+              const int copy_nwords, const int nwords_buf_to)
+{
+
+  if (*pos_nwords_to + copy_nwords > nwords_buf_to) {
+    B2FATAL("Buffer overflow. Exiting...");
+  }
+
+  memcpy(buf_to + *pos_nwords_to, buf_from, copy_nwords * sizeof(int));
+  *pos_nwords_to += copy_nwords;
+  return;
+}
+
diff --git a/Scripts/b2slc.py b/Scripts/b2slc.py
index 0335ea67db300bd32a825db11b2c9249a9c4fb24..ad5b430bb579c0668da0db433a627e1b6c7b6926 100644
--- a/Scripts/b2slc.py
+++ b/Scripts/b2slc.py
@@ -4,11 +4,13 @@ from ctypes import *
 lli = CDLL("libpcie40.so")
 
 parser = argparse.ArgumentParser( description = 'Read/Write registers via slow control' )
-parser.add_argument( '-a' , '--address' , type=lambda x: int(x,0) , required = True )
+parser.add_argument( '-a' , '--address' , type=lambda x: int(x,0) )
 group = parser.add_mutually_exclusive_group(required = True)
 group.add_argument('-r','--read',action='store_true')
 group.add_argument('-w','--write', type = lambda x: int(x,0) )
+group.add_argument('-f','--file')
 parser.add_argument( '-t' , '--type' , choices=['8b','32b'], default='32b', help='Access type (8 bits or 32 bits), 32 bits by default')
+parser.add_argument( '-c' , '--channel' , type=lambda x:int(x,0), default='0', help='Channel number' ) 
 
 args = parser.parse_args()
 result = 0 
@@ -16,16 +18,20 @@ lli.ecs_open( 0 , 2 )
 
 if ( args.read ):
     if args.type == '32b':
-        result = lli.pcie40_readfee32( 0 , args.address )
+        result = lli.pcie40_readfee32( 0 , args.channel , args.address )
     else:
-        result = lli.pcie40_readfee8( 0 , args.address )
-    print 'Read value 0x{:X} (address = 0x{:X})'.format(result,args.address)
+        result = lli.pcie40_readfee8( 0 , args.channel , args.address )
+    if result == -1: print "Error Value = ", result 
+    else: print 'Read value {0} (address = {1})'.format(result,args.address)
+elif (args.file ):
+    result = lli.pcie40_writestream_arich( 0 , args.channel , args.file ) 
+    if result == -1: print "Error" 
 else:
     if args.type == '32b':
-        result = lli.pcie40_writefee32( 0 , args.address , args.write )
+        result = lli.pcie40_writefee32( 0 , args.channel , args.address , args.write )
     else:
-        result = lli.pcie40_writefee8( 0 , args.address , args.write )
-    print 'Wrote value 0x{:X} (address = 0x{:X})'.format(args.write,args.address)
+        result = lli.pcie40_writefee8( 0 , args.channel , args.address , args.write )
+    if result == -1: print "Error Value = ", result  
+    else: print 'Wrote value {0} (address = {1})'.format(args.write,args.address)
 
 lli.ecs_close( 0 , 2 )
-
diff --git a/Scripts/pll_status_small.py b/Scripts/pll_status_small.py
index c9b18d0c2689ee28943334e267c636471c3aa6c7..21036599d0e63d565a07b522ffed8f951eb9619a 100755
--- a/Scripts/pll_status_small.py
+++ b/Scripts/pll_status_small.py
@@ -109,48 +109,63 @@ def fanout_window(fpga, win):
         win.addstr(str(frequency_read) + " Hz", GREEN)
     win.addstr(3,1,'Run number : ' , curses.A_BOLD)
     win.addstr(3,14,'{0:4d}'.format(fpga.runNumber()),GREEN)
-    win.addstr(3,20,'Trigger tag : '  , curses.A_BOLD )
-    win.addstr(3,34, '{0:5d}'.format(fpga.triggerTag()) , GREEN )
-    win.addstr(3,40, 'Clock Up : ' , curses.A_BOLD ) 
+    win.addstr(3,19,'Trigger tag : '  , curses.A_BOLD )
+    win.addstr(3,33, '{0:10d}'.format(fpga.triggerTag()) , GREEN )
+    win.addstr(3,44, 'Clock Up : ' , curses.A_BOLD ) 
     if fpga.clockUp() == 1:
-        win.addstr(3,51, 'OK' , GREEN )
+        win.addstr(3,55, 'OK' , GREEN )
     else:
-        win.addstr(3,51,'NO',RED)
-    win.addstr(3,55, 'TTD Up : ' , curses.A_BOLD ) 
+        win.addstr(3,55,'NO',RED)
+    win.addstr(3,58, 'TTD Up : ' , curses.A_BOLD ) 
     if fpga.ttdUp() == 1:
-        win.addstr(3,64, 'OK' , GREEN )
+        win.addstr(3,67, 'OK' , GREEN )
     else:
-        win.addstr(3,64,'NO',RED)
+        win.addstr(3,67,'NO',RED)
  
-    win.addstr(3,68,'Trigger type : ' , curses.A_BOLD)
-    win.addstr(3,83,'{0:2d}'.format(fpga.triggerType()),GREEN)
+    win.addstr(3,70,'Trigger type : ' , curses.A_BOLD)
+    win.addstr(3,85,'{0:2d}'.format(fpga.triggerType()),GREEN)
     win.addstr(4,1,'Trigger counter : ' , curses.A_BOLD)
     win.addstr(4,19,'{0:5d}'.format(fpga.triggerCounter()),GREEN)
 
-    win.addstr(5,1,'RX ready : ' , curses.A_BOLD)
-    if fpga.rxReady() == 1:
-        win.addstr(5,12, 'OK' , GREEN )
-    else:
-        win.addstr(5,12,'NO',RED)
-    win.addstr(5,16,'TX ready : ' , curses.A_BOLD)
-    if fpga.txReady() == 1:
-        win.addstr(5,27, 'OK' , GREEN )
-    else:
-        win.addstr(5,27,'NO',RED)
-    win.addstr(5,31,'b2link ready : ' , curses.A_BOLD)
-    if fpga.b2linkReady() == 1:
-        win.addstr(5,46, 'OK' , GREEN )
-    else:
-        win.addstr(5,46,'NO',RED)
       
     win.refresh()
 
+
+def link_window(fpga, win):
+    #win.addstr(5,1,'RX ready : ' , curses.A_BOLD)
+    for link in range( 48 ):
+        if fpga.validChannel( link ) == 0:
+            win.addstr(5+link%24+int(link%24/6), 6 + 22 * int( link / 24 ) , 'XX' , CYAN ) 
+        elif fpga.rxReadyIndividual(link) == 1:
+            win.addstr(5+link%24+int(link%24/6), 6 + 22 * int( link / 24 ) , 'OK' , GREEN )
+        else:
+            win.addstr(5+link%24+int(link%24/6), 6 + 22 * int( link / 24 ) , 'NO' , RED)
+    #win.addstr(5,31,'TX ready : ' , curses.A_BOLD)
+    for link in range( 48 ):
+        if fpga.validChannel( link ) == 0:
+            win.addstr(5+link%24+int(link%24/6), 10 + 22 * int( link / 24 ), 'XX' , CYAN ) 
+        elif fpga.txReadyIndividual(link) == 1:
+            win.addstr(5+link%24+int(link%24/6), 10 + 22 * int( link / 24 ), 'OK' , GREEN )
+        else:
+            win.addstr(5+link%24+int(link%24/6), 10 + 22 * int( link / 24 ), 'NO' , RED)
+    #win.addstr(5,62,'b2link ready : ' , curses.A_BOLD)
+    for link in range( 48 ):
+        if fpga.validChannel( link ) == 0:
+            win.addstr(5+link%24+int(link%24/6), 14 + 22 * int( link / 24 ), 'XX' , CYAN ) 
+        elif fpga.b2linkReadyIndividual( link ) == 1:
+            win.addstr(5+link%24+int(link%24/6), 14 + 22 * int( link / 24 ), 'OK' , GREEN )
+        else:
+            win.addstr(5+link%24+int(link%24/6), 14 + 22 * int( link / 24 ), 'NO' , RED)
+      
+    win.refresh()
+
+
 def program_plls(plls, devices, files, win):
 
     #win.move(2,1)
     win.clrtobot()
     win.box()
-    line = 3
+    line = 4
 
     for i in plls.keys():  # programs the 3 PLLs
         (status, part_number) = plls[i].read_part_number()
@@ -288,7 +303,7 @@ def draw_menu(stdscr, dev):
 
     y_max, x_max = stdscr.getmaxyx()
 
-    win1 = stdscr.subwin(y_max/6, x_max-2, 0, 0)
+    win1 = stdscr.subwin(y_max/6, int(0.7*(x_max))-2, 0, 0)
     win1.box()
     win1.addstr(1, 1, "Command window", CYAN | curses.A_BOLD)
     board = EepromAT24C(dev, const.EEPROM_FPGA_BUS, const.EEPROM_U64_ADD)
@@ -297,10 +312,21 @@ def draw_menu(stdscr, dev):
     val = val.replace("\"","")
     val = val.split(",")[0]
     win1.addstr("                           Running on : " + val, CYAN | curses.A_BOLD)
+    #try:
+    vers = fpga.read_version()
+    #except ValueError:
+    #vers = { "design_version": "N/A" , "server" : "N/A" , "links" : "N/A" } 
+    if not "server" in vers.keys(): vers["server"] = 'N/A'
+    if not "links" in vers.keys(): vers["links"] = 'N/A'
+
+    win1.addstr(2 , 1 , "    Firmware version : " + vers[ 'design_version' ] , CYAN | curses.A_BOLD ) 
+    win1.addstr( ", for server : " + vers[ 'server' ] , CYAN | curses.A_BOLD ) 
+    win1.addstr( ", and number of links : " + vers[ 'links' ] , CYAN | curses.A_BOLD ) 
+    
     win1.refresh()
 
     win2 = stdscr.subwin(y_max/6,
-                         x_max - 2,
+                         int(0.7*x_max - 2),
                          y_max/6,
                          0)
     win2.box()
@@ -308,35 +334,50 @@ def draw_menu(stdscr, dev):
     win2.refresh()
 
     win3 = stdscr.subwin(y_max/6,
-                         x_max - 2,
+                         int(0.7*x_max - 2),
                          2*y_max/6,
                          0)
     win3.box()
     win3.addstr(1, 1, "PLL SI54345_2", CYAN | curses.A_BOLD)
     win3.refresh()
 
-    win4 = stdscr.subwin( y_max/6 , x_max-2 , 3*y_max/6, 0 )
+    win4 = stdscr.subwin( y_max/6 , int(0.7*x_max-2) , 3*y_max/6, 0 )
     win4.box()
     win4.addstr(1, 1, "PLL SI54344", CYAN | curses.A_BOLD)
     win4.refresh()
 
     win5 = stdscr.subwin(y_max/6,
-                         x_max -2,
+                         int(0.7*x_max -2),
                          4*y_max/6,
                          0)
     win5.box()
     win5.addstr(1, 1, "Clock FTSW", CYAN | curses.A_BOLD)
     win5.refresh()
 
+    win7 = stdscr.subwin( y_max - 1 , int( 0.3*x_max ) , 0 , int(0.7*x_max) ) 
+    win7.box()
+    win7.addstr( 4 , 6 , "RX" , curses.A_BOLD ) 
+    win7.addstr( 4 , 10 , "TX" , curses.A_BOLD ) 
+    win7.addstr( 4 , 14 , "B2L" , curses.A_BOLD ) 
+    win7.addstr( 4 , 6+22 , "RX" , curses.A_BOLD ) 
+    win7.addstr( 4 , 10+22 , "TX" , curses.A_BOLD ) 
+    win7.addstr( 4 , 14+22 , "B2L" , curses.A_BOLD ) 
+    for i in range( 24 ) :
+        win7.addstr( 5 + i + int( i / 6 ) , 2 , str(i) ) 
+        win7.addstr( 5 + i + int( i / 6 ) , 22 , str(i + 24 ) ) 
+    win7.refresh()
+
     win6 = stdscr.subwin(y_max/6,
-                         x_max -2,
+                         int(0.7*x_max -2),
                          5*y_max/6,
                          0)
     win6.box()
     win6.addstr(1, 1, "F2: Program PLLs (source = FTSW),  F3: Program PLLs (source = Osci.)", CYAN | curses.A_BOLD)
     win6.addstr(2, 1, "F4: Clear LOS/OOF/LOL Flag, F5 : Hard reset, F6: Soft reset", CYAN | curses.A_BOLD)
-    win6.addstr(3, 1, "F8: Resynchronize b2link, F9: Reset trigger counter", CYAN | curses.A_BOLD)
-
+    win6.addstr(3, 1, "F7: Reset trigger counter, r: Resynchronize one b2link", CYAN | curses.A_BOLD)
+    win6.addstr(4, 1, "a: Activate all channels, d: Deactivate all channels", CYAN | curses.A_BOLD)
+    win6.addstr(5, 1, "m: (Des)activate one channel", CYAN | curses.A_BOLD)
+    
     win6.refresh()
 
     # Loop where k is the last character pressed
@@ -355,10 +396,10 @@ def draw_menu(stdscr, dev):
         elif k == curses.KEY_LEFT:
             cursor_x = cursor_x - 1
         elif k == curses.KEY_F2:
-            win1.move(2, 1)
+            win1.move(3, 1)
             win1.clrtobot()
             win1.box()
-            win1.addstr(2, 1, "Programming PLLs (source = FTSW)" , curses.A_BOLD)
+            win1.addstr(3, 1, "Programming PLLs (source = FTSW)" , curses.A_BOLD)
             files = files1b
             conf = conf1
             program_plls(plls, devices, files, win1)
@@ -422,27 +463,30 @@ def draw_menu(stdscr, dev):
                 win1.addstr(line, 1, "..... Done")
                 line = line + 1
             win1.refresh()
+        elif k== ord('r'):
+            win7.addstr(37 , 2 , "Enter channel number to reset + ENTER" , curses.A_BOLD ) 
+            win7.refresh()
+            curses.echo()
+            stdscr.nodelay (False)
+            the_s = stdscr.getstr( 37 , 149 )
+            win7.addstr(37 , 2 , "                                          " , curses.A_BOLD ) 
+            curses.noecho()
+            fpga.resynchronizeLink( int(the_s) ) 
         elif k== curses.KEY_F7:
-            y_max, x_max = win1.getmaxyx()
-            win1.move(2, 1)
-            win1.clrtobot()
-            win1.box()
-            win1.addstr(2, 1, " Initializing INTR masks    ", WHITE)
-            line = 3
-            col = 1
-            for i in plls.keys():
-                plls[i].init_mask_values()
-                win1.addstr(line, 1, devices[i])
-                masks = plls[i].read_mask_values()
-                for mask in sorted(masks.keys()):
-                    win1.addstr(line, col, mask + " : " + str(masks[mask]))
-                    line = line + 1
-                col = col + x_max / 3
-                line = 3
-        elif k== curses.KEY_F8:
-            fpga.resynchronizeLink()
-        elif k==curses.KEY_F9:
             fpga.resetTriggerCounter()
+        elif k==ord('a'):
+            fpga.activateAllChannels()
+        elif k==ord('d'):
+            fpga.deactivateAllChannels()
+        elif k==ord('m'):
+            win7.addstr(38 , 2 , "Enter channel to (un)mask + ENTER" , curses.A_BOLD ) 
+            win7.refresh()
+            curses.echo()
+            stdscr.nodelay (False)
+            the_s = stdscr.getstr( 38 , 145 )
+            win7.addstr(38 , 2 , "                                          " , curses.A_BOLD ) 
+            curses.noecho()
+            fpga.toggleActivateChannel( int(the_s) ) 
 
         # cursor_x = max (0, cursor_x)
         # cursor_x = min (width - 1, cursor_x)
@@ -455,7 +499,7 @@ def draw_menu(stdscr, dev):
         pll_window(pll_si5345_2, devices[2], fpga, freq[2], conf[2], win3)
         pll_window(pll_si5344  , devices[3], fpga, freq[3], conf[3], win4)
         fanout_window(fpga, win5)
-
+        link_window( fpga , win7 ) 
 
         # Refresh the screen
         #stdscr.refresh ()
diff --git a/Scripts/testB2LFrontEnd_DMA.py b/Scripts/testB2LFrontEnd_DMA.py
deleted file mode 100644
index 08da1c51a61904e21946e99ee3cea704536c5aac..0000000000000000000000000000000000000000
--- a/Scripts/testB2LFrontEnd_DMA.py
+++ /dev/null
@@ -1,136 +0,0 @@
-from ctypes import *
-b2 = CDLL("libpcie40.so")
-dma_reset = b2.pcie40_b2dmabufferreset
-dma_read = b2.pcie40_b2dmabufferread
-DMASIZE = 0x2000
-
-nErr = 0 
-
-import os, itertools
-
-CRC16_XMODEM_TABLE = [
-        0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
-        0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
-        0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
-        0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
-        0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
-        0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
-        0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
-        0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
-        0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
-        0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
-        0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
-        0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
-        0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
-        0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
-        0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
-        0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
-        0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
-        0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
-        0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
-        0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
-        0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
-        0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
-        0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
-        0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
-        0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
-        0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
-        0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
-        0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
-        0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
-        0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
-        0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
-        0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
-        ]
-
-
-def _crc16(data, crc, table):
-    """Calculate CRC16 using the given table.
-    `data`      - data for calculating CRC, must be a string
-    `crc`       - initial value
-    `table`     - table for caclulating CRC (list of 256 integers)
-    Return calculated value of CRC
-    """
-    for byte in data:
-        byte1 = byte & 0xFF 
-        byte2 = ( byte & 0xFF00 ) >> 8
-        crc = ((crc<<8)&0xff00) ^ table[((crc>>8)&0xff)^byte2]
-        crc = ((crc<<8)&0xff00) ^ table[((crc>>8)&0xff)^byte1]
-    return crc & 0xffff
-
-def decode_data( dataraw , data ):
-    # Remove intermediate lines
-    datamsb = list( itertools.islice( dataraw , 0 , None , 16 ) ) 
-    datalsb = list( itertools.islice( dataraw , 8 , None , 16 ) ) 
-    # Group in 32 bit words
-    data += [ ( ( x & 0xFFFF ) | (  ( y & 0xFFFF ) << 16 ) ) for x, y in zip( datalsb, datamsb) ] 
-    # Find beginning and end of event
-    size = [ i for i, n in enumerate( data ) if n == data[0] ][1] + 2
-    return size
-
-import socket
-hname = socket.gethostname()
-
-b2.ecs_open( 0 , 2 )
-b2.ecs_open( 0 , 0 )
-
-for nev in range( 1 ): 
-    # Reset DMA buffer
-    dma_reset( 0 ) 
-
-    # Send trigger (adapt this line to your system)
-    if ( hname == 'belle2daq.local' ):
-        os.system( "ssh vme \"trigft -80 pulse 1 1\"" ) ### ADD this to suppress output >/dev/null 2>&1" )
-    else:   ### KEK 
-        os.system( "ssh vme \"trigft -53 pulse 1 1\"" )
-
-    # wait for data to arrive
-    size = 0
-    ## temporisation of 2s
-    import time
-    time.sleep( 2 )
-    
-    # Read DMA
-    dataraw = ( c_int * DMASIZE )( *range( DMASIZE ) ) 
-
-    data = []
-    data_crc = []
-
-    dma_read( 0 , dataraw ) 
-
-    size = decode_data( dataraw , data ) 
-    print "Number of words received = {0}".format( size )
-
-    if size == 0: 
-        print 'Not enough data read, exit' 
-        exit( 0 )
-    
-    for i in range( size ):
-        if ( i <= (size-3)) : 
-            data_crc.append( ( data[ i ] & 0xFFFF0000 ) >> 16 )
-            data_crc.append( ( data[ i ] & 0xFFFF ) ) 
-
-    # Display data:
-    print '==================================='
-    print 'B2L: {0:08x}'.format(data[0])
-    print 'B2L: {0:08x}'.format(data[1])
-    print 'B2L: {0:08x}'.format(data[2])
-    print 'B2L: {0:08x}'.format(data[3])
-    print 'B2L: {0:08x}'.format(data[4])
-    print '-----------------------------------'
-    print 'FEE: data #0 {0:08x}'.format(data[5])
-    print 'FEE: data #1 {0:08x}'.format(data[6])
-    print 'FEE:   ..........'
-    print 'FEE: data #{0} {1:08x}'.format(size-7,data[size-3])
-    print '-----------------------------------'
-    print 'B2L: {0:08x}'.format(data[size-2])
-    print 'B2L: {0:08x}'.format(data[size-1])
-    print '==================================='
-    print ''
-    print 'CRC = {0:04x}'.format(data[size-1]&0xFFFF)
-    print 'Computed CRC {0:04x}'.format(_crc16( data_crc, 0xffff , CRC16_XMODEM_TABLE ) )
-    if ( data[size-1]&0xFFFF ) != ( _crc16( data_crc, 0xffff , CRC16_XMODEM_TABLE ) ):
-        print 'Error in CRC comparison' 
-        nErr = nErr + 1 
-
-print 'number of errors = {0}'.format( nErr ) 
diff --git a/Scripts/testB2L_DMA.py b/Scripts/testB2L_DMA.py
index 820baf7f43ab329844700ad6d33eadf9830f8a60..18c910cf81125d18815fc035090a54f677fbb3aa 100644
--- a/Scripts/testB2L_DMA.py
+++ b/Scripts/testB2L_DMA.py
@@ -2,7 +2,7 @@ from ctypes import *
 b2 = CDLL("libpcie40.so")
 dma_reset = b2.pcie40_b2dmabufferreset
 dma_read = b2.pcie40_b2dmabufferread
-DMASIZE = 0x2000
+DMASIZE = 0x10000
 import os
 
 import socket
diff --git a/Scripts/testDAQHighRate.py b/Scripts/testDAQHighRate.py
index 358cf12f4831592288ccd840c6c6cbbce84de686..08fd2d4d6bd2a217bd1613c734b986a6d4d46f1b 100644
--- a/Scripts/testDAQHighRate.py
+++ b/Scripts/testDAQHighRate.py
@@ -2,7 +2,7 @@ from ctypes import *
 b2 = CDLL("libpcie40.so")
 dma_reset = b2.pcie40_b2dmabufferreset
 dma_read = b2.pcie40_b2dmabufferread
-DMASIZE = 0x2000
+DMASIZE = 0x10000
 
 nErr = 0 
 currentEventIndex = 0 
diff --git a/Scripts/testSLC.py b/Scripts/testSLC.py
index dbebe0322057d8a1440f2f3c86bdf78ce4b2102a..279b3d359467fb8b9d9cc6aab7757866a44bf0d4 100644
--- a/Scripts/testSLC.py
+++ b/Scripts/testSLC.py
@@ -1,6 +1,8 @@
 import argparse
 from ctypes import *
-import random
+import random, time
+
+address = { 'CDC': 0x17 , 'ARICH': 0x12 } 
 
 lli = CDLL("libpcie40.so")
 slc_read = lli.pcie40_readfee32
@@ -8,6 +10,8 @@ slc_read.restype = c_ulong
 
 parser = argparse.ArgumentParser( description = 'Test slow control: read/write random values in register 0x17' )
 parser.add_argument('N',type=int,help='Number of events')
+parser.add_argument('--channel', '-c' , help = 'Channel number' , type = int , default = 0 )
+parser.add_argument('--detector' , '-d' , help = 'Detector' , default = 'CDC' )
 
 args = parser.parse_args()
 result = 0 
@@ -19,9 +23,10 @@ nerr = 0
 
 for i in xrange( args.N ):
     data = random.randint( 0 , 0xFFFFFFFF )
-    lli.pcie40_writefee32( 0 , 0x17 , data )
-    result = slc_read( 0 , 0x17 )
+    lli.pcie40_writefee32( 0 , args.channel , address[ args.detector ] , data )
+    result = slc_read( 0 , args.channel , address[ args.detector ] )
     if result != data:
+        print("mismatch between write ({0:X}) and read ({1:X})".format( data , result ))  
         nerr = nerr + 1
 
 lli.ecs_close( 0 , 2 )