StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
swaps.cxx
1 /***************************************************************************
2  * $Id: swaps.cxx,v 1.3 2007/12/24 06:04:17 fine Exp $
3  * Author: M.W. Schulz
4  ***************************************************************************
5  * Description: swap method and macros for use on DAQ banks
6  * these defines MAY NOT be moved into a header file,
7  * they are of use only in this source file - MWS
8  *
9  ***************************************************************************
10  * $Log: swaps.cxx,v $
11  * Revision 1.3 2007/12/24 06:04:17 fine
12  * introduce OLDEVP namespace to allow ole and new EVP library concurrently
13  *
14  * Revision 1.2 1999/07/02 04:37:42 levine
15  * Many changes - see change logs in individual programs
16  *
17  *
18  **************************************************************************/
19 
20 #define SWP0312 {help = data[i] ; cdp[i*4] = ch[3] ; cdp[i*4+1] = ch[2] ; cdp[i*4+2] = ch[1] ; cdp[i*4+3] = ch[0] ;}
21 #define SWP12 {help = data[i] ; cdp[i*4] = ch[0] ; cdp[i*4+1] = ch[2] ; cdp[i*4+2] = ch[1] ; cdp[i*4+3] = ch[3] ;}
22 #define SWP04 { help = data[i]; cdp[i*4] = ch[3] ; cdp[i*4+1] = ch[1] ; cdp[i*4+2] = ch[2] ; cdp[i*4+3] = ch[0] ;}
23 #define SWP_SHORT {help = data[i] ; cdp[i*4] = ch[1] ; cdp[i*4+1] = ch[0] ; cdp[i*4+2] = ch[3] ; cdp[i*4+3] = ch[2] ;}
24 
25 namespace OLDEVP {
26 
27 int swap_raw(int data_byte_ordering,int* data, int size)
28 {
29  if(data_byte_ordering == 0x04030201) return(0) ;
30  char* cdp = (char*) data ;
31  int help ;
32  char* ch = (char*)&help ;
33  int i ;
34  if(data_byte_ordering == 0x01020304) { /* swap 0-3 1 1-2 */ for(i = 0 ; i < size ;i++) SWP0312 return(1) ; }
35  if(data_byte_ordering == 0x04020301) { /* swap 1-2 */ for(i = 0 ; i < size ;i++)SWP12 return(2) ; }
36  if(data_byte_ordering == 0x01030204) { /* swap 0-4 */ for(i = 0 ; i < size ;i++)SWP04 return(3) ; }
37  return(-1) ; /* realy bad */
38 };
39 
40 int swap_short(int data_byte_ordering,int* data, int size)
41 {
42  if(data_byte_ordering == 0x04030201) return(0) ;
43  char* cdp = (char*) data ;
44  int help ;
45  char* ch = (char*)&help ;
46  int i ;
47  if(data_byte_ordering == 0x01020304) { /* swap 0-3 1 1-2 */ for(i = 0 ; i < size ;i++) SWP_SHORT return(1) ; }
48  if(data_byte_ordering == 0x04020301) { return -1; }
49  if(data_byte_ordering == 0x01030204) { return -1; }
50  return(-1) ; /* realy bad */
51 }
52 }
53 #undef SWP0312
54 #undef SWP12
55 #undef SWP04
56 #undef SWP_SHORT
57 
58