Creates a function on a state_collection, which creates analysis_collections for each state in the collection.
    
    Optionally sorts the collection if the state_measure has a sort_by parameter (see funtool.lib.general.sort_states for details)

def _wrap_measure(individual_state_measure_process, state_measure, loaded_processes): 
    """
    Creates a function on a state_collection, which creates analysis_collections for each state in the collection.
    
    Optionally sorts the collection if the state_measure has a sort_by parameter (see funtool.lib.general.sort_states for details)
    """
    def wrapped_measure(state_collection,overriding_parameters=None,loggers=None):
        if loggers == None:
            loggers = funtool.logger.set_default_loggers()
        if loaded_processes != None :
            if state_measure.grouping_selectors != None:
                for grouping_selector_name in state_measure.grouping_selectors:
                    state_collection= funtool.state_collection.add_grouping(state_collection, grouping_selector_name, loaded_processes) 
            states= state_collection.states
            measure_parameters= get_measure_parameters(state_measure, overriding_parameters)
            if 'sort_by' in measure_parameters.keys():
                states= funtool.lib.general.sort_states(states, measure_parameters['sort_by'])
            for state_index,state in enumerate(states):
                step_size= len(states)//20
                if state_index % step_size == 0:
                    loggers.status_logger.warn("{}: {} %".format( datetime.datetime.now(), round((state_index/len(states) * 100 ), 1) ) )
                analysis_collection = funtool.analysis.AnalysisCollection(state,None,{},{})
                if state_measure.analysis_selectors != None:
                    for analysis_selector in state_measure.analysis_selectors:
                        analysis_collection = loaded_processes["analysis_selector"][analysis_selector].process_function(analysis_collection,state_collection)
                if analysis_collection != None:
                    individual_state_measure_process(analysis_collection,state_collection,overriding_parameters)
        return state_collection
    return wrapped_measure