Skip to content

Commit

Permalink
add StatusMap IO and a converter to RejectList
Browse files Browse the repository at this point in the history
  • Loading branch information
pillot authored and ktf committed May 21, 2024
1 parent 189812f commit fba58db
Show file tree
Hide file tree
Showing 10 changed files with 488 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Detectors/MUON/MCH/IO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,19 @@ o2_add_executable(tracks-writer-workflow
COMPONENT_NAME mch
PUBLIC_LINK_LIBRARIES O2::MCHIO)

o2_add_executable(statusmaps-reader-workflow
SOURCES src/StatusMapReaderSpec.cxx src/statusmaps-reader-workflow.cxx
COMPONENT_NAME mch
PUBLIC_LINK_LIBRARIES
O2::DPLUtils
O2::DetectorsRaw
O2::MCHStatus
)

o2_add_executable(statusmaps-writer-workflow
SOURCES src/StatusMapWriterSpec.cxx src/statusmaps-writer-workflow.cxx
COMPONENT_NAME mch
PUBLIC_LINK_LIBRARIES
O2::DPLUtils
O2::MCHStatus
)
20 changes: 20 additions & 0 deletions Detectors/MUON/MCH/IO/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* [Cluster writer](#cluster-writer)
* [Track reader](#track-reader)
* [Track writer](#track-writer)
* [StatusMap reader](#statusmap-reader)
* [StatusMap writer](#statusmap-writer)

<!-- vim-markdown-toc -->

Expand Down Expand Up @@ -126,3 +128,21 @@ Option `--digits` allows to also write the associated digits ([Digit](/DataForma

Option `--enable-mc` allows to also write the track MC labels from the input message with the data description "TRACKLABELS".

## StatusMap reader

```shell
o2-mch-statusmaps-reader-workflow --infile mchstatusmaps.root
```

Send the status map ([StatusMap](../Status/include/MCHStatus/StatusMap.h)) of the current time frame, with the data description "STATUSMAP".

Option `--input-dir` allows to set the name of the directory containing the input file (default = current directory).

## StatusMap writer

```shell
o2-mch-statusmaps-writer-workflow
```

Take as input the status map ([StatusMap](../Status/include/MCHStatus/StatusMap.h)) of the current time frame, with the data description "STATUSMAP", and write it in the root file "mchstatusmaps.root".

70 changes: 70 additions & 0 deletions Detectors/MUON/MCH/IO/src/StatusMapReaderSpec.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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 "StatusMapReaderSpec.h"

#include <memory>
#include <string>

#include "Framework/ConfigParamRegistry.h"
#include "Framework/ConfigParamSpec.h"
#include "Framework/ControlService.h"
#include "Framework/InitContext.h"
#include "Framework/Lifetime.h"
#include "Framework/OutputSpec.h"
#include "Framework/ProcessingContext.h"
#include "Framework/Task.h"

#include "DPLUtils/RootTreeReader.h"
#include "CommonUtils/StringUtils.h"
#include "MCHStatus/StatusMap.h"

using namespace o2::framework;

namespace o2::mch
{

struct StatusMapReader {
std::unique_ptr<RootTreeReader> mTreeReader;

void init(InitContext& ic)
{
auto fileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")), ic.options().get<std::string>("infile"));
mTreeReader = std::make_unique<RootTreeReader>(
"o2sim",
fileName.c_str(),
-1,
RootTreeReader::PublishingMode::Single,
RootTreeReader::BranchDefinition<StatusMap>{Output{"MCH", "STATUSMAP", 0}, "statusmaps"});
}

void run(ProcessingContext& pc)
{
if (mTreeReader->next()) {
(*mTreeReader)(pc);
} else {
pc.services().get<ControlService>().endOfStream();
}
}
};

DataProcessorSpec getStatusMapReaderSpec(const char* specName)
{
return DataProcessorSpec{
specName,
Inputs{},
Outputs{OutputSpec{{"statusmaps"}, "MCH", "STATUSMAP", 0, Lifetime::Timeframe}},
adaptFromTask<StatusMapReader>(),
Options{{"infile", VariantType::String, "mchstatusmaps.root", {"name of the input status map file"}},
{"input-dir", VariantType::String, "none", {"Input directory"}}}};
}

} // namespace o2::mch
22 changes: 22 additions & 0 deletions Detectors/MUON/MCH/IO/src/StatusMapReaderSpec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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.

#ifndef O2_MCH_WORKFLOW_STATUSMAP_READER_SPEC_H
#define O2_MCH_WORKFLOW_STATUSMAP_READER_SPEC_H

#include "Framework/DataProcessorSpec.h"

namespace o2::mch
{
framework::DataProcessorSpec getStatusMapReaderSpec(const char* specName = "mch-statusmap-reader");
}

#endif
33 changes: 33 additions & 0 deletions Detectors/MUON/MCH/IO/src/StatusMapWriterSpec.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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 "StatusMapWriterSpec.h"

#include "DPLUtils/MakeRootTreeWriterSpec.h"
#include "MCHStatus/StatusMap.h"

using namespace o2::framework;

namespace o2::mch
{

template <typename T>
using BranchDefinition = MakeRootTreeWriterSpec::BranchDefinition<T>;

DataProcessorSpec getStatusMapWriterSpec(const char* specName)
{
return MakeRootTreeWriterSpec(specName,
"mchstatusmaps.root",
MakeRootTreeWriterSpec::TreeAttributes{"o2sim", "Tree MCH StatusMaps"},
BranchDefinition<StatusMap>{InputSpec{"statusmaps", "MCH", "STATUSMAP"}, "statusmaps"})();
}

} // namespace o2::mch
22 changes: 22 additions & 0 deletions Detectors/MUON/MCH/IO/src/StatusMapWriterSpec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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.

#ifndef O2_MCH_WORKFLOW_STATUSMAP_WRITER_SPEC_H
#define O2_MCH_WORKFLOW_STATUSMAP_WRITER_SPEC_H

#include "Framework/DataProcessorSpec.h"

namespace o2::mch
{
framework::DataProcessorSpec getStatusMapWriterSpec(const char* specName = "mch-statusmap-writer");
}

#endif
38 changes: 38 additions & 0 deletions Detectors/MUON/MCH/IO/src/statusmaps-reader-workflow.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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 <vector>
#include "DetectorsRaw/HBFUtilsInitializer.h"
#include "Framework/CallbacksPolicy.h"
#include "Framework/ConfigParamSpec.h"
#include "StatusMapReaderSpec.h"

using namespace o2::framework;

void customize(std::vector<CallbacksPolicy>& policies)
{
o2::raw::HBFUtilsInitializer::addNewTimeSliceCallback(policies);
}

// we need to add workflow options before including Framework/runDataProcessing
void customize(std::vector<ConfigParamSpec>& workflowOptions)
{
o2::raw::HBFUtilsInitializer::addConfigOption(workflowOptions);
}

#include "Framework/runDataProcessing.h"

WorkflowSpec defineDataProcessing(const ConfigContext& config)
{
WorkflowSpec wf{o2::mch::getStatusMapReaderSpec("mch-statusmap-reader")};
o2::raw::HBFUtilsInitializer hbfIni(config, wf);
return wf;
}
29 changes: 29 additions & 0 deletions Detectors/MUON/MCH/IO/src/statusmaps-writer-workflow.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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 <vector>
#include "Framework/CompletionPolicyHelpers.h"
#include "StatusMapWriterSpec.h"

using namespace o2::framework;

void customize(std::vector<o2::framework::CompletionPolicy>& policies)
{
// ordered policies for the writers
policies.push_back(CompletionPolicyHelpers::consumeWhenAllOrdered(".*(?:MCH|mch).*[W,w]riter.*"));
}

#include "Framework/runDataProcessing.h"

WorkflowSpec defineDataProcessing(const ConfigContext&)
{
return WorkflowSpec{o2::mch::getStatusMapWriterSpec("mch-statusmap-writer")};
}
13 changes: 13 additions & 0 deletions Detectors/MUON/MCH/Status/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ o2_add_executable(
O2::MCHStatus
)

o2_add_executable(
statusmap-to-rejectlist
COMPONENT_NAME mch
SOURCES src/statusmap-to-rejectlist.cxx
PUBLIC_LINK_LIBRARIES
ROOT::TreePlayer
O2::CCDB
O2::DataFormatsMCH
O2::Framework
O2::MCHGlobalMapping
O2::MCHStatus
)

if(BUILD_TESTING)

o2_add_test(
Expand Down
Loading

0 comments on commit fba58db

Please sign in to comment.