40void customize(std::vector<ConfigParamSpec>& workflowOptions)
43 workflowOptions.emplace_back(
"global", VariantType::Bool,
false,
45 workflowOptions.emplace_back(
"no-digits", VariantType::Bool,
false,
63 LOG(info) <<
"initializing cluster sampler";
65 auto inputFileName = ic.
options().
get<std::string>(
"infile");
66 mInputFile.open(inputFileName, std::ios::binary);
67 if (!mInputFile.is_open()) {
68 throw std::invalid_argument(
"cannot open input file" + inputFileName);
70 if (mInputFile.peek() == EOF) {
71 throw std::length_error(
"input file is empty");
74 mNEventsPerTF = ic.
options().
get<
int>(
"nEventsPerTF");
75 if (mNEventsPerTF < 1) {
76 throw std::invalid_argument(
"number of events per time frame must be >= 1");
79 auto stop = [
this]() {
81 LOG(info) <<
"stop cluster sampler";
82 this->mInputFile.close();
92 static uint32_t
event(0);
95 if (mInputFile.peek() == EOF) {
104 std::vector<Digit, o2::pmr::polymorphic_allocator<Digit>>*
digits(
nullptr);
110 for (
int iEvt = 0; iEvt < mNEventsPerTF && mInputFile.peek() != EOF; ++iEvt) {
118 int readOneEvent(std::vector<
Cluster, o2::pmr::polymorphic_allocator<Cluster>>&
clusters,
119 std::vector<
Digit, o2::pmr::polymorphic_allocator<Digit>>*
digits)
125 mInputFile.read(
reinterpret_cast<char*
>(&
nClusters),
sizeof(
int));
126 if (mInputFile.fail()) {
127 throw std::length_error(
"invalid input");
132 mInputFile.read(
reinterpret_cast<char*
>(&nDigits),
sizeof(
int));
133 if (mInputFile.fail()) {
134 throw std::length_error(
"invalid input");
138 throw std::length_error(
"invalid input");
144 throw std::length_error(
"invalid input");
146 LOG(info) <<
"event is empty";
151 int clusterOffset =
clusters.size();
154 if (mInputFile.fail()) {
155 throw std::length_error(
"invalid input");
161 throw std::length_error(
"missing digits");
163 int digitOffset =
digits->size();
164 digits->resize(digitOffset + nDigits);
165 mInputFile.read(
reinterpret_cast<char*
>(&(*
digits)[digitOffset]), nDigits *
sizeof(
Digit));
166 if (mInputFile.fail()) {
167 throw std::length_error(
"invalid input");
169 for (
auto itCluster =
clusters.begin() + clusterOffset; itCluster <
clusters.end(); ++itCluster) {
170 itCluster->firstDigit += digitOffset;
172 }
else if (nDigits > 0) {
173 mInputFile.seekg(nDigits *
sizeof(
Digit), std::ios::cur);
174 if (mInputFile.fail()) {
175 throw std::length_error(
"invalid input");
182 std::ifstream mInputFile{};
183 bool mDoDigits =
false;
184 int mNEventsPerTF = 1;
190 std::vector<OutputSpec> outputSpecs{};
191 outputSpecs.emplace_back(
OutputSpec{{
"rofs"},
"MCH",
"CLUSTERROFS", 0, Lifetime::Timeframe});
193 outputSpecs.emplace_back(
OutputSpec{{
"clusters"},
"MCH", clusterDesc, 0, Lifetime::Timeframe});
195 outputSpecs.emplace_back(
OutputSpec{{
"digits"},
"MCH",
"CLUSTERDIGITS", 0, Lifetime::Timeframe});
203 Options{{
"infile", VariantType::String,
"", {
"input filename"}},
204 {
"nEventsPerTF", VariantType::Int, 1, {
"number of events per time frame"}}}};
210 bool global =
cc.options().get<
bool>(
"global");
211 bool doDigits = !
cc.options().get<
bool>(
"no-digits");
void run(ProcessingContext &pc)
void init(InitContext &ic)
ClusterSamplerTask(bool doDigits)
T get(const char *key) const
decltype(auto) make(const Output &spec, Args... args)
ServiceRegistryRef services()
ConfigParamRegistry const & options()
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
ServiceRegistryRef services()
The services registry associated with this processing context.
MCH digit implementation.
WorkflowSpec defineDataProcessing(const ConfigContext &cc)
void customize(std::vector< ConfigParamSpec > &workflowOptions)
DataProcessorSpec getClusterSamplerSpec(const char *specName, bool global, bool doDigits)
Defining PrimaryVertex explicitly as messageable.
std::vector< DataProcessorSpec > WorkflowSpec
std::vector< InputSpec > Inputs
cluster minimal structure
std::vector< o2::mch::ChannelCode > cc
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Cluster > clusters
std::vector< Digit > digits