function codeCoverageClass = getActiveCodeCoverageClass...
(hooks, lTopModelStandalone)
%

% Copyright 2014 The MathWorks, Inc.

% Returns the name of the active code coverage class, or an empty string if no
% code coverage is active

codeCoverageClass='';
activeClassIdx = false(size(hooks));

if ~isempty(hooks)
[~, toolClasses] = coder.coverage.CodeCoverageHelper.getTools();
end

for i=1:length(hooks)
hook = hooks(i);
if any(strcmp(toolClasses, hook.className));

% Test if this is a Model block SIL or PIL simulation
% with code coverage for referenced models switched off
% (i.e. code coverage is effectively switched off)
modelBlockSilOrPilWithNoCodeCov = ...
~lTopModelStandalone && ...
strcmp(hook.includeReferencedModels,'off');

% Check if coverage is completely switched off
coverageOff = strcmp(hook.includeReferencedModels,'off') && ...
strcmp(hook.includeTopModel,'off');

% Filter out arguments that should not affect the checksum
if strcmp(hook.enabled,'on') && ~coverageOff && ...
~modelBlockSilOrPilWithNoCodeCov
activeClassIdx(i)=true;
end
end
end

if any(activeClassIdx)
assert(sum(activeClassIdx)<=1, ...
'There cannot be more than one code coverage tool enabled');
codeCoverageClass = hooks(activeClassIdx).className;
end