function [dataMat, out, justifiedHits] = getAPIMetricInfo(cvd, metricName, blockCvId, ignoreDescendants, includeAllSizes)
%

% Copyright 1990-2015 The MathWorks, Inc.
    out = [];
    justifiedHits = [];
     
    try
        if isfield(cvd.metrics, metricName)
            dataMat = cvd.metrics.(metricName);
        elseif isfield(cvd.metrics,'testobjectives') &&  isfield(cvd.metrics.testobjectives, metricName)
            dataMat = cvd.metrics.testobjectives.(metricName);
        end
    catch
        % If data.metrics does not have a name specified by metricName
        dataMat = [];
    end
    if isempty(dataMat)
        return;
    end
    
    if cvi.ReportUtils.checkInternalRationale(cvi.ReportUtils.getFilterRationale(blockCvId))
        %masked out: no data;
        return;
    end
    
    metricEnum =  cvi.MetricRegistry.getEnum(metricName);
            
    [totalCnt,varTotalCntIdx,totalIdx,justifiedTotalIdx,...
        localCnt,varLocalCntIdx,localIdx, justifiedLocalIdx,...
        hasVariableSize, hasLocalVariableSize] = cv('MetricGet',blockCvId,metricEnum, ...
                                               '.dataCnt.deep','.dataCnt.varDeepIdx','.dataIdx.deep','.justifiedDataIdx.deep',...
                                               '.dataCnt.shallow','.dataCnt.varShallowIdx','.dataIdx.shallow','.justifiedDataIdx.shallow',...
                                               '.hasVariableSize', '.hasLocalVariableSize');
    if ignoreDescendants
        if localIdx < 0
            return;
        end
        hits = dataMat(localIdx+1);
        justifiedHits = dataMat(justifiedLocalIdx+1);
       
        if hasLocalVariableSize
           varLocalCnt = dataMat(varLocalCntIdx + 1);
           if includeAllSizes 
               out = [hits varLocalCnt localCnt];
            else
               out = [hits varLocalCnt];
            end
        else
            out = [hits localCnt];
        end
    else
        if totalIdx < 0
            return;
        end
        hits = dataMat(totalIdx+1);
        justifiedHits = dataMat(justifiedTotalIdx+1);
        executedIn = cvd.getTrace(metricName, totalIdx + 1, false);   

        if hasVariableSize 
            varTotalCnt = dataMat(varTotalCntIdx + 1);
            if includeAllSizes 
               out = [hits varTotalCnt totalCnt];
            else
               out = [hits varTotalCnt];
            end
        elseif hasLocalVariableSize 
            varLocalCnt  = dataMat(varLocalCntIdx + 1);
            if includeAllSizes 
               out = [hits varLocalCnt  totalCnt];
            else
               out = [hits varLocalCnt];
            end
        else
            out = [hits totalCnt];
        end
    end



