A necessary and sufficient condition for the nontrivial limit of the derivative martingale in a branching random walk