9#include <alignment/dbobjects/VXDAlignment.h>
10#include <alignment/GlobalTimeLine.h>
11#include <alignment/Manager.h>
12#include <cdc/dbobjects/CDCAlignment.h>
13#include <framework/database/Configuration.h>
14#include <framework/database/Database.h>
15#include <framework/database/EventDependency.h>
16#include <framework/database/TestingPayloadStorage.h>
17#include <framework/dataobjects/EventMetaData.h>
18#include <vxd/dataobjects/VxdID.h>
20#include <gtest/gtest.h>
30using namespace alignment;
31using namespace timeline;
37 MockDBObj(
double value = 0.) : m_param(value) {}
40 static unsigned short getGlobalUniqueID()
42 static_assert(UID != 0,
"Non-zero UID required");
46 double getGlobalParam(
unsigned short element,
unsigned short param) {
return m_param;}
48 void setGlobalParam(
double value,
unsigned short element,
unsigned short param) {m_param = value;}
50 std::vector<std::pair<unsigned short, unsigned short>> listGlobalParams() {
return {{0, 0}};}
56 class TimeLineTest :
public ::testing::Test {
59 IntraIoVPayloads beamspotRun0 = {
60 {
EventMetaData(0, 0, 0), std::make_shared<GlobalParamSet<BeamSpot>>()}
63 IntraIoVPayloads beamspotRun1 = {
64 {
EventMetaData(0, 1, 0), std::make_shared<GlobalParamSet<BeamSpot>>()}
67 IntraIoVPayloads beamspotRun2 = {
68 {
EventMetaData(0, 2, 0), std::make_shared<GlobalParamSet<BeamSpot>>()},
69 {
EventMetaData(530532, 2, 0), std::make_shared<GlobalParamSet<BeamSpot>>()}
72 IntraIoVPayloads beamspotRun3 = {
73 {
EventMetaData(0, 3, 0), std::make_shared<GlobalParamSet<BeamSpot>>()}
76 IntraIoVPayloads beamspotRun4 = {
77 {
EventMetaData(0, 4, 0), std::make_shared<GlobalParamSet<BeamSpot>>()}
80 PayloadIovBlockRow beamspotRow = {
88 IntraIoVPayloads vxdRun0to2 = {
89 {
EventMetaData(0, 0, 0), std::make_shared<GlobalParamSet<VXDAlignment>>()},
92 IntraIoVPayloads vxdRun3toInf = {
93 {
EventMetaData(0, 3, 0), std::make_shared<GlobalParamSet<VXDAlignment>>()},
96 PayloadIovBlockRow vxdRow = {
102 IntraIoVPayloads cdcBlock = {
103 {
EventMetaData(0, 0, 0), std::make_shared<GlobalParamSet<CDCAlignment>>()}
106 PayloadIovBlockRow cdcRow = {
110 PayloadsTable payloadsTable = {
116 std::vector<int> head0 = {0, 1, 2, 3, 4, 5};
117 std::vector<int> head1 = {0, 1, 2, 2, 3, 4};
118 std::vector<int> row0 = {0, 1, 2, 3, 4, 5};
119 std::vector<int> row1 = {0, 0, 0, 0, 1, 1};
120 std::vector<int> row2 = {0, 0, 0, 0, 0, 0};
122 EventHeader eventHeader = {
131 RunHeader runHeader = {
140 TableData tableData = {
146 TimeTable timeTable = std::make_tuple(eventHeader, runHeader, tableData);
148 std::vector<int> irow0 = {0, 1, 1, 1, 1, 1};
149 std::vector<int> irow1 = {0, 0, 0, 0, 1, 0};
150 std::vector<int> irow2 = {0, 0, 0, 0, 0, 0};
152 TableData initTableData = {
158 TimeTable initTimeTable = std::make_tuple(eventHeader, runHeader, initTableData);
171 c.setNewPayloadLocation(
"testPayloads/TestDatabase.txt");
176 auto beamspotX = GlobalLabel::construct<BeamSpot>(0, 1);
177 auto beamspotZ = GlobalLabel::construct<BeamSpot>(0, 3);
178 auto yingZ = GlobalLabel::construct<VXDAlignment>(
VxdID(1, 0, 0, 1).
getID(), 3);
180 yingZ.registerTimeDependent(4);
185 beamspotX.registerTimeDependent(2);
186 beamspotX.registerTimeDependent(3);
187 beamspotX.registerTimeDependent(4);
189 beamspotZ.registerTimeDependent(1);
190 beamspotZ.registerTimeDependent(2);
191 beamspotZ.registerTimeDependent(3);
192 beamspotZ.registerTimeDependent(4);
193 beamspotZ.registerTimeDependent(5);
198 virtual void TearDown()
203 std::filesystem::remove_all(
"testPayloads");
211 TEST_F(TimeLineTest, InitialTimeTable)
214 auto table = makeInitialTimeTable(eventHeader, label);
216 std::vector<int> myrow0 = {0, 1, 1, 1, 1, 1};
217 std::vector<int> myrow1 = {0, 0, 0, 0, 1, 0};
219 TableData myInitTableData = {
224 TimeTable myInitTimeTable = std::make_tuple(eventHeader, runHeader, myInitTableData);
227 EXPECT_EQ(table, myInitTimeTable);
232 TEST_F(TimeLineTest, TimeTable)
234 finalizeTimeTable(initTimeTable);
235 EXPECT_EQ(initTimeTable, timeTable);
237 EXPECT_EQ(getContinuousIndexByTimeID(timeTable, 1, 3), 3);
238 EXPECT_EQ(getContinuousIndexByTimeID(timeTable, 10, 3), 0);
239 EXPECT_EQ(getContinuousIndexByTimeID(timeTable, 27, 3), 0);
244 TEST_F(TimeLineTest, PayloadTable)
247 getPayloadByContinuousIndex(payloadsTable, 1, 3).second->setGlobalParam(42., 0, 1);
248 EXPECT_EQ(getPayloadByContinuousIndex(payloadsTable, 1, 3).second->getGlobalParam(0, 1), 42.);
251 EXPECT_EQ(getPayloadByContinuousIndex(payloadsTable, 1, 0).first,
EventMetaData(0, 0, 0));
252 EXPECT_EQ(getPayloadByContinuousIndex(payloadsTable, 1, 1).first,
EventMetaData(0, 1, 0));
253 EXPECT_EQ(getPayloadByContinuousIndex(payloadsTable, 1, 2).first,
EventMetaData(0, 2, 0));
254 EXPECT_EQ(getPayloadByContinuousIndex(payloadsTable, 1, 3).first,
EventMetaData(530532, 2, 0));
255 EXPECT_EQ(getPayloadByContinuousIndex(payloadsTable, 1, 4).first,
EventMetaData(0, 3, 0));
256 EXPECT_EQ(getPayloadByContinuousIndex(payloadsTable, 1, 5).first,
EventMetaData(0, 4, 0));
258 EXPECT_EQ(getPayloadByContinuousIndex(payloadsTable, 10, 0).first,
EventMetaData(0, 0, 0));
259 EXPECT_EQ(getPayloadByContinuousIndex(payloadsTable, 10, 1).first,
EventMetaData(0, 3, 0));
261 EXPECT_EQ(getPayloadByContinuousIndex(payloadsTable, 27, 0).first,
EventMetaData(0, 0, 0));
267 TEST_F(TimeLineTest, TimeTable2PayloadsTable)
269 GlobalParamVector vector({
"BeamSpot",
"VXDAlignment",
"CDCAlignment"});
270 GlobalCalibrationManager::initGlobalVector(vector);
277 ev = gotoNextChangeInRun(timeTable, 10, timeid);
278 EXPECT_EQ(timeid, 0);
282 ev = gotoNextChangeInRun(timeTable, 10, timeid);
283 EXPECT_EQ(timeid, 1);
287 ev = gotoNextChangeInRun(timeTable, 10, timeid);
288 EXPECT_EQ(timeid, 4);
292 ev = gotoNextChangeInRun(timeTable, 10, timeid);
293 EXPECT_EQ(timeid, 5);
298 ev = gotoNextChangeInRun(timeTable, 1, timeid);
299 EXPECT_EQ(timeid, 0);
303 ev = gotoNextChangeInRun(timeTable, 1, timeid);
304 EXPECT_EQ(timeid, 1);
308 ev = gotoNextChangeInRun(timeTable, 1, timeid);
309 EXPECT_EQ(timeid, 3);
313 ev = gotoNextChangeInRun(timeTable, 1, timeid);
314 EXPECT_EQ(timeid, 3);
318 ev = gotoNextChangeInRun(timeTable, 1, timeid);
319 EXPECT_EQ(timeid, 4);
323 ev = gotoNextChangeInRun(timeTable, 1, timeid);
324 EXPECT_EQ(timeid, 5);
330 ev = gotoNextChangeRunWise(timeTable, 1, timeid);
331 EXPECT_EQ(timeid, 0);
335 ev = gotoNextChangeRunWise(timeTable, 1, timeid);
336 EXPECT_EQ(timeid, 1);
340 ev = gotoNextChangeRunWise(timeTable, 1, timeid);
341 EXPECT_EQ(timeid, 3);
345 ev = gotoNextChangeRunWise(timeTable, 1, timeid);
346 EXPECT_EQ(timeid, 3);
350 ev = gotoNextChangeRunWise(timeTable, 1, timeid);
351 EXPECT_EQ(timeid, 4);
355 ev = gotoNextChangeRunWise(timeTable, 1, timeid);
356 EXPECT_EQ(timeid, 5);
362 ev = gotoNextChangeRunWise(timeTable, 10, timeid);
363 EXPECT_EQ(timeid, 3);
365 ev = gotoNextChangeRunWise(timeTable, 10, timeid);
366 EXPECT_EQ(timeid, 3);
370 ev = gotoNextChangeRunWise(timeTable, 10, timeid);
371 EXPECT_EQ(timeid, 5);
377 auto table = TimeIdsTable2PayloadsTable(timeTable, vector);
380 EXPECT_EQ(getPayloadByContinuousIndex(table, 27, 0).first.getExperiment(), getPayloadByContinuousIndex(payloadsTable, 27,
381 0).first.getExperiment());
384 B2INFO(table.at(27).at(0).second.at(0).first.getEvent() <<
" " << table.at(27).at(0).second.at(0).first.getRun() <<
" " << table.at(
385 27).at(0).second.at(0).first.getExperiment());
386 EXPECT_EQ(table.at(27).at(0).second.at(0).first, payloadsTable.at(27).at(0).second.at(0).first);
387 B2INFO(table.at(27).at(0).second.at(0).second->getGlobalUniqueID());
388 EXPECT_EQ(table.at(27).at(0).second.at(0).second->getGlobalUniqueID(),
389 payloadsTable.at(27).at(0).second.at(0).second->getGlobalUniqueID());
391 B2INFO(table.at(10).at(0).second.at(0).first.getEvent() <<
" " << table.at(10).at(0).second.at(0).first.getRun() <<
" " << table.at(
392 10).at(0).second.at(0).first.getExperiment());
393 EXPECT_EQ(table.at(10).at(0).second.at(0).first, payloadsTable.at(10).at(0).second.at(0).first);
394 B2INFO(table.at(10).at(0).second.at(0).second->getGlobalUniqueID());
395 EXPECT_EQ(table.at(10).at(0).second.at(0).second->getGlobalUniqueID(),
396 payloadsTable.at(10).at(0).second.at(0).second->getGlobalUniqueID());
398 B2INFO(table.at(1).at(0).second.at(0).first.getEvent() <<
" " << table.at(1).at(0).second.at(0).first.getRun() <<
" " << table.at(
399 1).at(0).second.at(0).first.getExperiment());
400 EXPECT_EQ(table.at(1).at(0).second.at(0).first, payloadsTable.at(1).at(0).second.at(0).first);
401 B2INFO(table.at(1).at(0).second.at(0).second->getGlobalUniqueID());
402 EXPECT_EQ(table.at(1).at(0).second.at(0).second->getGlobalUniqueID(),
403 payloadsTable.at(1).at(0).second.at(0).second->getGlobalUniqueID());
405 B2INFO(table.at(1).at(2).second.at(1).first.getEvent() <<
" " << table.at(1).at(2).second.at(1).first.getRun() <<
" " << table.at(
406 1).at(2).second.at(1).first.getExperiment());
407 EXPECT_EQ(table.at(1).at(2).second.at(1).first, payloadsTable.at(1).at(2).second.at(1).first);
408 B2INFO(table.at(1).at(2).second.at(1).second->getGlobalUniqueID());
409 EXPECT_EQ(table.at(1).at(2).second.at(1).second->getGlobalUniqueID(),
410 payloadsTable.at(1).at(2).second.at(1).second->getGlobalUniqueID());
416 TEST_F(TimeLineTest, GlobalParamTimeLine)
419 GlobalParamVector vector({
"BeamSpot",
"VXDAlignment",
"CDCAlignment"});
420 GlobalCalibrationManager::initGlobalVector(vector);
422 GlobalParamTimeLine timeline(eventHeader, label, vector);
424 timeline.loadFromDB();
427 auto beamX0 = GlobalLabel::construct<BeamSpot>(0, 1).label();
428 timeline.updateGlobalParam(
GlobalLabel(beamX0), 3.);
431 auto beamZ = GlobalLabel::construct<BeamSpot>(0, 3).label();
432 auto beamX = GlobalLabel::construct<BeamSpot>(0, 1).label();
435 auto yingZ = GlobalLabel::construct<VXDAlignment>(
VxdID(1, 0, 0, 1).
getID(), 3).label();
438 timeline.updateGlobalParam(
GlobalLabel(beamZ), 42.);
439 timeline.updateGlobalParam(
GlobalLabel(beamX), 43.);
440 timeline.updateGlobalParam(
GlobalLabel(yingZ), 44.);
442 auto objects = timeline.releaseObjects();
443 EXPECT_EQ(objects.size(), 8);
445 for (
auto iov_obj : objects)
454 ASSERT_TRUE(payloads.get(eventMetaData, payloadInfo));
455 ASSERT_FALSE(payloadInfo.filename.empty());
456 TFile file(payloadInfo.filename.c_str());
457 ASSERT_TRUE(file.IsOpen());
462 EXPECT_EQ(beam->getIPPosition()[2], 42.);
465 EXPECT_EQ(beam->getIPPosition()[0], 43.);
468 EXPECT_EQ(beam->getIPPosition()[2], 0.);
471 EXPECT_EQ(beam->getIPPosition()[0], 0.);
476 ASSERT_TRUE(payloads.get(eventMetaData, payloadInfo));
477 ASSERT_FALSE(payloadInfo.filename.empty());
478 TFile file(payloadInfo.filename.c_str());
479 ASSERT_TRUE(file.IsOpen());
481 auto beam2 = (
BeamSpot*) file.Get(
"BeamSpot");
483 beam2->getIPPosition().Print();
484 EXPECT_EQ(beam2->getIPPosition()[0], 3.);
489 ASSERT_TRUE(payloads.get(eventMetaData, payloadInfo));
490 ASSERT_FALSE(payloadInfo.filename.empty());
491 TFile file(payloadInfo.filename.c_str());
492 ASSERT_TRUE(file.IsOpen());
496 EXPECT_EQ(vxd->getGlobalParam(
VxdID(1, 0, 0, 1).
getID(), 3), 44.);
This class contains the beam spot position and size modeled as a gaussian distribution in space.
static unsigned short getGlobalUniqueID()
Return unique ID of BeamSpot in global Millepede calibration (1)
static unsigned short getGlobalUniqueID()
Get global unique id.
static Configuration & getInstance()
Get a reference to the instance which will be used when the Database is initialized.
Class to store and retrieve temporary payloads.
static std::string objectName(const TClass *t, const std::string &name)
Return the storage name for an object of the given TClass and name.
static DataStore & Instance()
Instance of singleton Store.
void setInitializeActive(bool active)
Setter for m_initializeActive.
void reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
Class for handling changing conditions as a function of event number.
Class to convert to/from global labels for Millepede II to/from detector & parameter identificators.
static void clearTimeDependentParamaters()
Forget all previously registered time dependent parameters.
static void setCurrentTimeInterval(gidTYPE time)
Sets current time id.
A class that describes the interval of experiments/runs for which an object in the database is valid.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Type-safe access to single objects in the data store.
bool construct(Args &&... params)
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments.
VXD alignment (and maybe some calibration) parameters.
static unsigned short getGlobalUniqueID()
Get global unique id.
Class to uniquely identify a any structure of the PXD and SVD.
static Database & Instance()
Instance of a singleton Database.
bool storeData(const std::string &name, TObject *object, const IntervalOfValidity &iov)
Store an object in the database.
static void reset(bool keepConfig=false)
Reset the database instance.
int getID(const std::vector< double > &breaks, double t)
get id of the time point t
Abstract base class for different kinds of events.