-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathTimeframeReaderDevice.cxx
More file actions
69 lines (59 loc) · 1.98 KB
/
TimeframeReaderDevice.cxx
File metadata and controls
69 lines (59 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include <cstring>
#include "DataFlow/TimeframeReaderDevice.h"
#include "DataFlow/TimeframeParser.h"
#include "Headers/SubframeMetadata.h"
#include "Headers/DataHeader.h"
#include <options/FairMQProgOptions.h>
using DataHeader = o2::header::DataHeader;
namespace o2
{
namespace data_flow
{
TimeframeReaderDevice::TimeframeReaderDevice()
: O2Device{}, mOutChannelName{}, mFile{}
{
}
void TimeframeReaderDevice::InitTask()
{
mOutChannelName = GetConfig()->GetValue<std::string>(OptionKeyOutputChannelName);
mInFileName = GetConfig()->GetValue<std::string>(OptionKeyInputFileName);
mSeen.clear();
}
bool TimeframeReaderDevice::ConditionalRun()
{
auto addPartFn = [this](FairMQParts& parts, char* buffer, size_t size) {
parts.AddPart(this->NewMessage(
buffer,
size,
[](void* data, void* hint) { delete[](char*) data; },
nullptr));
};
auto sendFn = [this](FairMQParts& parts) { this->Send(parts, this->mOutChannelName); };
// FIXME: For the moment we support a single file. This should really be a glob. We
// should also have a strategy for watching directories.
std::vector<std::string> files;
files.push_back(mInFileName);
for (auto&& fn : files) {
mFile.open(fn, std::ofstream::in | std::ofstream::binary);
try {
streamTimeframe(mFile,
addPartFn,
sendFn);
} catch (std::runtime_error& e) {
LOG(ERROR) << e.what() << "\n";
}
mSeen.push_back(fn);
}
return false;
}
} // namespace data_flow
} // namespace o2