]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Adding useful methods for converting between DDL and slice/patch. Plus cleaning up...
authoraszostak <aszostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 4 Aug 2010 16:05:43 +0000 (16:05 +0000)
committeraszostak <aszostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 4 Aug 2010 16:05:43 +0000 (16:05 +0000)
HLT/TPCLib/AliHLTTPCDefinitions.cxx
HLT/TPCLib/AliHLTTPCDefinitions.h
HLT/TPCLib/test/Makefile.am
HLT/TPCLib/test/testAliHLTTPCDefinitions.C [new file with mode: 0644]

index c0f7655180c4a1b7346a42ec117f52afff4256de..d8cd5c2df061e9220690cfdd928a50012da4cddd 100644 (file)
@@ -73,4 +73,24 @@ AliHLTTPCDefinitions::~AliHLTTPCDefinitions()
   // see header file for class documentation
 }
 
+bool AliHLTTPCDefinitions::DDLIdToSlicePatch(AliHLTInt32_t ddlid, AliHLTUInt8_t& slice, AliHLTUInt8_t& patch)
+{
+       // Convert DDL ID to patch and slice numbers.
+       
+       if ((AliHLTUInt32_t(ddlid) >> 8) != 0x3) return false;  // Check that detector is TPC.
+       AliHLTUInt32_t ddl = (AliHLTUInt32_t(ddlid) & 0xFF);
+       if (ddl > 215) return false;
+       if (ddl < 72)
+       {
+               slice = ddl / 2;
+               patch = ddl % 2;
+       }
+       else
+       {
+               ddl -= 72;
+               slice = ddl / 4;
+               patch = ddl % 4 + 2;
+       }
+       return true;
+}
     
index fb832e7087673404648a01f2e11b6bd022f8fec0..ef6fcca174fa172e57f4598456c43b8a5c32eebe 100644 (file)
@@ -19,8 +19,6 @@
 class AliHLTTPCDefinitions
 {
 public:
-      AliHLTTPCDefinitions();
-      virtual ~AliHLTTPCDefinitions();
 
        static AliHLTUInt8_t GetMinSliceNr( const AliHLTComponentBlockData& block )
                {
@@ -62,6 +60,30 @@ public:
                {
                return ((maxSliceNr & 0xFF) << 24) | ((minSliceNr & 0xFF) << 16) | ((maxPatchNr & 0xFF) << 8) | ((minPatchNr & 0xFF));
                }
+       
+       /**
+        * Converts a slice and patch number to a DDL ID number for TPC.
+        * \param slice  The slice number in the range [0..35] (0..17 for A side and 18..35 for C side).
+        * \param patch  The patch number in the range [0..5].
+        * \returns the DDL ID number of TPC or -1 if the slice or patch was invalid.
+        * \note A side is in the -z axis direction (same side as the muon spectrometer)
+        *       and C side is in the +z axis direction.
+        */
+       static AliHLTInt32_t SlicePatchToDDLId(AliHLTUInt8_t slice, AliHLTUInt8_t patch)
+               {
+               if (slice > 35 or patch > 5) return -1;
+               return 768 + (patch > 1 ? 72 + 4*slice + patch - 2 : 2*slice + patch);
+               }
+               
+       /**
+        * Converts a DDL ID number for the TPC to a slice and patch number.
+        * [in] \param ddlid  The DDL ID number to convert.
+        * [out] \param slice  The resultant slice number in the range [0..35].
+        * [out] \param patch  The resultant patch number in the range [0..5].
+        * \returns true if the DDL ID number was valid and slice and patch were set,
+        *     otherwise false for an invalid DDL ID.
+        */
+       static bool DDLIdToSlicePatch(AliHLTInt32_t ddlid, AliHLTUInt8_t& slice, AliHLTUInt8_t& patch);
 
   /** DDL packed RAW data */
   static const AliHLTComponentDataType fgkDDLPackedRawDataType;         // see above
@@ -113,7 +135,13 @@ public:
   /** cluster monte carlo information */
   static const AliHLTComponentDataType fgkAliHLTDataTypeClusterMCInfo;    // see above
 
-  ClassDef(AliHLTTPCDefinitions, 4)
+private:
+
+  /// Do not allow creation of this class since everything is static.
+  AliHLTTPCDefinitions();
+  virtual ~AliHLTTPCDefinitions();
+
+  ClassDef(AliHLTTPCDefinitions, 0)  // Useful static definitions and methods for TPC
 };
 
 #endif
index e7e78b5404d5f4cda35a80571ebce4f8f5dc35fe..3aeea73a9a28928422c3f320c79d0e1b52328cb1 100644 (file)
@@ -11,11 +11,13 @@ EXTRA_DIST                  =
 
 check_PROGRAMS                 = testAliHLTTPCDigitReaderDecoder \
                                  testAliHLTTPCDigitReaderPacked \
-                                 testAliHLTTPCMapping
+                                 testAliHLTTPCMapping \
+                                 testAliHLTTPCDefinitions
 
 testAliHLTTPCDigitReaderDecoder_SOURCES = testAliHLTTPCDigitReaderDecoder.C
 testAliHLTTPCDigitReaderPacked_SOURCES = testAliHLTTPCDigitReaderPacked.C
 testAliHLTTPCMapping_SOURCES           = testAliHLTTPCMapping.C
+testAliHLTTPCDefinitions_SOURCES       = testAliHLTTPCDefinitions.C
 
 
 # linker flags
@@ -29,11 +31,14 @@ LDFLAGS_COMMON                              = -L@ROOTLIBDIR@ \
 testAliHLTTPCDigitReaderDecoder_LDADD  = $(LDADD_COMMON)
 testAliHLTTPCDigitReaderPacked_LDADD   = $(LDADD_COMMON)
 testAliHLTTPCMapping_LDADD             = $(LDADD_COMMON)
+testAliHLTTPCDefinitions_LDADD         = $(LDADD_COMMON)
 testAliHLTTPCDigitReaderDecoder_LDFLAGS        = $(LDFLAGS_COMMON)
 testAliHLTTPCDigitReaderPacked_LDFLAGS = $(LDFLAGS_COMMON)
 testAliHLTTPCMapping_LDFLAGS           = $(LDFLAGS_COMMON)
+testAliHLTTPCDefinitions_LDFLAGS       = $(LDFLAGS_COMMON)
 
 # set back to all as sson as DigitReaderPacked is fixed
 #TESTS                         = $(check_PROGRAMS)
 TESTS                          = testAliHLTTPCDigitReaderDecoder \
-                                 testAliHLTTPCMapping
+                                 testAliHLTTPCMapping \
+                                 testAliHLTTPCDefinitions
diff --git a/HLT/TPCLib/test/testAliHLTTPCDefinitions.C b/HLT/TPCLib/test/testAliHLTTPCDefinitions.C
new file mode 100644 (file)
index 0000000..f04e10c
--- /dev/null
@@ -0,0 +1,145 @@
+/**************************************************************************
+ * 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   testAliHLTTPCDefinitions.C
+ * @author Artur Szostak <artursz@iafrica.com>
+ * @date   4 Aug 2010
+ *
+ * This macro is used to test the AliHLTTPCDefinitions class.
+ * Specifically the mapping encoded in the different methods.
+ */
+
+#if !defined(__CINT__) || defined(__MAKECINT__)
+#include "Riostream.h"
+#include "TClassTable.h"
+#include "TSystem.h"
+#include "AliDAQ.h"
+#include "AliHLTTPCDefinitions.h"
+#endif
+
+
+/**
+ * Routine to check that the SlicePatchToDDLId and DDLIdToSlicePatch methods work.
+ */
+bool CheckDDLToSlicePatchConversion()
+{
+       // Check the conversion from slice + patch to DDL ID.
+       Int_t minDDL = AliDAQ::DdlIDOffset("TPC");
+       Int_t maxDDL = AliDAQ::DdlIDOffset("TPC") + AliDAQ::NumberOfDdls("TPC") - 1;
+       for (AliHLTUInt16_t slice = 0; slice < 256; ++slice)
+       for (AliHLTUInt16_t patch = 0; patch < 256; ++patch)
+       {
+               Int_t ddlid = AliHLTTPCDefinitions::SlicePatchToDDLId(AliHLTUInt8_t(slice), AliHLTUInt8_t(patch));
+               if (slice < 36 && patch < 6)
+               {
+                       // The slice and patch are valid so they should give a valid DDL ID.
+                       if (ddlid < minDDL || maxDDL < ddlid)
+                       {
+                               cerr << "ERROR: AliHLTTPCDefinitions::SlicePatchToDDLId("
+                                       << int(slice) << ", " << int(patch) << ") returned invalid DDL ID of "
+                                       << ddlid << " which is outside the valid range of ["
+                                       << minDDL << ".." << maxDDL << "]." << endl;
+                               return false;
+                       }
+               }
+               else
+               {
+                       // The slice or patch are not valid so the result should be -1
+                       if (ddlid != -1)
+                       {
+                               cerr << "ERROR: AliHLTTPCDefinitions::SlicePatchToDDLId("
+                                       << int(slice) << ", " << int(patch) << ") returned invalid responce of "
+                                       << ddlid << " when is should have returned -1." << endl;
+                               return false;
+                       }
+               }
+       }
+       
+       // Check the conversion from DDL ID to slice + patch.
+       for (AliHLTInt32_t ddlid2 = 0; ddlid2 < 8000; ++ddlid2)
+       {
+               AliHLTUInt8_t slice2 = 255;
+               AliHLTUInt8_t patch2 = 255;
+               bool result = AliHLTTPCDefinitions::DDLIdToSlicePatch(ddlid2, slice2, patch2);
+               if (minDDL <= ddlid2 && ddlid2 <= maxDDL)
+               {
+                       // The DDL ID was valid so the slice and patch should also be.
+                       if (result == false)
+                       {
+                               cerr << "ERROR: AliHLTTPCDefinitions::DDLIdToSlicePatch("
+                                       << ddlid2 << ") returned invalid result of 'false'."
+                                       << " But it should have been 'true'." << endl;
+                               return false;
+                       }
+                       if (slice2 > 35)
+                       {
+                               cerr << "ERROR: AliHLTTPCDefinitions::DDLIdToSlicePatch("
+                                       << ddlid2 << ") returned invalid slice value of "
+                                       << int(slice2) << ", but the valid range is [0..35]."
+                                       << endl;
+                               return false;
+                       }
+                       if (patch2 > 5)
+                       {
+                               cerr << "ERROR: AliHLTTPCDefinitions::DDLIdToSlicePatch("
+                                       << ddlid2 << ") returned invalid patch value of "
+                                       << int(patch2) << ", but the valid range is [0..5]."
+                                       << endl;
+                               return false;
+                       }
+               }
+               else
+               {
+                       // The DDL ID was not valid so the responce should be false.
+                       if (result == true)
+                       {
+                               cerr << "ERROR: AliHLTTPCDefinitions::DDLIdToSlicePatch("
+                                       << ddlid2 << ") returned invalid result of 'true'."
+                                       << " But it should have been 'false'." << endl;
+                               return false;
+                       }
+               }
+       }
+       return true;
+}
+
+/**
+ * This is the top level testing method which calls individual tests.
+ * \returns true if all tests succeeded and false otherwise.
+ */
+bool testAliHLTTPCDefinitions()
+{
+       if (gClassTable->GetID("AliHLTTPCDefinitions") < 0)
+       {
+               gSystem->Load("libAliHLTUtil.so");
+               gSystem->Load("libAliHLTTPC.so");
+       }
+       if (! CheckDDLToSlicePatchConversion()) return false;
+       return true;
+}
+
+#ifndef __MAKECINT__
+
+int main(int /*argc*/, const char** /*argv*/)
+{
+       bool resultOk = testAliHLTTPCDefinitions();
+       if (not resultOk) return 1;
+       return 0;
+}
+
+#endif // __MAKECINT__
+