During an instructional class for crime scene investigators inside San Francisco’s Hall of Justice at 850 Bryant St.,a veteran inspector began a discussion on single action vs. double action firearms when — kaboom! — his gun fired a bullet straight through a cubicle wall.

No one was hurt, but a person familiar with the Aug. 8 incident inside Room 442 later joked, “The investigators got a crime scene to investigate all right — their office.”

The accidental discharge was just one of 29 unplanned shootings by the city’s police officers since 2005, when the department began tracking all shots fired, planned or otherwise. Documents that summarize the incidents showed that San Francisco officers have, to their great displeasure, accidentally shot themselves in the hand (while cleaning a gun) and in the leg (while holstering) and in the foot (but of course).

Given the high number of gun-toting officers on the force — more than 2,000 — and the number of their daily interactions with firearms, an accidental discharge is rare. Almost statistically nonexistent.

But when they happen, they can be totally embarrassing. Aside from the collegial ribbing that comes after shot-gunning an innocent file cabinet (more on that later), a bad discharge can also stain an officer’s personnel file. One law enforcement authority told us the blunder goes under-reported. Our source theorized, “Would you call your commander to tell him you just shot off a round at home while cleaning your gun?”

Well, in San Francisco, at least three officers did.

According to the department reports, one officer fired his semi-automatic rifle into the cement floor of his Sunset District garage; another Sunset-dwelling cop blew out his living room window and destroyed the blinds.

The third, who lives in Richmond, was cleaning his personal .45-caliber handgun the evening of Jan. 8, 2008, when, the report reads, “he retracted the slide and accidentally discharged one round, which traveled through a window and into a neighbor’s backyard.”

Luckily, as the unsentimental reports so often conclude, “No one was injured.”

At every police station in the city officers can deposit their weapons into a “safety box” — a steel-clad locker designed to limit the chances of mishap. On at least two occasions — once at the Taraval Station and another at the Richmond District station — officers managed to fire their weapons into the container.

On May 16, 2007 — a day that may live in misfire infamy — two unintended police shootings took place in San Francisco. At about 7 p.m. a homicide inspector at the Hall of Justice was preparing to book a sawed-off shotgun into evidence. As he attempted to “clear the weapon” — or, remove the shells — he shot the base of a filing cabinet.

A few hours later across town at the Bayview Station, a field training officer with his new recruit in tow ended his shift. The field training officer, clearing his shotgun, thought there were five rounds to remove.

There were six.

“Believing the weapon to be empty,” the report reads, “the field training officer attempted to lock back the slide; his hand slipped, and the sixth round discharged skyward.”

Sometimes, officers appear to suffer from plain bad luck.

On Aug. 18, 2008, at 4:30 p.m., cops from the Ingleside Station were sneaking up on suspected gang house to serve a search warrant when a veteran officer carrying a shotgun — well, we’ll let the report take it from here:

“The officer ran across an uneven surface when his knee buckled, causing the officer to fall forward. Not wanting to drop his weapon, the officer clenched both hands on the shotgun and accidentally pulled the trigger with his right hand. One round was discharged into the ground, about six feet ahead of the officer.”

A SWAT team entered a smoke-filled house on New Year’s Day 2007 to capture a parole violator believed to be armed and dangerous. Wearing a gas mask and tasked with conducting a search of the rear bedroom, one officer swung his M-4 rifle to his rear side in order to use both his hands to open closet doors and sift through dresser drawers. “It is suspected that the officer’s rifle snagged upon his equipment with sufficient force to disengage the safety and discharge his weapon,” the report reads.

Other times, casual curiosity sets in and has near-deadly consequences.

“A patrol officer assigned to the Mission District was sitting alone in the station lunchroom,” the report from Aug. 12, 2008, begins. “At this time he noticed some ‘wear and tear’ on his department-issued firearm. The officer drew his weapon, locked the slide back and removed the magazine. He inspected the weapon and determined that any damage was cosmetic. He then reloaded the weapon and — intending to de-cock the firearm — pulled the trigger, discharging one round into the floor.”

No one, the report concluded, was injured.

JUSTIN BERTON is a general assignment reporter at The San Francisco Chronicle. You can follow him on Twitter at http://twitter.com/#!/justinberton