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