ATLAS Offline Software
SGFolder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <cassert>
6 #include <cstdlib> /* atoi */
7 #include <iostream>
8 #include <vector>
9 
10 #include "GaudiKernel/IMessageSvc.h"
11 #include "GaudiKernel/MsgStream.h"
12 #include "GaudiKernel/ISvcLocator.h"
13 
15 #include "GaudiKernel/IClassIDSvc.h"
17 
18 #include "SGFolder.h"
19 
20 /* #define SGFOLDER_DEBUG 1 */
21 
22 using namespace SG;
23 
24 
25 
26 //-----------------------------------------------------------------------------
27 Folder::Folder( const std::string& type,
28  const std::string& name,
29  const IInterface* parent) :
30  AthAlgTool( type, name, parent ),
31  m_pCLIDSvc("ClassIDSvc", name),
32  m_checkItems(false)
33 {
34  declareProperty("ItemList", m_itemList,
35  " list of data objects identified by a class name (or clid)#key pairs. One can use '*' as key value to add all objects of a given type to the Folder. If the type name ends with !, then write the object as exactly that type (and not as any derived class). ");
36  m_itemList.declareUpdateHandler(&Folder::decodeItemList, this);
37  declareProperty("CheckItems", m_checkItems,
38  "check if item types are known to ClassIDSvc");
39 }
40 
41 //-----------------------------------------------------------------------------
43 {}
44 
45 //-----------------------------------------------------------------------------
46 StatusCode Folder::queryInterface(const InterfaceID& riid, void** ppvIf) {
47  if ( riid == SG::IFolder::interfaceID() ) {
48  *ppvIf = (IFolder*)this;
49  addRef();
50  return StatusCode::SUCCESS;
51  }
52  return AthAlgTool::queryInterface( riid, ppvIf );
53 }
54 
55 //-----------------------------------------------------------------------------
57  return m_pCLIDSvc.retrieve();
58 }
59 
60 //-----------------------------------------------------------------------------
61 void Folder::updateItemList(bool checkValid) {
62  std::vector< std::string >::const_iterator
63  i(m_itemList.value().begin()), e(m_itemList.value().end());
64  while (i != e) decodeItem(*i++, checkValid);
65 }
66 
67 void Folder::decodeItem(const std::string& item, bool checkValid) {
68  assert( !item.empty() );
69  assert( m_pCLIDSvc );
70 #ifdef SGFOLDER_DEBUG
71  //can't use MsgStream (log level still not defined)
72  std::cout << "Folder::decodeItem("<< item<<") called" << std::endl;
73 #endif
74  std::string::size_type sep(item.rfind('#'));
75  std::string typeName (item.substr(0,sep));
76  std::string skey;
77  if (sep != std::string::npos) skey = item.substr(sep+1);
78 
79  //item contains a typename OR a CLID. Try the CLID hypothesis first
80  CLID clid(atoi(typeName.c_str()));
81  //atoi would return 0 if "typeName" is not a stringified number
82  if ( 0 == clid) {
83  //notice that if the typename is not yet in the ClassIDSvc registry the entry will be ignored
84  add(typeName, skey).ignore();
85  } else add(clid, skey, checkValid, false).ignore();
86 }
87 
89 Folder::add(const std::string& typeName, const std::string& skey) {
90  bool exact = false;
91  std::string tn = typeName;
92  if (tn.size() > 0 && tn[tn.size()-1] == '!') {
93  exact = true;
94  tn.erase (tn.end()-1);
95  }
96 
97  CLID clid;
98  //let's see if the typename is known to ClassIDSvc
99  StatusCode sc(m_pCLIDSvc->getIDOfTypeName(tn, clid));
100  //if so, add the corresponding clid (no point in checking it again)
101  if (sc.isSuccess()) sc=add(clid, skey, false, exact);
102  else {
103  MsgStream log(msgSvc(), name());
104  log << MSG::WARNING << "add: can not find type ["
105  << typeName << "] in clid db" << endmsg;
106  }
107  return sc;
108 }
109 
111 Folder::add(const CLID& clid, const std::string& skey,
112  bool checkValid, bool exact)
113 {
114  StatusCode sc(StatusCode::FAILURE);
115  if ( !checkValid || m_pCLIDSvc->isIDInUse(clid) ) {
116  m_list.insert(FolderItem(clid, skey, exact));
117  sc = StatusCode::SUCCESS;
118  } else if (0 != clid) {
119  MsgStream log(msgSvc(), name());
120  log << MSG::WARNING << "add: can not find clid "
121  << clid << " in clid db" << endmsg;
122  }
123 #ifdef SGFOLDER_DEBUG
124  std::cout << "SG::Folder::add(" << clid << ",\"" << skey << "\") returns "
125  << (sc.isSuccess() ? "SUCCESS" : "FAILURE") << std::endl;
126 #endif
127  return sc;
128 }
SGFolder.h
a run-time configurable list of data objects
SG::Folder::~Folder
virtual ~Folder() override
Definition: SGFolder.cxx:42
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::Folder::updateItemList
virtual void updateItemList(bool checkValidCLID) override final
update contents of the ItemList
Definition: SGFolder.cxx:61
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
SG::Folder::queryInterface
virtual StatusCode queryInterface(const InterfaceID &, void **) override
Query for a given interface.
Definition: SGFolder.cxx:46
SG::Folder::m_pCLIDSvc
ServiceHandle< IClassIDSvc > m_pCLIDSvc
Definition: SGFolder.h:91
SG::Folder::m_itemList
StringArrayProperty m_itemList
property: the list of items (data objects identified by a class name/key pair)
Definition: SGFolder.h:93
SG::IFolder
a run-time configurable list of data objects
Definition: SGIFolder.h:25
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
lumiFormat.i
int i
Definition: lumiFormat.py:92
ClassID_traits.h
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
SG::Folder::Folder
Folder(const std::string &type, const std::string &name, const IInterface *parent)
Definition: SGFolder.cxx:27
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::Folder::m_list
ItemList m_list
Definition: SGFolder.h:105
test_pyathena.parent
parent
Definition: test_pyathena.py:15
SG::Folder::decodeItemList
void decodeItemList(Gaudi::Details::PropertyBase &)
Definition: SGFolder.h:94
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
grepfile.sep
sep
Definition: grepfile.py:38
SG::Folder::m_checkItems
BooleanProperty m_checkItems
property: check if item types are known to ClassIDSvc
Definition: SGFolder.h:107
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SG::Folder::add
virtual StatusCode add(const std::string &typeName, const std::string &skey) override
add a data object identifier to the list.
Definition: SGFolder.cxx:89
item
Definition: ItemListSvc.h:43
SG::Folder::initialize
virtual StatusCode initialize() override
Definition: SGFolder.cxx:56
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
SG::IFolder::interfaceID
static const InterfaceID & interfaceID()
Definition: SGIFolder.h:48
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
AthAlgTool
Definition: AthAlgTool.h:26
DefaultKey.h
SG::Folder::decodeItem
void decodeItem(const std::string &item, bool checkValidCLID)
Definition: SGFolder.cxx:67
SG::FolderItem
a Folder item (data object) is identified by the clid/key pair
Definition: SGFolderItem.h:24