]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Adding unit test for AliHLTReadoutList
authoraszostak <aszostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 10 Jun 2010 21:13:26 +0000 (21:13 +0000)
committeraszostak <aszostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 10 Jun 2010 21:13:26 +0000 (21:13 +0000)
HLT/BASE/test/Makefile.am
HLT/BASE/test/testAliHLTReadoutList.C [new file with mode: 0644]

index 8e0ac562d643f39b762dc580f5c98f683128d78b..d63e4191207ddaef1286f2eb0bec3213469bf875 100644 (file)
@@ -9,6 +9,7 @@ check_PROGRAMS  = testAliHLTBlockDataCollection \
                  testAliHLTComponent \
                  testAliHLTCTPData \
                  testAliHLTDataBuffer \
+                 testAliHLTReadoutList \
                  dtOperators \
                  testDefaultDataTypes
 
@@ -36,4 +37,11 @@ testAliHLTCTPData_LDADD = $(top_builddir)/BASE/libHLTbase.la \
 testAliHLTDataBuffer_SOURCES = testAliHLTDataBuffer.C
 testAliHLTDataBuffer_LDADD = $(top_builddir)/BASE/libHLTbase.la
 
+testAliHLTReadoutList_SOURCES = testAliHLTReadoutList.C
+testAliHLTReadoutList_LDADD = $(top_builddir)/BASE/libHLTbase.la \
+                               -L@ROOTLIBDIR@ \
+                               @ROOTLIBS@ \
+                               @ALIROOT_LDFLAGS@ \
+                               @ALIROOT_LIBS@
+
 TESTS          = $(check_PROGRAMS)
diff --git a/HLT/BASE/test/testAliHLTReadoutList.C b/HLT/BASE/test/testAliHLTReadoutList.C
new file mode 100644 (file)
index 0000000..e7aec0b
--- /dev/null
@@ -0,0 +1,338 @@
+// $Id: $
+
+/**************************************************************************
+ * This file is property of and copyright by the ALICE HLT Project        *
+ * ALICE Experiment at CERN, All rights reserved.                         *
+ *                                                                        *
+ * Primary Authors: Artur Szostak <artursz@iafrica.com>                   *
+ *                  for The ALICE HLT Project.                            *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/// @file   testAliHLTReadoutList.C
+/// @author Artur Szostak <artursz@iafrica.com>
+/// @date   8 June 2010
+/// @brief  Test program for the AliHLTReadoutList class.
+///
+
+#if defined(__CINT__) && (! defined(__MAKECINT__))
+#error This macro must be compiled. Try running as testAliHLTReadoutList.C++.
+#endif
+
+#if !defined(__CINT__) || defined(__MAKECINT__)
+#include "AliHLTDataTypes.h"
+#include "AliHLTReadoutList.h"
+#include "AliHLTDAQ.h"
+#include "TRandom3.h"
+#include "TString.h"
+#include "Riostream.h"
+#include <vector>
+#include <algorithm>
+#endif
+
+// The detector codes as used by AliHLTReadoutList.
+const int kgNumberOfCodes = 21;
+const int kgDetCodes[kgNumberOfCodes] = {
+       AliHLTReadoutList::kITSSPD,
+       AliHLTReadoutList::kITSSDD,
+       AliHLTReadoutList::kITSSSD,
+       AliHLTReadoutList::kTPC,
+       AliHLTReadoutList::kTRD,
+       AliHLTReadoutList::kTOF,
+       AliHLTReadoutList::kHMPID,
+       AliHLTReadoutList::kPHOS,
+       AliHLTReadoutList::kCPV,
+       AliHLTReadoutList::kPMD,
+       AliHLTReadoutList::kMUONTRK,
+       AliHLTReadoutList::kMUONTRG,
+       AliHLTReadoutList::kFMD,
+       AliHLTReadoutList::kT0,
+       AliHLTReadoutList::kV0,
+       AliHLTReadoutList::kZDC,
+       AliHLTReadoutList::kACORDE,
+       AliHLTReadoutList::kTRG,
+       AliHLTReadoutList::kEMCAL,
+       AliHLTReadoutList::kDAQTEST,
+       AliHLTReadoutList::kHLT
+};
+const char* kgDetCodeName[kgNumberOfCodes] = {
+       "AliHLTReadoutList::kITSSPD",
+       "AliHLTReadoutList::kITSSDD",
+       "AliHLTReadoutList::kITSSSD",
+       "AliHLTReadoutList::kTPC",
+       "AliHLTReadoutList::kTRD",
+       "AliHLTReadoutList::kTOF",
+       "AliHLTReadoutList::kHMPID",
+       "AliHLTReadoutList::kPHOS",
+       "AliHLTReadoutList::kCPV",
+       "AliHLTReadoutList::kPMD",
+       "AliHLTReadoutList::kMUONTRK",
+       "AliHLTReadoutList::kMUONTRG",
+       "AliHLTReadoutList::kFMD",
+       "AliHLTReadoutList::kT0",
+       "AliHLTReadoutList::kV0",
+       "AliHLTReadoutList::kZDC",
+       "AliHLTReadoutList::kACORDE",
+       "AliHLTReadoutList::kTRG",
+       "AliHLTReadoutList::kEMCAL",
+       "AliHLTReadoutList::kDAQTEST",
+       "AliHLTReadoutList::kHLT"
+};
+
+/**
+ * Converts a code to string.
+ * \param code  The ID code of the detector. One of AliHLTReadoutList::EDetectorId
+ * \returns the code name as a string given a the detector code.
+ */
+const char* CodeToString(int code)
+{
+       for (int i = 0; i < kgNumberOfCodes; ++i)
+       {
+               if (kgDetCodes[i] == code) return kgDetCodeName[i];
+       }
+       return "UNKNOWN";
+}
+
+/**
+ * Checks if the basic empty and clear methods work.
+ */
+bool CheckEmptyAndClear()
+{
+       AliHLTReadoutList rl;
+       if (rl.Empty() != true)
+       {
+               cerr << "ERROR: AliHLTReadoutList::Empty returns false for an empty readout list." << endl;
+               return false;
+       }
+       
+       // Enable all the detectors and check this operation.
+       rl.Enable(AliHLTReadoutList::kALLDET);
+       for (int i = 0; i < kgNumberOfCodes; ++i)
+       {
+               if (i == 19) continue; // This is the test DDL. off by default.
+               if (not rl.DetectorEnabled(kgDetCodes[i]))
+               {
+                       cerr << "ERROR: AliHLTReadoutList::Enable(AliHLTReadoutList::kALLDET) did not enable for "
+                               << CodeToString(kgDetCodes[i]) << "." << endl;
+                       return false;
+               }
+       }
+       if (rl.DetectorEnabled(AliHLTReadoutList::kDAQTEST))
+       {
+               cerr << "ERROR: AliHLTReadoutList::Enable(AliHLTReadoutList::kALLDET) enabled bits"
+                       " for AliHLTReadoutList::kDAQTEST but should not have." << endl;
+               return false;
+       }
+       
+       rl.Clear();
+       // Fetch the raw bits for the readout list structure and check that they
+       // are all zero, since we should have disabled everything in the loop above.
+       AliHLTEventDDL bits = rl;
+       if (bits.fCount != (unsigned int)gkAliHLTDDLListSize)
+       {
+               cerr << "ERROR: Typecast operator AliHLTEventDDL () is not"
+                       " setting the fCount of the structure correctly." << endl;
+               return false;
+       }
+       for (int j = 0; j < gkAliHLTDDLListSize; ++j)
+       {
+               if (bits.fList[j] != 0x0)
+               {
+                       cerr << "ERROR: Word " << j << " in internal AliHLTReadoutList"
+                               " bitfield structure is not zero as expected after a"
+                               " call to AliHLTReadoutList::Clear." << endl;
+                       return false;
+               }
+       }
+       
+       return true;
+}
+
+/**
+ * Tests enabling and disabling of different detectors.
+ */
+bool CheckEnablingDisabling()
+{
+       for (int i = 0; i < 10000; ++i)
+       {
+               // Get 3 random detector codes.
+               int code[3] = {
+                       kgDetCodes[gRandom->Integer(kgNumberOfCodes)],
+                       kgDetCodes[gRandom->Integer(kgNumberOfCodes)],
+                       kgDetCodes[gRandom->Integer(kgNumberOfCodes)]
+               };
+               // make sure the codes are not duplicated.
+               while (code[1] == code[0]) code[1] = kgDetCodes[gRandom->Integer(kgNumberOfCodes)];
+               while (code[2] == code[1] or code[2] == code[0]) code[2] = kgDetCodes[gRandom->Integer(kgNumberOfCodes)];
+               
+               // Choose the number of codes to use, from 1 to max 3.
+               int codeCount = gRandom->Integer(3) + 1;
+               
+               // Build up the detector code list for the AliHLTReadoutList constructor.
+               int totalCode = 0;
+               for (int j = 0; j < codeCount; ++j) totalCode |= code[j];
+               
+               AliHLTReadoutList rl(totalCode);
+               if (rl.Empty() == true)
+               {
+                       cerr << "ERROR: AliHLTReadoutList::Empty returns true for a non empty readout list." << endl;
+                       return false;
+               }
+               
+               // Check that the correct detectors have been enabled and
+               // that we can disable a detector correctly.
+               for (int j = 0; j < codeCount; ++j)
+               {
+                       if (rl.DetectorEnabled(code[j]) == false)
+                       {
+                               cerr << "ERROR: Detector was not enabled for "
+                                       << CodeToString(code[j]) << " by constructor." << endl;
+                               return false;
+                       }
+                       rl.Disable(code[j]);
+                       if (rl.DetectorEnabled(code[j]) == true)
+                       {
+                               cerr << "ERROR: AliHLTReadoutList::Disable(x) is not working for x = "
+                                       << CodeToString(code[j]) << "." << endl;
+                               return false;
+                       }
+               }
+               
+               // Fetch the raw bits for the readout list structure and check that they
+               // are all zero, since we should have disabled everything in the loop above.
+               AliHLTEventDDL bits = rl;
+               for (int j = 0; j < gkAliHLTDDLListSize; ++j)
+               {
+                       if (bits.fList[j] != 0x0)
+                       {
+                               cerr << "ERROR: Word " << j << " in internal AliHLTReadoutList"
+                                       " bitfield structure is not zero as expected." << endl;
+                               return false;
+                       }
+               }
+       }
+       return true;
+}
+
+/**
+ * Tests enabling and disabling of different DDLs.
+ */
+bool CheckEnablingDisablingDDLs()
+{
+       for (int i = 0; i < 10000; ++i)
+       {
+               // Get random DDL IDs that are each unique.
+               std::vector<int> ddls;
+               int ddlCount = gRandom->Integer(100) + 1;
+               for (int j = 0; j < ddlCount; ++j)
+               {
+                       int ddlid = -1;
+                       do
+                       {
+                               int det = gRandom->Integer(AliHLTDAQ::NumberOfDetectors());
+                               int maxddls = AliHLTDAQ::NumberOfDdls(det);
+                               // The following is a special check since AliDAQ could be the newer version.
+                               // det = 18 is for EMCAL and gkAliHLTDDLListSize = 30 indicates old version
+                               // of AliHLTEventDDL before EMCAL expantion with DCAL.
+                               if (det == 18 and gkAliHLTDDLListSize == 30 and maxddls > 24) maxddls = 24;
+                               int ddlindex = gRandom->Integer(maxddls);
+                               ddlid = AliHLTDAQ::DdlID(det, ddlindex);
+                               if (std::find(ddls.begin(), ddls.end(), ddlid) != ddls.end()) ddlid = -1;
+                       }
+                       while (ddlid == -1);
+                       ddls.push_back(ddlid);
+               }
+               
+               // Build up the enable list for the AliHLTReadoutList constructor.
+               TString enableList;
+               for (size_t j = 0; j < ddls.size(); ++j)
+               {
+                       char num[32];
+                       sprintf(num, "%d", ddls[j]);
+                       enableList += " ";
+                       enableList += num;
+               }
+               
+               AliHLTReadoutList rl(enableList.Data());
+               if (rl.Empty() == true)
+               {
+                       cerr << "ERROR: AliHLTReadoutList::Empty returns true for a non empty readout list." << endl;
+                       return false;
+               }
+               
+               // Check that the correct DDLs have been enabled and
+               // that we can disable a DDL correctly.
+               for (size_t j = 0; j < ddls.size(); ++j)
+               {
+                       if (rl.IsDDLEnabled(ddls[j]) == false)
+                       {
+                               cerr << "ERROR: DDL " << ddls[j] << " was not enabled by constructor." << endl;
+                               return false;
+                       }
+                       rl.DisableDDLBit(ddls[j]);
+                       if (rl.IsDDLDisabled(ddls[j]) == false)
+                       {
+                               cerr << "ERROR: AliHLTReadoutList::DisableDDLBit(x) is not working for x = "
+                                       << ddls[j] << "." << endl;
+                               return false;
+                       }
+               }
+               
+               // Fetch the raw bits for the readout list structure and check that they
+               // are all zero, since we should have disabled everything in the loop above.
+               AliHLTEventDDL bits = rl;
+               for (int j = 0; j < gkAliHLTDDLListSize; ++j)
+               {
+                       if (bits.fList[j] != 0x0)
+                       {
+                               cerr << "ERROR: Word " << j << " in internal AliHLTReadoutList"
+                                       " bitfield structure is not zero as expected." << endl;
+                               return false;
+                       }
+               }
+       }
+       return true;
+}
+
+/**
+ * Runs the unit test for the AliHLTReadoutList class.
+ * \returns true if the class passed the test and false otherwise.
+ */
+bool testAliHLTReadoutList()
+{
+       gRandom->SetSeed(123);
+       
+       if (AliHLTDAQ::NumberOfDetectors() != kgNumberOfCodes)
+       {
+               cerr << "ERROR: The testAliHLTReadoutList.C macro needs to be updated"
+                       " or something went really wrong."
+                       " The number of detectors reported by AliHLTDAQ is not "
+                       << kgNumberOfCodes << ", as expected, but "
+                       << AliHLTDAQ::NumberOfDetectors() << "." << endl;
+               return false;
+       }
+       
+       if (not CheckEmptyAndClear()) return false;
+       if (not CheckEnablingDisabling()) return false;
+       if (not CheckEnablingDisablingDDLs()) return false;
+       
+       return true;
+}
+
+#ifndef __MAKECINT__
+
+int main(int /*argc*/, const char** /*argv*/)
+{
+       bool resultOk = testAliHLTReadoutList();
+       if (not resultOk) return 1;
+       return 0;
+}
+
+#endif // __MAKECINT__