When may you legally drive around or under a railroad crossing gate?

Do not go around or under any lowered gate at a railroad crossing. Once the gate is raised, do not proceed across the tracks until you can see clearly in both directions and are sure there are no trains coming.
DMV Writen Test