ATLAS Offline Software
Loading...
Searching...
No Matches
ASCIICondDbSvc Class Reference

#include <ASCIICondDbSvc.h>

Inheritance diagram for ASCIICondDbSvc:
Collaboration diagram for ASCIICondDbSvc:

Public Member Functions

 ASCIICondDbSvc (const std::string &name, ISvcLocator *svc)
 ~ASCIICondDbSvc ()=default
virtual StatusCode initialize () override
virtual StatusCode finalize () override
virtual StatusCode getRange (const std::string &, const EventContext &, EventIDRange &, IASCIICondDbSvc::dbData_t &) const override
virtual void dump () const override
void dump (std::ostringstream &) const

Private Types

typedef std::map< std::string, std::vector< IOVEntryT< IASCIICondDbSvc::dbData_t > > > registry_t

Private Member Functions

bool parse (EventIDRange &t, const std::string &s)
bool parse (IOVEntryT< IASCIICondDbSvc::dbData_t > &t, const std::string &s)
StatusCode readDbFile (const std::string &)

Private Attributes

Gaudi::Property< std::string > m_file {this, "CondFile", "", "cond db file name"}
Gaudi::Property< unsigned int > m_lbn {this, "LBN", 1, "explicit lumi block number"}
registry_t m_registry
std::mutex m_lock

Detailed Description

Definition at line 21 of file ASCIICondDbSvc.h.

Member Typedef Documentation

◆ registry_t

typedef std::map<std::string, std::vector<IOVEntryT<IASCIICondDbSvc::dbData_t> > > ASCIICondDbSvc::registry_t
private

Definition at line 51 of file ASCIICondDbSvc.h.

Constructor & Destructor Documentation

◆ ASCIICondDbSvc()

ASCIICondDbSvc::ASCIICondDbSvc ( const std::string & name,
ISvcLocator * svc )

Definition at line 24 of file ASCIICondDbSvc.cxx.

24 :
25 base_class(name,svcLoc)
26{}

◆ ~ASCIICondDbSvc()

ASCIICondDbSvc::~ASCIICondDbSvc ( )
default

Member Function Documentation

◆ dump() [1/2]

void ASCIICondDbSvc::dump ( ) const
overridevirtual

Definition at line 119 of file ASCIICondDbSvc.cxx.

119 {
120
121 std::ostringstream ost;
122 dump(ost);
123
124 ATH_MSG_INFO( "{}", ost.str() );
125
126}
#define ATH_MSG_INFO(x,...)
virtual void dump() const override

◆ dump() [2/2]

void ASCIICondDbSvc::dump ( std::ostringstream & ost) const

Definition at line 132 of file ASCIICondDbSvc.cxx.

132 {
133
134 std::lock_guard<std::mutex> lock(m_lock);
135 std::println (ost, "ASCIICondDbSvc::dump()");
136}
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
std::mutex m_lock

◆ finalize()

StatusCode ASCIICondDbSvc::finalize ( )
overridevirtual

Definition at line 141 of file ASCIICondDbSvc.cxx.

141 {
142
143 ATH_MSG_DEBUG( "ASCIICondDbSvc::finalize()" );
144
145 if (msgLvl(MSG::DEBUG)) {
146 std::ostringstream ost;
147 dump(ost);
148
149 ATH_MSG_DEBUG( ost.str() );
150 }
151
152 for ( auto e : m_registry ) {
153 for ( auto ie : e.second ) {
154 delete ie.objPtr();
155 ie.setPtr(0);
156 }
157 }
158
159
160 return StatusCode::SUCCESS;
161
162}
#define ATH_MSG_DEBUG(x,...)
registry_t m_registry

◆ getRange()

StatusCode ASCIICondDbSvc::getRange ( const std::string & dbKey,
const EventContext & ctx,
EventIDRange & rng,
IASCIICondDbSvc::dbData_t & val ) const
overridevirtual

Definition at line 229 of file ASCIICondDbSvc.cxx.

230 {
231
232 std::lock_guard<std::mutex> lock(m_lock);
233
234 registry_t::const_iterator itr = m_registry.find(dbKey);
235
236 if (itr == m_registry.end()) {
237 ATH_MSG_ERROR( "getRange: no dbKey {} found in registry", dbKey );
238 return StatusCode::FAILURE;
239 }
240
241 for (const IOVEntryT<IASCIICondDbSvc::dbData_t>& e : itr->second) {
242 ATH_MSG_DEBUG( "compare " << e.range() << " with " << ctx.eventID() );
243 if (e.range().isInRange(EventIDBase(ctx.eventID()))) {
244 rng = e.range();
245 val = *(e.objPtr());
246 return StatusCode::SUCCESS;
247 }
248 }
249
250 ATH_MSG_ERROR( "getRange: no range for Time " << ctx.eventID()
251 << " found for dbKey " << dbKey );
252
253 return StatusCode::FAILURE;
254}
#define ATH_MSG_ERROR(x,...)
uint32_t rng()
Definition FillerAlg.cxx:40

◆ initialize()

StatusCode ASCIICondDbSvc::initialize ( )
overridevirtual

Definition at line 31 of file ASCIICondDbSvc.cxx.

31 {
32
33 // Initialise mother class in order to print DEBUG messages during initialize()
34 StatusCode sc(AthService::initialize());
35 msg().setLevel( m_outputLevel.value() );
36
37 if (!sc.isSuccess()) {
38 ATH_MSG_WARNING( "Base class could not be initialized" );
39 return StatusCode::FAILURE;
40 }
41
42 if (m_file == "") {
43 ATH_MSG_DEBUG("db file not set");
44 return StatusCode::SUCCESS;
45 }
46
47 if (readDbFile(m_file).isFailure()) {
48 return StatusCode::FAILURE;
49 }
50
51 std::ostringstream ost;
52 std::print(ost, " Printing CondDB registry");
53 for (const auto& e : m_registry) {
54 std::print(ost, "\n - id: {} r:", e.first);
55 for (const IOVEntryT<IASCIICondDbSvc::dbData_t>& r : e.second) {
56 std::print (ost, " {} :: {}", static_cast<std::string>(r.range()), *r.objPtr());
57 }
58 }
59
60 ATH_MSG_DEBUG( ost.str() );
61
62 return StatusCode::SUCCESS;
63
64}
#define ATH_MSG_WARNING(x,...)
static Double_t sc
Gaudi::Property< std::string > m_file
StatusCode readDbFile(const std::string &)
int r
Definition globals.cxx:22
::StatusCode StatusCode
StatusCode definition for legacy code.
MsgStream & msg
Definition testRead.cxx:32

◆ parse() [1/2]

bool ASCIICondDbSvc::parse ( EventIDRange & t,
const std::string & s )
private

Definition at line 167 of file ASCIICondDbSvc.cxx.

167 {
168
169 std::smatch m;
170 std::regex_match(s,m,rr);
171
172 if (m.size() != 5) { return false; }
173
174 // set run# and timestamp
175 EventIDBase start(std::stoi(m[1]), EventIDBase::UNDEFEVT, std::stoi(m[2]));
176 EventIDBase end(std::stoi(m[3]), EventIDBase::UNDEFEVT, std::stoi(m[4]));
177
178 start.set_lumi_block(m_lbn);
179 end.set_lumi_block(m_lbn);
180
181 t = EventIDRange(start, end);
182
183 return true;
184
185}
const std::regex rr(r_r)
Gaudi::Property< unsigned int > m_lbn

◆ parse() [2/2]

bool ASCIICondDbSvc::parse ( IOVEntryT< IASCIICondDbSvc::dbData_t > & t,
const std::string & s )
private

Definition at line 190 of file ASCIICondDbSvc.cxx.

190 {
191
192 std::smatch m;
193 std::regex_match(s,m,ref);
194
195 if (m.size() != 6) { return false; }
196
197 // set run#, lumi and timestamp
198 // EventIDBase start(std::stoi(m[1]), EventIDBase::UNDEFEVT, std::stoi(m[2]));
199 // EventIDBase end(std::stoi(m[3]), EventIDBase::UNDEFEVT, std::stoi(m[4]));
200 // start.set_lumi_block(m_lbn);
201 // end.set_lumi_block(m_lbn);
202
203 // set lumi and Timestamp
204 EventIDBase start(0, EventIDBase::UNDEFEVT,
205 std::stoi(m[2]));
206 EventIDBase end(EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT,
207 std::stoi(m[4]));
208 start.set_lumi_block(std::stoi(m[1]));
209 end.set_lumi_block(std::stoi(m[3]));
210
211 // Set Run/Lumi
212 // EventIDBase start(std::stoi(m[1]), EventIDBase::UNDEFEVT);
213 // EventIDBase end(std::stoi(m[3]), EventIDBase::UNDEFEVT);
214 // start.set_lumi_block(std::stoi(m[2]));
215 // end.set_lumi_block(std::stoi(m[4]));
216
217 ie.setRange(EventIDRange(start,end));
218
219 IASCIICondDbSvc::dbData_t *v = new IASCIICondDbSvc::dbData_t( std::stof(m[5]) );
220 ie.setPtr(v);
221
222 return true;
223
224}
const std::regex ref(r_ef)

◆ readDbFile()

StatusCode ASCIICondDbSvc::readDbFile ( const std::string & fname)
private

Definition at line 68 of file ASCIICondDbSvc.cxx.

68 {
69
70 StatusCode sc(StatusCode::SUCCESS);
71
72 ATH_MSG_DEBUG("reading cond db from \"{}\"", fname);
73
74 std::ifstream ifs (fname);
75 std::string line;
76 if(ifs.is_open()) {
77
78 IOVEntryT<IASCIICondDbSvc::dbData_t> ie;
79
80 while( getline (ifs, line) ) {
81
82 // ignore anything after a "#" and blank lines
83 size_t fh = line.find("#");
84 if(fh != std::string::npos)
85 line.erase(fh,line.length()-fh);
86 if (line.length() == 0) continue;
87
88 std::vector<std::string> tokens;
89 for (auto&& token : line | std::views::split(' ')) if (!token.empty()) tokens.emplace_back(token.begin(), token.end());
90 auto it = tokens.begin();
91
92 std::string dbKey = *it;
93
94 ++it;
95
96 while (it != tokens.end()) {
97 if (parse(ie,*it)) {
98 m_registry[dbKey].push_back( ie );
99 } else {
100 ATH_MSG_ERROR( "while reading {} problem parsing in line {}",
101 fname, *it, line);
102 sc = StatusCode::FAILURE;
103 }
104 ++it;
105 }
106 }
107 ifs.close();
108 } else {
109 ATH_MSG_ERROR( "unable to open file {}", m_file.value() );
110 sc = StatusCode::FAILURE;
111 }
112
113 return sc;
114
115}
bool parse(EventIDRange &t, const std::string &s)

Member Data Documentation

◆ m_file

Gaudi::Property<std::string> ASCIICondDbSvc::m_file {this, "CondFile", "", "cond db file name"}
private

Definition at line 48 of file ASCIICondDbSvc.h.

48{this, "CondFile", "", "cond db file name"};

◆ m_lbn

Gaudi::Property<unsigned int> ASCIICondDbSvc::m_lbn {this, "LBN", 1, "explicit lumi block number"}
private

Definition at line 49 of file ASCIICondDbSvc.h.

49{this, "LBN", 1, "explicit lumi block number"};

◆ m_lock

std::mutex ASCIICondDbSvc::m_lock
mutableprivate

Definition at line 54 of file ASCIICondDbSvc.h.

◆ m_registry

registry_t ASCIICondDbSvc::m_registry
private

Definition at line 52 of file ASCIICondDbSvc.h.


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