S + had + past participle (V3) + when/before/by the time + S + Vpast (V2)
S + Vpast (V2) + after + S + had + past participle (V3)
We need a comma if the conjunction begins the sentence.
When/before/by the time + S + Vpast (V2) , S + had + past participle (V3)
After + S + had + past participle (V3) , S + Vpast (V2)
We use the past perfect tense fairly often in English.
1: A completed action before something else in the past.
When we arrived, the film had started. (= first the film started, then later we arrived)
2: To explain or give a reason for something in the past.
I’d eaten dinner so I wasn’t hungry.
It had snowed in the night, so the bus didn’t arrive.
3: Stative verbs only: something that started in the past and continued up to another action in the past.
When he graduated, he had been in London for six years.
(= he arrived in London six years before he graduated and lived there continuously until he graduated, or even longer)
4: As part of the third conditional.
If I had known you were ill, I would have visited you.