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