Skip to content

Commit ab12d5b

Browse files
wiechulaBarthelemy
authored andcommitted
Tpc qc pid (#232)
* Example for TPC PID QA * Add workflow reading from tracks file
1 parent 793528f commit ab12d5b

10 files changed

Lines changed: 415 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ README.md.*
1111
cmake-build-*
1212
Framework/test/testCcdbApi2.cxx
1313
local_history.patch
14+
.*.swp
15+
*.orig

Framework/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ set(EXE_SRCS
108108
src/runDataProducer.cxx
109109
src/runQC.cxx
110110
src/runBasic.cxx
111+
src/runTPCQCPID.cxx
111112
src/runAdvanced.cxx
112113
src/runReadout.cxx
113114
src/runMergerTest.cxx
@@ -120,6 +121,7 @@ set(EXE_NAMES
120121
o2-qc-run-producer
121122
o2-qc
122123
o2-qc-run-basic
124+
o2-qc-run-tpcpid
123125
o2-qc-run-advanced
124126
o2-qc-run-readout
125127
o2-qc-run-merger-test
@@ -134,6 +136,7 @@ set(EXE_OLD_NAMES
134136
qcRunProducer
135137
o2-qc-run-qc
136138
qcRunBasic
139+
qcRunTPCPID
137140
qcRunAdvanced
138141
qcRunReadout
139142
runMergerTest
@@ -157,7 +160,7 @@ foreach(i RANGE ${count})
157160
list(GET EXE_NAMES ${i} name)
158161
list(GET EXE_OLD_NAMES ${i} oldname)
159162
add_executable(${name} ${src})
160-
target_link_libraries(${name} PRIVATE QualityControl CURL::libcurl)
163+
target_link_libraries(${name} PRIVATE QualityControl CURL::libcurl ROOT::Tree)
161164
install_symlink(${name} ${CMAKE_INSTALL_FULL_BINDIR}/${oldname})
162165
endforeach()
163166

@@ -314,6 +317,7 @@ install(FILES example-default.json
314317
alfa.json
315318
dataDump.json
316319
basic.json
320+
tpcQCPID.json
317321
basic-no-sampling.json
318322
advanced.json
319323
readout.json

Framework/src/runTPCQCPID.cxx

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
///
12+
/// \file runTPCQCPID.cxx
13+
/// \author Jens Wiechula
14+
///
15+
/// \brief run TPC PID QC task, reading tracks from file for the moment
16+
///
17+
18+
// IMPORTANT:
19+
// for some reason, if the 'customize' functions are below the other includes,
20+
// the options are not added to the workflow.
21+
// So the structure should be kept as it is
22+
#include "Framework/DataSampling.h"
23+
#include "QualityControl/InfrastructureGenerator.h"
24+
25+
using namespace o2::framework;
26+
27+
void customize(std::vector<CompletionPolicy>& policies)
28+
{
29+
DataSampling::CustomizeInfrastructure(policies);
30+
}
31+
32+
void customize(std::vector<ChannelConfigurationPolicy>& policies)
33+
{
34+
DataSampling::CustomizeInfrastructure(policies);
35+
}
36+
37+
void customize(std::vector<ConfigParamSpec>& workflowOptions)
38+
{
39+
workflowOptions.push_back(ConfigParamSpec{ "input-file", VariantType::String, "tpctracks.root", { "Input file name for TPC tracks" } });
40+
workflowOptions.push_back(ConfigParamSpec{ "tree-name", VariantType::String, "tpcrec", { "Name of the tree containing the TPC tracks vector" } });
41+
workflowOptions.push_back(ConfigParamSpec{ "branch-name", VariantType::String, "TPCTracks", { "Name of the branch of the TPC tracks vector" } });
42+
}
43+
44+
// c++ includes
45+
#include <memory>
46+
#include <random>
47+
48+
// ROOT includes
49+
#include <TH1F.h>
50+
51+
// o2 included
52+
#include "Framework/runDataProcessing.h"
53+
#include "DPLUtils/RootTreeReader.h"
54+
55+
// qc includes
56+
#include "QualityControl/Checker.h"
57+
#include "QualityControl/runnerUtils.h"
58+
59+
WorkflowSpec defineDataProcessing(const ConfigContext& config)
60+
{
61+
WorkflowSpec specs;
62+
63+
// ===| workflow options |====================================================
64+
//
65+
auto inputFile = config.options().get<std::string>("input-file");
66+
auto treeName = config.options().get<std::string>("tree-name");
67+
auto branchName = config.options().get<std::string>("branch-name");
68+
69+
// ===| tree reader |=========================================================
70+
//
71+
// The tree reader will read tpc tracks from file crated via the o2 sim/rec
72+
// workflow
73+
DataProcessorSpec producer{
74+
"tpc-track-reader",
75+
Inputs{},
76+
Outputs{
77+
{ "TPC", "TRACKS", 0, Lifetime::Timeframe } },
78+
AlgorithmSpec{
79+
(AlgorithmSpec::InitCallback)[inputFile, treeName, branchName](InitContext&){
80+
81+
// root tree reader
82+
//constexpr auto persistency = Lifetime::Transient;
83+
constexpr auto persistency = Lifetime::Timeframe;
84+
85+
auto reader = std::make_shared<RootTreeReader>(treeName.data(), // tree name
86+
inputFile.data(), // input file name
87+
RootTreeReader::PublishingMode::Loop, // loop over
88+
Output{ "TPC", "TRACKS", 0, persistency },
89+
branchName.data() // name of the branch
90+
);
91+
92+
return (AlgorithmSpec::ProcessCallback)[reader](ProcessingContext & processingContext) mutable
93+
{
94+
//(++(*reader))(processingContext);
95+
if (reader->next()) {
96+
(*reader)(processingContext);
97+
//LOG(INFO) << "Call producer AlgorithmSpec::ProcessCallback: has data " << reader->getCount();
98+
} else {
99+
//LOG(INFO) << "Call producer AlgorithmSpec::ProcessCallback: no next data" << reader->getCount();
100+
}
101+
};
102+
}
103+
}
104+
}
105+
;
106+
107+
specs.push_back(producer);
108+
109+
// ===| QC task |=============================================================
110+
//
111+
std::string filename = "tpcQCPID.json";
112+
const std::string qcConfigurationSource = std::string("json://") + getenv("QUALITYCONTROL_ROOT") + "/etc/" + filename;
113+
LOG(INFO) << "Using config file '" << qcConfigurationSource << "'";
114+
115+
// Generation of Data Sampling infrastructure
116+
DataSampling::GenerateInfrastructure(specs, qcConfigurationSource);
117+
118+
// Generation of the QC topology (one task, one checker in this case)
119+
o2::quality_control::generateRemoteInfrastructure(specs, qcConfigurationSource);
120+
121+
return specs;
122+
}

Framework/tpcQCPID.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"qc": {
3+
"config": {
4+
"database": {
5+
"implementation": "CCDB",
6+
"host": "ccdb-test.cern.ch:8080",
7+
"username": "not_applicable",
8+
"password": "not_applicable",
9+
"name": "not_applicable"
10+
},
11+
"Activity": {
12+
"number": "42",
13+
"type": "2"
14+
}
15+
},
16+
"tasks": {
17+
"TPCQCPID": {
18+
"active": "true",
19+
"className": "o2::quality_control_modules::tpc::PID",
20+
"moduleName": "QcTPC",
21+
"cycleDurationSeconds": "10",
22+
"maxNumberCycles": "-1",
23+
"dataSource_comment": "The other type of dataSource is \"direct\", see basic-no-sampling.json.",
24+
"dataSource": {
25+
"type": "dataSamplingPolicy",
26+
"name": "tpc-tracks"
27+
},
28+
"taskParameters": {
29+
"nothing": "rien"
30+
},
31+
"location": "remote"
32+
}
33+
}
34+
},
35+
"dataSamplingPolicies": [
36+
{
37+
"id": "tpc-tracks",
38+
"active": "true",
39+
"machines": [],
40+
"dataHeaders": [
41+
{
42+
"binding": "tpc-sampled-tracks",
43+
"dataOrigin": "TPC",
44+
"dataDescription": "TRACKS"
45+
}
46+
],
47+
"subSpec": "0",
48+
"samplingConditions": [
49+
{
50+
"condition": "random",
51+
"fraction": "0.9",
52+
"seed": "1234"
53+
}
54+
],
55+
"blocking": "false"
56+
}
57+
]
58+
}

Modules/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ add_subdirectory(Example)
66
add_subdirectory(Skeleton)
77
add_subdirectory(TOF)
88
add_subdirectory(EMCAL)
9+
add_subdirectory(TPC)

Modules/TPC/CMakeLists.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# ---- Library ----
2+
3+
add_library(QcTPC)
4+
5+
target_sources(QcTPC PRIVATE src/PID.cxx)
6+
7+
target_include_directories(
8+
QcTPC
9+
PUBLIC $<INSTALL_INTERFACE:include>
10+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
11+
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
12+
${O2_ROOT}/include/GPU)
13+
14+
target_link_libraries(QcTPC PUBLIC QualityControl O2::TPCQC)
15+
16+
install(TARGETS QcTPC
17+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
18+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
19+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
20+
21+
add_root_dictionary(QcTPC
22+
HEADERS include/TPC/PID.h
23+
LINKDEF include/TPC/LinkDef.h
24+
BASENAME QcTPC)
25+
26+
# ---- Test(s) ----
27+
28+
set(TEST_SRCS test/testQcTPC.cxx)
29+
30+
foreach(test ${TEST_SRCS})
31+
get_filename_component(test_name ${test} NAME)
32+
string(REGEX REPLACE ".cxx" "" test_name ${test_name})
33+
34+
add_executable(${test_name} ${test})
35+
target_link_libraries(${test_name}
36+
PUBLIC QcTPC
37+
PRIVATE Boost::unit_test_framework)
38+
add_test(NAME ${test_name} COMMAND ${test_name})
39+
set_tests_properties(${test_name} PROPERTIES TIMEOUT 60)
40+
endforeach()

Modules/TPC/include/TPC/LinkDef.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifdef __CLING__
2+
#pragma link off all globals;
3+
#pragma link off all classes;
4+
#pragma link off all functions;
5+
6+
#pragma link C++ class o2::quality_control_modules::tpc::PID+;
7+
#endif

Modules/TPC/include/TPC/PID.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
///
12+
/// \file PID.h
13+
/// \author Jens Wiechula
14+
///
15+
16+
#ifndef QC_MODULE_TPC_PID_H
17+
#define QC_MODULE_TPC_PID_H
18+
19+
// O2 includes
20+
#include "TPCQC/PID.h"
21+
22+
// QC includes
23+
#include "QualityControl/TaskInterface.h"
24+
25+
class TH1F;
26+
27+
using namespace o2::quality_control::core;
28+
29+
namespace o2::quality_control_modules::tpc
30+
{
31+
32+
/// \brief Example Quality Control DPL Task
33+
/// It is final because there is no reason to derive from it. Just remove it if needed.
34+
/// \author Barthelemy von Haller
35+
/// \author Piotr Konopka
36+
class PID /*final*/ : public TaskInterface // todo add back the "final" when doxygen is fixed
37+
{
38+
public:
39+
/// \brief Constructor
40+
PID();
41+
/// Destructor
42+
~PID() override;
43+
44+
// Definition of the methods for the template method pattern
45+
void initialize(o2::framework::InitContext& ctx) override;
46+
void startOfActivity(Activity& activity) override;
47+
void startOfCycle() override;
48+
void monitorData(o2::framework::ProcessingContext& ctx) override;
49+
void endOfCycle() override;
50+
void endOfActivity(Activity& activity) override;
51+
void reset() override;
52+
53+
private:
54+
o2::tpc::qc::PID mQCPID{};
55+
TH1F* mH{ nullptr };
56+
};
57+
58+
} // namespace o2::quality_control_modules::tpc
59+
60+
#endif // QC_MODULE_TPC_PID_H

0 commit comments

Comments
 (0)