Repository navigation
ctpdev: ctpproxy publish CTP scalers #8119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3b48fc3
dev: o2-ctp-proxy for counters
lietava fdab59c
dev:ctp-proxy
lietava 5ca640a
clang formar
lietava e6c6a1c
fix: bad spacing
lietava e2fd2cf
fix: ctp-proxy: payload
lietava a52fe47
dev: ctp-proxy minor
lietava 33562bf
dev: CTP scalers
lietava e6ce805
clang
lietava 601c090
Cgange of number of inputs
lietava 7994ed0
dev: scalers to CCDB
lietava File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,3 +18,4 @@ o2_add_library(CTPReconstruction | |
| O2::rANS | ||
| Microsoft.GSL::GSL) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| o2_add_executable( | ||
| proxy | ||
| COMPONENT_NAME ctp | ||
| SOURCES src/ctp-proxy.cxx | ||
| PUBLIC_LINK_LIBRARIES O2::DCStestWorkflow | ||
| O2::DataFormatsCTP) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import zmq | ||
| import random | ||
| import sys | ||
| import time | ||
|
|
||
| port = "500901" | ||
| if len(sys.argv) > 1: | ||
| port = sys.argv[1] | ||
| int(port) | ||
|
|
||
| context = zmq.Context() | ||
| socket = context.socket(zmq.PUB) | ||
| socket.bind("tcp://*:%s" % port) | ||
| while True: | ||
| topic = random.randrange(0,2**32) | ||
| #messagedata = random.randrange(1,215) - 80 | ||
| header = "CTP" | ||
| messagedata = str(topic)+"1 2 3 4 5" | ||
| print("Sending:",header, messagedata) | ||
| data = str(messagedata).encode() | ||
| header = str(header).encode() | ||
| socket.send(memoryview(header),zmq.SNDMORE) | ||
| socket.send(memoryview(data)) | ||
| time.sleep(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import sys | ||
| import zmq | ||
|
|
||
| port = "500901" | ||
| if len(sys.argv) > 1: | ||
| port = sys.argv[1] | ||
| int(port) | ||
|
|
||
| if len(sys.argv) > 2: | ||
| port1 = sys.argv[2] | ||
| int(port1) | ||
|
|
||
| # Socket to talk to server | ||
| context = zmq.Context() | ||
| socket = context.socket(zmq.SUB) | ||
|
|
||
| print("Collecting updates from CTP server, port:",port) | ||
| socket.connect ("tcp://localhost:%s" % port) | ||
|
|
||
| if len(sys.argv) > 2: | ||
| socket.connect ("tcp://localhost:%s" % port1) | ||
| # Subscribe to zipcode, default is NYC, 10001 | ||
| topicfilter = "CTP" | ||
| socket.setsockopt_string(zmq.SUBSCRIBE, topicfilter) | ||
|
|
||
| # Process 5 updates | ||
| total_value = 0 | ||
| while(1): | ||
| string = socket.recv_multipart() | ||
| #string = stringr.decode() | ||
| print("string:",string) | ||
| #topic, messagedata = string.split() | ||
| #total_value += int(messagedata) | ||
| #print(topic, messagedata) | ||
|
|
||
| print("Average messagedata value for topic '%s' was %dF" % (topicfilter, total_value / update_nbr)) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| // 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. | ||
|
|
||
| // 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. | ||
|
|
||
| // example to run: | ||
| // o2-ctp-proxy --ctp-proxy '--channel-config "name=ctp-proxy,type=sub,method=connect,address=tcp://127.0.0.1:5556,rateLogging=1,transport=zeromq"' | ||
|
|
||
| #include "Framework/WorkflowSpec.h" | ||
| #include "Framework/DataProcessorSpec.h" | ||
| #include "Framework/DataSpecUtils.h" | ||
| #include "Framework/ControlService.h" | ||
| #include "Framework/Logger.h" | ||
| #include "Framework/Lifetime.h" | ||
| #include "Framework/ConfigParamSpec.h" | ||
| #include "Framework/ExternalFairMQDeviceProxy.h" | ||
| #include "DetectorsCommonDataFormats/DetID.h" | ||
| #include "Headers/DataHeaderHelpers.h" | ||
| #include <fairmq/FairMQDevice.h> | ||
| #include "CommonUtils/StringUtils.h" | ||
| #include <vector> | ||
| #include <string> | ||
|
|
||
| using namespace o2::framework; | ||
| using DetID = o2::detectors::DetID; | ||
| InjectorFunction dcs2dpl() | ||
| { | ||
|
|
||
| auto timesliceId = std::make_shared<size_t>(0); | ||
|
|
||
| return [timesliceId](FairMQDevice& device, FairMQParts& parts, ChannelRetriever channelRetriever) { | ||
| // make sure just 2 messages received | ||
| if (parts.Size() != 2) { | ||
| LOG(error) << "received " << parts.Size() << " instead of 2 expected"; | ||
| return; | ||
| } | ||
| std::string messageHeader{static_cast<const char*>(parts.At(0)->GetData()), parts.At(0)->GetSize()}; | ||
| size_t dataSize = parts.At(1)->GetSize(); | ||
| std::string messageData{static_cast<const char*>(parts.At(1)->GetData()), parts.At(1)->GetSize()}; | ||
| LOG(info) << "received message " << messageHeader << " of size " << dataSize << " Payload:" << messageData; | ||
| o2::header::DataHeader hdrF("CTP_COUNTERS", o2::header::gDataOriginCTP, 0); | ||
| OutputSpec outsp{hdrF.dataOrigin, hdrF.dataDescription, hdrF.subSpecification}; | ||
| auto channel = channelRetriever(outsp, *timesliceId); | ||
| if (channel.empty()) { | ||
| LOG(error) << "No output channel found for OutputSpec " << outsp; | ||
| return; | ||
| } | ||
|
|
||
| hdrF.tfCounter = *timesliceId; // this also | ||
| hdrF.payloadSerializationMethod = o2::header::gSerializationMethodNone; | ||
| hdrF.splitPayloadParts = 1; | ||
| hdrF.splitPayloadIndex = 0; | ||
| hdrF.payloadSize = parts.At(1)->GetSize(); | ||
| hdrF.firstTForbit = 0; // this should be irrelevant for Counters ? Orbit is in payload | ||
|
|
||
| auto fmqFactory = device.GetChannel(channel).Transport(); | ||
|
|
||
| o2::header::Stack headerStackF{hdrF, DataProcessingHeader{*timesliceId, 1}}; | ||
| auto hdMessageF = fmqFactory->CreateMessage(headerStackF.size(), fair::mq::Alignment{64}); | ||
| auto plMessageF = fmqFactory->CreateMessage(hdrF.payloadSize, fair::mq::Alignment{64}); | ||
| memcpy(hdMessageF->GetData(), headerStackF.data(), headerStackF.size()); | ||
| memcpy(plMessageF->GetData(), parts.At(1)->GetData(), hdrF.payloadSize); | ||
|
|
||
| FairMQParts outParts; | ||
| outParts.AddPart(std::move(hdMessageF)); | ||
| outParts.AddPart(std::move(plMessageF)); | ||
| sendOnChannel(device, outParts, channel); | ||
| // LOG(info) << "Sent CTP counters DPL message"; | ||
| }; | ||
| } | ||
|
|
||
| // we need to add workflow options before including Framework/runDataProcessing | ||
| void customize(std::vector<ConfigParamSpec>& workflowOptions) | ||
| { | ||
| workflowOptions.push_back(ConfigParamSpec{"subscribe-to", VariantType::String, "type=sub,method=connect,address=tcp://188.184.30.57:5556,rateLogging=10,transport=zeromq", {"channel subscribe to"}}); | ||
| } | ||
|
|
||
| #include "Framework/runDataProcessing.h" | ||
|
|
||
| WorkflowSpec defineDataProcessing(ConfigContext const& config) | ||
| { | ||
| LOG(info) << "Defining data processing"; | ||
| auto setChanName = [](const std::string& chan, const std::string& name) { | ||
| size_t n = 0; | ||
| if (std::string(chan).find("name=") != std::string::npos) { | ||
| n = std::string(chan).find(","); | ||
| if (n == std::string::npos) { | ||
| throw std::runtime_error(fmt::format("wrongly formatted channel: {}", chan)); | ||
| } | ||
| n++; | ||
| } | ||
| LOG(info) << "===>inside:" << name << " " << chan; | ||
| return o2::utils::Str::concat_string("name=", name, ",", chan.substr(n, chan.size())); | ||
| }; | ||
| const std::string devName = "ctp-proxy"; | ||
| auto chan = config.options().get<std::string>("subscribe-to"); | ||
| if (chan.empty()) { | ||
| throw std::runtime_error("input channel is not provided"); | ||
| } | ||
| chan = setChanName(chan, devName); | ||
| LOG(info) << "name:" << devName << " chan:" << chan; | ||
| LOG(info) << "Channels setup: " << chan; | ||
| Outputs ctpCountersOutputs; | ||
| ctpCountersOutputs.emplace_back("CTP", "CTP_COUNTERS", 0, Lifetime::Timeframe); | ||
| LOG(info) << "===> Proxy to be set"; | ||
| DataProcessorSpec ctpProxy = specifyExternalFairMQDeviceProxy( | ||
| devName.c_str(), | ||
| std::move(ctpCountersOutputs), | ||
| // this is just default, can be overriden by --ctp-config-proxy '--channel-config..' | ||
| chan.c_str(), | ||
| dcs2dpl()); | ||
| LOG(info) << "===> Proxy done"; | ||
| WorkflowSpec workflow; | ||
| workflow.emplace_back(ctpProxy); | ||
| return workflow; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method does nothing, just creates/destroys a local vector. Is this intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, sorry about that. It is not finished. I wanted to pull to avoid too much divergence from dev.