]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTOUT.cxx
coding conventions and compilation warnings
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTOUT.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   AliHLTOUT.cxx
20     @author Matthias Richter
21     @date   
22     @brief  The control class for HLTOUT data.                            */
23
24 // see header file for class documentation
25 // or
26 // refer to README to build package
27 // or
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
29
30 #include <cerrno>
31 #include <cassert>
32 #include "AliHLTOUT.h"
33
34 /** ROOT macro for the implementation of ROOT specific class methods */
35 ClassImp(AliHLTOUT)
36
37 AliHLTOUT::AliHLTOUT()
38   :
39   fSearchDataType(kAliHLTVoidDataType),
40   fSearchSpecification(kAliHLTVoidDataSpec),
41   fFlags(0),
42   fBlockDescList(),
43   fCurrent(fBlockDescList.begin()),
44   fpBuffer(NULL),
45   fDataHandlers()
46 {
47   // see header file for class documentation
48   // or
49   // refer to README to build package
50   // or
51   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
52 }
53
54 AliHLTOUT::~AliHLTOUT()
55 {
56   // see header file for class documentation
57 }
58
59 int AliHLTOUT::Init()
60 {
61   // see header file for class documentation
62   int iResult=0;
63   SetStatusFlag(kCollecting);
64   if ((iResult=GenerateIndex())>=0) {
65     if ((iResult=InitHandlers())>=0) {
66     }
67   }
68   ClearStatusFlag(kCollecting);
69   return iResult;
70 }
71
72 int AliHLTOUT::GetNofDataBlocks()
73 {
74   // see header file for class documentation
75   return fBlockDescList.size();
76 }
77
78 int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec,
79                                     AliHLTModuleAgent::AliHLTOUTHandlerType handlerType)
80 {
81   // see header file for class documentation
82   if (CheckStatusFlag(kLocked)) return -EPERM;
83   fCurrent=fBlockDescList.begin();
84   fSearchDataType=dt;
85   fSearchSpecification=spec;
86   //fSearchHandlerType=handlerType;
87   return FindAndSelectDataBlock();
88 }
89
90 int AliHLTOUT::SelectNextDataBlock()
91 {
92   // see header file for class documentation
93   if (CheckStatusFlag(kLocked)) return -EPERM;
94   if (fCurrent==fBlockDescList.end()) return -ENOENT;
95   fCurrent++;
96   return FindAndSelectDataBlock();
97 }
98
99 int AliHLTOUT::FindAndSelectDataBlock()
100 {
101   // see header file for class documentation
102   if (CheckStatusFlag(kLocked)) return -EPERM;
103   int iResult=-ENOENT;
104   while (fCurrent!=fBlockDescList.end() && iResult==-ENOENT) {
105     if ((*fCurrent)==fSearchDataType &&
106         fSearchSpecification==kAliHLTVoidDataSpec || (*fCurrent)==fSearchSpecification &&
107         1/*fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput*/) {
108       iResult=fCurrent->GetIndex();
109       // TODO: check the byte order on the current system and the byte order of the
110       // data block, print warning when missmatch and user did not check
111       //AliHLTOUTByteOrder blockBO=CheckByteOrder();
112       CheckByteOrder();
113       /*
114         if (blockBO!=fByteOrder) {
115         SetStatusFlag(kByteOrderWarning);
116
117         }
118        */
119       ClearStatusFlag(kByteOrderChecked);
120
121       // TODO: check the alignment on the current system and the alignment of the
122       // data block, print warning when missmatch and user did not check
123       ClearStatusFlag(kAlignmentChecked);
124
125       break;
126     }
127     fCurrent++;
128   }
129   return iResult;
130 }
131
132 int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec)
133 {
134   // see header file for class documentation
135   int iResult=-ENOENT;
136   if (fCurrent!=fBlockDescList.end()) {
137     iResult=0;
138     dt=(*fCurrent);
139     spec=(*fCurrent);
140   }
141   return iResult;
142 }
143
144 AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
145 {
146   // see header file for class documentation
147   if (fCurrent==fBlockDescList.end()) return AliHLTOUTInvalidIndex;
148   return fCurrent->GetIndex();
149 }
150
151 int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
152 {
153   // see header file for class documentation
154   int iResult=-ENOENT;
155   pBuffer=NULL;
156   size=0;
157   if (fCurrent!=fBlockDescList.end()) {
158     if ((iResult=GetDataBuffer(fCurrent->GetIndex(), pBuffer, size))>=0) {
159       fpBuffer=pBuffer;
160     }
161   }
162   return iResult;  
163 }
164
165 int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
166 {
167   // see header file for class documentation
168   int iResult=0;
169   if (pBuffer==fpBuffer) {
170     fpBuffer=NULL;
171   } else {
172     HLTWarning("buffer %p does not match the provided one %p", pBuffer, fpBuffer);
173   }
174   return iResult;  
175 }
176
177 AliHLTOUTHandler* AliHLTOUT::GetHandler()
178 {
179   // see header file for class documentation
180   AliHLTOUTHandler* pHandler=NULL;
181   pHandler=FindHandlerDesc(GetDataBlockIndex());
182   return pHandler;
183 }
184
185 int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
186 {
187   // see header file for class documentation
188   if (!CheckStatusFlag(kCollecting)) return -EPERM;
189   int iResult=0;
190   fBlockDescList.push_back(desc);
191   return iResult;  
192 }
193
194 AliHLTOUT::AliHLTOUTByteOrder AliHLTOUT::CheckByteOrder()
195 {
196   // see header file for class documentation
197   if (fCurrent!=fBlockDescList.end()) {
198     SetStatusFlag(kByteOrderChecked);
199     AliHLTOUT::AliHLTOUTByteOrder order=CheckBlockByteOrder((*fCurrent).GetIndex());
200     return order;
201   }
202   return kInvalidByteOrder;
203 }
204
205 int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType type)
206 {
207   // see header file for class documentation
208   if (fCurrent!=fBlockDescList.end()) {
209     SetStatusFlag(kAlignmentChecked);
210     int alignment=CheckBlockAlignment((*fCurrent).GetIndex(), type);
211     return alignment;
212   }
213   return -ENOENT;
214 }
215
216 int AliHLTOUT::InitHandlers()
217 {
218   // see header file for class documentation
219   int iResult=0;
220   AliHLTOUTIndexList remnants;
221   for (int havedata=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); havedata>=0; havedata=SelectNextDataBlock()) {
222     remnants.push_back(GetDataBlockIndex());
223     AliHLTComponentDataType dt=kAliHLTVoidDataType;
224     AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
225     if (GetDataBlockDescription(dt, spec)<0) break;
226     for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) {
227       AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
228       if (pAgent->GetHandlerDescription(dt, spec, handlerDesc)>0) {
229         AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
230         InsertHandler(entry);
231         remnants.pop_back();
232         break;
233       }
234     }
235   }
236   if (remnants.size()>0) {
237     HLTWarning("no handlers found for %d data blocks out of %d", remnants.size(), GetNofDataBlocks());
238     AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
239     for (AliHLTOUTIndexList::iterator element=remnants.begin(); element!=remnants.end(); element++) {
240       for (int trials=0; trials<2; trials++) {
241         do {
242           // we start searching the index from the current position in the block list
243           if ((*block).GetIndex()==*element) break;
244         } while ((++block)!=fBlockDescList.end());
245         if (block==fBlockDescList.end()) {
246           // rewind and try again
247           block=fBlockDescList.begin();
248         }
249       }
250       assert(block!=fBlockDescList.end());
251       if (block!=fBlockDescList.end()) {
252         HLTDebug("   %s", AliHLTComponent::DataType2Text((AliHLTComponentDataType)*block).c_str());
253       }
254     }
255   }
256   return iResult;
257 }
258
259 int AliHLTOUT::InsertHandler(const AliHLTOUTHandlerListEntry &entry)
260 {
261   // see header file for class documentation
262   int iResult=0;
263   AliHLTOUTHandlerListEntryVector::iterator element=fDataHandlers.begin();
264   while (element!=fDataHandlers.end()) {
265     if (entry==(*element)) break;
266     element++;
267   }
268   if (element==fDataHandlers.end()) {
269     fDataHandlers.push_back(entry);
270   } else {
271     element->AddIndex(const_cast<AliHLTOUTHandlerListEntry&>(entry));
272   }
273   return iResult;
274 }
275
276 AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::FindHandlerDesc(AliHLTUInt32_t blockIndex)
277 {
278   // see header file for class documentation
279   AliHLTOUTHandlerListEntryVector::iterator element=fDataHandlers.begin();
280   while (element!=fDataHandlers.end()) {
281     if (element->HasIndex(blockIndex)) {
282       return *element;
283     }
284     element++;
285   }
286   return AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;
287 }
288
289 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry()
290   :
291   fpHandler(NULL),
292   fpHandlerDesc(NULL),
293   fpAgent(NULL),
294   fBlocks()
295 {
296   // see header file for class documentation
297 }
298
299 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler, 
300                                                                 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
301                                                                 AliHLTModuleAgent* pAgent,
302                                                                 AliHLTUInt32_t index)
303   :
304   fpHandler(pHandler),
305   fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
306   fpAgent(pAgent),
307   fBlocks()
308 {
309   // see header file for class documentation
310   *fpHandlerDesc=handlerDesc;
311   fBlocks.push_back(index);
312 }
313
314 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src)
315   :
316   fpHandler(src.fpHandler),
317   fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
318   fpAgent(src.fpAgent),
319   fBlocks()
320 {
321   // see header file for class documentation
322   *fpHandlerDesc=*src.fpHandlerDesc;
323   fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
324 }
325
326 AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry()
327 {
328   // see header file for class documentation
329   if (fpHandlerDesc) delete fpHandlerDesc;
330   fpHandlerDesc=NULL;
331 }
332
333 AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTHandlerListEntry::operator=(const AliHLTOUTHandlerListEntry& src)
334 {
335   // see header file for class documentation
336   fpHandler=src.fpHandler;
337   *fpHandlerDesc=*src.fpHandlerDesc;
338   fpAgent=src.fpAgent;
339   fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
340   return *this;
341 }
342
343 AliHLTUInt32_t AliHLTOUT::AliHLTOUTHandlerListEntry::operator[](int i) const
344 {
345   // see header file for class documentation
346   return (int)fBlocks.size()>i?fBlocks[i]:AliHLTOUTInvalidIndex;
347 }
348
349 bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTOUTHandlerListEntry& entry) const
350 {
351   // see header file for class documentation
352   if (entry.fpHandler!=fpHandler || fpHandler==NULL) return false;
353   assert(entry.fpAgent==fpAgent);
354   if (entry.fpAgent!=fpAgent) return false;
355   return true;
356 }
357
358 void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTOUT::AliHLTOUTHandlerListEntry &desc)
359 {
360   // see header file for class documentation
361   AliHLTOUTIndexList::iterator element;
362   for (element=desc.fBlocks.begin(); element!=desc.fBlocks.end(); element++) {
363     AddIndex(*element);
364   }  
365 }
366
367 void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index)
368 {
369   // see header file for class documentation
370   fBlocks.push_back(index);
371 }
372
373 bool AliHLTOUT::AliHLTOUTHandlerListEntry::HasIndex(AliHLTUInt32_t index)
374 {
375   // see header file for class documentation
376   AliHLTOUTIndexList::iterator element;
377   for (element=fBlocks.begin(); element!=fBlocks.end(); element++) {
378     if (*element==index) return true;
379   }
380   return false;
381 }
382
383 const AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;