ReaderInternal: Internal data format implementation
[u/mrichter/AliRoot.git] / HBTAN / AliHBTReader.cxx
CommitLineData
1b446896 1#include "AliHBTReader.h"
2
0fdcc83d 3#include <TString.h>
4#include <TObjString.h>
5#include <TObjArray.h>
6#include <TClass.h>
7#include <iostream.h>
8
1b446896 9#include "AliHBTParticleCut.h"
10
11
12ClassImp(AliHBTReader)
13//pure virtual
14
15/*************************************************************************************/
16
17AliHBTReader::AliHBTReader()
18{
19//constructor
20 fCuts = new TObjArray();
0fdcc83d 21 fDirs = 0x0;
1b446896 22}
23
24/*************************************************************************************/
0fdcc83d 25AliHBTReader::AliHBTReader(TObjArray* dirs)
26 {
27 fCuts = new TObjArray();
28 fDirs = dirs;
29 }
1b446896 30
31AliHBTReader::~AliHBTReader()
32{
33//destructor
36ee4bd5 34 if(fCuts)
35 {
36 fCuts->SetOwner();
37 delete fCuts;
38 }
1b446896 39}
40
41/*************************************************************************************/
42
43void AliHBTReader::AddParticleCut(AliHBTParticleCut* cut)
44{
45 //sets the new cut
46
47 if (!cut) //if cut is NULL return with error
48 {
49 Error("AddParticleType","NULL pointers are not accepted any more.\nIf You want to accept all particles of this type, set an empty cut ");
50 return;
51 }
52 AliHBTParticleCut *c = (AliHBTParticleCut*)cut->Clone();
53 fCuts->Add(c);
54}
55
56/*************************************************************************************/
57
58Bool_t AliHBTReader::Pass(AliHBTParticle* p)
59 {
60 //Method examines whether particle meets all cut and particle type criteria
61
62 if(p==0x0)//of corse we not pass NULL pointers
63 {
64 Warning("Pass()","No Pasaran! We never accept NULL pointers");
65 return kTRUE;
66 }
67 //if no particle is specified, we pass all particles
68 //excluding NULL pointers, of course
e526d37c 69 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
1b446896 70 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
71 {
72 AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i));
73 if(!cut.Pass(p)) return kFALSE; //accepted
74 }
75
76 return kTRUE;//not accepted
77
78 }
79/*************************************************************************************/
80
81Bool_t AliHBTReader::Pass(Int_t pid)
82{
83//this method checks if any of existing cuts accepts this pid particles
84//or any cuts accepts all particles
85
86 if(pid == 0)
87 return kTRUE;
e526d37c 88
89 if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
1b446896 90
91 for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)
92 {
93 AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i));
94 //if some of cuts accepts all particles or some accepts particles of this type, accept
95 if ( (cut.GetPID() == 0) || (cut.GetPID() == pid) ) return kFALSE;
96 }
97 return kTRUE;
98}
99/*************************************************************************************/
0fdcc83d 100
101TString& AliHBTReader::GetDirName(Int_t entry)
102 {
103 TString* retval;//return value
104 if (fDirs == 0x0)
105 {
106 retval = new TString(".");
107 return *retval;
108 }
109
110 if ( (entry>fDirs->GetEntries()) || (entry<0))//if out of bounds return empty string
111 { //note that entry==0 is accepted even if array is empty (size=0)
112 Error("GetDirName","Name out of bounds");
113 retval = new TString();
114 return *retval;
115 }
116
117 if (fDirs->GetEntries() == 0)
118 {
119 retval = new TString(".");
120 return *retval;
121 }
122
123 TClass *objclass = fDirs->At(entry)->IsA();
124 TClass *stringclass = TObjString::Class();
125
126 TObjString *dir = (TObjString*)objclass->DynamicCast(stringclass,fDirs->At(entry));
127
128 if(dir == 0x0)
129 {
130 Error("GetDirName","Object in TObjArray is not a TObjString or its descendant");
131 retval = new TString();
132 return *retval;
133 }
134 if (gDebug > 0) cout<<"Returned ok "<<dir->String().Data()<<endl;
135 return dir->String();
136 }
137