documentation
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTLoaderPublisherComponent.cxx
CommitLineData
90ebac25 1// @(#) $Id$
2
9be2600f 3/**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
6 * *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
90ebac25 19/** @file AliHLTLoaderPublisherComponent.cxx
20 @author Matthias Richter
21 @date
22 @brief A general tree publisher component for the AliLoader.
23*/
24
c534985b 25// see header file for class documentation
26// or
27// refer to README to build package
28// or
29// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
90ebac25 31#include "AliHLTLoaderPublisherComponent.h"
32#include "AliRunLoader.h"
33#include "AliLoader.h"
34#include "AliLog.h"
35#include "TTree.h"
36
37/** global instance for agent registration */
38AliHLTLoaderPublisherComponent gAliHLTLoaderPublisherComponent;
39
40/** ROOT macro for the implementation of ROOT specific class methods */
41ClassImp(AliHLTLoaderPublisherComponent)
42
43AliHLTLoaderPublisherComponent::AliHLTLoaderPublisherComponent()
44 :
45 fMaxSize(0),
46 fLoaderType(),
47 fTreeType("digits"),
48 fVerbose(kFALSE),
49 fDataType(kAliHLTAnyDataType),
50 fSpecification(0),
51 fpLoader(NULL)
52{
53 // see header file for class documentation
54 // or
55 // refer to README to build package
56 // or
57 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58}
59
60AliHLTLoaderPublisherComponent::~AliHLTLoaderPublisherComponent()
61{
62 // see header file for class documentation
63}
64
65const char* AliHLTLoaderPublisherComponent::GetComponentID()
66{
67 // see header file for class documentation
68 return "AliLoaderPublisher";
69}
70
71AliHLTComponentDataType AliHLTLoaderPublisherComponent::GetOutputDataType()
72{
73 return fDataType;
74}
75
76void AliHLTLoaderPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
77{
78 constBase=fMaxSize;
79 inputMultiplier=1;
80}
81
82AliHLTComponent* AliHLTLoaderPublisherComponent::Spawn()
83{
84 // see header file for class documentation
85 return new AliHLTLoaderPublisherComponent;
86}
87
88int AliHLTLoaderPublisherComponent::DoInit( int argc, const char** argv )
89{
90 // see header file for class documentation
91 int iResult=0;
92
93 // scan arguments
94 TString argument="";
95 int bMissingParam=0;
96 for (int i=0; i<argc && iResult>=0; i++) {
97 argument=argv[i];
98 if (argument.IsNull()) continue;
99
100 // -loader
101 if (argument.CompareTo("-loader")==0) {
102 if ((bMissingParam=(++i>=argc))) break;
103 fLoaderType=argv[i];
104
105 // -tree
106 } else if (argument.CompareTo("-tree")==0) {
107 if ((bMissingParam=(++i>=argc))) break;
108 fTreeType=argv[i];
109
110 // -verbose
111 } else if (argument.CompareTo("-verbose")==0) {
112 fVerbose=kTRUE;
113
114 // -datatype
115 } else if (argument.CompareTo("-datatype")==0) {
116 if ((bMissingParam=(++i>=argc))) break;
117 memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i])));
118 if ((bMissingParam=(++i>=argc))) break;
119 memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i])));
120
121 // -dataspec
122 } else if (argument.CompareTo("-dataspec")==0) {
123 if ((bMissingParam=(++i>=argc))) break;
124 TString parameter(argv[i]);
125 parameter.Remove(TString::kLeading, ' '); // remove all blanks
126 if (parameter.IsDigit()) {
127 fSpecification=(AliHLTUInt32_t)parameter.Atoi();
128 } else if (parameter.BeginsWith("0x") &&
129 parameter.Replace(0,2,"",0).IsHex()) {
130 sscanf(parameter.Data(),"%x", &fSpecification);
131 } else {
132 HLTError("wrong parameter for argument %s, number expected", argument.Data());
133 iResult=-EINVAL;
134 }
135 } else {
136 HLTError("unknown argument %s", argument.Data());
137 iResult=-EINVAL;
138 }
139 }
140 if (bMissingParam) {
141 HLTError("missing parameter for argument %s", argument.Data());
142 iResult=-EINVAL;
143 }
144
145 if (iResult<0) return iResult;
146
147 if (fLoaderType.IsNull()) {
c534985b 148 AliErrorStream() << "loader type required, use \'-loader\' option" << endl;
90ebac25 149 return -EINVAL;
150 }
151
152 // fetch runLoader instance from interface
153 AliRunLoader* pRunLoader=GetRunLoader();
154 if (pRunLoader) {
155
156 // get the TPC loader
157 fpLoader=pRunLoader->GetLoader(fLoaderType.Data());
158 if (fpLoader) {
159 // prepare the loader
160 fpLoader->LoadDigits("read");
161
162 // scan trough all events and estimate the size of the digits
163 for (int i=0; i<pRunLoader->GetNumberOfEvents(); i++) {
164 pRunLoader->GetEvent(i);
165 TTree* pTree=GetTree();
166 if (pTree) {
167 int size=EstimateObjectSize(pTree);
168 if (size>fMaxSize) fMaxSize=size;
169 if (fVerbose) {
170 AliInfoStream() << "event " << i << " "
171 << fTreeType <<" size " << size
172 << " count " << pTree->GetEntries() << endl;
173 }
174 } else {
175 AliWarningStream() << "no " << fTreeType << " tree for event " << i << endl;
176 }
177 }
178 } else {
179 AliErrorStream() << "can not get loader of type " << fLoaderType << endl;
180 iResult=-EFAULT;
181 }
182 } else {
183 AliErrorStream() << "can not get runLoader" << endl;
184 iResult=-EFAULT;
185 }
186 return iResult;
187}
188
189int AliHLTLoaderPublisherComponent::DoDeinit()
190{
191 // see header file for class documentation
192 int iResult=0;
193 if (fpLoader) {
194 fpLoader->UnloadDigits();
195 }
196 fpLoader=NULL;
197 return iResult;
198}
199
298ef463 200int AliHLTLoaderPublisherComponent::GetEvent(const AliHLTComponentEventData& /*evtData*/,
201 AliHLTComponentTriggerData& /*trigData*/)
90ebac25 202{
203 // see header file for class documentation
204 int iResult=0;
205 // fetch runLoader instance from interface
206 AliRunLoader* pRunLoader=GetRunLoader();
207 if (pRunLoader && fpLoader) {
208 pRunLoader->GetEvent(GetEventCount());
209 TTree* pTree=GetTree();
210 if (pTree) {
211 PushBack(pTree, fDataType);
212 } else {
213 AliWarningStream() << "no " << fTreeType << " tree for event " << GetEventCount() << endl;
214 }
215 } else {
216 AliErrorStream() << "component not initialized" << endl;
56951e49 217 iResult=-EFAULT;
90ebac25 218 }
219 return iResult;
220}
221
222TTree* AliHLTLoaderPublisherComponent::GetTree()
223{
224 TTree* pTree=NULL;
225 if (fpLoader) {
226 if (fTreeType.CompareTo("digits")==0)
227 pTree=fpLoader->TreeD();
228 else if (fTreeType.CompareTo("clusters")==0) {
229 pTree=fpLoader->TreeR();
230 }
231 } else {
232 }
233 return pTree;
234}