Just a quick word about Sitges which is located about 30 minutes south of Barcelona by train.
Barcelona is an incredibly popular city which means it books out well ahead and is expensive for accommodation.
Sitges is a very attractive town to stay in if you're struggling to find reasonably priced accommodation in or near Barcelona. In it's own right this is a great place to go and experience. Great beaches, an historic town centre and waterfront and many accommodation and eating options.
The efficient Barcelona trains run to and from Sitges about every 20 minutes through the day.
Perhaps consider Sitges as an option if you're going to Barcelona.