3 //**************************************************************************
4 //* This file is property of and copyright by the *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /// @file AliHLTSampleRawAnalysisComponent.cxx
20 /// @author Matthias Richter
22 /// @brief A sample processing component for raw data
23 /// @ingroup alihlt_tutorial
25 #include "AliHLTSampleRawAnalysisComponent.h"
27 #include "AliRawReaderMemory.h"
29 #include "TObjString.h"
31 /////////////////////////////////////////////////////////////////////////
32 // includes files likely to be skipped in a real implementation
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
37 #include "AliHLTDAQ.h"
39 /** ROOT macro for the implementation of ROOT specific class methods */
40 ClassImp(AliHLTSampleRawAnalysisComponent)
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
49 AliHLTSampleRawAnalysisComponent gAliHLTSampleRawAnalysisComponent;
51 AliHLTSampleRawAnalysisComponent::AliHLTSampleRawAnalysisComponent()
56 // an example component which implements the ALICE HLT processor
57 // interface and does some analysis on the input raw data
59 // see header file for class documentation
61 // refer to README to build package
63 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
65 // NOTE: all helper classes should be instantiated in DoInit()
68 AliHLTSampleRawAnalysisComponent::~AliHLTSampleRawAnalysisComponent()
72 // NOTE: implement proper cleanup in DoDeinit()
75 const char* AliHLTSampleRawAnalysisComponent::GetComponentID()
77 // component property: id
78 return "SampleRawAnalysis";
81 void AliHLTSampleRawAnalysisComponent::GetInputDataTypes( AliHLTComponentDataTypeList& list)
83 // component property: list of input data types
84 list.push_back(kAliHLTDataTypeDDLRaw);
87 AliHLTComponentDataType AliHLTSampleRawAnalysisComponent::GetOutputDataType()
89 // component property: output data type
90 return kAliHLTDataTypeHistogram|kAliHLTDataOriginSample;
93 void AliHLTSampleRawAnalysisComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
95 // component property: output size estimator
100 void AliHLTSampleRawAnalysisComponent::GetOCDBObjectDescription( TMap* const targetMap)
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
108 if (!targetMap) return;
109 targetMap->Add(new TObjString("HLT/ConfigSample/SampleRawAnalysis"),
110 new TObjString("configuration object"));
113 AliHLTComponent* AliHLTSampleRawAnalysisComponent::Spawn()
115 // Spawn function, return new class instance
116 return new AliHLTSampleRawAnalysisComponent;
119 int AliHLTSampleRawAnalysisComponent::DoInit( int argc, const char** argv )
121 // see header file for class documentation
124 // init stage 1: default values for all data members
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);
136 // init stage 3: read the component arguments
138 iResult=ConfigureFromArgumentString(argc, argv);
141 // implement the component initialization
143 if (iResult<0) break;
145 fRawReader=new AliRawReaderMemory;
151 // implement further initialization
156 if (fRawReader) delete fRawReader;
163 int AliHLTSampleRawAnalysisComponent::ScanConfigurationArgument(int argc, const char** argv)
165 // Scan configuration arguments
166 // Return the number of processed arguments
167 // -EPROTO if argument format error (e.g. number expected but not found)
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.
174 TString argument=argv[i];
176 if (argument.IsNull()) return 0;
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
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
193 if (argument.CompareTo("-verbose")==0) {
195 return 1; // only keyword
201 int AliHLTSampleRawAnalysisComponent::DoDeinit()
203 // component cleanup, delete all instances of helper classes here
204 if (fRawReader) delete fRawReader;
210 int AliHLTSampleRawAnalysisComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
211 AliHLTComponentTriggerData& /*trigData*/)
213 // event processing function
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;
220 if (fVerbosity>0) AliInfoClass(Form("==================== event %3d ================================", GetEventCount()));
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
228 for (unsigned pos=0; pos<8*sizeof(AliHLTUInt32_t); pos++) {
229 if (pBlock->fSpecification & (0x1<<pos)) {
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);
244 if (ddlnum<0) continue;
245 int id=AliHLTDAQ::DdlID(AliHLTDAQ::DetectorName(pBlock->fDataType.fOrigin), ddlnum);
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);
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);
265 // now use raw reader to do some data processing
267 while (fRawReader->ReadNextData(pData)) {
268 AliInfoClass(Form("got data for equipment id %d: size %d", fRawReader->GetEquipmentId(), fRawReader->GetEquipmentSize()));
271 // clear the rawreader
272 fRawReader->ClearBuffers();
274 // publish the array of tracks as output
279 int AliHLTSampleRawAnalysisComponent::Reconfigure(const char* cdbEntry, const char* chainId)
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.
289 cdbPath="HLT/ConfigSample/";
290 cdbPath+=GetComponentID();
292 AliInfoClass(Form("reconfigure '%s' from entry %s%s", chainId, cdbPath.Data(), cdbEntry?"":" (default)"));
293 iResult=ConfigureFromCDBTObjString(cdbPath);
298 int AliHLTSampleRawAnalysisComponent::ReadPreprocessorValues(const char* modules)
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.
304 TString detectors(modules!=NULL?modules:"");
305 AliInfoClass(Form("read preprocessor values for detector(s): %s", detectors.IsNull()?"none":detectors.Data()));