]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTOUT.cxx
66cd4fd2ab8d359937e97b3e3044d8b191a01609
[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 "AliHLTOUT.h"
32
33 /** ROOT macro for the implementation of ROOT specific class methods */
34 ClassImp(AliHLTOUT)
35
36 AliHLTOUT::AliHLTOUT()
37   :
38   fSearchDataType(kAliHLTVoidDataType),
39   fSearchSpecification(kAliHLTVoidDataSpec),
40   fFlags(0),
41   fBlockDescList(),
42   fCurrent(fBlockDescList.begin()),
43   fpBuffer(NULL)
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 // definitions from ALICE internal note ALICE-INT-2002-010
53 const unsigned char AliHLTOUT::fgkCDHStatusWord=4;
54 const unsigned char AliHLTOUT::fgkCDHStatusFlagsOffset=12;
55
56 // definitions from ALICE internal note ALICE-INT-2006-XXX
57 const unsigned char AliHLTOUT::fgkCDHFlagsHLTDecision=6;
58 const unsigned char AliHLTOUT::fgkCDHFlagsHLTPayload=7;
59
60 AliHLTOUT::~AliHLTOUT()
61 {
62   // see header file for class documentation
63 }
64
65 int AliHLTOUT::GetNofDataBlocks()
66 {
67   // see header file for class documentation
68   return fBlockDescList.size();
69 }
70
71 int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec)
72 {
73   // see header file for class documentation
74   if (CheckStatusFlag(kLocked)) return -EPERM;
75   fCurrent=fBlockDescList.begin();
76   fSearchDataType=dt;
77   fSearchSpecification=spec;
78   return FindAndSelectDataBlock();
79 }
80
81 int AliHLTOUT::SelectNextDataBlock()
82 {
83   // see header file for class documentation
84   if (CheckStatusFlag(kLocked)) return -EPERM;
85   fCurrent++;
86   return FindAndSelectDataBlock();
87 }
88
89 int AliHLTOUT::FindAndSelectDataBlock()
90 {
91   // see header file for class documentation
92   if (CheckStatusFlag(kLocked)) return -EPERM;
93   int iResult=-ENOENT;
94   while (fCurrent!=fBlockDescList.end() && iResult==-ENOENT) {
95     if ((fSearchDataType==kAliHLTAnyDataType || (*fCurrent)==fSearchDataType) &&
96         fSearchSpecification==kAliHLTVoidDataSpec || (*fCurrent)==fSearchSpecification) {
97       iResult=0;
98       // TODO: check the byte order on the current system and the byte order of the
99       // data block, print warning when missmatch and user did not check
100       //AliHLTOUTByteOrder_t blockBO=CheckByteOrder();
101       /*
102         if (blockBO!=fByteOrder) {
103         SetStatusFlag(kByteOrderWarning);
104
105         }
106        */
107       ClearStatusFlag(kByteOrderChecked);
108
109       // TODO: check the alignment on the current system and the alignment of the
110       // data block, print warning when missmatch and user did not check
111       ClearStatusFlag(kAlignmentChecked);
112     }
113     fCurrent++;
114   }
115   return iResult;
116 }
117
118 int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec)
119 {
120   // see header file for class documentation
121   int iResult=-ENOENT;
122   if (fCurrent!=fBlockDescList.end()) {
123     iResult=0;
124     dt=(*fCurrent);
125     spec=(*fCurrent);
126   }
127   return iResult;
128 }
129
130 int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
131 {
132   // see header file for class documentation
133   int iResult=-ENOENT;
134   pBuffer=NULL;
135   size=0;
136   if (fCurrent!=fBlockDescList.end()) {
137     if ((iResult=GetDataBuffer((*fCurrent).GetIndex(), pBuffer, size))>=0) {
138       fpBuffer=pBuffer;
139     }
140   }
141   return iResult;  
142 }
143
144 int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
145 {
146   // see header file for class documentation
147   int iResult=0;
148   if (pBuffer==fpBuffer) {
149     fpBuffer=NULL;
150   } else {
151     HLTWarning("buffer %p does not match the provided one %p", pBuffer, fpBuffer);
152   }
153   return iResult;  
154 }
155
156 int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
157 {
158   // see header file for class documentation
159   if (!CheckStatusFlag(kCollecting)) return -EPERM;
160   int iResult=0;
161   fBlockDescList.push_back(desc);
162   return iResult;  
163 }
164
165 AliHLTOUT::AliHLTOUTByteOrder_t AliHLTOUT::CheckByteOrder()
166 {
167   if (fCurrent!=fBlockDescList.end()) {
168     SetStatusFlag(kByteOrderChecked);
169     AliHLTOUT::AliHLTOUTByteOrder_t order=CheckBlockByteOrder((*fCurrent).GetIndex());
170     return order;
171   }
172   return kInvalidByteOrder;
173 }
174
175 int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType_t type)
176 {
177   if (fCurrent!=fBlockDescList.end()) {
178     SetStatusFlag(kAlignmentChecked);
179     int alignment=CheckBlockAlignment((*fCurrent).GetIndex(), type);
180     return alignment;
181   }
182   return -ENOENT;
183 }