bool createAbcArchiveCache( Abc::IArchive *pArchive, AbcArchiveCache* fullNameToObjectCache, CommonProgressBar *pBar ) {
	ESS_PROFILE_SCOPE("createAbcArchiveCache");
	EC_LOG_INFO( "Creating AbcArchiveCache for archive: " << pArchive->getName() );

	runonce();

	Abc::IObject top = pArchive->getTop();
	return addObjectToCache( fullNameToObjectCache, top, "", pBar ) != 0;
}
int delRefArchive(std::string const& path)
{
  ESS_PROFILE_SCOPE("delRefArchive");
  std::string resolvedPath = resolvePath(path);
  std::map<std::string, AlembicArchiveInfo>::iterator it;
  it = gArchives.find(resolvedPath);
  if (it == gArchives.end()) return -1;
  it->second.refCount--;
#ifdef _DEBUG
  EC_LOG_INFO("ref count (d): " << it->second.refCount);
#endif
  if (it->second.refCount == 0) {
#ifdef _DEBUG
    EC_LOG_INFO("ref delete");
#endif
    deleteArchive(resolvedPath);
    return 0;
  }
  return it->second.refCount;
}
void deleteArchive(std::string const& path)
{
  ESS_PROFILE_SCOPE("deleteArchive");
  std::string resolvedPath = resolvePath(path);
  std::map<std::string, AlembicArchiveInfo>::iterator it;
  it = gArchives.find(resolvedPath);
  if (it == gArchives.end()) return;

  EC_LOG_INFO("Closing Abc Archive: " << it->second.archive->getName());
  it->second.archive->reset();
  delete (it->second.archive);
  gArchives.erase(it);
}
int addRefArchive(std::string const& path)
{
  ESS_PROFILE_SCOPE("addRefArchive");
  if (path.empty()) return -1;
  std::string resolvedPath = resolvePath(path);

  // call get archive to ensure to create it!
  getArchiveFromID(path);
  std::map<std::string, AlembicArchiveInfo>::iterator it;
  it = gArchives.find(resolvedPath);
  if (it == gArchives.end()) return -1;
  it->second.refCount++;
#ifdef _DEBUG
  EC_LOG_INFO("ref count (a): " << it->second.refCount);
#endif
  return it->second.refCount;
}
Alembic::Abc::IArchive* getArchiveFromID(std::string const& path)
{
  ESS_PROFILE_SCOPE("getArchiveFromID-1");
  std::map<std::string, AlembicArchiveInfo>::iterator it;
  std::string resolvedPath = resolvePath(path);
  it = gArchives.find(resolvedPath);
  if (it == gArchives.end()) {
    // check if the file exists

    if (!boost::filesystem::exists(resolvedPath.c_str())) {
      ESS_LOG_ERROR("Can't find Alembic file.  Path: "
                    << path << "  Resolved path: " << resolvedPath);
      return NULL;
    }

    FILE* file = fopen(resolvedPath.c_str(), "rb");
    if (file == NULL) {
      return NULL;
    }
    else {
      fclose(file);

      AbcF::IFactory iFactory;
      AbcF::IFactory::CoreType oType;
      addArchive(new Abc::IArchive(iFactory.getArchive(resolvedPath, oType)));

      // addArchive(new Abc::IArchive( Alembic::AbcCoreHDF5::ReadArchive(),
      // resolvedPath));

      Abc::IArchive* pArchive = gArchives.find(resolvedPath)->second.archive;
      EC_LOG_INFO("Opening Abc Archive: " << pArchive->getName());
      return pArchive;
    }
  }
  return it->second.archive;
}