1 | // ESAF : Euso Simulation and Analysis Framework |
---|
2 | // $Id: ListPhotonsOnPupil.cc 2604 2006-03-20 21:51:35Z thea $ |
---|
3 | // M. Pallavicini created Jul, 2 2002 |
---|
4 | |
---|
5 | #include "ListPhotonsOnPupil.hh" |
---|
6 | #include <stdexcept> |
---|
7 | |
---|
8 | ClassImp(ListPhotonsOnPupil) |
---|
9 | |
---|
10 | //______________________________________________________________________________ |
---|
11 | ListPhotonsOnPupil::ListPhotonsOnPupil( vector<ParentPhoton*>* list ) : |
---|
12 | PhotonsOnPupil(), fPhotons( list ) { |
---|
13 | // |
---|
14 | // constructor |
---|
15 | // |
---|
16 | fCurrent = 0; |
---|
17 | if (!list) fPhotons = new vector<ParentPhoton*>; |
---|
18 | } |
---|
19 | |
---|
20 | //______________________________________________________________________________ |
---|
21 | ListPhotonsOnPupil::~ListPhotonsOnPupil() { |
---|
22 | // |
---|
23 | // destructor |
---|
24 | // |
---|
25 | if (fPhotons) { |
---|
26 | Clear(); |
---|
27 | SafeDelete(fPhotons); |
---|
28 | } |
---|
29 | } |
---|
30 | |
---|
31 | //______________________________________________________________________________ |
---|
32 | Bool_t ListPhotonsOnPupil::ClearMemory() { |
---|
33 | // |
---|
34 | // Release all the memory hold by the buffers |
---|
35 | // |
---|
36 | |
---|
37 | Clear(); |
---|
38 | vector<ParentPhoton*> empty; |
---|
39 | empty.swap( *fPhotons ); |
---|
40 | return kTRUE; |
---|
41 | |
---|
42 | } |
---|
43 | |
---|
44 | //______________________________________________________________________________ |
---|
45 | Photon* ListPhotonsOnPupil::GetPhoton() { |
---|
46 | // |
---|
47 | // returns a Photon object |
---|
48 | // |
---|
49 | if ( fCurrent == fPhotons->size() ) |
---|
50 | return (Photon*)0; |
---|
51 | return &( (*fPhotons)[fCurrent++]->GetPhoton() ); |
---|
52 | } |
---|
53 | |
---|
54 | //______________________________________________________________________________ |
---|
55 | void ListPhotonsOnPupil::Clear() { |
---|
56 | // |
---|
57 | // reset the list |
---|
58 | // |
---|
59 | fCurrent=0; |
---|
60 | for(size_t i=0; i < fPhotons->size();i++) { |
---|
61 | ParentPhoton *p=(*fPhotons)[i]; |
---|
62 | SafeDelete(p); |
---|
63 | } |
---|
64 | fPhotons->clear(); |
---|
65 | } |
---|
66 | |
---|
67 | //______________________________________________________________________________ |
---|
68 | void ListPhotonsOnPupil::Add( const SinglePhoton& sp, const TVector3& pos, const TVector3& local_dir) { |
---|
69 | // |
---|
70 | // Convert SinglePhoton into ParentPhoton, then add the latter |
---|
71 | // |
---|
72 | ParentPhoton* pp = new ParentPhoton(sp,pos,local_dir); |
---|
73 | Add(pp); |
---|
74 | } |
---|