StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
L3_Banks.cxx
1 /***************************************************************************
2  *
3  * $Id: L3_Banks.cxx,v 1.5 2007/12/24 06:04:20 fine Exp $
4  *
5  * Author: Christof Struck, struck@star.physics.yale.edu
6  ***************************************************************************
7  *
8  * Description: L3 specific swap functions
9  *
10  *
11  *
12  * change log:
13  * 06 Jun 00 CS initial version
14  * 24 Jul 00 CS added i960 cluster banks
15  *
16  ***************************************************************************
17  *
18  * $Log: L3_Banks.cxx,v $
19  * Revision 1.5 2007/12/24 06:04:20 fine
20  * introduce OLDEVP namespace to allow ole and new EVP library concurrently
21  *
22  * Revision 1.4 2001/08/20 05:37:36 struck
23  * removed naming conflicts with 'Stl3Utils/foreign/L3Formats.h'
24  *
25  * Revision 1.3 2001/07/17 19:16:11 struck
26  * update to 2001 data format (backwards compatible)Z
27  *
28  * Revision 1.2 2001/06/21 19:24:50 struck
29  * corrected typo in filenames
30  *
31  * Revision 1.1 2001/06/21 19:19:15 struck
32  * Should have been ...
33  *
34  * Revision 1.4 2000/07/26 02:37:41 struck
35  * minor changes
36  *
37  * Revision 1.3 2000/07/26 02:12:27 struck
38  * added i960 cluster reader
39  *
40  * Revision 1.2 2000/07/06 18:16:00 ward
41  * Install L3 code from Christof Struck.
42  *
43  *
44  **************************************************************************/
45 #include "L3_Banks.hh"
46 #include <assert.h>
47 
48 using namespace OLDEVP;
49 
50 int Bank_L3_SUMD::swap()
51 {
52  // get bank length
53  int words = header.BankLength;
54  int iret = swap_raw(header.ByteOrder,&words,1);
55 
56  // returns zero means none needed
57  if(!iret) return(0);
58  // returns negative means error
59  if(iret < 0) return iret;
60 
61  // swap body first
62  iret = swap_raw(header.ByteOrder, (INT32 *)&nProcessed, 3);
63  assert(iret > 0);
64 
65  // now swap algorithm_data structure
66  for (int i=0; i<nAlg; i++) {
67  iret = swap_raw(header.ByteOrder, (INT32 *)&alg[i].algId, 1);
68  iret = swap_raw(header.ByteOrder, (INT32 *)&alg[i].nProcessed, 13);
69  }
70 
71  // swap the header
72  iret = header.swap();
73 
74  return iret;
75 }
76 
77 
78 int Bank_L3_GTD::swap()
79 {
80  // get bank length
81  int words = header.BankLength;
82  int iret = swap_raw(header.ByteOrder,&words,1);
83 
84  // returns zero means none needed
85  if(!iret) return(0);
86  // returns negative means error
87  if(iret < 0) return iret;
88 
89  // swap body first
90  iret = swap_raw(header.ByteOrder, (INT32 *)&nHits, 5);
91  assert(iret > 0);
92 
93  // now swap globalTrack structure
94  for (unsigned int i=0; i<nTracks; i++) {
95  iret = swap_raw(header.ByteOrder, (int *)&track[i].id, 1);
96  iret = l3Swap_short((short *)&track[i].flag, (short) 1);
97  iret = swap_raw(header.ByteOrder, (int *)&track[i].chi2, 13);
98  }
99 
100  // swap the header
101  iret = header.swap();
102 
103  return iret;
104 }
105 
106 
107 int Bank_L3_LTD::swap()
108 {
109  // get bank length
110  int words = header.BankLength;
111  int iret = swap_raw(header.ByteOrder,&words,1);
112 
113  // returns zero means none needed
114  if(!iret) return(0);
115  // returns negative means error
116  if(iret < 0) return iret;
117 
118  int nTracks = (int) (words * 4 - sizeof(Bank_Header)) / sizeof(localTrack);
119 
120  // now swap localTrack structure
121  for (int i=0; i<nTracks; i++) {
122  iret = l3Swap_short((short *)&track[i].id, 1);
123  iret = l3Swap_short((short *)&track[i].innerMostRow, (short) 4);
124  iret = swap_raw(header.ByteOrder, (INT32 *)&track[i].dedx, 8);
125  iret = l3Swap_short((short *)&track[i].dpt, 4);
126  }
127 
128  // swap the header
129  iret = header.swap();
130 
131  return iret;
132 }
133 
134 
135 int Bank_L3_SECCD::swap()
136 {
137  // get bank length
138  int words = header.BankLength;
139  int iret = swap_raw(header.ByteOrder,&words,1);
140 
141  // returns zero means none needed
142  if(!iret) return(0);
143  // returns negative means error
144  if(iret < 0) return iret;
145 
146  // swap body first
147  iret = swap_raw(header.ByteOrder, (INT32 *)&nrClusters_in_sector, 1);
148  assert(iret > 0);
149 
150  // now swap L3_Cluster structure
151  for (unsigned int i=0; i<nrClusters_in_sector; i++) {
152  iret = l3Swap_short((short *)&cluster[i].pad, (short) 5);
153  }
154 
155  // swap the header
156  iret = header.swap();
157 
158  return iret;
159 }
160 
161 
162 // taken from TPCV2PO.Banks.cxx
163 int Bank_TPCMZCLD::swap()
164 {
165  int iret = swap_raw(header.ByteOrder, &numberOfRows, 1);
166  if(iret <= 0) return iret;
167 
168  int nsp = 0;
169  int *word = &numberOfRows;
170  word++; //bump to first instance of PadRow
171  for (int i=0; i<numberOfRows; i++) {
172  swap_raw(header.ByteOrder, word, 2);
173  nsp = word[1];
174  word += 2; //point to first cluster
175  swap_short(header.ByteOrder, word, 2*nsp);
176  word += 2 * nsp; //bump past clusters
177  }
178 
179  return header.swap();
180 }
181 
182 
183 // our own swap, which swaps shorts (and not words of shorts)
184 int l3Swap_short (short* data, short size)
185 {
186  char *curr = (char *)data;
187  for (int i=0; i<size; i++) {
188  char temp = curr[0];
189  curr[0] = curr[1];
190  curr[1] = temp;
191  curr += 2;
192  }
193  return 1;
194 };