16 using namespace Diana;
19 using std::stringstream;
25 #define ASSERT_EQUAL(x,y)\
29 stringstream difference;\
30 difference<<x<<" vs "<<y;\
31 Error("Test failed: file %s; line %d: %s", __FILE__ , __LINE__,difference.str().c_str());\
57 if(!isEnabled())
return;
58 Info(
"----TEST SUMMARY-----");
59 Info(
"OK: %d", fTestOK);
60 if(fTestKO >0) Error(
"KO: %d", fTestKO);
62 if(GetSequence().GetName() ==
"Test")
63 if(fTestOK !=250137 ) Panic(
"Expected test %d vs %d",250137,fTestOK);
64 if(GetSequence().GetName() ==
"TestBis") {
65 if(GetOccurrence() == 0 && fTestOK != 7758 ) Panic(
"Expected test %d vs %d",7758,fTestOK);
66 if(GetOccurrence() == 1 && fTestOK != 7619 ) Panic(
"Expected test %d vs %d",7619,fTestOK);
74 if(GetSequence().GetName() ==
"Test") {
76 fIsFirstSequence =
true;
79 fIsFirstSequence =
false;
84 fIter = GetInt(
"Iterations",1);
85 fWriteEvtNum = GetBool(
"WriteEvtNum",
false);
86 fTestGlobal = GetBool(
"TestGlobalQuantities",
false);
87 fTestEvent = GetBool(
"TestEventQuantities",
false);
88 fTestDefaults = GetBool(
"TestRunDataLoader",
false);
89 testConfigFile = GetBool(
"TestConfigFile",
false);
90 fOutputDir = GetString(
"OutputDir",
"NODEFAULT");
94 std::string testStr = GetString(
"TestString",
"DianaFramework");
95 int testInt = GetInt(
"TestInt",3);
96 double testDouble = GetDouble(
"TestDouble",3.);
97 bool testBool = GetBool(
"TestBool",
true);
98 std::vector<int> defaultVectorInt;
99 defaultVectorInt.push_back(18);
100 defaultVectorInt.push_back(22);
101 if(GetOccurrence()==0) {
102 std::vector<int> testVectorInt = GetVectorInt(
"TestVectorInt",defaultVectorInt);
113 std::vector<int> testVectorInt = GetVectorInt(
"TestVectorInt",defaultVectorInt,
false);
134 fGlobalQVector.Resize(20);
135 fGlobalQVectorC.Resize(20);
142 if(GetSequence().GetName() ==
"Test") {
149 ev.
Add<QVector>(
"TestVector");
150 ev.
Add<QVectorC>(
"TestVectorC");
153 ev.
Add<
QInt>(
"NotWrittenInt").SetWrite(
false);
176 if(fWriteEvtNum) Info(
"ReadNumber is %d, EventNumber is %d, Passed %s",
202 fEventVector.Resize(eventnum%100+1);
203 for(
size_t i = 0; i< fEventVector.Size(); i++) {
204 fEventVector[i] = (double)i;
206 fEventVectorC.SetArray((fEventVector*3.).GetConstArray(),
207 (fEventVector*4.).GetConstArray(), fEventVector.Size());
210 fEventMatrix.Resize(fEventVector.Size(),fEventVector.Size());
211 for(
size_t i = 0; i< fEventVector.Size(); i++) {
212 fEventMatrix.SetCol(i,fEventVector*i);
215 fEventMatrixC.Resize(fEventVectorC.Size(),fEventVectorC.Size());
216 for(
size_t i = 0; i< fEventVectorC.Size(); i++) {
217 fEventMatrixC.SetCol(i,fEventVectorC*i);
226 if(GetSequence().GetName() ==
"TestBis") {
243 if(fIsFirstSequence && fTestGlobal) {
245 GlobalData().Set(
"Int1",
QInt(1),
"CurrentWriter");
248 if(readnum == 1001) {
249 GlobalData().Set(
"Int2",
QInt(2),
"CurrentWriter");
251 if(readnum == 1501) {
252 GlobalData().Set(
"Int3",
QInt(3),
"CurrentWriter");
255 if(!fIsFirstSequence && fTestGlobal) {
257 int a = GlobalData().Get<
QInt>(
"Int1",
"CurrentReader");
261 if(readnum == 1001) {
262 int a = GlobalData().Get<
QInt>(
"Int2",
"CurrentReader");
265 if(readnum == 1501) {
266 int a = GlobalData().Get<
QInt>(
"Int3",
"CurrentReader");
272 if(GetIteration() == 1) {
279 ev.
Get<
QInt>(
"TestInt")=eventnum;
280 ev.
Get<
QInt>(
"TestInt2")=eventnum*2;
284 ev.
Get<
QString>(
"TestString")=
"DianaFramework";
285 ev.
Get<QVector>(
"TestVector")=fEventVector;
286 ev.
Get<QVectorC>(
"TestVectorC")=fEventVectorC;
300 ev.
Get(
"TestModule",rhandle);
301 const QVector & testVector = rhandle.
Get();
302 const QVectorC & testVectorC = evr.
Get<QVectorC>(
"TestModule",
"TestVectorC");
310 for(
size_t i = 0; i< fEventVector.Size(); i++) {
321 if(readnum == 2000 && !fIsFirstSequence && fTestGlobal) {
323 const QVector& fileVec2pp =GlobalData().Get<QVector>(
"MyGlobalVector2",
Q_CURRENT_READER);
324 const QVector& fileVec2 = fileVec2pp;
326 for(
int i = 0; i < 20; i++)
ASSERT_EQUAL(fileVec2[i], i * 3.);
330 ev.
Get(
"BaselineModule",preHandle);
331 if(fIsFirstSequence && GetIteration() == 1) {
342 if(fIsFirstSequence && fTestGlobal) {
343 if(GetIteration() == 1) {
345 for(
int i = 0; i < 20; i++)
347 fGlobalQVector[i] = i * 3.;
348 fGlobalQVectorC[i]=
QComplex(i*3.,i*3.);
351 fGlobalQMatrix.Resize(3,20);
352 fGlobalQMatrix.SetRow(0,fGlobalQVector);
353 fGlobalQMatrix.SetRow(1,fGlobalQVector*2);
354 fGlobalQMatrix.SetRow(2,fGlobalQVector*3);
355 fGlobalQMatrixC.Resize(3,20);
356 fGlobalQMatrixC.SetRow(0,fGlobalQVectorC);
357 fGlobalQMatrixC.SetRow(1,fGlobalQVectorC*2);
358 fGlobalQMatrixC.SetRow(2,fGlobalQVectorC*3);
359 GlobalData().Set(
"MyGlobalIntMemory",
QInt(3),
"");
360 GlobalData().Set(
"MyGlobalDouble",
QDouble(3.14) ,fOutputDir +
"/testglobal.root");
362 GlobalData().Set(
"MyGlobalString",
QString(
"Hi, this is Marco"),fOutputDir +
"/testglobal.root");
363 GlobalData().Set(
"MyGlobalFloat",
QDouble(6.28),fOutputDir +
"/testglobal.root");
364 GlobalData().Set(
"MyGlobalInt",
QInt(1234),fOutputDir +
"/testglobal.root");
365 GlobalData().Set(
"MyGlobalIntTxt",
QInt(1234),fOutputDir +
"/testglobal.txt");
366 GlobalData().Set(
"MyGlobalBool",
QBool(
true),fOutputDir +
"/testglobal.root");
367 GlobalData().Set(
"MyGlobalBoolTxt",
QBool(
true),fOutputDir +
"/testglobal.txt");
368 GlobalData().Set(
"MyGlobalBool2",
QBool(
false),fOutputDir +
"/testglobal.root");
369 GlobalData().Set(
"MyGlobalVector", fGlobalQVector,fOutputDir +
"/testglobal.root");
370 GlobalData().Set(
"MyGlobalVector2", fGlobalQVector,fOutputDir +
"/testglobal2.root");
371 GlobalData().Set(
"MyGlobalVector2Txt", fGlobalQVector,fOutputDir +
"/testglobal2.txt");
372 GlobalData().Set(
"MyGlobalMatrixTxt", fGlobalQMatrix,fOutputDir +
"/testglobal3.txt");
373 GlobalData().Set(
"MyGlobalVectorC", fGlobalQVectorC,fOutputDir +
"/testglobal.root");
374 GlobalData().Set(
"MyGlobalVectorC2", fGlobalQVectorC,fOutputDir +
"/testglobal2.root");
375 GlobalData().Set(
"MyGlobalVectorC2Txt", fGlobalQVectorC,fOutputDir +
"/testglobal2.txt");
384 ASSERT_EQUAL(3,GlobalData().Get<QInt>(
"MyGlobalIntMemory",
""));
392 if(fTestGlobal && !fIsFirstSequence) {
395 ASSERT_EQUAL(3.14, GlobalData().Get<QDouble>(
"MyGlobalDouble",fOutputDir +
"/testglobal.root"));
396 ASSERT_EQUAL( GlobalData().Get<QString>(
"MyGlobalString",fOutputDir +
"/testglobal.root"),
"Hi, this is Marco");
397 ASSERT_EQUAL(6.28, GlobalData().Get<QDouble>(
"MyGlobalFloat",fOutputDir +
"/testglobal.root"));
398 ASSERT_EQUAL(1234, GlobalData().Get<QInt>(
"MyGlobalInt",fOutputDir +
"/testglobal.root"));
399 GlobalHandle<QInt> gh(
"MyGlobalIntTxt");
400 GlobalData().Get(&gh,fOutputDir +
"/testglobal.txt");
405 ASSERT_EQUAL(
true, GlobalData().Get<QBool>(
"MyGlobalBool",fOutputDir +
"/testglobal.root"));
406 GlobalHandle<QBool> ghb(
"MyGlobalBoolTxt");
407 GlobalData().Get(&ghb,fOutputDir +
"/testglobal.txt");
413 ASSERT_EQUAL(
false, GlobalData().Get<QBool>(
"MyGlobalBool2",fOutputDir +
"/testglobal.root"));
414 const QVector& fileVecp = GlobalData().Get<QVector>(
"MyGlobalVector",fOutputDir +
"/testglobal.root");
416 const QVector& fileVec = fileVecp;
418 for(
int i = 0; i < 20; i++)
ASSERT_EQUAL(fileVec[i], i * 3.);
420 const QVector& fileVec2p = GlobalData().Get<QVector>(
"MyGlobalVector2",fOutputDir +
"/testglobal2.root");
421 const QVector& fileVec2 = fileVec2p;
423 for(
int i = 0; i < 20; i++)
ASSERT_EQUAL(fileVec2[i], i * 3.);
425 const QVector& fileVec2Txtp =GlobalData().Get<QVector>(
"MyGlobalVector2Txt",fOutputDir +
"/testglobal2.txt");
426 const QVector& fileVec2Txt = fileVec2Txtp;
428 for(
int i = 0; i < 20; i++)
ASSERT_EQUAL(fileVec2Txt[i], i * 3.);
430 const QMatrix& fileMatrixTxtp =GlobalData().Get<
QMatrix>(
"MyGlobalMatrixTxt",fOutputDir +
"/testglobal3.txt");
433 for(
int i = 0; i < 3; i++)
434 for(
int j = 0; j < 20;j++)
442 if(GetIteration() < fIter) {
443 Info(
"Ending iteration %d",GetIteration());
450 Info(
"QError: %s, %s",
err.ToString().c_str(),
err.GetDescription().c_str());
#define ASSERT_EQUAL(x, y)
QBaseType< double > QDouble
double wrapped in a QObject
QBaseType< int > QInt
int wrapped in a QObject
Diana::QComplex pow(const Diana::QComplex &z, double a)
Raise a complex number to a real power.
#define REGISTER_MODULE(clazz)
diana framework software test.
static Diana::QSequence * fFirstSequence
void TestQEvent(const Diana::QEvent &ev)
virtual void Do(Diana::QEvent &ev)
static Diana::QSequence * fCurrentSequence
virtual void Init(Diana::QEvent &ev)
base types wrapped into a QObject. Currently implemented types are QInt QDouble and QFloat....
bool wrapped into a QObject
error class with error type and description
label for QObject in the QEvent
const Q & GetByLabel(const QEventLabel &label) const
Get a QObject in read mode by label.
void Get(const char *owner, ReadHandle< Q > &handle) const
Get a QObject Handle in read mode.
unsigned int GetReadNumber() const
return the event number as read by the current reader.
void Add(WriteHandle< Q > &handle)
Add a QObject to the event.
virtual bool IsValid() const
Check object validity.
Interface for complex matrices in Diana analysis.
Interface for matrices in Diana analysis.
UInt_t GetNRow() const
get number rows
QVector GetRow(UInt_t nrow)
get row
UInt_t GetNCol() const
get number of columns
MemberInfo FindBaseType(QObject *obj, const char *member)
Raw event: sampled waveform.
string wrapped into a QObject
read handle to access QEvent QObject's.
const T & Get() const
Get Object.
write handle to access and add QEvent QObject's.
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...