ATLAS Offline Software
Loading...
Searching...
No Matches
IDC_Helper.icc
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 "Identifier/IdentifierHash.h"
6template< class IDC, class IDHELPER >
7static
8typename IDC::IDENTIFIABLE*
9Muon::IDC_Helper::getCollection ATLAS_NOT_THREAD_SAFE
10 ( const Identifier collId, IDC* idc, const IDHELPER& idHelper, MsgStream& log)
11{
12 IdentifierHash idHash;
13 if (idHelper.get_module_hash( collId, idHash )) {
14 log << MSG::ERROR << "Unable to get CSC hash id from CSC RDO collection "
15 << " the identifier is \n"
16 << collId <<endmsg;
17 }
18
19 typename IDC::IDENTIFIABLE* collection=0;
20 auto collptr = idc->indexFindPtr(idHash);
21 if (collptr == nullptr) {
22 collection = new typename IDC::IDENTIFIABLE(idHash);
23 collection->setIdentifier(collId);
24 StatusCode status = idc->addCollection(collection, idHash );
25 if (status.isFailure())
26 log << MSG::ERROR << "Couldn't add collection to IDC" << endmsg;
27 } else {
28 //Use naughtyRetrieve to protect external caches from modification
29 StatusCode status = idc->naughtyRetrieve(idHash, collection);
30 if (status.isFailure())
31 log << MSG::ERROR << "Attempt to get unsafe access to external cache" << endmsg;
32 }
33 return collection;
34}
35
36
37template< class IDC, class IDHELPER >
38typename IDC::IDENTIFIABLE*
39Muon::IDC_Helper::addCollection( const Identifier collId, IDC* idc, const IDHELPER& idHelper, MsgStream& log){
40 IdentifierHash idHash;
41 if (idHelper.get_module_hash( collId, idHash )) {
42 log << MSG::ERROR << "Unable to get CSC hash id from CSC RDO collection "
43 << " the identifier is \n"
44 << collId <<endmsg;
45 }
46
47 std::unique_ptr<typename IDC::IDENTIFIABLE> collection;
48 auto collptr = idc->indexFindPtr(idHash);
49 if (collptr == nullptr) {
50 collection = std::make_unique<typename IDC::IDENTIFIABLE>(idHash);
51 collection->setIdentifier(collId);
52 StatusCode status = idc->addCollection(collection.get(), idHash );
53 if (status.isFailure()) {
54 collection.reset();
55 if (idc->indexFindPtr(idHash)) {
56 log << MSG::ERROR << "Attempt to get unsafe access to external cache" << endmsg;
57 }
58 else {
59 log << MSG::ERROR << "Couldn't add collection to IDC" << endmsg;
60 }
61 }
62 } else {
63 log << MSG::ERROR << "Attempt to get unsafe access to external cache" << endmsg;
64 }
65 return collection.release();
66}
67