]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/util/AliHLTLoaderPublisherComponent.cxx
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
25#include "AliHLTLoaderPublisherComponent.h"
26#include "AliRunLoader.h"
27#include "AliLoader.h"
28#include "AliLog.h"
29#include "TTree.h"
30
31/** global instance for agent registration */
32AliHLTLoaderPublisherComponent gAliHLTLoaderPublisherComponent;
33
34/** ROOT macro for the implementation of ROOT specific class methods */
35ClassImp(AliHLTLoaderPublisherComponent)
36
37AliHLTLoaderPublisherComponent::AliHLTLoaderPublisherComponent()
38 :
39 fMaxSize(0),
40 fLoaderType(),
41 fTreeType("digits"),
42 fVerbose(kFALSE),
43 fDataType(kAliHLTAnyDataType),
44 fSpecification(0),
45 fpLoader(NULL)
46{
47 // see header file for class documentation
48 // or
49 // refer to README to build package
50 // or
51 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
52}
53
54AliHLTLoaderPublisherComponent::~AliHLTLoaderPublisherComponent()
55{
56 // see header file for class documentation
57}
58
59const char* AliHLTLoaderPublisherComponent::GetComponentID()
60{
61 // see header file for class documentation
62 return "AliLoaderPublisher";
63}
64
65AliHLTComponentDataType AliHLTLoaderPublisherComponent::GetOutputDataType()
66{
67 return fDataType;
68}
69
70void AliHLTLoaderPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
71{
72 constBase=fMaxSize;
73 inputMultiplier=1;
74}
75
76AliHLTComponent* AliHLTLoaderPublisherComponent::Spawn()
77{
78 // see header file for class documentation
79 return new AliHLTLoaderPublisherComponent;
80}
81
82int AliHLTLoaderPublisherComponent::DoInit( int argc, const char** argv )
83{
84 // see header file for class documentation
85 int iResult=0;
86
87 // scan arguments
88 TString argument="";
89 int bMissingParam=0;
90 for (int i=0; i<argc && iResult>=0; i++) {
91 argument=argv[i];
92 if (argument.IsNull()) continue;
93
94 // -loader
95 if (argument.CompareTo("-loader")==0) {
96 if ((bMissingParam=(++i>=argc))) break;
97 fLoaderType=argv[i];
98
99 // -tree
100 } else if (argument.CompareTo("-tree")==0) {
101 if ((bMissingParam=(++i>=argc))) break;
102 fTreeType=argv[i];
103
104 // -verbose
105 } else if (argument.CompareTo("-verbose")==0) {
106 fVerbose=kTRUE;
107
108 // -datatype
109 } else if (argument.CompareTo("-datatype")==0) {
110 if ((bMissingParam=(++i>=argc))) break;
111 memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i])));
112 if ((bMissingParam=(++i>=argc))) break;
113 memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i])));
114
115 // -dataspec
116 } else if (argument.CompareTo("-dataspec")==0) {
117 if ((bMissingParam=(++i>=argc))) break;
118 TString parameter(argv[i]);
119 parameter.Remove(TString::kLeading, ' '); // remove all blanks
120 if (parameter.IsDigit()) {
121 fSpecification=(AliHLTUInt32_t)parameter.Atoi();
122 } else if (parameter.BeginsWith("0x") &&
123 parameter.Replace(0,2,"",0).IsHex()) {
124 sscanf(parameter.Data(),"%x", &fSpecification);
125 } else {
126 HLTError("wrong parameter for argument %s, number expected", argument.Data());
127 iResult=-EINVAL;
128 }
129 } else {
130 HLTError("unknown argument %s", argument.Data());
131 iResult=-EINVAL;
132 }
133 }
134 if (bMissingParam) {
135 HLTError("missing parameter for argument %s", argument.Data());
136 iResult=-EINVAL;
137 }
138
139 if (iResult<0) return iResult;
140
141 if (fLoaderType.IsNull()) {
142 HLTError("loader type required, use \'-loader\' option");
143 return -EINVAL;
144 }
145
146 // fetch runLoader instance from interface
147 AliRunLoader* pRunLoader=GetRunLoader();
148 if (pRunLoader) {
149
150 // get the TPC loader
151 fpLoader=pRunLoader->GetLoader(fLoaderType.Data());
152 if (fpLoader) {
153 // prepare the loader
154 fpLoader->LoadDigits("read");
155
156 // scan trough all events and estimate the size of the digits
157 for (int i=0; i<pRunLoader->GetNumberOfEvents(); i++) {
158 pRunLoader->GetEvent(i);
159 TTree* pTree=GetTree();
160 if (pTree) {
161 int size=EstimateObjectSize(pTree);
162 if (size>fMaxSize) fMaxSize=size;
163 if (fVerbose) {
164 AliInfoStream() << "event " << i << " "
165 << fTreeType <<" size " << size
166 << " count " << pTree->GetEntries() << endl;
167 }
168 } else {
169 AliWarningStream() << "no " << fTreeType << " tree for event " << i << endl;
170 }
171 }
172 } else {
173 AliErrorStream() << "can not get loader of type " << fLoaderType << endl;
174 iResult=-EFAULT;
175 }
176 } else {
177 AliErrorStream() << "can not get runLoader" << endl;
178 iResult=-EFAULT;
179 }
180 return iResult;
181}
182
183int AliHLTLoaderPublisherComponent::DoDeinit()
184{
185 // see header file for class documentation
186 int iResult=0;
187 if (fpLoader) {
188 fpLoader->UnloadDigits();
189 }
190 fpLoader=NULL;
191 return iResult;
192}
193
194int AliHLTLoaderPublisherComponent::GetEvent(const AliHLTComponentEventData& evtData,
195 AliHLTComponentTriggerData& trigData)
196{
197 // see header file for class documentation
198 int iResult=0;
199 // fetch runLoader instance from interface
200 AliRunLoader* pRunLoader=GetRunLoader();
201 if (pRunLoader && fpLoader) {
202 pRunLoader->GetEvent(GetEventCount());
203 TTree* pTree=GetTree();
204 if (pTree) {
205 PushBack(pTree, fDataType);
206 } else {
207 AliWarningStream() << "no " << fTreeType << " tree for event " << GetEventCount() << endl;
208 }
209 } else {
210 AliErrorStream() << "component not initialized" << endl;
211 }
212 return iResult;
213}
214
215TTree* AliHLTLoaderPublisherComponent::GetTree()
216{
217 TTree* pTree=NULL;
218 if (fpLoader) {
219 if (fTreeType.CompareTo("digits")==0)
220 pTree=fpLoader->TreeD();
221 else if (fTreeType.CompareTo("clusters")==0) {
222 pTree=fpLoader->TreeR();
223 }
224 } else {
225 }
226 return pTree;
227}