]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/RCU/AliHLTAltroEncoder.h
code documantation and minor cleanup
[u/mrichter/AliRoot.git] / HLT / RCU / AliHLTAltroEncoder.h
CommitLineData
768be5c3 1//-*- Mode: C++ -*-
2// $Id$
3
4#ifndef ALIHLTALTROENCODER_H
5#define ALIHLTALTROENCODER_H
6//* This file is property of and copyright by the ALICE HLT Project *
7//* ALICE Experiment at CERN, All rights reserved. *
8//* See cxx source for full Copyright notice *
9
10/** @file AliHLTAltroEncoder.h
11 @author Matthias Richter
12 @date
13 @brief Encoder class for 10/40bit Altro Data format
14*/
15
768be5c3 16#include "AliHLTDataTypes.h"
17#include "AliHLTLogging.h"
18#include <vector>
19
20#define AliHLTUInt16MAX 0xffff
21
22/**
23 * @class AliHLTAltroEncoder
24 * Encoder of the RCU/Altro data format.
25 * The class allows to encodes data sets of channel, timebin and signal
26 * value into the 10bit/40bit Altro format. It works on a provided buffer.
27 *
297174de 28 * Signal values can be added by using the AddSignal(AliHLTUInt16_t, AliHLTUInt16_t)
29 * function. It functions works on a 'current channel'. If data is supposed to go into
30 * a new channel, SetChannel(AliHLTUInt16_t) has to be used.
31 *
32 * <pre>
33 * AliHLTAltroEncoder encoder;
34 * encoder.SetBuffer(pBuffer, size);
35 *
36 * for (channel ...) {
37 * int channelAddress=...;
38 * ...
39 * for (int bunch=0; bunch<nofBunches; bunch++) {
40 * int bunchLength=...;
41 * int startTime=...;
42 * int time=startTime;
43 * for (; time<startTime+bunchLength; time++) {
44 * iResult=encoder.AddSignal(signal, time);
45 * }
46 * }
47 *
48 * encoder.SetChannel(channelAddress);
49 * }
50 * </pre>
51 *
52 * @ingroup alihlt_rcu
768be5c3 53 */
54class AliHLTAltroEncoder : AliHLTLogging {
55 public:
56 /** default constructor */
57 AliHLTAltroEncoder();
58 /** constructor */
59 AliHLTAltroEncoder(AliHLTUInt8_t* pBuffer, int iSize);
60 /** destructor */
61 virtual ~AliHLTAltroEncoder();
62
63 /**
64 * Set the target buffer.
65 */
66 int SetBuffer(AliHLTUInt8_t* pBuffer, int iSize);
67
68 /**
69 * Add a signal value.
70 * If the timebin is a consecutive timebin, the signal is added to the
71 * current bunch. If not, the previous bunch is terminated and a new
72 * one opened.
73 *
74 * The first timebins decide whether the order is ascending or descending.
75 * @param signal 10bit signal value
76 * @param timebin 10bot time bin value
77 */
78 int AddSignal(AliHLTUInt16_t signal, AliHLTUInt16_t timebin);
79
80 /**
81 * Set and terminate the current channel.
82 *
83 * @param hwaddress Hardware address of the channel
84 */
85 int SetChannel(AliHLTUInt16_t hwaddress);
86
87 /**
88 * Add a signal value.
89 * The function is a combination of ::AddSignal and ::SetChannel.
90 * All signal of the same channel are added and if a new channel is detected,
91 * the current one is terminated and a new one created.
92 *
93 * @param signal 10bit signal value
94 * @param timebin 10bot time bin value
95 * @param hwaddress Hardware address of the channel
96 * @return number of 10bit words added
97 */
98 int AddChannelSignal(AliHLTUInt16_t signal, AliHLTUInt16_t timebin, AliHLTUInt16_t hwaddress);
99
100 /**
101 * Get total number of 40bit Altro words
102 */
103 int GetTotal40bitWords();
104
105 enum {
106 kUnknownOrder = 0,
107 kAscending,
108 kDescending
109 };
110
111 protected:
112
113 private:
114 /** copy constructor prohibited */
115 AliHLTAltroEncoder(const AliHLTAltroEncoder&);
116 /** assignment operator prohibited */
117 AliHLTAltroEncoder& operator=(const AliHLTAltroEncoder&);
118
119 /**
120 * Add 10bit value to the buffer
121 */
122 int Add10BitValue(AliHLTUInt16_t value);
123
124 /**
125 * Fill with 0x2aa paddings to reach complete 40bit word
126 */
127 int Pad40Bit();
128
129 /**
130 * Finalize the current bunch
131 */
132 int SetBunch();
133
134 /// external data buffer
135 AliHLTUInt8_t* fpBuffer; //!transient
136
137 /// size of the data buffer
138 int fBufferSize; //!transient
139
140 /// the previous time bin
141 AliHLTUInt16_t fPrevTimebin; //!transient
142
143 /// length of the current bunch
144 AliHLTUInt16_t fBunchLength; //!transient
145
146 /// start of the current channel in 10bit word count
147 AliHLTUInt16_t fChannelStart; //!transient
148
149 /// the current channel
150 AliHLTUInt16_t fChannel; //!transient
151
152 /// list of already finished channels
153 vector<AliHLTUInt16_t> fChannels; //!transient
154
155 /// current byte offset
156 int fOffset; //!transient
157
158 /// current 10bit word count
159 int f10bitWords; //!transient
160
161 /// time bin order
162 int fOrder; //!transient
163
164 ClassDef(AliHLTAltroEncoder, 0);
165};
166
167#endif