CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
CDFootPrint Class Reference

#include <CDFootPrint.h>

Public Member Functions

 CDFootPrint ()
 
 CDFootPrint (const CDFootPrint &)
 
virtual ~CDFootPrint ()
 
const CDFootPrintoperator= (const CDFootPrint &)
 
const CDFootPrintoperator+= (const CDFootPrint &aOtherPrint)
 
CDFootPrintfresh ()
 
bool operator== (const CDFootPrint &aOtherPrint) const
 
bool operator!= (const CDFootPrint &aOtherPrint) const
 
CDFootPrint operator+ (const CDFootPrint &aOtherPrint) const
 
bool overlap (const CDFootPrint &aOtherPrint) const
 
bool contains (const CDFootPrint &aOtherPrint) const
 
uint32_t ToUInt32 () const
 

Static Public Member Functions

static void reset ()
 

Friends

class FingerPrint
 
std::ostream & operator<< (std::ostream &os, const CDFootPrint &obj)
 

Detailed Description

Definition at line 80 of file CDFootPrint.h.

Constructor & Destructor Documentation

◆ CDFootPrint() [1/2]

CDFootPrint::CDFootPrint ( )

Definition at line 106 of file CDFootPrint.cxx.

106 :
107 m_size(0),
108 m_array(0)
109{
110 ++m_numberFootprints;
111}

◆ CDFootPrint() [2/2]

CDFootPrint::CDFootPrint ( const CDFootPrint aOtherPrint)

Definition at line 115 of file CDFootPrint.cxx.

115 :
116 m_size(0) ,
117 m_array(0)
118{
119 //
120 // book the memory and copy contents of aOtherPrint
121 //
122 resize( aOtherPrint.m_size );
123 for ( uint32_t index = 0 ;
124 index != m_size ;
125 ++index ) {
126 m_array[ index ] = aOtherPrint.m_array[ index ] ;
127 }
128 ++m_numberFootprints;
129}

◆ ~CDFootPrint()

CDFootPrint::~CDFootPrint ( )
virtual

Definition at line 133 of file CDFootPrint.cxx.

134{
135 //
136 // delete memory
137 //
138 delete [] m_array ;
139 if( 0 == --m_numberFootprints ) {
140 reset();
141 }
142}
static void reset()

Member Function Documentation

◆ contains()

bool CDFootPrint::contains ( const CDFootPrint aOtherPrint) const

Definition at line 420 of file CDFootPrint.cxx.

421{
422 if (this == & aOtherPrint) {
423 //
424 // if being tested with itself return `true'
425 //
426 return(! false);
427 }
428 //
429 // find the shortest length to compare the two memoery sections
430 //
431 uint32_t shorterSize ;
432 if ( m_size > aOtherPrint.m_size ) {
433 shorterSize = aOtherPrint.m_size ;
434 }
435 else {
436 shorterSize = m_size ;
437 }
438
439 //
440 // for shorter CDFootPrint check aOtherPrint is within this one
441 //
442 uint32_t index = 0 ;
443 while ( ( index != shorterSize ) &&
444 ( m_array[ index ] ==( m_array[index] | aOtherPrint.m_array[index] ) ) ) {
445 ++index ;
446 }
447 //
448 // if check finished before the shorter CDFootPrint was covered,
449 // then aOtherPrint has at least one bit outside this CDFootPrint
450 //
451 if ( index != shorterSize ) {
452 return ( false ) ;
453 }
454 //
455 // if this CDFootPrint is the longer then aOtherPrint is totally contained
456 //
457 if ( m_size > aOtherPrint.m_size ) {
458 return ( !false ) ;
459 }
460 //
461 // as aOtherPrint is longer need to check rest of it is zero
462 //
463 while( ( index != aOtherPrint.m_size ) &&
464 (aOtherPrint.m_array[ index ] == uint32_t( 0 ) ) ) {
465 ++index ;
466 }
467 //
468 // if check finished before aOtherPrint was finished
469 // then aOtherPrint has at least one bit in the rest of it
470 //
471 return ( aOtherPrint.m_size == index ) ;
472}

◆ fresh()

CDFootPrint & CDFootPrint::fresh ( void  )

Definition at line 234 of file CDFootPrint.cxx.

235{
236 if ( m_size != 0 ) {
237 //
238 // if already assigned a value do nothing
239 //
240 return ( *this ) ;
241 }
242
243 const uint32_t kBitsInByte = 8 ;
244 //
245 // Take a number and increase the number of CDFootPrints issued
246 //
247 uint32_t freshNumber = m_numberIssued++ ;
248 //
249 // calculate which bit, and which element to set
250 //
251 uint32_t element = freshNumber / ( kBitsInByte * sizeof( uint32_t ) ) ;
252 uint32_t offsetInElement = freshNumber % ( kBitsInByte * sizeof( uint32_t ) ) ;
253 //
254 // book enough memory
255 //
256 resize( element + 1 ) ;
257 //
258 // fill all but the last part of the memory with zeros
259 //
260 for ( uint32_t index = 0 ;
261 index < element ;
262 ++index ) {
263 m_array[ index ] = uint32_t( 0 );
264 }
265 //
266 // fill in last part of memory with correct bit set
267 //
268 m_array[ element ] = uint32_t(1) << offsetInElement ;
269 return ( *this ) ;
270}

◆ operator!=()

bool CDFootPrint::operator!= ( const CDFootPrint aOtherPrint) const

Definition at line 365 of file CDFootPrint.cxx.

366{
367 return ( ! operator == ( aOtherPrint ) ) ;
368}

◆ operator+()

CDFootPrint CDFootPrint::operator+ ( const CDFootPrint aOtherPrint) const

Definition at line 373 of file CDFootPrint.cxx.

374{
375 CDFootPrint result( *this ) ;
376 result += aOtherPrint ;
377 return ( result ) ;
378}

◆ operator+=()

const CDFootPrint & CDFootPrint::operator+= ( const CDFootPrint aOtherPrint)

Definition at line 168 of file CDFootPrint.cxx.

169{
170 if ( this == &aOtherPrint ) {
171 //
172 // if Footprint is added and assigned to itself do nothing.
173 //
174 return(*this);
175 }
176 if ( m_size >= aOtherPrint.m_size ) {
177 //
178 // if this Footprint is larger or equal than to aOtherPrint,
179 // only `or' with the contents of aOtherPoint
180 //
181 for ( uint32_t index = 0 ;
182 index != aOtherPrint.m_size ;
183 ++index) {
184 m_array[ index ] |= aOtherPrint.m_array[ index ] ;
185 }
186 }
187 else {
188 //
189 // if this Footprint is smaller than to aOtherPrint book new memory
190 // Note: can not use resize, as this thorws away old memory
191 //
192 uint32_t* tmp_ptr = new uint32_t[ aOtherPrint.m_size ];
193 if ( 0 == tmp_ptr ) {
194 std::cerr << "No memory to allocate another kinematicData" << std::endl ;
195 exit( 1 ) ;
196 }
197 //
198 // for the length of the old memory, fill the new memory with
199 // `or' of old and aOtherPrint
200 //
201 for ( uint32_t index_1 = 0 ;
202 index_1 != m_size ;
203 ++index_1 ) {
204 tmp_ptr[ index_1 ] = m_array[ index_1 ] | aOtherPrint.m_array[ index_1 ] ;
205 }
206 //
207 // for the rest of length of the new memory, fill with aOtherPrint
208 //
209 for ( uint32_t index_2 = m_size ;
210 index_2 != aOtherPrint.m_size ;
211 ++index_2) {
212 tmp_ptr[ index_2 ] = aOtherPrint.m_array[ index_2 ] ;
213 }
214 //
215 // delete old memory
216 //
217 delete [] m_array ;
218 //
219 // update member data elements
220 //
221 m_size = aOtherPrint.m_size;
222 m_array = tmp_ptr ;
223 }
224 return ( *this ) ;
225}

◆ operator=()

const CDFootPrint & CDFootPrint::operator= ( const CDFootPrint aOtherPrint)

Definition at line 148 of file CDFootPrint.cxx.

149{
150 if ( this == &aOtherPrint ) {
151 //
152 // if Footprint is assigned to itself do nothing.
153 //
154 return( *this ) ;
155 }
156 //
157 // book the memory and copy contents of aOtherPrint
158 //
159 resize( aOtherPrint.m_size ) ;
160 for ( uint32_t index = 0 ;
161 index != m_size ;
162 ++index ) {
163 m_array[ index ] = aOtherPrint.m_array[ index ] ;
164 }
165 return ( *this ) ;
166}

◆ operator==()

bool CDFootPrint::operator== ( const CDFootPrint aOtherPrint) const

Definition at line 310 of file CDFootPrint.cxx.

311{
312 if ( this == &aOtherPrint ) {
313 //
314 // if being compare with itself return `true'
315 //
316 return( !false ) ;
317 }
318 //
319 // find the shortest length to compare the two memory sections
320 //
321 uint32_t shorterSize ;
322 if ( m_size > aOtherPrint.m_size ) {
323 shorterSize = aOtherPrint.m_size ;
324 }
325 else {
326 shorterSize = m_size ;
327 }
328 //
329 // check shorter CDFootPrint matches the section longer CDFootPrint
330 //
331 uint32_t index = 0;
332 while ( ( index != shorterSize ) &&
333 ( m_array[ index ] == aOtherPrint.m_array[ index ] ) ) {
334 ++index ;
335 }
336 //
337 // if check finished before the shorter CDFootPrint was covered,
338 // then two CDFootPrints are unequal
339 //
340 if ( index != shorterSize ) {
341 return ( false ) ;
342 }
343 //
344 // check that the rest of the longer footprint is zero
345 //
346 if ( m_size >= aOtherPrint.m_size ) {
347 while ( ( index != m_size ) &&
348 ( m_array[ index ] == uint32_t( 0 ) ) ) {
349 ++index ;
350 }
351 return ( m_size == index );
352 }
353 else {
354 while( ( index != aOtherPrint.m_size ) &&
355 (aOtherPrint.m_array[ index ] == uint32_t( 0 ) ) ) {
356 ++index ;
357 }
358 return ( aOtherPrint.m_size == index );
359 }
360}

◆ overlap()

bool CDFootPrint::overlap ( const CDFootPrint aOtherPrint) const

Definition at line 384 of file CDFootPrint.cxx.

385{
386 if (this == & aOtherPrint) {
387 //
388 // if being tested with itself return `true'
389 //
390 return( !false );
391 }
392 //
393 // find the shortest length to compare the two memoery sections
394 //
395 uint32_t shorterSize ;
396 if ( m_size > aOtherPrint.m_size ) {
397 shorterSize = aOtherPrint.m_size ;
398 }
399 else {
400 shorterSize = m_size ;
401 }
402 //
403 // check shorter CDFootPrint matches the section longer CDFootPrint
404 //
405 uint32_t index = 0;
406 while ( ( index != shorterSize ) &&
407 ( 0 == ( m_array[ index ] & aOtherPrint.m_array[ index ] ) ) ) {
408 ++index ;
409 }
410 //
411 // if check finished before the shorter CDFootPrint was covered,
412 // then two CDFootPrints have at least one bit in common
413 //
414 return ( index != shorterSize ) ;
415}

Referenced by CDCandidate::overlap().

◆ reset()

void CDFootPrint::reset ( )
static

Definition at line 481 of file CDFootPrint.cxx.

482{
483 m_numberIssued = 0 ;
484}

Referenced by ~CDFootPrint().

◆ ToUInt32()

uint32_t CDFootPrint::ToUInt32 ( ) const
inline

Definition at line 109 of file CDFootPrint.h.

109{ return m_array[0]; }

Friends And Related Function Documentation

◆ FingerPrint

friend class FingerPrint
friend

Definition at line 84 of file CDFootPrint.h.

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const CDFootPrint obj 
)
friend

Definition at line 89 of file CDFootPrint.cxx.

89 {
90 os << "0x" << std::hex;
91 for ( int i = obj.m_size-1; i >= 0; i-- ) {
92 os << obj.m_array[i];
93 }
94 os << std::dec;
95
96 return os;
97}

The documentation for this class was generated from the following files: