diff --git a/src/scdaq.cc b/src/scdaq.cc index 7fd7b7fec7f88649f516c9eee4eb362d3eb52f19..a42e5544600244f5a540689d310ab9b2931727ea 100644 --- a/src/scdaq.cc +++ b/src/scdaq.cc @@ -35,117 +35,135 @@ bool silent = false; int run_pipeline( int nbThreads, ctrl& control, config& conf ) { - config::InputType input = conf.getInput(); - size_t packetBufferSize = conf.getDmaPacketBufferSize(); - size_t nbPacketBuffers = conf.getNumberOfDmaPacketBuffers(); - - // Create empty input reader, will assign later when we know what is the data source - std::shared_ptr<InputFilter> input_filter; - - // Create the pipeline - tbb::pipeline pipeline; - - if (input == config::InputType::DMA) { - // Create DMA reader - input_filter = std::make_shared<DmaInputFilter>( conf.getDmaDevice(), packetBufferSize, nbPacketBuffers, control ); - - } else if (input == config::InputType::FILEDMA) { - // Create FILE DMA reader - input_filter = std::make_shared<FileDmaInputFilter>( conf.getInputFile(), packetBufferSize, nbPacketBuffers, control ); - - } else if (input == config::InputType::WZDMA ) { - // Create WZ DMA reader - input_filter = std::make_shared<WZDmaInputFilter>( packetBufferSize, nbPacketBuffers, control ); - - } else { - throw std::invalid_argument("Configuration error: Unknown input type was specified"); - } - - // Add input reader to a pipeline - pipeline.add_filter( *input_filter ); - - // Create reformatter and add it to the pipeline - // TODO: Created here so we are not subject of scoping, fix later... - StreamProcessor stream_processor(packetBufferSize, conf.getDoZS(), conf.getProcessorType()); - if ( conf.getEnableStreamProcessor() ) { - pipeline.add_filter( stream_processor ); - } - - // Create elastic populator (if requested) - std::string url = conf.getElasticUrl(); - // TODO: Created here so we are not subject of scoping, fix later... - ElasticProcessor elastic_processor(packetBufferSize, - &control, - url, - conf.getPtCut(), - conf.getQualCut()); - if ( conf.getEnableElasticProcessor() ) { - pipeline.add_filter(elastic_processor); - } - - // Create file-writing stage and add it to the pipeline - OutputStream output_stream( conf.getOutputFilenameBase(), conf.getOutputFilenamePrefix(), control); - pipeline.add_filter( output_stream ); - - // Run the pipeline - tbb::tick_count t0 = tbb::tick_count::now(); - // Need more than one token in flight per thread to keep all threads - // busy; 2-4 works - pipeline.run( nbThreads * 4 ); - tbb::tick_count t1 = tbb::tick_count::now(); - - if ( !silent ) { - LOG(INFO) << "time = " << (t1-t0).seconds(); - } - - return 1; + config::InputType input = conf.getInput(); + size_t packetBufferSize = conf.getDmaPacketBufferSize(); + size_t nbPacketBuffers = conf.getNumberOfDmaPacketBuffers(); + + // Create empty input reader, will assign later when we know what is the data source + std::shared_ptr<InputFilter> input_filter; + + // Create the pipeline + tbb::pipeline pipeline; + + if (input == config::InputType::DMA) { + // Create DMA reader + input_filter = std::make_shared<DmaInputFilter>( conf.getDmaDevice(), packetBufferSize, nbPacketBuffers, control ); + + } else if (input == config::InputType::FILEDMA) { + // Create FILE DMA reader + input_filter = std::make_shared<FileDmaInputFilter>( conf.getInputFile(), packetBufferSize, nbPacketBuffers, control ); + + } else if (input == config::InputType::WZDMA ) { + // Create WZ DMA reader + input_filter = std::make_shared<WZDmaInputFilter>( packetBufferSize, nbPacketBuffers, control ); + + } else { + throw std::invalid_argument("Configuration error: Unknown input type was specified"); + } + + // Add input reader to a pipeline + pipeline.add_filter( *input_filter ); + + // Create reformatter and add it to the pipeline + // TODO: Created here so we are not subject of scoping, fix later... + StreamProcessor stream_processor(packetBufferSize, conf.getDoZS(), conf.getProcessorType()); + if ( conf.getEnableStreamProcessor() ) { + pipeline.add_filter( stream_processor ); + } + + // Create elastic populator (if requested) + std::string url = conf.getElasticUrl(); + // TODO: Created here so we are not subject of scoping, fix later... + ElasticProcessor elastic_processor(packetBufferSize, + &control, + url, + conf.getPtCut(), + conf.getQualCut()); + if ( conf.getEnableElasticProcessor() ) { + pipeline.add_filter(elastic_processor); + } + + // Create file-writing stage and add it to the pipeline + OutputStream output_stream( conf.getOutputFilenameBase(), conf.getOutputFilenamePrefix(), control); + pipeline.add_filter( output_stream ); + + // Run the pipeline + tbb::tick_count t0 = tbb::tick_count::now(); + // Need more than one token in flight per thread to keep all threads + // busy; 2-4 works + pipeline.run( nbThreads * 4 ); + tbb::tick_count t1 = tbb::tick_count::now(); + + if ( !silent ) { + LOG(INFO) << "time = " << (t1-t0).seconds(); + } + + return 1; } int main( int argc, char* argv[] ) { - (void)(argc); - (void)(argv); - if(argc<2){ - LOG(ERROR) << "missing argument [conffile] in scdaq invocation"; - exit(-1); - } - LOG(DEBUG) << "scdaq started with argument" << argv[1]; - - try { - config conf(argv[1]); - conf.print(); - LOG(DEBUG) << "configuration loaded"; - ctrl control; - // tbb::tick_count mainStartTime = tbb::tick_count::now(); - - - control.running = false; - control.run_number = 0; - control.max_file_size = conf.getOutputMaxFileSize();//in Bytes - control.packets_per_report = conf.getPacketsPerReport(); - control.output_force_write = conf.getOutputForceWrite(); - - // Firmware needs at least 1MB buffer for DMA - if (conf.getDmaPacketBufferSize() < 1024*1024) { - LOG(ERROR) << "dma_packet_buffer_size must be at least 1048576 bytes (1MB), but " << conf.getDmaPacketBufferSize() << " bytes was given. Check the configuration file."; - return 1; - } - - boost::asio::io_service io_service; - server s(io_service, conf.getPortNumber(), control); - boost::thread t(boost::bind(&boost::asio::io_service::run, &io_service)); - - int nbThreads = conf.getNumThreads(); - - tbb::task_scheduler_init init( nbThreads ); - if (!run_pipeline (nbThreads, control, conf)) - return 1; - - // utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds()); - - return 0; - } catch(std::exception& e) { - LOG(ERROR) << "error occurred. error text is :\"" << e.what() << "\""; - return 1; - } + (void)(argc); + (void)(argv); + + if(argc < 2){ + LOG(DEBUG) << "no arguments provided to scdaq, try --help"; + return 1; + + } + + if((std::string(argv[1]) == "-h") || (std::string(argv[1]) == "--help")){ + LOG(DEBUG) << "HELP: expected arguments --config [configfilename]"; + return 1; + } + + if((argc != 3)){ + LOG(ERROR) << "error occurred, number of arguments != 2, expected --config [configfilename] , try --help"; + return 1; + } + + if (std::string(argv[1]) == "--config"){ + LOG(DEBUG) << "scdaq started with conffile" << std::string(argv[2]); + }else{ + LOG(ERROR) << "invalid argument, expected --config, see --help"; + return 1; + } + + try { + config conf(argv[2]); + conf.print(); + LOG(DEBUG) << "configuration loaded"; + ctrl control; + // tbb::tick_count mainStartTime = tbb::tick_count::now(); + + + control.running = false; + control.run_number = 0; + control.max_file_size = conf.getOutputMaxFileSize();//in Bytes + control.packets_per_report = conf.getPacketsPerReport(); + control.output_force_write = conf.getOutputForceWrite(); + + // Firmware needs at least 1MB buffer for DMA + if (conf.getDmaPacketBufferSize() < 1024*1024) { + LOG(ERROR) << "dma_packet_buffer_size must be at least 1048576 bytes (1MB), but " << conf.getDmaPacketBufferSize() << " bytes was given. Check the configuration file."; + return 1; + } + + boost::asio::io_service io_service; + server s(io_service, conf.getPortNumber(), control); + boost::thread t(boost::bind(&boost::asio::io_service::run, &io_service)); + + int nbThreads = conf.getNumThreads(); + + tbb::task_scheduler_init init( nbThreads ); + if (!run_pipeline (nbThreads, control, conf)) + return 1; + + // utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds()); + + return 0; + } catch(std::exception& e) { + LOG(ERROR) << "error occurred. error text is :\"" << e.what() << "\""; + return 1; + } }