67 def fetch_iovs(folder_name, since=None, until=None, channels=None, tag="",
68 what="all", max_records=-1, with_channel=True, loud=False,
69 database=None, convert_time=False, named_channels=False,
70 selection=None, runs=None, with_time=False, unicode_strings=False):
72 Helper to fetch objects in a pythonic manner
73 `folder_name` may be an abbreviated name (DQMFONL) or a fully-qualified name
74 (e.g. /GLOBAL/DETSTATUS/DQMFONL)
75 `since`, `until` can be (run, lumi) tuples, or standard iov keys
76 `channels` can be a cool ChannelSelection object or a list of ids/names
78 `what` is a list of strings specifying which records should be fetched
79 if it is the string "all" (not a list), then all records are fetched,
80 and naming is turned on.
81 `max_records` specifies the maximum number of records to fetch. -1 means all
82 `with_channel` specifies whether the channel number should be in the result
84 `loud` specifies whether quick_retrieve (C++ function) should print its
85 status every 1000 objects
86 `database` can be used to specify an abbreviated database, or a connection
88 `convert_time` performs a conversion of `since` and `until` from runlumi
89 to nanoseconds since the epoch.
90 `named_channels` causes the iovs returned to contain strings in the channel
92 `selection` [NOT IMPLEMENTED YET] create a cool selection object
93 `runs` if it is an integer, it is a run number. If it is a tuple, it is a
95 `with_time` retrieve insertiontime for iovs
96 `unicode_strings` return unicode string objects, assuming database content
99 from .quick_retrieve
import quick_retrieve, browse_coracool, get_coracool_payload_spec
101 if channels == []:
return IOVSet()
105 channel_mapping =
None
106 if isinstance(folder_name, str):
107 folder = Databases.get_folder(folder_name, database)
111 folder_name = folder.fullPath()
113 log.error(
"Exception when interpreting folder: {0}".
format(folder_name))
116 log.info(
"Querying %s", folder_name)
117 log.debug(
"Query range: [%s, %s]", since, until)
119 short_folder = folder.fullPath().
split(
"/")[-1]
121 time_based_folder =
"<timeStamp>time</timeStamp>" in folder.description()
122 coracool_folder =
"<coracool>" in folder.description()
123 iov_key_type = TimestampType
if time_based_folder
else RunLumiType
125 if time_based_folder
and (convert_time
or runs):
135 since, until = runrange.first.StartTime, runrange.last.EndTime
136 return fetch_iovs(folder_name, since, until, channels, tag, what,
137 max_records, with_channel, loud,
138 database, convert_time=
False,
139 named_channels=named_channels, selection=selection,
141 unicode_strings=unicode_strings)
145 detstatus_names =
"DQMFOFL",
"DCSOFL",
"DQMFONL",
"SHIFTOFL",
"SHIFTONL",
"LBSUMM"
146 if any(short_folder.endswith(x)
for x
in detstatus_names):
147 channel_mapping =
None
150 cm_reversed = dict((value, key)
for key, value
in six.iteritems(channelmap))
151 channelmap.update(cm_reversed)
152 channel_mapping = channelmap
156 field_name =
"%s_VAL" % short_folder
158 if not coracool_folder:
160 what = folder.folderSpecification().payloadSpecification().
keys()
166 folder.setPrefetchAll(
False)
170 iterator = folder.browseObjects(since, until, channels, tag, sel)
172 iterator = folder.browseObjects(since, until, channels, tag)
176 fields.append(
"insertion_time")
178 fields.append(
"channel")
183 result =
quick_retrieve(iterator, record, what, max_records, with_channel,
184 loud, iov_key_type, channelmap, with_time,
188 args = folder_name, database
189 database, folder_path = Databases.resolve_folder_string(*args)
192 assert database,
"Coracool folder - you must specify a database"
194 db = Databases.get_instance(database)
199 assert isinstance(what, list), (
"Coracool folder - you must specify "
200 "`what` to fetch (it cannot be inferred, as with non-coracool.)")
207 what, record, element, iov_key_type)
209 result = IOVSet(result, iov_type=record, origin=short_folder)