ATLAS Offline Software
Loading...
Searching...
No Matches
asg::detail Namespace Reference

Enumerations

enum class  AnaToolHandleMode {
  EMPTY , CREATE_PRIVATE , CREATE_SHARED , RETRIEVE_SHARED ,
  USER
}
 the mode with which an AnaToolHandle object is initialized More...

Functions

void throw_check_fail (const std::string &str)
 throw an error for a failed check
bool matchesRegex (const std::string &regex, const std::string &str)
 return whether str matches regex
StatusCode hasPropertiesInCatalogue (const std::string &toolName)
StatusCode addPropertyToCatalogue (const std::string &toolName, const std::string &propertyName, const std::string &propertyValue)
StatusCode removePropertyFromCatalogue (const std::string &toolName, const std::string &propertyName)
StatusCode toolExists (const std::string &fullName, interfaceType_t *&tool)
StatusCode factoryExists (const std::string &type)
StatusCode copyPropertiesInCatalogue (const std::string &fromTool, const std::string &toTool)
StatusCode readToolConfig (AsgToolConfig &config, const std::string &toolName)
StatusCode packStringMap (const std::map< std::string, std::string > &value, std::string &result)
StatusCode packStringVector (const std::vector< std::string > &value, std::string &result)
StatusCode packStringSingle (const std::string &value, std::string &result)
StatusCode unpackStringSingle (const std::string &value, std::string &result)
StatusCode unpackStringVector (const std::string &value, std::vector< std::string > &result)
StatusCode unpackStringMap (const std::string &value, std::map< std::string, std::string > &result)

Enumeration Type Documentation

◆ AnaToolHandleMode

enum class asg::detail::AnaToolHandleMode
strong

the mode with which an AnaToolHandle object is initialized

Enumerator
EMPTY 

do not create a tool

this can be either explicitly an empty tool handle set by the user, or an AnaToolHandle that was never configured in the first place.

CREATE_PRIVATE 

create a private tool normally

CREATE_SHARED 

create a shared tool normally

RETRIEVE_SHARED 

retrieve a shared tool

USER 

retrieve a tool from the user tool handle

this can still refer to a tool handle that is empty, though usually it will point to an actual tool

Definition at line 45 of file AnaToolHandle.h.

46 {
52 EMPTY,
53
56
59
62
67 USER
68 };
@ USER
retrieve a tool from the user tool handle
@ CREATE_SHARED
create a shared tool normally
@ RETRIEVE_SHARED
retrieve a shared tool
@ CREATE_PRIVATE
create a private tool normally

Function Documentation

◆ addPropertyToCatalogue()

StatusCode asg::detail::addPropertyToCatalogue ( const std::string & toolName,
const std::string & propertyName,
const std::string & propertyValue )

Definition at line 210 of file AnaToolHandle.cxx.

210 {
211//std::cout << "Adding " << toolName << " ." << propertyName << " = " << propertyValue << std::endl;
212 ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc","AnaToolHandle");
213 //check if propertyName contains '.' . If it does, then assume settng a property of a private tool, so adjust toolname
214 joSvc->set( toolName + "." + propertyName, propertyValue );
215 if(joSvc.release().isFailure()) return StatusCode::FAILURE;
216 return StatusCode::SUCCESS;
217 }

◆ copyPropertiesInCatalogue()

StatusCode asg::detail::copyPropertiesInCatalogue ( const std::string & fromTool,
const std::string & toTool )

Definition at line 253 of file AnaToolHandle.cxx.

253 {
254 using namespace msgToolHandle;
255 //this method copies any properties assigned to 'fromTool' to 'toTool'
256 //purpose of this is because python joboptions will set joboptions properties using the name of the handle
257 //but we would like the name of the property (in declareProperty) to be used for anatoolhandles instead, in the case of private tools
258//std::cout << "copy : " << fromTool << " -> " << toTool << std::endl;
259 if(fromTool == toTool) return StatusCode::SUCCESS; //nothing to do
260
261 ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc","AnaToolHandle");
262 auto fromProps = joSvc->items(std::regex ("^" + fromTool));
263 for(auto& prop : fromProps) {
264 std::get<0>(prop).replace (0, fromTool.size(), toTool);
265 joSvc->set( std::get<0>(prop) , std::get<1>(prop) );
266 }
267 if(joSvc.release().isFailure()) return StatusCode::FAILURE;
268 return StatusCode::SUCCESS;
269 }

◆ factoryExists()

StatusCode asg::detail::factoryExists ( const std::string & type)

Definition at line 246 of file AnaToolHandle.cxx.

246 {
247 using Gaudi::PluginService::Details::Registry;
248 Registry &reg = Registry::instance();
249 if(reg.getInfo(type).library=="unknown") return StatusCode::FAILURE;
250 return StatusCode::SUCCESS;
251 }

◆ hasPropertiesInCatalogue()

StatusCode asg::detail::hasPropertiesInCatalogue ( const std::string & toolName)

Definition at line 194 of file AnaToolHandle.cxx.

194 {
195 ServiceHandle<Gaudi::Interfaces::IOptionsSvc> svc("JobOptionsSvc","AnaToolHandle");
196 if( svc.retrieve().isFailure() ) return StatusCode::FAILURE;
197 auto props = svc->items(std::regex("^" + toolName + "\\."));
198 StatusCode out = StatusCode::FAILURE;
199 for (auto& prop : svc->items())
200 {
201 if (std::get<0>(prop).substr (0, toolName.size()) == toolName &&
202 std::get<0>(prop)[toolName.size()] == '.')
203 out = StatusCode::SUCCESS;
204 }
205 svc.release().ignore();
206 //delete props;
207 return out;
208 }

◆ matchesRegex()

bool asg::detail::matchesRegex ( const std::string & regex,
const std::string & str )

return whether str matches regex

Guarantee
strong
Failures
out of memory II
expression error

Definition at line 25 of file Control/AthToolSupport/AsgTesting/Root/UnitTest.cxx.

26 {
27 return regex_search (str, std::regex (regex));
28 }

◆ packStringMap()

StatusCode asg::detail::packStringMap ( const std::map< std::string, std::string > & value,
std::string & result )

Definition at line 273 of file TProperty.cxx.

275 {
276 std::string myresult;
277 for (const auto& subvalue : value)
278 {
279 if (!myresult.empty())
280 myresult += ",";
281 myresult += quoteString (subvalue.first) + ":" + quoteString (subvalue.second);
282 }
283 result = "{" + std::move (myresult) + "}";
284 return StatusCode::SUCCESS;
285 }

◆ packStringSingle()

StatusCode asg::detail::packStringSingle ( const std::string & value,
std::string & result )

Definition at line 305 of file TProperty.cxx.

307 {
308 if (value.find ("\\") == std::string::npos)
309 {
310 if (value.find ("\'") == std::string::npos)
311 {
312 result = "\'" + value + "\'";
313 return StatusCode::SUCCESS;
314 }
315 if (value.find ("\"") == std::string::npos)
316 {
317 result = "\"" + value + "\"";
318 return StatusCode::SUCCESS;
319 }
320 }
321 char quote = '\'';
322 if (value.find ("\'") != std::string::npos &&
323 value.find ("\"") == std::string::npos)
324 quote = '\"';
325 result = quote;
326 for (char ch : value)
327 {
328 if (ch == quote || ch == '\\')
329 result += '\\';
330 result += ch;
331 }
332 result += quote;
333 return StatusCode::SUCCESS;
334 }
std::string quote(const std::string &sentence)
Enclose a string in ".

◆ packStringVector()

StatusCode asg::detail::packStringVector ( const std::vector< std::string > & value,
std::string & result )

Definition at line 289 of file TProperty.cxx.

291 {
292 std::string myresult;
293 for (const auto& subvalue : value)
294 {
295 if (!myresult.empty())
296 myresult += ",";
297 myresult += quoteString (subvalue);
298 }
299 result = "[" + std::move (myresult) + "]";
300 return StatusCode::SUCCESS;
301 }

◆ readToolConfig()

StatusCode asg::detail::readToolConfig ( AsgToolConfig & config,
const std::string & toolName )

Definition at line 272 of file AnaToolHandle.cxx.

272 {
273 using namespace msgToolHandle;
274 //this method copies any properties assigned to tool with 'toolName' to 'config'
275 ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc","AnaToolHandle");
276 decltype(auto) fromProps = joSvc->items(std::regex ("^" + toolName));
277 for(const auto& prop : fromProps) {
278 if (std::get<0>(prop) == toolName)
279 {
280 config.setTypeAndName (std::get<1>(prop));
281 } else
282 {
283 config.setPropertyFromString (std::get<0>(prop).substr (toolName.size()+1) , std::get<1>(prop));
284 }
285 }
286 ANA_CHECK (joSvc.release());
287 return StatusCode::SUCCESS;
288 }
#define ANA_CHECK(EXP)
check whether the given expression was successful

◆ removePropertyFromCatalogue()

StatusCode asg::detail::removePropertyFromCatalogue ( const std::string & toolName,
const std::string & propertyName )

Definition at line 221 of file AnaToolHandle.cxx.

221 {
222 ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc","AnaToolHandle");
223 //check if propertyName contains '.' . If it does, then assume settng a property of a private tool, so adjust toolname
224 std::string theToolName = toolName; std::string thePropertyName=propertyName;
225 std::string::size_type dotLocation = thePropertyName.find_last_of('.');
226 if(dotLocation != std::string::npos) {
227 theToolName = toolName + "." + thePropertyName.substr(0,dotLocation);
228 thePropertyName = thePropertyName.substr(dotLocation+1,thePropertyName.length()-dotLocation);
229 }
230 joSvc->pop( theToolName + "." + thePropertyName );
231 if(joSvc.release().isFailure()) return StatusCode::FAILURE;
232 return StatusCode::SUCCESS;
233 }

◆ throw_check_fail()

void asg::detail::throw_check_fail ( const std::string & str)

throw an error for a failed check

the main reason to have a separate function for this is to cut down on the number of includes in the header file.

Definition at line 27 of file Control/AthToolSupport/AsgMessaging/Root/MessageCheck.cxx.

28 {
29 throw std::runtime_error (str);
30 }

◆ toolExists()

StatusCode asg::detail::toolExists ( const std::string & fullName,
interfaceType_t *& tool )

Definition at line 234 of file AnaToolHandle.cxx.

234 {
235 ServiceHandle<IToolSvc> toolSvc("ToolSvc","AnaToolHandle");
236 toolSvc.retrieve().ignore();
237 auto tools = toolSvc->getTools();
238 StatusCode out(StatusCode::FAILURE);
239 for(auto atool : tools) {
240 if(atool && atool->name() == fullName) {out=StatusCode::SUCCESS;tool=atool;break;}
241 }
242 toolSvc.release().ignore();
243 return out;
244 }

◆ unpackStringMap()

StatusCode asg::detail::unpackStringMap ( const std::string & value,
std::map< std::string, std::string > & result )

Definition at line 489 of file TProperty.cxx.

491 {
492 using namespace asg::msgProperty;
493
494 std::vector<Token> tokenTree;
495 {
496 std::vector<Token> tokenList;
497 ANA_CHECK (make_token_list (value, tokenList));
498 auto iterator = tokenList.begin();
499 ANA_CHECK (make_token_tree (iterator, tokenList.end(), tokenTree, false));
500 }
501
502 if (tokenTree.size() != 1 ||
503 tokenTree[0].m_type != TokenType::SUBGROUP ||
504 tokenTree[0].m_subtokens[0].m_type != TokenType::MAP_OPEN)
505 {
506 ANA_MSG_ERROR ("failed to recognize value as map: " << value);
507 return StatusCode::FAILURE;
508 }
509
510 // note that this loop avoids the first and last token,
511 // i.e. "{" and "}"
512 for (std::size_t index = 1;
513 index < tokenTree[0].m_subtokens.size()-1; ++ index)
514 {
515 Token& mytoken = tokenTree[0].m_subtokens[index];
516 switch (index % 4)
517 {
518 case 0:
519 if (mytoken.m_type != TokenType::COMMA)
520 {
521 ANA_MSG_ERROR ("unexpected token " << mytoken.m_raw);
522 return StatusCode::FAILURE;
523 }
524 break;
525 case 1:
526 if (mytoken.m_type == TokenType::COMMA ||
527 mytoken.m_type == TokenType::MAP_SEPARATOR)
528 {
529 ANA_MSG_ERROR ("unexpected token " << mytoken.m_raw);
530 return StatusCode::FAILURE;
531 }
532 break;
533 case 2:
534 if (mytoken.m_type != TokenType::MAP_SEPARATOR)
535 {
536 ANA_MSG_ERROR ("unexpected token " << mytoken.m_raw);
537 return StatusCode::FAILURE;
538 }
539 break;
540 case 3:
541 if (mytoken.m_type == TokenType::COMMA ||
542 mytoken.m_type == TokenType::MAP_SEPARATOR)
543 {
544 ANA_MSG_ERROR ("unexpected token " << mytoken.m_raw);
545 return StatusCode::FAILURE;
546 }
547 Token& keytoken = tokenTree[0].m_subtokens[index-2];
548 result.emplace (keytoken.m_raw, mytoken.m_raw);
549 break;
550 }
551 }
552 if (tokenTree[0].m_subtokens.size() > 2 &&
553 tokenTree[0].m_subtokens.size()%4 != 1)
554 {
555 ANA_MSG_ERROR ("unexpected token " << tokenTree[0].m_subtokens.back().m_raw);
556 return StatusCode::FAILURE;
557 }
558 return StatusCode::SUCCESS;
559 }
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition Token.h:21
int m_type
Token type.
Definition Token.h:123
str index
Definition DeMoScan.py:362
Definition index.py:1

◆ unpackStringSingle()

StatusCode asg::detail::unpackStringSingle ( const std::string & value,
std::string & result )

Definition at line 339 of file TProperty.cxx.

341 {
342 using namespace asg::msgProperty;
343
344 // special case: we don't have a quote, use string verbatim
345 if (value.find ('\'') == std::string::npos &&
346 value.find ('"') == std::string::npos)
347 {
348 result = value;
349 return StatusCode::SUCCESS;
350 }
351
352 std::vector<Token> tokens;
353 ANA_CHECK (make_token_list (value, tokens));
354 assert (!tokens.empty());
355 if (tokens.front().m_type == TokenType::SPACE)
356 {
357 tokens.erase (tokens.begin());
358 assert (!tokens.empty());
359 }
360 if (tokens.back().m_type == TokenType::SPACE)
361 {
362 tokens.erase (tokens.begin() + (tokens.size() - 1));
363 assert (!tokens.empty());
364 }
365 if (tokens[0].m_type != TokenType::STRING)
366 {
367 ANA_MSG_ERROR ("string property didn't start with a quote: " << value);
368 return StatusCode::FAILURE;
369 }
370 if (tokens.size() > 1)
371 {
372 ANA_MSG_ERROR ("extra text beyond quoted string: " << value);
373 return StatusCode::FAILURE;
374 }
375 result.swap (tokens[0].m_cooked);
376 return StatusCode::SUCCESS;
377 }

◆ unpackStringVector()

StatusCode asg::detail::unpackStringVector ( const std::string & value,
std::vector< std::string > & result )

Definition at line 381 of file TProperty.cxx.

383 {
384 using namespace asg::msgProperty;
385
386 std::vector<std::string> myresult;
387
388 std::vector<Token> tokens;
389 ANA_CHECK (make_token_list (value, tokens));
390
391 bool done = false;
392 unsigned level = 0;
393 std::string subresult;
394 for (auto& token : tokens)
395 {
396 if (token.m_type == TokenType::LIST_OPEN)
397 ++ level;
398 if (level > 1)
399 {
400 subresult += token.m_raw;
401 } else if (level == 0)
402 {
403 if (token.m_type != TokenType::SPACE)
404 {
405 if (done)
406 {
407 ANA_MSG_ERROR ("vector property does not end with ']': " << value);
408 return StatusCode::FAILURE;
409 } else
410 {
411 ANA_MSG_ERROR ("vector property does not begin with '[': " << value);
412 return StatusCode::FAILURE;
413 }
414 }
415 } else switch (token.m_type)
416 {
417 case TokenType::MAP_SEPARATOR:
418 case TokenType::MAP_OPEN:
419 case TokenType::MAP_CLOSE:
420 case TokenType::SUBGROUP:
421 // not handling this (for now). if it comes up I fix it,
422 // but for now this would be more of a distraction.
423 ANA_MSG_ERROR ("(currently) unsupported token in vector: " << token.m_raw);
424 return StatusCode::FAILURE;
425 case TokenType::SPACE:
426 break;
427 case TokenType::STRING:
428 case TokenType::NUMBER:
429 if (!subresult.empty())
430 {
431 ANA_MSG_ERROR ("invalid entry in vector: " << subresult << token.m_raw);
432 return StatusCode::FAILURE;
433 }
434 subresult = std::move (token.m_raw);
435 break;
436 case TokenType::COMMA:
437 if (subresult.empty())
438 {
439 ANA_MSG_ERROR ("comma not preceded by value: " << value);
440 return StatusCode::FAILURE;
441 }
442 myresult.push_back (std::move (subresult));
443 subresult.clear ();
444 break;
445 case TokenType::LIST_OPEN:
446 if (done)
447 {
448 ANA_MSG_ERROR ("vector property does not begin with '[': " << value);
449 return StatusCode::FAILURE;
450 }
451 break;
452 case TokenType::LIST_CLOSE:
453 if (!subresult.empty())
454 {
455 myresult.push_back (std::move (subresult));
456 subresult.clear ();
457 } else
458 {
459 if (!myresult.empty())
460 {
461 ANA_MSG_ERROR ("vector property has ',' before ']': " << value);
462 return StatusCode::FAILURE;
463 }
464 }
465 done = true;
466 break;
467 }
468 if (token.m_type == TokenType::LIST_CLOSE)
469 {
470 if (level == 0)
471 {
472 ANA_MSG_ERROR ("extra ']' in vector: " << value);
473 return StatusCode::FAILURE;
474 }
475 -- level;
476 }
477 }
478 if (!done)
479 {
480 ANA_MSG_ERROR ("did not find a vector in the string");
481 return StatusCode::FAILURE;
482 }
483 result.swap (myresult);
484 return StatusCode::SUCCESS;
485 }