Sample weighting with a ConcatDataset

Hi all,
I have combined 3 datasets using ConcatDataset. I was wondering if there is a way to tell from which original dataset a sample from the concatenated dataset came from (to use for weighting in the sampling process).
In addition I was wondering if there is an efficient way to determine the class at each index of the dataset - do I have to iterate over the entire dataset and store the class and index? This is quite expensive in my case.