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 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
31 #include "AliHLTTPCDigitPublisherComponent.h"
32 #include "AliRunLoader.h"
35 #include "AliHLTTPCDigitData.h"
36 #include "AliHLTTPCDefinitions.h"
37 #include "AliHLTTPCFileHandler.h"
39 /** ROOT macro for the implementation of ROOT specific class methods */
40 ClassImp(AliHLTTPCDigitPublisherComponent)
42 AliHLTTPCDigitPublisherComponent::AliHLTTPCDigitPublisherComponent()
44 fMaxSize(200000), // just a number to start with
48 // see header file for class documentation
50 // refer to README to build package
52 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55 AliHLTTPCFileHandler* AliHLTTPCDigitPublisherComponent::fgpFileHandler=NULL;
56 int AliHLTTPCDigitPublisherComponent::fgFileHandlerInstances=0;
57 int AliHLTTPCDigitPublisherComponent::fgCurrEvent=-1;
59 AliHLTTPCDigitPublisherComponent::~AliHLTTPCDigitPublisherComponent()
61 // see header file for class documentation
62 if (fgpFileHandler!=NULL && fgFileHandlerInstances<=0) {
63 HLTWarning("improper state, de-initialization missing");
68 const char* AliHLTTPCDigitPublisherComponent::GetComponentID()
70 // see header file for class documentation
71 return "TPCDigitPublisher";
74 AliHLTComponentDataType AliHLTTPCDigitPublisherComponent::GetOutputDataType()
76 return AliHLTTPCDefinitions::fgkUnpackedRawDataType;
79 void AliHLTTPCDigitPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
85 AliHLTComponent* AliHLTTPCDigitPublisherComponent::Spawn()
87 // see header file for class documentation
88 return new AliHLTTPCDigitPublisherComponent;
91 int AliHLTTPCDigitPublisherComponent::DoInit( int argc, const char** argv )
93 // see header file for class documentation
99 for (int i=0; i<argc && iResult>=0; i++) {
101 if (argument.IsNull()) continue;
104 if (argument.CompareTo("-slice")==0) {
105 if ((bMissingParam=(++i>=argc))) break;
106 TString parameter(argv[i]);
107 parameter.Remove(TString::kLeading, ' '); // remove all blanks
108 if (parameter.IsDigit()) {
109 fMinSlice=parameter.Atoi();
111 HLTError("wrong parameter for argument %s, number expected", argument.Data());
115 } else if (argument.CompareTo("-partition")==0) {
116 if ((bMissingParam=(++i>=argc))) break;
117 TString parameter(argv[i]);
118 parameter.Remove(TString::kLeading, ' '); // remove all blanks
119 if (parameter.IsDigit()) {
120 fMinPart=parameter.Atoi();
122 HLTError("wrong parameter for argument %s, number expected", argument.Data());
126 HLTError("unknown argument %s", argument.Data());
131 HLTError("missing parameter for argument %s", argument.Data());
136 HLTError("slice no required");
141 HLTError("partition (patch) no required");
145 if (iResult<0) return iResult;
147 // fetch runLoader instance from interface
148 AliRunLoader* pRunLoader=GetRunLoader();
150 if (fgpFileHandler==NULL) {
151 fgpFileHandler=new AliHLTTPCFileHandler;
153 fgFileHandlerInstances=1;
155 fgFileHandlerInstances++;
156 //HLTDebug("publisher %p: %d references to file handler instance", this, fgFileHandlerInstances);
158 if (fgpFileHandler) {
159 if (!fgpFileHandler->SetAliInput(pRunLoader)) {
163 AliErrorStream() << "can not allocate file handler object" << endl;
167 AliErrorStream() << "can not get runLoader" << endl;
173 int AliHLTTPCDigitPublisherComponent::DoDeinit()
175 // see header file for class documentation
177 if (fgCurrEvent>=0) {
178 fgpFileHandler->FreeDigitsTree();
181 //HLTDebug("publisher %p: %d references to file handler instance", this, fgFileHandlerInstances);
182 if (--fgFileHandlerInstances==0 && fgpFileHandler!=NULL) {
184 if (fgpFileHandler) {
185 delete fgpFileHandler;
189 HLTFatal("exeption during object cleanup");
197 int AliHLTTPCDigitPublisherComponent::GetEvent(const AliHLTComponentEventData& /*evtData*/,
198 AliHLTComponentTriggerData& /*trigData*/,
199 AliHLTUInt8_t* outputPtr,
200 AliHLTUInt32_t& osize,
201 vector<AliHLTComponentBlockData>& outputBlocks)
203 // see header file for class documentation
205 AliHLTUInt32_t capacity=osize;
208 // process data events only
209 if (!IsDataEvent()) return 0;
211 if (outputPtr==NULL || capacity==0) {
212 HLTError("no target buffer provided");
216 if (fgpFileHandler) {
217 int event=GetEventCount();
218 AliHLTTPCUnpackedRawData* pTgt=reinterpret_cast<AliHLTTPCUnpackedRawData*>(outputPtr);
221 UInt_t tgtSize=capacity-sizeof(AliHLTTPCUnpackedRawData);
222 if (fgCurrEvent>=0 && fgCurrEvent!=event) {
223 HLTDebug("new event %d, free digit tree for event %d", event, fgCurrEvent);
224 fgpFileHandler->FreeDigitsTree();
227 HLTDebug("converting digits for slice %d partition %d", fMinSlice, fMinPart);
228 fgpFileHandler->Init(fMinSlice,fMinPart);
229 AliHLTTPCDigitRowData* pData=fgpFileHandler->AliDigits2Memory(nrow, event, reinterpret_cast<Byte_t*>(pTgt->fDigits), &tgtSize);
230 if (pData==NULL && tgtSize>0 && tgtSize>fMaxSize) {
231 HLTDebug("target buffer too small: %d byte required, %d available", tgtSize+sizeof(AliHLTTPCUnpackedRawData), capacity);
232 // indicate insufficient buffer size, on occasion the frameworks calls
233 // again with the corrected buffer
236 } else if (pData!=pTgt->fDigits) {
237 HLTError("can not read directly into output buffer");
239 catch (...) {/* no action */}
242 osize=tgtSize+sizeof(AliHLTTPCUnpackedRawData);
243 AliHLTComponentBlockData bd;
247 bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification(fMinSlice, fMinSlice, fMinPart, fMinPart);
248 outputBlocks.push_back( bd );
249 HLTDebug("added AliHLTTPCUnpackedRawData size %d, first row %d nof digits %d", osize, pTgt->fDigits->fRow, pTgt->fDigits->fNDigit);
253 AliErrorStream() << "component not initialized" << endl;