BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtCyclic3.cc
Go to the documentation of this file.
1#include "EvtPatches.hh"
2/*******************************************************************************
3 * Project: BaBar detector at the SLAC PEP-II B-factory
4 * Package: EvtGenBase
5 * File: $Id: EvtCyclic3.cc,v 1.1.1.2 2007/10/26 05:03:14 pingrg Exp $
6 * Author: Alexei Dvoretskii, dvoretsk@slac.stanford.edu, 2001-2002
7 *
8 * Copyright (C) 2002 Caltech
9 *******************************************************************************/
10
11#include "EvtCyclic3.hh"
12#include <assert.h>
13#include <iostream>
14#include <string.h>
15using std::ostream;
16
17using namespace EvtCyclic3;
18
20 if ( p == ABC ) return i;
21 else if ( p == BCA )
22 {
23 if ( i == A ) return C;
24 else if ( i == B ) return A;
25 else if ( i == C ) return B;
26 }
27 else if ( p == BCA )
28 {
29 if ( i == A ) return C;
30 else if ( i == B ) return A;
31 else if ( i == C ) return B;
32 }
33 else if ( p == CAB )
34 {
35 if ( i == A ) return B;
36 else if ( i == B ) return C;
37 else if ( i == C ) return A;
38 }
39 else if ( p == CBA )
40 {
41 if ( i == A ) return C;
42 else if ( i == B ) return B;
43 else if ( i == C ) return A;
44 }
45 else if ( p == BAC )
46 {
47 if ( i == A ) return B;
48 else if ( i == B ) return A;
49 else if ( i == C ) return C;
50 }
51 else if ( p == ACB )
52 {
53 if ( i == A ) return A;
54 else if ( i == B ) return C;
55 else if ( i == C ) return B;
56 }
57 return A;
58}
59
61 assert( i1 != i2 && i2 != i3 && i3 != i1 );
62 if ( i1 == A ) return ( i2 == B ) ? ABC : ACB;
63 if ( i1 == B ) return ( i2 == C ) ? BCA : BAC;
64 if ( i1 == C ) return ( i2 == A ) ? CAB : CBA;
65 return ABC;
66}
67
69 Index i1 = permute( permute( A, i ), p );
70 Index i2 = permute( permute( B, i ), p );
71 Index i3 = permute( permute( C, i ), p );
72
73 return permutation( i1, i2, i3 );
74}
75
77 Index i1 = permute( first( i ), p );
78 Index i2 = permute( second( i ), p );
79 return combine( i1, i2 );
80}
81
83 assert( 0 <= i && i <= 2 );
84 switch ( i )
85 {
86 case 0: return BC;
87 case 1: return CA;
88 case 2: return AB;
89 }
90 assert( 0 );
91 return AB; // should never get here
92}
93
95 switch ( i )
96 {
97 case A: return C;
98 case B: return A;
99 case C: return B;
100 }
101 assert( 0 );
102 return A; // should never get here
103}
104
106 switch ( i )
107 {
108 case A: return B;
109 case B: return C;
110 case C: return A;
111 }
112 assert( 0 );
113 return A; // should never get here
114}
115
117 assert( i != j );
118 switch ( i )
119 {
120 case A:
121 switch ( j )
122 {
123 case B: return C;
124 case C: return B;
125 default: assert( 0 );
126 }
127 case B:
128 switch ( j )
129 {
130 case C: return A;
131 case A: return C;
132 default: assert( 0 );
133 }
134 case C:
135 switch ( j )
136 {
137 case A: return B;
138 case B: return A;
139 default: assert( 0 );
140 }
141 }
142 assert( 0 );
143 return A; // should never get here
144}
145
146// Index-to-pair conversions
147
149 switch ( i )
150 {
151 case A: return BC;
152 case B: return CA;
153 case C: return AB;
154 }
155 assert( 0 );
156 return AB; // should never get here
157}
158
159Pair EvtCyclic3::combine( Index i, Index j ) { return other( other( i, j ) ); }
160
161// Pair-to-pair conversions
162
164 Pair ret = CA;
165 if ( i == BC ) ret = AB;
166 else if ( i == CA ) ret = BC;
167
168 return ret;
169}
170
172 Pair ret = BC;
173 if ( i == BC ) ret = CA;
174 else if ( i == CA ) ret = AB;
175
176 return ret;
177}
178
179Pair EvtCyclic3::other( Pair i, Pair j ) { return combine( other( i ), other( j ) ); }
180
181// Pair-to-index conversions
182
184 switch ( i )
185 {
186 case BC: return B;
187 case CA: return C;
188 case AB: return A;
189 }
190 assert( 0 );
191 return A; // should never get here
192}
193
195 switch ( i )
196 {
197 case BC: return C;
198 case CA: return A;
199 case AB: return B;
200 }
201 assert( 0 );
202 return A; // should never get here
203}
204
206 switch ( i )
207 {
208 case BC: return A;
209 case CA: return B;
210 case AB: return C;
211 }
212 assert( 0 );
213 return A; // should never get here
214}
215
216Index EvtCyclic3::common( Pair i, Pair j ) { return other( other( i, j ) ); }
217
218Index EvtCyclic3::strToIndex( const char* str ) {
219 if ( strcmp( str, "A" ) ) return A;
220 else if ( strcmp( str, "B" ) ) return B;
221 else if ( strcmp( str, "C" ) ) return C;
222 else
223 {
224 std::cerr << __FILE__ << ":" << __LINE__ << "Should not reach here!" << std::endl;
225 abort();
226 }
227}
228
229Pair EvtCyclic3::strToPair( const char* str ) {
230 if ( !strcmp( str, "AB" ) || !strcmp( str, "BA" ) ) return AB;
231 else if ( !strcmp( str, "BC" ) || !strcmp( str, "CB" ) ) return BC;
232 else if ( !strcmp( str, "CA" ) || !strcmp( str, "AC" ) ) return CA;
233 else
234 {
235 std::cerr << __FILE__ << ":" << __LINE__ << "Should not reach here!" << std::endl;
236 abort();
237 }
238}
239
241 switch ( i )
242 {
243 case A: return "A";
244 case B: return "B";
245 case C: return "C";
246 }
247 assert( 0 );
248 return 0; // sngh
249}
250
252 switch ( i )
253 {
254 case BC: return "BC";
255 case CA: return "CA";
256 case AB: return "AB";
257 }
258 assert( 0 );
259 return 0; // sngh
260}
261
263 if ( p == ABC ) return "ABC";
264 if ( p == BCA ) return "BCA";
265 if ( p == CAB ) return "CAB";
266 if ( p == CBA ) return "CBA";
267 if ( p == BAC ) return "BAC";
268 if ( p == ACB ) return "ACB";
269 return "???";
270}
271
272char* EvtCyclic3::append( const char* str, EvtCyclic3::Index i ) {
273 // str + null + 1 character
274 char* s = new char[strlen( str ) + 2];
275 strcpy( s, str );
276 strcat( s, c_str( i ) );
277
278 return s;
279}
280
281char* EvtCyclic3::append( const char* str, EvtCyclic3::Pair i ) {
282 // str + null + 2 characters
283 char* s = new char[strlen( str ) + 3];
284 strcpy( s, str );
285 strcat( s, c_str( i ) );
286
287 return s;
288}
289
290ostream& operator<<( ostream& os, EvtCyclic3::Index i ) {
291 switch ( i )
292 {
293 case A: {
294 os << "A";
295 return os;
296 }
297 case B: {
298 os << "B";
299 return os;
300 }
301 case C: {
302 os << "C";
303 return os;
304 }
305 }
306 assert( 0 );
307 return os; // should never get here
308}
309
310ostream& operator<<( ostream& os, EvtCyclic3::Pair i ) {
311 switch ( i )
312 {
313 case BC: {
314 os << "BC";
315 return os;
316 }
317 case CA: {
318 os << "CA";
319 return os;
320 }
321 case AB: {
322 os << "AB";
323 return os;
324 }
325 }
326 assert( 0 );
327 return os; // should never get here
328}
ostream & operator<<(ostream &os, EvtCyclic3::Index i)
XmlRpcServer s
Index permute(Index i, Perm p)
Definition EvtCyclic3.cc:19
Index next(Index i)
Index strToIndex(const char *str)
Perm permutation(Index i1, Index i2, Index i3)
Definition EvtCyclic3.cc:60
char * append(const char *str, EvtCyclic3::Index i)
Index common(Pair i, Pair j)
Pair strToPair(const char *str)
Pair combine(Index i, Index j)
Index second(Pair i)
Pair i2pair(int i)
Definition EvtCyclic3.cc:82
Index prev(Index i)
Definition EvtCyclic3.cc:94
char * c_str(Index i)
Index other(Index i, Index j)
Index first(Pair i)