A man visiting his son in Chicago's Cook County Jail last Saturday spent more than 30 hours trapped alone in a room after a door closed behind him in a maximum security area.

He managed to alert the fire department by breaking a fire sprinkler on the ceiling with his hands, Larry Langford, a spokesperson for the Chicago Fire Department, told USA TODAY Network.

Water flowed out of the sprinkler and triggered an automatic alarm, according to Langford. "It was raining in the room when we got there," he said.

The fire department arrived around 1:30 a.m. Monday after the man had accidentally walked into the wrong room around 6 p.m. Saturday, said Cara Smith, the jail's executive director, to USA TODAY Network.

The man's son had recently been moved to a new division of the jail, and the man had never visited that area before, according to Smith.

He was instructed to go down the hallway to the right. On his way to the set of doors that would have taken him to the correct area, he encountered a door that was propped open, Smith said.

"On the door it said 'visitor vestibule' so he very logically thought that was where he was supposed to be," she said.

The doors somehow closed behind him after he entered the room and he was trapped. They are still investigating why the doors were open, but Smith said they may have been propped by contractors hired to install cameras in the space.

The room has steel doors and 2-feet concrete walls and is not used on weekends, which is why no one heard him or found him earlier, Smith said.

The man injured his thumb in the process of breaking the sprinkler and had to get a few stitches, but was otherwise in good condition, according to Smith.

"The good news is that he's OK. We are exceptionally grateful for that, and we are looking at every aspect of how this came about," she said.