19 #include "GaudiKernel/ConcurrencyFlags.h"
28 base_class(
name, pSvcLocator ),
30 m_moduleName(
"libTrigInDetCUDA.so"),
31 m_useITkGeometry(false),
35 m_detStore(
"DetectorStore",
name),
36 m_evtStore(
"StoreGateSvc",
name),
37 m_factoryConfigured(false) {
39 declareProperty(
"NumberOfDCs",
m_nDCs = 8 );
40 declareProperty(
"ModuleName",
m_moduleName =
"libTrigInDetCUDA.so");
42 declareProperty(
"MiddleSpacePointLayers",
m_middleSpacePointLayers = std::vector<int>(),
"Global IDs of layers that can contain middle spacepoints of track seeds" );
62 ATH_MSG_INFO(
"TrigInDetAccelerationSvc: cannot load the factory library, error:"<<dlerror());
63 return StatusCode::SUCCESS;
75 int factory_id_to_load = 0;
86 ATH_MSG_INFO(
"OffloadFactory with id "<<std::hex<<factory_id_to_load<<
" not available from the module");
88 return StatusCode::SUCCESS;
96 return StatusCode::SUCCESS;
111 SmartIF<IIncidentSvc> incsvc{service(
"IncidentSvc")};
114 const bool is_multiprocess = (Gaudi::Concurrency::ConcurrencyFlags::numProcs() > 0);
115 if (is_multiprocess) {
119 incsvc->addListener(
this,
"BeginRun",
priority);
123 return StatusCode::SUCCESS;
135 return StatusCode::SUCCESS;
149 std::map<std::tuple<short,short, int, int>,std::vector<PhiEtaHash> > hashMap;
161 std::map<std::tuple<short,short,short>,std::vector<PhiEtaHash> > hashMap;
191 if (i<0 || i>2)
i = 0;
199 if (
m_detStore->retrieve(pix_mgr,
"ITkPixel").isFailure()) {
207 const size_t bufferOffset = 256;
208 size_t totalSize = bufferOffset + dataTypeSize;
217 memset(pArray,0,dataTypeSize);
219 int nLayers = (
int)hashMap.size();
224 int middleLayerIdx=0;
226 for(std::map<std::tuple<short,short, int, int>,std::vector<PhiEtaHash> >::const_iterator
it = hashMap.begin();
it!=hashMap.end();++
it, layerIdx++) {
228 short barrel_ec = std::get<0>((*it).first);
229 int vol_id = std::get<2>((*it).first);
230 int lay_id = std::get<3>((*it).first);
231 if(barrel_ec == -100) barrel_ec = 0;
232 int globalLayerId = vol_id*1000 + lay_id;
244 std::vector<std::vector<PhiEtaHash>::const_iterator> vStops;
245 vStops.push_back((*it).second.begin());
246 std::vector<PhiEtaHash>::const_iterator firstIt = (*it).second.begin();
247 std::vector<PhiEtaHash>::const_iterator nextIt = (*it).second.begin();
252 for(; nextIt!=(*it).second.end();++nextIt, ++firstIt) {
253 if((*nextIt).m_phiIndex!=(*firstIt).m_phiIndex) {
254 vStops.push_back(nextIt);
261 vStops.push_back((*it).second.end());
264 float minBound = 100000.0;
265 float maxBound =-100000.0;
271 for(
unsigned int iStops = 1; iStops<vStops.size();iStops++) {
275 for(std::vector<PhiEtaHash>::const_iterator hIt = vStops[iStops-1];hIt!=vStops[iStops];++hIt, nPhiModules++) {
287 if (barrel_ec == 0) {
288 rc += sqrt(
C(0)*
C(0)+
C(1)*
C(1));
289 if(
p->zMin() < minBound) minBound =
p->zMin();
290 if(
p->zMax() > maxBound) maxBound =
p->zMax();
295 if(
p->rMin() < minBound) minBound =
p->rMin();
296 if(
p->rMax() > maxBound) maxBound =
p->rMax();
310 std::shared_ptr<TrigAccel::OffloadBuffer> pDMBuff = std::make_shared<TrigAccel::OffloadBuffer>(pBG);
325 const PixelID* pixelId =
nullptr;
327 if (
m_detStore->retrieve(pixelId,
"PixelID").isFailure()) {
338 if(offlineId==0)
continue;
340 short barrel_ec = pixelId->
barrel_ec(offlineId);
341 if(abs(barrel_ec)>2)
continue;
343 short phi_index = pixelId->
phi_module(offlineId);
345 short layer_disk = pixelId->
layer_disk(offlineId);
349 if (barrel_ec== 0) vol_id = 8;
350 if (barrel_ec==-2) vol_id = 7;
351 if (barrel_ec== 2) vol_id = 9;
353 int new_vol=0, new_lay=0;
355 if (vol_id == 7 || vol_id == 9) {
356 new_vol = 10*vol_id + layer_disk;
358 }
else if (vol_id == 8) {
360 new_vol = 10*vol_id + layer_disk;
363 auto t = std::make_tuple(barrel_ec==0 ? -100 : barrel_ec, subdetid, new_vol, new_lay);
364 std::map<std::tuple<short,short,int,int>,std::vector<PhiEtaHash> >
::iterator it = hashMap.find(
t);
365 if(
it==hashMap.end())
366 hashMap.insert(std::pair<std::tuple<short,short,int,int>,std::vector<PhiEtaHash> >(
t,std::vector<PhiEtaHash>(1,
PhiEtaHash(phi_index,
eta_index,
hash) )));
378 for(std::map<std::tuple<short,short,int,int>,std::vector<PhiEtaHash> >::
iterator it = hashMap.begin();
it!=hashMap.end();++
it, layerId++) {
380 short barrel_ec = std::get<0>((*it).first);
381 short subdetId = std::get<1>((*it).first);
382 if(barrel_ec == -100) barrel_ec = 0;
393 for(std::map<std::tuple<short,short,int,int>,std::vector<PhiEtaHash> >::
iterator it = hashMap.begin();
it!=hashMap.end();++
it) {
409 if (
m_detStore->retrieve(sct_mgr,
"SCT").isFailure()) {
414 if (
m_detStore->retrieve(pix_mgr,
"Pixel").isFailure()) {
422 const size_t bufferOffset = 256;
423 size_t totalSize = bufferOffset + dataTypeSize;
432 memset(pArray,0,dataTypeSize);
434 int nLayers = (
int)hashMap.size();
440 for(std::map<std::tuple<short,short,short>,std::vector<PhiEtaHash> >::const_iterator
it = hashMap.begin();
it!=hashMap.end();++
it, layerIdx++) {
441 short subdetid = std::get<0>((*it).first);
442 short barrel_ec = std::get<1>((*it).first);
448 std::vector<std::vector<PhiEtaHash>::const_iterator> vStops;
449 vStops.push_back((*it).second.begin());
450 std::vector<PhiEtaHash>::const_iterator firstIt = (*it).second.begin();
451 std::vector<PhiEtaHash>::const_iterator nextIt = (*it).second.begin();
456 for(; nextIt!=(*it).second.end();++nextIt, ++firstIt) {
457 if((*nextIt).m_phiIndex!=(*firstIt).m_phiIndex) {
458 vStops.push_back(nextIt);
465 vStops.push_back((*it).second.end());
468 float minBound = 100000.0;
469 float maxBound =-100000.0;
475 for(
unsigned int iStops = 1; iStops<vStops.size();iStops++) {
481 for(std::vector<PhiEtaHash>::const_iterator hIt = vStops[iStops-1];hIt!=vStops[iStops];++hIt, nPhiModules++) {
495 rc += sqrt(
C(0)*
C(0)+
C(1)*
C(1));
496 if(
p->zMin() < minBound) minBound =
p->zMin();
497 if(
p->zMax() > maxBound) maxBound =
p->zMax();
503 if(
p->rMin() < minBound) minBound =
p->rMin();
504 if(
p->rMax() > maxBound) maxBound =
p->rMax();
518 std::shared_ptr<TrigAccel::OffloadBuffer> pDMBuff = std::make_shared<TrigAccel::OffloadBuffer>(pBG);
533 const PixelID* pixelId =
nullptr;
534 const SCT_ID* sctId =
nullptr;
536 if (
m_detStore->retrieve(pixelId,
"PixelID").isFailure()) {
541 if (
m_detStore->retrieve(sctId,
"SCT_ID").isFailure()) {
552 if(offlineId==0)
continue;
554 short barrel_ec = pixelId->
barrel_ec(offlineId);
555 if(abs(barrel_ec)>2)
continue;
556 short layer_disk = pixelId->
layer_disk(offlineId);
557 short phi_index = pixelId->
phi_module(offlineId);
559 auto t = std::make_tuple(subdetid, barrel_ec, layer_disk);
560 std::map<std::tuple<short,short,short>,std::vector<PhiEtaHash> >
::iterator it = hashMap.find(
t);
561 if(
it==hashMap.end())
562 hashMap.insert(std::pair<std::tuple<short,short,short>,std::vector<PhiEtaHash> >(
t,std::vector<PhiEtaHash>(1,
PhiEtaHash(phi_index,
eta_index,
hash) )));
570 if(offlineId==0)
continue;
572 short barrel_ec = sctId->
barrel_ec(offlineId);
573 short layer_disk = sctId->
layer_disk(offlineId);
574 short phi_index = sctId->
phi_module(offlineId);
577 auto t = std::make_tuple(subdetid, barrel_ec, layer_disk);
578 std::map<std::tuple<short,short,short>,std::vector<PhiEtaHash> >
::iterator it = hashMap.find(
t);
579 if(
it==hashMap.end())
580 hashMap.insert(std::pair<std::tuple<short,short,short>,std::vector<PhiEtaHash> >(
t,std::vector<PhiEtaHash>(1,
PhiEtaHash(phi_index,
eta_index,
hash))));
589 for(std::map<std::tuple<short,short,short>,std::vector<PhiEtaHash> >::
iterator it = hashMap.begin();
it!=hashMap.end();++
it, layerId++) {
591 short subdetId = std::get<0>((*it).first);
592 short barrel_ec = std::get<1>((*it).first);
609 for(std::map<std::tuple<short,short,short>,std::vector<PhiEtaHash> >::
iterator it = hashMap.begin();
it!=hashMap.end();++
it) {