8#include <boost/shared_ptr.hpp>
16#include "EventStorage/EventStorageRecords.h"
17#include "EventStorage/RawFileName.h"
18#include "EventStorage/SimpleFileName.h"
22#include "GaudiKernel/ServiceHandle.h"
23#include "GaudiKernel/IIoComponentMgr.h"
31 const std::string& name, ISvcLocator* pSvcLocator)
32 : base_class(name, pSvcLocator) {
59 return StatusCode::SUCCESS;
66 return StatusCode::SUCCESS;
79 if (!dWok)
ATH_MSG_WARNING(
"Could not write Metadata for eventless file");
82 return StatusCode::SUCCESS;
93 return StatusCode::SUCCESS;
103 if (eventInfo ==
nullptr)
ATH_MSG_WARNING(
"failed to retrieve EventInfo");
106 if (metaData ==
nullptr)
119 if (evtInfo or metaData)
122 throw std::runtime_error(
"Cannot write data without run parameters");
142 << params.fileNameCore);
153 return putEvent(
re, Gaudi::Hive::currentContext());
159 const RawEvent*
re,
const EventContext& ctx) {
168 cache->
size =
re->fragment_size_word();
171 cache->
buffer = std::make_unique< DataType[] >(cache->
size);
172 std::copy(
re->start(),
re->start() + cache->
size, cache->
buffer.get());
188 EventStorage::DWError write_result =
m_dataWriter->putData(
190 reinterpret_cast< void*
>(cache->
buffer.get()));
193 if (write_result != EventStorage::DWOK) {
208 if (!
m_ioMgr->io_hasitem(
this)) {
209 ATH_MSG_FATAL(
"IoComponentMgr does not know about myself !");
210 return StatusCode::FAILURE;
215 ATH_MSG_INFO(
"I/O reinitialization, file = " << outputFile);
216 std::string &fname = outputFile;
217 if (!
m_ioMgr->io_contains(
this, fname)) {
218 ATH_MSG_ERROR(
"IoComponentMgr does not know about [" << fname <<
"] !");
219 return StatusCode::FAILURE;
224 m_inputDir.setValue(outputFile.substr(0, outputFile.find_last_of(
"/")));
235 return StatusCode::SUCCESS;
244 if (!metaDataCont.
isValid())
return nullptr;
246 if (metaDataCont->size() > 1)
248 "Bytestream format only supports one. Arbitrarily "
251 return metaDataCont->front();
257 const EventContext& ctx)
261 if (!metaDataCont.
isValid())
return nullptr;
263 if (metaDataCont->size() > 1)
265 "Bytestream format only supports one. Arbitrarily "
268 return metaDataCont->front();
279 if (
m_run != 0) params.rPar.run_number =
m_run;
288 if (params.streamType.empty()) params.streamType =
"Single";
289 if (params.streamName.empty()) params.streamName =
"Stream";
291 params.stream = params.streamType +
"_" + params.streamName;
299 boost::shared_ptr<EventStorage::SimpleFileName> simple_file_name(
301 params.theFNCB = simple_file_name;
304 daq::RawFileName fileNameObj(
306 params.rPar.run_number,
309 params.lumiBlockNumber,
310 params.applicationName);
311 params.fileNameCore = fileNameObj.fileNameCore();
316 : EventStorage::NONE;
319 params.maxFileNE = params.rPar.max_events =
m_maxFileNE;
326 ATH_MSG_DEBUG(
"Parsing run parameters from EventInfo" << eventInfo);
328 params.rPar.run_number = eventInfo.
runNumber();
329 params.lumiBlockNumber = eventInfo.
lumiBlock();
332 if(!tag.type().empty()) {
333 params.streamType = tag.type();
338 if (!tag.name().empty()) {
339 params.streamName = tag.name();
344 params.fmdStrings.push_back(tag.first +
' ' + tag.second);
347 std::string beamTypeStr =
m_tagInfoMgr->findInputTag(
"beam_type");
348 if (!beamTypeStr.empty()) {
349 ATH_MSG_DEBUG(
"Got beam_type from input file metadata: " << beamTypeStr);
350 if (beamTypeStr ==
"collisions") {
351 params.rPar.beam_type = 1;
352 }
else if (beamTypeStr ==
"cosmics") {
353 params.rPar.beam_type = 0;
357 std::string beamEnergyStr =
m_tagInfoMgr->findInputTag(
"beam_energy");
358 if (!beamEnergyStr.empty()) {
360 params.rPar.beam_energy = std::stoul(beamEnergyStr);
361 ATH_MSG_DEBUG(
"Got beam_energy from input file metadata: " << params.rPar.beam_energy);
362 }
catch (
const std::exception& e) {
363 ATH_MSG_WARNING(
"Could not convert beam_energy '" << beamEnergyStr <<
"' to number: " << e.what());
368 const std::vector<std::string>* iovMetaStrings =
m_metaDataStore->tryRetrieve<std::vector<std::string>>(
"IOVMetaDataStrings");
369 if (iovMetaStrings !=
nullptr) {
370 ATH_MSG_DEBUG(
"Retrieved " << iovMetaStrings->size() <<
" IOV metadata strings from MetaDataStore");
371 for (
const std::string&
str : *iovMetaStrings) {
372 params.fmdStrings.push_back(
str);
375 ATH_MSG_DEBUG(
"No IOV metadata strings found in MetaDataStore (this is normal if not configured)");
379 params.rPar.detector_mask_LS = eventInfo.
detectorMask();
382 std::string event_type =
"Event type: sim/data - ";
384 event_type +=
"is sim";
385 else event_type +=
"is data";
387 event_type +=
" , testbeam/atlas - ";
389 event_type +=
"is testbeam";
390 else event_type +=
"is atlas";
392 event_type +=
" , calibration/physics - ";
394 event_type +=
"is calibration";
395 else event_type +=
"is physics";
397 params.fmdStrings.push_back(std::move(event_type));
404 ATH_MSG_DEBUG(
"Parsing run parameters from metadata:\n" << metaData);
409 const std::string stream = metaData.
getStream();
410 const std::string::size_type
split = stream.find(
'_');
412 if (
split != std::string::npos and params.streamType.empty())
413 params.streamType = stream.substr(0,
split);
415 if (
split != std::string::npos and params.streamName.empty())
416 params.streamName = stream.substr(
split+1);
419 params.maxFileNE = params.rPar.max_events = metaData.
getMaxEvents();
431 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
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
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
EventStorage BS version to produce, "v5" 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.