RE: Relation between DimensionAttributeValueTotallingCriteria and MainAccount
You can see it from the existsForMainAccountReference() method where you have next select statement:
elect firstonly RecId from totallingCrit
where totallingCrit.FromValue <= _referenceMainAccountId
&& totallingCrit.ToValue >= _referenceMainAccountId
exists join dimAttrValue
where dimAttrValue.RecId == totallingCrit.DimensionAttributeValue
&& dimAttrValue.DimensionAttribute == DimensionAttribute::getMainAccountDimensionAttribute()
exists join mainAcct
where mainAcct.RecId == dimAttrValue.EntityInstance
&& mainAcct.LedgerChartOfAccounts == _chartOfAccounts;