]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/SampleLib/AliHLTSampleRawAnalysisComponent.cxx
make the update of the period level QA safe (by running in a temp location and only...
[u/mrichter/AliRoot.git] / HLT / SampleLib / AliHLTSampleRawAnalysisComponent.cxx
CommitLineData
79965b8c 1// $Id$
2
3//**************************************************************************
0cfce653 4//* This file is property of and copyright by the *
79965b8c 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 AliHLTSampleRawAnalysisComponent.cxx
20/// @author Matthias Richter
21/// @date 2010-08-29
22/// @brief A sample processing component for raw data
23/// @ingroup alihlt_tutorial
24
25#include "AliHLTSampleRawAnalysisComponent.h"
26#include "AliLog.h"
27#include "AliRawReaderMemory.h"
28#include "TMap.h"
29#include "TObjString.h"
30
31/////////////////////////////////////////////////////////////////////////
32// includes files likely to be skipped in a real implementation
33
34// AliHLTDAQ needed to get generic mapping of data origin to DDL numbers
35// not since a real component will select only blocks of the origin it
36// is made for
37#include "AliHLTDAQ.h"
38
39/** ROOT macro for the implementation of ROOT specific class methods */
40ClassImp(AliHLTSampleRawAnalysisComponent)
41
42/** one global instance used for registration of
43 * AliHLTSampleRawAnalysisComponent
44 * Note: there are two ways of component registration
45 * - via a global object
46 * - via the AliHLTModuleAgent::RegisterComponents function
47 * @see @ref alihlt_component_registration
48 */
49AliHLTSampleRawAnalysisComponent gAliHLTSampleRawAnalysisComponent;
50
51AliHLTSampleRawAnalysisComponent::AliHLTSampleRawAnalysisComponent()
52 : AliHLTProcessor()
53 , fVerbosity(0)
54 , fRawReader(NULL)
55{
56 // an example component which implements the ALICE HLT processor
57 // interface and does some analysis on the input raw data
58 //
59 // see header file for class documentation
60 // or
61 // refer to README to build package
62 // or
63 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
64 //
65 // NOTE: all helper classes should be instantiated in DoInit()
66}
67
68AliHLTSampleRawAnalysisComponent::~AliHLTSampleRawAnalysisComponent()
69{
70 // destructor
71 //
72 // NOTE: implement proper cleanup in DoDeinit()
73}
74
75const char* AliHLTSampleRawAnalysisComponent::GetComponentID()
76{
77 // component property: id
78 return "SampleRawAnalysis";
79}
80
0cfce653 81void AliHLTSampleRawAnalysisComponent::GetInputDataTypes( AliHLTComponentDataTypeList& list)
79965b8c 82{
83 // component property: list of input data types
84 list.push_back(kAliHLTDataTypeDDLRaw);
85}
86
87AliHLTComponentDataType AliHLTSampleRawAnalysisComponent::GetOutputDataType()
88{
89 // component property: output data type
90 return kAliHLTDataTypeHistogram|kAliHLTDataOriginSample;
91}
92
93void AliHLTSampleRawAnalysisComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
94{
95 // component property: output size estimator
96 constBase = 1000;
97 inputMultiplier = 0;
98}
99
100void AliHLTSampleRawAnalysisComponent::GetOCDBObjectDescription( TMap* const targetMap)
101{
102 // Get a list of OCDB object description.
103 // The list of objects is provided in a TMap
104 // - key: complete OCDB path, e.g. GRP/GRP/Data
105 // - value: short description why the object is needed
106 // Key and value objects created inside this class go into ownership of
107 // target TMap.
108 if (!targetMap) return;
109 targetMap->Add(new TObjString("HLT/ConfigSample/SampleRawAnalysis"),
110 new TObjString("configuration object"));
111}
112
113AliHLTComponent* AliHLTSampleRawAnalysisComponent::Spawn()
114{
115 // Spawn function, return new class instance
116 return new AliHLTSampleRawAnalysisComponent;
117}
118
119int AliHLTSampleRawAnalysisComponent::DoInit( int argc, const char** argv )
120{
121 // see header file for class documentation
122 int iResult=0;
123
124 // init stage 1: default values for all data members
125
126 // init stage 2: read configuration object
127 // ScanConfigurationArgument() needs to be implemented
128 // HLT component configuration objects are located in the HLT/ConfigDET
129 // of the OCDB. TObjString configuration objects can be generated with
130 // the macro HLT/exa/makeComponentConfigurationObject.C, e.g.
131 // aliroot -b -q -l $ALICE_ROOT/HLT/exa/makeComponentConfigurationObject.C'("HLT/ConfigSample/SampleRawAnalysis", "")'
132 TString cdbPath="HLT/ConfigSample/";
133 cdbPath+=GetComponentID();
134 iResult=ConfigureFromCDBTObjString(cdbPath);
135
136 // init stage 3: read the component arguments
137 if (iResult>=0) {
138 iResult=ConfigureFromArgumentString(argc, argv);
139 }
140
141 // implement the component initialization
142 do {
143 if (iResult<0) break;
144
145 fRawReader=new AliRawReaderMemory;
146 if (!fRawReader) {
147 iResult=-ENOMEM;
148 break;
149 }
150
151 // implement further initialization
152 } while (0);
153
154 if (iResult<0) {
155 // implement cleanup
156 if (fRawReader) delete fRawReader;
157 fRawReader=NULL;
158 }
159
160 return iResult;
161}
162
163int AliHLTSampleRawAnalysisComponent::ScanConfigurationArgument(int argc, const char** argv)
164{
165 // Scan configuration arguments
166 // Return the number of processed arguments
167 // -EPROTO if argument format error (e.g. number expected but not found)
168 //
169 // The AliHLTComponent base class implements a parsing loop for argument strings and
170 // arrays of strings which is invoked by ConfigureFromArgumentString/ConfigureFromCDBTObjString
171 // The component needs to implement ScanConfigurationArgument in order to decode the arguments.
172
173 int i=0;
174 TString argument=argv[i];
175
176 if (argument.IsNull()) return 0;
177
178 // -mandatory1 arg
179 if (argument.CompareTo("-mandatory1")==0) {
180 if (++i>=argc) return -EINVAL;
181 HLTInfo("got \'-mandatory1\' argument: %s", argv[i]);
182 return 2; // keyword + 1 argument
183 }
184
185 // -optional1 arg
186 if (argument.CompareTo("-optional1")==0) {
187 if (++i>=argc) return -EINVAL;
188 HLTInfo("got \'-optional1\' argument: %s", argv[i]);
189 return 2; // keyword + 1 argument
190 }
191
192 // -verbose
193 if (argument.CompareTo("-verbose")==0) {
194 fVerbosity=1;
195 return 1; // only keyword
196 }
197
198 return 0;
199}
200
201int AliHLTSampleRawAnalysisComponent::DoDeinit()
202{
203 // component cleanup, delete all instances of helper classes here
204 if (fRawReader) delete fRawReader;
205 fRawReader=NULL;
206
207 return 0;
208}
209
210int AliHLTSampleRawAnalysisComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
211 AliHLTComponentTriggerData& /*trigData*/)
212{
213 // event processing function
214 int iResult=0;
215
216 // check if this is a data event, there are a couple of special events
217 // which should be ignored for normal processing
218 if (!IsDataEvent()) return 0;
219
220 if (fVerbosity>0) AliInfoClass(Form("==================== event %3d ================================", GetEventCount()));
221
222 // loop over the raw input data blocks and set up the rawreader
223 for (const AliHLTComponentBlockData* pBlock = GetFirstInputBlock(kAliHLTDataTypeDDLRaw);
224 pBlock!=NULL && iResult>=0;
225 pBlock=GetNextInputBlock()) {
226 // extract DDL id from specification
227 int ddlnum=-1;
9faa798a 228 for (unsigned pos=0; pos<8*sizeof(AliHLTUInt32_t); pos++) {
79965b8c 229 if (pBlock->fSpecification & (0x1<<pos)) {
230 if (ddlnum>=0) {
231 // this is just an example, please avoid warnings in every event since those will
232 // seturate the logging system. Consider AliHLTErrorGuard for such cases, e.g.
233 // ALIHLTERRORGUARD(5, "nasty error, first occurence in event %d", event);
234 // this will show the error 5 times and then a summary at the end
235 HLTWarning("Can not uniquely identify DDL number from specification, skipping data block %s 0x%08x",
236 DataType2Text(pBlock->fDataType).c_str(),
237 pBlock->fSpecification);
238 ddlnum=-1;
239 break;
240 }
241 ddlnum=pos;
242 }
243 }
244 if (ddlnum<0) continue;
245 int id=AliHLTDAQ::DdlID(AliHLTDAQ::DetectorName(pBlock->fDataType.fOrigin), ddlnum);
246 if (id<0) {
247 // this is just an example, please avoid warnings in every event since those will
248 // seturate the logging system. Consider AliHLTErrorGuard for such cases, e.g.
249 // ALIHLTERRORGUARD(5, "nasty error, first occurence in event %d", event);
250 // this will show the error 5 times and then a summary at the end
251 HLTWarning("failed to get DDL id of link %d for data block %s, 0x%08x", ddlnum,
252 DataType2Text(pBlock->fDataType).c_str(),
253 pBlock->fSpecification);
254 continue;
255 }
256
257 // add data block to rawreader
258 if(!fRawReader->AddBuffer((UChar_t*) pBlock->fPtr, pBlock->fSize, id)){
259 HLTError("Could not add buffer of data block %s, 0x%08x to rawreader",
260 DataType2Text(pBlock->fDataType).c_str(),
261 pBlock->fSpecification);
262 }
263 }
264
265 // now use raw reader to do some data processing
266 UChar_t* pData=NULL;
267 while (fRawReader->ReadNextData(pData)) {
268 AliInfoClass(Form("got data for equipment id %d: size %d", fRawReader->GetEquipmentId(), fRawReader->GetEquipmentSize()));
269 }
270
271 // clear the rawreader
272 fRawReader->ClearBuffers();
273
274 // publish the array of tracks as output
275
276 return iResult;
277}
278
279int AliHLTSampleRawAnalysisComponent::Reconfigure(const char* cdbEntry, const char* chainId)
280{
281 // reconfigure the component from the specified CDB entry, or default CDB entry
282 // function is invoked by the framework if a reconfigure command was received.
283 //
284 int iResult=0;
285 TString cdbPath;
286 if (cdbEntry) {
287 cdbPath=cdbEntry;
288 } else {
289 cdbPath="HLT/ConfigSample/";
290 cdbPath+=GetComponentID();
291 }
292 AliInfoClass(Form("reconfigure '%s' from entry %s%s", chainId, cdbPath.Data(), cdbEntry?"":" (default)"));
293 iResult=ConfigureFromCDBTObjString(cdbPath);
294
295 return iResult;
296}
297
298int AliHLTSampleRawAnalysisComponent::ReadPreprocessorValues(const char* modules)
299{
300 // read the preprocessor values for the detectors in the modules list
301 // function is invoked by the framework if the pendolino indivates an update
302 // of online calibration objects, e.g temperature and pressure measurements.
303 int iResult=0;
304 TString detectors(modules!=NULL?modules:"");
305 AliInfoClass(Form("read preprocessor values for detector(s): %s", detectors.IsNull()?"none":detectors.Data()));
306 return iResult;
307}