ATLAS Offline Software
CopyEventStreamInfo.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 #include "CopyEventStreamInfo.h"
12 
14 #include "StoreGate/StoreGateSvc.h"
15 
16 //___________________________________________________________________________
18  const std::string& name,
19  const IInterface* parent) : ::AthAlgTool(type, name, parent),
20  m_metaDataSvc("MetaDataSvc", name),
21  m_inputMetaDataStore("StoreGateSvc/InputMetaDataStore", name) {
22  // Declare IMetaDataTool interface
23  declareInterface<IMetaDataTool>(this);
24 }
25 //___________________________________________________________________________
27 }
28 //___________________________________________________________________________
30  ATH_MSG_INFO("Initializing " << name());
31  // Locate the MetaDataSvc and InputMetaDataStore
32  if (!m_metaDataSvc.retrieve().isSuccess()) {
33  ATH_MSG_FATAL("Could not find MetaDataSvc");
34  return(StatusCode::FAILURE);
35  }
36  if (!m_inputMetaDataStore.retrieve().isSuccess()) {
37  ATH_MSG_FATAL("Could not find InputMetaDataStore");
38  return(StatusCode::FAILURE);
39  }
40  return(StatusCode::SUCCESS);
41 }
42 //___________________________________________________________________________
44  ATH_MSG_DEBUG("in finalize()");
45  // release the MetaDataSvc and InputMetaDataStore
46  if (!m_metaDataSvc.release().isSuccess()) {
47  ATH_MSG_WARNING("Could not release MetaDataSvc");
48  }
49  if (!m_inputMetaDataStore.release().isSuccess()) {
50  ATH_MSG_WARNING("Could not release InputMetaDataStore");
51  }
52  return(StatusCode::SUCCESS);
53 }
54 
55 
57 {
58  std::vector<std::string> keys = m_keys;
59  if (keys.empty()) {
61  } else {
62  // remove keys not in the InputMetaDataStore
63  keys.erase(
64  std::remove_if(
65  keys.begin(), keys.end(),
66  [this](std::string& key) {
67  return !m_inputMetaDataStore->contains<EventStreamInfo>(key);
68  }),
69  keys.end());
70  }
71 
72  // If the input file doesn't have any event format metadata,
73  // then finish right away:
74  if (keys.empty()) return StatusCode::SUCCESS;
75 
76  for (const auto &key : keys) {
77  // Ignore versioned container
78  if (key.substr(0, 1) == ";" && key.substr(3, 1) == ";") {
79  ATH_MSG_VERBOSE( "Ignore versioned container: " << key );
80  continue;
81  }
82  std::list<SG::ObjectWithVersion<EventStreamInfo> > allVersions;
83  if (!m_inputMetaDataStore->retrieveAllVersions(allVersions, key).isSuccess()) {
84  ATH_MSG_ERROR("Could not retrieve all versions for EventStreamInfo");
85  return StatusCode::FAILURE;
86  }
87  EventStreamInfo* evtStrInfo_out = 0;
88  for (SG::ObjectWithVersion<EventStreamInfo>& obj : allVersions) {
89  const EventStreamInfo* evtStrInfo_in = obj.dataObject.cptr();
90  evtStrInfo_out = m_metaDataSvc->tryRetrieve<EventStreamInfo>(key);
91  if( !evtStrInfo_out ) {
92  auto esinfo_up = std::make_unique<EventStreamInfo>(*evtStrInfo_in);
93  if( m_metaDataSvc->record( std::move(esinfo_up), key ).isFailure()) {
94  ATH_MSG_ERROR("Could not record DataObject: " << key);
95  return StatusCode::FAILURE;
96  }
97  } else {
98  evtStrInfo_out->addEvent(evtStrInfo_in->getNumberOfEvents());
99  for (auto elem = evtStrInfo_in->getRunNumbers().begin(),
100  lastElem = evtStrInfo_in->getRunNumbers().end();
101  elem != lastElem; elem++) {
102  evtStrInfo_out->insertRunNumber(*elem);
103  }
104  for (auto elem = evtStrInfo_in->getLumiBlockNumbers().begin(),
105  lastElem = evtStrInfo_in->getLumiBlockNumbers().end();
106  elem != lastElem; elem++) {
107  evtStrInfo_out->insertLumiBlockNumber(*elem);
108  }
109  for (auto elem = evtStrInfo_in->getProcessingTags().begin(),
110  lastElem = evtStrInfo_in->getProcessingTags().end();
111  elem != lastElem; elem++) {
112  evtStrInfo_out->insertProcessingTag(*elem);
113  }
114  for (auto elem = evtStrInfo_in->getItemList().begin(),
115  lastElem = evtStrInfo_in->getItemList().end();
116  elem != lastElem; elem++) {
117  evtStrInfo_out->insertItemList((*elem).first, (*elem).second);
118  }
119  for (auto elem = evtStrInfo_in->getEventTypes().begin(),
120  lastElem = evtStrInfo_in->getEventTypes().end();
121  elem != lastElem; elem++) {
122  evtStrInfo_out->insertEventType(*elem);
123  }
124  }
125  }
126  }
127  return(StatusCode::SUCCESS);
128 }
130 {
131  return(StatusCode::SUCCESS);
132 }
134 {
135  return(StatusCode::SUCCESS);
136 }
CopyEventStreamInfo.h
This file contains the class definition for the CopyEventStreamInfo class.
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
EventStreamInfo::getRunNumbers
const std::set< unsigned int > & getRunNumbers() const
Definition: EventStreamInfo.cxx:23
CopyEventStreamInfo::initialize
StatusCode initialize()
AthAlgTool Interface method implementations:
Definition: CopyEventStreamInfo.cxx:29
EventStreamInfo::getProcessingTags
const std::set< std::string > & getProcessingTags() const
Definition: EventStreamInfo.cxx:35
CopyEventStreamInfo::m_inputMetaDataStore
ServiceHandle< StoreGateSvc > m_inputMetaDataStore
MetaDataStore for input.
Definition: CopyEventStreamInfo.h:56
EventStreamInfo::getEventTypes
const std::set< EventType > & getEventTypes() const
Definition: EventStreamInfo.cxx:47
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
CopyEventStreamInfo::m_keys
Gaudi::Property< std::vector< std::string > > m_keys
(optional) list of keys to copy, all if empty, default: empty
Definition: CopyEventStreamInfo.h:50
CopyEventStreamInfo::beginInputFile
virtual StatusCode beginInputFile(const SG::SourceID &="Serial")
Function called when a new input file is opened.
Definition: CopyEventStreamInfo.cxx:56
EventStreamInfo.h
This file contains the class definition for the EventStreamInfo class.
EventStreamInfo::getLumiBlockNumbers
const std::set< unsigned int > & getLumiBlockNumbers() const
Definition: EventStreamInfo.cxx:29
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EventStreamInfo::insertRunNumber
void insertRunNumber(unsigned int run)
Insert new Run Number into a set.
Definition: EventStreamInfo.cxx:59
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
EventStreamInfo::addEvent
void addEvent(unsigned int number=1)
Increase Event Counter.
Definition: EventStreamInfo.cxx:53
EventStreamInfo::insertProcessingTag
void insertProcessingTag(const std::string &process)
Insert new Processing Tag into a set.
Definition: EventStreamInfo.cxx:71
CopyEventStreamInfo::~CopyEventStreamInfo
virtual ~CopyEventStreamInfo()
Destructor.
Definition: CopyEventStreamInfo.cxx:26
CopyEventStreamInfo::m_metaDataSvc
ServiceHandle< IAthMetaDataSvc > m_metaDataSvc
Access to output MetaDataStore through MetaDataSvc (using MetaContainers)
Definition: CopyEventStreamInfo.h:54
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
EventStreamInfo::getNumberOfEvents
unsigned int getNumberOfEvents() const
Definition: EventStreamInfo.cxx:17
EventStreamInfo::getItemList
const std::set< std::pair< CLID, std::string > > & getItemList() const
Definition: EventStreamInfo.cxx:41
CopyEventStreamInfo::metaDataStop
virtual StatusCode metaDataStop()
Function called when the tool should write out its metadata.
Definition: CopyEventStreamInfo.cxx:133
CopyEventStreamInfo::CopyEventStreamInfo
CopyEventStreamInfo(const std::string &type, const std::string &name, const IInterface *parent)
Standard AlgTool Constructor.
Definition: CopyEventStreamInfo.cxx:17
EventStreamInfo
This class provides the summary information stored for data written as a Event Stream.
Definition: EventStreamInfo.h:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CopyEventStreamInfo::endInputFile
virtual StatusCode endInputFile(const SG::SourceID &="Serial")
Function called when the currently open input file got completely processed.
Definition: CopyEventStreamInfo.cxx:129
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SG::SourceID
std::string SourceID
Definition: AthenaKernel/AthenaKernel/SourceID.h:23
EventStreamInfo::insertItemList
void insertItemList(CLID type, const std::string &key)
Insert new ItemList Entry into a set.
Definition: EventStreamInfo.cxx:77
CopyEventStreamInfo::finalize
StatusCode finalize()
Definition: CopyEventStreamInfo.cxx:43
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
AthAlgTool
Definition: AthAlgTool.h:26
SG::ObjectWithVersion
associate a data object with its VersionedKey The object is held by a ReadHandle to delay its retriev...
Definition: SGVersionedKey.h:17
python.PyAthena.obj
obj
Definition: PyAthena.py:135
StoreGateSvc.h
EventStreamInfo::insertEventType
void insertEventType(const EventType &event)
Insert new Event Type into a set.
Definition: EventStreamInfo.cxx:83
EventStreamInfo::insertLumiBlockNumber
void insertLumiBlockNumber(unsigned int lumiBlock)
Insert new Luminosity Block Number into a set.
Definition: EventStreamInfo.cxx:65
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37