Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
BlkArr< T > Class Template Reference

#include <BlkArr.h>

+ Inheritance diagram for BlkArr< T >:

Public Member Functions

 BlkArr (void)
 
 BlkArr (long fqel)
 
 BlkArr (long fqel, const T &val)
 
 BlkArr (long fqel, const T *ar, ArgInterp_Arr t)
 
BlkArr< T > & operator= (const BlkArr< T > &f)
 
 BlkArr (const BlkArr< T > &f)
 
 BlkArr (PILF_CONST BlkArr< T > &f, Pilfer)
 
void pilfer (PILF_CONST BlkArr< T > &f)
 
BlkArrassignAll (const T &f)
 
T & operator[] (long n)
 
const T & operator[] (long n) const
 
T & last_el (void)
 
const T & last_el (void) const
 
long get_qel (void) const
 
void put_qel (long fqel)
 
void increment (void)
 
void decrement (void)
 
void append (const T &val)
 
void print_struct (std::ostream &file) const
 
void allocate_block (long fqel)
 
void clear (void)
 
 macro_copy_total (BlkArr)
 
virtual ~BlkArr (void)
 

Detailed Description

template<class T>
class BlkArr< T >

Definition at line 80 of file BlkArr.h.

Constructor & Destructor Documentation

◆ BlkArr() [1/6]

template<class T >
BlkArr< T >::BlkArr ( void  )
inline

Definition at line 86 of file BlkArr.h.

86: qel(0), la(), size_of_element(sizeof(T)) { ; }

◆ BlkArr() [2/6]

template<class T >
BlkArr< T >::BlkArr ( long  fqel)
inlineexplicit

Definition at line 87 of file BlkArr.h.

88 : qel(fqel), la(DynLinArr<T>(0)), size_of_element(sizeof(T)) {
89 if (qel > 0) la.get_first_node()->el.put_qel(qel);
90 }
AbsListNode< T > * get_first_node(void) const
Definition: AbsList.h:173

◆ BlkArr() [3/6]

template<class T >
BlkArr< T >::BlkArr ( long  fqel,
const T &  val 
)
inline

Definition at line 91 of file BlkArr.h.

92 : qel(fqel), la(DynLinArr<T>(0)), size_of_element(sizeof(T)) {
93 if (qel > 0) la.get_first_node()->el.put_qel(qel, val);
94 }

◆ BlkArr() [4/6]

template<class T >
BlkArr< T >::BlkArr ( long  fqel,
const T *  ar,
ArgInterp_Arr  t 
)
inline

Definition at line 95 of file BlkArr.h.

96 : qel(fqel), la(DynLinArr<T>(0)), size_of_element(sizeof(T)) {
97 if (qel > 0)
98 // la.get_first_node()->el.put_qel(qel, ar, interp_as_arr); error
99 la.get_first_node()->el.pilfer(DynLinArr<T>(qel, ar, t));
100 }

◆ BlkArr() [5/6]

template<class T >
BlkArr< T >::BlkArr ( const BlkArr< T > &  f)
inline

Definition at line 125 of file BlkArr.h.

126 :
127#ifndef DONT_USE_ABSPTR
128 RegPassivePtr(),
129#endif
130 qel(0),
131 la() {
132#ifdef DEBUG_BLKARR
133 mcout << "BlkArr(const BlkArr<T>& f) is working\n";
134#endif
135 *this = f;
136 }
#define mcout
Definition: prstream.h:133

◆ BlkArr() [6/6]

template<class T >
BlkArr< T >::BlkArr ( PILF_CONST BlkArr< T > &  f,
Pilfer   
)
inline

Definition at line 137 of file BlkArr.h.

138 : qel(f.qel), size_of_element(f.size_of_element), la(f.la, steal) {
139#ifdef DEBUG_BLKARR
140 mcout << "BlkArr( BlkArr<T>& f, Pilfer) is working\n";
141#endif
142 f.qel = 0;
143 f.size_of_element = 0;
144 }
@ steal
Definition: AbsPtr.h:513

◆ ~BlkArr()

template<class T >
virtual BlkArr< T >::~BlkArr ( void  )
inlinevirtual

Definition at line 245 of file BlkArr.h.

245{}

Member Function Documentation

◆ allocate_block()

template<class T >
void BlkArr< T >::allocate_block ( long  fqel)
inline

Definition at line 231 of file BlkArr.h.

232 {
233 la.clear();
234 qel = 0;
235 put_qel(fqel);
236 qel = 0;
237 }
void clear(void)
Definition: AbsList.h:227
void put_qel(long fqel)
Definition: BlkArr.h:354

Referenced by Heed::HeedParticle::HeedParticle(), Heed::HeedParticle_BGM::HeedParticle_BGM(), Heed::HeedParticle::physics(), and Heed::HeedParticle_BGM::physics().

◆ append()

template<class T >
void BlkArr< T >::append ( const T &  val)
inline

Definition at line 205 of file BlkArr.h.

205 {
206 increment();
207 operator[](qel - 1) = val;
208 }
void increment(void)
Definition: BlkArr.h:197
T & operator[](long n)
Definition: BlkArr.h:256

Referenced by Heed::HeedParticle::physics(), and Heed::HeedParticle_BGM::physics().

◆ assignAll()

template<class T >
BlkArr & BlkArr< T >::assignAll ( const T &  f)
inline

Definition at line 170 of file BlkArr.h.

170 {
171 long n;
172 for (n = 0; n < qel; n++)
173 operator[](n) = f;
174 return *this;
175 }

◆ clear()

template<class T >
void BlkArr< T >::clear ( void  )
inline

Definition at line 238 of file BlkArr.h.

238 {
239 la.clear();
240 qel = 0;
241 }

◆ decrement()

template<class T >
void BlkArr< T >::decrement ( void  )
inline

Definition at line 201 of file BlkArr.h.

201 {
202 long q = qel - 1;
203 put_qel(q);
204 }

◆ get_qel()

template<class T >
long BlkArr< T >::get_qel ( void  ) const
inline

Definition at line 181 of file BlkArr.h.

181{ return qel; }

Referenced by apeq_mant(), convert(), operator<<(), and operator==().

◆ increment()

template<class T >
void BlkArr< T >::increment ( void  )
inline

Definition at line 197 of file BlkArr.h.

197 {
198 long q = qel + 1;
199 put_qel(q);
200 }

Referenced by BlkArr< T >::append().

◆ last_el() [1/2]

template<class T >
T & BlkArr< T >::last_el ( void  )

Definition at line 304 of file BlkArr.h.

304 {
305 if (qel <= 0) {
306 mcerr << "T& BlkArr::last_el(): no elements in array\n"
307 << " qel=" << qel << '\n';
308 spexit(mcerr);
309 }
310 long q;
312 long n = qel - 1;
313 do {
314 if ((q = aln->el.get_qel()) > n)
315 return aln->el.acu(n);
316 else
317 n -= q;
318 aln = aln->get_next_node();
319 } while (aln != NULL);
320 mcerr << "T& BlkArr::::last_el(): should never happen, n=" << n
321 << " qel=" << qel << '\n';
322 spexit(mcerr);
323#ifdef INS_CRETURN // Insert calming return
324 return aln->el[0]; // to quiet Microsoft Visial Studio compiler against
325 // "not all control paths return a value"
326#endif
327}
#define spexit(stream)
Definition: FunNameStack.h:536
#define mcerr
Definition: prstream.h:135

◆ last_el() [2/2]

template<class T >
const T & BlkArr< T >::last_el ( void  ) const

Definition at line 329 of file BlkArr.h.

329 {
330 if (qel <= 0) {
331 mcerr << "const T& BlkArr::last_el(): no elements in array\n"
332 << " qel=" << qel << '\n';
333 spexit(mcerr);
334 }
335 long q;
337 long n = qel - 1;
338 do {
339 if ((q = aln->el.get_qel()) > n)
340 return aln->el.acu(n);
341 else
342 n -= q;
343 aln = aln->get_next_node();
344 } while (aln != NULL);
345 mcerr << "T& BlkArr::::last_el(): should never happen, n=" << n
346 << " qel=" << qel << '\n';
347 spexit(mcerr);
348#ifdef INS_CRETURN // Insert calming return
349 return aln->el[0]; // to quiet Microsoft Visial Studio compiler against
350 // "not all control paths return a value"
351#endif
352}

◆ macro_copy_total()

template<class T >
BlkArr< T >::macro_copy_total ( BlkArr< T >  )

◆ operator=()

template<class T >
BlkArr< T > & BlkArr< T >::operator= ( const BlkArr< T > &  f)
inline

Definition at line 113 of file BlkArr.h.

113 {
114#ifdef DEBUG_BLKARR
115 mcout << "BlkArr<T>& operator=(const BlkArr<T>& f) is called\n";
116#endif
117 if (this != &f) {
118 qel = f.qel;
119 size_of_element = f.size_of_element;
120 la = f.la;
121 }
122 return *this;
123 }

◆ operator[]() [1/2]

template<class T >
T & BlkArr< T >::operator[] ( long  n)

Definition at line 256 of file BlkArr.h.

256 {
257 if (n < 0 || n >= qel) {
258 mcerr << "T& BlkArr::operator[](long n): n is out of bounds, n=" << n
259 << " qel=" << qel << '\n';
260 spexit(mcerr);
261 }
262 long q;
264 do {
265 if ((q = aln->el.get_qel()) > n)
266 return aln->el.acu(n);
267 else
268 n -= q;
269 aln = aln->get_next_node();
270 } while (aln != NULL);
271 mcerr << "T& BlkArr::operator[](long n): should never happen, n=" << n
272 << " qel=" << qel << '\n';
273 spexit(mcerr);
274#ifdef INS_CRETURN // Insert calming return
275 return aln->el[0]; // to quiet Microsoft Visial Studio compiler against
276 // "not all control paths return a value"
277#endif
278}

Referenced by BlkArr< T >::append().

◆ operator[]() [2/2]

template<class T >
const T & BlkArr< T >::operator[] ( long  n) const

Definition at line 280 of file BlkArr.h.

280 {
281 if (n < 0 || n >= qel) {
282 mcerr << "const T& BlkArr::operator[](long n): n is out of bounds, n=" << n
283 << " qel=" << qel << '\n';
284 spexit(mcerr);
285 }
286 long q;
288 do {
289 if ((q = aln->el.get_qel()) > n)
290 return aln->el.acu(n);
291 else
292 n -= q;
293 aln = aln->get_next_node();
294 } while (aln != NULL);
295 mcerr << "T& BlkArr::operator[](long n): should never happen, n=" << n
296 << " qel=" << qel << '\n';
297 spexit(mcerr);
298#ifdef INS_CRETURN // Insert calming return
299 return aln->el[0]; // to quiet Microsoft Visial Studio compiler against
300 // "not all control paths return a value"
301#endif
302}

◆ pilfer()

template<class T >
void BlkArr< T >::pilfer ( PILF_CONST BlkArr< T > &  f)
inline

Definition at line 145 of file BlkArr.h.

145 {
146#ifdef DEBUG_BLKARR
147 mcout << "BlkArr::pilfer is called\n";
148#endif
149 if (this != &f) {
150 if (qel != 0) {
151 if (f.qel != 0) {
152 mcerr << "ERROR in BlkArr::pilfer(...):\n";
153 mcerr << "Both the destination and source arrays are not empty\n";
154 // For explanations why it is dengerous, see similar function
155 // of ActivePtr.
156 spexit(mcerr);
157 } else {
158 la.clear();
159 size_of_element = 0;
160 qel = 0;
161 }
162 }
163 qel = f.qel;
164 size_of_element = f.size_of_element;
165 la.pilfer(f.la);
166 f.qel = 0;
167 f.size_of_element = 0;
168 }
169 }
void pilfer(PILF_CONST AbsList< T > &al)
Definition: AbsList.h:664

◆ print_struct()

template<class T >
void BlkArr< T >::print_struct ( std::ostream &  file) const

Definition at line 493 of file BlkArr.h.

493 {
494 Ifile << "structure: qel=" << qel << " size_of_element=" << size_of_element
495 << "\n";
496 indn.n += 2;
497 long total_q = 0;
498 long n = 0;
500 if (aln != NULL) {
501 do {
502 Ifile << "n=" << n << " qel=" << aln->el.get_qel() << '\n';
503 total_q += aln->el.get_qel();
504 aln = aln->get_next_node();
505 } while (aln != NULL);
506 }
507 Ifile << "total_q=" << total_q << '\n';
508 Ifile << "end of structure.\n";
509 indn.n -= 2;
510}
indentation indn
Definition: prstream.cpp:13
#define Ifile
Definition: prstream.h:207

Referenced by operator<<().

◆ put_qel()

template<class T >
void BlkArr< T >::put_qel ( long  fqel)

Definition at line 354 of file BlkArr.h.

354 {
355 //mcout<<"BlkArr<T>::put_qel: fqel="<<fqel<<'\n';
356 if (fqel == qel) return;
357 /*
358 if(fqel == 0)
359 {
360 qel = 0;
361 la.clear();
362 }
363 else
364 {
365 */
366 //long n;
368 if (aln == NULL) {
369 la.insert_after(NULL, DynLinArr<T>(0));
370 la.get_first_node()->el.put_qel(fqel);
371 qel = fqel;
372 return;
373 } else {
374 if (fqel > qel) // the case of increase
375 {
376 long fqel_res = fqel; // space to reserve
377 // fqel_res should be more than fqel
378 // But remember, both are the total number of elements, not the increase
379 if (fqel_res < 2 * qel) // then consider more space to reserve
380 {
381 long ex = 2 * qel * size_of_element; // compute the memory expense
382 if (ex < max_size_of_extra_increment) // check whether it is not large
383 fqel_res = 2 * qel; // OK
384 else { // No, too large
385 long q = max_size_of_extra_increment / size_of_element; //less number
386 if (q <= 0) q = 1; // 1 at least
387 if (fqel_res - qel < q) fqel_res = qel + q; // increase
388 }
389 }
390 long q;
391 long left_old_qel = qel;
392 long left_new_qel = fqel;
393 long left_new_qel_res = fqel_res;
394 //Iprintn(mcout, left_new_qel);
395 //Iprintn(mcout, left_new_qel_res);
397 do {
398 q = aln->el.get_qel();
399 //Iprintn(mcout, q);
400 //Iprintn(mcout, left_old_qel);
401 //Iprintn(mcout, left_new_qel);
402 if (q >= left_old_qel) // this node, there is space
403 {
404 if (q >= left_new_qel) // that's enough, nothing to do
405 { // and no reservation additional space
406 qel = fqel;
407 return;
408 } else // No, the new requested space is larger then the available
409 { // in the current node. But there may be next ones inited
410 // already
411 left_new_qel -= q;
412 left_new_qel_res -= q;
413 AbsListNode<DynLinArr<T> >* aln1; // pointer to block
414 while (
415 (aln1 = aln->get_next_node()) !=
416 NULL) { // scanning next blocks, which may be present already
417 aln = aln1;
418 q = aln->el.get_qel();
419 if (q >= left_new_qel) // Good, existing space is enogh
420 {
421 qel = fqel;
422 return;
423 }
424 left_new_qel -= q;
425 left_new_qel_res -= q;
426 } // No, is not enough
427 // then make new node with reservation
428 la.insert_after(aln, DynLinArr<T>(0));
429 la.get_last_node()->el.put_qel(left_new_qel_res);
430 qel = fqel;
431 //Iprintn(mcout, qel);
432 return;
433 }
434 }
435 left_old_qel -= q;
436 left_new_qel -= q;
437 aln = aln->get_next_node();
438 } while (aln != NULL);
439 mcout << "BlkArr<T>::put_qel: should never happen\n";
440 } else // the case of decrease
441 {
442 long q;
443 long left_old_qel = qel;
444 long left_new_qel = fqel;
446 do {
447 q = aln->el.get_qel();
448 if (q >= left_new_qel) // this node, there is space
449 {
450 // initialize by dummy constructor so as to get rid of garbage,
451 // that is of elements at the end of this block
452 long n;
453 for (n = left_new_qel; n < q; n++) {
454 aln->el[n] = T();
455 }
456 left_old_qel -= q;
457 //left_new_qel -= q;
459 if (aln1 != NULL) // so preserving next node as histeresis
460 {
461 if (left_new_qel != 0) // possible if fqel=0
462 { // if fqel=0, all the next nodes will be deleted in total
463 // later
464 aln = aln1;
465 q = aln->el.get_qel();
466 if (left_old_qel > 0) // then getting rid of garbage
467 {
468 long l = left_old_qel;
469 if (q < l) l = q;
470 for (n = 0; n < l; n++) {
471 aln->el[n] = T();
472 }
473 }
474 }
475 while ((aln1 = aln->get_next_node()) != NULL) // deleting all next
476 // nodes
477 {
478 la.erase(aln1);
479 }
480 }
481 qel = fqel;
482 return;
483 }
484 left_old_qel -= q;
485 left_new_qel -= q;
486 aln = aln->get_next_node();
487 } while (aln != NULL);
488 qel = fqel;
489 }
490 }
491}
const long max_size_of_extra_increment
Definition: BlkArr.h:76
AbsListNode< T > * get_next_node(void) const
Definition: AbsList.h:98
AbsListNode< T > * insert_after(AbsListNode< T > *an, const T &fel)
Definition: AbsList.h:487
void erase(AbsListNode< T > *an)
Definition: AbsList.h:547
AbsListNode< T > * get_last_node(void) const
Definition: AbsList.h:174

Referenced by BlkArr< T >::allocate_block(), BlkArr< T >::decrement(), BlkArr< T >::increment(), and Heed::SimpleTablePhotoAbsCS::SimpleTablePhotoAbsCS().


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