ATLAS Offline Software
Blob2ToolConstants.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "Blob2ToolConstants.h"
6 
8 #include "CoralBase/Attribute.h"
9 #include "CoralBase/AttributeListSpecification.h"
10 #include "CoralBase/AttributeListException.h"
11 #include "CoralBase/Blob.h"
12 
13 #include "TBufferFile.h"
14 #include "TClass.h"
15 
17 #include "CxxUtils/crc64.h"
18 
20  const std::string& name,
21  const IInterface* parent) :
23 {
24  declareInterface<Blob2ToolConstants>(this);
25 }
26 
27 
29  msg(MSG::DEBUG) << "Initializing..." << endmsg;
30  return StatusCode::SUCCESS;
31 }
32 
33 
35 
36  coral::AttributeListSpecification* spec = new coral::AttributeListSpecification();
37 
38  spec->extend("clsname","string"); //Data member of CaloRec::ToolConstants
39  spec->extend("version","unsigned int"); //Data member of CaloRec::ToolConstants
40  spec->extend("blobVersion","unsigned int"); //Should allow schema evolution if needed
41  spec->extend("Constants","blob"); //Holds the map<string,Arrayrep>
42 
43 
44  auto attrList = std::make_unique<coral::AttributeList>(*spec);
45 
46  spec->release();
47  // cppcheck-suppress memleak
48  spec = nullptr;
49 
50  (*attrList)["clsname"].data<std::string>()=tc->clsname();
51  (*attrList)["version"].data<unsigned int>()=(unsigned int)tc->version();
52  (*attrList)["blobVersion"].data<unsigned int>()=(unsigned int)0;
53 
54  coral::Blob& blob=(*attrList)["Constants"].data<coral::Blob>();
55 
56  //typedef std::map<std::string, CaloRec::Arrayrep> T;
57  TClass* klass = TClass::GetClass ("std::map<std::string, CaloRec::Arrayrep>");
58  if (klass==nullptr) {
59  msg( MSG::ERROR) << "Can't find TClass std::map<std::string, CaloRec::Arrayrep>" << endmsg;
60  return nullptr;
61  }
62  else
63  msg(MSG::DEBUG) << "Got TClass std::map<std::string, CaloRec::Arrayrep>" << endmsg;
64 
65  TBufferFile buf (TBuffer::kWrite);
66 
67  if (buf.WriteObjectAny (&tc->map(), klass) != 1) {
68  msg(MSG::ERROR) << "Failed to stream CaloRec::ToolConstants::Maptype " << endmsg;
69  return nullptr;
70  }
71 
72  blob.resize(buf.Length());
73  void* adr = blob.startingAddress();
74  memcpy(adr,buf.Buffer(),buf.Length());
75  return attrList.release();
76  }
77 
79 
81  std::unique_ptr<T> map;
82 
83  try {
84  tc.clsname(attrList["clsname"].data<std::string>());
85  tc.version(attrList["version"].data<unsigned int>());
86  const unsigned blobVersion=attrList["blobVersion"].data<unsigned int>();
87  const coral::Blob& blob = attrList["Constants"].data<coral::Blob>();
88 
89  if (blobVersion!=0) {
90  msg(MSG::ERROR) << "Can't interpret BLOB version " << blobVersion << endmsg;
91  return StatusCode::FAILURE;
92  }
93 
94  TClass* klass = TClass::GetClass ("std::map<std::string, CaloRec::Arrayrep>");
95  if (klass==nullptr) {
96  msg(MSG::ERROR) << "Can't find TClass std::map<std::string, CaloRec::Arrayrep>" << endmsg;
97  return StatusCode::FAILURE;
98  }
99  else
100  msg(MSG::DEBUG) << "Got TClass std::map<std::string, CaloRec::Arrayrep>" << endmsg;
101 
102  // TBufferFile needs a void* even in read-only mode:
103  void* blob_start ATLAS_THREAD_SAFE = const_cast<void*>(blob.startingAddress());
104  TBufferFile buf (TBuffer::kRead, blob.size(), blob_start, false);
105  map.reset( (T*)buf.ReadObjectAny (klass) );
106  }catch (coral::AttributeListException &e) {
107  msg(MSG::ERROR) << e.what() << endmsg;
108  return StatusCode::FAILURE;
109  }
110 
111  T::const_iterator it=map->begin();
112  T::const_iterator it_e=map->end();
113  for (;it!=it_e;++it) {
114  tc.setrep(it->first,it->second);
115  }
116  return StatusCode::SUCCESS;
117 }
118 
121  const uint32_t hash32=(uint32_t)(hash64 & 0xFFFFFFFF);
122  //std::cout << "HASH: 64bit:" << std::hex << hash64 << " 32bit:" << hash32 << std::endl;
123  return hash32;
124  }
125 
126 
127 static const InterfaceID IID_Blob2ToolConstants ("Blob2ToolConstants", 1 , 0);
128 
129 
130 const InterfaceID& Blob2ToolConstants::interfaceID() {
131  return IID_Blob2ToolConstants;
132 }
133 
CaloRec::ToolConstants::version
int version() const
Return the version of the C++ class that operates on these constants.
Definition: ToolConstants.cxx:170
ToolConstants.h
Container for the tool constants managed by ToolWithConstants.
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
CaloCondBlobAlgs_fillNoiseFromASCII.spec
spec
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:47
skel.it
it
Definition: skel.GENtoEVGEN.py:423
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
klass
This class describe the base functionalities of a HypoTool used by the ComboAlg.
python.LArBadChannelDBAlg.xFFFFFFFF
xFFFFFFFF
Definition: LArBadChannelDBAlg.py:73
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
CaloRec::ToolConstants::Maptype
std::map< std::string, CxxUtils::Arrayrep > Maptype
Type of the map from keys to values.
Definition: ToolConstants.h:35
Blob2ToolConstants::initialize
virtual StatusCode initialize()
Definition: Blob2ToolConstants.cxx:28
CaloRec::ToolConstants::map
const Maptype & map() const
Return the key -> value map.
Definition: ToolConstants.cxx:188
Blob2ToolConstants::interfaceID
static const InterfaceID & interfaceID()
Definition: Blob2ToolConstants.cxx:130
test_pyathena.parent
parent
Definition: test_pyathena.py:15
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
Blob2ToolConstants::nameToChannelNumber
static unsigned nameToChannelNumber(const std::string &name)
Method to create a channel number (hash)
Definition: Blob2ToolConstants.cxx:119
CxxUtils::crc64
uint64_t crc64(const CRCTable &table, const char *data, size_t data_len)
Find the CRC-64 of a string,.
Definition: crc64.cxx:696
Blob2ToolConstants.h
An AlgTool to convert btw ToolConstants and coral::AttributeList.
WriteCalibToCool.blobVersion
blobVersion
Definition: WriteCalibToCool.py:82
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
Blob2ToolConstants::ToolConstantsToAttrList
coral::AttributeList * ToolConstantsToAttrList(const CaloRec::ToolConstants *tc) const
Method convert ToolConstants -> AttributeList (writing)
Definition: Blob2ToolConstants.cxx:34
xxh3::hash64
std::uint64_t hash64(const void *data, std::size_t size)
Passthrough to XXH3_64bits.
Definition: XXH.cxx:9
CaloRec::ToolConstants
Container for the tool constants managed by ToolWithConstants.
Definition: ToolConstants.h:32
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
CaloRec::ToolConstants::setrep
void setrep(const std::string &key, const CxxUtils::Arrayrep &rep)
Set an entry.
Definition: ToolConstants.cxx:79
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
crc64.h
A crc-64 implementation, using pclmul where possible.
AthAlgTool
Definition: AthAlgTool.h:26
Blob2ToolConstants::AttrListToToolConstants
StatusCode AttrListToToolConstants(const coral::AttributeList &attrList, CaloRec::ToolConstants &tc) const
Method convert AttributeList->ToolConstants (reading)
Definition: Blob2ToolConstants.cxx:78
checker_macros.h
Define macros for attributes used to control the static checker.
Blob2ToolConstants::Blob2ToolConstants
Blob2ToolConstants(const std::string &type, const std::string &name, const IInterface *parent)
Definition: Blob2ToolConstants.cxx:19
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
CaloCondBlobAlgs_fillNoiseFromASCII.blob
blob
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:96
CaloRec::ToolConstants::clsname
const std::string & clsname() const
Return the name of the C++ class that operates on these constants.
Definition: ToolConstants.cxx:152