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