ROOT logo
// $Id$

//**************************************************************************
//* This file is property of and copyright by the                          * 
//* 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   AliHLTOUTHandlerDetectorDDL.cxx
/// @author Matthias Richter
/// @date   2008-09-09
/// @brief  HLTOUT handler returning equipment id from data type and spec.
///

#include "AliHLTOUTHandlerDetectorDDL.h"
#include "AliHLTOUT.h"
#include "AliHLTDAQ.h"

/** ROOT macro for the implementation of ROOT specific class methods */
ClassImp(AliHLTOUTHandlerDetectorDDL)

AliHLTOUTHandlerDetectorDDL::AliHLTOUTHandlerDetectorDDL(const char* detector, AliHLTComponentDataType dt)
  :
  fDDLOffset(-1),
  fNumberOfDDLs(-1),
  fDt(dt)
{ 
  // A default handler class for DDL raw data redirection handlers.
  //
  // This class implements an AliHLTOUTHandlerEquId which extracts the
  // equipment Id from the bit pattern in the specification. All detectors
  // with up to 32 DDL links follow this convention. The bit no in the
  // data specification word corresponds to the DDL number within the
  // sub-detector.
  
  fDDLOffset=AliHLTDAQ::DdlIDOffset(detector);
  fNumberOfDDLs=AliHLTDAQ::NumberOfDdls(detector);
}

AliHLTOUTHandlerDetectorDDL::~AliHLTOUTHandlerDetectorDDL()
{
  // destructor
}

int AliHLTOUTHandlerDetectorDDL::ProcessData(AliHLTOUT* pData)
{
  // extract the ddl no from the data specification of the data
  // block and return it
  // negative error code if failed
  if (!pData) return -EINVAL;
  if (fDDLOffset<0 || fNumberOfDDLs<0) return -ENODEV;

  static int errorCount=0;
  const int maxErrorCount=10;
  AliHLTComponentDataType dt=kAliHLTVoidDataType;
  AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
  int iResult=pData->GetDataBlockDescription(dt, spec);
  if (iResult>=0 && dt!=kAliHLTVoidDataType && spec!=kAliHLTVoidDataSpec) {
    if (dt==fDt) {
      int ddlNo=0;
      for (;ddlNo<32 && ddlNo<fNumberOfDDLs; ddlNo++) {
	if (spec&(0x1<<ddlNo)) break;
      }
      if (ddlNo>=32 || ddlNo>=fNumberOfDDLs) {
	HLTError("invalid specification 0x%08x: can not extract DDL id for data block %s", spec, AliHLTComponent::DataType2Text(dt).c_str());
	iResult=-ENODEV;
      } else if (spec^(0x1<<ddlNo)) {
	iResult=-EEXIST;
	HLTError("multiple links set in specification 0x%08x: can not extract DDL id for data block %s", spec, AliHLTComponent::DataType2Text(dt).c_str());
      } else {
	iResult=fDDLOffset+ddlNo;
      }
    } else {
      if (errorCount++<10) {
	HLTError("wrong data type: expecting %s, got %s%s",
		 AliHLTComponent::DataType2Text(fDt).c_str(),
		 AliHLTComponent::DataType2Text(dt).c_str(),
		 errorCount==maxErrorCount?"; suppressing further error messages":"");
      }
      iResult=-EBADF;
    }
  } else {
    if (errorCount++<10) {
      HLTError("can not get a valid data type and specification from HLTOUT: type %s, specification 0x%08x%s",
	       AliHLTComponent::DataType2Text(dt).c_str(), spec,
	       errorCount==maxErrorCount?"; suppressing further error messages":"");
    }
    iResult=-ENODATA;
  }
  return iResult;
}
 AliHLTOUTHandlerDetectorDDL.cxx:1
 AliHLTOUTHandlerDetectorDDL.cxx:2
 AliHLTOUTHandlerDetectorDDL.cxx:3
 AliHLTOUTHandlerDetectorDDL.cxx:4
 AliHLTOUTHandlerDetectorDDL.cxx:5
 AliHLTOUTHandlerDetectorDDL.cxx:6
 AliHLTOUTHandlerDetectorDDL.cxx:7
 AliHLTOUTHandlerDetectorDDL.cxx:8
 AliHLTOUTHandlerDetectorDDL.cxx:9
 AliHLTOUTHandlerDetectorDDL.cxx:10
 AliHLTOUTHandlerDetectorDDL.cxx:11
 AliHLTOUTHandlerDetectorDDL.cxx:12
 AliHLTOUTHandlerDetectorDDL.cxx:13
 AliHLTOUTHandlerDetectorDDL.cxx:14
 AliHLTOUTHandlerDetectorDDL.cxx:15
 AliHLTOUTHandlerDetectorDDL.cxx:16
 AliHLTOUTHandlerDetectorDDL.cxx:17
 AliHLTOUTHandlerDetectorDDL.cxx:18
 AliHLTOUTHandlerDetectorDDL.cxx:19
 AliHLTOUTHandlerDetectorDDL.cxx:20
 AliHLTOUTHandlerDetectorDDL.cxx:21
 AliHLTOUTHandlerDetectorDDL.cxx:22
 AliHLTOUTHandlerDetectorDDL.cxx:23
 AliHLTOUTHandlerDetectorDDL.cxx:24
 AliHLTOUTHandlerDetectorDDL.cxx:25
 AliHLTOUTHandlerDetectorDDL.cxx:26
 AliHLTOUTHandlerDetectorDDL.cxx:27
 AliHLTOUTHandlerDetectorDDL.cxx:28
 AliHLTOUTHandlerDetectorDDL.cxx:29
 AliHLTOUTHandlerDetectorDDL.cxx:30
 AliHLTOUTHandlerDetectorDDL.cxx:31
 AliHLTOUTHandlerDetectorDDL.cxx:32
 AliHLTOUTHandlerDetectorDDL.cxx:33
 AliHLTOUTHandlerDetectorDDL.cxx:34
 AliHLTOUTHandlerDetectorDDL.cxx:35
 AliHLTOUTHandlerDetectorDDL.cxx:36
 AliHLTOUTHandlerDetectorDDL.cxx:37
 AliHLTOUTHandlerDetectorDDL.cxx:38
 AliHLTOUTHandlerDetectorDDL.cxx:39
 AliHLTOUTHandlerDetectorDDL.cxx:40
 AliHLTOUTHandlerDetectorDDL.cxx:41
 AliHLTOUTHandlerDetectorDDL.cxx:42
 AliHLTOUTHandlerDetectorDDL.cxx:43
 AliHLTOUTHandlerDetectorDDL.cxx:44
 AliHLTOUTHandlerDetectorDDL.cxx:45
 AliHLTOUTHandlerDetectorDDL.cxx:46
 AliHLTOUTHandlerDetectorDDL.cxx:47
 AliHLTOUTHandlerDetectorDDL.cxx:48
 AliHLTOUTHandlerDetectorDDL.cxx:49
 AliHLTOUTHandlerDetectorDDL.cxx:50
 AliHLTOUTHandlerDetectorDDL.cxx:51
 AliHLTOUTHandlerDetectorDDL.cxx:52
 AliHLTOUTHandlerDetectorDDL.cxx:53
 AliHLTOUTHandlerDetectorDDL.cxx:54
 AliHLTOUTHandlerDetectorDDL.cxx:55
 AliHLTOUTHandlerDetectorDDL.cxx:56
 AliHLTOUTHandlerDetectorDDL.cxx:57
 AliHLTOUTHandlerDetectorDDL.cxx:58
 AliHLTOUTHandlerDetectorDDL.cxx:59
 AliHLTOUTHandlerDetectorDDL.cxx:60
 AliHLTOUTHandlerDetectorDDL.cxx:61
 AliHLTOUTHandlerDetectorDDL.cxx:62
 AliHLTOUTHandlerDetectorDDL.cxx:63
 AliHLTOUTHandlerDetectorDDL.cxx:64
 AliHLTOUTHandlerDetectorDDL.cxx:65
 AliHLTOUTHandlerDetectorDDL.cxx:66
 AliHLTOUTHandlerDetectorDDL.cxx:67
 AliHLTOUTHandlerDetectorDDL.cxx:68
 AliHLTOUTHandlerDetectorDDL.cxx:69
 AliHLTOUTHandlerDetectorDDL.cxx:70
 AliHLTOUTHandlerDetectorDDL.cxx:71
 AliHLTOUTHandlerDetectorDDL.cxx:72
 AliHLTOUTHandlerDetectorDDL.cxx:73
 AliHLTOUTHandlerDetectorDDL.cxx:74
 AliHLTOUTHandlerDetectorDDL.cxx:75
 AliHLTOUTHandlerDetectorDDL.cxx:76
 AliHLTOUTHandlerDetectorDDL.cxx:77
 AliHLTOUTHandlerDetectorDDL.cxx:78
 AliHLTOUTHandlerDetectorDDL.cxx:79
 AliHLTOUTHandlerDetectorDDL.cxx:80
 AliHLTOUTHandlerDetectorDDL.cxx:81
 AliHLTOUTHandlerDetectorDDL.cxx:82
 AliHLTOUTHandlerDetectorDDL.cxx:83
 AliHLTOUTHandlerDetectorDDL.cxx:84
 AliHLTOUTHandlerDetectorDDL.cxx:85
 AliHLTOUTHandlerDetectorDDL.cxx:86
 AliHLTOUTHandlerDetectorDDL.cxx:87
 AliHLTOUTHandlerDetectorDDL.cxx:88
 AliHLTOUTHandlerDetectorDDL.cxx:89
 AliHLTOUTHandlerDetectorDDL.cxx:90
 AliHLTOUTHandlerDetectorDDL.cxx:91
 AliHLTOUTHandlerDetectorDDL.cxx:92
 AliHLTOUTHandlerDetectorDDL.cxx:93
 AliHLTOUTHandlerDetectorDDL.cxx:94
 AliHLTOUTHandlerDetectorDDL.cxx:95
 AliHLTOUTHandlerDetectorDDL.cxx:96
 AliHLTOUTHandlerDetectorDDL.cxx:97
 AliHLTOUTHandlerDetectorDDL.cxx:98
 AliHLTOUTHandlerDetectorDDL.cxx:99
 AliHLTOUTHandlerDetectorDDL.cxx:100
 AliHLTOUTHandlerDetectorDDL.cxx:101