19 : fLogLevel(1), fNASICsPerBoard(1), fNBoardsPerAPA(1), fServiceName(
"HardwareMapperService") {
23 const std::string func_name =
"HardwareMapperService";
26 loginfo << func_name <<
"\n" 41 const std::string func_name =
"checkGeomVsFileDetectorName";
59 if(fDetectorNameFromGeometry != fDetectorNameFromFile){
60 throw cet::exception(
"HardwareMapperService") <<
"Detector Name missmatch!\n" 61 <<
"Detector Name from Geometry Service: " << fDetectorNameFromGeometry <<
"\n" 62 <<
"Detector Name from File: " << fDetectorNameFromFile <<
"\n" 63 <<
"This means that the HardwareMapperService is filled with information for the wrong Geometry\n" 64 <<
"Throwing an exception as the user should make sure the Geometry in their fcl and that used to produce their file match\n";
74 if(
fLogLevel>1||
true) loginfo <<
"In Function: " << func_name <<
"\n";
76 loginfo <<
"Filling ASIC Map - fNASICsPerBoard: " <<
fNASICsPerBoard <<
"\n";
78 if(
fLogLevel>0) loginfo <<
"Looping over Boards" <<
"\n";
82 std::shared_ptr<Hardware::Board> board_ptr = id_board_pair.second;
84 if(
fLogLevel>0) loginfo << *board_ptr <<
"\n";
86 unsigned int channels_in_this_asic = 0;
87 unsigned int max_channels_in_asic = board_ptr->getNChannels() /
fNASICsPerBoard;
89 if(
fLogLevel>1) loginfo <<
"current_asic_id: " << current_asic_id <<
"\n";
92 std::shared_ptr<Hardware::ASIC> this_asic_ptr = std::shared_ptr<Hardware::ASIC>(
new Hardware::ASIC(current_asic_id));
94 if(
fLogLevel>1) loginfo <<
"Creating new asic" 95 <<
" registered to Board: " << board_ptr->getID()
96 <<
"- This Board has: " << board_ptr->getNHardwareIDs()
97 <<
" pieces of hardware" 100 if(
fLogLevel>1) loginfo <<
"Looping over channels" <<
"\n";
102 for(
auto channel : board_ptr->getChannels()){
103 if(channels_in_this_asic >= max_channels_in_asic){
104 if(
fLogLevel>1) loginfo <<
"Need new asic - current_asic_id: " << current_asic_id
105 <<
" channels_in_this_asic: " << channels_in_this_asic
106 <<
"/" << max_channels_in_asic
110 fASICMap[this_asic_ptr->getID()] = this_asic_ptr;
112 channels_in_this_asic=0;
114 if(
fLogLevel>1) loginfo <<
"Last ASIC: " << *this_asic_ptr <<
"\n\n";
116 this_asic_ptr=std::shared_ptr<Hardware::ASIC>(
new Hardware::ASIC(current_asic_id));
119 if(
fLogLevel>1) loginfo <<
"Creating new asic" 120 <<
" registered to Board: " << board_ptr->getID()
121 <<
"- This Board has: " << board_ptr->getNHardwareIDs()
122 <<
" pieces of hardware" 125 this_asic_ptr->addChannel(
channel);
126 channels_in_this_asic++;
129 if(
fLogLevel>1) loginfo <<
"Finished channel loop\n" 130 <<
"current_asic_id: " << current_asic_id
131 <<
" channels_in_this_asic: " << channels_in_this_asic
132 <<
"/" << max_channels_in_asic
134 fASICMap[this_asic_ptr->getID()] = this_asic_ptr;
136 if(
fLogLevel>0) loginfo <<
"Finished this Board\n" 137 << *board_ptr <<
"\n" 138 <<
"Total ASICs in fASICMap: " <<
getNASICs() <<
"\n" 139 <<
"-----------------------\n\n";
141 loginfo <<
"Finished filling ASIC Map\n" 142 <<
"Filled: " <<
getNASICs() <<
" ASICs";
153 loginfo <<
"Filling Board Map - fNBoardsPerAPA: " <<
fNBoardsPerAPA <<
"\n";
156 if(
fLogLevel>0) loginfo <<
"Looping over apas" <<
"\n";
159 for(
auto id_apa_pair:
fAPAMap){
161 std::shared_ptr<Hardware::APA> apa_ptr = id_apa_pair.second;
163 unsigned int max_channels_in_board = apa_ptr->getNChannels() /
fNBoardsPerAPA;
171 std::vector< std::shared_ptr<Hardware::Board> > BoardsFromAPA;
172 std::vector< TVector3 > ZPosOfColWires;
177 BoardsFromAPA .push_back( std::shared_ptr<Hardware::Board>(
new Hardware::Board( current_board_id )) );
178 ZPosOfColWires.push_back( {DBL_MAX, -DBL_MAX, -1} );
179 std::cout <<
"Creating a new board with id " << FirstBoard+cb <<
" - " << BoardsFromAPA[ cb ]->getID() <<
" on APA " << apa_ptr->getID() <<
std::endl;
185 if(
fLogLevel>1) loginfo <<
"Looping over channels" <<
"\n";
189 double ThisAPA_MinZ = DBL_MAX;
190 double ThisAPA_MaxZ = -DBL_MAX;
192 for(
auto channel : apa_ptr->getChannels()) {
196 double WireSt[3], WireEn[3];
198 if (WireSt[2] < ThisAPA_MinZ ) ThisAPA_MinZ = WireSt[2];
199 if (WireSt[2] > ThisAPA_MaxZ ) ThisAPA_MaxZ = WireSt[2];
203 if (TotColWires%fNBoardsPerAPA != 0) {
204 throw cet::exception(
"HardwareMapperService") <<
"The number of collection plane wires doesn't divide evenly. There are " << TotColWires <<
" col wires," 205 <<
" and you want " << fNBoardsPerAPA <<
", leaving a remainder of " << TotColWires%fNBoardsPerAPA <<
" wires.";
207 std::cout <<
" There are " << TotColWires <<
" collection plane wires on this APA." 208 <<
" Each board will have " << NumColWiresPerBoard <<
" collection plane wires, and " << max_channels_in_board - TotColWires/fNBoardsPerAPA <<
" ind wires." 209 <<
" The wires go from " << ThisAPA_MinZ <<
" to " << ThisAPA_MaxZ <<
".\n" 213 int NumColPush = 0, PushToBoard = 0;
214 for(
auto channel : apa_ptr->getChannels()) {
217 double WireSt[3], WireEn[3];
219 BoardsFromAPA[ PushToBoard ]->addChannel(
channel);
221 if( WireSt[2] < ZPosOfColWires[ PushToBoard ][0] ) ZPosOfColWires[ PushToBoard ][0] = WireSt[2];
222 if( WireEn[2] > ZPosOfColWires[ PushToBoard ][1] ) ZPosOfColWires[ PushToBoard ][1] = WireEn[2];
233 if ( NumColPush%NumColWiresPerBoard == 0 ) {
239 std::cout <<
" Looking at board " << BoardsFromAPA[ nn ]->getID() <<
", in TPC " << ZPosOfColWires[ nn ][2]
240 <<
" the extremes are " << ZPosOfColWires[ nn ][0] <<
" - " << ZPosOfColWires[ nn ][1] <<
std::endl;
246 for(
auto channel : apa_ptr->getChannels()) {
252 double WireSt[3], WireEn[3];
262 if ( (
abs(WireSt[1]) > 600 && WireSt[2] > ZPosOfColWires[
nb][0] && WireSt[2] < ZPosOfColWires[
nb][1] ) ||
263 (
abs(WireEn[1]) > 600 && WireEn[2] > ZPosOfColWires[
nb][0] && WireEn[2] < ZPosOfColWires[
nb][1] ) ) {
264 BoardsFromAPA[
nb ]->addChannel(
channel);
278 unsigned int ThisID = BoardsFromAPA[ cb ]->getID();
279 fBoardMap[ ThisID ] = BoardsFromAPA[ cb ];
280 std::cout <<
"Adding board " << BoardsFromAPA[ cb ]->getID() <<
" to APA " << apa_ptr->getID()
281 <<
", it has " << BoardsFromAPA[ cb ]->getNChannels() <<
" - " <<
fBoardMap[ ThisID ]->getNChannels()
284 if(
fLogLevel>0) loginfo <<
"Finished this APA\n" << *apa_ptr <<
"\n" <<
"Total Boards in fBoardMap: " <<
getNBoards() <<
"\n-----------------------\n\n";
289 loginfo<<
"Finished filling Board Map\n Filled: " <<
getNBoards() <<
" Boards";
296 if(
fLogLevel>1) loginfo <<
"In Function: " << func_name <<
"\n";
298 loginfo <<
"Filling TPC Map with " << Nchannels <<
" channels" <<
"\n";
302 for(
auto wire : Wires){
303 auto tpc_id = wire.TPC;
305 auto find_result =
fTPCMap.find(tpc_id);
306 std::shared_ptr<Hardware::TPC> this_tpc;
307 if(find_result !=
fTPCMap.end()){
309 this_tpc = (*find_result).second;
313 this_tpc = std::shared_ptr<Hardware::TPC>(
new Hardware::TPC(tpc_id));
319 loginfo <<
"Finished filling TPC Map\n" 320 <<
"Filled: " <<
getNTPCs() <<
" TPCs";
329 if(
fLogLevel>1) loginfo <<
"In Function: " << func_name <<
"\n";
332 loginfo <<
"Filling APA Map with " << Nchannels <<
" channels" <<
"\n";
336 for(
auto wire : Wires){
337 auto apa_id = wire.TPC / 2;
339 auto find_result =
fAPAMap.find(apa_id);
340 std::shared_ptr<Hardware::APA> this_apa;
341 if(find_result !=
fAPAMap.end()){
343 this_apa = (*find_result).second;
347 this_apa = std::shared_ptr<Hardware::APA>(
new Hardware::APA(apa_id));
353 loginfo <<
"Finished filling APA Map\n" 354 <<
"Filled: " <<
getNAPAs() <<
" APAs";
367 loginfo <<
"HardwareMapperService\n";
368 loginfo <<
"Filling Hardware Maps using geometry service\n";
382 loginfo <<
"Number of TPCs: " <<
getNTPCs() <<
"\n" 383 <<
"Number of APAs: " <<
getNAPAs() <<
"\n" 384 <<
"Number of Boards: " <<
getNBoards() <<
"\n" 385 <<
"Number of ASICs: " <<
getNASICs() <<
"\n";
394 loginfo <<
"Printing the first: " << num_asics_to_print <<
" ASICs\n";
395 unsigned int total_channels = 0;
396 unsigned int count = 0;
398 if(count++ >= num_asics_to_print)
break;
399 std::shared_ptr<Hardware::ASIC> this_asic = this_pair.second;
400 total_channels += this_asic->getNChannels();
401 loginfo << *this_asic <<
"\n";
404 loginfo <<
"Total Channels: " << total_channels <<
"\n";
413 loginfo <<
"Printing the first: " << num_boards_to_print <<
" Boards\n";
414 unsigned int total_channels = 0;
415 unsigned int count = 0;
417 if(count++ >= num_boards_to_print)
break;
418 std::shared_ptr<Hardware::Board> this_board = this_pair.second;
419 total_channels += this_board->getNChannels();
420 loginfo << *this_board <<
"\n";
423 loginfo <<
"Total Channels: " << total_channels <<
"\n";
432 loginfo <<
"Printing the first: " << num_tpcs_to_print <<
" TPCs\n";
433 unsigned int total_channels = 0;
434 unsigned int count = 0;
435 for(
auto this_pair :
fTPCMap ){
436 if(count++ >= num_tpcs_to_print)
break;
437 std::shared_ptr<Hardware::TPC> this_tpc = this_pair.second;
438 total_channels += this_tpc->getNChannels();
439 loginfo << *this_tpc <<
"\n";
442 loginfo <<
"Total Channels: " << total_channels <<
"\n";
452 loginfo <<
"Printing the first: " << num_apas_to_print <<
" APAs\n";
453 unsigned int total_channels = 0;
454 unsigned int count = 0;
455 for(
auto this_pair :
fAPAMap ){
456 if(count++ >= num_apas_to_print)
break;
457 std::shared_ptr<Hardware::APA> this_apa = this_pair.second;
458 total_channels += this_apa->getNChannels();
459 loginfo << *this_apa <<
"\n";
462 loginfo <<
"Total Channels: " << total_channels <<
"\n";
473 <<
"N.B. the geometry service can reload a new geometry on beginRun(), which would be bad" 485 <<
"Num TPCs: " <<
getNTPCs() <<
"\n" 496 loginfo <<
"Geometry Information with current Geometry Service\n";
503 loginfo <<
"Ncryostats: " << Ncryostats <<
"\n";
504 loginfo <<
"TotalNTPC: " << TotalNTPC <<
"\n";
505 loginfo <<
"Nchannels: " << Nchannels <<
"\n";
506 loginfo <<
"NOpChannels: " << NOpChannels <<
"\n";
520 if(
fLogLevel>1) loginfo <<
"In Function: " << func_name <<
"\n";
521 if(
fLogLevel>1) loginfo <<
"Finding channels for TPC: " << tpc_id <<
"\n";
523 auto find_result =
fTPCMap.find(tpc_id);
524 std::shared_ptr<Hardware::TPC> this_tpc;
526 if(find_result ==
fTPCMap.end()){
529 static std::vector<raw::ChannelID_t> emptyVector;
532 this_tpc = (*find_result).second;
533 if(
fLogLevel>1) loginfo <<
"Found " << *this_tpc <<
"\n";
535 return this_tpc->getChannels();
543 if(
fLogLevel>1) loginfo <<
"Finding channels for APA: " << apa_id <<
"\n";
545 auto find_result =
fAPAMap.find(apa_id);
546 std::shared_ptr<Hardware::APA> this_apa;
548 if(find_result ==
fAPAMap.end()){
551 static std::vector<raw::ChannelID_t> emptyVector;
554 this_apa = (*find_result).second;
555 if(
fLogLevel>1) loginfo <<
"Found " << *this_apa <<
"\n";
557 return this_apa->getChannels();
565 if(
fLogLevel>1) loginfo <<
"Finding channels for TPC: " << tpc_id <<
"\n";
567 auto find_result =
fTPCMap.find(tpc_id);
568 std::shared_ptr<Hardware::TPC> this_tpc;
570 if(find_result ==
fTPCMap.end()){
573 static std::set<raw::ChannelID_t> emptySet;
576 this_tpc = (*find_result).second;
577 if(
fLogLevel>1) loginfo <<
"Found " << *this_tpc <<
"\n";
579 return this_tpc->getChannelsSet();
587 if(
fLogLevel>1) loginfo <<
"Finding channels for APA: " << apa_id <<
"\n";
589 auto find_result =
fAPAMap.find(apa_id);
590 std::shared_ptr<Hardware::APA> this_apa;
592 if(find_result ==
fAPAMap.end()){
595 static std::set<raw::ChannelID_t> emptySet;
598 this_apa = (*find_result).second;
599 if(
fLogLevel>1) loginfo <<
"Found " << *this_apa <<
"\n";
601 return this_apa->getChannelsSet();
unsigned int getNBoards() const
std::vector< raw::ChannelID_t > const & getAPAChannels(Hardware::ID apa_id)
static constexpr double nb
unsigned int TotalNTPC() const
Returns the total number of TPCs in the detector.
art::ServiceHandle< geo::Geometry > fGeometryService
Hardware::BoardMap fBoardMap
void printBoardMap(unsigned int num_boards_to_print=20)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
unsigned int getNAPAs() const
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
std::vector< raw::ChannelID_t > const & getTPCChannels(Hardware::ID tpc_id)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
unsigned int NOpChannels() const
Number of electronics channels for all the optical detectors.
std::string fDetectorNameFromGeometry
std::set< raw::ChannelID_t > const & getTPCChannelsSet(Hardware::ID tpc_id)
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
unsigned int fNBoardsPerAPA
double TotalMass() const
Returns the total mass [kg] of the specified volume (default: world).
geo::TPCID FindTPCAtPosition(double const worldLoc[3]) const
Returns the ID of the TPC at specified location.
void printASICMap(unsigned int num_asics_to_print=20)
unsigned int getNASICs() const
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
void printTPCMap(unsigned int num_tpcs_to_print=20)
HardwareMapperService(fhicl::ParameterSet const &pset, art::ActivityRegistry ®)
std::set< raw::ChannelID_t > const & getAPAChannelsSet(Hardware::ID apa_id)
void printAPAMap(unsigned int num_apas_to_print=20)
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
unsigned int getNTPCs() const
unsigned int fNASICsPerBoard
#define DEFINE_ART_SERVICE(svc)
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
std::optional< T > get_if_present(std::string const &key) const
void checkGeomVsFileDetectorName(art::Run const &run)
void WireEndPoints(geo::WireID const &wireid, double *xyzStart, double *xyzEnd) const
Fills two arrays with the coordinates of the wire end points.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
TPCID_t TPC
Index of the TPC within its cryostat.
std::string fDetectorNameFromFile
Hardware::ASICMap fASICMap
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)