Marijuana is not legal in Barcelona. The personalized use of marijuana has been decriminalized, but trafficking, selling, or carrying cannabis is a crime. You will need to join a cannabis club in order to acquire weed legally, which is obviously difficult for tourists.
Because using marijuana has been decriminalized, if you are able to get some on the black market and smoke it discretely you will likely be okay.