68 selection=None, runs=None, with_time=False, unicode_strings=False):
69 """
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
75 `tag` COOL folder tag
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
81 list of each tuple
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
85 string
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
89 identifier
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
92 run range.
93 `with_time` retrieve insertiontime for iovs
94 `unicode_strings` return unicode string objects, assuming database content
95 is UTF-8
96 """
97 from .quick_retrieve import quick_retrieve, browse_coracool, get_coracool_payload_spec
98
99 if channels == []: return IOVSet()
100
101 since, until = get_query_range(since, until, runs)
102
103 channel_mapping = None
104 if isinstance(folder_name, str):
105 folder = Databases.get_folder(folder_name, database)
106 else:
107 try:
108 folder = folder_name
109 folder_name = folder.fullPath()
110 except Exception:
111 log.error("Exception when interpreting folder: {0}".format(folder_name))
112 raise
113
114 log.info("Querying %s", folder_name)
115 log.debug("Query range: [%s, %s]", since, until)
116
117 short_folder = folder.fullPath().
split(
"/")[-1]
118
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
122
123 if time_based_folder and (convert_time or runs):
124
125
126
127
128
129 until =
min(until, RunLumi(100000000, 0))
130 runrange = fetch_iovs("LBLB", since, until)
131 if runrange:
132
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,
138 with_time=with_time,
139 unicode_strings=unicode_strings)
140 else:
141 return IOVSet()
142
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
146 else:
147 _, _, channelmap = get_channel_ids_names(folder)
148 cm_reversed = {value: key for key, value in channelmap.items()}
149 channelmap.update(cm_reversed)
150 channel_mapping = channelmap
151
152 channels = make_channelselection(channels, channel_mapping)
153
154 field_name = "%s_VAL" % short_folder
155
156 if not coracool_folder:
157 if what == "all":
158 what = folder.folderSpecification().payloadSpecification().keys()
159
160 channelmap = None
161 if named_channels:
162 _, _, channelmap = get_channel_ids_names(folder)
163
164 folder.setPrefetchAll(False)
165
166 if selection:
167 sel = make_browse_objects_selection(folder, selection)
168 iterator = folder.browseObjects(since, until, channels, tag, sel)
169 else:
170 iterator = folder.browseObjects(since, until, channels, tag)
171
172 fields = []
173 if with_time:
174 fields.append("insertion_time")
175 if with_channel:
176 fields.append("channel")
177 fields.extend(what)
178
179 record = make_iov_type(field_name, make_safe_fields(fields))
180
181 result =
quick_retrieve(iterator, record, what, max_records, with_channel,
182 loud, iov_key_type, channelmap, with_time,
183 unicode_strings)
184
185 else:
186 args = folder_name, database
187 database, folder_path = Databases.resolve_folder_string(*args)
188
189
190 assert database, "Coracool folder - you must specify a database"
191
192 db = Databases.get_instance(database)
194 if what == "all":
195 what = spec.keys()
196
197 assert isinstance(what, list), ("Coracool folder - you must specify "
198 "`what` to fetch (it cannot be inferred, as with non-coracool.)")
199
200 record = make_iov_type(field_name, ["channel", "elements"])
201
202 element = namedtuple("element", " ".join(make_safe_fields(what)))
203
205 what, record, element, iov_key_type)
206
207 result = IOVSet(result, iov_type=record, origin=short_folder)
208
209 return result
210
const cool::RecordSpecification get_coracool_payload_spec(IDatabasePtr cooldb, const string &folder)
PyObject * quick_retrieve(const IObjectIteratorPtr &objects, PyObject *object_converter, PyObject *to_fetch=NULL, const long max_records=-1, const bool with_channel=true, const bool loud=false, PyObject *iovkey_wrapper=NULL, PyObject *channel_name_mapping=NULL, const bool with_time=false, const bool as_unicode=false)
PyObject * browse_coracool(IDatabasePtr cooldb, const string &folder, ValidityKey since, ValidityKey until, const ChannelSelection &cs=ChannelSelection::all(), const char *tag="", PyObject *to_fetch=NULL, PyObject *object_converter=NULL, PyObject *inner_object_converter=NULL, PyObject *iovkey_wrapper=NULL)
std::vector< std::string > split(const std::string &s, const std::string &t=":")