]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/offline/AliHLTTPCDigitPublisherComponent.cxx
HLT TPC Conformal mapping tracker running in AliRoot
[u/mrichter/AliRoot.git] / HLT / TPCLib / offline / AliHLTTPCDigitPublisherComponent.cxx
1 // @(#) $Id$
2
3 /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        * 
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   AliHLTTPCDigitPublisherComponent.cxx
20     @author Matthias Richter
21     @date   
22     @brief  TPC digit publisher component (input from offline).
23 */
24
25 #include "AliHLTTPCDigitPublisherComponent.h"
26 #include "AliRunLoader.h"
27 #include "AliLog.h"
28 #include "TTree.h"
29 #include "AliHLTTPCDigitData.h"
30 #include "AliHLTTPCDefinitions.h"
31 #include "AliHLTTPCFileHandler.h"
32
33 /** global instance for agent registration */
34 AliHLTTPCDigitPublisherComponent gAliHLTTPCDigitPublisherComponent;
35
36 /** ROOT macro for the implementation of ROOT specific class methods */
37 ClassImp(AliHLTTPCDigitPublisherComponent)
38
39 AliHLTTPCDigitPublisherComponent::AliHLTTPCDigitPublisherComponent()
40   :
41   fMaxSize(200000), // just a number to start with
42   fMinSlice(-1),
43   fMinPart(-1)
44 {
45   // see header file for class documentation
46   // or
47   // refer to README to build package
48   // or
49   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
50 }
51
52 AliHLTTPCFileHandler* AliHLTTPCDigitPublisherComponent::fpFileHandler=NULL;
53 int AliHLTTPCDigitPublisherComponent::fFileHandlerInstances=0;
54 int AliHLTTPCDigitPublisherComponent::fCurrEvent=-1;
55
56 AliHLTTPCDigitPublisherComponent::~AliHLTTPCDigitPublisherComponent()
57 {
58   // see header file for class documentation
59   if (fpFileHandler!=NULL && fFileHandlerInstances<=0) {
60     HLTWarning("improper state, de-initialization missing");
61     DoDeinit();
62   }
63 }
64
65 const char* AliHLTTPCDigitPublisherComponent::GetComponentID()
66 {
67   // see header file for class documentation
68   return "TPCDigitPublisher";
69 }
70
71 AliHLTComponentDataType AliHLTTPCDigitPublisherComponent::GetOutputDataType()
72 {
73   return AliHLTTPCDefinitions::fgkUnpackedRawDataType;
74 }
75
76 void AliHLTTPCDigitPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
77 {
78   constBase=fMaxSize;
79   inputMultiplier=1;
80 }
81
82 AliHLTComponent* AliHLTTPCDigitPublisherComponent::Spawn()
83 {
84   // see header file for class documentation
85   return new AliHLTTPCDigitPublisherComponent;
86 }
87
88 int AliHLTTPCDigitPublisherComponent::DoInit( int argc, const char** argv )
89 {
90   // see header file for class documentation
91   int iResult=0;
92
93   // scan arguments
94   TString argument="";
95   int bMissingParam=0;
96   for (int i=0; i<argc && iResult>=0; i++) {
97     argument=argv[i];
98     if (argument.IsNull()) continue;
99
100     // -slice
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();
107       } else {
108         HLTError("wrong parameter for argument %s, number expected", argument.Data());
109         iResult=-EINVAL;
110       }
111       // -partition
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();
118       } else {
119         HLTError("wrong parameter for argument %s, number expected", argument.Data());
120         iResult=-EINVAL;
121       }
122     } else {
123       HLTError("unknown argument %s", argument.Data());
124       iResult=-EINVAL;
125     }
126   }
127   if (bMissingParam) {
128     HLTError("missing parameter for argument %s", argument.Data());
129     iResult=-EINVAL;
130   }
131
132   if (fMinSlice<0) {
133     HLTError("slice no required");
134     iResult=-EINVAL;
135   }
136
137   if (fMinPart<0) {
138     HLTError("partition (patch) no required");
139     iResult=-EINVAL;
140   }
141
142   if (iResult<0) return iResult;
143
144   // fetch runLoader instance from interface
145   AliRunLoader* pRunLoader=GetRunLoader();
146   if (pRunLoader) {
147     if (fpFileHandler==NULL) {
148       fpFileHandler=new AliHLTTPCFileHandler;
149       fCurrEvent=-1;
150       fFileHandlerInstances=1;
151     } else {
152       fFileHandlerInstances++;
153       //HLTDebug("publisher %p: %d references to file handler instance", this, fFileHandlerInstances);
154     }
155     if (fpFileHandler) {
156       if (!fpFileHandler->SetAliInput(pRunLoader)) {
157         iResult=-EFAULT;
158       }
159     } else {
160       AliErrorStream() << "can not allocate file handler object" << endl;
161       iResult=-ENOMEM;
162     }
163   } else {
164     AliErrorStream() << "can not get runLoader" << endl;
165     iResult=-EFAULT;
166   }
167   return iResult;
168 }
169
170 int AliHLTTPCDigitPublisherComponent::DoDeinit()
171 {
172   // see header file for class documentation
173   int iResult=0;
174   if (fCurrEvent>=0) {
175     fpFileHandler->FreeDigitsTree();
176     fCurrEvent=-1;
177   }
178   //HLTDebug("publisher %p: %d references to file handler instance", this, fFileHandlerInstances);
179   if (--fFileHandlerInstances==0 && fpFileHandler!=NULL) {
180     try {
181       if (fpFileHandler) {
182         delete fpFileHandler;
183       }
184     }
185     catch (...) {
186       HLTFatal("exeption during object cleanup");
187       iResult=-EFAULT;
188     }
189     fpFileHandler=NULL;
190   }
191   return iResult;
192 }
193
194 int AliHLTTPCDigitPublisherComponent::GetEvent(const AliHLTComponentEventData& evtData,
195                                                AliHLTComponentTriggerData& trigData,
196                                                AliHLTUInt8_t* outputPtr, 
197                                                AliHLTUInt32_t& size,
198                                                vector<AliHLTComponentBlockData>& outputBlocks)
199 {
200   // see header file for class documentation
201   int iResult=0;
202   if (outputPtr==NULL || size==0) {
203     HLTError("no target buffer provided");
204     return -EFAULT;
205   }
206
207   if (fpFileHandler) {
208     int event=GetEventCount();
209     AliHLTTPCUnpackedRawData* pTgt=reinterpret_cast<AliHLTTPCUnpackedRawData*>(outputPtr);
210     if (pTgt) {
211       UInt_t nrow=0;
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();
216       }
217       fCurrEvent=event;
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 
225         fMaxSize=tgtSize;
226         iResult=-ENOSPC;
227       } else if (pData!=pTgt->fDigits) {
228         HLTError("can not read directly into output buffer");
229         try {delete pData;}
230         catch (...) {/* no action */}
231         iResult=-EIO;
232       } else {
233         size=tgtSize+sizeof(AliHLTTPCUnpackedRawData);
234         AliHLTComponentBlockData bd;
235         FillBlockData( bd );
236         bd.fOffset = 0;
237         bd.fSize = size;
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);
241       }
242     }
243   } else {
244     AliErrorStream() << "component not initialized" << endl;
245     iResult=-EFAULT;
246   }
247   return iResult;
248 }