The return order is guaranteed to match the supplied tag path list, so you should only need to call readBlocking() once.
As far as system.tag.query() it really depends on what you are needing. The function is really just a scripting implementation of the Tag Report Tool, so if you can configure the query in the tag report tool to get the results you're looking for, then the function can also return those results.
And to echo these other folks: if you're calling readBlocking multiple times in a row with single tag paths, your script is wrong, and you've stumbled onto one of the most common performance footguns in scripting.
Each readBlocking call from the client/designer implies at least two network hops - one to send out the list of tags, another to return the values from the gateway. Calling the function multiple times means you're paying that pain in series.
Calling from the gateway/in a Perspective context is less bad, but still not ideal for performance.
Yes, how quickly will your 3 calls now balloon into 300?
Also, you can do something like this (breaking out the logic to a function):
def chunker(seq, size):
return (seq[pos:pos + size] for pos in xrange(0,len(seq),size))
tagValues = [qv.value for qv in system.tag.readBlocking(pathAll)]
tagActive , tagValue, tagCode = [chunk for chunk in chunker(tagValues,3)]
Also, if you're doing this in a tagValue change script, don't. Move it to a Gateway Tag Change script. ValueChange scripts can't tolerate the round trip latency of tag reads (especially blocking ones).
tag_path_list = [x.get("fullPath") for x in system.tag.browse(folder_path)]
tag_list_active = [str(path) + "/IsActive" for path in tag_path_list]
tag_list_current = [str(path) + "/CurrentValue" for path in tag_path_list]
tag_list_code = [str(path) + "/ReasonCode" for path in tag_path_list]
tag_list_all = tag_list_active + tag_list_current
tag_list_all = system.tag.readBlocking(
tag_list_all
)
index = -1
min_current = float('inf')
n = len(tag_list_active)
tag_list_active = map(lambda x: x.value, tag_list_all[:n])
tag_list_current = map(lambda x: system.date.toMillis(x.timestamp), tag_list_all[:n])
for idx, (active, current) in enumerate(zip(tag_list_active, tag_list_current)):
if active and current < min_current:
min_current = current
index = idx
if index != -1:
reason_code = system.tag.readBlocking(
[tag_list_code[index]]
)[0].value
system.tag.writeAsync(
["[UNS]to/path/AlarmCode"], [reason_code]
)