ATLAS Offline Software
Loading...
Searching...
No Matches
TrigSORFromPtreeHelper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
11
12#include <ctime>
13#include <eformat/DetectorMask.h>
14
15using namespace boost::property_tree;
16
17namespace
18{
19 const std::string CLNAME{"TrigSORFromPtreeHelper"};
20}
21
24 const ServiceHandle<StoreGateSvc>& detStore,
25 const std::string& sorpath,
26 const ptree& rparams) :
27 AthMessaging(msgSvc, CLNAME),
28 m_detStore(detStore),
29 m_sorpath(sorpath),
30 m_rparams(rparams)
31{
32 // Set run number and timestamp from RunParams. Can be overwritten later.
33 m_runNumber = rparams.get<unsigned int>("run_number");
34
35 std::istringstream ss(rparams.get_child("timeSOR").data());
36 std::tm t = {};
37 t.tm_isdst = -1; // auto-detect daylight savings time
38 unsigned int microseconds = 0;
39
40 // Format: 08/05/24 22:14:38.000000 (see OWLTime in tdaq)
41 ss >> std::get_time(&t, "%d/%m/%y %H:%M:%S.") >> microseconds;
42 if (ss.fail()) {
43 ATH_MSG_ERROR("Cannot parse timeSOR: " << ss.str());
44 }
45 m_sorTime_ns = std::mktime(&t)*std::nano::den + microseconds*1000;
46}
47
49StatusCode TrigSORFromPtreeHelper::fillSOR(const EventContext& ctx) const
50{
51 ATH_MSG_DEBUG("Setup SOR in DetectorStore");
52
53 // get handle to the IOVDbSvc
54 ServiceHandle<IIOVDbSvc> iovdbsvc("IOVDbSvc", CLNAME);
55 if ((iovdbsvc.retrieve()).isFailure()) {
56 ATH_MSG_ERROR("Could not find IOVDbSvc. Time dependent conditions data may be not properly handled.");
57 } else {
58 IOVTime currentIOVTime(ctx.eventID());
59 // Signal BeginRun directly to IOVDbSvc to set complete IOV start time
60 if ( iovdbsvc->signalBeginRun(currentIOVTime, ctx).isFailure() ) {
61 ATH_MSG_ERROR("Unable to signal begin run IOVTime to IOVDbSvc. IOVTime = " << currentIOVTime);
62 } else {
63 ATH_MSG_DEBUG("Set start of run time to IOVTime = " << currentIOVTime);
64 }
65 }
66
67 // createSOR marked unsafe due to copying/deletion of coral::AttributeList
68 // objects. There's no sharing of specificiations, though, so it's ok.
69 StatusCode sc ATLAS_THREAD_SAFE = createSOR();
70 ATH_CHECK( sc );
71
72 return StatusCode::SUCCESS;
73}
74
77{
78 EventIDBase eid;
79
80 // Set run and timestamp
81 eid.set_run_number( m_runNumber );
82 eid.set_time_stamp( m_sorTime_ns / (1000*1000*1000) );
83 eid.set_time_stamp_ns_offset( m_sorTime_ns % (1000*1000*1000) );
84
85 eid.set_lumi_block(0); // our best guess as this is not part of RunParams
86
87 return eid;
88}
89
91StatusCode TrigSORFromPtreeHelper::createSOR ATLAS_NOT_THREAD_SAFE () const
92{
93 // obtain SOR contents from ptree
94 auto attrList = getAttrList();
95
96 // Validity
97 IOVTime iovTimeStart(attrList["RunNumber"].data<unsigned int>(),0);
98 IOVTime iovTimeStop(attrList["RunNumber"].data<unsigned int>()+1,0);
99 IOVRange iovRange(iovTimeStart, iovTimeStop);
100
101 auto sor = new SOR(/*hasRunLumiBlockTime*/true);
102 sor->add(SOR::ChanNum{0}, attrList);
103 sor->add(SOR::ChanNum{0}, iovRange);
104 sor->resetMinRange();
105 sor->addNewStart(iovTimeStart);
106 sor->addNewStop(iovTimeStop);
107
108 // Record or overwrite existing SOR
109 if ( m_detStore->transientContains<SOR>(m_sorpath) ) {
110 const SOR * oldsor = m_detStore->retrieve<const SOR>(m_sorpath);
111 ATH_MSG_INFO("Overwriting SOR contents (a dump of the old one follows):");
112 oldsor->dump();
113 ATH_CHECK( m_detStore->overwrite(sor, m_sorpath, true) );
114 }
115 else {
116 ATH_MSG_DEBUG("Recording new SOR");
117 ATH_CHECK( m_detStore->record(sor, m_sorpath, true) );
118 }
119
120 ATH_CHECK( setIOVRange(iovRange) );
121 ATH_CHECK( updateProxy(sor) );
122
123 ATH_MSG_INFO("Successfully setup SOR:");
124 sor->dump();
125
126 return StatusCode::SUCCESS;
127}
128
129
131coral::AttributeList TrigSORFromPtreeHelper::getAttrList ATLAS_NOT_THREAD_SAFE () const
132{
133 // First create attribute specification
134 // ugly new needed:
135 // dtor is protected, have to use ptr and release it explicitly... go figure
136 auto attrSpec = new coral::AttributeListSpecification{};
137 attrSpec->extend("RunNumber", "unsigned int");
138 attrSpec->extend("SORTime", "unsigned long long");
139 attrSpec->extend("RunType", "string");
140 attrSpec->extend("DetectorMaskFst", "unsigned long long");
141 attrSpec->extend("DetectorMaskSnd", "unsigned long long");
142 attrSpec->extend("RecordingEnabled", "bool");
143
144 // now create the attribute list and fill it in
145 coral::AttributeList attrList(*attrSpec);
146
147 attrList["RunNumber"].data<unsigned int>() = m_runNumber;
148 attrList["RunType"].data<std::string>() = m_rparams.get<std::string>("run_type");
149 attrList["RecordingEnabled"].data<bool>() = m_rparams.get<bool>("recording_enabled");
150
151 attrList["SORTime"].data<unsigned long long>() = m_sorTime_ns;
152
153 std::pair<uint64_t, uint64_t> dm = eformat::helper::DetectorMask(m_rparams.get_child("det_mask").data()).serialize();
154 attrList["DetectorMaskFst"].data<unsigned long long>() = dm.first;
155 attrList["DetectorMaskSnd"].data<unsigned long long>() = dm.second;
156
157 // coral wants us to have to do this explicitly...
158 attrSpec->release(); // we don't delete because the dtor is private
159 // we have to hope the CORAL framework will
160
161 return attrList;
162}
163
166{
167 // set IOVRange on the IOVSvc
168 ServiceHandle<IIOVSvc> iovsvc("IOVSvc", CLNAME);
169 ATH_CHECK( iovsvc.retrieve() );
170
171 auto clid = ClassID_traits<SOR>::ID();
172 ATH_CHECK( iovsvc->setRange(clid, m_sorpath, iovRange, "StoreGateSvc") );
173
174 return StatusCode::SUCCESS;
175}
176
179{
180 // check the SOR_Params proxy and add if necessary an IAddressProvider (typically for MC)
181 auto proxy = m_detStore->proxy(sor);
182 if (!proxy) {
183 ATH_MSG_ERROR("Could not find proxy for SOR_Params folder.");
184 return StatusCode::FAILURE;
185 }
186
187 // check if the transient address has an IAddressProvider, if not set IOVDbSvc as provider
188 if (!proxy->provider()) {
189 // get handle to the IOVDbSvc
190 ServiceHandle<IIOVDbSvc> iovdbsvc("IOVDbSvc", CLNAME);
191 ATH_CHECK( iovdbsvc.retrieve() );
192
193 IAddressProvider* provider = dynamic_cast<IAddressProvider*>(&*iovdbsvc);
194 if (!provider) {
195 ATH_MSG_ERROR("Could not cast to IAddressProvider interface and set the provider for SOR_Params.");
196 return StatusCode::FAILURE;
197 }
198 proxy->setProvider(provider, proxy->storeID());
199 }
200
201 return StatusCode::SUCCESS;
202}
203
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Abstract interface to IOVDbSvc to access IOVRange and tag information.
boost::property_tree::ptree ptree
static Double_t ss
static Double_t sc
StatusCode TrigSORFromPtreeHelper::createSOR ATLAS_NOT_THREAD_SAFE() const
Define macros for attributes used to control the static checker.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE
Messaging initialized (initMessaging)
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
interface for IOA providers
Validity Range object.
Definition IOVRange.h:30
Basic time unit for IOVSvc.
Definition IOVTime.h:33
StatusCode setIOVRange(IOVRange &iovRange) const
TrigSORFromPtreeHelper(IMessageSvc *msgSvc, const ServiceHandle< StoreGateSvc > &detStore, const std::string &sorpath, const boost::property_tree::ptree &rparams)
Create the SOR helper @params msgSvc Pointer to MessageSvc @params detStore Handle to DetectorStore @...
StatusCode updateProxy(SOR *sor) const
ServiceHandle< StoreGateSvc > m_detStore
CondAttrListCollection SOR
unsigned long long m_sorTime_ns
StatusCode fillSOR(const EventContext &ctx) const
Fill SOR record in Detector Store, reusing if present or creating new one otherwise/ @params ctx Even...
EventIDBase eventID() const
Create an EventIDBase filled with the value from rparams.
const boost::property_tree::ptree & m_rparams