StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CRC.cxx
1 /***************************************************************************
2  * $Id: CRC.cxx,v 1.6 2018/06/10 17:16:01 smirnovd Exp $
3  * Author: M.W. Schulz
4  ***************************************************************************
5  * Description: calculate and check the CRC
6  *
7  *
8  * change log
9  * 02-Jul-99 MJL removed default value in args (already done in function
10  * prototypes in CRC.hh
11  *
12  ***************************************************************************
13  * $Log: CRC.cxx,v $
14  * Revision 1.6 2018/06/10 17:16:01 smirnovd
15  * Add missing namespace OLDEVP
16  *
17  * Revision 1.5 2007/12/24 06:04:16 fine
18  * introduce OLDEVP namespace to allow ole and new EVP library concurrently
19  *
20  * Revision 1.4 1999/12/07 23:10:30 levine
21  * changes to silence the gcc compiler warnings
22  *
23  * Revision 1.3 1999/07/02 21:07:45 levine
24  * removed redundant default value for function parameter, which caused error in
25  * Linux gcc compiler. Default value already declared in function prototype
26  * in CRC.hh
27  *
28  * Revision 1.2 1999/07/02 04:37:41 levine
29  * Many changes - see change logs in individual programs
30  *
31  *
32  **************************************************************************/
33 #include "CRC.hh"
34 
35 using namespace OLDEVP;
36 
37 #define LSWP0312 ch[0] = cdp[i*4 +3] ; ch[1] = cdp[i*4 + 2] ; ch[2] = cdp[i*4+1] ; ch[3] = cdp[i*4] ;
38 #define LSWP12 ch[0] = cdp[i*4] ; ch[1] = cdp[i*4 + 2] ; ch[2] = cdp[i*4+1] ; ch[3] = cdp[i*4+3] ;
39 #define LSWP04 ch[0] = cdp[i*4 +3] ; ch[1] = cdp[i*4 + 1] ; ch[2] = cdp[i*4+2] ; ch[3] = cdp[i*4] ;
40 
41 
42 
43 /* in memory everything has to be done like this !!!!!*/
44 /* if you read the data from file, we have to use the variable routine
45  for some of the banks */
46 unsigned int OLDEVP::compute_crc_bank(Bank* d,unsigned int lcrc )
47 {
48  /* first do the header, but not the crc */
49  int i ;
50  int* p;
51  if(d->header.ByteOrder == 0x04030201) /* fine no swap */
52  {
53  p = (int*)&d->header ;
54  for(i = 0 ; i < d->header.BankLength ;i++) CRC32DEF(p[i],lcrc) ;
55  return(lcrc);
56  }
57  else
58  {
59  int help ;
60  int length ;
61  char* cdp ;
62  char* ch = (char*)&help ;
63  p = (int*)&d->header ;
64  cdp = (char*)p ;
65  length = (sizeof(Bank_Header)/4) ;
66  if(d->header.ByteOrder == 0x01020304)
67  {
68  p = (int*)&d->header ;
69  cdp = (char*)p ;
70  for(i = 0 ; i < length ;i++){ LSWP0312 ; if(i==2)length = help ; CRC32DEF(help,lcrc) ;}
71  return(lcrc) ;
72  }
73  if(d->header.ByteOrder == 0x04030201)
74  {
75  p = (int*)&d->header ;
76  cdp = (char*)p ;
77  for(i = 0 ; i < length ;i++){ LSWP12 ;if(i==2)length = help ; CRC32DEF(help,lcrc) ;}
78  return(lcrc) ;
79  }
80  if(d->header.ByteOrder == 0x04030201)
81  {
82  p = (int*)&d->header ;
83  cdp = (char*)p ;
84  for(i = 0 ; i < length ;i++){ LSWP04 ;if(i==2)length = help ; CRC32DEF(help,lcrc) ;}
85  return(lcrc) ;
86  }
87  return(0xffffff) ;
88  }
89 };
90 //**************************************************************************
91 unsigned int OLDEVP::compute_crc_block(int* p,unsigned int ByteOrder,int Length,unsigned int lcrc )
92 {
93  int i ;
94  if(ByteOrder == 0x04030201) /* fine no swap */
95  {
96  for(i = 0 ; i < Length ;i++) CRC32DEF(p[i],lcrc) ;
97  return(lcrc);
98  }
99  else
100  {
101  int help ;
102  int length ;
103  char* cdp ;
104  char* ch = (char*)&help ;
105  cdp = (char*)p ;
106  length = Length ;
107  if(ByteOrder == 0x01020304)
108  {
109  cdp = (char*)p ;
110  for(i = 0 ; i < length ;i++){ LSWP0312 ; CRC32DEF(help,lcrc) ;}
111  return(lcrc) ;
112  }
113  if(ByteOrder == 0x04030201)
114  {
115  cdp = (char*)p ;
116  for(i = 0 ; i < length ;i++){ LSWP12 ; CRC32DEF(help,lcrc) ;}
117  return(lcrc) ;
118  }
119  if(ByteOrder == 0x04030201)
120  {
121  cdp = (char*)p ;
122  for(i = 0 ; i < length ;i++){ LSWP04 ; CRC32DEF(help,lcrc) ;}
123  return(lcrc) ;
124  }
125  return(0xffffff) ;
126  }
127 };
128 
129