8#include <boost/shared_ptr.hpp>
17#include "EventStorage/EventStorageRecords.h"
18#include "EventStorage/RawFileName.h"
19#include "EventStorage/SimpleFileName.h"
23#include "GaudiKernel/ServiceHandle.h"
24#include "GaudiKernel/IIoComponentMgr.h"
32 const std::string& name, ISvcLocator* pSvcLocator)
33 : base_class(name, pSvcLocator) {
59 const std::vector< std::string > choices_ef{
"current",
"v40",
"run1"};
61 == choices_ef.end()) {
62 ATH_MSG_FATAL(
"Unexpected value for EformatVersion property: "
64 return StatusCode::FAILURE;
69 const std::vector< std::string > choices_es{
"current",
"v5",
"run1"};
71 == choices_es.end()) {
72 ATH_MSG_FATAL(
"Unexpected value for EventStorageVersion property: "
74 return StatusCode::FAILURE;
83 return StatusCode::SUCCESS;
90 return StatusCode::SUCCESS;
103 if (!dWok)
ATH_MSG_WARNING(
"Could not write Metadata for eventless file");
106 return StatusCode::SUCCESS;
117 return StatusCode::SUCCESS;
127 if (eventInfo ==
nullptr)
ATH_MSG_WARNING(
"failed to retrieve EventInfo");
130 if (metaData ==
nullptr)
143 if (evtInfo or metaData)
146 throw std::runtime_error(
"Cannot write data without run parameters");
166 << params.fileNameCore);
177 return putEvent(
re, Gaudi::Hive::currentContext());
183 const RawEvent*
re,
const EventContext& ctx) {
192 cache->
size =
re->fragment_size_word();
201 cache->
buffer = std::make_unique< DataType[] >(cache->
size);
203 << std::hex << cache->
buffer.get() << std::dec);
211 if (cache->
size == 0) {
213 ATH_MSG_ERROR(
"Failed to convert event, buffer is too small");
218 <<
" version = " << cache->
buffer.get()[3]);
221 cache->
buffer = std::make_unique< DataType[] >(cache->
size);
222 std::copy(
re->start(),
re->start() + cache->
size, cache->
buffer.get());
239 EventStorage::DWError write_result =
m_dataWriter->putData(
241 reinterpret_cast< void*
>(cache->
buffer.get()));
244 if (write_result != EventStorage::DWOK) {
259 if (!
m_ioMgr->io_hasitem(
this)) {
260 ATH_MSG_FATAL(
"IoComponentMgr does not know about myself !");
261 return StatusCode::FAILURE;
266 ATH_MSG_INFO(
"I/O reinitialization, file = " << outputFile);
267 std::string &fname = outputFile;
268 if (!
m_ioMgr->io_contains(
this, fname)) {
269 ATH_MSG_ERROR(
"IoComponentMgr does not know about [" << fname <<
"] !");
270 return StatusCode::FAILURE;
275 m_inputDir.setValue(outputFile.substr(0, outputFile.find_last_of(
"/")));
286 return StatusCode::SUCCESS;
295 if (!metaDataCont.
isValid())
return nullptr;
297 if (metaDataCont->size() > 1)
299 "Bytestream format only supports one. Arbitrarily "
302 return metaDataCont->front();
308 const EventContext& ctx)
312 if (!metaDataCont.
isValid())
return nullptr;
314 if (metaDataCont->size() > 1)
316 "Bytestream format only supports one. Arbitrarily "
319 return metaDataCont->front();
329 else params.version = 0;
333 if (
m_run != 0) params.rPar.run_number =
m_run;
342 if (params.streamType.empty()) params.streamType =
"Single";
343 if (params.streamName.empty()) params.streamName =
"Stream";
345 params.stream = params.streamType +
"_" + params.streamName;
353 boost::shared_ptr<EventStorage::SimpleFileName> simple_file_name(
355 params.theFNCB = simple_file_name;
358 daq::RawFileName fileNameObj(
360 params.rPar.run_number,
363 params.lumiBlockNumber,
364 params.applicationName);
365 params.fileNameCore = fileNameObj.fileNameCore();
370 : EventStorage::NONE;
373 params.maxFileNE = params.rPar.max_events =
m_maxFileNE;
380 ATH_MSG_DEBUG(
"Parsing run parameters from EventInfo" << eventInfo);
382 params.rPar.run_number = eventInfo.
runNumber();
383 params.lumiBlockNumber = eventInfo.
lumiBlock();
386 if(!tag.type().empty()) {
387 params.streamType = tag.type();
392 if (!tag.name().empty()) {
393 params.streamName = tag.name();
398 params.fmdStrings.push_back(tag.first +
' ' + tag.second);
401 std::string beamTypeStr =
m_tagInfoMgr->findInputTag(
"beam_type");
402 if (!beamTypeStr.empty()) {
403 ATH_MSG_DEBUG(
"Got beam_type from input file metadata: " << beamTypeStr);
404 if (beamTypeStr ==
"collisions") {
405 params.rPar.beam_type = 1;
406 }
else if (beamTypeStr ==
"cosmics") {
407 params.rPar.beam_type = 0;
411 std::string beamEnergyStr =
m_tagInfoMgr->findInputTag(
"beam_energy");
412 if (!beamEnergyStr.empty()) {
414 params.rPar.beam_energy = std::stoul(beamEnergyStr);
415 ATH_MSG_DEBUG(
"Got beam_energy from input file metadata: " << params.rPar.beam_energy);
416 }
catch (
const std::exception& e) {
417 ATH_MSG_WARNING(
"Could not convert beam_energy '" << beamEnergyStr <<
"' to number: " << e.what());
422 const std::vector<std::string>* iovMetaStrings =
m_metaDataStore->tryRetrieve<std::vector<std::string>>(
"IOVMetaDataStrings");
423 if (iovMetaStrings !=
nullptr) {
424 ATH_MSG_DEBUG(
"Retrieved " << iovMetaStrings->size() <<
" IOV metadata strings from MetaDataStore");
425 for (
const std::string&
str : *iovMetaStrings) {
426 params.fmdStrings.push_back(
str);
429 ATH_MSG_DEBUG(
"No IOV metadata strings found in MetaDataStore (this is normal if not configured)");
433 params.rPar.detector_mask_LS = eventInfo.
detectorMask();
436 std::string event_type =
"Event type: sim/data - ";
438 event_type +=
"is sim";
439 else event_type +=
"is data";
441 event_type +=
" , testbeam/atlas - ";
443 event_type +=
"is testbeam";
444 else event_type +=
"is atlas";
446 event_type +=
" , calibration/physics - ";
448 event_type +=
"is calibration";
449 else event_type +=
"is physics";
451 params.fmdStrings.push_back(std::move(event_type));
458 ATH_MSG_DEBUG(
"Parsing run parameters from metadata:\n" << metaData);
463 const std::string stream = metaData.
getStream();
464 const std::string::size_type
split = stream.find(
'_');
466 if (
split != std::string::npos and params.streamType.empty())
467 params.streamType = stream.substr(0,
split);
469 if (
split != std::string::npos and params.streamName.empty())
470 params.streamName = stream.substr(
split+1);
473 params.maxFileNE = params.rPar.max_events = metaData.
getMaxEvents();
485 params.fmdStrings.push_back(fmd);
const boost::regex re(r_e)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
This file contains the class definition for the ByteStreamDataWriter class.
This file contains the class definition for the ByteStreamEventStorageOutputSvc class.
OFFLINE_FRAGMENTS_NAMESPACE::FullEventFragment RawEvent
data type for reading raw event
Handle class for reading from StoreGate.
static std::unique_ptr< ByteStreamDataWriter > makeWriter(int version, const std::string &writingPath, const std::string &fileNameCore, const EventStorage::run_parameters_record &rPar, const std::vector< std::string > &fmdStrings, unsigned int maxFileNE=0, unsigned int maxFileMB=0, unsigned int startIndex=1, EventStorage::CompressionType compression=EventStorage::NONE, unsigned int compLevel=1)
Factory method returning data writer instance for specified version.
Gaudi::Property< unsigned int > m_maxFileMB
number of events per file
ServiceHandle< IIoComponentMgr > m_ioMgr
StatusCode reinit()
reinitialize the service when a fork() occurred/was-issued
Gaudi::Property< std::string > m_projectTag
Application Name.
Gaudi::Property< bool > m_writeEventless
Compress events.
Gaudi::Property< std::string > m_streamType
stream name
StatusCode finalize() override
StatusCode initialize() override
Required of all Gaudi Services.
Gaudi::Property< unsigned int > m_maxFileNE
Gaudi::Property< std::string > m_eventStorageVersion
stream name for multiple output
std::mutex m_dataWriterMutex
mutex to lock data writer during initialization or writing
Gaudi::Property< std::string > m_simpleFileName
use this string for filename, not from the "AgreedFileName"
StatusCode io_reinit() override
bool initDataWriter(const EventContext *ctx=nullptr)
initialize EventStorage's DataWriter
int m_totalEventCounter
number of event counter
Gaudi::Property< int > m_lumiBlockNumber
run number
virtual bool putEvent(const RawEvent *re) override
Implementation of the IByteStreamOutputSvc interface method putEvent.
SG::SlotSpecificObj< EventCache > m_eventCache
Cache of event data for each slot.
SG::ReadHandleKey< ByteStreamMetadataContainer > m_byteStreamMetadataKey
ServiceHandle< ITagInfoMgr > m_tagInfoMgr
Gaudi::Property< std::string > m_eformatVersion
EventStorage BS version to produce, "v5" for run1, or "current".
ByteStreamEventStorageOutputSvc(const std::string &name, ISvcLocator *pSvcLocator)
Constructors:
Gaudi::Property< int > m_run
Dump fragments.
ServiceHandle< StoreGateSvc > m_metaDataStore
Gaudi::Property< std::string > m_appName
File Tag.
void updateDataWriterParameters(DataWriterParameters &) const
Create DataWriter parameters from job properties.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
StatusCode stop() override
Gaudi::Property< std::string > m_streamName
eformat event version to produce, "v40" for run1, or "current"
Gaudi::Property< bool > m_compressEvents
number of MB per file
std::unique_ptr< ByteStreamDataWriter > m_dataWriter
pointer to DataWriter
const ByteStreamMetadata * getByteStreamMetadata()
Gaudi::Property< std::string > m_inputDir
< directory for the data files
bool initDataWriterContents(const xAOD::EventInfo *, const ByteStreamMetadata *)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Class describing a stream tag on the event.
uint32_t lumiBlock() const
The current event's luminosity block number.
bool eventType(EventType type) const
Check for one particular bitmask value.
uint16_t level1TriggerType() const
The Level-1 trigger type.
uint64_t detectorMaskExt() const
Bit field indicating which TTC zones are present in the event.
const std::vector< StreamTag > & streamTags() const
Get the streams that the event was put in.
@ IS_CALIBRATION
true: calibration, false: physics
@ IS_SIMULATION
true: simulation, false: data
@ IS_TESTBEAM
true: testbeam, false: full detector
uint32_t runNumber() const
The current event's run number.
uint64_t detectorMask() const
Bit field indicating which TTC zones are present in the event.
const DetDescrTags_t & detDescrTags() const
The detector description tags.
std::vector< std::string > split(const std::string &s, const std::string &t=":")
const DataType * PointerType
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
EventInfo_v1 EventInfo
Definition of the latest event info version.
std::unique_ptr< uint32_t[] > buffer
Underlying data structure.
Class containing parameters needed to initiate DataWriter.
Declarations of methods for working with old eformat versions.