create or replace function proton_count (ob in number)
 return number as
  subtype dt_Handle is number;
  atoms dt_Handle;
  atom dt_Handle;
  hcount number := 0;
begin
  atoms := dt_stream(ob, 19);
  loop
    atom := dt_next(atoms);
    if (atom = 0) then
      exit;
    end if;
    if (dt_number(atom) = 1) then
      hcount := hcount + 1;
    end if;
    hcount := hcount + dt_imp_hcount(atom);
  end loop;
  return hcount;
end;
/
