]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/test/testAliHLTTPCDefinitions.C
Update master to aliroot
[u/mrichter/AliRoot.git] / HLT / TPCLib / test / testAliHLTTPCDefinitions.C
CommitLineData
625b072f 1/**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Primary Authors: Artur Szostak <artursz@iafrica.com> *
6 * for The ALICE HLT Project. *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
17/**
18 * @file testAliHLTTPCDefinitions.C
19 * @author Artur Szostak <artursz@iafrica.com>
20 * @date 4 Aug 2010
21 *
22 * This macro is used to test the AliHLTTPCDefinitions class.
23 * Specifically the mapping encoded in the different methods.
24 */
25
26#if !defined(__CINT__) || defined(__MAKECINT__)
27#include "Riostream.h"
28#include "TClassTable.h"
29#include "TSystem.h"
30#include "AliDAQ.h"
31#include "AliHLTTPCDefinitions.h"
32#endif
33
34
35/**
36 * Routine to check that the SlicePatchToDDLId and DDLIdToSlicePatch methods work.
37 */
38bool CheckDDLToSlicePatchConversion()
39{
40 // Check the conversion from slice + patch to DDL ID.
41 Int_t minDDL = AliDAQ::DdlIDOffset("TPC");
42 Int_t maxDDL = AliDAQ::DdlIDOffset("TPC") + AliDAQ::NumberOfDdls("TPC") - 1;
43 for (AliHLTUInt16_t slice = 0; slice < 256; ++slice)
44 for (AliHLTUInt16_t patch = 0; patch < 256; ++patch)
45 {
46 Int_t ddlid = AliHLTTPCDefinitions::SlicePatchToDDLId(AliHLTUInt8_t(slice), AliHLTUInt8_t(patch));
47 if (slice < 36 && patch < 6)
48 {
49 // The slice and patch are valid so they should give a valid DDL ID.
50 if (ddlid < minDDL || maxDDL < ddlid)
51 {
52 cerr << "ERROR: AliHLTTPCDefinitions::SlicePatchToDDLId("
53 << int(slice) << ", " << int(patch) << ") returned invalid DDL ID of "
54 << ddlid << " which is outside the valid range of ["
55 << minDDL << ".." << maxDDL << "]." << endl;
56 return false;
57 }
58 }
59 else
60 {
61 // The slice or patch are not valid so the result should be -1
62 if (ddlid != -1)
63 {
64 cerr << "ERROR: AliHLTTPCDefinitions::SlicePatchToDDLId("
65 << int(slice) << ", " << int(patch) << ") returned invalid responce of "
66 << ddlid << " when is should have returned -1." << endl;
67 return false;
68 }
69 }
70 }
71
72 // Check the conversion from DDL ID to slice + patch.
73 for (AliHLTInt32_t ddlid2 = 0; ddlid2 < 8000; ++ddlid2)
74 {
75 AliHLTUInt8_t slice2 = 255;
76 AliHLTUInt8_t patch2 = 255;
77 bool result = AliHLTTPCDefinitions::DDLIdToSlicePatch(ddlid2, slice2, patch2);
78 if (minDDL <= ddlid2 && ddlid2 <= maxDDL)
79 {
80 // The DDL ID was valid so the slice and patch should also be.
81 if (result == false)
82 {
83 cerr << "ERROR: AliHLTTPCDefinitions::DDLIdToSlicePatch("
84 << ddlid2 << ") returned invalid result of 'false'."
85 << " But it should have been 'true'." << endl;
86 return false;
87 }
88 if (slice2 > 35)
89 {
90 cerr << "ERROR: AliHLTTPCDefinitions::DDLIdToSlicePatch("
91 << ddlid2 << ") returned invalid slice value of "
92 << int(slice2) << ", but the valid range is [0..35]."
93 << endl;
94 return false;
95 }
96 if (patch2 > 5)
97 {
98 cerr << "ERROR: AliHLTTPCDefinitions::DDLIdToSlicePatch("
99 << ddlid2 << ") returned invalid patch value of "
100 << int(patch2) << ", but the valid range is [0..5]."
101 << endl;
102 return false;
103 }
844b1999 104 if (AliHLTTPCDefinitions::SlicePatchToDDLId(slice2, patch2) != ddlid2)
105 {
106 cerr << "ERROR: AliHLTTPCDefinitions::DDLIdToSlicePatch("
107 << ddlid2 << ") generated a slice value of "
108 << int(slice2) << " and patch value of "
109 << int(patch2) << ", which gives a different DDL ID with the"
110 << " inverse map given by AliHLTTPCDefinitions::SlicePatchToDDLId("
111 << int(slice2) << ", " << int(patch2) << ")."
112 << endl;
113 return false;
114 }
625b072f 115 }
116 else
117 {
118 // The DDL ID was not valid so the responce should be false.
119 if (result == true)
120 {
121 cerr << "ERROR: AliHLTTPCDefinitions::DDLIdToSlicePatch("
122 << ddlid2 << ") returned invalid result of 'true'."
123 << " But it should have been 'false'." << endl;
124 return false;
125 }
126 }
127 }
128 return true;
129}
130
131/**
132 * This is the top level testing method which calls individual tests.
133 * \returns true if all tests succeeded and false otherwise.
134 */
135bool testAliHLTTPCDefinitions()
136{
137 if (gClassTable->GetID("AliHLTTPCDefinitions") < 0)
138 {
4070f709 139 gSystem->Load("libAliHLTUtil");
140 gSystem->Load("libAliHLTTPC");
625b072f 141 }
142 if (! CheckDDLToSlicePatchConversion()) return false;
143 return true;
144}
145
146#ifndef __MAKECINT__
147
148int main(int /*argc*/, const char** /*argv*/)
149{
150 bool resultOk = testAliHLTTPCDefinitions();
151 if (not resultOk) return 1;
152 return 0;
153}
154
155#endif // __MAKECINT__
156