source: JEM-EUSO/esaf_cc_at_lal/packages/simulation/detector/G4Detector/G4fresnellens/include/FixedStack.h @ 114

Last change on this file since 114 was 114, checked in by moretto, 11 years ago

actual version of ESAF at CCin2p3

File size: 2.9 KB
Line 
1#ifndef __FIXEDSTACK__
2#define __FIXEDSTACK__
3#include <stack>
4
5namespace G4FresnelLens{
6//__________________________________________________________________________________
7struct fcIterationStep{
8    //fcIterationStep ( int i1, int i2, double lr, double lz, double rr, double rz ) :
9    //                 leftI(i1), rightI(i2), leftRho(lr), rightRho(rr), leftZ(lz), rightZ(rz) {};
10    fcIterationStep(){};
11    fcIterationStep( int i1, int i2 ) : leftI(i1), rightI(i2) {};
12    int leftI, rightI;
13    //double leftRho, rightRho, leftZ, rightZ;
14};
15
16//__________________________________________________________________________________
17#define LIFOStackSize 20
18//#define LIFOStackDebug
19class fixedISStack {
20    public:
21        fixedISStack() : size(LIFOStackSize), last(-1) {};
22
23        inline void push(int i1, int i2/*, double lr, double lz, double rr, double rz*/);
24        inline fcIterationStep* pop();
25        bool empty() { return last<0; }
26        inline void clear();
27
28    private:
29        fcIterationStep steps[LIFOStackSize];
30        int size, last;
31        std::stack<fcIterationStep*> overSteps;
32};
33
34//__________________________________________________________________________________
35void fixedISStack::push(int i1, int i2/*, double lr, double lz, double rr, double rz*/){
36    last++;
37    fcIterationStep* cstep;
38    if ( last>=LIFOStackSize ) {
39        //Warning_("fixedISStack overfill. Recompile!");
40        //return;
41        cstep=new fcIterationStep(i1,i2);
42        overSteps.push(cstep);
43        #ifdef LIFOStackDebug
44          printf("stack push (dynamic)  %i: %9i, %9i\n", last, cstep->leftI, cstep->rightI);
45        #endif
46    }
47    else {
48        cstep=(steps+last);
49        cstep->leftI=i1;
50        cstep->rightI=i2;
51        #ifdef LIFOStackDebug
52          printf("stack push (static)  %i: %9i, %9i\n", last, steps[last].leftI, steps[last].rightI);
53        #endif
54    }
55}
56
57//__________________________________________________________________________________
58fcIterationStep* fixedISStack::pop(){
59    if ( last<0 ) {
60        #ifdef LIFOStackDebug
61          printf("stack pop: empty\n");
62        #endif
63        return 0;
64    }
65    if ( last>=LIFOStackSize ) {
66        fcIterationStep* out=overSteps.top();
67        overSteps.pop();
68        last--;
69        #ifdef LIFOStackDebug
70          printf("stack pop (dynamic)  %i: %9i, %9i\n", last, out->leftI, out->rightI);
71        #endif
72        return out;
73    }
74
75    #ifdef LIFOStackDebug
76      printf("stack pop (static)  %i: %9i, %9i\n", last, steps[last].leftI, steps[last].rightI);
77    #endif
78    return steps+last--;
79}
80
81//__________________________________________________________________________________
82void fixedISStack::clear(){
83    #ifdef LIFOStackDebug
84      printf("stack pop: clear\n");
85    #endif
86    if ( last>=LIFOStackSize ) {
87        while ( !overSteps.empty() ){
88            delete overSteps.top();
89            overSteps.pop();
90        }
91    }
92    last=-1;
93}
94
95};
96#endif
Note: See TracBrowser for help on using the repository browser.