65 def fetch_iovs(folder_name, since=None, until=None, channels=None, tag="",
66 what="all", max_records=-1, with_channel=True, loud=False,
67 database=None, convert_time=False, named_channels=False,
68 selection=None, runs=None, with_time=False, unicode_strings=False):
70 Helper to fetch objects in a pythonic manner
71 `folder_name` may be an abbreviated name (DQMFONL) or a fully-qualified name
72 (e.g. /GLOBAL/DETSTATUS/DQMFONL)
73 `since`, `until` can be (run, lumi) tuples, or standard iov keys
74 `channels` can be a cool ChannelSelection object or a list of ids/names
76 `what` is a list of strings specifying which records should be fetched
77 if it is the string "all" (not a list), then all records are fetched,
78 and naming is turned on.
79 `max_records` specifies the maximum number of records to fetch. -1 means all
80 `with_channel` specifies whether the channel number should be in the result
82 `loud` specifies whether quick_retrieve (C++ function) should print its
83 status every 1000 objects
84 `database` can be used to specify an abbreviated database, or a connection
86 `convert_time` performs a conversion of `since` and `until` from runlumi
87 to nanoseconds since the epoch.
88 `named_channels` causes the iovs returned to contain strings in the channel
90 `selection` [NOT IMPLEMENTED YET] create a cool selection object
91 `runs` if it is an integer, it is a run number. If it is a tuple, it is a
93 `with_time` retrieve insertiontime for iovs
94 `unicode_strings` return unicode string objects, assuming database content
97 from .quick_retrieve
import quick_retrieve, browse_coracool, get_coracool_payload_spec
99 if channels == []:
return IOVSet()
103 channel_mapping =
None
104 if isinstance(folder_name, str):
105 folder = Databases.get_folder(folder_name, database)
109 folder_name = folder.fullPath()
111 log.error(
"Exception when interpreting folder: {0}".
format(folder_name))
114 log.info(
"Querying %s", folder_name)
115 log.debug(
"Query range: [%s, %s]", since, until)
117 short_folder = folder.fullPath().
split(
"/")[-1]
119 time_based_folder =
"<timeStamp>time</timeStamp>" in folder.description()
120 coracool_folder =
"<coracool>" in folder.description()
121 iov_key_type = TimestampType
if time_based_folder
else RunLumiType
123 if time_based_folder
and (convert_time
or runs):
133 since, until = runrange.first.StartTime, runrange.last.EndTime
134 return fetch_iovs(folder_name, since, until, channels, tag, what,
135 max_records, with_channel, loud,
136 database, convert_time=
False,
137 named_channels=named_channels, selection=selection,
139 unicode_strings=unicode_strings)
143 detstatus_names =
"DQMFOFL",
"DCSOFL",
"DQMFONL",
"SHIFTOFL",
"SHIFTONL",
"LBSUMM"
144 if any(short_folder.endswith(x)
for x
in detstatus_names):
145 channel_mapping =
None
148 cm_reversed = {value: key
for key, value
in channelmap.items()}
149 channelmap.update(cm_reversed)
150 channel_mapping = channelmap
154 field_name =
"%s_VAL" % short_folder
156 if not coracool_folder:
158 what = folder.folderSpecification().payloadSpecification().
keys()
164 folder.setPrefetchAll(
False)
168 iterator = folder.browseObjects(since, until, channels, tag, sel)
170 iterator = folder.browseObjects(since, until, channels, tag)
174 fields.append(
"insertion_time")
176 fields.append(
"channel")
181 result =
quick_retrieve(iterator, record, what, max_records, with_channel,
182 loud, iov_key_type, channelmap, with_time,
186 args = folder_name, database
187 database, folder_path = Databases.resolve_folder_string(*args)
190 assert database,
"Coracool folder - you must specify a database"
192 db = Databases.get_instance(database)
197 assert isinstance(what, list), (
"Coracool folder - you must specify "
198 "`what` to fetch (it cannot be inferred, as with non-coracool.)")
205 what, record, element, iov_key_type)
207 result = IOVSet(result, iov_type=record, origin=short_folder)