9#include <b2bii/modules/B2BIIMdstInput/B2BIIMdstInputModule.h>
11#include <framework/core/Environment.h>
12#include <framework/utilities/FileSystem.h>
13#include <framework/database/Configuration.h>
16#include "belle_legacy/tables/belletdf.h"
19#include <framework/utilities/NumberSequence.h>
36vector<string> globbing(
const vector<string>& patterns)
39 for (
const auto& pat : patterns) {
41 glob(pat.c_str(), GLOB_TILDE, NULL, &glob_result);
42 for (
unsigned int i = 0; i < glob_result.gl_pathc; ++i) {
43 ret.push_back(
string(glob_result.gl_pathv[i]));
45 globfree(&glob_result);
71 "For more than one file use inputFileNames", std::string(
""));
75 std::vector<std::string> emptyvector;
77 "The number sequences (e.g. 23:42,101) defining the entries which are processed for each inputFileName."
78 "Must be specified exactly once for each file to be opened."
79 "The first event has the number 0.", emptyvector);
90 if (!inputFiles.empty()) {
104 if (entrySequencesOverride.size() > 0)
109 B2FATAL(
"Empty list of files supplied, cannot continue");
113 B2FATAL(
"Number of provided filenames does not match the number of given entrySequences parameters: len(inputFileNames) = "
122 const char* table_dir = getenv(
"PANTHER_TABLE_DIR");
125 B2WARNING(
"PANTHER_TABLE_DIR environment variable not set correctly. This is a known problem with externals v00-05-09, using " <<
126 fixed_table_dir <<
" instead.");
128 B2FATAL(
"Path " << fixed_table_dir <<
" does not exist, your externals setup seems broken.");
129 setenv(
"PANTHER_TABLE_DIR", fixed_table_dir.c_str(), 1);
149 B2DEBUG(99,
"[B2BIIMdstInputModule::initializeDataStore] initialization of DataStore started");
153 B2DEBUG(99,
"[B2BIIMdstInputModule::initializeDataStore] initialization of DataStore ended");
159 B2DEBUG(99,
"B2BIIMdstInput: beginRun called.");
165 BsClrTab(BBS_CLEAR_ALL);
176 m_fd =
new Belle::Panther_FileIO(name.c_str(), BBS_READ);
179 if (
m_fd->read() == -1) {
180 B2FATAL(
"Couldn't read file '" << name <<
"'!");
201 while (rectype < 0 && rectype != -2) {
204 rectype =
m_fd->read();
206 B2ERROR(
"Error while reading panther tables! Record skipped.");
210 B2DEBUG(99,
"[B2BIIMdstInputModule::Conversion] Conversion stopped at event #" <<
m_nevt <<
". EOF detected!");
233 B2DEBUG(99,
"[B2BIIMdstInputModule::Conversion] Conversion stopped at event #" <<
m_nevt <<
". No more files");
241 Belle::Belle_event_Manager& evman = Belle::Belle_event_Manager::get_manager();
242 Belle::Belle_event& evt = evman[0];
247 Belle::Belle_runhead_Manager& rhdmgr = Belle::Belle_runhead_Manager::get_manager();
248 Belle::Belle_runhead_Manager::const_iterator belleevt = rhdmgr.begin();
250 B2DEBUG(90,
"Event number " <<
m_nevt);
251 if (belleevt == rhdmgr.end() || not(*belleevt)) {
252 B2WARNING(
"Missing RUNHEAD: Creating RUNHEAD from Event. This is as far as we know fine and handled correctly.");
254 Belle::Belle_runhead& bgr = rhdmgr.add();
255 bgr.ExpMC(evt.ExpMC());
256 bgr.ExpNo(evt.ExpNo());
257 bgr.RunNo(evt.RunNo());
258 bgr.Time(evt.Time());
259 bgr.Date(evt.Date());
260 bgr.Field(evt.MagFieldID());
261 bgr.MaxField(evt.BField());
263 bgr.ELER(evt.ELER());
264 bgr.EHER(evt.EHER());
274 Belle::Belle_runhead& bgr = rhdmgr[0];
275 B2DEBUG(90,
"ExpMC " << bgr.ExpMC() <<
" " << evt.ExpMC());
276 B2DEBUG(90,
"ExpNo " << bgr.ExpNo() <<
" " << evt.ExpNo());
277 B2DEBUG(90,
"RunNo " << bgr.RunNo() <<
" " << evt.RunNo());
278 B2DEBUG(90,
"Time " << bgr.Time() <<
" " << evt.Time());
279 B2DEBUG(90,
"Date " << bgr.Date() <<
" " << evt.Date());
280 B2DEBUG(90,
"Field " << bgr.Field() <<
" " << evt.MagFieldID());
281 B2DEBUG(90,
"MaxField " << bgr.MaxField() <<
" " << evt.BField());
282 B2DEBUG(90,
"Type " << bgr.Type());
283 B2DEBUG(90,
"ELER " << bgr.ELER() <<
" " << evt.ELER());
284 B2DEBUG(90,
"EHER " << bgr.EHER() <<
" " << evt.EHER());
288 evtmetadata->setExperiment(evt.ExpNo());
289 evtmetadata->setRun(evt.RunNo());
290 evtmetadata->setEvent(evt.EvtNo() & 0x0fffffff);
293 bool realData = evt.ExpMC() != 2;
294 evtmetadata->setGeneratedWeight(realData ? -1.0 : 1.0);
302 std::string tag = realData ?
"B2BII" :
"B2BII_MC";
307 B2FATAL(
"Information whether we process real or simulated data has changed. Refusing to continue");
311 B2DEBUG(90,
"[B2BIIMdstInputModule] Convert exp/run/evt: " << evt.ExpNo() <<
"/" << evt.RunNo() <<
"/" <<
int(
312 evt.EvtNo() & 0x0fffffff));
317 B2INFO(
"B2BIIMdstInput: endRun done.");
324 B2INFO(
"B2BIIMdstInput: 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.
std::vector< std::string > getEntrySequencesOverride() const
Returns the number sequences (e.g.
const std::vector< std::string > & getInputFilesOverride() const
Return overriden input file names, or empty vector if none were set.
const std::string & getExternalsPath() const
Returns the path which points to the externals directory of the framework.
static Environment & Instance()
Static method to get a reference to the Environment instance.
static bool isDir(const std::string &filename)
Check if filename points to an existing directory.
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).
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.
std::set< int64_t > generate_number_sequence(const std::string &str)
Generate a sequence of numbers defined by a string.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.