- added libPHOSshuttle to PHOS libraries
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 18 Apr 2008 07:01:42 +0000 (07:01 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 18 Apr 2008 07:01:42 +0000 (07:01 +0000)
- added unit test for AliHLTEsdManager
- added default CDB entry for solenoid field
- bugfix in FileWriter: include block no in the generated file name
  (according to the class documentation)

HLT/BASE/util/AliHLTFileWriter.cxx
HLT/ConfigHLT/SolenoidBz/Run0_0_v0_s0.root [new file with mode: 0644]
HLT/configure.ac
HLT/rec/Makefile.am
HLT/rec/test/Makefile.am [new file with mode: 0644]
HLT/rec/test/testAliHLTEsdManager.C [new file with mode: 0644]

index 66aceed..7c8280f 100644 (file)
@@ -44,7 +44,7 @@ AliHLTFileWriter::AliHLTFileWriter()
   fSubDirFormat(""),
   fIdFormat(""),
   fSpecFormat(""),
-  fBlcknoFormat(""),
+  fBlcknoFormat("_0x%02x"),
   fCurrentFileName(""),
   fMode(0)
 {
diff --git a/HLT/ConfigHLT/SolenoidBz/Run0_0_v0_s0.root b/HLT/ConfigHLT/SolenoidBz/Run0_0_v0_s0.root
new file mode 100644 (file)
index 0000000..3900a73
Binary files /dev/null and b/HLT/ConfigHLT/SolenoidBz/Run0_0_v0_s0.root differ
index e054f5f..7e603ea 100644 (file)
@@ -598,7 +598,7 @@ ALIPHOS_LIBS=
 CHECK_HLTMODULE([phos],
                [], [$ALIROOT_CPPFLAGS],
                [RAWDatasim], [-L$ROOTLIBDIR $ALIROOT_LDFLAGS], [$ROOTLIBS $ADD_ROOTLIBS $ALIROOT_LIBS],
-               [PHOSbase PHOSrec PHOSsim], [-L$ROOTLIBDIR $ALIROOT_LDFLAGS], 
+               [PHOSbase PHOSrec PHOSsim PHOSshuttle], [-L$ROOTLIBDIR $ALIROOT_LDFLAGS], 
                [$ROOTLIBS $ADD_ROOTLIBS $ALIROOT_LIBS])
 
 if test "x$enable_module" = "xmissheader"; then
@@ -902,6 +902,7 @@ AM_CONDITIONAL(HAVE_ALIROOT, test "x$have_aliroot" != "xno" )
 if test "x$have_aliroot" != "xno"; then 
   AC_CONFIG_FILES([sim/Makefile         
                   rec/Makefile  
+                  rec/test/Makefile     
                   shuttle/Makefile
                   ])
 fi
@@ -915,6 +916,13 @@ if test "x$enable_sample" = "xyes"; then
   AC_CONFIG_FILES([SampleLib/Makefile])
 fi
 
+AC_MSG_NOTICE([compile RCU library: $enable_rcu])
+if test "x$enable_rcu" = "xyes"; then 
+  AC_CONFIG_FILES([RCU/Makefile
+                  RCU/test/Makefile
+                  ])
+fi
+
 AC_MSG_NOTICE([compile TPC library: $enable_tpc])
 if test "x$enable_tpc" = "xyes"; then 
   AC_CONFIG_FILES([TPCLib/Makefile           
@@ -924,13 +932,6 @@ if test "x$enable_tpc" = "xyes"; then
                   ])
 fi
 
-AC_MSG_NOTICE([compile RCU library: $enable_rcu])
-if test "x$enable_rcu" = "xyes"; then 
-  AC_CONFIG_FILES([RCU/Makefile
-                  RCU/test/Makefile
-                  ])
-fi
-
 AC_MSG_NOTICE([compile PHOS library: $enable_phos])
 if test "x$enable_phos" = "xyes"; then 
   AC_CONFIG_FILES([PHOS/Makefile])
index 5d43774..de8e0f2 100644 (file)
@@ -3,7 +3,7 @@
 
 MODULE                         = HLTrec
 
-SUBDIRS                        = 
+SUBDIRS                        = . test
 
 EXTRA_DIST                     = 
 
diff --git a/HLT/rec/test/Makefile.am b/HLT/rec/test/Makefile.am
new file mode 100644 (file)
index 0000000..2adbb72
--- /dev/null
@@ -0,0 +1,28 @@
+# $Id$
+# Makefile template ALICE HLT libHLTrec library test programs
+
+AM_CPPFLAGS                    = -I$(top_srcdir)/BASE \
+                                 -I$(srcdir)/.. \
+                                 @ALIROOT_CPPFLAGS@ \
+                                 -I@ROOTINCDIR@
+
+EXTRA_DIST                     = 
+
+check_PROGRAMS                 = testAliHLTEsdManager
+
+testAliHLTEsdManager_SOURCES   = testAliHLTEsdManager.C
+
+
+# linker flags
+LDADD_COMMON                   = $(top_builddir)/BASE/libHLTbase.la \
+                                 $(top_builddir)/rec/libHLTrec.la
+LDFLAGS_COMMON                 = -L@ROOTLIBDIR@ \
+                                 @ROOTLIBS@ \
+                                 @ALIROOT_LDFLAGS@ \
+                                 @ALIROOT_LIBS@
+
+testAliHLTEsdManager_LDADD     = $(LDADD_COMMON)
+
+testAliHLTEsdManager_LDFLAGS   = $(LDFLAGS_COMMON)
+
+TESTS                          = $(check_PROGRAMS)
diff --git a/HLT/rec/test/testAliHLTEsdManager.C b/HLT/rec/test/testAliHLTEsdManager.C
new file mode 100644 (file)
index 0000000..9dce978
--- /dev/null
@@ -0,0 +1,282 @@
+// $Id$
+
+/**************************************************************************
+ * This file is property of and copyright by the ALICE HLT Project        * 
+ * ALICE Experiment at CERN, All rights reserved.                         *
+ *                                                                        *
+ * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
+ *                  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   testAliHLTEsdManager.C
+    @author Matthias Richter
+    @date   
+    @brief  Test macro/program for the AliHLTEsdManager class
+ */
+
+#ifndef __CINT__
+#include "TFile.h"
+#include "TDatime.h"
+#include "TRandom.h"
+#include "TArrayI.h"
+#include "TSystem.h"
+#include "TTree.h"
+#include "TFile.h"
+#include "AliESDEvent.h"
+#include "AliHLTDataTypes.h"
+#include "AliHLTComponent.h"
+#include "AliHLTEsdManager.h"
+#include "AliHLTMessage.h"
+#include "AliHLTSystem.h"
+#include <ostream>
+#endif //__CINT__
+
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+//
+// configuration of the test program
+//
+
+// printouts or not
+const bool bVerbose=false;
+
+
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+//
+// forward declarations
+//
+class AliHLTEsdManager;
+int GetRandom(int min, int max);
+int CreateAndWriteESD(AliHLTEsdManager& manager, int eventno, AliHLTComponentDataType dt, AliESDEvent* pTgt);
+int CheckFields(const char* file, TArrayI* fields);
+int CheckFields(TTree* pTree, TArrayI* fields, const char* file);
+
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+//
+// compiled version and root macro are not equivalent for this unit test
+// The macro just tests with one data type
+// This is mainly due to some restrictions in CINT which can not handle
+// the array of data types correctly
+int testAliHLTEsdManager()
+{
+  cout << "macro still not working with CINT, sorry!" << endl;
+  return 0;
+
+  int iResult=0;
+#ifdef __CINT__
+  if (gSystem->Load("libHLTrec.so")<0) {
+    cerr << "error loading libHLTrec.so library" << endl;
+    return -1;
+  }
+#endif
+
+  AliHLTEsdManager manager;
+  manager.SetDirectory(gSystem->TempDirectory());
+
+  int nofEvents=10;
+  AliHLTComponentDataType tpcesd;
+  AliHLTComponent::SetDataType(tpcesd, "ESD_TREE", "TPC ");
+  cout << AliHLTComponent::DataType2Text(tpcesd).c_str() << endl;
+  for (int event=0; event<nofEvents && iResult>=0; event++) {
+    cout << AliHLTComponent::DataType2Text(tpcesd).c_str() << endl;
+    CreateAndWriteESD(manager, event, tpcesd, NULL);
+  }
+
+  return iResult;
+}
+
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+//
+int main(int /*argc*/, const char** /*argv*/)
+{
+  int iResult=0;
+  int nofEvents=10;
+  AliHLTSystem gHLT;
+  gHLT.SetGlobalLoggingLevel(kHLTLogDefault);
+
+  AliHLTEsdManager manager;
+  manager.SetDirectory(gSystem->TempDirectory());
+
+  AliHLTComponentDataType types[] = {
+    // first entry is special, ESD is written to the global target ESD
+    //kAliHLTDataTypeESDTree|kAliHLTDataOriginTPC,
+    kAliHLTDataTypeESDTree|kAliHLTDataOriginTPC,
+    kAliHLTDataTypeESDTree|kAliHLTDataOriginPHOS,
+    kAliHLTDataTypeESDTree|kAliHLTDataOriginTRD,
+    kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTRD,
+    kAliHLTVoidDataType
+  };
+
+  TTree* pMasterTree=new TTree("esdTree", "Tree with HLT ESD objects");
+  AliESDEvent* pMasterESD=new AliESDEvent;
+  pMasterESD->CreateStdContent();
+  pMasterESD->WriteToTree(pMasterTree);
+
+  vector<TArrayI*> randomFields;
+  for (int event=0; event<nofEvents && iResult>=0; event++) {
+    pMasterESD->ResetStdContent();
+    for (unsigned int type=0; types[type]!=kAliHLTVoidDataType && iResult>=0; type++) {
+      if (randomFields.size()<=type) {
+       randomFields.push_back(new TArrayI(nofEvents));
+      }
+      AliESDEvent* pTgt=NULL;
+      //if (type==0) pTgt=pMasterESD;
+      int field=CreateAndWriteESD(manager, event, types[type], pTgt);
+      if (field>=0) {
+       (*randomFields[type])[event]=field;
+      } else {
+       iResult=-1;
+       break;
+      }
+    }
+    pMasterTree->Fill();
+  }
+
+  if (iResult>=0) {
+    manager.PadESDs(nofEvents);
+  }
+
+  for (int type=0; types[type]!=kAliHLTVoidDataType; type++) {
+    TString filename=manager.GetFileNames(types[type]);
+    if (iResult>=0) {
+      iResult=CheckFields(filename, dynamic_cast<TArrayI*>(randomFields[type]));
+    }
+    TString shellcmd="rm -f ";
+    shellcmd+=filename;
+    gSystem->Exec(shellcmd);    
+  }
+
+  vector<TArrayI*>::iterator element;
+  while ((element=randomFields.end())!=randomFields.begin()) {
+    element--;
+    if (*element) delete *element;
+    randomFields.pop_back();
+  }
+
+  delete pMasterESD;
+
+  return iResult;
+}
+
+Bool_t seedSet=kFALSE;
+
+/**
+ * Get a random number in the given range.
+ */
+int GetRandom(int min, int max)
+{
+  if (max-min<2) return min;
+  static TRandom rand;
+  if (!seedSet) {
+    TDatime dt;
+    rand.SetSeed(dt.Get());
+    seedSet=kTRUE;
+  }
+  return rand.Integer(max-min);
+}
+
+/**
+ * Creates a dummy ESD object and sets the magnetic field to a random number.
+ * The ESD is streamed via AliHLTMessage and processed by the AliHLTEsdmanager.
+ * @return 0 no ESD created, >0 random number of the magnetic field, 
+ *         neg error if failed
+ */
+int CreateAndWriteESD(AliHLTEsdManager& manager, int eventno, AliHLTComponentDataType dt, AliESDEvent* pTgt)
+{
+  int iResult=0;
+  int magField=0;
+  const char* message="";
+  if ((GetRandom(0,10)%3)==0) {
+    message=": adding ESD for block ";
+    TTree* pTree=new TTree;
+    AliESDEvent* pESD=new AliESDEvent;
+    pESD->CreateStdContent();
+    magField=GetRandom(1, 1000);
+    pESD->SetMagneticField(magField);
+    pESD->WriteToTree(pTree);
+    pTree->Fill();
+    pTree->GetUserInfo()->Add(pESD);
+    AliHLTMessage msg(kMESS_OBJECT);
+    msg.WriteObject(pTree);
+    Int_t iMsgLength=msg.Length();
+    if (iMsgLength>0) {
+      msg.SetLength(); // sets the length to the first (reserved) word
+      iResult=manager.WriteESD((AliHLTUInt8_t*)msg.Buffer(), iMsgLength, dt, pTgt, eventno);
+    }
+    pTree->GetUserInfo()->Clear();
+    delete pTree;
+    delete pESD;
+  } else {
+    message=": omitting block       ";
+  }
+  if (iResult>=0) iResult=magField;
+  if (bVerbose) cout << "event " << eventno << message << AliHLTComponent::DataType2Text(dt).c_str() << ": " << iResult << endl;
+  return iResult;
+}
+
+/**
+ * Read the ESD from the file and compare with the
+ * random field values previously set to the ESDs
+ */
+int CheckFields(const char* file, TArrayI* fields)
+{
+  if (!file || !fields) {
+    cerr << "invalid parameters" << endl;
+    return 0;
+  }
+  TFile esdfile(file);
+  if (!esdfile.IsZombie()) {
+    TTree* pTree=NULL;
+    esdfile.GetObject("esdTree", pTree);
+    if (pTree) {
+      int res=CheckFields(pTree, fields, file);
+      if (res<0) return res;
+    } else {
+      cerr << "can not find esdTree in file " << file << endl;
+    }
+  } else {
+    cerr << "can not open file " << file << endl;
+    return -1;
+  }
+  cout << "checking: " << file << " ok" << endl;
+  return 0;
+}
+
+/**
+ * Compare ESD from tree with the
+ * random field values previously set to the ESDs
+ */
+int CheckFields(TTree* pTree, TArrayI* fields, const char* file)
+{
+  if (fields->GetSize()!=pTree->GetEntries()) {
+    cerr << "event number mismatch in file " << file << " : expected " << fields->GetSize() << "  found " << pTree->GetEntries() << endl;
+    return -1;
+  }
+  AliESDEvent* pESD=new AliESDEvent;
+  pESD->ReadFromTree(pTree);
+  for (int event=0; event<pTree->GetEntries(); event++) {
+    pTree->GetEvent(event);
+    if (fields->At(event)!=pESD->GetMagneticField()) {
+      cerr << "magnetic field mismatch in file " << file << " event " << event << ": expected " << fields->At(event) << "  found " << pESD->GetMagneticField() << endl;
+      return -1;
+    }
+  }
+
+  delete pESD;
+  return 0;
+}