]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/AliHLTMUONTriggerChannelsBlockStruct.cxx
Protection against zero field (Alex)
[u/mrichter/AliRoot.git] / HLT / MUON / AliHLTMUONTriggerChannelsBlockStruct.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 /**
19  * @file   AliHLTMUONTriggerChannelsBlockStruct.cxx
20  * @author Artur Szostak <artursz@iafrica.com>
21  * @date   
22  * @brief  Implementation of the stream and comparison operators.
23  */
24
25 #include "AliHLTMUONTriggerChannelsBlockStruct.h"
26 #include "AliHLTMUONUtils.h"
27 #include <cassert>
28
29 std::ostream& operator << (
30                 std::ostream& stream, const AliHLTMUONTriggerChannelStruct& channel
31         )
32 {
33         stream  << "{fTrigRecId = " << channel.fTrigRecId
34                 << ", fChamber = " << channel.fChamber
35                 << ", fSignal = " << channel.fSignal
36                 << ", fRawDataWord = " << std::showbase << std::hex
37                 << channel.fRawDataWord << std::dec << "}";
38         return stream;
39 }
40
41
42 std::ostream& operator << (
43                 std::ostream& stream,
44                 const AliHLTMUONTriggerChannelsBlockStruct& block
45         )
46 {
47         assert( AliHLTMUONUtils::IntegrityOk(block) );
48
49         const AliHLTMUONTriggerChannelStruct* channel =
50                 reinterpret_cast<const AliHLTMUONTriggerChannelStruct*>(&block + 1);
51         stream  << "{fHeader = " << block.fHeader << ", fChannel[] = [";
52         if (block.fHeader.fNrecords > 0) stream << channel[0];
53         for (AliHLTUInt32_t i = 1; i < block.fHeader.fNrecords; i++)
54                 stream << ", " << channel[i];
55         stream << "]}";
56         return stream;
57 }
58
59
60 bool operator == (
61                 const AliHLTMUONTriggerChannelsBlockStruct& a,
62                 const AliHLTMUONTriggerChannelsBlockStruct& b
63         )
64 {
65         assert( AliHLTMUONUtils::IntegrityOk(a) );
66         assert( AliHLTMUONUtils::IntegrityOk(b) );
67
68         const AliHLTMUONTriggerChannelStruct* channelA =
69                 reinterpret_cast<const AliHLTMUONTriggerChannelStruct*>(&a + 1);
70         const AliHLTMUONTriggerChannelStruct* channelB =
71                 reinterpret_cast<const AliHLTMUONTriggerChannelStruct*>(&b + 1);
72         
73         // First check if the blocks have the same header. If they do then check
74         // if every channel is the same. In either case if we find a difference
75         // return false.
76         if (a.fHeader != b.fHeader) return false;
77         for (AliHLTUInt32_t i = 0; i < a.fHeader.fNrecords; i++)
78                 if (channelA[i] != channelB[i]) return false;
79         return true;
80 }