|
| 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 | +#include "SimReaderSpec.h" |
| 12 | + |
| 13 | +#include "Framework/DataProcessorSpec.h" |
| 14 | +#include "Framework/DataRefUtils.h" |
| 15 | +#include "Framework/ControlService.h" |
| 16 | +#include "Framework/Lifetime.h" |
| 17 | +#include "Headers/DataHeader.h" |
| 18 | +#include "Steer/HitProcessingManager.h" |
| 19 | +#include <FairMQLogger.h> |
| 20 | +#include <TMessage.h> // object serialization |
| 21 | +#include <memory> // std::unique_ptr |
| 22 | +#include <cstring> // memcpy |
| 23 | +#include <string> // std::string |
| 24 | +#include <cassert> |
| 25 | +#include <chrono> |
| 26 | +#include <thread> |
| 27 | + |
| 28 | +using namespace o2::framework; |
| 29 | +using SubSpecificationType = o2::framework::DataAllocator::SubSpecificationType; |
| 30 | +namespace o2 |
| 31 | +{ |
| 32 | +namespace steer |
| 33 | +{ |
| 34 | +DataProcessorSpec getSimReaderSpec(int fanoutsize) |
| 35 | +{ |
| 36 | + auto doit = [fanoutsize](ProcessingContext& pc) { |
| 37 | + auto& mgr = steer::HitProcessingManager::instance(); |
| 38 | + auto eventrecords = mgr.getRunContext().getEventRecords(); |
| 39 | + const auto& context = mgr.getRunContext(); |
| 40 | + |
| 41 | + // counter to make sure we are sending the data only once |
| 42 | + static int counter = 0; |
| 43 | + if (counter++ == 0) { |
| 44 | + // sleep(10); |
| 45 | + LOG(INFO) << "SENDING " << eventrecords.size() << " records"; |
| 46 | + |
| 47 | + for (int subchannel = 0; subchannel < fanoutsize; ++subchannel) { |
| 48 | + pc.outputs().snapshot( |
| 49 | + Output{ "SIM", "EVENTTIMES", static_cast<SubSpecificationType>(subchannel), Lifetime::Timeframe }, context); |
| 50 | + } |
| 51 | + |
| 52 | + // do this only one |
| 53 | + pc.services().get<ControlService>().readyToQuit(false); |
| 54 | + } |
| 55 | + }; |
| 56 | + |
| 57 | + // init function return a lambda taking a ProcessingContext |
| 58 | + auto initIt = [doit](InitContext& ctx) { |
| 59 | + // initialize fundamental objects |
| 60 | + auto& mgr = steer::HitProcessingManager::instance(); |
| 61 | + mgr.addInputFile(ctx.options().get<std::string>("simFile").c_str()); |
| 62 | + mgr.setupRun(); |
| 63 | + |
| 64 | + LOG(INFO) << "Initializing Spec ... have " << mgr.getRunContext().getEventRecords().size() << " times "; |
| 65 | + return doit; |
| 66 | + }; |
| 67 | + |
| 68 | + std::vector<OutputSpec> outputs; |
| 69 | + for (int subchannel = 0; subchannel < fanoutsize; ++subchannel) { |
| 70 | + outputs.emplace_back( |
| 71 | + OutputSpec{ "SIM", "EVENTTIMES", static_cast<SubSpecificationType>(subchannel), Lifetime::Timeframe }); |
| 72 | + } |
| 73 | + |
| 74 | + return DataProcessorSpec{ /*ID*/ "SimReader", |
| 75 | + /*INPUT CHANNELS*/ Inputs{}, outputs, |
| 76 | + /* ALGORITHM */ |
| 77 | + AlgorithmSpec{ initIt }, |
| 78 | + /* OPTIONS */ |
| 79 | + Options{ { "simFile", VariantType::String, "o2sim.root", { "Sim input filename" } } } }; |
| 80 | +} |
| 81 | +} |
| 82 | +} |
0 commit comments