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