177 opDetDigitizerWorker::Config wConfig( config().pmtAlgoConfig(), config().araAlgoConfig());
181 const char *env = std::getenv(
"SBNDCODE_OPDETSIM_NTHREADS");
185 int n_threads = std::stoi(env);
186 if (n_threads <= 0) {
187 throw std::invalid_argument(
"Expect positive integer");
192 mf::LogError(
"OpDetDigitizer") <<
"Unable to parse number of threads "
193 <<
"in environment variable (SBNDCODE_OPDETSIM_NTHREADS): (" << env <<
").\n"
194 <<
"Setting Number opdet threads to 1." << std::endl;
201 fNThreads = std::thread::hardware_concurrency();
206 mf::LogInfo(
"OpDetDigitizer") <<
"Digitizing on n threads: " <<
fNThreads << std::endl;
210 wConfig.UseSimPhotonsLite = config().UseSimPhotonsLite();
211 wConfig.InputModuleName = config().InputModuleName();
213 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
214 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob(clockData);
215 wConfig.Sampling = (clockData.OpticalClock().Frequency()) / 1000.0;
216 wConfig.Sampling_Daphne = config().araAlgoConfig().DaphneFrequency() / 1000.0;
218 wConfig.Nsamples = (wConfig.EnableWindow[1] - wConfig.EnableWindow[0]) * 1000. * wConfig.Sampling ;
219 wConfig.Nsamples_Daphne = (wConfig.EnableWindow[1] - wConfig.EnableWindow[0]) * 1000. * wConfig.Sampling_Daphne ;
225 for (
unsigned i = 0; i <
fNThreads; i++) {
227 art::ServiceHandle<rndm::NuRandomService> seedSvc;
228 CLHEP::HepJamesRandom *engine =
new CLHEP::HepJamesRandom;
229 seedSvc->registerEngine(rndm::NuRandomService::CLHEPengineSeeder(engine),
"opDetDigitizerSBND" +
std::to_string(i));
251 produces< std::vector< raw::OpDetWaveform > >();
std::vector< art::Handle< std::vector< sim::SimPhotons > > > fPhotonHandles
void opDetDigitizerWorkerThread(const opDetDigitizerWorker &worker, detinfo::DetectorClocksData const &clockData, opDetDigitizerWorker::Semaphore &sem_start, opDetDigitizerWorker::Semaphore &sem_finish, bool ApplyTriggerLocations, bool *finished)
std::vector< opdet::opDetDigitizerWorker > fWorkers
std::array< double, 2 > TriggerEnableWindow(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp) const
std::vector< art::Handle< std::vector< sim::SimPhotonsLite > > > fPhotonLiteHandles
unsigned fArapucaBaseline
opdet::opDetDigitizerWorker::Semaphore fSemStart
opdet::opDetDigitizerWorker::Semaphore fSemFinish
std::string to_string(WindowPattern const &pattern)
std::vector< std::thread > fWorkerThreads
std::vector< raw::OpDetWaveform > fWaveforms
std::vector< std::vector< raw::OpDetWaveform > > fTriggeredWaveforms
opdet::opDetSBNDTriggerAlg fTriggerAlg