def collapse(l, raw):
    logger_ts.info("enter collapse")
    _master = {}
    _dsn = ""
    try:
        _pc = l[0]["mode"]
        for entry in l:
            dsn = entry['dataSetName']
            _dsn = dsn
            _current = entry
            if dsn not in _master:
                logger_ts.info("collapsing: {}".format(dsn))
                print("collapsing: {}".format(dsn))
                _master, _current = _collapse_root(_master, _current, dsn, _pc)
                try:
                    _master[dsn]["paleoData"] = raw[dsn]["paleoData"]
                    if "chronData" in raw[dsn]:
                        _master[dsn]["chronData"] = raw[dsn]["chronData"]
                except KeyError as e:
                    print("collapse: Could not collapse an object the dataset: {}, {}".format(dsn, e))
            _master = _collapse_pc(_master, _current, dsn, _pc)
        if len(_master) == 1:
            _master = _master[_dsn]
            print("Created LiPD data: 1 dataset")
        else:
            print("Created LiPD data: {} datasets".format(len(_master)))
    except Exception as e:
        print("Error: Unable to collapse time series, {}".format(e))
        logger_ts.error("collapse: Exception: {}".format(e))
    logger_ts.info("exit collapse")
    return _master