]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/test/testAliHLTBlockDataCollection.C
Adding the new detector MFT (Antonio Uras)
[u/mrichter/AliRoot.git] / HLT / BASE / test / testAliHLTBlockDataCollection.C
CommitLineData
4b31e06b 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 testAliHLTBlockDataCollection.C
20 @author Matthias Richter
21 @date
22 @brief Test macro/program for the AliHLTBlockDataCollection
23 */
24
25#ifndef __CINT__
26#include <ostream>
27#include <vector>
28#include "AliHLTBlockDataCollection.h"
29#include "AliHLTComponent.h"
30#else
31#define EINVAL 22
32#define EPROTO 71
33#endif //__CINT__
34
35typedef struct init_t {
36 const char* arguments;
37 int result;
38} init_t;
39
40typedef struct select_t {
41 const char* id;
42 const char* origin;
43 UInt_t specification;
44 int result;
45} select_t;
46
47init_t gInits[]={
48 {"-datatype 'ESD_TREE' 'TPC ' ", 3},
49 {"-datatype 'ESD_TREE' 'TPC ' "
50 "-origin PHOS "
51 "-verbosity "
52 "-origin 'TRD ' "
53 "-dataspec 0xdeadbeef ", 9},
54 {"-datatype 'ESD_TREE'", -EPROTO},
55 {NULL, 0}
56};
57
58select_t gSelections[]={
59 {"ESD_TREE", "TPC ", 0, 1},
60 {"DDL_RAW ", "TPC ", 0xaffe, 0},
61 {"ESD_TREE", "TRD ", 0xaffe, 0},
62 {"ESD_TREE", "TRD ", 0xdeadbeef, 1},
63 {NULL, NULL, 0, 0}
64};
65
66int gVerbosity=0;
67
68int InitCollection(AliHLTBlockDataCollection& collection, const char* init)
69{
70 // build argument vector
71 int iResult=0;
72 char* arguments=new char[strlen(init)+1];
73 strcpy(arguments, init);
74 vector<int> positions;
75 bool bQuote=false;
76 int i=0;
77 int iStart=0;
78 for (;arguments[i]!=0; i++) {
79 if (arguments[i]=='\'') {
f0b885ac 80 if ((bQuote=(!bQuote))) {
4b31e06b 81 // opening quote, set start
82 } else {
83 // closing quote, add argument
84 arguments[i]=0;
85 if (i-iStart>0) positions.push_back(iStart);
86 }
87 iStart=i+1;
88 } else if ((arguments[i]==' ' && !bQuote) ||
89 arguments[i]==0) {
90 arguments[i]=0;
91 if (i-iStart>0) positions.push_back(iStart);
92 iStart=i+1;
93 }
94 }
95 if (i-iStart>0) positions.push_back(iStart);
96
97 int argc=positions.size();
98 const char** argv=new const char*[argc];
99 for (int j=0; j<argc ; j++) {
100 argv[j]=&arguments[positions[j]];
101 }
102
103 // test argument scan
104 for (i=0; i<argc; i++) {
105 if (gVerbosity>1) cout << "scanning " << argc-i << " arguments: " << argv[i] << endl;
106 int result=collection.ScanArgument(argc-i, &argv[i]);
107 if (result>0) {
108 iResult+=result;
109 i+=result-1;
110 } else if (result<0) {
111 iResult=result;
112 break;
113 }
114 }
115
116 // cleanup
117 delete [] argv;
118 delete [] arguments;
119
120 return iResult;
121}
122
123int testAliHLTBlockDataCollection(int verbosity=0)
124{
125 gVerbosity=verbosity;
126 AliHLTBlockDataCollection collection;
127 for (int initNo=0; gInits[initNo].arguments!=NULL; initNo++) {
128 if (gVerbosity>0) cout << "checking: " << gInits[initNo].arguments << endl;
129 int result=InitCollection(collection, gInits[initNo].arguments);
130 if (result!=gInits[initNo].result) {
131 cerr << "failed: " << initNo << " (" << gInits[initNo].arguments << ") " << ": result " << result << ", expected " << gInits[initNo].result << endl;
132 return -1;
133 } else {
134 if (gVerbosity>1) cout << "init " << initNo << " (" << gInits[initNo].arguments << ") " << "succeeded: result " << result << endl;
135 }
136 }
137
138 AliHLTComponentBlockData bd;
139 AliHLTComponent::FillBlockData(bd);
140
141 for (int selectNo=0; gSelections[selectNo].id!=NULL; selectNo++) {
142 AliHLTComponent::SetDataType(bd.fDataType, gSelections[selectNo].id, gSelections[selectNo].origin );
143 bd.fSpecification=gSelections[selectNo].specification;
144 int result=collection.IsSelected(bd);
145 if (result!=gSelections[selectNo].result) {
146 cerr << "failed: block " << gSelections[selectNo].id << ":" << gSelections[selectNo].origin << " 0x" << hex << gSelections[selectNo].specification << ": result " << result << ", expected " << gSelections[selectNo].result << endl;
147 return -1;
148 } else {
149 if (gVerbosity>0) cout << "checking: block " << gSelections[selectNo].id << ":" << gSelections[selectNo].origin << " 0x" << hex << gSelections[selectNo].specification << (result==1?" selected":" not selected") << " (correctly)" << endl;
150 }
151 }
152
153 return 0;
154}
155
156int main(int /*argc*/, const char** /*argv*/)
157{
158 int iResult=0;
159 if ((iResult=testAliHLTBlockDataCollection(1))<0) {
160 cerr << "<<<<< re-run with higher verbosity >>>>>>>" << endl;
161 testAliHLTBlockDataCollection(2);
162 }
163 return iResult;
164}