9#include <framework/modules/rootio/SeqRootInputModule.h>
11#include <framework/core/Environment.h>
12#include <framework/datastore/DataStore.h>
13#include <framework/datastore/StoreObjPtr.h>
14#include <framework/dataobjects/FileMetaData.h>
15#include <framework/database/Configuration.h>
40 "Input file name. Can also be a gzip-compressed file (with suffix .gz). "
41 "Parameter can be overridden using the -i argument to basf2.",
46 "filename as a boost::format pattern instead of the standard where "
47 "subsequent files are named .sroot-N. For example 'myfile-f%08d.sroot'",
49 addParam(
"declareRealData",
m_realData,
"Declare the input to be real, not generated data",
false);
52SeqRootInputModule::~SeqRootInputModule() =
default;
58 B2FATAL(
"Cannot specify both 'inputFileName' and 'inputFileNames'");
61 if (!inputFiles.empty()) {
62 if (inputFiles.size() > 1) {
85 B2FATAL(
"SeqRootInput : Error in opening input file : " <<
m_inputFileName);
97 if (evtmsg->
type() == MSG_STREAMERINFO) {
99 B2INFO(
"Reading StreamerInfo");
100 if (info_cnt != 0) B2FATAL(
"SeqRootInput : Reading StreamerInfos twice");
112 B2FATAL(
"SeqRootInput : Error in reading first event");
121 fileMetaData->declareRealData();
131 gettimeofday(&
m_t0,
nullptr);
135 B2INFO(
"SeqRootInput: beginRun called.");
144 if (++
m_nevt == 0)
return;
151 B2ERROR(
"SeqRootInput : file read error");
157 }
else if (size == 0) {
158 B2INFO(
"SeqRootInput : EOF detected");
172 B2FATAL(
"SeqRootInput : Error in opening input file : " <<
m_inputFileName);
178 B2FATAL(
"SeqRootInput : Error in reading file. error code = " << is);
183 B2FATAL(
"SeqRootInput : Error in reading file. error code = " << is);
191 double dsize = (double)size / 1000.0;
195 if (evtmsg->
type() == MSG_STREAMERINFO) {
196 B2WARNING(
"SeqRootInput : StreamerInfo is found in the middle of *.sroot-* files. Skip record");
199 B2FATAL(
"SeqRootInput : Error in reading file. error code = " << is);
217 gettimeofday(&
m_tend,
nullptr);
218 auto etime = (double)((
m_tend.tv_sec -
m_t0.tv_sec) * 1000000 +
224 double flowmb =
m_size / etime * 1000.0;
225 double evrate = (double)
m_nevt / (etime / 1000.0);
228 double sigma2 = avesize2 - avesize * avesize;
229 double sigma =
sqrt(sigma2);
233 B2INFO(
"SeqRootInput : " <<
m_nevt <<
" events read with total bytes of " <<
m_size <<
" kB");
234 B2INFO(
"SeqRootInput : event rate = " << evrate <<
" (KHz)");
235 B2INFO(
"SeqRootInput : flow rate = " << flowmb <<
" (MB/s)");
236 B2INFO(
"SeqRootInput : event size = " << avesize <<
" +- " << sigma <<
" (kB)");
238 B2INFO(
"SeqRootInput: endRun done.");
246 B2INFO(
"SeqRootInput: terminate called");
static Configuration & getInstance()
Get a reference to the instance which will be used when the Database is initialized.
void setInputGlobaltags(const std::vector< std::string > &inputTags)
To be called by input modules with the tags to be added from input files.
Stream/restore DataStore objects to/from EvtMessage.
int restoreDataStore(EvtMessage *msg)
Restore DataStore objects from EvtMessage.
@ c_Persistent
Object is available during entire execution time.
const std::vector< std::string > & getInputFilesOverride() const
Return overridden input file names, or empty vector if none were set.
static Environment & Instance()
Static method to get a reference to the Environment instance.
Class to manage streamed object.
ERecordType type() const
Get record type.
static const unsigned int c_MaxEventSize
maximal EvtMessage size, in bytes (200MB).
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_Input
This module is an input module (reads data).
A class to manage I/O for a chain of blocked files.
int status() const
Returns status after constructor call.
int read(char *buf, int max)
Read a record from a file.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
Type-safe access to single objects in the data store.
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.