]>
Commit | Line | Data |
---|---|---|
87434909 | 1 | |
2 | /************************************************************************** | |
3 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
4 | * * | |
5 | * Authors: Oystein Djuvsland <oysteind@ift.uib.no> * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | ||
17 | #include <iostream> | |
18 | ||
19 | #include "AliHLTPHOSESDCaloClusterWriterComponent.h" | |
20 | #include "AliESDCaloCluster.h" | |
21 | #include "TTree.h" | |
22 | #include "TClonesArray.h" | |
23 | #include "TFile.h" | |
24 | ||
25 | /** @file AliHLTPHOSESDCaloClusterWriterComponent.cxx | |
26 | @author Oystein Djuvsland | |
27 | @date | |
28 | @brief An ESD calo cluster writer component for PHOS HLT | |
29 | */ | |
30 | ||
31 | // see header file for class documentation | |
32 | // or | |
33 | // refer to README to build package | |
34 | // or | |
35 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
36 | ||
37 | #if __GNUC__>= 3 | |
38 | using namespace std; | |
39 | #endif | |
40 | ||
41 | AliHLTPHOSESDCaloClusterWriterComponent gAliHLTPHOSESDCaloClusterWriterComponent; | |
42 | ||
43 | AliHLTPHOSESDCaloClusterWriterComponent::AliHLTPHOSESDCaloClusterWriterComponent(): | |
44 | AliHLTPHOSProcessor(), | |
45 | fOutfile(0), | |
46 | fOutfileName(0), | |
47 | fWriteModulo(1000), | |
48 | fESDCaloClusterTreePtr(0), | |
49 | fESDCaloClustersPtr(0) | |
50 | { | |
51 | //See headerfile for documentation | |
52 | } | |
53 | ||
54 | AliHLTPHOSESDCaloClusterWriterComponent::~AliHLTPHOSESDCaloClusterWriterComponent() | |
55 | { | |
56 | //See headerfile for documentation | |
57 | ||
58 | if(fESDCaloClustersPtr) | |
59 | { | |
60 | fESDCaloClustersPtr->Write(); | |
61 | delete fESDCaloClustersPtr; | |
62 | fESDCaloClustersPtr = 0; | |
63 | } | |
64 | if (fOutfile) | |
65 | { | |
66 | fOutfile->Close(); | |
67 | delete fOutfile; | |
68 | fOutfile = 0; | |
69 | } | |
70 | } | |
71 | ||
72 | ||
73 | int | |
74 | AliHLTPHOSESDCaloClusterWriterComponent::Deinit() | |
75 | { | |
76 | //See headerfile for documentation | |
77 | ||
78 | if(fESDCaloClustersPtr) | |
79 | { | |
80 | fESDCaloClustersPtr->Write(); | |
81 | delete fESDCaloClustersPtr; | |
82 | fESDCaloClustersPtr = 0; | |
83 | } | |
84 | if (fOutfile) | |
85 | { | |
86 | fOutfile->Close(); | |
87 | delete fOutfile; | |
88 | fOutfile = 0; | |
89 | } | |
90 | return 0; | |
91 | } | |
92 | ||
93 | const Char_t* | |
94 | AliHLTPHOSESDCaloClusterWriterComponent::GetComponentID() | |
95 | { | |
96 | //See headerfile for documentation | |
97 | ||
98 | return "PhosEsdCaloClusterWriter"; | |
99 | } | |
100 | ||
101 | void | |
102 | AliHLTPHOSESDCaloClusterWriterComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) | |
103 | { | |
104 | //See headerfile for documentation | |
105 | list.clear(); | |
106 | list.push_back(AliHLTPHOSDefinitions::fgkESDCaloClusterDataType); | |
107 | ||
108 | } | |
109 | ||
110 | AliHLTComponentDataType | |
111 | AliHLTPHOSESDCaloClusterWriterComponent::GetOutputDataType() | |
112 | { | |
113 | //See headerfile for documentation | |
114 | return kAliHLTAnyDataType; | |
115 | } | |
116 | ||
117 | void | |
118 | AliHLTPHOSESDCaloClusterWriterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier ) | |
119 | ||
120 | { | |
121 | //See headerfile for documentation | |
122 | ||
123 | constBase = 30; | |
124 | inputMultiplier = 2; | |
125 | } | |
126 | ||
127 | Int_t | |
128 | AliHLTPHOSESDCaloClusterWriterComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/ ) | |
129 | { | |
130 | // see header file for class documentation | |
131 | ||
132 | const TObject* iter = 0; | |
133 | // const AliHLTComponentBlockData* iter = 0; | |
134 | ||
135 | //UInt_t specification = 0; | |
136 | // iter = GetFirstInputObject(AliHLTPHOSDefinitions::fgkESDCaloClusterDataType); | |
137 | //cout << iter << endl; | |
138 | for(iter = GetFirstInputObject(AliHLTPHOSDefinitions::fgkESDCaloClusterDataType); iter != NULL; iter = GetNextInputObject()) | |
139 | { | |
140 | ||
141 | ||
142 | //fESDCaloClustersPtr->AddAll(reinterpret_cast<const TClonesArray*>(iter)); | |
143 | fESDCaloClustersPtr = reinterpret_cast<TClonesArray*>(const_cast<TObject*>(iter)->Clone()); | |
144 | ||
145 | } | |
146 | ||
147 | ||
148 | ||
149 | // iter = GetFirstInputBlock(AliHLTPHOSDefinitions::fgkESDCaloClusterDataType); | |
150 | ||
151 | // if(iter) | |
152 | // { | |
153 | // specification = specification|iter->fSpecification; | |
154 | // cout << (reinterpret_cast<TClonesArray*>(iter->fPtr))->GetEntries() << endl; | |
155 | // // fESDCaloClustersPtr->AddAll(reinterpret_cast<TClonesArray*>(iter->fPtr)); | |
156 | // while((iter = GetNextInputBlock())) | |
157 | // { | |
158 | // // fESDCaloClustersPtr->AddAll(reinterpret_cast<TClonesArray*>(iter->fPtr)); | |
159 | // } | |
160 | ||
161 | // } | |
162 | // HLTError("Number of clusters: %d", fESDCaloClustersPtr->GetEntries()); | |
163 | fESDCaloClusterTreePtr->Fill(); | |
164 | ||
165 | fPhosEventCount++; | |
166 | ||
167 | if(fPhosEventCount % fWriteModulo == 0) | |
168 | { | |
169 | WriteTree(); | |
170 | } | |
171 | ||
172 | //fESDCaloClustersPtr->Delete(); | |
173 | ||
174 | return 0; | |
175 | } | |
176 | ||
177 | int | |
178 | AliHLTPHOSESDCaloClusterWriterComponent::WriteTree() | |
179 | { | |
180 | ||
181 | // See headerfile for documentation | |
182 | char tmpFilename[128]; | |
183 | sprintf(tmpFilename, "%s_%d.root", fOutfileName, fPhosEventCount/fWriteModulo); | |
184 | ||
185 | fOutfile = TFile::Open(tmpFilename, "RECREATE"); | |
186 | if(fOutfile == 0) | |
187 | { | |
188 | HLTError("Could not open file %s for writing", tmpFilename); | |
189 | return -1; | |
190 | } | |
191 | fESDCaloClusterTreePtr->Write(); | |
192 | fOutfile->Close(); | |
193 | fESDCaloClusterTreePtr->Reset(); | |
194 | return 0; | |
195 | } | |
196 | ||
197 | int | |
198 | AliHLTPHOSESDCaloClusterWriterComponent::DoInit(int argc, const char** argv ) | |
199 | { | |
200 | //See headerfile for documentation | |
201 | fOutfileName = new char[128]; | |
202 | char tmpFilename[128]; | |
203 | ScanArgumentsModule(argc, argv); | |
204 | for (int i = 0; i < argc; i++) | |
205 | { | |
206 | if(!strcmp("-filename", argv[i])) | |
207 | { | |
208 | sprintf(fOutfileName, "/tmp/%s", argv[i+1]); | |
209 | sprintf(tmpFilename, "%s_0.root", fOutfileName); | |
210 | } | |
211 | if(!strcmp("-writemodulo", argv[i])) | |
212 | { | |
213 | fWriteModulo = atoi(argv[i+1]); | |
214 | } | |
215 | } | |
216 | // fESDCaloClustersPtr = new TClonesArray(AliESDCaloCluster::Class(), 0); | |
217 | fESDCaloClusterTreePtr = new TTree("caloClusterTree", "Tree containing AliESDCaloClusters reconstructed in HLT"); | |
218 | fESDCaloClusterTreePtr->Branch("CaloClusters", &fESDCaloClustersPtr); | |
219 | ||
220 | //fESDCaloClusterTreePtr->SetBranchAddress("CaloClusters", &fESDCaloClustersPtr); | |
221 | ||
222 | return 0; | |
223 | } | |
224 | ||
225 | AliHLTComponent* | |
226 | AliHLTPHOSESDCaloClusterWriterComponent::Spawn() | |
227 | { | |
228 | //See headerfile for documentation | |
229 | ||
230 | return new AliHLTPHOSESDCaloClusterWriterComponent(); | |
231 | } | |
232 |