function restoreLoggers(obj, modelHIncludingLoggers)
%

%   Copyright 2014 The MathWorks, Inc.

    if nargin<2
        modelHIncludingLoggers = [];
    end
    
    if ~isempty(modelHIncludingLoggers)
        restoreDirtyness = true;
        origDirty = get_param(modelHIncludingLoggers,'Dirty');
    else
        restoreDirtyness = false;
    end

    if ~isempty(obj.ExistingLoggerConfig)
        if isfield(obj.ExistingLoggerConfig,'Signal')
            SignalLoggerConfig = obj.ExistingLoggerConfig.Signal;
            numPortset = length(SignalLoggerConfig);
            numPorts = length(obj.PortHsToLog);
            loggerFields = fields(SignalLoggerConfig);
            numFields = length(loggerFields);
            for idx=1:numPorts
                if numPortset >= idx
                    for jdx=1:numFields
                        set_param(obj.PortHsToLog(idx),loggerFields{jdx},...
                            SignalLoggerConfig(idx).(loggerFields{jdx}));
                    end
                end
            end
        end
        if isfield(obj.ExistingLoggerConfig,'DSM')
            DSMLoggerConfig = obj.ExistingLoggerConfig.DSM;
            numDSMset = length(DSMLoggerConfig);
            numDSMs = length(obj.dsmHsToLog);
            loggerFields = fields(DSMLoggerConfig);
            numFields = length(loggerFields);
            for idx=1:numDSMs
                if numDSMset >= idx
                    for jdx=1:numFields
                        set_param(obj.dsmHsToLog(idx),loggerFields{jdx},...
                            DSMLoggerConfig(idx).(loggerFields{jdx}));
                    end
                end
            end
        end
        obj.ExistingLoggerConfig = [];
    end
    
     if restoreDirtyness
        set_param(modelHIncludingLoggers,'Dirty',origDirty);       
    end
end