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