<commit_before>/**************************************************************************
 * This file is property of and copyright by the ALICE HLT Project        * 
 * All rights reserved.                                                   *
 *                                                                        *
 * Primary Authors:                                                       *
 *   <NAME> <<EMAIL>>                                  *
 *                                                                        *
 * 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.                  *
 **************************************************************************/

/* $Id$ */

///
/// @file   AliHLTMUONRootifierComponent.cxx
/// @author <NAME> <<EMAIL>>
/// @date   29 Sep 2007
/// @brief  Implementation of the AliHLTMUONRootifierComponent component.
///

#include "AliHLTMUONRootifierComponent.h"
#include "AliHLTMUONEvent.h"
#include "AliHLTMUONConstants.h"
#include "AliHLTMUONUtils.h"
#include "AliHLTMUONRecHit.h"
#include "AliHLTMUONTriggerRecord.h"
#include "AliHLTMUONMansoTrack.h"
#include "AliHLTMUONDecision.h"
#include "TClonesArray.h"
#include <cassert>

ClassImp(AliHLTMUONRootifierComponent);


AliHLTMUONRootifierComponent::AliHLTMUONRootifierComponent() :
	AliHLTMUONProcessor(),
	fWarnForUnexpecedBlock(false)
{
	///
	/// Default constructor.
	///
}


AliHLTMUONRootifierComponent::~AliHLTMUONRootifierComponent()
{
	///
	/// Default destructor.
	///
}


bool AliHLTMUONRootifierComponent::IgnoreArgument(const char* arg) const
{
	/// Return true if the argument is one of -cdbpath -run or -delaysetup
	/// to prevent the parent class from parsing these arguments in DoInit.
	
	if (strcmp(arg, "-cdbpath") == 0 or strcmp(arg, "-run") == 0 or
	    strcmp(arg, "-delaysetup") == 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}


int AliHLTMUONRootifierComponent::DoInit(int argc, const char** argv)
{
	///
	/// Inherited from AliHLTComponent.
	/// Parses the command line parameters and initialises the component.
	///
	
	HLTInfo("Initialising dHLT rootifier component.");

	// Inherit the parents functionality.
	int result = AliHLTMUONProcessor::DoInit(argc, argv);
	if (result != 0) return result;
	
	fWarnForUnexpecedBlock = false;
	
	for (int i = 0; i < argc; i++)
	{
		if (ArgumentAlreadyHandled(i, argv[i])) continue;

		if (strcmp(argv[i], "-warn_on_unexpected_block") == 0)
		{
			fWarnForUnexpecedBlock = true;
			continue;
		}

		HLTError("Unknown option '%s'.", argv[i]);
		return -EINVAL;
	}
	
	return 0;
}


int AliHLTMUONRootifierComponent::DoDeinit()
{
	///
	/// Inherited from AliHLTComponent. Performs a cleanup of the component.
	///
	
	HLTInfo("Deinitialising dHLT rootifier component.");
	return 0;
}


const char* AliHLTMUONRootifierComponent::GetComponentID()
{
	///
	/// Inherited from AliHLTComponent. Returns the component ID.
	///
	
	return AliHLTMUONConstants::RootifierComponentId();
}


AliHLTComponentDataType AliHLTMUONRootifierComponent::GetOutputDataType()
{
	/// Inherited from AliHLTComponent. Returns kAliHLTMultipleDataType
	/// refer to GetOutputDataTypes for all returned data types.
	
	return kAliHLTMultipleDataType;
}


int AliHLTMUONRootifierComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
{
	/// Inherited from AliHLTComponent. Returns the output data types.
	
	tgtList.push_back(kAliHLTAnyDataType);
	return tgtList.size();
}


void AliHLTMUONRootifierComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
{
	///
	/// Inherited from AliHLTProcessor. Returns the list of expected input data types.
	///
	
	list.push_back(kAliHLTAnyDataType);
}


void AliHLTMUONRootifierComponent::GetOutputDataSize(
		unsigned long& constBase, double& inputMultiplier
	)
{
	///
	/// Inherited from AliHLTComponent. Returns an estimate of the expected output data size.
	///
	
	constBase = 1024*1024;
	inputMultiplier = 100;
}


AliHLTComponent* AliHLTMUONRootifierComponent::Spawn()
{
	///
	/// Inherited from AliHLTComponent. Creates a new object instance.
	///
	
	return new AliHLTMUONRootifierComponent();
}


int AliHLTMUONRootifierComponent::DoEvent(
		const AliHLTComponentEventData& evtData,
		AliHLTComponentTriggerData& trigData
	)
{
	///
	/// Inherited from AliHLTProcessor. Processes the new event data.
	///
	
	AliHLTMUONEvent event(evtData.fEventID);
	const AliHLTComponentBlockData* block = NULL;
	AliHLTUInt32_t specification = 0;  // Contains the output data block spec bits.

	// First process the blocks of reconstructed hits and trigger records.
	for (int i = 0; i < GetNumberOfInputBlocks(); i++)
	{
		block = GetInputBlock(i);
		assert( block != NULL );
		
		HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.",
			i, DataType2Text(block->fDataType).c_str(), block->fPtr, block->fSize
		);
		
		if (block->fDataType == AliHLTMUONConstants::RecHitsBlockDataType())
		{
			specification |= block->fSpecification;
			AliHLTMUONRecHitsBlockReader inblock(block->fPtr, block->fSize);
			if (not BlockStructureOk(inblock))
			{
				if (DumpDataOnError()) DumpEvent(evtData, trigData);
				continue;
			}
			
			// Decode the source DDL from the specification bits.
			Int_t sourceDDL = -1;
			bool ddl[22];
			AliHLTMUONUtils::UnpackSpecBits(block->fSpecification, ddl);
			for (int k = 0; k < 22; k++)
			{
				if (ddl[k])
				{
					if (sourceDDL == -1)
					{
						sourceDDL = k+1;
					}
					else
					{
						HLTWarning("The input data block %d contains"
							" data from multiple DDL sources.", i
						);
					}
				}
			}
			if (sourceDDL > 20)
			{
				HLTWarning("The source DDL for input data block %d is %d."
					" The expected range for the DDL is [1..20].",
					i, sourceDDL
				);
			}
			
			for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
			{
				const AliHLTMUONRecHitStruct& h = inblock[n];
				event.Add(new AliHLTMUONRecHit(h.fX, h.fY, h.fZ, sourceDDL));
			}
		}
		else if (block->fDataType == AliHLTMUONConstants::TriggerRecordsBlockDataType())
		{
			specification |= block->fSpecification;
			AliHLTMUONTriggerRecordsBlockReader inblock(block->fPtr, block->fSize);
			if (not BlockStructureOk(inblock))
			{
				if (DumpDataOnError()) DumpEvent(evtData, trigData);
				continue;
			}
			
			// Decode the source DDL from the specification bits.
			Int_t sourceDDL = -1;
			bool ddl[22];
			AliHLTMUONUtils::UnpackSpecBits(block->fSpecification, ddl);
			for (int k = 0; k < 22; k++)
			{
				if (ddl[k])
				{
					if (sourceDDL == -1)
					{<commit_msg>Bug fix. Filling in chamber ID and detection element ID information correctly for reconstructed hit objects.<commit_after>/**************************************************************************
 * This file is property of and copyright by the ALICE HLT Project        * 
 * All rights reserved.                                                   *
 *                                                                        *
 * Primary Authors:                                                       *
 *   <NAME> <<EMAIL>>                                  *
 *                                                                        *
 * 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.                  *
 **************************************************************************/

/* $Id$ */

///
/// @file   AliHLTMUONRootifierComponent.cxx
/// @author <NAME> <<EMAIL>>
/// @date   29 Sep 2007
/// @brief  Implementation of the AliHLTMUONRootifierComponent component.
///

#include "AliHLTMUONRootifierComponent.h"
#include "AliHLTMUONEvent.h"
#include "AliHLTMUONConstants.h"
#include "AliHLTMUONUtils.h"
#include "AliHLTMUONRecHit.h"
#include "AliHLTMUONTriggerRecord.h"
#include "AliHLTMUONMansoTrack.h"
#include "AliHLTMUONDecision.h"
#include "TClonesArray.h"
#include <cassert>

ClassImp(AliHLTMUONRootifierComponent);


AliHLTMUONRootifierComponent::AliHLTMUONRootifierComponent() :
	AliHLTMUONProcessor(),
	fWarnForUnexpecedBlock(false)
{
	///
	/// Default constructor.
	///
}


AliHLTMUONRootifierComponent::~AliHLTMUONRootifierComponent()
{
	///
	/// Default destructor.
	///
}


bool AliHLTMUONRootifierComponent::IgnoreArgument(const char* arg) const
{
	/// Return true if the argument is one of -cdbpath -run or -delaysetup
	/// to prevent the parent class from parsing these arguments in DoInit.
	
	if (strcmp(arg, "-cdbpath") == 0 or strcmp(arg, "-run") == 0 or
	    strcmp(arg, "-delaysetup") == 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}


int AliHLTMUONRootifierComponent::DoInit(int argc, const char** argv)
{
	///
	/// Inherited from AliHLTComponent.
	/// Parses the command line parameters and initialises the component.
	///
	
	HLTInfo("Initialising dHLT rootifier component.");

	// Inherit the parents functionality.
	int result = AliHLTMUONProcessor::DoInit(argc, argv);
	if (result != 0) return result;
	
	fWarnForUnexpecedBlock = false;
	
	for (int i = 0; i < argc; i++)
	{
		if (ArgumentAlreadyHandled(i, argv[i])) continue;

		if (strcmp(argv[i], "-warn_on_unexpected_block") == 0)
		{
			fWarnForUnexpecedBlock = true;
			continue;
		}

		HLTError("Unknown option '%s'.", argv[i]);
		return -EINVAL;
	}
	
	return 0;
}


int AliHLTMUONRootifierComponent::DoDeinit()
{
	///
	/// Inherited from AliHLTComponent. Performs a cleanup of the component.
	///
	
	HLTInfo("Deinitialising dHLT rootifier component.");
	return 0;
}


const char* AliHLTMUONRootifierComponent::GetComponentID()
{
	///
	/// Inherited from AliHLTComponent. Returns the component ID.
	///
	
	return AliHLTMUONConstants::RootifierComponentId();
}


AliHLTComponentDataType AliHLTMUONRootifierComponent::GetOutputDataType()
{
	/// Inherited from AliHLTComponent. Returns kAliHLTMultipleDataType
	/// refer to GetOutputDataTypes for all returned data types.
	
	return kAliHLTMultipleDataType;
}


int AliHLTMUONRootifierComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
{
	/// Inherited from AliHLTComponent. Returns the output data types.
	
	tgtList.push_back(kAliHLTAnyDataType);
	return tgtList.size();
}


void AliHLTMUONRootifierComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
{
	///
	/// Inherited from AliHLTProcessor. Returns the list of expected input data types.
	///
	
	list.push_back(kAliHLTAnyDataType);
}


void AliHLTMUONRootifierComponent::GetOutputDataSize(
		unsigned long& constBase, double& inputMultiplier
	)
{
	///
	/// Inherited from AliHLTComponent. Returns an estimate of the expected output data size.
	///
	
	constBase = 1024*1024;
	inputMultiplier = 100;
}


AliHLTComponent* AliHLTMUONRootifierComponent::Spawn()
{
	///
	/// Inherited from AliHLTComponent. Creates a new object instance.
	///
	
	return new AliHLTMUONRootifierComponent();
}


int AliHLTMUONRootifierComponent::DoEvent(
		const AliHLTComponentEventData& evtData,
		AliHLTComponentTriggerData& trigData
	)
{
	///
	/// Inherited from AliHLTProcessor. Processes the new event data.
	///
	
	AliHLTMUONEvent event(evtData.fEventID);
	const AliHLTComponentBlockData* block = NULL;
	AliHLTUInt32_t specification = 0;  // Contains the output data block spec bits.

	// First process the blocks of reconstructed hits and trigger records.
	for (int i = 0; i < GetNumberOfInputBlocks(); i++)
	{
		block = GetInputBlock(i);
		assert( block != NULL );
		
		HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.",
			i, DataType2Text(block->fDataType).c_str(), block->fPtr, block->fSize
		);
		
		if (block->fDataType == AliHLTMUONConstants::RecHitsBlockDataType())
		{
			specification |= block->fSpecification;
			AliHLTMUONRecHitsBlockReader inblock(block->fPtr, block->fSize);
			if (not BlockStructureOk(inblock))
			{
				if (DumpDataOnError()) DumpEvent(evtData, trigData);
				continue;
			}
			
			// Decode the source DDL from the specification bits.
			Int_t sourceDDL = -1;
			bool ddl[22];
			AliHLTMUONUtils::UnpackSpecBits(block->fSpecification, ddl);
			for (int k = 0; k < 22; k++)
			{
				if (ddl[k])
				{
					if (sourceDDL == -1)
					{
						sourceDDL = k+1;
					}
					else
					{
						HLTWarning("The input data block %d contains"
							" data from multiple DDL sources.", i
						);
					}
				}
			}
			if (sourceDDL > 20)
			{
				HLTWarning("The source DDL for input data block %d is %d."
					" The expected range for the DDL is [1..20].",
					i, sourceDDL
				);
			}
			
			for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
			{
				const AliHLTMUONRecHitStruct& h = inblock[n];
				AliHLTUInt8_t chamber;
				AliHLTUInt16_t detElemId;
				AliHLTMUONUtils::UnpackRecHitFlags(h.fFlags, chamber, detElemId);
				event.Add(new AliHLTMUONRecHit(h.fX, h.fY, h.fZ, sourceDDL, detElemId, chamber));
			}
		}
		else if (block->fDataType == AliHLTMUONConstants::TriggerRecordsBlockDataType())
		{
			specification |= block->fSpecification;
			AliHLTMUONTriggerRecordsBlockReader inblock(block->fPtr, block->fSize);
			if (not BlockStructureOk(inblock))
			{
				if (DumpDataOnError()) DumpEvent(evtData, trigData);
				continue;
			}
			
			// Decode the source DDL from the specification bits.
			Int_t sourceDDL = -1;
			bool ddl[22];
			AliHLTMUONUtils::UnpackSpecBits(block->fSpecification, ddl);
			for (int k = 0; k < 22; k++)
			{
				if (ddl[k])
				{
					if (sourceDDL == -1)
					{
{'fraction_non_alphanumeric': 0.12987924740241505, 'fraction_numerical': 0.007652344846953103, 'mean_word_length': 3.1075547866205304, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5448770', 'n_tokens_mistral': 5077, 'n_tokens_neox': 4517, 'n_words': 1152}