From 69d3f8ec6e0d4772bee63f6e6f86e90759d89097 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Thu, 3 Jun 2021 12:27:01 -0500 Subject: [PATCH 01/46] Adding module for BNB info --- CMakeLists.txt | 2 + sbncode/BeamSpillInfoRetriever/CMakeLists.txt | 10 + .../Retriever/#Retriever_module.cc# | 302 ++++++++++++++++++ .../Retriever/CMakeLists.txt | 43 +++ .../Retriever/MWRData.cpp | 79 +++++ .../Retriever/MWRData.h | 39 +++ .../Retriever/Retriever_module.cc | 274 ++++++++++++++++ .../Retriever/Retriever_module_brokeit.cc | 242 ++++++++++++++ .../BeamSpillInfoRetriever/job/CMakeLists.txt | 3 + .../job/beamspillinfo.fcl | 15 + sbncode/CMakeLists.txt | 4 + 11 files changed, 1013 insertions(+) create mode 100644 sbncode/BeamSpillInfoRetriever/CMakeLists.txt create mode 100644 sbncode/BeamSpillInfoRetriever/Retriever/#Retriever_module.cc# create mode 100644 sbncode/BeamSpillInfoRetriever/Retriever/CMakeLists.txt create mode 100644 sbncode/BeamSpillInfoRetriever/Retriever/MWRData.cpp create mode 100644 sbncode/BeamSpillInfoRetriever/Retriever/MWRData.h create mode 100644 sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc create mode 100644 sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module_brokeit.cc create mode 100644 sbncode/BeamSpillInfoRetriever/job/CMakeLists.txt create mode 100644 sbncode/BeamSpillInfoRetriever/job/beamspillinfo.fcl diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a5a66d74..1787c992e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,8 @@ find_ups_product(larreco) find_ups_product(larpandora) find_ups_product(larsoft v09_00_00) find_ups_product(artdaq_core v3_06_01) +find_ups_product(ifbeam) +find_ups_product(libwda) find_ups_product(sbnobj v09_10_00) #find_ups_product(sbndcode v06_67_00) #find_ups_product(uboonecode v06_67_00) diff --git a/sbncode/BeamSpillInfoRetriever/CMakeLists.txt b/sbncode/BeamSpillInfoRetriever/CMakeLists.txt new file mode 100644 index 000000000..8cc6b80ae --- /dev/null +++ b/sbncode/BeamSpillInfoRetriever/CMakeLists.txt @@ -0,0 +1,10 @@ +add_subdirectory(Retriever) +add_subdirectory(job) + +link_directories( + $ENV{ROOTSYS}/lib +) + +install_headers() +install_fhicl() +install_source() diff --git a/sbncode/BeamSpillInfoRetriever/Retriever/#Retriever_module.cc# b/sbncode/BeamSpillInfoRetriever/Retriever/#Retriever_module.cc# new file mode 100644 index 000000000..1e5c01487 --- /dev/null +++ b/sbncode/BeamSpillInfoRetriever/Retriever/#Retriever_module.cc# @@ -0,0 +1,302 @@ +//////////////////////////////////////////////////////////////////////// +// Class: Retriever +// Plugin Type: producer +// File: Retriever_module.cc +// +// Created by hand Wed April 9 2021 by J. Zennamo (FNAL) +// Based heavily on code by Z. Pavlovic written for MicroBooNE +// Based heavily on code by NOvA collaboration (Thanks NOvA!): +// https://cdcvs.fnal.gov/redmine/projects/novaart/repository/entry/trunk/IFDBSpillInfo/BNBInfo_module.cc +//////////////////////////////////////////////////////////////////////// + +#include "art/Framework/Core/EDProducer.h" +#include "art/Framework/Core/ModuleMacros.h" +#include "art/Framework/Principal/Event.h" +#include "art/Framework/Principal/Handle.h" +#include "art/Framework/Principal/Run.h" +#include "art/Framework/Principal/SubRun.h" +#include "canvas/Utilities/InputTag.h" +#include "fhiclcpp/ParameterSet.h" +#include "messagefacility/MessageLogger/MessageLogger.h" +#include "lardata/Utilities/AssociationUtil.h" +#include "lardataobj/Utilities/sparse_vector.h" +#include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" +#include "larcorealg/Geometry/Exceptions.h" + +#include "artdaq-core/Data/Fragment.hh" + +#include "lardataalg/DetectorInfo/DetectorPropertiesStandard.h" +#include "lardata/DetectorInfoServices/DetectorPropertiesService.h" +#include "sbnobj/Common/POTAccounting/BeamSpillInfo.h" + +#include "IFBeam_service.h" +#include "ifbeam_c.h" +#include "MWRData.h" + +#include +#include +#include +#include +#include +#include + +namespace sbn { + class Retriever; +} + +class sbn::Retriever : public art::EDProducer { +public: + explicit Retriever(fhicl::ParameterSet const& p); + // The compiler-generated destructor is fine for non-base + // classes without bare pointers or other resource use. + + // Plugins should not be copied or assigned. + Retriever(Retriever const&) = delete; + Retriever(Retriever&&) = delete; + Retriever& operator=(Retriever const&) = delete; + Retriever& operator=(Retriever&&) = delete; + + // Required functions. + void produce(art::Event& e) override; + void beginSubRun(art::SubRun& sr); + void endSubRun(art::SubRun& sr); + +private: + // input labels + std::vector< sbn::BeamSpillInfo > fOutbeamInfos; + int fTimePad; + std::string fURL; + MWRData mwrdata; + std::string raw_data_label_; + + art::ServiceHandle ifbeam_handle; + std::unique_ptr bfp; + std::unique_ptr bfp_mwr; + +}; + + +sbn::Retriever::Retriever(fhicl::ParameterSet const& p) + : EDProducer{p}, + fTimePad(p.get("TimePadding",0.0333)), //seconds + raw_data_label_(p.get("raw_data_label")), + bfp( ifbeam_handle->getBeamFolder(p.get< std::string >("Bundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))), + bfp_mwr( ifbeam_handle->getBeamFolder(p.get< std::string >("MultiWireBundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))) +{ + bfp->set_epsilon(0.0333); // how close in time does the spill time have to be from the DAQ time (in seconds). + bfp_mwr->set_epsilon(100); // how close in time does the spill time have to be from the DAQ time (in seconds). + produces< std::vector< sbn::BeamSpillInfo >, art::InSubRun >(); + +} + +void sbn::Retriever::produce(art::Event& e) +{ + + //Get the time of the event and the previous event + // time since epoch sec . nanoseconds + //1616202843.932767280 + //.932767280 + //.030000000 + + + art::Handle< std::vector > raw_data_ptr; + e.getByLabel(raw_data_label_, "ICARUSTriggerUDP", raw_data_ptr); + auto const & raw_data = (*raw_data_ptr); + + auto fragment = raw_data[0]; + const char* buffer = fragment.dataBeginBytes(); + size_t pos = 0; + std::string delimiter = ","; + std::vector sections; + std::string token = ""; + while ((pos = data_input.find(delimiter)) != std::string::npos) { + token = data_input.substr(0, pos); + sections.push_back(token); + data_input.erase(0, pos + delimiter.length()); + } + sections.push_back(data_input); + //std::string trig_name = sections[0]; + name = sections[0]; + //t->setHardwareTS_Type(sections[0]); + event_no = std::stol(sections[1]); + seconds = std::stoi(sections[2]); + nanoseconds = std::stol(sections[3]); + if(sections.size() > 5) + { + wr_name = sections[4]; + wr_event_no = std::stol(sections[5]); + wr_seconds = std::stol(sections[6]); + wr_nanoseconds = std::stol(sections[7]); + gate_id = std::stol(sections[9]); + gate_type = std::stoi(sections[11]); + } + + + + + + // double t_previous_event = 1616202844.932767280; + // double t_current_event = 1616202843.932767280; + + double t_previous_event = 0; + double t_current_event = 0; + std::cout << "This many raw_datums : " << raw_data.size() << std::endl; + for(auto raw_datum : raw_data){ + + uint64_t artdaq_ts = fragment.timestamp(); + icarus::ICARUSTriggerUDPFragment frag(fragment); + std::string data = frag.GetDataString(); + char *buffer = const_cast(data.c_str()); + icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerString(buffer); + int gate_type = datastream_info.gate_type; + if(gate_type != 1) continue; + + t_current_event = datastream_info.getNanoseconds_since_UTC_epoch() + 2; //check this offset... + t_previous_event = frag.getLastTimestampBNB(); + + } + + std::cout << "Previous : " << t_previous_event << ", Current : " << t_current_event << std::endl; + + if(t_previous_event == t_current_event) return -1; + + + try{ + double test_curr; double test_t1; + bfp->GetNamedData((t_previous_event)-fTimePad,"E:THCURR",&test_curr,&test_t1); + std::cout << "got values " << test_curr << "for E:THCURR at time " << test_t1 << "\n"; + } + catch (WebAPIException &we) { + std::cout << "got exception: " << we.what() << "\n"; + } + std::cout.precision(17); + + + try{ + auto packed_M876BB_temp = bfp_mwr->GetNamedVector((t_previous_event)-35,"E:M875BB{4440:888}.RAW"); + } + catch (WebAPIException &we) { + //we have to have this or it doesn't work... + } + + // bfp_mwr->setValidWindow(86400); + //std::cout << "Is this a valid Window " << bfp_mwr->getValidWindow()< > unpacked_M876BB_str; + // unpacked_M876BB_str.resize(3); + std::vector unpacked_M876BB_str; + std::string packed_data_str; + // int dev = 0; + std::vector vars = bfp_mwr->GetDeviceList(); + double t_mwr; + std::cout << int(vars.size()) << " MWR Devices " << std::endl; + for (int i = 0; i < int(vars.size()); i++) { + if(vars[i].empty()) continue; + + /// Check the device name and interate the double-vector index + // if(vars[i].M875BB) dev = 0; + //M876BB; + //MMBTBB; + //std::cout << vars[i] << std::endl; + + + //var - > E:M875BB{888:888}.RAW + t_mwr = 0; + std::vector packed_M876BB = bfp_mwr->GetNamedVector((t_previous_event)-35,vars[i],&t_mwr); + + packed_data_str.clear(); + packed_data_str += std::to_string(int(t_mwr)); + packed_data_str.append(","); + packed_data_str.append(vars[i]); + packed_data_str.append(",,"); + + for(int j = 0; j < int(packed_M876BB.size()); j++){ + packed_data_str += std::to_string(int(packed_M876BB[j])); + if(j < int(packed_M876BB.size())-1) + packed_data_str.append(","); + } + + // std::cout << packed_data_str << std::endl; + + auto unpacked_M876BB_str_temp = mwrdata.unpackMWR(packed_data_str,long(-35)); + unpacked_M876BB_str.insert(unpacked_M876BB_str.end(), + unpacked_M876BB_str_temp.begin(), + unpacked_M876BB_str_temp.end()); + + + std::cout << int(unpacked_M876BB_str.size()) << " unpacked datas ... " << std::endl; + } + + //for(int j = 0; j < int(unpacked_M876BB_str.size()); j++){ + // std::cout << unpacked_M876BB_str[j] << std::endl; + //} + + + std::vector times_temps = bfp->GetTimeList(); + for (size_t i = 0; i < times_temps.size(); i++) { + if(times_temps[i] > (t_current_event+fTimePad)){break;} + + double TOR860 = 0; + double TOR875 = 0; + double LM875A = 0; + double LM875B = 0; + double LM875C = 0; + double HP875 = 0; + double VP875 = 0; + double HPTG1 = 0; + double VPTG1 = 0; + double HPTG2 = 0; + double VPTG2 = 0; + double BTJT2 = 0; + double THCURR = 0; + + double TOR860_time = 0; + + bfp->GetNamedData(times_temps[i], "E:TOR860@,E:TOR875,E:LM875A,E:LM875B,E:LM875C,E:HP875,E:VP875,E:HPTG1,E:VPTG1,E:HPTG2,E:VPTG2,E:BTJT2,E:THCURR",&TOR860,&TOR860_time,&TOR875,&LM875A,&LM875B,&LM875C,&HP875,&VP875,&HPTG1,&VPTG1,&HPTG2,&VPTG2,&BTJT2,&THCURR); + + + unsigned long int time_closest_int = (int) TOR860_time; + double time_closest_ns = (TOR860_time - time_closest_int)*1e9; + + sbn::BeamSpillInfo beamInfo; + beamInfo.TOR860 = TOR860; + beamInfo.TOR875 = TOR875; + beamInfo.LM875A = LM875A; + beamInfo.LM875B = LM875B; + beamInfo.LM875C = LM875C; + beamInfo.HP875 = HP875; + beamInfo.VP875 = VP875; + beamInfo.HPTG1 = HPTG1; + beamInfo.VPTG1 = VPTG1; + beamInfo.HPTG2 = HPTG2; + beamInfo.VPTG2 = VPTG2; + beamInfo.BTJT2 = BTJT2; + beamInfo.THCURR = THCURR; + beamInfo.spill_time_s = time_closest_int; + beamInfo.spill_time_ns = time_closest_ns; + + fOutbeamInfos.push_back(beamInfo); + + + } + +} + +void sbn::Retriever::beginSubRun(art::SubRun& sr) +{ + return; +} + +//____________________________________________________________________________ +void sbn::Retriever::endSubRun(art::SubRun& sr) +{ + + auto p = std::make_unique< std::vector< sbn::BeamSpillInfo > >(fOutbeamInfos); + + sr.put(std::move(p)); + + return; +} + +DEFINE_ART_MODULE(sbn::Retriever) diff --git a/sbncode/BeamSpillInfoRetriever/Retriever/CMakeLists.txt b/sbncode/BeamSpillInfoRetriever/Retriever/CMakeLists.txt new file mode 100644 index 000000000..69e21a189 --- /dev/null +++ b/sbncode/BeamSpillInfoRetriever/Retriever/CMakeLists.txt @@ -0,0 +1,43 @@ + +include_directories( $ENV{IFBEAM_FQ_DIR}/include ) +include_directories( $ENV{LIBWDA_FQ_DIR}/include ) +include_directories( $ENV{IFDHC_FQ_DIR}/inc ) +include_directories( $ENV{IFDH_ART_INC} ) +cet_find_library( IFBEAMSERVICE NAMES IFBeam_service PATHS ENV IFDH_ART_LIB NO_DEFAULT_PATH ) +cet_find_library( IFBEAM NAMES ifbeam PATHS ENV IFBEAM_LIB NO_DEFAULT_PATH ) + +art_make_library( + LIBRARY_NAME sbn_BeamSpillInfoRetriever_MWRData + SOURCE MWRData.cpp +) + + +simple_plugin(Retriever module + ${ART_FRAMEWORK_CORE} + ${ART_FRAMEWORK_SERVICES_REGISTRY} + ${ART_ROOT_IO_TFILESERVICE_SERVICE} ${ART_FRAMEWORK_SERVICES} + ${ART_FRAMEWORK_PRINCIPAL} + art_Persistency_Common + art_Utilities canvas + ${MF_MESSAGELOGGER} + ${MF_UTILITIES} + ${FHICLCPP} + cetlib cetlib_except + ${ROOT_EVE_LIB_LIST} + ${ROOT_X3d} + ${ROOT_BASIC_LIB_LIST} + ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_DATE_TIME_LIBRARY} ${Boost_SERIALIZATION_LIBRARY} + ${Boost_SYSTEM_LIBRARY} + MF_MessageLogger + sbnobj_Common_POTAccounting + ${IFBEAMSERVICE} + ${IFBEAM} + artdaq-core_Utilities + sbndaq-artdaq-core_Overlays_ICARUS + sbn_BeamSpillInfoRetriever_MWRData +) + +install_headers() +install_fhicl() +install_source() + diff --git a/sbncode/BeamSpillInfoRetriever/Retriever/MWRData.cpp b/sbncode/BeamSpillInfoRetriever/Retriever/MWRData.cpp new file mode 100644 index 000000000..66dc6a20a --- /dev/null +++ b/sbncode/BeamSpillInfoRetriever/Retriever/MWRData.cpp @@ -0,0 +1,79 @@ +#include +#include +#include +#include +#include +#include +#include "MWRData.h" + +using namespace std; + +namespace sbn{ + +std::vector MWRData::unpackMWR(std::string packed_data, long timeoffset) +{ + + std::vector unpacked_data; + + short data[444]; + + std::vector row(0); + boost::split(row, packed_data, boost::is_any_of(",")); + if (row.size()==447) { + for (int i=3;i<447;i++) { + data[i-3]=atoi(row[i].c_str()); + } + string devname=row[1].substr(0,8); + for (int idev=0;idev<4;idev++) { + mwrpulse_t mwr=getMWRdata(data,idev); + std::stringstream ss; + ss<< std::to_string(mwr.sheader.timesec*1000.+mwr.sheader.timensec/1000000.+timeoffset)<<","< +namespace sbn{ +class MWRData +{ + typedef struct swicheader_t { + long timesec; + long timensec; + long gpstime1; + long gpstime2; + short boosterevent; + short mievent; + short hz15micnt; + long delta1f; + short pulsemi; + short pulsesc; + } swicheader_t; + + typedef struct mwrpulse_t { + short hor[48]; + short ver[48]; + swicheader_t sheader; + } mwrpulse_t; + + long flipByte(long data) + { + return ((data>>16)&0x0000FFFF) | ((data<<16)&0xFFFF0000); + } + + mwrpulse_t getMWRdata(short* data, int nblock); + + public: + std::vector unpackMWR(std::string packed_data, long timeoffset=0); +}; +} + +#endif /* #ifndef _MWRDATA_H */ diff --git a/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc b/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc new file mode 100644 index 000000000..0a1dc8275 --- /dev/null +++ b/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc @@ -0,0 +1,274 @@ +//////////////////////////////////////////////////////////////////////// +// Class: Retriever +// Plugin Type: producer +// File: Retriever_module.cc +// +// Created by hand Wed April 9 2021 by J. Zennamo (FNAL) +// Based heavily on code by Z. Pavlovic written for MicroBooNE +// Based heavily on code by NOvA collaboration (Thanks NOvA!): +// https://cdcvs.fnal.gov/redmine/projects/novaart/repository/entry/trunk/IFDBSpillInfo/BNBInfo_module.cc +//////////////////////////////////////////////////////////////////////// + +#include "art/Framework/Core/EDProducer.h" +#include "art/Framework/Core/ModuleMacros.h" +#include "art/Framework/Principal/Event.h" +#include "art/Framework/Principal/Handle.h" +#include "art/Framework/Principal/Run.h" +#include "art/Framework/Principal/SubRun.h" +#include "canvas/Utilities/InputTag.h" +#include "fhiclcpp/ParameterSet.h" +#include "messagefacility/MessageLogger/MessageLogger.h" +#include "lardata/Utilities/AssociationUtil.h" +#include "lardataobj/Utilities/sparse_vector.h" +#include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" +#include "larcorealg/Geometry/Exceptions.h" + +#include "artdaq-core/Data/Fragment.hh" +#include "sbndaq-artdaq-core/Overlays/ICARUS/ICARUSTriggerUDPFragment.hh" + +#include "lardataalg/DetectorInfo/DetectorPropertiesStandard.h" +#include "lardata/DetectorInfoServices/DetectorPropertiesService.h" +#include "sbnobj/Common/POTAccounting/BeamSpillInfo.h" + +#include "IFBeam_service.h" +#include "ifbeam_c.h" +#include "MWRData.h" + +#include +#include +#include +#include +#include +#include + +namespace sbn { + class Retriever; +} + +class sbn::Retriever : public art::EDProducer { +public: + explicit Retriever(fhicl::ParameterSet const& p); + // The compiler-generated destructor is fine for non-base + // classes without bare pointers or other resource use. + + // Plugins should not be copied or assigned. + Retriever(Retriever const&) = delete; + Retriever(Retriever&&) = delete; + Retriever& operator=(Retriever const&) = delete; + Retriever& operator=(Retriever&&) = delete; + + // Required functions. + void produce(art::Event& e) override; + void beginSubRun(art::SubRun& sr); + void endSubRun(art::SubRun& sr); + +private: + // input labels + std::vector< sbn::BeamSpillInfo > fOutbeamInfos; + int fTimePad; + std::string fURL; + MWRData mwrdata; + std::string raw_data_label_; + + art::ServiceHandle ifbeam_handle; + std::unique_ptr bfp; + std::unique_ptr bfp_mwr; + +}; + + +sbn::Retriever::Retriever(fhicl::ParameterSet const& p) + : EDProducer{p}, + fTimePad(p.get("TimePadding",0.0333)), //seconds + raw_data_label_(p.get("raw_data_label")), + bfp( ifbeam_handle->getBeamFolder(p.get< std::string >("Bundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))), + bfp_mwr( ifbeam_handle->getBeamFolder(p.get< std::string >("MultiWireBundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))) +{ + bfp->set_epsilon(0.0333); // how close in time does the spill time have to be from the DAQ time (in seconds). + bfp_mwr->set_epsilon(100); // how close in time does the spill time have to be from the DAQ time (in seconds). + produces< std::vector< sbn::BeamSpillInfo >, art::InSubRun >(); + +} + +void sbn::Retriever::produce(art::Event& e) +{ + + //Get the time of the event and the previous event + // time since epoch sec . nanoseconds + //1616202843.932767280 + //.932767280 + //.030000000 + + + art::Handle< std::vector > raw_data_ptr; + e.getByLabel(raw_data_label_, "ICARUSTriggerUDP", raw_data_ptr); + auto const & raw_data = (*raw_data_ptr); + icarus::ICARUSTriggerUDPFragment frag(fragment); + + + + // double t_previous_event = 1616202844.932767280; + // double t_current_event = 1616202843.932767280; + + double t_previous_event = 0; + double t_current_event = 0; + std::cout << "This many raw_datums : " << raw_data.size() << std::endl; + for(auto raw_datum : raw_data){ + + uint64_t artdaq_ts = fragment.timestamp(); + icarus::ICARUSTriggerUDPFragment frag(fragment); + std::string data = frag.GetDataString(); + char *buffer = const_cast(data.c_str()); + icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerString(buffer); + int gate_type = datastream_info.gate_type; + if(gate_type != 1) continue; + + t_current_event = datastream_info.getNanoseconds_since_UTC_epoch() + 2; //check this offset... + t_previous_event = frag.getLastTimestampBNB(); + + } + + std::cout << "Previous : " << t_previous_event << ", Current : " << t_current_event << std::endl; + + if(t_previous_event == t_current_event) return -1; + + + try{ + double test_curr; double test_t1; + bfp->GetNamedData((t_previous_event)-fTimePad,"E:THCURR",&test_curr,&test_t1); + std::cout << "got values " << test_curr << "for E:THCURR at time " << test_t1 << "\n"; + } + catch (WebAPIException &we) { + std::cout << "got exception: " << we.what() << "\n"; + } + std::cout.precision(17); + + + try{ + auto packed_M876BB_temp = bfp_mwr->GetNamedVector((t_previous_event)-35,"E:M875BB{4440:888}.RAW"); + } + catch (WebAPIException &we) { + //we have to have this or it doesn't work... + } + + // bfp_mwr->setValidWindow(86400); + //std::cout << "Is this a valid Window " << bfp_mwr->getValidWindow()< > unpacked_M876BB_str; + // unpacked_M876BB_str.resize(3); + std::vector unpacked_M876BB_str; + std::string packed_data_str; + // int dev = 0; + std::vector vars = bfp_mwr->GetDeviceList(); + double t_mwr; + std::cout << int(vars.size()) << " MWR Devices " << std::endl; + for (int i = 0; i < int(vars.size()); i++) { + if(vars[i].empty()) continue; + + /// Check the device name and interate the double-vector index + // if(vars[i].M875BB) dev = 0; + //M876BB; + //MMBTBB; + //std::cout << vars[i] << std::endl; + + + //var - > E:M875BB{888:888}.RAW + t_mwr = 0; + std::vector packed_M876BB = bfp_mwr->GetNamedVector((t_previous_event)-35,vars[i],&t_mwr); + + packed_data_str.clear(); + packed_data_str += std::to_string(int(t_mwr)); + packed_data_str.append(","); + packed_data_str.append(vars[i]); + packed_data_str.append(",,"); + + for(int j = 0; j < int(packed_M876BB.size()); j++){ + packed_data_str += std::to_string(int(packed_M876BB[j])); + if(j < int(packed_M876BB.size())-1) + packed_data_str.append(","); + } + + // std::cout << packed_data_str << std::endl; + + auto unpacked_M876BB_str_temp = mwrdata.unpackMWR(packed_data_str,long(-35)); + unpacked_M876BB_str.insert(unpacked_M876BB_str.end(), + unpacked_M876BB_str_temp.begin(), + unpacked_M876BB_str_temp.end()); + + + std::cout << int(unpacked_M876BB_str.size()) << " unpacked datas ... " << std::endl; + } + + //for(int j = 0; j < int(unpacked_M876BB_str.size()); j++){ + // std::cout << unpacked_M876BB_str[j] << std::endl; + //} + + + std::vector times_temps = bfp->GetTimeList(); + for (size_t i = 0; i < times_temps.size(); i++) { + if(times_temps[i] > (t_current_event+fTimePad)){break;} + + double TOR860 = 0; + double TOR875 = 0; + double LM875A = 0; + double LM875B = 0; + double LM875C = 0; + double HP875 = 0; + double VP875 = 0; + double HPTG1 = 0; + double VPTG1 = 0; + double HPTG2 = 0; + double VPTG2 = 0; + double BTJT2 = 0; + double THCURR = 0; + + double TOR860_time = 0; + + bfp->GetNamedData(times_temps[i], "E:TOR860@,E:TOR875,E:LM875A,E:LM875B,E:LM875C,E:HP875,E:VP875,E:HPTG1,E:VPTG1,E:HPTG2,E:VPTG2,E:BTJT2,E:THCURR",&TOR860,&TOR860_time,&TOR875,&LM875A,&LM875B,&LM875C,&HP875,&VP875,&HPTG1,&VPTG1,&HPTG2,&VPTG2,&BTJT2,&THCURR); + + + unsigned long int time_closest_int = (int) TOR860_time; + double time_closest_ns = (TOR860_time - time_closest_int)*1e9; + + sbn::BeamSpillInfo beamInfo; + beamInfo.TOR860 = TOR860; + beamInfo.TOR875 = TOR875; + beamInfo.LM875A = LM875A; + beamInfo.LM875B = LM875B; + beamInfo.LM875C = LM875C; + beamInfo.HP875 = HP875; + beamInfo.VP875 = VP875; + beamInfo.HPTG1 = HPTG1; + beamInfo.VPTG1 = VPTG1; + beamInfo.HPTG2 = HPTG2; + beamInfo.VPTG2 = VPTG2; + beamInfo.BTJT2 = BTJT2; + beamInfo.THCURR = THCURR; + beamInfo.spill_time_s = time_closest_int; + beamInfo.spill_time_ns = time_closest_ns; + + fOutbeamInfos.push_back(beamInfo); + + + } + +} + +void sbn::Retriever::beginSubRun(art::SubRun& sr) +{ + return; +} + +//____________________________________________________________________________ +void sbn::Retriever::endSubRun(art::SubRun& sr) +{ + + auto p = std::make_unique< std::vector< sbn::BeamSpillInfo > >(fOutbeamInfos); + + sr.put(std::move(p)); + + return; +} + +DEFINE_ART_MODULE(sbn::Retriever) diff --git a/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module_brokeit.cc b/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module_brokeit.cc new file mode 100644 index 000000000..0ef5edcae --- /dev/null +++ b/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module_brokeit.cc @@ -0,0 +1,242 @@ +//////////////////////////////////////////////////////////////////////// +// Class: Retriever +// Plugin Type: producer +// File: Retriever_module.cc +// +// Created by hand Wed April 9 2021 by J. Zennamo (FNAL) +// Based heavily on code by Z. Pavlovic written for MicroBooNE +// Based heavily on code by NOvA collaboration (Thanks NOvA!): +// https://cdcvs.fnal.gov/redmine/projects/novaart/repository/entry/trunk/IFDBSpillInfo/BNBInfo_module.cc +//////////////////////////////////////////////////////////////////////// + +#include "art/Framework/Core/EDProducer.h" +#include "art/Framework/Core/ModuleMacros.h" +#include "art/Framework/Principal/Event.h" +#include "artdaq-core/Data/Fragment.hh" +#include "art/Framework/Principal/Handle.h" +#include "art/Framework/Principal/Run.h" +#include "art/Framework/Principal/SubRun.h" +#include "canvas/Utilities/InputTag.h" +#include "fhiclcpp/ParameterSet.h" +#include "messagefacility/MessageLogger/MessageLogger.h" +#include "lardata/Utilities/AssociationUtil.h" +#include "lardataobj/Utilities/sparse_vector.h" +#include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" +#include "larcorealg/Geometry/Exceptions.h" + +#include "lardataalg/DetectorInfo/DetectorPropertiesStandard.h" +#include "lardata/DetectorInfoServices/DetectorPropertiesService.h" +#include "sbnobj/Common/POTAccounting/BeamSpillInfo.h" + +#include "IFBeam_service.h" +#include "ifbeam_c.h" +#include "MWRData.h" + +#include +#include +#include +#include +#include +#include + +namespace sbn { + class Retriever; +} + +class sbn::Retriever : public BNBRetriever { +public: + explicit Retriever(fhicl::ParameterSet const& p); + // The compiler-generated destructor is fine for non-base + // classes without bare pointers or other resource use. + + // Plugins should not be copied or assigned. + Retriever(Retriever const&) = delete; + Retriever(Retriever&&) = delete; + Retriever& operator=(Retriever const&) = delete; + Retriever& operator=(Retriever&&) = delete; + + // Required functions. + void produces(art::ProducesCollector&); + void process_fragment(const artdaq::Fragment &fragment); + void beginSubRun(art::SubRun& sr); + void endSubRun(art::SubRun& sr); + +private: + // input labels + std::vector< sbn::BeamSpillInfo > fOutbeamInfos; + int fTimePad; + std::string fURL; + MWRData mwrdata; + + art::ServiceHandle ifbeam_handle; + std::unique_ptr bfp; + std::unique_ptr bfp_mwr; + +}; + + +sbn::Retriever::Retriever(fhicl::ParameterSet const& p) + : EDProducer{p}, + fTimePad(p.get("TimePadding",0.0333)), //seconds + bfp( ifbeam_handle->getBeamFolder(p.get< std::string >("Bundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))), + bfp_mwr( ifbeam_handle->getBeamFolder(p.get< std::string >("MultiWireBundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))) +{ + bfp->set_epsilon(0.0333); // how close in time does the spill time have to be from the DAQ time (in seconds). + bfp_mwr->set_epsilon(100); // how close in time does the spill time have to be from the DAQ time (in seconds). + // produces< std::vector< sbn::BeamSpillInfo >, art::InSubRun >(); + +} + +void sbn::Retriever::produces(art::ProducesCollector& collector) +{ + collector.produces< std::vector< sbn::BeamSpillInfo >, art::InSubRun >(); +} + +void sbn::Retriever::process_fragment(const artdaq::Fragment &fragment) +{ + //Get the time of the event and the previous event + // time since epoch sec . nanoseconds + //1616202843.932767280 + //.932767280 + //.030000000 + double t_previous_event = 1616202844.932767280; + double t_current_event = 1616202843.932767280; + + try{ + double test_curr; double test_t1; + bfp->GetNamedData((t_previous_event)-fTimePad,"E:THCURR",&test_curr,&test_t1); + std::cout << "got values " << test_curr << "for E:THCURR at time " << test_t1 << "\n"; + } + catch (WebAPIException &we) { + std::cout << "got exception: " << we.what() << "\n"; + } + std::cout.precision(17); + + + try{ + auto packed_M876BB_temp = bfp_mwr->GetNamedVector((t_previous_event)-35,"E:M875BB{4440:888}.RAW"); + } + catch (WebAPIException &we) { + //we have to have this or it doesn't work... + } + + // bfp_mwr->setValidWindow(86400); + //std::cout << "Is this a valid Window " << bfp_mwr->getValidWindow()< unpacked_M876BB_str; + // unpacked_M876BB_str.resize(3); + std::string packed_data_str; + //int dev = 0; + std::vector vars = bfp_mwr->GetDeviceList(); + double t_mwr; + std::cout << int(vars.size()) << " MWR Devices " << std::endl; + for (int i = 0; i < int(vars.size()); i++) { + if(vars[i].empty()) continue; + + /// Check the device name and interate the double-vector index + // if(vars[i].M875BB) dev = 0; + // M876BB; + // MMBTBB; + std::cout << vars[i] << std::endl; + + + //var - > E:M875BB{888:888}.RAW + t_mwr = 0; + std::vector packed_M876BB = bfp_mwr->GetNamedVector((t_previous_event)-35,vars[i],&t_mwr); + + packed_data_str.clear(); + packed_data_str += std::to_string(int(t_mwr)); + packed_data_str.append(","); + packed_data_str.append(vars[i]); + packed_data_str.append(",,"); + + for(int j = 0; j < int(packed_M876BB.size()); j++){ + packed_data_str += std::to_string(int(packed_M876BB[j])); + if(j < int(packed_M876BB.size())-1) + packed_data_str.append(","); + } + + // std::cout << packed_data_str << std::endl; + + auto unpacked_M876BB_str_temp = mwrdata.unpackMWR(packed_data_str,long(-35)); + unpacked_M876BB_str.insert(unpacked_M876BB_str.end(), + unpacked_M876BB_str_temp.begin(), + unpacked_M876BB_str_temp.end()); + + + std::cout << int(unpacked_M876BB_str.size()) << " unpacked datas ... " << std::endl; + } + + for(int j = 0; j < int(unpacked_M876BB_str.size()); j++){ + std::cout << unpacked_M876BB_str[j] << std::endl; + } + + + std::vector times_temps = bfp->GetTimeList(); + for (size_t i = 0; i < times_temps.size(); i++) { + if(times_temps[i] > (t_current_event+fTimePad)){break;} + + double TOR860 = 0; + double TOR875 = 0; + double LM875A = 0; + double LM875B = 0; + double LM875C = 0; + double HP875 = 0; + double VP875 = 0; + double HPTG1 = 0; + double VPTG1 = 0; + double HPTG2 = 0; + double VPTG2 = 0; + double BTJT2 = 0; + double THCURR = 0; + + double TOR860_time = 0; + + bfp->GetNamedData(times_temps[i], "E:TOR860@,E:TOR875,E:LM875A,E:LM875B,E:LM875C,E:HP875,E:VP875,E:HPTG1,E:VPTG1,E:HPTG2,E:VPTG2,E:BTJT2,E:THCURR",&TOR860,&TOR860_time,&TOR875,&LM875A,&LM875B,&LM875C,&HP875,&VP875,&HPTG1,&VPTG1,&HPTG2,&VPTG2,&BTJT2,&THCURR); + + + unsigned long int time_closest_int = (int) TOR860_time; + double time_closest_ns = (TOR860_time - time_closest_int)*1e9; + + sbn::BeamSpillInfo beamInfo; + beamInfo.TOR860 = TOR860; + beamInfo.TOR875 = TOR875; + beamInfo.LM875A = LM875A; + beamInfo.LM875B = LM875B; + beamInfo.LM875C = LM875C; + beamInfo.HP875 = HP875; + beamInfo.VP875 = VP875; + beamInfo.HPTG1 = HPTG1; + beamInfo.VPTG1 = VPTG1; + beamInfo.HPTG2 = HPTG2; + beamInfo.VPTG2 = VPTG2; + beamInfo.BTJT2 = BTJT2; + beamInfo.THCURR = THCURR; + beamInfo.spill_time_s = time_closest_int; + beamInfo.spill_time_ns = time_closest_ns; + + fOutbeamInfos.push_back(beamInfo); + + + } + +} + +void sbn::Retriever::beginSubRun(art::SubRun& sr) +{ + return; +} + +//____________________________________________________________________________ +void sbn::Retriever::endSubRun(art::SubRun& sr) +{ + + auto p = std::make_unique< std::vector< sbn::BeamSpillInfo > >(fOutbeamInfos); + + sr.put(std::move(p)); + + return; +} + +DEFINE_ART_MODULE(sbn::Retriever) diff --git a/sbncode/BeamSpillInfoRetriever/job/CMakeLists.txt b/sbncode/BeamSpillInfoRetriever/job/CMakeLists.txt new file mode 100644 index 000000000..0361ef331 --- /dev/null +++ b/sbncode/BeamSpillInfoRetriever/job/CMakeLists.txt @@ -0,0 +1,3 @@ +install_fhicl() +FILE(GLOB fcl_files *.fcl) +install_source( EXTRAS ${fcl_files} ) diff --git a/sbncode/BeamSpillInfoRetriever/job/beamspillinfo.fcl b/sbncode/BeamSpillInfoRetriever/job/beamspillinfo.fcl new file mode 100644 index 000000000..f727754e5 --- /dev/null +++ b/sbncode/BeamSpillInfoRetriever/job/beamspillinfo.fcl @@ -0,0 +1,15 @@ + +BEGIN_PROLOG + +beamspillinfo: { + + module_type: "Retriever" + TimePadding: 0.0333 #unit seconds, Booster Rep Rate is 15 Hz, so the closest spill could be 66ms away + URL: "" #keep this blank and we're good + Bundle: "BoosterNeutrinoBeam_read" + MultiWireBundle: "BNBMultiWire" + TimeWindow: "500" #seconds + raw_data_label: "daq" + +} +END_PROLOG diff --git a/sbncode/CMakeLists.txt b/sbncode/CMakeLists.txt index d1c17ae2f..7f1c9490a 100644 --- a/sbncode/CMakeLists.txt +++ b/sbncode/CMakeLists.txt @@ -1,5 +1,7 @@ cet_find_library( BOOST_SERIALIZATION NAMES boost_serialization PATHS ENV BOOST_LIB NO_DEFAULT_PATH ) cet_find_library( BOOST_DATE_TIME NAMES boost_date_time PATHS ENV BOOST_LIB NO_DEFAULT_PATH ) +cet_find_library( IFBEAM NAMES ifbeam PATHS ENV IFBEAM_LIB NO_DEFAULT_PATH ) +cet_find_library( WDA NAMES wda PATHS ENV LIBWDA_LIB NO_DEFAULT_PATH ) find_ups_product(sbnanaobj) @@ -14,3 +16,5 @@ add_subdirectory(Metadata) add_subdirectory(FlashMatch) add_subdirectory(LArRecoProducer) add_subdirectory(TPCReco) + +add_subdirectory(BeamSpillInfoRetriever) From 8950d4b00c0e2d9780543e88b8865b34f4a0d51a Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Wed, 9 Jun 2021 13:15:21 -0500 Subject: [PATCH 02/46] needed to add sbndaq --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1787c992e..a38fae7ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,7 @@ find_ups_product(libwda) find_ups_product(sbnobj v09_10_00) #find_ups_product(sbndcode v06_67_00) #find_ups_product(uboonecode v06_67_00) +find_ups_product( sbndaq_artdaq_core ) # macros for dictionary and simple_plugin include(ArtDictionary) From 9ffc4f16a23684dae2eff336dcdb5f3b3446f0b0 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Wed, 9 Jun 2021 13:15:40 -0500 Subject: [PATCH 03/46] adding libraries --- sbncode/BeamSpillInfoRetriever/Retriever/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sbncode/BeamSpillInfoRetriever/Retriever/CMakeLists.txt b/sbncode/BeamSpillInfoRetriever/Retriever/CMakeLists.txt index 69e21a189..6e7464b9a 100644 --- a/sbncode/BeamSpillInfoRetriever/Retriever/CMakeLists.txt +++ b/sbncode/BeamSpillInfoRetriever/Retriever/CMakeLists.txt @@ -32,8 +32,10 @@ simple_plugin(Retriever module sbnobj_Common_POTAccounting ${IFBEAMSERVICE} ${IFBEAM} - artdaq-core_Utilities + sbndaq-artdaq-core_Overlays_Common + sbndaq-artdaq-core_Overlays sbndaq-artdaq-core_Overlays_ICARUS + artdaq-core_Utilities sbn_BeamSpillInfoRetriever_MWRData ) From b831f5685458e11a49d3ee5445bd0fc65e47295c Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Wed, 9 Jun 2021 13:46:23 -0500 Subject: [PATCH 04/46] builds now --- .../Retriever/Retriever_module.cc | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc b/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc index 0a1dc8275..14174f95b 100644 --- a/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc @@ -103,9 +103,6 @@ void sbn::Retriever::produce(art::Event& e) art::Handle< std::vector > raw_data_ptr; e.getByLabel(raw_data_label_, "ICARUSTriggerUDP", raw_data_ptr); auto const & raw_data = (*raw_data_ptr); - icarus::ICARUSTriggerUDPFragment frag(fragment); - - // double t_previous_event = 1616202844.932767280; // double t_current_event = 1616202843.932767280; @@ -115,8 +112,8 @@ void sbn::Retriever::produce(art::Event& e) std::cout << "This many raw_datums : " << raw_data.size() << std::endl; for(auto raw_datum : raw_data){ - uint64_t artdaq_ts = fragment.timestamp(); - icarus::ICARUSTriggerUDPFragment frag(fragment); + //uint64_t artdaq_ts = raw_datum.timestamp(); + icarus::ICARUSTriggerUDPFragment frag(raw_datum); std::string data = frag.GetDataString(); char *buffer = const_cast(data.c_str()); icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerString(buffer); @@ -130,8 +127,7 @@ void sbn::Retriever::produce(art::Event& e) std::cout << "Previous : " << t_previous_event << ", Current : " << t_current_event << std::endl; - if(t_previous_event == t_current_event) return -1; - + //if(t_previous_event == t_current_event) return -1; try{ double test_curr; double test_t1; From e32319349a910b7f0bab951c493b5182efa5ac95 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 9 Jun 2021 15:41:48 -0500 Subject: [PATCH 05/46] Updates to Joseph's work to extract only BNB spills, code working but need to look at IFBeam database query logic --- .../Retriever/Retriever_module.cc | 250 +++++++++--------- 1 file changed, 128 insertions(+), 122 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc b/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc index 0a1dc8275..8500b1d5c 100644 --- a/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc @@ -99,12 +99,10 @@ void sbn::Retriever::produce(art::Event& e) //.932767280 //.030000000 - + int gate_type = 0; art::Handle< std::vector > raw_data_ptr; e.getByLabel(raw_data_label_, "ICARUSTriggerUDP", raw_data_ptr); auto const & raw_data = (*raw_data_ptr); - icarus::ICARUSTriggerUDPFragment frag(fragment); - // double t_previous_event = 1616202844.932767280; @@ -115,144 +113,152 @@ void sbn::Retriever::produce(art::Event& e) std::cout << "This many raw_datums : " << raw_data.size() << std::endl; for(auto raw_datum : raw_data){ - uint64_t artdaq_ts = fragment.timestamp(); - icarus::ICARUSTriggerUDPFragment frag(fragment); + uint64_t artdaq_ts = raw_datum.timestamp(); + icarus::ICARUSTriggerUDPFragment frag(raw_datum); std::string data = frag.GetDataString(); char *buffer = const_cast(data.c_str()); icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerString(buffer); - int gate_type = datastream_info.gate_type; - if(gate_type != 1) continue; - - t_current_event = datastream_info.getNanoseconds_since_UTC_epoch() + 2; //check this offset... - t_previous_event = frag.getLastTimestampBNB(); - - } - - std::cout << "Previous : " << t_previous_event << ", Current : " << t_current_event << std::endl; - - if(t_previous_event == t_current_event) return -1; - - - try{ - double test_curr; double test_t1; - bfp->GetNamedData((t_previous_event)-fTimePad,"E:THCURR",&test_curr,&test_t1); - std::cout << "got values " << test_curr << "for E:THCURR at time " << test_t1 << "\n"; - } - catch (WebAPIException &we) { - std::cout << "got exception: " << we.what() << "\n"; - } - std::cout.precision(17); - - - try{ - auto packed_M876BB_temp = bfp_mwr->GetNamedVector((t_previous_event)-35,"E:M875BB{4440:888}.RAW"); - } - catch (WebAPIException &we) { - //we have to have this or it doesn't work... + gate_type = datastream_info.gate_type; + double delta_gates = frag.getDeltaGatesBNB(); + std::cout << "Gate_type: " << gate_type << std::endl; + if(gate_type == 1) + std::cout << "Number of beam gates since the last spill of this type: " << delta_gates << std::endl; + std::cout << "Fragment timestamp: " << artdaq_ts << std::endl; + t_current_event = static_cast(artdaq_ts)/(1000000000); //check this offset... + if(gate_type == 1) + t_previous_event = (static_cast(frag.getLastTimestampBNB()))/(1e9); + else + t_previous_event = (static_cast(frag.getLastTimestampOther()))/(1000000000); + } - // bfp_mwr->setValidWindow(86400); - //std::cout << "Is this a valid Window " << bfp_mwr->getValidWindow()< > unpacked_M876BB_str; - // unpacked_M876BB_str.resize(3); - std::vector unpacked_M876BB_str; - std::string packed_data_str; - // int dev = 0; - std::vector vars = bfp_mwr->GetDeviceList(); - double t_mwr; - std::cout << int(vars.size()) << " MWR Devices " << std::endl; - for (int i = 0; i < int(vars.size()); i++) { - if(vars[i].empty()) continue; - - /// Check the device name and interate the double-vector index - // if(vars[i].M875BB) dev = 0; - //M876BB; - //MMBTBB; - //std::cout << vars[i] << std::endl; - - - //var - > E:M875BB{888:888}.RAW - t_mwr = 0; - std::vector packed_M876BB = bfp_mwr->GetNamedVector((t_previous_event)-35,vars[i],&t_mwr); + //if(t_previous_event == t_current_event) continue; + + if(gate_type == 1) + { + std::cout << "Is BNB event! Extracting POT!" << std::endl; + try{ + double test_curr; double test_t1; + bfp->GetNamedData((t_previous_event)-fTimePad,"E:THCURR",&test_curr,&test_t1); + std::cout << "got values " << test_curr << "for E:THCURR at time " << test_t1 << "\n"; + } + catch (WebAPIException &we) { + std::cout << "got exception: " << we.what() << "\n"; + } + std::cout.precision(17); - packed_data_str.clear(); - packed_data_str += std::to_string(int(t_mwr)); - packed_data_str.append(","); - packed_data_str.append(vars[i]); - packed_data_str.append(",,"); - for(int j = 0; j < int(packed_M876BB.size()); j++){ - packed_data_str += std::to_string(int(packed_M876BB[j])); - if(j < int(packed_M876BB.size())-1) - packed_data_str.append(","); + try{ + auto packed_M876BB_temp = bfp_mwr->GetNamedVector((t_previous_event)-35,"E:M875BB{4440:888}.RAW"); + } + catch (WebAPIException &we) { + //we have to have this or it doesn't work... } - // std::cout << packed_data_str << std::endl; + // bfp_mwr->setValidWindow(86400); + //std::cout << "Is this a valid Window " << bfp_mwr->getValidWindow()< > unpacked_M876BB_str; + // unpacked_M876BB_str.resize(3); + std::vector unpacked_M876BB_str; + std::string packed_data_str; + // int dev = 0; + std::vector vars = bfp_mwr->GetDeviceList(); + double t_mwr; + std::cout << int(vars.size()) << " MWR Devices " << std::endl; + for (int i = 0; i < int(vars.size()); i++) { + if(vars[i].empty()) continue; + + /// Check the device name and interate the double-vector index + // if(vars[i].M875BB) dev = 0; + //M876BB; + //MMBTBB; + //std::cout << vars[i] << std::endl; + + + //var - > E:M875BB{888:888}.RAW + t_mwr = 0; + std::vector packed_M876BB = bfp_mwr->GetNamedVector((t_previous_event)-35,vars[i],&t_mwr); + + packed_data_str.clear(); + packed_data_str += std::to_string(int(t_mwr)); + packed_data_str.append(","); + packed_data_str.append(vars[i]); + packed_data_str.append(",,"); + + for(int j = 0; j < int(packed_M876BB.size()); j++){ + packed_data_str += std::to_string(int(packed_M876BB[j])); + if(j < int(packed_M876BB.size())-1) + packed_data_str.append(","); + } + + // std::cout << packed_data_str << std::endl; + + auto unpacked_M876BB_str_temp = mwrdata.unpackMWR(packed_data_str,long(-35)); + unpacked_M876BB_str.insert(unpacked_M876BB_str.end(), + unpacked_M876BB_str_temp.begin(), + unpacked_M876BB_str_temp.end()); + + + //std::cout << int(unpacked_M876BB_str.size()) << " unpacked datas ... " << std::endl; + } - std::cout << int(unpacked_M876BB_str.size()) << " unpacked datas ... " << std::endl; - } - - //for(int j = 0; j < int(unpacked_M876BB_str.size()); j++){ - // std::cout << unpacked_M876BB_str[j] << std::endl; + //for(int j = 0; j < int(unpacked_M876BB_str.size()); j++){ + // std::cout << unpacked_M876BB_str[j] << std::endl; //} - - - std::vector times_temps = bfp->GetTimeList(); - for (size_t i = 0; i < times_temps.size(); i++) { - if(times_temps[i] > (t_current_event+fTimePad)){break;} - double TOR860 = 0; - double TOR875 = 0; - double LM875A = 0; - double LM875B = 0; - double LM875C = 0; - double HP875 = 0; - double VP875 = 0; - double HPTG1 = 0; - double VPTG1 = 0; - double HPTG2 = 0; - double VPTG2 = 0; - double BTJT2 = 0; - double THCURR = 0; - double TOR860_time = 0; - - bfp->GetNamedData(times_temps[i], "E:TOR860@,E:TOR875,E:LM875A,E:LM875B,E:LM875C,E:HP875,E:VP875,E:HPTG1,E:VPTG1,E:HPTG2,E:VPTG2,E:BTJT2,E:THCURR",&TOR860,&TOR860_time,&TOR875,&LM875A,&LM875B,&LM875C,&HP875,&VP875,&HPTG1,&VPTG1,&HPTG2,&VPTG2,&BTJT2,&THCURR); - + std::vector times_temps = bfp->GetTimeList(); + for (size_t i = 0; i < times_temps.size(); i++) { + if(times_temps[i] > (t_current_event+fTimePad)){break;} + + double TOR860 = 0; + double TOR875 = 0; + double LM875A = 0; + double LM875B = 0; + double LM875C = 0; + double HP875 = 0; + double VP875 = 0; + double HPTG1 = 0; + double VPTG1 = 0; + double HPTG2 = 0; + double VPTG2 = 0; + double BTJT2 = 0; + double THCURR = 0; + + double TOR860_time = 0; + + bfp->GetNamedData(times_temps[i], "E:TOR860@,E:TOR875,E:LM875A,E:LM875B,E:LM875C,E:HP875,E:VP875,E:HPTG1,E:VPTG1,E:HPTG2,E:VPTG2,E:BTJT2,E:THCURR",&TOR860,&TOR860_time,&TOR875,&LM875A,&LM875B,&LM875C,&HP875,&VP875,&HPTG1,&VPTG1,&HPTG2,&VPTG2,&BTJT2,&THCURR); + + + unsigned long int time_closest_int = (int) TOR860_time; + double time_closest_ns = (TOR860_time - time_closest_int)*1e9; + + sbn::BeamSpillInfo beamInfo; + beamInfo.TOR860 = TOR860; + beamInfo.TOR875 = TOR875; + beamInfo.LM875A = LM875A; + beamInfo.LM875B = LM875B; + beamInfo.LM875C = LM875C; + beamInfo.HP875 = HP875; + beamInfo.VP875 = VP875; + beamInfo.HPTG1 = HPTG1; + beamInfo.VPTG1 = VPTG1; + beamInfo.HPTG2 = HPTG2; + beamInfo.VPTG2 = VPTG2; + beamInfo.BTJT2 = BTJT2; + beamInfo.THCURR = THCURR; + beamInfo.spill_time_s = time_closest_int; + beamInfo.spill_time_ns = time_closest_ns; + + fOutbeamInfos.push_back(beamInfo); - unsigned long int time_closest_int = (int) TOR860_time; - double time_closest_ns = (TOR860_time - time_closest_int)*1e9; - - sbn::BeamSpillInfo beamInfo; - beamInfo.TOR860 = TOR860; - beamInfo.TOR875 = TOR875; - beamInfo.LM875A = LM875A; - beamInfo.LM875B = LM875B; - beamInfo.LM875C = LM875C; - beamInfo.HP875 = HP875; - beamInfo.VP875 = VP875; - beamInfo.HPTG1 = HPTG1; - beamInfo.VPTG1 = VPTG1; - beamInfo.HPTG2 = HPTG2; - beamInfo.VPTG2 = VPTG2; - beamInfo.BTJT2 = BTJT2; - beamInfo.THCURR = THCURR; - beamInfo.spill_time_s = time_closest_int; - beamInfo.spill_time_ns = time_closest_ns; - - fOutbeamInfos.push_back(beamInfo); - + } } - } void sbn::Retriever::beginSubRun(art::SubRun& sr) From 56fd3b2d571564724c27b45848594300dbbff5a2 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 9 Jun 2021 15:45:20 -0500 Subject: [PATCH 06/46] Fixing merge issue, should be right now --- .../Retriever/Retriever_module.cc | 34 +++---------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc b/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc index faba0421c..8500b1d5c 100644 --- a/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc @@ -103,6 +103,8 @@ void sbn::Retriever::produce(art::Event& e) art::Handle< std::vector > raw_data_ptr; e.getByLabel(raw_data_label_, "ICARUSTriggerUDP", raw_data_ptr); auto const & raw_data = (*raw_data_ptr); + + // double t_previous_event = 1616202844.932767280; // double t_current_event = 1616202843.932767280; @@ -115,7 +117,7 @@ void sbn::Retriever::produce(art::Event& e) icarus::ICARUSTriggerUDPFragment frag(raw_datum); std::string data = frag.GetDataString(); char *buffer = const_cast(data.c_str()); - icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerString(buffer); + icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerString(buffer); gate_type = datastream_info.gate_type; double delta_gates = frag.getDeltaGatesBNB(); std::cout << "Gate_type: " << gate_type << std::endl; @@ -127,35 +129,7 @@ void sbn::Retriever::produce(art::Event& e) t_previous_event = (static_cast(frag.getLastTimestampBNB()))/(1e9); else t_previous_event = (static_cast(frag.getLastTimestampOther()))/(1000000000); - int gate_type = datastream_info.gate_type; - if(gate_type != 1) continue; - - t_current_event = datastream_info.getNanoseconds_since_UTC_epoch() + 2; //check this offset... - t_previous_event = frag.getLastTimestampBNB(); - - } - - std::cout << "Previous : " << t_previous_event << ", Current : " << t_current_event << std::endl; - - //if(t_previous_event == t_current_event) return -1; - - try{ - double test_curr; double test_t1; - bfp->GetNamedData((t_previous_event)-fTimePad,"E:THCURR",&test_curr,&test_t1); - std::cout << "got values " << test_curr << "for E:THCURR at time " << test_t1 << "\n"; - } - catch (WebAPIException &we) { - std::cout << "got exception: " << we.what() << "\n"; - } - std::cout.precision(17); - - - try{ - auto packed_M876BB_temp = bfp_mwr->GetNamedVector((t_previous_event)-35,"E:M875BB{4440:888}.RAW"); - } - catch (WebAPIException &we) { - //we have to have this or it doesn't work... ->>>>>>> b831f5685458e11a49d3ee5445bd0fc65e47295c + } std::cout << std::setprecision(19) << "Previous : " << t_previous_event << ", Current : " << t_current_event << std::endl; From 2efbcb476b62220ed70c6f7e69178ff27d401fcd Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Thu, 17 Jun 2021 13:27:22 -0500 Subject: [PATCH 07/46] changed name and got it working --- .../BNBRetriever_module.cc} | 152 +++++---- .../CMakeLists.txt | 6 +- .../{Retriever => BNBRetriever}/MWRData.cpp | 0 .../{Retriever => BNBRetriever}/MWRData.h | 0 sbncode/BeamSpillInfoRetriever/CMakeLists.txt | 2 +- .../Retriever/#Retriever_module.cc# | 302 ------------------ .../Retriever/Retriever_module_brokeit.cc | 242 -------------- .../{beamspillinfo.fcl => bnbspillinfo.fcl} | 4 +- .../job/run_bnbinfo_sbn.fcl | 33 ++ 9 files changed, 120 insertions(+), 621 deletions(-) rename sbncode/BeamSpillInfoRetriever/{Retriever/Retriever_module.cc => BNBRetriever/BNBRetriever_module.cc} (57%) rename sbncode/BeamSpillInfoRetriever/{Retriever => BNBRetriever}/CMakeLists.txt (91%) rename sbncode/BeamSpillInfoRetriever/{Retriever => BNBRetriever}/MWRData.cpp (100%) rename sbncode/BeamSpillInfoRetriever/{Retriever => BNBRetriever}/MWRData.h (100%) delete mode 100644 sbncode/BeamSpillInfoRetriever/Retriever/#Retriever_module.cc# delete mode 100644 sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module_brokeit.cc rename sbncode/BeamSpillInfoRetriever/job/{beamspillinfo.fcl => bnbspillinfo.fcl} (85%) create mode 100644 sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl diff --git a/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc similarity index 57% rename from sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc rename to sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 8500b1d5c..17ad8214c 100644 --- a/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////// -// Class: Retriever +// Class: BNBRetriever // Plugin Type: producer -// File: Retriever_module.cc +// File: BNBRetriever_module.cc // // Created by hand Wed April 9 2021 by J. Zennamo (FNAL) // Based heavily on code by Z. Pavlovic written for MicroBooNE @@ -28,7 +28,7 @@ #include "lardataalg/DetectorInfo/DetectorPropertiesStandard.h" #include "lardata/DetectorInfoServices/DetectorPropertiesService.h" -#include "sbnobj/Common/POTAccounting/BeamSpillInfo.h" +#include "sbnobj/Common/POTAccounting/BNBSpillInfo.h" #include "IFBeam_service.h" #include "ifbeam_c.h" @@ -42,20 +42,20 @@ #include namespace sbn { - class Retriever; + class BNBRetriever; } -class sbn::Retriever : public art::EDProducer { +class sbn::BNBRetriever : public art::EDProducer { public: - explicit Retriever(fhicl::ParameterSet const& p); + explicit BNBRetriever(fhicl::ParameterSet const& p); // The compiler-generated destructor is fine for non-base // classes without bare pointers or other resource use. // Plugins should not be copied or assigned. - Retriever(Retriever const&) = delete; - Retriever(Retriever&&) = delete; - Retriever& operator=(Retriever const&) = delete; - Retriever& operator=(Retriever&&) = delete; + BNBRetriever(BNBRetriever const&) = delete; + BNBRetriever(BNBRetriever&&) = delete; + BNBRetriever& operator=(BNBRetriever const&) = delete; + BNBRetriever& operator=(BNBRetriever&&) = delete; // Required functions. void produce(art::Event& e) override; @@ -64,7 +64,7 @@ class sbn::Retriever : public art::EDProducer { private: // input labels - std::vector< sbn::BeamSpillInfo > fOutbeamInfos; + std::vector< sbn::BNBSpillInfo > fOutbeamInfos; int fTimePad; std::string fURL; MWRData mwrdata; @@ -73,44 +73,40 @@ class sbn::Retriever : public art::EDProducer { art::ServiceHandle ifbeam_handle; std::unique_ptr bfp; std::unique_ptr bfp_mwr; + int TotalBeamSpills; + }; -sbn::Retriever::Retriever(fhicl::ParameterSet const& p) +sbn::BNBRetriever::BNBRetriever(fhicl::ParameterSet const& p) : EDProducer{p}, fTimePad(p.get("TimePadding",0.0333)), //seconds raw_data_label_(p.get("raw_data_label")), bfp( ifbeam_handle->getBeamFolder(p.get< std::string >("Bundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))), bfp_mwr( ifbeam_handle->getBeamFolder(p.get< std::string >("MultiWireBundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))) { - bfp->set_epsilon(0.0333); // how close in time does the spill time have to be from the DAQ time (in seconds). + + //bfp->set_epsilon(0.0333); // how close in time does the spill time have to be from the DAQ time (in seconds). + + bfp->set_epsilon(0.02); // how close in time does the spill time have to be from the DAQ time (in seconds). bfp_mwr->set_epsilon(100); // how close in time does the spill time have to be from the DAQ time (in seconds). - produces< std::vector< sbn::BeamSpillInfo >, art::InSubRun >(); - + produces< std::vector< sbn::BNBSpillInfo >, art::InSubRun >(); + TotalBeamSpills = 0; } -void sbn::Retriever::produce(art::Event& e) +void sbn::BNBRetriever::produce(art::Event& e) { - - //Get the time of the event and the previous event - // time since epoch sec . nanoseconds - //1616202843.932767280 - //.932767280 - //.030000000 int gate_type = 0; art::Handle< std::vector > raw_data_ptr; e.getByLabel(raw_data_label_, "ICARUSTriggerUDP", raw_data_ptr); auto const & raw_data = (*raw_data_ptr); - - // double t_previous_event = 1616202844.932767280; - // double t_current_event = 1616202843.932767280; - double t_previous_event = 0; double t_current_event = 0; - std::cout << "This many raw_datums : " << raw_data.size() << std::endl; + double number_of_gates_since_previous_event = 0; + for(auto raw_datum : raw_data){ uint64_t artdaq_ts = raw_datum.timestamp(); @@ -119,11 +115,8 @@ void sbn::Retriever::produce(art::Event& e) char *buffer = const_cast(data.c_str()); icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerString(buffer); gate_type = datastream_info.gate_type; - double delta_gates = frag.getDeltaGatesBNB(); - std::cout << "Gate_type: " << gate_type << std::endl; - if(gate_type == 1) - std::cout << "Number of beam gates since the last spill of this type: " << delta_gates << std::endl; - std::cout << "Fragment timestamp: " << artdaq_ts << std::endl; + number_of_gates_since_previous_event = frag.getDeltaGatesBNB(); + t_current_event = static_cast(artdaq_ts)/(1000000000); //check this offset... if(gate_type == 1) t_previous_event = (static_cast(frag.getLastTimestampBNB()))/(1e9); @@ -134,18 +127,17 @@ void sbn::Retriever::produce(art::Event& e) std::cout << std::setprecision(19) << "Previous : " << t_previous_event << ", Current : " << t_current_event << std::endl; - //if(t_previous_event == t_current_event) continue; - if(gate_type == 1) { - std::cout << "Is BNB event! Extracting POT!" << std::endl; + TotalBeamSpills += number_of_gates_since_previous_event; + try{ double test_curr; double test_t1; bfp->GetNamedData((t_previous_event)-fTimePad,"E:THCURR",&test_curr,&test_t1); std::cout << "got values " << test_curr << "for E:THCURR at time " << test_t1 << "\n"; } catch (WebAPIException &we) { - std::cout << "got exception: " << we.what() << "\n"; + } std::cout.precision(17); @@ -181,40 +173,43 @@ void sbn::Retriever::produce(art::Event& e) //var - > E:M875BB{888:888}.RAW t_mwr = 0; - std::vector packed_M876BB = bfp_mwr->GetNamedVector((t_previous_event)-35,vars[i],&t_mwr); - - packed_data_str.clear(); - packed_data_str += std::to_string(int(t_mwr)); - packed_data_str.append(","); - packed_data_str.append(vars[i]); - packed_data_str.append(",,"); - for(int j = 0; j < int(packed_M876BB.size()); j++){ - packed_data_str += std::to_string(int(packed_M876BB[j])); - if(j < int(packed_M876BB.size())-1) - packed_data_str.append(","); - } - - // std::cout << packed_data_str << std::endl; - - auto unpacked_M876BB_str_temp = mwrdata.unpackMWR(packed_data_str,long(-35)); - unpacked_M876BB_str.insert(unpacked_M876BB_str.end(), - unpacked_M876BB_str_temp.begin(), + try{ + std::vector packed_M876BB = bfp_mwr->GetNamedVector((t_previous_event)-35,vars[i],&t_mwr); + + packed_data_str.clear(); + packed_data_str += std::to_string(int(t_mwr)); + packed_data_str.append(","); + packed_data_str.append(vars[i]); + packed_data_str.append(",,"); + + for(int j = 0; j < int(packed_M876BB.size()); j++){ + packed_data_str += std::to_string(int(packed_M876BB[j])); + if(j < int(packed_M876BB.size())-1) + packed_data_str.append(","); + } + + auto unpacked_M876BB_str_temp = mwrdata.unpackMWR(packed_data_str,long(-35)); + unpacked_M876BB_str.insert(unpacked_M876BB_str.end(), + unpacked_M876BB_str_temp.begin(), unpacked_M876BB_str_temp.end()); + + } + catch (WebAPIException &we) { + + } - - //std::cout << int(unpacked_M876BB_str.size()) << " unpacked datas ... " << std::endl; } - - //for(int j = 0; j < int(unpacked_M876BB_str.size()); j++){ - // std::cout << unpacked_M876BB_str[j] << std::endl; - //} - std::vector times_temps = bfp->GetTimeList(); + std::vector times_temps = bfp->GetTimeList("E:TOR860"); +int spill_count = 0; for (size_t i = 0; i < times_temps.size(); i++) { - if(times_temps[i] > (t_current_event+fTimePad)){break;} - + + if(times_temps[i] > (t_current_event+fTimePad)){continue;} + if(times_temps[i] <= (t_previous_event-fTimePad)){continue;} + + spill_count++; double TOR860 = 0; double TOR875 = 0; double LM875A = 0; @@ -230,14 +225,25 @@ void sbn::Retriever::produce(art::Event& e) double THCURR = 0; double TOR860_time = 0; - - bfp->GetNamedData(times_temps[i], "E:TOR860@,E:TOR875,E:LM875A,E:LM875B,E:LM875C,E:HP875,E:VP875,E:HPTG1,E:VPTG1,E:HPTG2,E:VPTG2,E:BTJT2,E:THCURR",&TOR860,&TOR860_time,&TOR875,&LM875A,&LM875B,&LM875C,&HP875,&VP875,&HPTG1,&VPTG1,&HPTG2,&VPTG2,&BTJT2,&THCURR); - + + try{bfp->GetNamedData(times_temps[i], "E:TOR860@",&TOR860,&TOR860_time);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:TOR875",&TOR875);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:LM875A",&LM875A);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:LM875B",&LM875B);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:LM875C",&LM875C);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:HP875",&HP875);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:VP875",&VP875);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:HPTG1",&HPTG1);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:VPTG1",&VPTG1);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:HPTG2",&HPTG2);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:VPTG2",&VPTG2);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:BTJT2",&BTJT2);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:THCURR",&THCURR);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} unsigned long int time_closest_int = (int) TOR860_time; double time_closest_ns = (TOR860_time - time_closest_int)*1e9; - sbn::BeamSpillInfo beamInfo; + sbn::BNBSpillInfo beamInfo; beamInfo.TOR860 = TOR860; beamInfo.TOR875 = TOR875; beamInfo.LM875A = LM875A; @@ -258,23 +264,27 @@ void sbn::Retriever::produce(art::Event& e) } +std::cout << "Event Spills : " << spill_count << std::endl; } } -void sbn::Retriever::beginSubRun(art::SubRun& sr) +void sbn::BNBRetriever::beginSubRun(art::SubRun& sr) { return; } //____________________________________________________________________________ -void sbn::Retriever::endSubRun(art::SubRun& sr) +void sbn::BNBRetriever::endSubRun(art::SubRun& sr) { - auto p = std::make_unique< std::vector< sbn::BeamSpillInfo > >(fOutbeamInfos); +std::cout << "Total number of DAQ Spills : " << TotalBeamSpills << std::endl; +std::cout << "Total number of Selected Spills : " << fOutbeamInfos.size() << std::endl; + + auto p = std::make_unique< std::vector< sbn::BNBSpillInfo > >(fOutbeamInfos); sr.put(std::move(p)); return; } -DEFINE_ART_MODULE(sbn::Retriever) +DEFINE_ART_MODULE(sbn::BNBRetriever) diff --git a/sbncode/BeamSpillInfoRetriever/Retriever/CMakeLists.txt b/sbncode/BeamSpillInfoRetriever/BNBRetriever/CMakeLists.txt similarity index 91% rename from sbncode/BeamSpillInfoRetriever/Retriever/CMakeLists.txt rename to sbncode/BeamSpillInfoRetriever/BNBRetriever/CMakeLists.txt index 6e7464b9a..c01903bdb 100644 --- a/sbncode/BeamSpillInfoRetriever/Retriever/CMakeLists.txt +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/CMakeLists.txt @@ -7,12 +7,12 @@ cet_find_library( IFBEAMSERVICE NAMES IFBeam_service PATHS ENV IFDH_AR cet_find_library( IFBEAM NAMES ifbeam PATHS ENV IFBEAM_LIB NO_DEFAULT_PATH ) art_make_library( - LIBRARY_NAME sbn_BeamSpillInfoRetriever_MWRData + LIBRARY_NAME sbn_BNBSpillInfoRetriever_MWRData SOURCE MWRData.cpp ) -simple_plugin(Retriever module +simple_plugin(BNBRetriever module ${ART_FRAMEWORK_CORE} ${ART_FRAMEWORK_SERVICES_REGISTRY} ${ART_ROOT_IO_TFILESERVICE_SERVICE} ${ART_FRAMEWORK_SERVICES} @@ -36,7 +36,7 @@ simple_plugin(Retriever module sbndaq-artdaq-core_Overlays sbndaq-artdaq-core_Overlays_ICARUS artdaq-core_Utilities - sbn_BeamSpillInfoRetriever_MWRData + sbn_BNBSpillInfoRetriever_MWRData ) install_headers() diff --git a/sbncode/BeamSpillInfoRetriever/Retriever/MWRData.cpp b/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.cpp similarity index 100% rename from sbncode/BeamSpillInfoRetriever/Retriever/MWRData.cpp rename to sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.cpp diff --git a/sbncode/BeamSpillInfoRetriever/Retriever/MWRData.h b/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.h similarity index 100% rename from sbncode/BeamSpillInfoRetriever/Retriever/MWRData.h rename to sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.h diff --git a/sbncode/BeamSpillInfoRetriever/CMakeLists.txt b/sbncode/BeamSpillInfoRetriever/CMakeLists.txt index 8cc6b80ae..fb0e63163 100644 --- a/sbncode/BeamSpillInfoRetriever/CMakeLists.txt +++ b/sbncode/BeamSpillInfoRetriever/CMakeLists.txt @@ -1,4 +1,4 @@ -add_subdirectory(Retriever) +add_subdirectory(BNBRetriever) add_subdirectory(job) link_directories( diff --git a/sbncode/BeamSpillInfoRetriever/Retriever/#Retriever_module.cc# b/sbncode/BeamSpillInfoRetriever/Retriever/#Retriever_module.cc# deleted file mode 100644 index 1e5c01487..000000000 --- a/sbncode/BeamSpillInfoRetriever/Retriever/#Retriever_module.cc# +++ /dev/null @@ -1,302 +0,0 @@ -//////////////////////////////////////////////////////////////////////// -// Class: Retriever -// Plugin Type: producer -// File: Retriever_module.cc -// -// Created by hand Wed April 9 2021 by J. Zennamo (FNAL) -// Based heavily on code by Z. Pavlovic written for MicroBooNE -// Based heavily on code by NOvA collaboration (Thanks NOvA!): -// https://cdcvs.fnal.gov/redmine/projects/novaart/repository/entry/trunk/IFDBSpillInfo/BNBInfo_module.cc -//////////////////////////////////////////////////////////////////////// - -#include "art/Framework/Core/EDProducer.h" -#include "art/Framework/Core/ModuleMacros.h" -#include "art/Framework/Principal/Event.h" -#include "art/Framework/Principal/Handle.h" -#include "art/Framework/Principal/Run.h" -#include "art/Framework/Principal/SubRun.h" -#include "canvas/Utilities/InputTag.h" -#include "fhiclcpp/ParameterSet.h" -#include "messagefacility/MessageLogger/MessageLogger.h" -#include "lardata/Utilities/AssociationUtil.h" -#include "lardataobj/Utilities/sparse_vector.h" -#include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" -#include "larcorealg/Geometry/Exceptions.h" - -#include "artdaq-core/Data/Fragment.hh" - -#include "lardataalg/DetectorInfo/DetectorPropertiesStandard.h" -#include "lardata/DetectorInfoServices/DetectorPropertiesService.h" -#include "sbnobj/Common/POTAccounting/BeamSpillInfo.h" - -#include "IFBeam_service.h" -#include "ifbeam_c.h" -#include "MWRData.h" - -#include -#include -#include -#include -#include -#include - -namespace sbn { - class Retriever; -} - -class sbn::Retriever : public art::EDProducer { -public: - explicit Retriever(fhicl::ParameterSet const& p); - // The compiler-generated destructor is fine for non-base - // classes without bare pointers or other resource use. - - // Plugins should not be copied or assigned. - Retriever(Retriever const&) = delete; - Retriever(Retriever&&) = delete; - Retriever& operator=(Retriever const&) = delete; - Retriever& operator=(Retriever&&) = delete; - - // Required functions. - void produce(art::Event& e) override; - void beginSubRun(art::SubRun& sr); - void endSubRun(art::SubRun& sr); - -private: - // input labels - std::vector< sbn::BeamSpillInfo > fOutbeamInfos; - int fTimePad; - std::string fURL; - MWRData mwrdata; - std::string raw_data_label_; - - art::ServiceHandle ifbeam_handle; - std::unique_ptr bfp; - std::unique_ptr bfp_mwr; - -}; - - -sbn::Retriever::Retriever(fhicl::ParameterSet const& p) - : EDProducer{p}, - fTimePad(p.get("TimePadding",0.0333)), //seconds - raw_data_label_(p.get("raw_data_label")), - bfp( ifbeam_handle->getBeamFolder(p.get< std::string >("Bundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))), - bfp_mwr( ifbeam_handle->getBeamFolder(p.get< std::string >("MultiWireBundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))) -{ - bfp->set_epsilon(0.0333); // how close in time does the spill time have to be from the DAQ time (in seconds). - bfp_mwr->set_epsilon(100); // how close in time does the spill time have to be from the DAQ time (in seconds). - produces< std::vector< sbn::BeamSpillInfo >, art::InSubRun >(); - -} - -void sbn::Retriever::produce(art::Event& e) -{ - - //Get the time of the event and the previous event - // time since epoch sec . nanoseconds - //1616202843.932767280 - //.932767280 - //.030000000 - - - art::Handle< std::vector > raw_data_ptr; - e.getByLabel(raw_data_label_, "ICARUSTriggerUDP", raw_data_ptr); - auto const & raw_data = (*raw_data_ptr); - - auto fragment = raw_data[0]; - const char* buffer = fragment.dataBeginBytes(); - size_t pos = 0; - std::string delimiter = ","; - std::vector sections; - std::string token = ""; - while ((pos = data_input.find(delimiter)) != std::string::npos) { - token = data_input.substr(0, pos); - sections.push_back(token); - data_input.erase(0, pos + delimiter.length()); - } - sections.push_back(data_input); - //std::string trig_name = sections[0]; - name = sections[0]; - //t->setHardwareTS_Type(sections[0]); - event_no = std::stol(sections[1]); - seconds = std::stoi(sections[2]); - nanoseconds = std::stol(sections[3]); - if(sections.size() > 5) - { - wr_name = sections[4]; - wr_event_no = std::stol(sections[5]); - wr_seconds = std::stol(sections[6]); - wr_nanoseconds = std::stol(sections[7]); - gate_id = std::stol(sections[9]); - gate_type = std::stoi(sections[11]); - } - - - - - - // double t_previous_event = 1616202844.932767280; - // double t_current_event = 1616202843.932767280; - - double t_previous_event = 0; - double t_current_event = 0; - std::cout << "This many raw_datums : " << raw_data.size() << std::endl; - for(auto raw_datum : raw_data){ - - uint64_t artdaq_ts = fragment.timestamp(); - icarus::ICARUSTriggerUDPFragment frag(fragment); - std::string data = frag.GetDataString(); - char *buffer = const_cast(data.c_str()); - icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerString(buffer); - int gate_type = datastream_info.gate_type; - if(gate_type != 1) continue; - - t_current_event = datastream_info.getNanoseconds_since_UTC_epoch() + 2; //check this offset... - t_previous_event = frag.getLastTimestampBNB(); - - } - - std::cout << "Previous : " << t_previous_event << ", Current : " << t_current_event << std::endl; - - if(t_previous_event == t_current_event) return -1; - - - try{ - double test_curr; double test_t1; - bfp->GetNamedData((t_previous_event)-fTimePad,"E:THCURR",&test_curr,&test_t1); - std::cout << "got values " << test_curr << "for E:THCURR at time " << test_t1 << "\n"; - } - catch (WebAPIException &we) { - std::cout << "got exception: " << we.what() << "\n"; - } - std::cout.precision(17); - - - try{ - auto packed_M876BB_temp = bfp_mwr->GetNamedVector((t_previous_event)-35,"E:M875BB{4440:888}.RAW"); - } - catch (WebAPIException &we) { - //we have to have this or it doesn't work... - } - - // bfp_mwr->setValidWindow(86400); - //std::cout << "Is this a valid Window " << bfp_mwr->getValidWindow()< > unpacked_M876BB_str; - // unpacked_M876BB_str.resize(3); - std::vector unpacked_M876BB_str; - std::string packed_data_str; - // int dev = 0; - std::vector vars = bfp_mwr->GetDeviceList(); - double t_mwr; - std::cout << int(vars.size()) << " MWR Devices " << std::endl; - for (int i = 0; i < int(vars.size()); i++) { - if(vars[i].empty()) continue; - - /// Check the device name and interate the double-vector index - // if(vars[i].M875BB) dev = 0; - //M876BB; - //MMBTBB; - //std::cout << vars[i] << std::endl; - - - //var - > E:M875BB{888:888}.RAW - t_mwr = 0; - std::vector packed_M876BB = bfp_mwr->GetNamedVector((t_previous_event)-35,vars[i],&t_mwr); - - packed_data_str.clear(); - packed_data_str += std::to_string(int(t_mwr)); - packed_data_str.append(","); - packed_data_str.append(vars[i]); - packed_data_str.append(",,"); - - for(int j = 0; j < int(packed_M876BB.size()); j++){ - packed_data_str += std::to_string(int(packed_M876BB[j])); - if(j < int(packed_M876BB.size())-1) - packed_data_str.append(","); - } - - // std::cout << packed_data_str << std::endl; - - auto unpacked_M876BB_str_temp = mwrdata.unpackMWR(packed_data_str,long(-35)); - unpacked_M876BB_str.insert(unpacked_M876BB_str.end(), - unpacked_M876BB_str_temp.begin(), - unpacked_M876BB_str_temp.end()); - - - std::cout << int(unpacked_M876BB_str.size()) << " unpacked datas ... " << std::endl; - } - - //for(int j = 0; j < int(unpacked_M876BB_str.size()); j++){ - // std::cout << unpacked_M876BB_str[j] << std::endl; - //} - - - std::vector times_temps = bfp->GetTimeList(); - for (size_t i = 0; i < times_temps.size(); i++) { - if(times_temps[i] > (t_current_event+fTimePad)){break;} - - double TOR860 = 0; - double TOR875 = 0; - double LM875A = 0; - double LM875B = 0; - double LM875C = 0; - double HP875 = 0; - double VP875 = 0; - double HPTG1 = 0; - double VPTG1 = 0; - double HPTG2 = 0; - double VPTG2 = 0; - double BTJT2 = 0; - double THCURR = 0; - - double TOR860_time = 0; - - bfp->GetNamedData(times_temps[i], "E:TOR860@,E:TOR875,E:LM875A,E:LM875B,E:LM875C,E:HP875,E:VP875,E:HPTG1,E:VPTG1,E:HPTG2,E:VPTG2,E:BTJT2,E:THCURR",&TOR860,&TOR860_time,&TOR875,&LM875A,&LM875B,&LM875C,&HP875,&VP875,&HPTG1,&VPTG1,&HPTG2,&VPTG2,&BTJT2,&THCURR); - - - unsigned long int time_closest_int = (int) TOR860_time; - double time_closest_ns = (TOR860_time - time_closest_int)*1e9; - - sbn::BeamSpillInfo beamInfo; - beamInfo.TOR860 = TOR860; - beamInfo.TOR875 = TOR875; - beamInfo.LM875A = LM875A; - beamInfo.LM875B = LM875B; - beamInfo.LM875C = LM875C; - beamInfo.HP875 = HP875; - beamInfo.VP875 = VP875; - beamInfo.HPTG1 = HPTG1; - beamInfo.VPTG1 = VPTG1; - beamInfo.HPTG2 = HPTG2; - beamInfo.VPTG2 = VPTG2; - beamInfo.BTJT2 = BTJT2; - beamInfo.THCURR = THCURR; - beamInfo.spill_time_s = time_closest_int; - beamInfo.spill_time_ns = time_closest_ns; - - fOutbeamInfos.push_back(beamInfo); - - - } - -} - -void sbn::Retriever::beginSubRun(art::SubRun& sr) -{ - return; -} - -//____________________________________________________________________________ -void sbn::Retriever::endSubRun(art::SubRun& sr) -{ - - auto p = std::make_unique< std::vector< sbn::BeamSpillInfo > >(fOutbeamInfos); - - sr.put(std::move(p)); - - return; -} - -DEFINE_ART_MODULE(sbn::Retriever) diff --git a/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module_brokeit.cc b/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module_brokeit.cc deleted file mode 100644 index 0ef5edcae..000000000 --- a/sbncode/BeamSpillInfoRetriever/Retriever/Retriever_module_brokeit.cc +++ /dev/null @@ -1,242 +0,0 @@ -//////////////////////////////////////////////////////////////////////// -// Class: Retriever -// Plugin Type: producer -// File: Retriever_module.cc -// -// Created by hand Wed April 9 2021 by J. Zennamo (FNAL) -// Based heavily on code by Z. Pavlovic written for MicroBooNE -// Based heavily on code by NOvA collaboration (Thanks NOvA!): -// https://cdcvs.fnal.gov/redmine/projects/novaart/repository/entry/trunk/IFDBSpillInfo/BNBInfo_module.cc -//////////////////////////////////////////////////////////////////////// - -#include "art/Framework/Core/EDProducer.h" -#include "art/Framework/Core/ModuleMacros.h" -#include "art/Framework/Principal/Event.h" -#include "artdaq-core/Data/Fragment.hh" -#include "art/Framework/Principal/Handle.h" -#include "art/Framework/Principal/Run.h" -#include "art/Framework/Principal/SubRun.h" -#include "canvas/Utilities/InputTag.h" -#include "fhiclcpp/ParameterSet.h" -#include "messagefacility/MessageLogger/MessageLogger.h" -#include "lardata/Utilities/AssociationUtil.h" -#include "lardataobj/Utilities/sparse_vector.h" -#include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" -#include "larcorealg/Geometry/Exceptions.h" - -#include "lardataalg/DetectorInfo/DetectorPropertiesStandard.h" -#include "lardata/DetectorInfoServices/DetectorPropertiesService.h" -#include "sbnobj/Common/POTAccounting/BeamSpillInfo.h" - -#include "IFBeam_service.h" -#include "ifbeam_c.h" -#include "MWRData.h" - -#include -#include -#include -#include -#include -#include - -namespace sbn { - class Retriever; -} - -class sbn::Retriever : public BNBRetriever { -public: - explicit Retriever(fhicl::ParameterSet const& p); - // The compiler-generated destructor is fine for non-base - // classes without bare pointers or other resource use. - - // Plugins should not be copied or assigned. - Retriever(Retriever const&) = delete; - Retriever(Retriever&&) = delete; - Retriever& operator=(Retriever const&) = delete; - Retriever& operator=(Retriever&&) = delete; - - // Required functions. - void produces(art::ProducesCollector&); - void process_fragment(const artdaq::Fragment &fragment); - void beginSubRun(art::SubRun& sr); - void endSubRun(art::SubRun& sr); - -private: - // input labels - std::vector< sbn::BeamSpillInfo > fOutbeamInfos; - int fTimePad; - std::string fURL; - MWRData mwrdata; - - art::ServiceHandle ifbeam_handle; - std::unique_ptr bfp; - std::unique_ptr bfp_mwr; - -}; - - -sbn::Retriever::Retriever(fhicl::ParameterSet const& p) - : EDProducer{p}, - fTimePad(p.get("TimePadding",0.0333)), //seconds - bfp( ifbeam_handle->getBeamFolder(p.get< std::string >("Bundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))), - bfp_mwr( ifbeam_handle->getBeamFolder(p.get< std::string >("MultiWireBundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))) -{ - bfp->set_epsilon(0.0333); // how close in time does the spill time have to be from the DAQ time (in seconds). - bfp_mwr->set_epsilon(100); // how close in time does the spill time have to be from the DAQ time (in seconds). - // produces< std::vector< sbn::BeamSpillInfo >, art::InSubRun >(); - -} - -void sbn::Retriever::produces(art::ProducesCollector& collector) -{ - collector.produces< std::vector< sbn::BeamSpillInfo >, art::InSubRun >(); -} - -void sbn::Retriever::process_fragment(const artdaq::Fragment &fragment) -{ - //Get the time of the event and the previous event - // time since epoch sec . nanoseconds - //1616202843.932767280 - //.932767280 - //.030000000 - double t_previous_event = 1616202844.932767280; - double t_current_event = 1616202843.932767280; - - try{ - double test_curr; double test_t1; - bfp->GetNamedData((t_previous_event)-fTimePad,"E:THCURR",&test_curr,&test_t1); - std::cout << "got values " << test_curr << "for E:THCURR at time " << test_t1 << "\n"; - } - catch (WebAPIException &we) { - std::cout << "got exception: " << we.what() << "\n"; - } - std::cout.precision(17); - - - try{ - auto packed_M876BB_temp = bfp_mwr->GetNamedVector((t_previous_event)-35,"E:M875BB{4440:888}.RAW"); - } - catch (WebAPIException &we) { - //we have to have this or it doesn't work... - } - - // bfp_mwr->setValidWindow(86400); - //std::cout << "Is this a valid Window " << bfp_mwr->getValidWindow()< unpacked_M876BB_str; - // unpacked_M876BB_str.resize(3); - std::string packed_data_str; - //int dev = 0; - std::vector vars = bfp_mwr->GetDeviceList(); - double t_mwr; - std::cout << int(vars.size()) << " MWR Devices " << std::endl; - for (int i = 0; i < int(vars.size()); i++) { - if(vars[i].empty()) continue; - - /// Check the device name and interate the double-vector index - // if(vars[i].M875BB) dev = 0; - // M876BB; - // MMBTBB; - std::cout << vars[i] << std::endl; - - - //var - > E:M875BB{888:888}.RAW - t_mwr = 0; - std::vector packed_M876BB = bfp_mwr->GetNamedVector((t_previous_event)-35,vars[i],&t_mwr); - - packed_data_str.clear(); - packed_data_str += std::to_string(int(t_mwr)); - packed_data_str.append(","); - packed_data_str.append(vars[i]); - packed_data_str.append(",,"); - - for(int j = 0; j < int(packed_M876BB.size()); j++){ - packed_data_str += std::to_string(int(packed_M876BB[j])); - if(j < int(packed_M876BB.size())-1) - packed_data_str.append(","); - } - - // std::cout << packed_data_str << std::endl; - - auto unpacked_M876BB_str_temp = mwrdata.unpackMWR(packed_data_str,long(-35)); - unpacked_M876BB_str.insert(unpacked_M876BB_str.end(), - unpacked_M876BB_str_temp.begin(), - unpacked_M876BB_str_temp.end()); - - - std::cout << int(unpacked_M876BB_str.size()) << " unpacked datas ... " << std::endl; - } - - for(int j = 0; j < int(unpacked_M876BB_str.size()); j++){ - std::cout << unpacked_M876BB_str[j] << std::endl; - } - - - std::vector times_temps = bfp->GetTimeList(); - for (size_t i = 0; i < times_temps.size(); i++) { - if(times_temps[i] > (t_current_event+fTimePad)){break;} - - double TOR860 = 0; - double TOR875 = 0; - double LM875A = 0; - double LM875B = 0; - double LM875C = 0; - double HP875 = 0; - double VP875 = 0; - double HPTG1 = 0; - double VPTG1 = 0; - double HPTG2 = 0; - double VPTG2 = 0; - double BTJT2 = 0; - double THCURR = 0; - - double TOR860_time = 0; - - bfp->GetNamedData(times_temps[i], "E:TOR860@,E:TOR875,E:LM875A,E:LM875B,E:LM875C,E:HP875,E:VP875,E:HPTG1,E:VPTG1,E:HPTG2,E:VPTG2,E:BTJT2,E:THCURR",&TOR860,&TOR860_time,&TOR875,&LM875A,&LM875B,&LM875C,&HP875,&VP875,&HPTG1,&VPTG1,&HPTG2,&VPTG2,&BTJT2,&THCURR); - - - unsigned long int time_closest_int = (int) TOR860_time; - double time_closest_ns = (TOR860_time - time_closest_int)*1e9; - - sbn::BeamSpillInfo beamInfo; - beamInfo.TOR860 = TOR860; - beamInfo.TOR875 = TOR875; - beamInfo.LM875A = LM875A; - beamInfo.LM875B = LM875B; - beamInfo.LM875C = LM875C; - beamInfo.HP875 = HP875; - beamInfo.VP875 = VP875; - beamInfo.HPTG1 = HPTG1; - beamInfo.VPTG1 = VPTG1; - beamInfo.HPTG2 = HPTG2; - beamInfo.VPTG2 = VPTG2; - beamInfo.BTJT2 = BTJT2; - beamInfo.THCURR = THCURR; - beamInfo.spill_time_s = time_closest_int; - beamInfo.spill_time_ns = time_closest_ns; - - fOutbeamInfos.push_back(beamInfo); - - - } - -} - -void sbn::Retriever::beginSubRun(art::SubRun& sr) -{ - return; -} - -//____________________________________________________________________________ -void sbn::Retriever::endSubRun(art::SubRun& sr) -{ - - auto p = std::make_unique< std::vector< sbn::BeamSpillInfo > >(fOutbeamInfos); - - sr.put(std::move(p)); - - return; -} - -DEFINE_ART_MODULE(sbn::Retriever) diff --git a/sbncode/BeamSpillInfoRetriever/job/beamspillinfo.fcl b/sbncode/BeamSpillInfoRetriever/job/bnbspillinfo.fcl similarity index 85% rename from sbncode/BeamSpillInfoRetriever/job/beamspillinfo.fcl rename to sbncode/BeamSpillInfoRetriever/job/bnbspillinfo.fcl index f727754e5..e962752b3 100644 --- a/sbncode/BeamSpillInfoRetriever/job/beamspillinfo.fcl +++ b/sbncode/BeamSpillInfoRetriever/job/bnbspillinfo.fcl @@ -1,9 +1,9 @@ BEGIN_PROLOG -beamspillinfo: { +bnbspillinfo: { - module_type: "Retriever" + module_type: "BNBRetriever" TimePadding: 0.0333 #unit seconds, Booster Rep Rate is 15 Hz, so the closest spill could be 66ms away URL: "" #keep this blank and we're good Bundle: "BoosterNeutrinoBeam_read" diff --git a/sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl b/sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl new file mode 100644 index 000000000..ec744270e --- /dev/null +++ b/sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl @@ -0,0 +1,33 @@ +#include "bnbspillinfo.fcl" + +process_name: BNBInfoGen + +services:{ + IFBeam:{} +} + + +source: { + module_type: RootInput +} + +physics: { + producers: { + bnbinfo: @local::bnbspillinfo + } + + simulate: [bnbinfo ] + stream1: [ out1 ] + trigger_paths: [ simulate ] + end_paths: [ stream1 ] +} + +outputs: { + out1: { + module_type: RootOutput + fileName: "%ifb_%tc_bnbinfo.root" + dataTier: "raw" + compressionLevel: 1 + } +} + From 2c7f2e3d10187983b67e4eaf95a9ea864bc60183 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Thu, 17 Jun 2021 14:18:21 -0500 Subject: [PATCH 08/46] fixed name --- sbncode/BeamSpillInfoRetriever/job/bnbspillinfo.fcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbncode/BeamSpillInfoRetriever/job/bnbspillinfo.fcl b/sbncode/BeamSpillInfoRetriever/job/bnbspillinfo.fcl index e962752b3..fd2d4a11a 100644 --- a/sbncode/BeamSpillInfoRetriever/job/bnbspillinfo.fcl +++ b/sbncode/BeamSpillInfoRetriever/job/bnbspillinfo.fcl @@ -10,6 +10,6 @@ bnbspillinfo: { MultiWireBundle: "BNBMultiWire" TimeWindow: "500" #seconds raw_data_label: "daq" - + DeviceUsedForTiming: "E:TOR860" } END_PROLOG From d84074908d37c90afa332505e6aab7bb6a75f34a Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Thu, 17 Jun 2021 14:18:36 -0500 Subject: [PATCH 09/46] added comments --- .../BNBRetriever/BNBRetriever_module.cc | 154 +++++++++++------- 1 file changed, 92 insertions(+), 62 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 17ad8214c..58aceef4e 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -69,11 +69,13 @@ class sbn::BNBRetriever : public art::EDProducer { std::string fURL; MWRData mwrdata; std::string raw_data_label_; - + std::string fDeviceUsedForTiming; + int TotalBeamSpills; + // art::ServiceHandle ifbeam_handle; std::unique_ptr bfp; std::unique_ptr bfp_mwr; - int TotalBeamSpills; + }; @@ -83,14 +85,17 @@ sbn::BNBRetriever::BNBRetriever(fhicl::ParameterSet const& p) : EDProducer{p}, fTimePad(p.get("TimePadding",0.0333)), //seconds raw_data_label_(p.get("raw_data_label")), + fDeviceUsedForTiming(p.get("DeviceUsedForTiming")), bfp( ifbeam_handle->getBeamFolder(p.get< std::string >("Bundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))), bfp_mwr( ifbeam_handle->getBeamFolder(p.get< std::string >("MultiWireBundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))) { - //bfp->set_epsilon(0.0333); // how close in time does the spill time have to be from the DAQ time (in seconds). - - bfp->set_epsilon(0.02); // how close in time does the spill time have to be from the DAQ time (in seconds). - bfp_mwr->set_epsilon(100); // how close in time does the spill time have to be from the DAQ time (in seconds). + // how close in time does the spill time have to be from the DAQ time (in seconds). + // If these are too large then it fails to capture the device + // If these are too small then the time jitter in devices means we miss good data + bfp->set_epsilon(0.02); //20 ms, this was tuned by hand and compared to IFBeamDB times + + bfp_mwr->set_epsilon(100); // TO BE TUNED! produces< std::vector< sbn::BNBSpillInfo >, art::InSubRun >(); TotalBeamSpills = 0; } @@ -98,13 +103,18 @@ sbn::BNBRetriever::BNBRetriever(fhicl::ParameterSet const& p) void sbn::BNBRetriever::produce(art::Event& e) { + //Here we read in the artdaq Fragments and extract three pieces of information: + // 1. The time of the current event, t_current_event + // 2. the time of the previously triggered event, t_previous_event (NOTE: Events are non-sequential!) + // 3. the number of beam spills since the previously triggered event, number_of_gates_since_previous_event + int gate_type = 0; art::Handle< std::vector > raw_data_ptr; e.getByLabel(raw_data_label_, "ICARUSTriggerUDP", raw_data_ptr); auto const & raw_data = (*raw_data_ptr); - double t_previous_event = 0; double t_current_event = 0; + double t_previous_event = 0; double number_of_gates_since_previous_event = 0; for(auto raw_datum : raw_data){ @@ -126,35 +136,28 @@ void sbn::BNBRetriever::produce(art::Event& e) } std::cout << std::setprecision(19) << "Previous : " << t_previous_event << ", Current : " << t_current_event << std::endl; - + + //We only want to process BNB gates, i.e. type 1 if(gate_type == 1) { + // Keep track of the number of beam gates the DAQ thinks + // are in this file TotalBeamSpills += number_of_gates_since_previous_event; - try{ - double test_curr; double test_t1; - bfp->GetNamedData((t_previous_event)-fTimePad,"E:THCURR",&test_curr,&test_t1); - std::cout << "got values " << test_curr << "for E:THCURR at time " << test_t1 << "\n"; - } - catch (WebAPIException &we) { - - } - std::cout.precision(17); - - - try{ - auto packed_M876BB_temp = bfp_mwr->GetNamedVector((t_previous_event)-35,"E:M875BB{4440:888}.RAW"); - } - catch (WebAPIException &we) { - //we have to have this or it doesn't work... - } + // These lines get everything primed within the IFBeamDB + // They seem redundant but they are needed + try{auto cur_vec_temp = bfp->GetNamedVector((t_previous_event)-fTimePad,"E:THCURR");} catch (WebAPIException &we) {} + try{auto packed_M876BB_temp = bfp_mwr->GetNamedVector((t_previous_event)-35,"E:M875BB{4440:888}.RAW");} catch (WebAPIException &we) {} + + + // I have to FIX the MultiWireReadouts to....work... // bfp_mwr->setValidWindow(86400); //std::cout << "Is this a valid Window " << bfp_mwr->getValidWindow()< > unpacked_M876BB_str; - // unpacked_M876BB_str.resize(3); + // std::vector< std::vector > unpacked_M876BB_str; + // unpacked_M876BB_str.resize(3); std::vector unpacked_M876BB_str; std::string packed_data_str; // int dev = 0; @@ -199,50 +202,72 @@ void sbn::BNBRetriever::produce(art::Event& e) } - } + }// Iterate over all the multiwire devices + + //Here we will start collecting all the other beamline devices + // First we get the times that the beamline device fired + // we have to pick a specific variable to use + std::vector times_temps = bfp->GetTimeList(fDeviceUsedForTiming); + + // We'll keep track of how many of these spills match to our + // DAQ trigger times + int spill_count = 0; - std::vector times_temps = bfp->GetTimeList("E:TOR860"); -int spill_count = 0; + // Iterating through each of the beamline times for (size_t i = 0; i < times_temps.size(); i++) { + // Only continue if these times are matched to our DAQ time + // plus or minus some time padding, currently using 3.3 ms + // which is half the Booster Rep Rate if(times_temps[i] > (t_current_event+fTimePad)){continue;} if(times_temps[i] <= (t_previous_event-fTimePad)){continue;} + //Great we found a matched spill! Let's count it spill_count++; - double TOR860 = 0; - double TOR875 = 0; - double LM875A = 0; - double LM875B = 0; - double LM875C = 0; - double HP875 = 0; - double VP875 = 0; - double HPTG1 = 0; - double VPTG1 = 0; - double HPTG2 = 0; - double VPTG2 = 0; - double BTJT2 = 0; - double THCURR = 0; - double TOR860_time = 0; - - try{bfp->GetNamedData(times_temps[i], "E:TOR860@",&TOR860,&TOR860_time);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:TOR875",&TOR875);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:LM875A",&LM875A);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:LM875B",&LM875B);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:LM875C",&LM875C);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:HP875",&HP875);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:VP875",&VP875);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:HPTG1",&HPTG1);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:VPTG1",&VPTG1);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:HPTG2",&HPTG2);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:VPTG2",&VPTG2);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:BTJT2",&BTJT2);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:THCURR",&THCURR);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + // initializing all of our device carriers + // device definitions can be found in BNBSpillInfo.h + + double TOR860 = 0; // units e12 protons + double TOR875 = 0; // units e12 protons + double LM875A = 0; // units R/s + double LM875B = 0; // units R/s + double LM875C = 0; // units R/s + double HP875 = 0; // units mm + double VP875 = 0; // units mm + double HPTG1 = 0; // units mm + double VPTG1 = 0; // units mm + double HPTG2 = 0; // units mm + double VPTG2 = 0; // units mm + double BTJT2 = 0; // units Deg C + double THCURR = 0; // units kiloAmps + double TOR860_time = 0; // units s + + // Here we request all the devices + // since sometimes devices fail to report we'll + // allow each to throw an exception but still move forward + // interpreting these failures will be part of the beam quality analyses + try{bfp->GetNamedData(times_temps[i], "E:TOR860@",&TOR860,&TOR860_time);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:TOR875",&TOR875);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:LM875A",&LM875A);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:LM875B",&LM875B);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:LM875C",&LM875C);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:HP875",&HP875);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:VP875",&VP875);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:HPTG1",&HPTG1);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:VPTG1",&VPTG1);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:HPTG2",&HPTG2);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:VPTG2",&VPTG2);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:BTJT2",&BTJT2);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:THCURR",&THCURR);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + + //crunch the times unsigned long int time_closest_int = (int) TOR860_time; double time_closest_ns = (TOR860_time - time_closest_int)*1e9; + //Store everything in our data-product sbn::BNBSpillInfo beamInfo; beamInfo.TOR860 = TOR860; beamInfo.TOR875 = TOR875; @@ -261,12 +286,14 @@ int spill_count = 0; beamInfo.spill_time_ns = time_closest_ns; fOutbeamInfos.push_back(beamInfo); + // We do not write these to the art::Events because + // we can filter events but want to keep all the POT + // information, so we'll write it to the SubRun - - } + }//end iteration over beam device times std::cout << "Event Spills : " << spill_count << std::endl; - } -} + } //end check if BNB DAQ triggered gate +}//end iteration over art::Events void sbn::BNBRetriever::beginSubRun(art::SubRun& sr) { @@ -276,6 +303,9 @@ void sbn::BNBRetriever::beginSubRun(art::SubRun& sr) //____________________________________________________________________________ void sbn::BNBRetriever::endSubRun(art::SubRun& sr) { + // We will add all of the BNBSpillInfo data-products to the + // art::SubRun so it persists + // currently this is ~2.7 kB/event or ~0.07 kB/spill std::cout << "Total number of DAQ Spills : " << TotalBeamSpills << std::endl; std::cout << "Total number of Selected Spills : " << fOutbeamInfos.size() << std::endl; From 9bf71bf691ff58ddba46c707af4592cce11d5372 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Mon, 21 Jun 2021 10:12:12 -0500 Subject: [PATCH 10/46] halfway to MWR info --- .../BNBRetriever/BNBRetriever_module.cc | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 58aceef4e..6dbbcabf3 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -155,30 +155,27 @@ void sbn::BNBRetriever::produce(art::Event& e) // bfp_mwr->setValidWindow(86400); //std::cout << "Is this a valid Window " << bfp_mwr->getValidWindow()< > unpacked_M876BB_str; - // unpacked_M876BB_str.resize(3); - std::vector unpacked_M876BB_str; + std::vector< std::vector > unpacked_MWR_str; + std::vector< std::vector > MWR_times; + unpacked_MWR_str.resize(3); + MWR_times.resize(3); + std::string packed_data_str; - // int dev = 0; std::vector vars = bfp_mwr->GetDeviceList(); - double t_mwr; + double time_for_mwr; std::cout << int(vars.size()) << " MWR Devices " << std::endl; for (int i = 0; i < int(vars.size()); i++) { if(vars[i].empty()) continue; /// Check the device name and interate the double-vector index - // if(vars[i].M875BB) dev = 0; - //M876BB; - //MMBTBB; - //std::cout << vars[i] << std::endl; - + if(vars[i].find("M875BB") != std::string::npos ) dev = 0; + if(vars[i].find("M876BB") != std::string::npos ) dev = 1; + if(vars[i].find("MMBTBB") != std::string::npos ) dev = 2; - //var - > E:M875BB{888:888}.RAW - t_mwr = 0; + time_for_mwr = 0; try{ - std::vector packed_M876BB = bfp_mwr->GetNamedVector((t_previous_event)-35,vars[i],&t_mwr); + std::vector packed_MWR = bfp_mwr->GetNamedVector((t_previous_event)-35,vars[i],&time_for_mwr); packed_data_str.clear(); packed_data_str += std::to_string(int(t_mwr)); @@ -186,20 +183,21 @@ void sbn::BNBRetriever::produce(art::Event& e) packed_data_str.append(vars[i]); packed_data_str.append(",,"); - for(int j = 0; j < int(packed_M876BB.size()); j++){ - packed_data_str += std::to_string(int(packed_M876BB[j])); - if(j < int(packed_M876BB.size())-1) + for(int j = 0; j < int(packed_MWR.size()); j++){ + packed_data_str += std::to_string(int(packed_MWR[j])); + if(j < int(packed_MWR.size())-1) packed_data_str.append(","); } - + + // FIXME : Need to correct the vector names and store the times auto unpacked_M876BB_str_temp = mwrdata.unpackMWR(packed_data_str,long(-35)); unpacked_M876BB_str.insert(unpacked_M876BB_str.end(), unpacked_M876BB_str_temp.begin(), - unpacked_M876BB_str_temp.end()); + unpacked_M876BB_str_temp.end()); } catch (WebAPIException &we) { - + std::cout << "got exception: " << we.what() << "\n" << std::endl; } }// Iterate over all the multiwire devices From 7a17545138eb2a79b6c44f0bdcbd227979bb50bf Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Wed, 23 Jun 2021 14:58:17 -0500 Subject: [PATCH 11/46] changed to work between with my work flow --- .../BNBRetriever/MWRData.cpp | 20 ++++++------------- .../BNBRetriever/MWRData.h | 2 +- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.cpp b/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.cpp index 66dc6a20a..e25036b3b 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.cpp +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.cpp @@ -10,11 +10,11 @@ using namespace std; namespace sbn{ -std::vector MWRData::unpackMWR(std::string packed_data, long timeoffset) + std::vector< std::vector < int > > MWRData::unpackMWR(std::string packed_data, std::vector &time_stamp, double timeoffset) { - std::vector unpacked_data; - + std::vector > unpacked_data; + unpacked_data.resize(4); short data[444]; std::vector row(0); @@ -26,21 +26,13 @@ std::vector MWRData::unpackMWR(std::string packed_data, long timeof string devname=row[1].substr(0,8); for (int idev=0;idev<4;idev++) { mwrpulse_t mwr=getMWRdata(data,idev); - std::stringstream ss; - ss<< std::to_string(mwr.sheader.timesec*1000.+mwr.sheader.timensec/1000000.+timeoffset)<<","< unpackMWR(std::string packed_data, long timeoffset=0); + std::vector< std::vector < int > > unpackMWR(std::string packed_data, std::vector &time_stamp, double timeoffset=0); }; } From 044817b81fa27840011e59c2c510f814f059e473 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Wed, 23 Jun 2021 14:58:52 -0500 Subject: [PATCH 12/46] added variable to open wider window for multiwires --- sbncode/BeamSpillInfoRetriever/job/bnbspillinfo.fcl | 1 + 1 file changed, 1 insertion(+) diff --git a/sbncode/BeamSpillInfoRetriever/job/bnbspillinfo.fcl b/sbncode/BeamSpillInfoRetriever/job/bnbspillinfo.fcl index fd2d4a11a..4959a0aaa 100644 --- a/sbncode/BeamSpillInfoRetriever/job/bnbspillinfo.fcl +++ b/sbncode/BeamSpillInfoRetriever/job/bnbspillinfo.fcl @@ -9,6 +9,7 @@ bnbspillinfo: { Bundle: "BoosterNeutrinoBeam_read" MultiWireBundle: "BNBMultiWire" TimeWindow: "500" #seconds + MWR_TimeWindow: "3601" #seconds raw_data_label: "daq" DeviceUsedForTiming: "E:TOR860" } From fe86f5da1d6f0aedfd7028137d35dac43110f992 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Wed, 23 Jun 2021 14:59:34 -0500 Subject: [PATCH 13/46] added functionality for multiwire --- .../BNBRetriever/BNBRetriever_module.cc | 188 +++++++++++++----- 1 file changed, 137 insertions(+), 51 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 6dbbcabf3..8ae15efda 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -87,7 +87,7 @@ sbn::BNBRetriever::BNBRetriever(fhicl::ParameterSet const& p) raw_data_label_(p.get("raw_data_label")), fDeviceUsedForTiming(p.get("DeviceUsedForTiming")), bfp( ifbeam_handle->getBeamFolder(p.get< std::string >("Bundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))), - bfp_mwr( ifbeam_handle->getBeamFolder(p.get< std::string >("MultiWireBundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))) + bfp_mwr( ifbeam_handle->getBeamFolder(p.get< std::string >("MultiWireBundle"), p.get< std::string >("URL"), p.get< double >("MWR_TimeWindow"))) { // how close in time does the spill time have to be from the DAQ time (in seconds). @@ -95,7 +95,8 @@ sbn::BNBRetriever::BNBRetriever(fhicl::ParameterSet const& p) // If these are too small then the time jitter in devices means we miss good data bfp->set_epsilon(0.02); //20 ms, this was tuned by hand and compared to IFBeamDB times - bfp_mwr->set_epsilon(100); // TO BE TUNED! + bfp_mwr->set_epsilon(0.5); // TO BE TUNED! + bfp_mwr->setValidWindow(86400); produces< std::vector< sbn::BNBSpillInfo >, art::InSubRun >(); TotalBeamSpills = 0; } @@ -147,60 +148,96 @@ void sbn::BNBRetriever::produce(art::Event& e) // These lines get everything primed within the IFBeamDB // They seem redundant but they are needed try{auto cur_vec_temp = bfp->GetNamedVector((t_previous_event)-fTimePad,"E:THCURR");} catch (WebAPIException &we) {} - try{auto packed_M876BB_temp = bfp_mwr->GetNamedVector((t_previous_event)-35,"E:M875BB{4440:888}.RAW");} catch (WebAPIException &we) {} + try{auto packed_M876BB_temp = bfp_mwr->GetNamedVector((t_current_event)+fTimePad,"E:M875BB{4440:888}.RAW");} catch (WebAPIException &we) {} - // I have to FIX the MultiWireReadouts to....work... - - // bfp_mwr->setValidWindow(86400); - //std::cout << "Is this a valid Window " << bfp_mwr->getValidWindow()< > unpacked_MWR_str; - std::vector< std::vector > MWR_times; - unpacked_MWR_str.resize(3); + //The multiwire chambers provide their + // data in a vector format but we'll have + // to sort through it in std::string format + // to correctly unpack it + std::vector< std::vector< std::vector< int > > > unpacked_MWR; + std::vector< std::vector< double> > MWR_times; + unpacked_MWR.resize(3); MWR_times.resize(3); - std::string packed_data_str; + + //Create a list of all the MWR devices with their different + // memory buffer increments + // generally in the format: "E:.{Memory Block}" std::vector vars = bfp_mwr->GetDeviceList(); - double time_for_mwr; - std::cout << int(vars.size()) << " MWR Devices " << std::endl; - for (int i = 0; i < int(vars.size()); i++) { - if(vars[i].empty()) continue; - - /// Check the device name and interate the double-vector index - if(vars[i].find("M875BB") != std::string::npos ) dev = 0; - if(vars[i].find("M876BB") != std::string::npos ) dev = 1; - if(vars[i].find("MMBTBB") != std::string::npos ) dev = 2; - - time_for_mwr = 0; - - try{ - std::vector packed_MWR = bfp_mwr->GetNamedVector((t_previous_event)-35,vars[i],&time_for_mwr); - - packed_data_str.clear(); - packed_data_str += std::to_string(int(t_mwr)); - packed_data_str.append(","); - packed_data_str.append(vars[i]); - packed_data_str.append(",,"); + + // Tracking the time from the IFBeamDB + double time_for_mwr; + + // this is an iterator to track which of the + // three devices we will be working with + int dev = 0; + + // The MWR devices are annoying and have confusing buffer + // what we'll do is sort through all of them first and then + // match them to the closest spills in time + // + int t_steps = int(fabs((t_previous_event - fTimePad) - (t_current_event + fTimePad))/0.5)+25; + + for(int t = 0; t < t_steps; t++){//Iterate through time increments + for (int i = 0; i < int(vars.size()); i++) {// Iterate through the devices + + //Make sure we have a device + if(vars[i].empty()) continue; - for(int j = 0; j < int(packed_MWR.size()); j++){ - packed_data_str += std::to_string(int(packed_MWR[j])); - if(j < int(packed_MWR.size())-1) - packed_data_str.append(","); - } - - // FIXME : Need to correct the vector names and store the times - auto unpacked_M876BB_str_temp = mwrdata.unpackMWR(packed_data_str,long(-35)); - unpacked_M876BB_str.insert(unpacked_M876BB_str.end(), - unpacked_M876BB_str_temp.begin(), - unpacked_M876BB_str_temp.end()); + /// Check the device name and interate the double-vector index + if(vars[i].find("M875BB") != std::string::npos ) dev = 0; + else if(vars[i].find("M876BB") != std::string::npos ) dev = 1; + else if(vars[i].find("MMBTBB") != std::string::npos ) dev = 2; + else{continue;} + + time_for_mwr = 0; - } - catch (WebAPIException &we) { - std::cout << "got exception: " << we.what() << "\n" << std::endl; - } - - }// Iterate over all the multiwire devices + try{ + //Pull the MWR data for the device + // these data are "packed" + std::vector packed_MWR = bfp_mwr->GetNamedVector((t_previous_event)-fTimePad+double(0.5*t),vars[i],&time_for_mwr); + + //We'll convert this into a format + // that we can unpack doubles >> strings + // + packed_data_str.clear(); + packed_data_str += std::to_string(int(time_for_mwr)); + packed_data_str.append(","); + packed_data_str.append(vars[i]); + packed_data_str.append(",,"); + + for(int j = 0; j < int(packed_MWR.size()); j++){ + packed_data_str += std::to_string(int(packed_MWR[j])); + if(j < int(packed_MWR.size())-1) + packed_data_str.append(","); + } + + // Use Zarko's unpacking function to turn this into consumeable data + std::vector MWR_times_temp; + + // There is a 35 ms offset between the toriod and the MWR times + // we'll just remove that here to match to the spill times + std::vector< std::vector< int > > unpacked_MWR_temp = mwrdata.unpackMWR(packed_data_str,MWR_times_temp,-0.035); + + //There are four events that are packed into one MWR IFBeam entry + for(int s = 0; s < int(unpacked_MWR_temp.size()); s++){ + + // If this entry has a unique time them store it for later + if(std::find(MWR_times[dev].begin(), MWR_times[dev].end(), MWR_times_temp[s]) == MWR_times[dev].end()){ + unpacked_MWR[dev].push_back(unpacked_MWR_temp[s]); + MWR_times[dev].push_back(MWR_times_temp[s]); + }//check for unique time + + }//Iterate through the unpacked events + }//try + catch (WebAPIException &we) { + //Ignore when we can't find the MWR devices + // they don't always report and the timing of them can be annoying + + }//catch + }// Iterate over all the multiwire devices + }// Iterate over all times //Here we will start collecting all the other beamline devices @@ -211,7 +248,9 @@ void sbn::BNBRetriever::produce(art::Event& e) // We'll keep track of how many of these spills match to our // DAQ trigger times int spill_count = 0; - + std::vector matched_MWR; + matched_MWR.resize(3); + // Iterating through each of the beamline times for (size_t i = 0; i < times_temps.size(); i++) { @@ -221,6 +260,46 @@ void sbn::BNBRetriever::produce(art::Event& e) if(times_temps[i] > (t_current_event+fTimePad)){continue;} if(times_temps[i] <= (t_previous_event-fTimePad)){continue;} + //Loop through the multiwire devices: + + for(int dev = 0; dev < int(MWR_times.size()); dev++){ + + //Loop through the multiwire times: + double Tdiff = 1000000000.; + matched_MWR[dev] = 0; + bool best_match = false; + for(int mwrt = 0; mwrt < int(MWR_times[dev].size()); mwrt++){ + + //found a candidate match! + if(fabs((MWR_times[dev][mwrt] - times_temps[i])) < Tdiff){ + best_match = true; + + //Check for a better match... + for (size_t j = 0; j < times_temps.size(); j++) { + if( j == i) continue; + if(times_temps[j] > (t_current_event+fTimePad)){continue;} + if(times_temps[j] <= (t_previous_event-fTimePad)){continue;} + + //is there a better match later in the spill sequence + if(fabs((MWR_times[dev][mwrt] - times_temps[j])) < + fabs((MWR_times[dev][mwrt] - times_temps[i]))){ + //we can have patience... + best_match = false; + break; + } + }//end better match check + + //Verified best match! + if(best_match == true){ + matched_MWR[dev] = mwrt; + Tdiff = fabs((MWR_times[dev][mwrt] - times_temps[i])); + } + }//Find matches between + }//end loop over MWR times + + }//end loop over MWR devices + + //Great we found a matched spill! Let's count it spill_count++; @@ -282,7 +361,14 @@ void sbn::BNBRetriever::produce(art::Event& e) beamInfo.THCURR = THCURR; beamInfo.spill_time_s = time_closest_int; beamInfo.spill_time_ns = time_closest_ns; - + + beamInfo.M875BB = unpacked_MWR[0][matched_MWR[0]]; + beamInfo.M875BB_spill_time_diff = (MWR_times[0][matched_MWR[0]] - times_temps[i]); + beamInfo.M876BB = unpacked_MWR[1][matched_MWR[1]]; + beamInfo.M876BB_spill_time_diff = (MWR_times[1][matched_MWR[1]] - times_temps[i]); + beamInfo.MMBTBB = unpacked_MWR[2][matched_MWR[2]]; + beamInfo.MMBTBB_spill_time_diff = (MWR_times[2][matched_MWR[2]] - times_temps[i]); + fOutbeamInfos.push_back(beamInfo); // We do not write these to the art::Events because // we can filter events but want to keep all the POT From a15db0eaa22fe038ebef628a41a2596ce2d4c7bc Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Thu, 24 Jun 2021 10:56:07 -0500 Subject: [PATCH 14/46] now correctly handling the first event in a run --- .../BNBRetriever/BNBRetriever_module.cc | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 8ae15efda..aea946dae 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -250,6 +250,28 @@ void sbn::BNBRetriever::produce(art::Event& e) int spill_count = 0; std::vector matched_MWR; matched_MWR.resize(3); + + + // Need to handle the first event in a run differently + if(e.event() == 1){ + + //We'll remove the spills after our event + int spills_after_our_target = 0; + // iterate through all the spills to find the + // spills that are after our triggered event + for (size_t i = 0; i < times_temps.size(); i++) { + if(times_temps[i] > (t_current_event+fTimePad)){ + spills_after_our_target++; + } + }//end loop through spill times + + // Remove the spills after our trigger + times_temps.erase(times_temps.end()-spills_after_our_target,times_temps.end()); + + // Remove the spills before the start of our Run + times_temps.erase(times_temps.begin(),times_temps.end()-number_of_gates_since_previous_event); + + }//end fix for "first event" // Iterating through each of the beamline times for (size_t i = 0; i < times_temps.size(); i++) { @@ -257,8 +279,11 @@ void sbn::BNBRetriever::produce(art::Event& e) // Only continue if these times are matched to our DAQ time // plus or minus some time padding, currently using 3.3 ms // which is half the Booster Rep Rate - if(times_temps[i] > (t_current_event+fTimePad)){continue;} - if(times_temps[i] <= (t_previous_event-fTimePad)){continue;} + + if(e.event() != 1){//We already addressed the "first event" above + if(times_temps[i] > (t_current_event+fTimePad)){continue;} + if(times_temps[i] <= (t_previous_event-fTimePad)){continue;} + } //Loop through the multiwire devices: @@ -375,7 +400,12 @@ void sbn::BNBRetriever::produce(art::Event& e) // information, so we'll write it to the SubRun }//end iteration over beam device times -std::cout << "Event Spills : " << spill_count << std::endl; + + if(spill_count > number_of_gates_since_previous_event) + std::cout << "Event Spills : " << spill_count << ", DAQ Spills : " << number_of_gates_since_previous_event << " \t \t ::: WRONG!"<< std::endl; + else + std::cout << "Event Spills : " << spill_count << ", DAQ Spills : " << number_of_gates_since_previous_event << std::endl; + } //end check if BNB DAQ triggered gate }//end iteration over art::Events From 4cdb704e65dd77fb453f56dda4ba1dbb4972ba8c Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Thu, 24 Jun 2021 12:14:50 -0500 Subject: [PATCH 15/46] added a retriever for the number of external gates --- sbncode/BeamSpillInfoRetriever/CMakeLists.txt | 1 + .../EXTRetriever/CMakeLists.txt | 34 +++++ .../EXTRetriever/EXTRetriever_module.cc | 141 ++++++++++++++++++ .../job/extcountinfo.fcl | 10 ++ .../job/run_extinfo_sbn.fcl | 33 ++++ 5 files changed, 219 insertions(+) create mode 100644 sbncode/BeamSpillInfoRetriever/EXTRetriever/CMakeLists.txt create mode 100644 sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc create mode 100644 sbncode/BeamSpillInfoRetriever/job/extcountinfo.fcl create mode 100644 sbncode/BeamSpillInfoRetriever/job/run_extinfo_sbn.fcl diff --git a/sbncode/BeamSpillInfoRetriever/CMakeLists.txt b/sbncode/BeamSpillInfoRetriever/CMakeLists.txt index fb0e63163..f92639eea 100644 --- a/sbncode/BeamSpillInfoRetriever/CMakeLists.txt +++ b/sbncode/BeamSpillInfoRetriever/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(BNBRetriever) +add_subdirectory(EXTRetriever) add_subdirectory(job) link_directories( diff --git a/sbncode/BeamSpillInfoRetriever/EXTRetriever/CMakeLists.txt b/sbncode/BeamSpillInfoRetriever/EXTRetriever/CMakeLists.txt new file mode 100644 index 000000000..8ae5a6a7d --- /dev/null +++ b/sbncode/BeamSpillInfoRetriever/EXTRetriever/CMakeLists.txt @@ -0,0 +1,34 @@ + +include_directories( $ENV{IFBEAM_FQ_DIR}/include ) +include_directories( $ENV{LIBWDA_FQ_DIR}/include ) +include_directories( $ENV{IFDHC_FQ_DIR}/inc ) +include_directories( $ENV{IFDH_ART_INC} ) + +simple_plugin(EXTRetriever module + ${ART_FRAMEWORK_CORE} + ${ART_FRAMEWORK_SERVICES_REGISTRY} + ${ART_ROOT_IO_TFILESERVICE_SERVICE} ${ART_FRAMEWORK_SERVICES} + ${ART_FRAMEWORK_PRINCIPAL} + art_Persistency_Common + art_Utilities canvas + ${MF_MESSAGELOGGER} + ${MF_UTILITIES} + ${FHICLCPP} + cetlib cetlib_except + ${ROOT_EVE_LIB_LIST} + ${ROOT_X3d} + ${ROOT_BASIC_LIB_LIST} + ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_DATE_TIME_LIBRARY} ${Boost_SERIALIZATION_LIBRARY} + ${Boost_SYSTEM_LIBRARY} + MF_MessageLogger + sbnobj_Common_POTAccounting + sbndaq-artdaq-core_Overlays_Common + sbndaq-artdaq-core_Overlays + sbndaq-artdaq-core_Overlays_ICARUS + artdaq-core_Utilities +) + +install_headers() +install_fhicl() +install_source() + diff --git a/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc new file mode 100644 index 000000000..30a2dbf8b --- /dev/null +++ b/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc @@ -0,0 +1,141 @@ +//////////////////////////////////////////////////////////////////////// +// Class: EXTRetriever +// Plugin Type: producer +// File: EXTRetriever_module.cc +// +// Created by hand Thurs June 24th 2021 by J. Zennamo (FNAL) +// +//////////////////////////////////////////////////////////////////////// + +#include "art/Framework/Core/EDProducer.h" +#include "art/Framework/Core/ModuleMacros.h" +#include "art/Framework/Principal/Event.h" +#include "art/Framework/Principal/Handle.h" +#include "art/Framework/Principal/Run.h" +#include "art/Framework/Principal/SubRun.h" +#include "canvas/Utilities/InputTag.h" +#include "fhiclcpp/ParameterSet.h" +#include "messagefacility/MessageLogger/MessageLogger.h" +#include "lardata/Utilities/AssociationUtil.h" +#include "lardataobj/Utilities/sparse_vector.h" +#include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" +#include "larcorealg/Geometry/Exceptions.h" + +#include "artdaq-core/Data/Fragment.hh" +#include "sbndaq-artdaq-core/Overlays/ICARUS/ICARUSTriggerUDPFragment.hh" + +#include "lardataalg/DetectorInfo/DetectorPropertiesStandard.h" +#include "lardata/DetectorInfoServices/DetectorPropertiesService.h" +#include "sbnobj/Common/POTAccounting/EXTCountInfo.h" + +#include +#include +#include +#include +#include +#include + +namespace sbn { + class EXTRetriever; +} + +class sbn::EXTRetriever : public art::EDProducer { +public: + explicit EXTRetriever(fhicl::ParameterSet const& p); + // The compiler-generated destructor is fine for non-base + // classes without bare pointers or other resource use. + + // Plugins should not be copied or assigned. + EXTRetriever(EXTRetriever const&) = delete; + EXTRetriever(EXTRetriever&&) = delete; + EXTRetriever& operator=(EXTRetriever const&) = delete; + EXTRetriever& operator=(EXTRetriever&&) = delete; + + // Required functions. + void produce(art::Event& e) override; + void beginSubRun(art::SubRun& sr); + void endSubRun(art::SubRun& sr); + +private: + std::vector< sbn::EXTCountInfo > fOutExtInfos; + + // input labels + std::string raw_data_label_; + int TotalEXTCounts; + +}; + + +sbn::EXTRetriever::EXTRetriever(fhicl::ParameterSet const& p) + : EDProducer{p}, + raw_data_label_(p.get("raw_data_label")) +{ + + produces< std::vector< sbn::EXTCountInfo >, art::InSubRun >(); + TotalEXTCounts = 0; +} + +void sbn::EXTRetriever::produce(art::Event& e) +{ + + //Here we read in the artdaq Fragments and extract three pieces of information: + // 1. The time of the current event, t_current_event + // 2. the time of the previously triggered event, t_previous_event (NOTE: Events are non-sequential!) + // 3. the number of beam spills since the previously triggered event, number_of_gates_since_previous_event + + int gate_type = 0; + art::Handle< std::vector > raw_data_ptr; + e.getByLabel(raw_data_label_, "ICARUSTriggerUDP", raw_data_ptr); + auto const & raw_data = (*raw_data_ptr); + + double number_of_gates_since_previous_event = 0; + + for(auto raw_datum : raw_data){ + + icarus::ICARUSTriggerUDPFragment frag(raw_datum); + std::string data = frag.GetDataString(); + char *buffer = const_cast(data.c_str()); + icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerString(buffer); + gate_type = datastream_info.gate_type; + number_of_gates_since_previous_event = frag.getDeltaGatesBNB(); + + } + + //We only want to process EXT gates, i.e. type 3 + if(gate_type == 3) + { + // Keep track of the number of beam gates the DAQ thinks + // are in this file + TotalEXTCounts += number_of_gates_since_previous_event; + + //Store everything in our data-product + sbn::EXTCountInfo extInfo; + extInfo.gates_since_last_trigger = number_of_gates_since_previous_event; + + fOutExtInfos.push_back(extInfo); + // We do not write these to the art::Events because + // we can filter events but want to keep all the POT + // information, so we'll write it to the SubRun + + }//end check on gate type +} //end loop over events + + +void sbn::EXTRetriever::beginSubRun(art::SubRun& sr) +{ + return; +} + +//____________________________________________________________________________ +void sbn::EXTRetriever::endSubRun(art::SubRun& sr) +{ + // We will add all of the EXTCountInfo data-products to the + // art::SubRun so it persists + auto p = std::make_unique< std::vector< sbn::EXTCountInfo > >(fOutExtInfos); + + sr.put(std::move(p)); + + return; +} + +DEFINE_ART_MODULE(sbn::EXTRetriever) diff --git a/sbncode/BeamSpillInfoRetriever/job/extcountinfo.fcl b/sbncode/BeamSpillInfoRetriever/job/extcountinfo.fcl new file mode 100644 index 000000000..1ca870996 --- /dev/null +++ b/sbncode/BeamSpillInfoRetriever/job/extcountinfo.fcl @@ -0,0 +1,10 @@ + +BEGIN_PROLOG + +extcountinfo: { + + module_type: "EXTRetriever" + raw_data_label: "daq" + +} +END_PROLOG diff --git a/sbncode/BeamSpillInfoRetriever/job/run_extinfo_sbn.fcl b/sbncode/BeamSpillInfoRetriever/job/run_extinfo_sbn.fcl new file mode 100644 index 000000000..f3b66bbb4 --- /dev/null +++ b/sbncode/BeamSpillInfoRetriever/job/run_extinfo_sbn.fcl @@ -0,0 +1,33 @@ +#include "extcountinfo.fcl" + +process_name: EXTInfoGen + +services:{ + IFBeam:{} +} + + +source: { + module_type: RootInput +} + +physics: { + producers: { + extinfo: @local::extcountinfo + } + + simulate: [extinfo ] + stream1: [ out1 ] + trigger_paths: [ simulate ] + end_paths: [ stream1 ] +} + +outputs: { + out1: { + module_type: RootOutput + fileName: "%ifb_%tc_extinfo.root" + dataTier: "raw" + compressionLevel: 1 + } +} + From 5b0f8c391c9420f71d90fcab9631168d2eef77f0 Mon Sep 17 00:00:00 2001 From: jzennamo Date: Mon, 28 Jun 2021 09:23:47 -0500 Subject: [PATCH 16/46] Update sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc Co-authored-by: Gianluca Petrillo --- .../BNBRetriever/BNBRetriever_module.cc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index aea946dae..0ff7f50c0 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -1,13 +1,12 @@ -//////////////////////////////////////////////////////////////////////// -// Class: BNBRetriever -// Plugin Type: producer -// File: BNBRetriever_module.cc -// -// Created by hand Wed April 9 2021 by J. Zennamo (FNAL) -// Based heavily on code by Z. Pavlovic written for MicroBooNE -// Based heavily on code by NOvA collaboration (Thanks NOvA!): -// https://cdcvs.fnal.gov/redmine/projects/novaart/repository/entry/trunk/IFDBSpillInfo/BNBInfo_module.cc -//////////////////////////////////////////////////////////////////////// +/** ******************************************************************** + * @file BNBRetriever_module.cc + * @date Wed April 9 2021 + * @author J. Zennamo (FNAL) + * + * Based heavily on code by Z. Pavlovic written for MicroBooNE + * Based heavily on code by NOvA collaboration (Thanks NOvA!): + * https://cdcvs.fnal.gov/redmine/projects/novaart/repository/entry/trunk/IFDBSpillInfo/BNBInfo_module.cc + */ #include "art/Framework/Core/EDProducer.h" #include "art/Framework/Core/ModuleMacros.h" From e019fe459b44cc57629667f8e3edb2f0d0df8e96 Mon Sep 17 00:00:00 2001 From: jzennamo Date: Mon, 28 Jun 2021 09:26:19 -0500 Subject: [PATCH 17/46] Update sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc Co-authored-by: Gianluca Petrillo --- .../BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 0ff7f50c0..317994f6a 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -36,9 +36,6 @@ #include #include #include -#include -#include -#include namespace sbn { class BNBRetriever; From 3a216c4dc0e12138a6719af555655e0f188e6dd2 Mon Sep 17 00:00:00 2001 From: jzennamo Date: Mon, 28 Jun 2021 09:29:00 -0500 Subject: [PATCH 18/46] Update sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc Co-authored-by: Gianluca Petrillo --- .../BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 317994f6a..a68fceebe 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -138,7 +138,7 @@ void sbn::BNBRetriever::produce(art::Event& e) if(gate_type == 1) { // Keep track of the number of beam gates the DAQ thinks - // are in this file + // are in this job TotalBeamSpills += number_of_gates_since_previous_event; // These lines get everything primed within the IFBeamDB From a35144fd1051dcead85c1e47dc4caf3b5d4f9520 Mon Sep 17 00:00:00 2001 From: jzennamo Date: Mon, 28 Jun 2021 09:40:52 -0500 Subject: [PATCH 19/46] Update sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc Co-authored-by: Gianluca Petrillo --- .../BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index a68fceebe..c18a6d054 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -422,7 +422,7 @@ std::cout << "Total number of Selected Spills : " << fOutbeamInfos.size() << std auto p = std::make_unique< std::vector< sbn::BNBSpillInfo > >(fOutbeamInfos); - sr.put(std::move(p)); + sr.put(std::move(p), art::subRunFragment()); return; } From c4af7af8ef5b413d956964db929c7e68a9d85724 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Mon, 28 Jun 2021 10:33:14 -0500 Subject: [PATCH 20/46] added SubRun overrides --- .../BNBRetriever/BNBRetriever_module.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index c18a6d054..931f69741 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -55,8 +55,8 @@ class sbn::BNBRetriever : public art::EDProducer { // Required functions. void produce(art::Event& e) override; - void beginSubRun(art::SubRun& sr); - void endSubRun(art::SubRun& sr); + void beginSubRun(art::SubRun& sr) override; + void endSubRun(art::SubRun& sr) override; private: // input labels From e83669193a65601539ae233376d39b6df57ba6e0 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Mon, 28 Jun 2021 10:39:21 -0500 Subject: [PATCH 21/46] fixed unit mismatch and added mf::Log handling --- .../BNBRetriever/BNBRetriever_module.cc | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 931f69741..90e5f92a7 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -61,12 +61,12 @@ class sbn::BNBRetriever : public art::EDProducer { private: // input labels std::vector< sbn::BNBSpillInfo > fOutbeamInfos; - int fTimePad; + double fTimePad; std::string fURL; MWRData mwrdata; std::string raw_data_label_; std::string fDeviceUsedForTiming; - int TotalBeamSpills; + unsigned int TotalBeamSpills; // art::ServiceHandle ifbeam_handle; std::unique_ptr bfp; @@ -79,7 +79,7 @@ class sbn::BNBRetriever : public art::EDProducer { sbn::BNBRetriever::BNBRetriever(fhicl::ParameterSet const& p) : EDProducer{p}, - fTimePad(p.get("TimePadding",0.0333)), //seconds + fTimePad{p.get("TimePadding",0.0333)}, //seconds raw_data_label_(p.get("raw_data_label")), fDeviceUsedForTiming(p.get("DeviceUsedForTiming")), bfp( ifbeam_handle->getBeamFolder(p.get< std::string >("Bundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))), @@ -132,7 +132,7 @@ void sbn::BNBRetriever::produce(art::Event& e) } - std::cout << std::setprecision(19) << "Previous : " << t_previous_event << ", Current : " << t_current_event << std::endl; + mf::LogDebug("BNBRetriever") << std::setprecision(19) << "Previous : " << t_previous_event << ", Current : " << t_current_event << std::endl; //We only want to process BNB gates, i.e. type 1 if(gate_type == 1) @@ -347,19 +347,19 @@ void sbn::BNBRetriever::produce(art::Event& e) // since sometimes devices fail to report we'll // allow each to throw an exception but still move forward // interpreting these failures will be part of the beam quality analyses - try{bfp->GetNamedData(times_temps[i], "E:TOR860@",&TOR860,&TOR860_time);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:TOR875",&TOR875);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:LM875A",&LM875A);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:LM875B",&LM875B);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:LM875C",&LM875C);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:HP875",&HP875);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:VP875",&VP875);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:HPTG1",&HPTG1);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:VPTG1",&VPTG1);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:HPTG2",&HPTG2);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:VPTG2",&VPTG2);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:BTJT2",&BTJT2);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:THCURR",&THCURR);}catch (WebAPIException &we) {std::cout << "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:TOR860@",&TOR860,&TOR860_time);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:TOR875",&TOR875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:LM875A",&LM875A);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:LM875B",&LM875B);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:LM875C",&LM875C);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:HP875",&HP875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:VP875",&VP875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:HPTG1",&HPTG1);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:VPTG1",&VPTG1);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:HPTG2",&HPTG2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:VPTG2",&VPTG2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:BTJT2",&BTJT2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:THCURR",&THCURR);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} //crunch the times unsigned long int time_closest_int = (int) TOR860_time; @@ -398,9 +398,9 @@ void sbn::BNBRetriever::produce(art::Event& e) }//end iteration over beam device times if(spill_count > number_of_gates_since_previous_event) - std::cout << "Event Spills : " << spill_count << ", DAQ Spills : " << number_of_gates_since_previous_event << " \t \t ::: WRONG!"<< std::endl; + mf::LogDebug("BNBRetriever")<< "Event Spills : " << spill_count << ", DAQ Spills : " << number_of_gates_since_previous_event << " \t \t ::: WRONG!"<< std::endl; else - std::cout << "Event Spills : " << spill_count << ", DAQ Spills : " << number_of_gates_since_previous_event << std::endl; + mf::LogDebug("BNBRetriever")<< "Event Spills : " << spill_count << ", DAQ Spills : " << number_of_gates_since_previous_event << std::endl; } //end check if BNB DAQ triggered gate }//end iteration over art::Events @@ -417,8 +417,8 @@ void sbn::BNBRetriever::endSubRun(art::SubRun& sr) // art::SubRun so it persists // currently this is ~2.7 kB/event or ~0.07 kB/spill -std::cout << "Total number of DAQ Spills : " << TotalBeamSpills << std::endl; -std::cout << "Total number of Selected Spills : " << fOutbeamInfos.size() << std::endl; +mf::LogDebug("BNBRetriever")<< "Total number of DAQ Spills : " << TotalBeamSpills << std::endl; +mf::LogDebug("BNBRetriever")<< "Total number of Selected Spills : " << fOutbeamInfos.size() << std::endl; auto p = std::make_unique< std::vector< sbn::BNBSpillInfo > >(fOutbeamInfos); From d60964a11d7ba2ef0b6c2b2badbcb779b69b4608 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Mon, 28 Jun 2021 10:42:38 -0500 Subject: [PATCH 22/46] more elegant check of the gate_type --- .../BNBRetriever/BNBRetriever_module.cc | 499 +++++++++--------- 1 file changed, 249 insertions(+), 250 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 90e5f92a7..7c3375523 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -135,274 +135,273 @@ void sbn::BNBRetriever::produce(art::Event& e) mf::LogDebug("BNBRetriever") << std::setprecision(19) << "Previous : " << t_previous_event << ", Current : " << t_current_event << std::endl; //We only want to process BNB gates, i.e. type 1 - if(gate_type == 1) - { - // Keep track of the number of beam gates the DAQ thinks - // are in this job - TotalBeamSpills += number_of_gates_since_previous_event; - - // These lines get everything primed within the IFBeamDB - // They seem redundant but they are needed - try{auto cur_vec_temp = bfp->GetNamedVector((t_previous_event)-fTimePad,"E:THCURR");} catch (WebAPIException &we) {} - try{auto packed_M876BB_temp = bfp_mwr->GetNamedVector((t_current_event)+fTimePad,"E:M875BB{4440:888}.RAW");} catch (WebAPIException &we) {} - - - //The multiwire chambers provide their - // data in a vector format but we'll have - // to sort through it in std::string format - // to correctly unpack it - std::vector< std::vector< std::vector< int > > > unpacked_MWR; - std::vector< std::vector< double> > MWR_times; - unpacked_MWR.resize(3); - MWR_times.resize(3); - std::string packed_data_str; - - //Create a list of all the MWR devices with their different - // memory buffer increments - // generally in the format: "E:.{Memory Block}" - std::vector vars = bfp_mwr->GetDeviceList(); - - // Tracking the time from the IFBeamDB - double time_for_mwr; - - // this is an iterator to track which of the - // three devices we will be working with - int dev = 0; - - // The MWR devices are annoying and have confusing buffer - // what we'll do is sort through all of them first and then - // match them to the closest spills in time - // - int t_steps = int(fabs((t_previous_event - fTimePad) - (t_current_event + fTimePad))/0.5)+25; - - for(int t = 0; t < t_steps; t++){//Iterate through time increments - for (int i = 0; i < int(vars.size()); i++) {// Iterate through the devices - - //Make sure we have a device - if(vars[i].empty()) continue; + if(gate_type != 1) return; + + // Keep track of the number of beam gates the DAQ thinks + // are in this job + TotalBeamSpills += number_of_gates_since_previous_event; + + // These lines get everything primed within the IFBeamDB + // They seem redundant but they are needed + try{auto cur_vec_temp = bfp->GetNamedVector((t_previous_event)-fTimePad,"E:THCURR");} catch (WebAPIException &we) {} + try{auto packed_M876BB_temp = bfp_mwr->GetNamedVector((t_current_event)+fTimePad,"E:M875BB{4440:888}.RAW");} catch (WebAPIException &we) {} + + + //The multiwire chambers provide their + // data in a vector format but we'll have + // to sort through it in std::string format + // to correctly unpack it + std::vector< std::vector< std::vector< int > > > unpacked_MWR; + std::vector< std::vector< double> > MWR_times; + unpacked_MWR.resize(3); + MWR_times.resize(3); + std::string packed_data_str; + + //Create a list of all the MWR devices with their different + // memory buffer increments + // generally in the format: "E:.{Memory Block}" + std::vector vars = bfp_mwr->GetDeviceList(); + + // Tracking the time from the IFBeamDB + double time_for_mwr; + + // this is an iterator to track which of the + // three devices we will be working with + int dev = 0; + + // The MWR devices are annoying and have confusing buffer + // what we'll do is sort through all of them first and then + // match them to the closest spills in time + // + int t_steps = int(fabs((t_previous_event - fTimePad) - (t_current_event + fTimePad))/0.5)+25; + + for(int t = 0; t < t_steps; t++){//Iterate through time increments + for (int i = 0; i < int(vars.size()); i++) {// Iterate through the devices + + //Make sure we have a device + if(vars[i].empty()) continue; + + /// Check the device name and interate the double-vector index + if(vars[i].find("M875BB") != std::string::npos ) dev = 0; + else if(vars[i].find("M876BB") != std::string::npos ) dev = 1; + else if(vars[i].find("MMBTBB") != std::string::npos ) dev = 2; + else{continue;} + + time_for_mwr = 0; + + try{ + //Pull the MWR data for the device + // these data are "packed" + std::vector packed_MWR = bfp_mwr->GetNamedVector((t_previous_event)-fTimePad+double(0.5*t),vars[i],&time_for_mwr); - /// Check the device name and interate the double-vector index - if(vars[i].find("M875BB") != std::string::npos ) dev = 0; - else if(vars[i].find("M876BB") != std::string::npos ) dev = 1; - else if(vars[i].find("MMBTBB") != std::string::npos ) dev = 2; - else{continue;} - - time_for_mwr = 0; + //We'll convert this into a format + // that we can unpack doubles >> strings + // + packed_data_str.clear(); + packed_data_str += std::to_string(int(time_for_mwr)); + packed_data_str.append(","); + packed_data_str.append(vars[i]); + packed_data_str.append(",,"); - try{ - //Pull the MWR data for the device - // these data are "packed" - std::vector packed_MWR = bfp_mwr->GetNamedVector((t_previous_event)-fTimePad+double(0.5*t),vars[i],&time_for_mwr); - - //We'll convert this into a format - // that we can unpack doubles >> strings - // - packed_data_str.clear(); - packed_data_str += std::to_string(int(time_for_mwr)); - packed_data_str.append(","); - packed_data_str.append(vars[i]); - packed_data_str.append(",,"); - - for(int j = 0; j < int(packed_MWR.size()); j++){ - packed_data_str += std::to_string(int(packed_MWR[j])); - if(j < int(packed_MWR.size())-1) - packed_data_str.append(","); - } - - // Use Zarko's unpacking function to turn this into consumeable data - std::vector MWR_times_temp; - - // There is a 35 ms offset between the toriod and the MWR times - // we'll just remove that here to match to the spill times - std::vector< std::vector< int > > unpacked_MWR_temp = mwrdata.unpackMWR(packed_data_str,MWR_times_temp,-0.035); + for(int j = 0; j < int(packed_MWR.size()); j++){ + packed_data_str += std::to_string(int(packed_MWR[j])); + if(j < int(packed_MWR.size())-1) + packed_data_str.append(","); + } + + // Use Zarko's unpacking function to turn this into consumeable data + std::vector MWR_times_temp; + + // There is a 35 ms offset between the toriod and the MWR times + // we'll just remove that here to match to the spill times + std::vector< std::vector< int > > unpacked_MWR_temp = mwrdata.unpackMWR(packed_data_str,MWR_times_temp,-0.035); + + //There are four events that are packed into one MWR IFBeam entry + for(int s = 0; s < int(unpacked_MWR_temp.size()); s++){ - //There are four events that are packed into one MWR IFBeam entry - for(int s = 0; s < int(unpacked_MWR_temp.size()); s++){ + // If this entry has a unique time them store it for later + if(std::find(MWR_times[dev].begin(), MWR_times[dev].end(), MWR_times_temp[s]) == MWR_times[dev].end()){ + unpacked_MWR[dev].push_back(unpacked_MWR_temp[s]); + MWR_times[dev].push_back(MWR_times_temp[s]); + }//check for unique time - // If this entry has a unique time them store it for later - if(std::find(MWR_times[dev].begin(), MWR_times[dev].end(), MWR_times_temp[s]) == MWR_times[dev].end()){ - unpacked_MWR[dev].push_back(unpacked_MWR_temp[s]); - MWR_times[dev].push_back(MWR_times_temp[s]); - }//check for unique time - - }//Iterate through the unpacked events + }//Iterate through the unpacked events }//try - catch (WebAPIException &we) { - //Ignore when we can't find the MWR devices - // they don't always report and the timing of them can be annoying - + catch (WebAPIException &we) { + //Ignore when we can't find the MWR devices + // they don't always report and the timing of them can be annoying + }//catch - }// Iterate over all the multiwire devices - }// Iterate over all times - - - //Here we will start collecting all the other beamline devices - // First we get the times that the beamline device fired - // we have to pick a specific variable to use - std::vector times_temps = bfp->GetTimeList(fDeviceUsedForTiming); - - // We'll keep track of how many of these spills match to our - // DAQ trigger times - int spill_count = 0; - std::vector matched_MWR; - matched_MWR.resize(3); + }// Iterate over all the multiwire devices + }// Iterate over all times + + + //Here we will start collecting all the other beamline devices + // First we get the times that the beamline device fired + // we have to pick a specific variable to use + std::vector times_temps = bfp->GetTimeList(fDeviceUsedForTiming); + + // We'll keep track of how many of these spills match to our + // DAQ trigger times + int spill_count = 0; + std::vector matched_MWR; + matched_MWR.resize(3); + + + // Need to handle the first event in a run differently + if(e.event() == 1){ - - // Need to handle the first event in a run differently - if(e.event() == 1){ - - //We'll remove the spills after our event - int spills_after_our_target = 0; - // iterate through all the spills to find the - // spills that are after our triggered event - for (size_t i = 0; i < times_temps.size(); i++) { - if(times_temps[i] > (t_current_event+fTimePad)){ - spills_after_our_target++; - } - }//end loop through spill times - - // Remove the spills after our trigger - times_temps.erase(times_temps.end()-spills_after_our_target,times_temps.end()); - - // Remove the spills before the start of our Run - times_temps.erase(times_temps.begin(),times_temps.end()-number_of_gates_since_previous_event); - - }//end fix for "first event" - - // Iterating through each of the beamline times - for (size_t i = 0; i < times_temps.size(); i++) { - - // Only continue if these times are matched to our DAQ time - // plus or minus some time padding, currently using 3.3 ms - // which is half the Booster Rep Rate - - if(e.event() != 1){//We already addressed the "first event" above - if(times_temps[i] > (t_current_event+fTimePad)){continue;} - if(times_temps[i] <= (t_previous_event-fTimePad)){continue;} + //We'll remove the spills after our event + int spills_after_our_target = 0; + // iterate through all the spills to find the + // spills that are after our triggered event + for (size_t i = 0; i < times_temps.size(); i++) { + if(times_temps[i] > (t_current_event+fTimePad)){ + spills_after_our_target++; } + }//end loop through spill times + + // Remove the spills after our trigger + times_temps.erase(times_temps.end()-spills_after_our_target,times_temps.end()); + + // Remove the spills before the start of our Run + times_temps.erase(times_temps.begin(),times_temps.end()-number_of_gates_since_previous_event); + + }//end fix for "first event" + + // Iterating through each of the beamline times + for (size_t i = 0; i < times_temps.size(); i++) { + + // Only continue if these times are matched to our DAQ time + // plus or minus some time padding, currently using 3.3 ms + // which is half the Booster Rep Rate + + if(e.event() != 1){//We already addressed the "first event" above + if(times_temps[i] > (t_current_event+fTimePad)){continue;} + if(times_temps[i] <= (t_previous_event-fTimePad)){continue;} + } - //Loop through the multiwire devices: + //Loop through the multiwire devices: + + for(int dev = 0; dev < int(MWR_times.size()); dev++){ - for(int dev = 0; dev < int(MWR_times.size()); dev++){ - - //Loop through the multiwire times: - double Tdiff = 1000000000.; - matched_MWR[dev] = 0; - bool best_match = false; - for(int mwrt = 0; mwrt < int(MWR_times[dev].size()); mwrt++){ + //Loop through the multiwire times: + double Tdiff = 1000000000.; + matched_MWR[dev] = 0; + bool best_match = false; + for(int mwrt = 0; mwrt < int(MWR_times[dev].size()); mwrt++){ + + //found a candidate match! + if(fabs((MWR_times[dev][mwrt] - times_temps[i])) < Tdiff){ + best_match = true; - //found a candidate match! - if(fabs((MWR_times[dev][mwrt] - times_temps[i])) < Tdiff){ - best_match = true; + //Check for a better match... + for (size_t j = 0; j < times_temps.size(); j++) { + if( j == i) continue; + if(times_temps[j] > (t_current_event+fTimePad)){continue;} + if(times_temps[j] <= (t_previous_event-fTimePad)){continue;} - //Check for a better match... - for (size_t j = 0; j < times_temps.size(); j++) { - if( j == i) continue; - if(times_temps[j] > (t_current_event+fTimePad)){continue;} - if(times_temps[j] <= (t_previous_event-fTimePad)){continue;} - - //is there a better match later in the spill sequence - if(fabs((MWR_times[dev][mwrt] - times_temps[j])) < - fabs((MWR_times[dev][mwrt] - times_temps[i]))){ - //we can have patience... - best_match = false; - break; - } - }//end better match check - - //Verified best match! - if(best_match == true){ - matched_MWR[dev] = mwrt; - Tdiff = fabs((MWR_times[dev][mwrt] - times_temps[i])); - } - }//Find matches between - }//end loop over MWR times - - }//end loop over MWR devices - - - //Great we found a matched spill! Let's count it - spill_count++; + //is there a better match later in the spill sequence + if(fabs((MWR_times[dev][mwrt] - times_temps[j])) < + fabs((MWR_times[dev][mwrt] - times_temps[i]))){ + //we can have patience... + best_match = false; + break; + } + }//end better match check + + //Verified best match! + if(best_match == true){ + matched_MWR[dev] = mwrt; + Tdiff = fabs((MWR_times[dev][mwrt] - times_temps[i])); + } + }//Find matches between + }//end loop over MWR times - // initializing all of our device carriers - // device definitions can be found in BNBSpillInfo.h + }//end loop over MWR devices - double TOR860 = 0; // units e12 protons - double TOR875 = 0; // units e12 protons - double LM875A = 0; // units R/s - double LM875B = 0; // units R/s - double LM875C = 0; // units R/s - double HP875 = 0; // units mm - double VP875 = 0; // units mm - double HPTG1 = 0; // units mm - double VPTG1 = 0; // units mm - double HPTG2 = 0; // units mm - double VPTG2 = 0; // units mm - double BTJT2 = 0; // units Deg C - double THCURR = 0; // units kiloAmps - - double TOR860_time = 0; // units s - - // Here we request all the devices - // since sometimes devices fail to report we'll - // allow each to throw an exception but still move forward - // interpreting these failures will be part of the beam quality analyses - try{bfp->GetNamedData(times_temps[i], "E:TOR860@",&TOR860,&TOR860_time);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:TOR875",&TOR875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:LM875A",&LM875A);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:LM875B",&LM875B);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:LM875C",&LM875C);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:HP875",&HP875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:VP875",&VP875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:HPTG1",&HPTG1);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:VPTG1",&VPTG1);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:HPTG2",&HPTG2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:VPTG2",&VPTG2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:BTJT2",&BTJT2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:THCURR",&THCURR);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - - //crunch the times - unsigned long int time_closest_int = (int) TOR860_time; - double time_closest_ns = (TOR860_time - time_closest_int)*1e9; + + //Great we found a matched spill! Let's count it + spill_count++; + + // initializing all of our device carriers + // device definitions can be found in BNBSpillInfo.h + + double TOR860 = 0; // units e12 protons + double TOR875 = 0; // units e12 protons + double LM875A = 0; // units R/s + double LM875B = 0; // units R/s + double LM875C = 0; // units R/s + double HP875 = 0; // units mm + double VP875 = 0; // units mm + double HPTG1 = 0; // units mm + double VPTG1 = 0; // units mm + double HPTG2 = 0; // units mm + double VPTG2 = 0; // units mm + double BTJT2 = 0; // units Deg C + double THCURR = 0; // units kiloAmps + + double TOR860_time = 0; // units s - //Store everything in our data-product - sbn::BNBSpillInfo beamInfo; - beamInfo.TOR860 = TOR860; - beamInfo.TOR875 = TOR875; - beamInfo.LM875A = LM875A; - beamInfo.LM875B = LM875B; - beamInfo.LM875C = LM875C; - beamInfo.HP875 = HP875; - beamInfo.VP875 = VP875; - beamInfo.HPTG1 = HPTG1; - beamInfo.VPTG1 = VPTG1; - beamInfo.HPTG2 = HPTG2; - beamInfo.VPTG2 = VPTG2; - beamInfo.BTJT2 = BTJT2; - beamInfo.THCURR = THCURR; - beamInfo.spill_time_s = time_closest_int; - beamInfo.spill_time_ns = time_closest_ns; - - beamInfo.M875BB = unpacked_MWR[0][matched_MWR[0]]; - beamInfo.M875BB_spill_time_diff = (MWR_times[0][matched_MWR[0]] - times_temps[i]); - beamInfo.M876BB = unpacked_MWR[1][matched_MWR[1]]; - beamInfo.M876BB_spill_time_diff = (MWR_times[1][matched_MWR[1]] - times_temps[i]); - beamInfo.MMBTBB = unpacked_MWR[2][matched_MWR[2]]; - beamInfo.MMBTBB_spill_time_diff = (MWR_times[2][matched_MWR[2]] - times_temps[i]); - - fOutbeamInfos.push_back(beamInfo); - // We do not write these to the art::Events because - // we can filter events but want to keep all the POT - // information, so we'll write it to the SubRun + // Here we request all the devices + // since sometimes devices fail to report we'll + // allow each to throw an exception but still move forward + // interpreting these failures will be part of the beam quality analyses + try{bfp->GetNamedData(times_temps[i], "E:TOR860@",&TOR860,&TOR860_time);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:TOR875",&TOR875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:LM875A",&LM875A);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:LM875B",&LM875B);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:LM875C",&LM875C);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:HP875",&HP875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:VP875",&VP875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:HPTG1",&HPTG1);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:VPTG1",&VPTG1);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:HPTG2",&HPTG2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:VPTG2",&VPTG2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:BTJT2",&BTJT2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(times_temps[i], "E:THCURR",&THCURR);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - }//end iteration over beam device times - - if(spill_count > number_of_gates_since_previous_event) - mf::LogDebug("BNBRetriever")<< "Event Spills : " << spill_count << ", DAQ Spills : " << number_of_gates_since_previous_event << " \t \t ::: WRONG!"<< std::endl; + //crunch the times + unsigned long int time_closest_int = (int) TOR860_time; + double time_closest_ns = (TOR860_time - time_closest_int)*1e9; + + //Store everything in our data-product + sbn::BNBSpillInfo beamInfo; + beamInfo.TOR860 = TOR860; + beamInfo.TOR875 = TOR875; + beamInfo.LM875A = LM875A; + beamInfo.LM875B = LM875B; + beamInfo.LM875C = LM875C; + beamInfo.HP875 = HP875; + beamInfo.VP875 = VP875; + beamInfo.HPTG1 = HPTG1; + beamInfo.VPTG1 = VPTG1; + beamInfo.HPTG2 = HPTG2; + beamInfo.VPTG2 = VPTG2; + beamInfo.BTJT2 = BTJT2; + beamInfo.THCURR = THCURR; + beamInfo.spill_time_s = time_closest_int; + beamInfo.spill_time_ns = time_closest_ns; + + beamInfo.M875BB = unpacked_MWR[0][matched_MWR[0]]; + beamInfo.M875BB_spill_time_diff = (MWR_times[0][matched_MWR[0]] - times_temps[i]); + beamInfo.M876BB = unpacked_MWR[1][matched_MWR[1]]; + beamInfo.M876BB_spill_time_diff = (MWR_times[1][matched_MWR[1]] - times_temps[i]); + beamInfo.MMBTBB = unpacked_MWR[2][matched_MWR[2]]; + beamInfo.MMBTBB_spill_time_diff = (MWR_times[2][matched_MWR[2]] - times_temps[i]); + + fOutbeamInfos.push_back(beamInfo); + // We do not write these to the art::Events because + // we can filter events but want to keep all the POT + // information, so we'll write it to the SubRun + + }//end iteration over beam device times + + if(spill_count > number_of_gates_since_previous_event) + mf::LogDebug("BNBRetriever")<< "Event Spills : " << spill_count << ", DAQ Spills : " << number_of_gates_since_previous_event << " \t \t ::: WRONG!"<< std::endl; else mf::LogDebug("BNBRetriever")<< "Event Spills : " << spill_count << ", DAQ Spills : " << number_of_gates_since_previous_event << std::endl; - - } //end check if BNB DAQ triggered gate + }//end iteration over art::Events void sbn::BNBRetriever::beginSubRun(art::SubRun& sr) From e07e086721bf059cf41842d18ba80527d38f96a3 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Mon, 28 Jun 2021 10:46:15 -0500 Subject: [PATCH 23/46] MWR variable list converted to range-for loop --- .../BNBRetriever/BNBRetriever_module.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 7c3375523..4b4bc943a 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -176,15 +176,15 @@ void sbn::BNBRetriever::produce(art::Event& e) int t_steps = int(fabs((t_previous_event - fTimePad) - (t_current_event + fTimePad))/0.5)+25; for(int t = 0; t < t_steps; t++){//Iterate through time increments - for (int i = 0; i < int(vars.size()); i++) {// Iterate through the devices + for (auto const& var : vars) {// Iterate through the devices //Make sure we have a device - if(vars[i].empty()) continue; + if(var.empty()) continue; /// Check the device name and interate the double-vector index - if(vars[i].find("M875BB") != std::string::npos ) dev = 0; - else if(vars[i].find("M876BB") != std::string::npos ) dev = 1; - else if(vars[i].find("MMBTBB") != std::string::npos ) dev = 2; + if(var.find("M875BB") != std::string::npos ) dev = 0; + else if(var.find("M876BB") != std::string::npos ) dev = 1; + else if(var.find("MMBTBB") != std::string::npos ) dev = 2; else{continue;} time_for_mwr = 0; @@ -192,7 +192,7 @@ void sbn::BNBRetriever::produce(art::Event& e) try{ //Pull the MWR data for the device // these data are "packed" - std::vector packed_MWR = bfp_mwr->GetNamedVector((t_previous_event)-fTimePad+double(0.5*t),vars[i],&time_for_mwr); + std::vector packed_MWR = bfp_mwr->GetNamedVector((t_previous_event)-fTimePad+double(0.5*t),var,&time_for_mwr); //We'll convert this into a format // that we can unpack doubles >> strings @@ -200,7 +200,7 @@ void sbn::BNBRetriever::produce(art::Event& e) packed_data_str.clear(); packed_data_str += std::to_string(int(time_for_mwr)); packed_data_str.append(","); - packed_data_str.append(vars[i]); + packed_data_str.append(var); packed_data_str.append(",,"); for(int j = 0; j < int(packed_MWR.size()); j++){ From 760d53e566dad74c6e8114abf516ef473d9b895a Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Mon, 28 Jun 2021 10:58:52 -0500 Subject: [PATCH 24/46] fixed a few loops and added a better data-product accessing method --- .../BNBRetriever/BNBRetriever_module.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 4b4bc943a..7353f5f37 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -20,6 +20,7 @@ #include "lardata/Utilities/AssociationUtil.h" #include "lardataobj/Utilities/sparse_vector.h" #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" +#include "larcorealg/CoreUtils/counter.h" #include "larcorealg/Geometry/Exceptions.h" #include "artdaq-core/Data/Fragment.hh" @@ -106,9 +107,7 @@ void sbn::BNBRetriever::produce(art::Event& e) // 3. the number of beam spills since the previously triggered event, number_of_gates_since_previous_event int gate_type = 0; - art::Handle< std::vector > raw_data_ptr; - e.getByLabel(raw_data_label_, "ICARUSTriggerUDP", raw_data_ptr); - auto const & raw_data = (*raw_data_ptr); + auto const & raw_data = e.getByLabel< std::vector >({ raw_data_label_, "ICARUSTriggerUDP" }); double t_current_event = 0; double t_previous_event = 0; @@ -176,7 +175,7 @@ void sbn::BNBRetriever::produce(art::Event& e) int t_steps = int(fabs((t_previous_event - fTimePad) - (t_current_event + fTimePad))/0.5)+25; for(int t = 0; t < t_steps; t++){//Iterate through time increments - for (auto const& var : vars) {// Iterate through the devices + for (std::string const& var : vars) {// Iterate through the devices //Make sure we have a device if(var.empty()) continue; @@ -203,10 +202,9 @@ void sbn::BNBRetriever::produce(art::Event& e) packed_data_str.append(var); packed_data_str.append(",,"); - for(int j = 0; j < int(packed_MWR.size()); j++){ - packed_data_str += std::to_string(int(packed_MWR[j])); - if(j < int(packed_MWR.size())-1) - packed_data_str.append(","); + for(auto const value: packed_MWR){ + packed_data_str += ','; + packed_data_str += std::to_string(int(value)); } // Use Zarko's unpacking function to turn this into consumeable data @@ -217,7 +215,8 @@ void sbn::BNBRetriever::produce(art::Event& e) std::vector< std::vector< int > > unpacked_MWR_temp = mwrdata.unpackMWR(packed_data_str,MWR_times_temp,-0.035); //There are four events that are packed into one MWR IFBeam entry - for(int s = 0; s < int(unpacked_MWR_temp.size()); s++){ + for(std::size_t s: util::counter(unpacked_MWR_temp.size())){ + //for(int s = 0; s < int(unpacked_MWR_temp.size()); s++){ // If this entry has a unique time them store it for later if(std::find(MWR_times[dev].begin(), MWR_times[dev].end(), MWR_times_temp[s]) == MWR_times[dev].end()){ From dffb43279201771a5e29cd1c2cbccd8bf4c1c4dc Mon Sep 17 00:00:00 2001 From: Gianluca Petrillo Date: Mon, 28 Jun 2021 16:58:50 -0500 Subject: [PATCH 25/46] Changes requested by Clang --- .../BNBRetriever/BNBRetriever_module.cc | 4 ++-- .../EXTRetriever/EXTRetriever_module.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index c18a6d054..931f69741 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -55,8 +55,8 @@ class sbn::BNBRetriever : public art::EDProducer { // Required functions. void produce(art::Event& e) override; - void beginSubRun(art::SubRun& sr); - void endSubRun(art::SubRun& sr); + void beginSubRun(art::SubRun& sr) override; + void endSubRun(art::SubRun& sr) override; private: // input labels diff --git a/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc index 30a2dbf8b..dc10f43c7 100644 --- a/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc @@ -53,8 +53,8 @@ class sbn::EXTRetriever : public art::EDProducer { // Required functions. void produce(art::Event& e) override; - void beginSubRun(art::SubRun& sr); - void endSubRun(art::SubRun& sr); + void beginSubRun(art::SubRun& sr) override; + void endSubRun(art::SubRun& sr) override; private: std::vector< sbn::EXTCountInfo > fOutExtInfos; From e0150f430abe1b93bbb40bad8173d7b6f8c18aba Mon Sep 17 00:00:00 2001 From: Gianluca Petrillo Date: Mon, 28 Jun 2021 16:59:40 -0500 Subject: [PATCH 26/46] FHiCL configuration validation for beam retrievers --- .../BNBRetriever/BNBRetriever_module.cc | 70 ++++++++++++++++--- .../EXTRetriever/EXTRetriever_module.cc | 26 +++++-- 2 files changed, 82 insertions(+), 14 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 931f69741..af2c5c813 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -15,7 +15,7 @@ #include "art/Framework/Principal/Run.h" #include "art/Framework/Principal/SubRun.h" #include "canvas/Utilities/InputTag.h" -#include "fhiclcpp/ParameterSet.h" +#include "fhiclcpp/types/Atom.h" #include "messagefacility/MessageLogger/MessageLogger.h" #include "lardata/Utilities/AssociationUtil.h" #include "lardataobj/Utilities/sparse_vector.h" @@ -43,7 +43,59 @@ namespace sbn { class sbn::BNBRetriever : public art::EDProducer { public: - explicit BNBRetriever(fhicl::ParameterSet const& p); + + struct Config { + + using Name = fhicl::Name; + using Comment = fhicl::Comment; + + fhicl::Atom TimePadding { + Name{ "TimePadding" }, + Comment{ "extension to the time window considered when collecting spills [seconds]" }, + 0.0333 // default + }; + + fhicl::Atom RawDataLabel { + Name{ "raw_data_label" }, + Comment{ "art data product instance name for trigger information (product label is 'daq')" } + }; + + fhicl::Atom DeviceUsedForTiming { + Name{ "DeviceUsedForTiming" }, + Comment{ "name in the IFBeam database of the device used to extract spill times" } + }; + + fhicl::Atom URL { + Name{ "URL" }, + Comment{ "IFBeam database access URL" } + }; + + fhicl::Atom Bundle { + Name{ "Bundle" }, + Comment{ "" } // explain what this is and which database/table it's looking for + }; + + fhicl::Atom TimeWindow { + Name{ "TimeWindow" }, + Comment{ "" } // explain what this is, what's for and its unit + }; + + fhicl::Atom MultiWireBundle { + Name{ "MultiWireBundle" }, + Comment{ "" } // explain what this is and which database/table it's looking for + }; + + fhicl::Atom MWR_TimeWindow { + Name{ "MWR_TimeWindow" }, + Comment{ "" } // explain what this is, what's for and its unit + }; + + }; // Config + + using Parameters = art::EDProducer::Table; + + + explicit BNBRetriever(Parameters const& params); // The compiler-generated destructor is fine for non-base // classes without bare pointers or other resource use. @@ -77,13 +129,13 @@ class sbn::BNBRetriever : public art::EDProducer { }; -sbn::BNBRetriever::BNBRetriever(fhicl::ParameterSet const& p) - : EDProducer{p}, - fTimePad(p.get("TimePadding",0.0333)), //seconds - raw_data_label_(p.get("raw_data_label")), - fDeviceUsedForTiming(p.get("DeviceUsedForTiming")), - bfp( ifbeam_handle->getBeamFolder(p.get< std::string >("Bundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))), - bfp_mwr( ifbeam_handle->getBeamFolder(p.get< std::string >("MultiWireBundle"), p.get< std::string >("URL"), p.get< double >("MWR_TimeWindow"))) +sbn::BNBRetriever::BNBRetriever(Parameters const& params) + : EDProducer{params}, + fTimePad(params().TimePadding()), + raw_data_label_(params().RawDataLabel()), + fDeviceUsedForTiming(params().DeviceUsedForTiming()), + bfp( ifbeam_handle->getBeamFolder(params().Bundle(), params().URL(), params().TimeWindow())), + bfp_mwr( ifbeam_handle->getBeamFolder(params().MultiWireBundle(), params().URL(), params().MWR_TimeWindow())) { // how close in time does the spill time have to be from the DAQ time (in seconds). diff --git a/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc index dc10f43c7..06e04ee94 100644 --- a/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc @@ -14,7 +14,7 @@ #include "art/Framework/Principal/Run.h" #include "art/Framework/Principal/SubRun.h" #include "canvas/Utilities/InputTag.h" -#include "fhiclcpp/ParameterSet.h" +#include "fhiclcpp/types/Atom.h" #include "messagefacility/MessageLogger/MessageLogger.h" #include "lardata/Utilities/AssociationUtil.h" #include "lardataobj/Utilities/sparse_vector.h" @@ -41,7 +41,23 @@ namespace sbn { class sbn::EXTRetriever : public art::EDProducer { public: - explicit EXTRetriever(fhicl::ParameterSet const& p); + + struct Config { + + using Name = fhicl::Name; + using Comment = fhicl::Comment; + + fhicl::Atom RawDataLabel { + Name{ "raw_data_label" }, + Comment{ "art data product instance name for trigger information (product label is 'daq')" } + }; + + }; // Config + + using Parameters = art::EDProducer::Table; + + + explicit EXTRetriever(Parameters const& params); // The compiler-generated destructor is fine for non-base // classes without bare pointers or other resource use. @@ -66,9 +82,9 @@ class sbn::EXTRetriever : public art::EDProducer { }; -sbn::EXTRetriever::EXTRetriever(fhicl::ParameterSet const& p) - : EDProducer{p}, - raw_data_label_(p.get("raw_data_label")) +sbn::EXTRetriever::EXTRetriever(Parameters const& params) + : EDProducer{params}, + raw_data_label_(params().RawDataLabel()) { produces< std::vector< sbn::EXTCountInfo >, art::InSubRun >(); From 1d9c40b9ca0f46eeec33c3de199a664cf62ded50 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Thu, 1 Jul 2021 10:50:28 -0500 Subject: [PATCH 27/46] fixed int to double --- .../BNBRetriever/BNBRetriever_module.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 7353f5f37..c1483f72e 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -35,7 +35,6 @@ #include "MWRData.h" #include -#include #include namespace sbn { @@ -123,11 +122,11 @@ void sbn::BNBRetriever::produce(art::Event& e) gate_type = datastream_info.gate_type; number_of_gates_since_previous_event = frag.getDeltaGatesBNB(); - t_current_event = static_cast(artdaq_ts)/(1000000000); //check this offset... + t_current_event = static_cast(artdaq_ts)/(1000000000.0); //check this offset... if(gate_type == 1) t_previous_event = (static_cast(frag.getLastTimestampBNB()))/(1e9); else - t_previous_event = (static_cast(frag.getLastTimestampOther()))/(1000000000); + t_previous_event = (static_cast(frag.getLastTimestampOther()))/(1000000000.0); } @@ -192,7 +191,7 @@ void sbn::BNBRetriever::produce(art::Event& e) //Pull the MWR data for the device // these data are "packed" std::vector packed_MWR = bfp_mwr->GetNamedVector((t_previous_event)-fTimePad+double(0.5*t),var,&time_for_mwr); - + //We'll convert this into a format // that we can unpack doubles >> strings // @@ -202,9 +201,14 @@ void sbn::BNBRetriever::produce(art::Event& e) packed_data_str.append(var); packed_data_str.append(",,"); - for(auto const value: packed_MWR){ + /* for(auto const value: packed_MWR){ packed_data_str += ','; packed_data_str += std::to_string(int(value)); + }*/ + for(int j = 0; j < int(packed_MWR.size()); j++){ + packed_data_str += std::to_string(int(packed_MWR[j])); + if(j < int(packed_MWR.size())-1) + packed_data_str.append(","); } // Use Zarko's unpacking function to turn this into consumeable data @@ -216,8 +220,7 @@ void sbn::BNBRetriever::produce(art::Event& e) //There are four events that are packed into one MWR IFBeam entry for(std::size_t s: util::counter(unpacked_MWR_temp.size())){ - //for(int s = 0; s < int(unpacked_MWR_temp.size()); s++){ - + // If this entry has a unique time them store it for later if(std::find(MWR_times[dev].begin(), MWR_times[dev].end(), MWR_times_temp[s]) == MWR_times[dev].end()){ unpacked_MWR[dev].push_back(unpacked_MWR_temp[s]); From c437ad21e3e01fcc01574ff8084fa5a17b5f6de4 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Thu, 1 Jul 2021 10:52:10 -0500 Subject: [PATCH 28/46] added check on the sign of our time padding --- .../BNBRetriever/BNBRetriever_module.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index c1483f72e..541c6c7aa 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -85,7 +85,13 @@ sbn::BNBRetriever::BNBRetriever(fhicl::ParameterSet const& p) bfp( ifbeam_handle->getBeamFolder(p.get< std::string >("Bundle"), p.get< std::string >("URL"), p.get< double >("TimeWindow"))), bfp_mwr( ifbeam_handle->getBeamFolder(p.get< std::string >("MultiWireBundle"), p.get< std::string >("URL"), p.get< double >("MWR_TimeWindow"))) { - + + // Check fTimePad is positive + if (fTimePad < 0) { + throw art::Exception(art::errors::Configuration) + << "Parameter `TimePadding` must be non-negative (" << fTimePad << " was specified).\n"; + }//End Time check + // how close in time does the spill time have to be from the DAQ time (in seconds). // If these are too large then it fails to capture the device // If these are too small then the time jitter in devices means we miss good data From adde95b0b3424609086047dea6c21cabd2109914 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Thu, 1 Jul 2021 10:58:42 -0500 Subject: [PATCH 29/46] removed unneeded abs --- .../BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 541c6c7aa..a9ac67ff5 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -177,7 +177,8 @@ void sbn::BNBRetriever::produce(art::Event& e) // what we'll do is sort through all of them first and then // match them to the closest spills in time // - int t_steps = int(fabs((t_previous_event - fTimePad) - (t_current_event + fTimePad))/0.5)+25; + + int t_steps = int(((t_previous_event - fTimePad) - (t_current_event + fTimePad))/0.5)+25; for(int t = 0; t < t_steps; t++){//Iterate through time increments for (std::string const& var : vars) {// Iterate through the devices From 81853471ff27a1abd78d410b7dfd5982f67d5fd8 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Thu, 1 Jul 2021 11:02:08 -0500 Subject: [PATCH 30/46] added the MWR-toroid delay as a constant variable --- .../BNBRetriever/BNBRetriever_module.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index a9ac67ff5..8ee085cee 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -72,6 +72,8 @@ class sbn::BNBRetriever : public art::EDProducer { std::unique_ptr bfp; std::unique_ptr bfp_mwr; + static const double MWRtoroidDelay = -0.035; ///< the same time point is measured _t_ by MWR and _t + MWRtoroidDelay`_ by the toroid [ms] + }; @@ -223,7 +225,7 @@ void sbn::BNBRetriever::produce(art::Event& e) // There is a 35 ms offset between the toriod and the MWR times // we'll just remove that here to match to the spill times - std::vector< std::vector< int > > unpacked_MWR_temp = mwrdata.unpackMWR(packed_data_str,MWR_times_temp,-0.035); + std::vector< std::vector< int > > unpacked_MWR_temp = mwrdata.unpackMWR(packed_data_str,MWR_times_temp,MWRtoroidDelay); //There are four events that are packed into one MWR IFBeam entry for(std::size_t s: util::counter(unpacked_MWR_temp.size())){ From 2d46c0a7b417fa21fd2843a3d3bb95ae57922b73 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Tue, 6 Jul 2021 09:40:59 -0500 Subject: [PATCH 31/46] removed unneeded fcl commands --- sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl | 2 -- sbncode/BeamSpillInfoRetriever/job/run_extinfo_sbn.fcl | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl b/sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl index ec744270e..f1fa8fcf4 100644 --- a/sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl +++ b/sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl @@ -18,8 +18,6 @@ physics: { simulate: [bnbinfo ] stream1: [ out1 ] - trigger_paths: [ simulate ] - end_paths: [ stream1 ] } outputs: { diff --git a/sbncode/BeamSpillInfoRetriever/job/run_extinfo_sbn.fcl b/sbncode/BeamSpillInfoRetriever/job/run_extinfo_sbn.fcl index f3b66bbb4..88b6faa70 100644 --- a/sbncode/BeamSpillInfoRetriever/job/run_extinfo_sbn.fcl +++ b/sbncode/BeamSpillInfoRetriever/job/run_extinfo_sbn.fcl @@ -18,8 +18,7 @@ physics: { simulate: [extinfo ] stream1: [ out1 ] - trigger_paths: [ simulate ] - end_paths: [ stream1 ] + } outputs: { From d720f73435975c2ef626f702de7a240a9f135c20 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Tue, 6 Jul 2021 09:41:30 -0500 Subject: [PATCH 32/46] removed unneeded libraries --- .../BeamSpillInfoRetriever/EXTRetriever/CMakeLists.txt | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/EXTRetriever/CMakeLists.txt b/sbncode/BeamSpillInfoRetriever/EXTRetriever/CMakeLists.txt index 8ae5a6a7d..da9f9d198 100644 --- a/sbncode/BeamSpillInfoRetriever/EXTRetriever/CMakeLists.txt +++ b/sbncode/BeamSpillInfoRetriever/EXTRetriever/CMakeLists.txt @@ -7,19 +7,12 @@ include_directories( $ENV{IFDH_ART_INC} ) simple_plugin(EXTRetriever module ${ART_FRAMEWORK_CORE} ${ART_FRAMEWORK_SERVICES_REGISTRY} - ${ART_ROOT_IO_TFILESERVICE_SERVICE} ${ART_FRAMEWORK_SERVICES} + ${ART_FRAMEWORK_SERVICES} ${ART_FRAMEWORK_PRINCIPAL} art_Persistency_Common art_Utilities canvas - ${MF_MESSAGELOGGER} - ${MF_UTILITIES} ${FHICLCPP} cetlib cetlib_except - ${ROOT_EVE_LIB_LIST} - ${ROOT_X3d} - ${ROOT_BASIC_LIB_LIST} - ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_DATE_TIME_LIBRARY} ${Boost_SERIALIZATION_LIBRARY} - ${Boost_SYSTEM_LIBRARY} MF_MessageLogger sbnobj_Common_POTAccounting sbndaq-artdaq-core_Overlays_Common From 1145592e0edf9010b194100603a1ec00c3a92d47 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Tue, 6 Jul 2021 09:41:53 -0500 Subject: [PATCH 33/46] removed unneeded libraries --- sbncode/BeamSpillInfoRetriever/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/CMakeLists.txt b/sbncode/BeamSpillInfoRetriever/CMakeLists.txt index f92639eea..fba5bc1ff 100644 --- a/sbncode/BeamSpillInfoRetriever/CMakeLists.txt +++ b/sbncode/BeamSpillInfoRetriever/CMakeLists.txt @@ -2,10 +2,6 @@ add_subdirectory(BNBRetriever) add_subdirectory(EXTRetriever) add_subdirectory(job) -link_directories( - $ENV{ROOTSYS}/lib -) - install_headers() install_fhicl() install_source() From 3db554578b26bce7f9527299ec1c55ad5c96977c Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Tue, 6 Jul 2021 09:42:21 -0500 Subject: [PATCH 34/46] calling data product in a better way --- .../EXTRetriever/EXTRetriever_module.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc index 30a2dbf8b..767a042a4 100644 --- a/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc @@ -84,9 +84,7 @@ void sbn::EXTRetriever::produce(art::Event& e) // 3. the number of beam spills since the previously triggered event, number_of_gates_since_previous_event int gate_type = 0; - art::Handle< std::vector > raw_data_ptr; - e.getByLabel(raw_data_label_, "ICARUSTriggerUDP", raw_data_ptr); - auto const & raw_data = (*raw_data_ptr); + auto const & raw_data = e.getByLabel< std::vector >({ raw_data_label_, "ICARUSTriggerUDP" }); double number_of_gates_since_previous_event = 0; From 7720c3c33e4c39cc4b87bd4666cc36df9fb460ea Mon Sep 17 00:00:00 2001 From: Gianluca Petrillo Date: Tue, 6 Jul 2021 14:32:39 -0500 Subject: [PATCH 35/46] Change required by Clang. --- .../BNBRetriever/BNBRetriever_module.cc | 2 +- .../EXTRetriever/EXTRetriever_module.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 8ee085cee..9563baec9 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -72,7 +72,7 @@ class sbn::BNBRetriever : public art::EDProducer { std::unique_ptr bfp; std::unique_ptr bfp_mwr; - static const double MWRtoroidDelay = -0.035; ///< the same time point is measured _t_ by MWR and _t + MWRtoroidDelay`_ by the toroid [ms] + static constexpr double MWRtoroidDelay = -0.035; ///< the same time point is measured _t_ by MWR and _t + MWRtoroidDelay`_ by the toroid [ms] diff --git a/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc index 767a042a4..5da6fbf50 100644 --- a/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc @@ -53,8 +53,8 @@ class sbn::EXTRetriever : public art::EDProducer { // Required functions. void produce(art::Event& e) override; - void beginSubRun(art::SubRun& sr); - void endSubRun(art::SubRun& sr); + void beginSubRun(art::SubRun& sr) override; + void endSubRun(art::SubRun& sr) override; private: std::vector< sbn::EXTCountInfo > fOutExtInfos; From 03249c814a23d18d6029d6562275a6d95cf7782e Mon Sep 17 00:00:00 2001 From: Gianluca Petrillo Date: Tue, 6 Jul 2021 13:04:57 -0500 Subject: [PATCH 36/46] BNBRetriever: factorised produce() method into functional parts. --- .../BNBRetriever/BNBRetriever_module.cc | 295 ++++++++++++------ .../BNBRetriever/MWRData.cpp | 4 +- .../BNBRetriever/MWRData.h | 6 +- 3 files changed, 198 insertions(+), 107 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 9563baec9..cca9f835a 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -72,9 +72,54 @@ class sbn::BNBRetriever : public art::EDProducer { std::unique_ptr bfp; std::unique_ptr bfp_mwr; + struct TriggerInfo_t { + int gate_type = 0; ///< Source of the spill: `1`: BNB, `2`: NuMI + double t_current_event = 0; + double t_previous_event = 0; + double number_of_gates_since_previous_event = 0; // FIXME needs to be integral type + }; + + struct MWRdata_t { + std::vector< std::vector > MWR_times; + std::vector< std::vector< std::vector< int > > > unpacked_MWR; + }; + + static constexpr double MWRtoroidDelay = -0.035; ///< the same time point is measured _t_ by MWR and _t + MWRtoroidDelay`_ by the toroid [ms] + /// Returns the information of the trigger in the current event. + TriggerInfo_t extractTriggerInfo(art::Event const& e) const; + + /** + * @brief Determines spill times and extracts data based on multiwire devices. + * @param triggerInfo information from the trigger of this event + * @return times and unpacked data, per device (`"M875BB"`, `"M876BB"`, `"MMBTBB"`) + */ + MWRdata_t extractSpillTimes(TriggerInfo_t const& triggerInfo) const; + + /** + * @brief Matches spill times with multiwire chamber data from the database. + * @param triggerInfo information from the trigger of this event + * @param MWRdata data from multiwire chambers + * @param isFirstEventInRun whether we are processing the first event of the run + * @param[out] beamInfos container to _add_ spill information records to + * @return count of matched spills + */ + int matchMultiWireData( + TriggerInfo_t const& triggerInfo, + MWRdata_t const& MWRdata, bool isFirstEventInRun, + std::vector< sbn::BNBSpillInfo >& beamInfos + ) const; + /** + * @brief Assembles and returns a spill information record. + * @param time time of the spill + * @param MWRdata all extracted data from multiwire chambers + * @param matched_MWR data from multiwire chambers matched with the time + * @return a `sbn::BNBSpillInfo` object with information on the spill at `time` + */ + sbn::BNBSpillInfo makeBNBSpillInfo + (double time, MWRdata_t const& MWRdata, std::vector const& matched_MWR) const; }; @@ -105,21 +150,44 @@ sbn::BNBRetriever::BNBRetriever(fhicl::ParameterSet const& p) TotalBeamSpills = 0; } + void sbn::BNBRetriever::produce(art::Event& e) { + TriggerInfo_t const triggerInfo = extractTriggerInfo(e); + + //We only want to process BNB gates, i.e. type 1 + if(triggerInfo.gate_type != 1) return; + // Keep track of the number of beam gates the DAQ thinks + // are in this job + TotalBeamSpills += triggerInfo.number_of_gates_since_previous_event; + + + MWRdata_t const MWRdata = extractSpillTimes(triggerInfo); + + + int const spill_count = matchMultiWireData(triggerInfo, MWRdata, e.event() == 1, fOutbeamInfos); + + + if(spill_count > triggerInfo.number_of_gates_since_previous_event) + mf::LogDebug("BNBRetriever")<< "Event Spills : " << spill_count << ", DAQ Spills : " << triggerInfo.number_of_gates_since_previous_event << " \t \t ::: WRONG!"<< std::endl; + else + mf::LogDebug("BNBRetriever")<< "Event Spills : " << spill_count << ", DAQ Spills : " << triggerInfo.number_of_gates_since_previous_event << std::endl; + +}//end iteration over art::Events + + +sbn::BNBRetriever::TriggerInfo_t sbn::BNBRetriever::extractTriggerInfo(art::Event const& e) const { + //Here we read in the artdaq Fragments and extract three pieces of information: // 1. The time of the current event, t_current_event // 2. the time of the previously triggered event, t_previous_event (NOTE: Events are non-sequential!) // 3. the number of beam spills since the previously triggered event, number_of_gates_since_previous_event - int gate_type = 0; auto const & raw_data = e.getByLabel< std::vector >({ raw_data_label_, "ICARUSTriggerUDP" }); - - double t_current_event = 0; - double t_previous_event = 0; - double number_of_gates_since_previous_event = 0; + TriggerInfo_t triggerInfo; + for(auto raw_datum : raw_data){ uint64_t artdaq_ts = raw_datum.timestamp(); @@ -127,30 +195,29 @@ void sbn::BNBRetriever::produce(art::Event& e) std::string data = frag.GetDataString(); char *buffer = const_cast(data.c_str()); icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerString(buffer); - gate_type = datastream_info.gate_type; - number_of_gates_since_previous_event = frag.getDeltaGatesBNB(); + triggerInfo.gate_type = datastream_info.gate_type; + triggerInfo.number_of_gates_since_previous_event = frag.getDeltaGatesBNB(); - t_current_event = static_cast(artdaq_ts)/(1000000000.0); //check this offset... - if(gate_type == 1) - t_previous_event = (static_cast(frag.getLastTimestampBNB()))/(1e9); + triggerInfo.t_current_event = static_cast(artdaq_ts)/(1000000000.0); //check this offset... + if(triggerInfo.gate_type == 1) + triggerInfo.t_previous_event = (static_cast(frag.getLastTimestampBNB()))/(1e9); else - t_previous_event = (static_cast(frag.getLastTimestampOther()))/(1000000000.0); + triggerInfo.t_previous_event = (static_cast(frag.getLastTimestampOther()))/(1000000000.0); } - mf::LogDebug("BNBRetriever") << std::setprecision(19) << "Previous : " << t_previous_event << ", Current : " << t_current_event << std::endl; + mf::LogDebug("BNBRetriever") << std::setprecision(19) << "Previous : " << triggerInfo.t_previous_event << ", Current : " << triggerInfo.t_current_event << std::endl; - //We only want to process BNB gates, i.e. type 1 - if(gate_type != 1) return; - - // Keep track of the number of beam gates the DAQ thinks - // are in this job - TotalBeamSpills += number_of_gates_since_previous_event; + return triggerInfo; +} + + +sbn::BNBRetriever::MWRdata_t sbn::BNBRetriever::extractSpillTimes(TriggerInfo_t const& triggerInfo) const { // These lines get everything primed within the IFBeamDB // They seem redundant but they are needed - try{auto cur_vec_temp = bfp->GetNamedVector((t_previous_event)-fTimePad,"E:THCURR");} catch (WebAPIException &we) {} - try{auto packed_M876BB_temp = bfp_mwr->GetNamedVector((t_current_event)+fTimePad,"E:M875BB{4440:888}.RAW");} catch (WebAPIException &we) {} + try{auto cur_vec_temp = bfp->GetNamedVector((triggerInfo.t_previous_event)-fTimePad,"E:THCURR");} catch (WebAPIException &we) {} + try{auto packed_M876BB_temp = bfp_mwr->GetNamedVector((triggerInfo.t_current_event)+fTimePad,"E:M875BB{4440:888}.RAW");} catch (WebAPIException &we) {} //The multiwire chambers provide their @@ -180,7 +247,7 @@ void sbn::BNBRetriever::produce(art::Event& e) // match them to the closest spills in time // - int t_steps = int(((t_previous_event - fTimePad) - (t_current_event + fTimePad))/0.5)+25; + int t_steps = int(((triggerInfo.t_previous_event - fTimePad) - (triggerInfo.t_current_event + fTimePad))/0.5)+25; for(int t = 0; t < t_steps; t++){//Iterate through time increments for (std::string const& var : vars) {// Iterate through the devices @@ -199,7 +266,7 @@ void sbn::BNBRetriever::produce(art::Event& e) try{ //Pull the MWR data for the device // these data are "packed" - std::vector packed_MWR = bfp_mwr->GetNamedVector((t_previous_event)-fTimePad+double(0.5*t),var,&time_for_mwr); + std::vector packed_MWR = bfp_mwr->GetNamedVector((triggerInfo.t_previous_event)-fTimePad+double(0.5*t),var,&time_for_mwr); //We'll convert this into a format // that we can unpack doubles >> strings @@ -246,6 +313,17 @@ void sbn::BNBRetriever::produce(art::Event& e) }// Iterate over all the multiwire devices }// Iterate over all times + return { std::move(MWR_times), std::move(unpacked_MWR) }; +} + + +int sbn::BNBRetriever::matchMultiWireData( + TriggerInfo_t const& triggerInfo, + MWRdata_t const& MWRdata, bool isFirstEventInRun, + std::vector< sbn::BNBSpillInfo >& beamInfos +) const { + + auto const& [ MWR_times, unpacked_MWR ] = MWRdata; // alias //Here we will start collecting all the other beamline devices // First we get the times that the beamline device fired @@ -260,14 +338,14 @@ void sbn::BNBRetriever::produce(art::Event& e) // Need to handle the first event in a run differently - if(e.event() == 1){ + if(isFirstEventInRun){ //We'll remove the spills after our event int spills_after_our_target = 0; // iterate through all the spills to find the // spills that are after our triggered event for (size_t i = 0; i < times_temps.size(); i++) { - if(times_temps[i] > (t_current_event+fTimePad)){ + if(times_temps[i] > (triggerInfo.t_current_event+fTimePad)){ spills_after_our_target++; } }//end loop through spill times @@ -276,7 +354,7 @@ void sbn::BNBRetriever::produce(art::Event& e) times_temps.erase(times_temps.end()-spills_after_our_target,times_temps.end()); // Remove the spills before the start of our Run - times_temps.erase(times_temps.begin(),times_temps.end()-number_of_gates_since_previous_event); + times_temps.erase(times_temps.begin(),times_temps.end()-triggerInfo.number_of_gates_since_previous_event); }//end fix for "first event" @@ -287,9 +365,9 @@ void sbn::BNBRetriever::produce(art::Event& e) // plus or minus some time padding, currently using 3.3 ms // which is half the Booster Rep Rate - if(e.event() != 1){//We already addressed the "first event" above - if(times_temps[i] > (t_current_event+fTimePad)){continue;} - if(times_temps[i] <= (t_previous_event-fTimePad)){continue;} + if(!isFirstEventInRun){//We already addressed the "first event" above + if(times_temps[i] > (triggerInfo.t_current_event+fTimePad)){continue;} + if(times_temps[i] <= (triggerInfo.t_previous_event-fTimePad)){continue;} } //Loop through the multiwire devices: @@ -309,8 +387,8 @@ void sbn::BNBRetriever::produce(art::Event& e) //Check for a better match... for (size_t j = 0; j < times_temps.size(); j++) { if( j == i) continue; - if(times_temps[j] > (t_current_event+fTimePad)){continue;} - if(times_temps[j] <= (t_previous_event-fTimePad)){continue;} + if(times_temps[j] > (triggerInfo.t_current_event+fTimePad)){continue;} + if(times_temps[j] <= (triggerInfo.t_previous_event-fTimePad)){continue;} //is there a better match later in the spill sequence if(fabs((MWR_times[dev][mwrt] - times_temps[j])) < @@ -335,85 +413,98 @@ void sbn::BNBRetriever::produce(art::Event& e) //Great we found a matched spill! Let's count it spill_count++; - // initializing all of our device carriers - // device definitions can be found in BNBSpillInfo.h - - double TOR860 = 0; // units e12 protons - double TOR875 = 0; // units e12 protons - double LM875A = 0; // units R/s - double LM875B = 0; // units R/s - double LM875C = 0; // units R/s - double HP875 = 0; // units mm - double VP875 = 0; // units mm - double HPTG1 = 0; // units mm - double VPTG1 = 0; // units mm - double HPTG2 = 0; // units mm - double VPTG2 = 0; // units mm - double BTJT2 = 0; // units Deg C - double THCURR = 0; // units kiloAmps - - double TOR860_time = 0; // units s - - // Here we request all the devices - // since sometimes devices fail to report we'll - // allow each to throw an exception but still move forward - // interpreting these failures will be part of the beam quality analyses - try{bfp->GetNamedData(times_temps[i], "E:TOR860@",&TOR860,&TOR860_time);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:TOR875",&TOR875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:LM875A",&LM875A);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:LM875B",&LM875B);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:LM875C",&LM875C);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:HP875",&HP875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:VP875",&VP875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:HPTG1",&HPTG1);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:VPTG1",&VPTG1);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:HPTG2",&HPTG2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:VPTG2",&VPTG2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:BTJT2",&BTJT2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - try{bfp->GetNamedData(times_temps[i], "E:THCURR",&THCURR);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} - - //crunch the times - unsigned long int time_closest_int = (int) TOR860_time; - double time_closest_ns = (TOR860_time - time_closest_int)*1e9; - - //Store everything in our data-product - sbn::BNBSpillInfo beamInfo; - beamInfo.TOR860 = TOR860; - beamInfo.TOR875 = TOR875; - beamInfo.LM875A = LM875A; - beamInfo.LM875B = LM875B; - beamInfo.LM875C = LM875C; - beamInfo.HP875 = HP875; - beamInfo.VP875 = VP875; - beamInfo.HPTG1 = HPTG1; - beamInfo.VPTG1 = VPTG1; - beamInfo.HPTG2 = HPTG2; - beamInfo.VPTG2 = VPTG2; - beamInfo.BTJT2 = BTJT2; - beamInfo.THCURR = THCURR; - beamInfo.spill_time_s = time_closest_int; - beamInfo.spill_time_ns = time_closest_ns; - - beamInfo.M875BB = unpacked_MWR[0][matched_MWR[0]]; - beamInfo.M875BB_spill_time_diff = (MWR_times[0][matched_MWR[0]] - times_temps[i]); - beamInfo.M876BB = unpacked_MWR[1][matched_MWR[1]]; - beamInfo.M876BB_spill_time_diff = (MWR_times[1][matched_MWR[1]] - times_temps[i]); - beamInfo.MMBTBB = unpacked_MWR[2][matched_MWR[2]]; - beamInfo.MMBTBB_spill_time_diff = (MWR_times[2][matched_MWR[2]] - times_temps[i]); - - fOutbeamInfos.push_back(beamInfo); + sbn::BNBSpillInfo spillInfo = makeBNBSpillInfo(times_temps[i], MWRdata, matched_MWR); + + beamInfos.push_back(std::move(spillInfo)); // We do not write these to the art::Events because // we can filter events but want to keep all the POT // information, so we'll write it to the SubRun }//end iteration over beam device times - if(spill_count > number_of_gates_since_previous_event) - mf::LogDebug("BNBRetriever")<< "Event Spills : " << spill_count << ", DAQ Spills : " << number_of_gates_since_previous_event << " \t \t ::: WRONG!"<< std::endl; - else - mf::LogDebug("BNBRetriever")<< "Event Spills : " << spill_count << ", DAQ Spills : " << number_of_gates_since_previous_event << std::endl; + return spill_count; +} + + +sbn::BNBSpillInfo sbn::BNBRetriever::makeBNBSpillInfo + (double time, MWRdata_t const& MWRdata, std::vector const& matched_MWR) const +{ -}//end iteration over art::Events + auto const& [ MWR_times, unpacked_MWR ] = MWRdata; // alias + + // initializing all of our device carriers + // device definitions can be found in BNBSpillInfo.h + + double TOR860 = 0; // units e12 protons + double TOR875 = 0; // units e12 protons + double LM875A = 0; // units R/s + double LM875B = 0; // units R/s + double LM875C = 0; // units R/s + double HP875 = 0; // units mm + double VP875 = 0; // units mm + double HPTG1 = 0; // units mm + double VPTG1 = 0; // units mm + double HPTG2 = 0; // units mm + double VPTG2 = 0; // units mm + double BTJT2 = 0; // units Deg C + double THCURR = 0; // units kiloAmps + + double TOR860_time = 0; // units s + + // Here we request all the devices + // since sometimes devices fail to report we'll + // allow each to throw an exception but still move forward + // interpreting these failures will be part of the beam quality analyses + try{bfp->GetNamedData(time, "E:TOR860@",&TOR860,&TOR860_time);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(time, "E:TOR875",&TOR875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(time, "E:LM875A",&LM875A);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(time, "E:LM875B",&LM875B);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(time, "E:LM875C",&LM875C);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(time, "E:HP875",&HP875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(time, "E:VP875",&VP875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(time, "E:HPTG1",&HPTG1);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(time, "E:VPTG1",&VPTG1);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(time, "E:HPTG2",&HPTG2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(time, "E:VPTG2",&VPTG2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(time, "E:BTJT2",&BTJT2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";} + try{bfp->GetNamedData(time, "E:THCURR",&THCURR);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";} + + //crunch the times + unsigned long int time_closest_int = (int) TOR860_time; + double time_closest_ns = (TOR860_time - time_closest_int)*1e9; + + //Store everything in our data-product + sbn::BNBSpillInfo beamInfo; + beamInfo.TOR860 = TOR860; + beamInfo.TOR875 = TOR875; + beamInfo.LM875A = LM875A; + beamInfo.LM875B = LM875B; + beamInfo.LM875C = LM875C; + beamInfo.HP875 = HP875; + beamInfo.VP875 = VP875; + beamInfo.HPTG1 = HPTG1; + beamInfo.VPTG1 = VPTG1; + beamInfo.HPTG2 = HPTG2; + beamInfo.VPTG2 = VPTG2; + beamInfo.BTJT2 = BTJT2; + beamInfo.THCURR = THCURR; + beamInfo.spill_time_s = time_closest_int; + beamInfo.spill_time_ns = time_closest_ns; + + beamInfo.M875BB = unpacked_MWR[0][matched_MWR[0]]; + beamInfo.M875BB_spill_time_diff = (MWR_times[0][matched_MWR[0]] - time); + beamInfo.M876BB = unpacked_MWR[1][matched_MWR[1]]; + beamInfo.M876BB_spill_time_diff = (MWR_times[1][matched_MWR[1]] - time); + beamInfo.MMBTBB = unpacked_MWR[2][matched_MWR[2]]; + beamInfo.MMBTBB_spill_time_diff = (MWR_times[2][matched_MWR[2]] - time); + + // We do not write these to the art::Events because + // we can filter events but want to keep all the POT + // information, so we'll write it to the SubRun + + return beamInfo; +} + void sbn::BNBRetriever::beginSubRun(art::SubRun& sr) { diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.cpp b/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.cpp index e25036b3b..763a785c1 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.cpp +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.cpp @@ -10,7 +10,7 @@ using namespace std; namespace sbn{ - std::vector< std::vector < int > > MWRData::unpackMWR(std::string packed_data, std::vector &time_stamp, double timeoffset) + std::vector< std::vector < int > > MWRData::unpackMWR(std::string packed_data, std::vector &time_stamp, double timeoffset) const { std::vector > unpacked_data; @@ -42,7 +42,7 @@ namespace sbn{ return unpacked_data; } -MWRData::mwrpulse_t MWRData::getMWRdata(short* data, int nblock) +MWRData::mwrpulse_t MWRData::getMWRdata(short* data, int nblock) const { mwrpulse_t mwrdata; diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.h b/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.h index 91f96c34b..7ba75dfbb 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.h +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.h @@ -24,15 +24,15 @@ class MWRData swicheader_t sheader; } mwrpulse_t; - long flipByte(long data) + static long flipByte(long data) { return ((data>>16)&0x0000FFFF) | ((data<<16)&0xFFFF0000); } - mwrpulse_t getMWRdata(short* data, int nblock); + mwrpulse_t getMWRdata(short* data, int nblock) const; public: - std::vector< std::vector < int > > unpackMWR(std::string packed_data, std::vector &time_stamp, double timeoffset=0); + std::vector< std::vector < int > > unpackMWR(std::string packed_data, std::vector &time_stamp, double timeoffset=0) const; }; } From c705ab9e30408b3717dd288f53d7b733a295045f Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Wed, 22 Sep 2021 10:53:28 -0500 Subject: [PATCH 37/46] adding debug output --- .../job/run_bnbinfo_sbn.fcl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl b/sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl index f1fa8fcf4..5a438bc36 100644 --- a/sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl +++ b/sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl @@ -3,6 +3,21 @@ process_name: BNBInfoGen services:{ + + message: { + debugModules: [ "*" ] + destinations: { + LogDebugFile:{ + type: "file" + filename: "debug.log" + append: false + threshold: "DEBUG" + categories: { + default: {} + } + } + } + } IFBeam:{} } From 58a4a5624f0e201360accd6fc6c5ca578485b6a8 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Wed, 22 Sep 2021 10:53:52 -0500 Subject: [PATCH 38/46] more debugging --- .../BNBRetriever/BNBRetriever_module.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 8ee085cee..b9f964fcb 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -72,7 +72,7 @@ class sbn::BNBRetriever : public art::EDProducer { std::unique_ptr bfp; std::unique_ptr bfp_mwr; - static const double MWRtoroidDelay = -0.035; ///< the same time point is measured _t_ by MWR and _t + MWRtoroidDelay`_ by the toroid [ms] + static constexpr double MWRtoroidDelay = -0.035; ///< the same time point is measured _t_ by MWR and _t + MWRtoroidDelay`_ by the toroid [ms] @@ -358,6 +358,7 @@ void sbn::BNBRetriever::produce(art::Event& e) // since sometimes devices fail to report we'll // allow each to throw an exception but still move forward // interpreting these failures will be part of the beam quality analyses + mf::LogDebug("BNBRetriever")<< "Got Here!"; try{bfp->GetNamedData(times_temps[i], "E:TOR860@",&TOR860,&TOR860_time);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} try{bfp->GetNamedData(times_temps[i], "E:TOR875",&TOR875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} try{bfp->GetNamedData(times_temps[i], "E:LM875A",&LM875A);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} @@ -372,6 +373,8 @@ void sbn::BNBRetriever::produce(art::Event& e) try{bfp->GetNamedData(times_temps[i], "E:BTJT2",&BTJT2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} try{bfp->GetNamedData(times_temps[i], "E:THCURR",&THCURR);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << times_temps[i] << " " << "got exception: " << we.what() << "\n";} + mf::LogDebug("BNBRetriever")<< "cleared the block!" << std::endl; + //crunch the times unsigned long int time_closest_int = (int) TOR860_time; double time_closest_ns = (TOR860_time - time_closest_int)*1e9; @@ -394,13 +397,22 @@ void sbn::BNBRetriever::produce(art::Event& e) beamInfo.spill_time_s = time_closest_int; beamInfo.spill_time_ns = time_closest_ns; + mf::LogDebug("BNBRetriever")<< "All my devices? " << std::endl; + mf::LogDebug("BNBRetriever")<< "unpacked_MWR.size() = " << unpacked_MWR.size() << std::endl; + mf::LogDebug("BNBRetriever")<< "unpacked_MWR[0].size() = " << unpacked_MWR[0].size() << std::endl; + mf::LogDebug("BNBRetriever")<< "unpacked_MWR[1].size() = " << unpacked_MWR[1].size() << std::endl; + mf::LogDebug("BNBRetriever")<< "unpacked_MWR[2].size() = " << unpacked_MWR[2].size() << std::endl; + mf::LogDebug("BNBRetriever")<< "matched_MWR[0] = " << matched_MWR[0] << std::endl; + mf::LogDebug("BNBRetriever")<< "matched_MWR[1] = " << matched_MWR[1] << std::endl; + mf::LogDebug("BNBRetriever")<< "matched_MWR[2] = " << matched_MWR[2] << std::endl; + beamInfo.M875BB = unpacked_MWR[0][matched_MWR[0]]; beamInfo.M875BB_spill_time_diff = (MWR_times[0][matched_MWR[0]] - times_temps[i]); beamInfo.M876BB = unpacked_MWR[1][matched_MWR[1]]; beamInfo.M876BB_spill_time_diff = (MWR_times[1][matched_MWR[1]] - times_temps[i]); beamInfo.MMBTBB = unpacked_MWR[2][matched_MWR[2]]; beamInfo.MMBTBB_spill_time_diff = (MWR_times[2][matched_MWR[2]] - times_temps[i]); - + mf::LogDebug("BNBRetriever")<< "All my devices! " << std::endl; fOutbeamInfos.push_back(beamInfo); // We do not write these to the art::Events because // we can filter events but want to keep all the POT From 2430461d0616d9f25e3add852999cbcdc053c077 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Fri, 24 Sep 2021 09:07:02 -0500 Subject: [PATCH 39/46] Adding Gianluca fixes --- .../BNBRetriever/BNBRetriever_module.cc | 121 ++++++++++-------- 1 file changed, 69 insertions(+), 52 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 11e1ad899..52cecb259 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -17,17 +17,11 @@ #include "canvas/Utilities/InputTag.h" #include "fhiclcpp/types/Atom.h" #include "messagefacility/MessageLogger/MessageLogger.h" -#include "lardata/Utilities/AssociationUtil.h" -#include "lardataobj/Utilities/sparse_vector.h" -#include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" #include "larcorealg/CoreUtils/counter.h" -#include "larcorealg/Geometry/Exceptions.h" #include "artdaq-core/Data/Fragment.hh" #include "sbndaq-artdaq-core/Overlays/ICARUS/ICARUSTriggerUDPFragment.hh" -#include "lardataalg/DetectorInfo/DetectorPropertiesStandard.h" -#include "lardata/DetectorInfoServices/DetectorPropertiesService.h" #include "sbnobj/Common/POTAccounting/BNBSpillInfo.h" #include "IFBeam_service.h" @@ -36,6 +30,7 @@ #include #include +#include namespace sbn { class BNBRetriever; @@ -116,7 +111,7 @@ class sbn::BNBRetriever : public art::EDProducer { double fTimePad; std::string fURL; MWRData mwrdata; - std::string raw_data_label_; + std::string raw_data_label; std::string fDeviceUsedForTiming; unsigned int TotalBeamSpills; // @@ -128,7 +123,7 @@ class sbn::BNBRetriever : public art::EDProducer { int gate_type = 0; ///< Source of the spill: `1`: BNB, `2`: NuMI double t_current_event = 0; double t_previous_event = 0; - double number_of_gates_since_previous_event = 0; // FIXME needs to be integral type + unsigned int number_of_gates_since_previous_event = 0; // FIXME needs to be integral type }; struct MWRdata_t { @@ -178,7 +173,7 @@ class sbn::BNBRetriever : public art::EDProducer { sbn::BNBRetriever::BNBRetriever(Parameters const& params) : EDProducer{params}, fTimePad(params().TimePadding()), - raw_data_label_(params().RawDataLabel()), + raw_data_label(params().RawDataLabel()), fDeviceUsedForTiming(params().DeviceUsedForTiming()), bfp( ifbeam_handle->getBeamFolder(params().Bundle(), params().URL(), params().TimeWindow())), bfp_mwr( ifbeam_handle->getBeamFolder(params().MultiWireBundle(), params().URL(), params().MWR_TimeWindow())) @@ -193,10 +188,14 @@ sbn::BNBRetriever::BNBRetriever(Parameters const& params) // how close in time does the spill time have to be from the DAQ time (in seconds). // If these are too large then it fails to capture the device // If these are too small then the time jitter in devices means we miss good data + // + // These values should likely not be changed unless authors of the IFBeam API are consulted + // bfp->set_epsilon(0.02); //20 ms, this was tuned by hand and compared to IFBeamDB times - - bfp_mwr->set_epsilon(0.5); // TO BE TUNED! - bfp_mwr->setValidWindow(86400); + bfp_mwr->set_epsilon(0.5); + + //bfp_mwr->setValidWindow(86400); + bfp_mwr->setValidWindow(3605); produces< std::vector< sbn::BNBSpillInfo >, art::InSubRun >(); TotalBeamSpills = 0; } @@ -220,7 +219,7 @@ void sbn::BNBRetriever::produce(art::Event& e) int const spill_count = matchMultiWireData(triggerInfo, MWRdata, e.event() == 1, fOutbeamInfos); - if(spill_count > triggerInfo.number_of_gates_since_previous_event) + if(spill_count > int(triggerInfo.number_of_gates_since_previous_event)) mf::LogDebug("BNBRetriever")<< "Event Spills : " << spill_count << ", DAQ Spills : " << triggerInfo.number_of_gates_since_previous_event << " \t \t ::: WRONG!"<< std::endl; else mf::LogDebug("BNBRetriever")<< "Event Spills : " << spill_count << ", DAQ Spills : " << triggerInfo.number_of_gates_since_previous_event << std::endl; @@ -235,7 +234,7 @@ sbn::BNBRetriever::TriggerInfo_t sbn::BNBRetriever::extractTriggerInfo(art::Even // 2. the time of the previously triggered event, t_previous_event (NOTE: Events are non-sequential!) // 3. the number of beam spills since the previously triggered event, number_of_gates_since_previous_event - auto const & raw_data = e.getByLabel< std::vector >({ raw_data_label_, "ICARUSTriggerUDP" }); + auto const & raw_data = e.getByLabel< std::vector >({ raw_data_label, "ICARUSTriggerUDP" }); TriggerInfo_t triggerInfo; @@ -285,7 +284,7 @@ sbn::BNBRetriever::MWRdata_t sbn::BNBRetriever::extractSpillTimes(TriggerInfo_t // memory buffer increments // generally in the format: "E:.{Memory Block}" std::vector vars = bfp_mwr->GetDeviceList(); - + mf::LogDebug("BNBRetriever") << " Number of MWR Device Blocks Found : " << vars.size() << std::endl; // Tracking the time from the IFBeamDB double time_for_mwr; @@ -298,26 +297,32 @@ sbn::BNBRetriever::MWRdata_t sbn::BNBRetriever::extractSpillTimes(TriggerInfo_t // match them to the closest spills in time // - int t_steps = int(((triggerInfo.t_previous_event - fTimePad) - (triggerInfo.t_current_event + fTimePad))/0.5)+25; - + // int t_steps = int(((triggerInfo.t_previous_event - fTimePad) - (triggerInfo.t_current_event + fTimePad))/0.5)+25; + int t_steps = int(((triggerInfo.t_current_event + fTimePad) - (triggerInfo.t_previous_event - fTimePad - 20.))/0.5)+25; + mf::LogDebug("BNBRetriever") << " t_steps " << t_steps << std::endl; + for(int t = 0; t < t_steps; t++){//Iterate through time increments for (std::string const& var : vars) {// Iterate through the devices //Make sure we have a device - if(var.empty()) continue; - + if(var.empty()){ + mf::LogDebug("BNBRetriever") << " NO MWR DEVICES?!" << std::endl; + continue; + } /// Check the device name and interate the double-vector index if(var.find("M875BB") != std::string::npos ) dev = 0; else if(var.find("M876BB") != std::string::npos ) dev = 1; else if(var.find("MMBTBB") != std::string::npos ) dev = 2; - else{continue;} + else{ + mf::LogDebug("BNBRetriever") << " NOT matched to a MWR DEVICES?!" << var << std::endl; + continue;} time_for_mwr = 0; try{ //Pull the MWR data for the device // these data are "packed" - std::vector packed_MWR = bfp_mwr->GetNamedVector((triggerInfo.t_previous_event)-fTimePad+double(0.5*t),var,&time_for_mwr); + std::vector packed_MWR = bfp_mwr->GetNamedVector((triggerInfo.t_previous_event)-20.-fTimePad+double(0.5*t),var,&time_for_mwr); //We'll convert this into a format // that we can unpack doubles >> strings @@ -353,16 +358,22 @@ sbn::BNBRetriever::MWRdata_t sbn::BNBRetriever::extractSpillTimes(TriggerInfo_t unpacked_MWR[dev].push_back(unpacked_MWR_temp[s]); MWR_times[dev].push_back(MWR_times_temp[s]); }//check for unique time - }//Iterate through the unpacked events }//try catch (WebAPIException &we) { //Ignore when we can't find the MWR devices // they don't always report and the timing of them can be annoying - + }//catch }// Iterate over all the multiwire devices }// Iterate over all times + + mf::LogDebug("BNBRetriever") << " Number of MWR[0] times : " << MWR_times[0].size() << std::endl; + mf::LogDebug("BNBRetriever") << " Number of MWR[0]s : " << unpacked_MWR[0].size() << std::endl; + mf::LogDebug("BNBRetriever") << " Number of MWR[1] times : " << MWR_times[1].size() << std::endl; + mf::LogDebug("BNBRetriever") << " Number of MWR[1]s : " << unpacked_MWR[1].size() << std::endl; + mf::LogDebug("BNBRetriever") << " Number of MWR[2] times : " << MWR_times[2].size() << std::endl; + mf::LogDebug("BNBRetriever") << " Number of MWR[2]s : " << unpacked_MWR[2].size() << std::endl; return { std::move(MWR_times), std::move(unpacked_MWR) }; } @@ -405,7 +416,7 @@ int sbn::BNBRetriever::matchMultiWireData( times_temps.erase(times_temps.end()-spills_after_our_target,times_temps.end()); // Remove the spills before the start of our Run - times_temps.erase(times_temps.begin(),times_temps.end()-triggerInfo.number_of_gates_since_previous_event); + times_temps.erase(times_temps.begin(), times_temps.end() - std::min(int(triggerInfo.number_of_gates_since_previous_event), int(times_temps.size()))); }//end fix for "first event" @@ -421,6 +432,10 @@ int sbn::BNBRetriever::matchMultiWireData( if(times_temps[i] <= (triggerInfo.t_previous_event-fTimePad)){continue;} } + + //Great we found a matched spill! Let's count it + spill_count++; + //Loop through the multiwire devices: for(int dev = 0; dev < int(MWR_times.size()); dev++){ @@ -428,41 +443,38 @@ int sbn::BNBRetriever::matchMultiWireData( //Loop through the multiwire times: double Tdiff = 1000000000.; matched_MWR[dev] = 0; - bool best_match = false; + for(int mwrt = 0; mwrt < int(MWR_times[dev].size()); mwrt++){ - + //found a candidate match! - if(fabs((MWR_times[dev][mwrt] - times_temps[i])) < Tdiff){ - best_match = true; + if(fabs((MWR_times[dev][mwrt] - times_temps[i])) >= Tdiff){continue;} + + bool best_match = true; - //Check for a better match... - for (size_t j = 0; j < times_temps.size(); j++) { - if( j == i) continue; - if(times_temps[j] > (triggerInfo.t_current_event+fTimePad)){continue;} - if(times_temps[j] <= (triggerInfo.t_previous_event-fTimePad)){continue;} - - //is there a better match later in the spill sequence - if(fabs((MWR_times[dev][mwrt] - times_temps[j])) < - fabs((MWR_times[dev][mwrt] - times_temps[i]))){ - //we can have patience... - best_match = false; - break; - } - }//end better match check + //Check for a better match... + for (size_t j = 0; j < times_temps.size(); j++) { + if( j == i) continue; + if(times_temps[j] > (triggerInfo.t_current_event+fTimePad)){continue;} + if(times_temps[j] <= (triggerInfo.t_previous_event-fTimePad)){continue;} - //Verified best match! - if(best_match == true){ - matched_MWR[dev] = mwrt; - Tdiff = fabs((MWR_times[dev][mwrt] - times_temps[i])); - } - }//Find matches between + //is there a better match later in the spill sequence + if(fabs((MWR_times[dev][mwrt] - times_temps[j])) < + fabs((MWR_times[dev][mwrt] - times_temps[i]))){ + //we can have patience... + best_match = false; + break; + } + }//end better match check + + //Verified best match! + if(best_match == true){ + matched_MWR[dev] = mwrt; + Tdiff = fabs((MWR_times[dev][mwrt] - times_temps[i])); + } + }//end loop over MWR times }//end loop over MWR devices - - - //Great we found a matched spill! Let's count it - spill_count++; sbn::BNBSpillInfo spillInfo = makeBNBSpillInfo(times_temps[i], MWRdata, matched_MWR); @@ -543,6 +555,11 @@ sbn::BNBSpillInfo sbn::BNBRetriever::makeBNBSpillInfo beamInfo.spill_time_s = time_closest_int; beamInfo.spill_time_ns = time_closest_ns; + for(auto const& MWRdata: unpacked_MWR){ + std::ignore = MWRdata; + assert(!MWRdata.empty()); + } + beamInfo.M875BB = unpacked_MWR[0][matched_MWR[0]]; beamInfo.M875BB_spill_time_diff = (MWR_times[0][matched_MWR[0]] - time); beamInfo.M876BB = unpacked_MWR[1][matched_MWR[1]]; From 919904c06a9ce04e5ee76e919064f416ff1f2d31 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Fri, 24 Sep 2021 09:07:52 -0500 Subject: [PATCH 40/46] doubles aren't ints --- .../BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc index 9276566b3..c657aff99 100644 --- a/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc @@ -102,7 +102,7 @@ void sbn::EXTRetriever::produce(art::Event& e) int gate_type = 0; auto const & raw_data = e.getByLabel< std::vector >({ raw_data_label_, "ICARUSTriggerUDP" }); - double number_of_gates_since_previous_event = 0; + unsigned int number_of_gates_since_previous_event = 0; for(auto raw_datum : raw_data){ From 6bf5747c5febfd2dea69cba5a74ba8d25dcbb113 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Fri, 24 Sep 2021 09:08:12 -0500 Subject: [PATCH 41/46] remove extra configs --- sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl | 2 +- sbncode/BeamSpillInfoRetriever/job/run_extinfo_sbn.fcl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl b/sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl index 5a438bc36..34f8f689d 100644 --- a/sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl +++ b/sbncode/BeamSpillInfoRetriever/job/run_bnbinfo_sbn.fcl @@ -23,7 +23,7 @@ services:{ source: { - module_type: RootInput + } physics: { diff --git a/sbncode/BeamSpillInfoRetriever/job/run_extinfo_sbn.fcl b/sbncode/BeamSpillInfoRetriever/job/run_extinfo_sbn.fcl index 88b6faa70..e55cb29fe 100644 --- a/sbncode/BeamSpillInfoRetriever/job/run_extinfo_sbn.fcl +++ b/sbncode/BeamSpillInfoRetriever/job/run_extinfo_sbn.fcl @@ -8,7 +8,7 @@ services:{ source: { - module_type: RootInput + } physics: { From cd8f4e01a40a975b9b90f7a95bc74d3dfda571e0 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Fri, 24 Sep 2021 10:10:36 -0500 Subject: [PATCH 42/46] adding module label to cout --- sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.cpp b/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.cpp index 763a785c1..48d0bda3f 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.cpp +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/MWRData.cpp @@ -35,7 +35,7 @@ namespace sbn{ } } } else { - cout <<"Bad data!"< Date: Mon, 11 Oct 2021 15:26:27 -0500 Subject: [PATCH 43/46] sbndaq_artdaq_core version update --- CMakeLists.txt | 2 +- ups/product_deps | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e268929e..1f5274235 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ cmake_minimum_required(VERSION 3.19 FATAL_ERROR) -project(sbncode VERSION 09.32.01 LANGUAGES CXX) +project(sbncode VERSION 09.32.01.01 LANGUAGES CXX) message(STATUS "\n\n ========================== ${PROJECT_NAME} ==========================") diff --git a/ups/product_deps b/ups/product_deps index 9b3da92dc..10559ed6d 100644 --- a/ups/product_deps +++ b/ups/product_deps @@ -37,7 +37,7 @@ product version larsoft v09_32_01 sbnobj v09_12_03 sbnanaobj v09_17_01 -sbndaq_artdaq_core v0_07_09of1 +sbndaq_artdaq_core v0_07_09of2 genie_xsec v3_00_04a # list products required ONLY for the build From 30bbf7e9d3c896acb71076a89bab11fe6cb8de9e Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Wed, 13 Oct 2021 11:48:54 -0500 Subject: [PATCH 44/46] fixing cmake for new mrb --- CMakeLists.txt | 1 + .../BNBRetriever/CMakeLists.txt | 16 ++++++++++------ .../EXTRetriever/CMakeLists.txt | 8 ++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77344ba57..e0c688551 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,7 @@ find_ups_product(larpandora) find_ups_product(larsoft v09_00_00) find_ups_product(artdaq_core v3_06_01) find_ups_product(ifbeam) +find_ups_product(ifbeam_art) find_ups_product(libwda) find_ups_product(sbnobj v09_10_00) find_ups_product(sbndata v01_00) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/CMakeLists.txt b/sbncode/BeamSpillInfoRetriever/BNBRetriever/CMakeLists.txt index c01903bdb..998b076d3 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/CMakeLists.txt +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/CMakeLists.txt @@ -1,3 +1,5 @@ +find_ups_product(ifbeam) +find_ups_product(ifbeam_art) include_directories( $ENV{IFBEAM_FQ_DIR}/include ) include_directories( $ENV{LIBWDA_FQ_DIR}/include ) @@ -30,12 +32,14 @@ simple_plugin(BNBRetriever module ${Boost_SYSTEM_LIBRARY} MF_MessageLogger sbnobj_Common_POTAccounting - ${IFBEAMSERVICE} - ${IFBEAM} - sbndaq-artdaq-core_Overlays_Common - sbndaq-artdaq-core_Overlays - sbndaq-artdaq-core_Overlays_ICARUS - artdaq-core_Utilities + #${IFBEAMSERVICE} + #${IFBEAM} + ifbeam + ifdh_art::IFBeam_service + sbndaq_artdaq_core::sbndaq-artdaq-core_Overlays_Common + sbndaq_artdaq_core::sbndaq-artdaq-core_Overlays + sbndaq_artdaq_core::sbndaq-artdaq-core_Overlays_ICARUS + artdaq_core::artdaq-core_Utilities sbn_BNBSpillInfoRetriever_MWRData ) diff --git a/sbncode/BeamSpillInfoRetriever/EXTRetriever/CMakeLists.txt b/sbncode/BeamSpillInfoRetriever/EXTRetriever/CMakeLists.txt index da9f9d198..4a3ceaf46 100644 --- a/sbncode/BeamSpillInfoRetriever/EXTRetriever/CMakeLists.txt +++ b/sbncode/BeamSpillInfoRetriever/EXTRetriever/CMakeLists.txt @@ -15,10 +15,10 @@ simple_plugin(EXTRetriever module cetlib cetlib_except MF_MessageLogger sbnobj_Common_POTAccounting - sbndaq-artdaq-core_Overlays_Common - sbndaq-artdaq-core_Overlays - sbndaq-artdaq-core_Overlays_ICARUS - artdaq-core_Utilities + sbndaq_artdaq_core::sbndaq-artdaq-core_Overlays_Common + sbndaq_artdaq_core::sbndaq-artdaq-core_Overlays + sbndaq_artdaq_core::sbndaq-artdaq-core_Overlays_ICARUS + artdaq_core::artdaq-core_Utilities ) install_headers() From ccd72107a4ad253af5d511ac34ba95c03e215b99 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Wed, 13 Oct 2021 11:49:15 -0500 Subject: [PATCH 45/46] switch to getProduct --- .../BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc | 2 +- .../BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc index 52cecb259..9e954f1b2 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/BNBRetriever_module.cc @@ -234,7 +234,7 @@ sbn::BNBRetriever::TriggerInfo_t sbn::BNBRetriever::extractTriggerInfo(art::Even // 2. the time of the previously triggered event, t_previous_event (NOTE: Events are non-sequential!) // 3. the number of beam spills since the previously triggered event, number_of_gates_since_previous_event - auto const & raw_data = e.getByLabel< std::vector >({ raw_data_label, "ICARUSTriggerUDP" }); + auto const & raw_data = e.getProduct< std::vector >({ raw_data_label, "ICARUSTriggerUDP" }); TriggerInfo_t triggerInfo; diff --git a/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc b/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc index c657aff99..77d0661e1 100644 --- a/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc +++ b/sbncode/BeamSpillInfoRetriever/EXTRetriever/EXTRetriever_module.cc @@ -100,7 +100,7 @@ void sbn::EXTRetriever::produce(art::Event& e) // 3. the number of beam spills since the previously triggered event, number_of_gates_since_previous_event int gate_type = 0; - auto const & raw_data = e.getByLabel< std::vector >({ raw_data_label_, "ICARUSTriggerUDP" }); + auto const & raw_data = e.getProduct< std::vector >({ raw_data_label_, "ICARUSTriggerUDP" }); unsigned int number_of_gates_since_previous_event = 0; From c0ac3b87ed92bef6a7b4f6f5f0c2f4e5ec72ee61 Mon Sep 17 00:00:00 2001 From: Joseph Zennamo Date: Fri, 15 Oct 2021 09:34:57 -0500 Subject: [PATCH 46/46] fixing boost for c7 --- CMakeLists.txt | 1 + sbncode/BeamSpillInfoRetriever/BNBRetriever/CMakeLists.txt | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0c688551..0c4c211d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,7 @@ find_ups_product(sbndata v01_00) find_ups_product(ifdhc) find_ups_product(ifdh_art) find_ups_product(log4cpp) +find_ups_boost() find_ups_root() #find_ups_product(sbndcode v06_67_00) #find_ups_product(uboonecode v06_67_00) diff --git a/sbncode/BeamSpillInfoRetriever/BNBRetriever/CMakeLists.txt b/sbncode/BeamSpillInfoRetriever/BNBRetriever/CMakeLists.txt index 998b076d3..99ec10d90 100644 --- a/sbncode/BeamSpillInfoRetriever/BNBRetriever/CMakeLists.txt +++ b/sbncode/BeamSpillInfoRetriever/BNBRetriever/CMakeLists.txt @@ -8,6 +8,8 @@ include_directories( $ENV{IFDH_ART_INC} ) cet_find_library( IFBEAMSERVICE NAMES IFBeam_service PATHS ENV IFDH_ART_LIB NO_DEFAULT_PATH ) cet_find_library( IFBEAM NAMES ifbeam PATHS ENV IFBEAM_LIB NO_DEFAULT_PATH ) +link_libraries( ${LIB_NAME} -L$ENV{BOOST_LIB} -lboost_system ${ROOTLIB} ) + art_make_library( LIBRARY_NAME sbn_BNBSpillInfoRetriever_MWRData SOURCE MWRData.cpp