Belle II Software development
GlobalParamTimeLine Class Reference

Convenient class to automatically create payloads from allowed time depedence of parameter, load their value from database, update te constants one by one usually from Millepde result) and output the final payloads (including EventDependencies) such that one can store them (updated) in the database. More...

#include <GlobalTimeLine.h>

Public Member Functions

 GlobalParamTimeLine (const std::vector< EventMetaData > &events, GlobalLabel &label, const GlobalParamVector &vector)
 Constructor.
 
void loadFromDB ()
 Load every single payload with the content in database at its corresponding event (when it should start to be valid) WARNING: This is potentionally a very expensive operation with lots of HTTP communication TODO: make the loading from DB slightly more optimized -> needs change in GlobalParamSet<...>
 
void updateGlobalParam (GlobalLabel label, double correction, bool resetParam=false)
 Add a correction to any payload's parameter in the timeline.
 
std::vector< std::pair< IntervalOfValidity, TObject * > > releaseObjects ()
 Release all the objects (you become the owner!) for DB storage.
 

Private Attributes

TimeTable timeTable {}
 The final TimeTable with payload indices.
 
PayloadsTable payloadsTable {}
 Table with payloads.
 

Detailed Description

Convenient class to automatically create payloads from allowed time depedence of parameter, load their value from database, update te constants one by one usually from Millepde result) and output the final payloads (including EventDependencies) such that one can store them (updated) in the database.

Definition at line 146 of file GlobalTimeLine.h.

Constructor & Destructor Documentation

◆ GlobalParamTimeLine()

GlobalParamTimeLine ( const std::vector< EventMetaData > &  events,
GlobalLabel label,
const GlobalParamVector vector 
)

Constructor.

Parameters
eventsvector of events to interpret time ids from GlobalLabel
label(only for style) - static functions called to read the mapping of parameters and time intervals
vectorthe global vector initialized with DB objects for which payloads shoudl be generated WARNING: do not construct() or loadFromDB() the vector - use it "raw" - the internal object handlers are copied into the payloads table constructing the internal DB objects would result in copiyng them around, too

Definition at line 220 of file GlobalTimeLine.cc.

221 : timeTable(makeInitialTimeTable(events, label))
222 {
223 finalizeTimeTable(timeTable);
224 payloadsTable = TimeIdsTable2PayloadsTable(timeTable, vector);
225
226 }
PayloadsTable payloadsTable
Table with payloads.
TimeTable timeTable
The final TimeTable with payload indices.

Member Function Documentation

◆ loadFromDB()

void loadFromDB ( )

Load every single payload with the content in database at its corresponding event (when it should start to be valid) WARNING: This is potentionally a very expensive operation with lots of HTTP communication TODO: make the loading from DB slightly more optimized -> needs change in GlobalParamSet<...>

Definition at line 228 of file GlobalTimeLine.cc.

229 {
230 std::map<std::tuple<int, int, int>, std::vector<std::shared_ptr<GlobalParamSetAccess>>> eventPayloads{};
231 for (auto& row : payloadsTable) {
232 for (auto& iovBlock : row.second) {
233 for (auto& payload : iovBlock.second) {
234 auto eventTuple = std::make_tuple((int)payload.first.getExperiment(), (int)payload.first.getRun(), (int)payload.first.getEvent());
235 auto iter_and_inserted = eventPayloads.insert(
236 {eventTuple, std::vector<std::shared_ptr<GlobalParamSetAccess>>()}
237 );
238 iter_and_inserted.first->second.push_back(payload.second);
239 }
240 }
241 }
242 for (auto event_payloads : eventPayloads) {
243 auto event = EventMetaData(std::get<2>(event_payloads.first), std::get<1>(event_payloads.first), std::get<0>(event_payloads.first));
244 DBStore::Instance().update(event);
245 DBStore::Instance().updateEvent(event.getEvent());
246 for (auto& payload : event_payloads.second) {
247 payload->loadFromDBObjPtr();
248 }
249 }
250 }
static DBStore & Instance()
Instance of a singleton DBStore.
Definition: DBStore.cc:28
void updateEvent()
Updates all intra-run dependent objects.
Definition: DBStore.cc:142
void update()
Updates all objects that are outside their interval of validity.
Definition: DBStore.cc:79

◆ releaseObjects()

std::vector< std::pair< IntervalOfValidity, TObject * > > releaseObjects ( )

Release all the objects (you become the owner!) for DB storage.

Returns
vector of pairs. First is the IoV to store this in DB. Second is the object (payload) itself. Note that this might be EventDependencies in case objects can change inside runs

Definition at line 279 of file GlobalTimeLine.cc.

280 {
281 std::vector<std::pair<IntervalOfValidity, TObject*>> result;
282
283 for (auto& row : payloadsTable) {
284 for (auto& iovBlock : row.second) {
285 auto iov = iovBlock.first;
286 auto obj = iovBlock.second.at(0).second->releaseObject();
287
288 // non-intra-run
289 if (iovBlock.second.size() == 1) {
290 if (obj)
291 result.push_back({iov, obj});
292
293 continue;
294 }
295
296 // First obj in event dependency
297 //TODO: how the lifetime of EventDependency is handled?
298 // both work now -> have to check data storage in DB in real life scenario
299 auto payloads = new EventDependency(obj);
300 //auto payloads = EventDependency(obj);
301 // Add others
302 for (long unsigned int iObj = 1; iObj < iovBlock.second.size(); ++iObj) {
303 auto nextEvent = iovBlock.second.at(iObj).first.getEvent();
304 auto nextObj = iovBlock.second.at(iObj).second->releaseObject();
305
306 if (nextObj)
307 payloads->add(nextEvent, nextObj);
308 //payloads.add(nextEvent, nextObj);
309 }
310 result.push_back({iov, payloads});
311 //result.push_back({iov, &payloads});
312 }
313 }
314 return result;
315 }

◆ updateGlobalParam()

void updateGlobalParam ( GlobalLabel  label,
double  correction,
bool  resetParam = false 
)

Add a correction to any payload's parameter in the timeline.

Parameters
labelthe label any global parameter constructed from integer after Millepede calibration The mapping of time intervals has to be loaded for the label to provide correct infortmation about its validity in time intervals -> all payloads are updated until the end of validity of this parameter
correctionthe value to be added to the given constant
resetParamif True, the parameters is not updated with correction, but set to 'correction' value This has special use-case when filling the objects with errors/corrections data instead of absolute parameter values

Definition at line 252 of file GlobalTimeLine.cc.

253 {
254 auto timeid = label.getTimeId();
255 auto eov = label.getEndOfValidity();
256 auto uid = label.getUniqueId();
257
258 std::set<int> payloadIndices;
259 // this is probably dangerous if we do not impose additional invariant
260 //TODO: better to always loop over whole event header?
261 for (int i = timeid; i < std::min(eov + 1, int(std::get<EventHeader>(timeTable).size())); ++i) {
262 payloadIndices.insert(getContinuousIndexByTimeID(timeTable, uid, i));
263 }
264
265 for (auto payloadIndex : payloadIndices) {
266 auto payload = getPayloadByContinuousIndex(payloadsTable, label.getUniqueId(), payloadIndex).second;
267 // If not found, we get an empty payload shared ptr
268 if (payload) {
269 if (resetParam) {
270 payload->setGlobalParam(correction, label.getElementId(), label.getParameterId());
271 } else {
272 payload->updateGlobalParam(correction, label.getElementId(), label.getParameterId());
273 }
274 }
275 }
276
277 }

Member Data Documentation

◆ payloadsTable

PayloadsTable payloadsTable {}
private

Table with payloads.

Definition at line 152 of file GlobalTimeLine.h.

◆ timeTable

TimeTable timeTable {}
private

The final TimeTable with payload indices.

Definition at line 150 of file GlobalTimeLine.h.


The documentation for this class was generated from the following files: