How to form it: (had been) + (verb + ing)
THE BIG PICTURE: Use the past perfect continuous to show that something was in the process of happening up until another activity came along and interrupted it. All activity occurred in the past and does not continue up until now. The first activity is in the past perfect continuous tense, while the second activity is in the simple past tense. Example: Joan had been waiting for the limousine driver for two hours before he finally arrived.
You can also use this tense for showing cause and effect in the past.
Example: Jill was out of breath because she had been running on the treadmill for an hour.