9#include <framework/modules/rootio/SeqRootOutputModule.h>
10#include <framework/datastore/DataStore.h>
11#include <framework/core/Environment.h>
17#include <TVirtualStreamerInfo.h>
34 setDescription(
"Save a sequential ROOT file (non-standard I/O format used in DAQ). See https://xwiki.desy.de/xwiki/rest/p/401e7 for further information and a comparison with the .root format.");
40 vector<string> emptyvector;
43 "Output file name. Add a .gz suffix to save a gzip-compressed file. Parameter can be overridden using the -o argument to basf2.",
44 string(
"SeqRootOutput.sroot"));
46 "Compression Level: 0 for no, 1 for low, 9 for high compression. Level 1 usually reduces size by 50%, higher levels have no noticable effect. NOTE: Because of a ROOT bug ( https://sft.its.cern.ch/jira/browse/ROOT-4550 ), this option currently causes memory leaks and is disabled.",
50 "instead of the standard where subsequent files are named .sroot-N. For example 'myfile-f%08d.sroot'",
false);
54SeqRootOutputModule::~SeqRootOutputModule()
62 if (!outputFileArgument.empty())
80 B2INFO(
"SeqRootOutput: initialized.");
88 gettimeofday(&
m_t0,
nullptr);
93 B2INFO(
"SeqRootOutput: beginRun called.");
108 double dsize = (double)stat / 1000.0;
119 gettimeofday(&
m_tend,
nullptr);
120 auto etime = (double)((
m_tend.tv_sec -
m_t0.tv_sec) * 1000000 +
126 double flowmb =
m_size / etime * 1000.0;
129 double sigma2 = avesize2 - avesize * avesize;
130 double sigma =
sqrt(sigma2);
132 B2INFO(
"SeqRootOutput : " <<
m_nevt <<
" events written with total bytes of " <<
m_size <<
" kB");
133 B2INFO(
"SeqRootOutput : flow rate = " << flowmb <<
" (MB/s)");
134 B2INFO(
"SeqRootOutput : event size = " << avesize <<
" +- " << sigma <<
" (kB)");
136 B2INFO(
"SeqRootOutput: endRun done.");
146 B2INFO(
"terminate called");
158 B2FATAL(
"DataStoreStreamer : m_msghandler is NULL.");
162 TList* minilist = nullptr ;
166 for (
auto& iter : map) {
167 const TClass* entryClass = iter.second.objClass;
168 TVirtualStreamerInfo* vinfo = entryClass->GetStreamerInfo();
169 B2INFO(
"Recording StreamerInfo : durability " << durability <<
" : Class Name " << entryClass->GetName());
170 if (!minilist) minilist =
new TList();
171 minilist->Add(vinfo);
181 (msg->
header())->nObjects = 1;
182 (msg->
header())->nArrays = 0;
191 B2FATAL(
"getStreamerInfo() is called twice in the same run ");
202 B2FATAL(
"Failed to get StreamerInfo : ");
Stream/restore DataStore objects to/from EvtMessage.
EvtMessage * streamDataStore(bool addPersistentDurability, bool streamTransientObjects=false)
Store DataStore objects in EvtMessage.
void setStreamingObjects(const std::vector< std::string > &list)
Set names of objects to be streamed/destreamed.
StoreEntryMap & getStoreEntryMap(EDurability durability)
Get a reference to the object/array map.
static const int c_NDurabilityTypes
Number of Durability Types.
EDurability
Durability types.
static DataStore & Instance()
Instance of singleton Store.
std::map< std::string, StoreEntry > StoreEntryMap
Map for StoreEntries.
const std::string & getOutputFileOverride() const
Return overriden output file name, or "" if none was set.
static Environment & Instance()
Static method to get a reference to the Environment instance.
Class to manage streamed object.
EvtHeader * header()
Get pointer to EvtHeader.
char * buffer()
Get buffer address.
void setDescription(const std::string &description)
Sets the description of the module.
A class to encode/decode an EvtMessage.
virtual void add(const TObject *, const std::string &name)
Add an object to be streamed.
virtual EvtMessage * encode_msg(ERecordType rectype)
Stream object list into an EvtMessage.
A class to manage I/O for a chain of blocked files.
int write(const char *buf)
Write a record to a file.
int m_nevt
Total nr. of events in the file.
DataStoreStreamer * m_streamer
DataStoreStreamer.
virtual void initialize() override
Module functions to be called from main process.
virtual void event() override
This method is the core of the module.
struct timeval m_tend
time at end of current run.
virtual void endRun() override
This method is called if the current run ends.
virtual void terminate() override
This method is called at the end of the event processing.
bool m_fileNameIsPattern
If true the output filename will be interpreted as a boost::format pattern.
int m_streamerinfo_size
The size of the StreamerInfo.
SeqFile * m_file
Blocked file handler.
MsgHandler * m_msghandler
Messaage handler.
virtual void beginRun() override
Module functions to be called from event process.
std::vector< std::string > m_saveObjs
List of objects to be saved.
int m_compressionLevel
Compression level.
SeqRootOutputModule()
Constructor / Destructor.
double m_size
total transferred data, in kB.
void getStreamerInfos()
! Write StreamerInfos to a file
char * m_streamerinfo
StreamerInfo to be written.
std::string m_outputFileName
File name.
double m_size2
sum of squares of data transferred in each event, in kB^2.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.