3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
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 AliHLTTPCDigitPublisherComponent.cxx
20 @author Matthias Richter
22 @brief TPC digit publisher component (input from offline).
25 #include "AliHLTTPCDigitPublisherComponent.h"
26 #include "AliRunLoader.h"
29 #include "AliHLTTPCDigitData.h"
30 #include "AliHLTTPCDefinitions.h"
31 #include "AliHLTTPCFileHandler.h"
33 /** global instance for agent registration */
34 AliHLTTPCDigitPublisherComponent gAliHLTTPCDigitPublisherComponent;
36 /** ROOT macro for the implementation of ROOT specific class methods */
37 ClassImp(AliHLTTPCDigitPublisherComponent)
39 AliHLTTPCDigitPublisherComponent::AliHLTTPCDigitPublisherComponent()
41 fMaxSize(200000), // just a number to start with
45 // see header file for class documentation
47 // refer to README to build package
49 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
52 AliHLTTPCFileHandler* AliHLTTPCDigitPublisherComponent::fpFileHandler=NULL;
53 int AliHLTTPCDigitPublisherComponent::fFileHandlerInstances=0;
54 int AliHLTTPCDigitPublisherComponent::fCurrEvent=-1;
56 AliHLTTPCDigitPublisherComponent::~AliHLTTPCDigitPublisherComponent()
58 // see header file for class documentation
59 if (fpFileHandler!=NULL && fFileHandlerInstances<=0) {
60 HLTWarning("improper state, de-initialization missing");
65 const char* AliHLTTPCDigitPublisherComponent::GetComponentID()
67 // see header file for class documentation
68 return "TPCDigitPublisher";
71 AliHLTComponentDataType AliHLTTPCDigitPublisherComponent::GetOutputDataType()
73 return AliHLTTPCDefinitions::fgkUnpackedRawDataType;
76 void AliHLTTPCDigitPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
82 AliHLTComponent* AliHLTTPCDigitPublisherComponent::Spawn()
84 // see header file for class documentation
85 return new AliHLTTPCDigitPublisherComponent;
88 int AliHLTTPCDigitPublisherComponent::DoInit( int argc, const char** argv )
90 // see header file for class documentation
96 for (int i=0; i<argc && iResult>=0; i++) {
98 if (argument.IsNull()) continue;
101 if (argument.CompareTo("-slice")==0) {
102 if ((bMissingParam=(++i>=argc))) break;
103 TString parameter(argv[i]);
104 parameter.Remove(TString::kLeading, ' '); // remove all blanks
105 if (parameter.IsDigit()) {
106 fMinSlice=parameter.Atoi();
108 HLTError("wrong parameter for argument %s, number expected", argument.Data());
112 } else if (argument.CompareTo("-partition")==0) {
113 if ((bMissingParam=(++i>=argc))) break;
114 TString parameter(argv[i]);
115 parameter.Remove(TString::kLeading, ' '); // remove all blanks
116 if (parameter.IsDigit()) {
117 fMinPart=parameter.Atoi();
119 HLTError("wrong parameter for argument %s, number expected", argument.Data());
123 HLTError("unknown argument %s", argument.Data());
128 HLTError("missing parameter for argument %s", argument.Data());
133 HLTError("slice no required");
138 HLTError("partition (patch) no required");
142 if (iResult<0) return iResult;
144 // fetch runLoader instance from interface
145 AliRunLoader* pRunLoader=GetRunLoader();
147 if (fpFileHandler==NULL) {
148 fpFileHandler=new AliHLTTPCFileHandler;
150 fFileHandlerInstances=1;
152 fFileHandlerInstances++;
153 //HLTDebug("publisher %p: %d references to file handler instance", this, fFileHandlerInstances);
156 if (!fpFileHandler->SetAliInput(pRunLoader)) {
160 AliErrorStream() << "can not allocate file handler object" << endl;
164 AliErrorStream() << "can not get runLoader" << endl;
170 int AliHLTTPCDigitPublisherComponent::DoDeinit()
172 // see header file for class documentation
175 fpFileHandler->FreeDigitsTree();
178 //HLTDebug("publisher %p: %d references to file handler instance", this, fFileHandlerInstances);
179 if (--fFileHandlerInstances==0 && fpFileHandler!=NULL) {
182 delete fpFileHandler;
186 HLTFatal("exeption during object cleanup");
194 int AliHLTTPCDigitPublisherComponent::GetEvent(const AliHLTComponentEventData& evtData,
195 AliHLTComponentTriggerData& trigData,
196 AliHLTUInt8_t* outputPtr,
197 AliHLTUInt32_t& size,
198 vector<AliHLTComponentBlockData>& outputBlocks)
200 // see header file for class documentation
202 if (outputPtr==NULL || size==0) {
203 HLTError("no target buffer provided");
208 int event=GetEventCount();
209 AliHLTTPCUnpackedRawData* pTgt=reinterpret_cast<AliHLTTPCUnpackedRawData*>(outputPtr);
212 UInt_t tgtSize=size-sizeof(AliHLTTPCUnpackedRawData);
213 if (fCurrEvent>=0 && fCurrEvent!=event) {
214 HLTDebug("new event %d, free digit tree for event %d", event, fCurrEvent);
215 fpFileHandler->FreeDigitsTree();
218 HLTDebug("converting digits for slice %d partition %d", fMinSlice, fMinPart);
219 fpFileHandler->Init(fMinSlice,fMinPart);
220 AliHLTTPCDigitRowData* pData=fpFileHandler->AliDigits2Memory(nrow, event, reinterpret_cast<Byte_t*>(pTgt->fDigits), &tgtSize);
221 if (pData==NULL && tgtSize>0 && tgtSize>fMaxSize) {
222 HLTDebug("target buffer too small: %d byte required, %d available", tgtSize+sizeof(AliHLTTPCUnpackedRawData), size);
223 // indicate insufficient buffer size, on occasion the frameworks calls
224 // again with the corrected buffer
227 } else if (pData!=pTgt->fDigits) {
228 HLTError("can not read directly into output buffer");
230 catch (...) {/* no action */}
233 size=tgtSize+sizeof(AliHLTTPCUnpackedRawData);
234 AliHLTComponentBlockData bd;
238 bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification(fMinSlice, fMinSlice, fMinPart, fMinPart);
239 outputBlocks.push_back( bd );
240 HLTDebug("added AliHLTTPCUnpackedRawData size %d, first row %d nof digits %d", size, pTgt->fDigits->fRow, pTgt->fDigits->fNDigit);
244 AliErrorStream() << "component not initialized" << endl;