HardwareMapperService_service.cc
Go to the documentation of this file.
1 // HardwareMapperService_service.cc
2 //
3 // Jonathan Davies j.p.davies@sussex.ac.uk
4 // August 2016
5 //
6 // Description: Dish out vectors of raw::ChannelID_t to the user for requested hardware element
7 
10 #include "fhiclcpp/ParameterSet.h"
12 
13 #include <sstream>
14 #include <set>
15 #include <memory>
16 
17 //......................................................
19  : fLogLevel(1), fNASICsPerBoard(1), fNBoardsPerAPA(1), fServiceName("HardwareMapperService") {
20  pset.get_if_present<unsigned int>("LogLevel", fLogLevel);
21  pset.get_if_present<unsigned int>("NASICsPerBoard", fNASICsPerBoard);
22  pset.get_if_present<unsigned int>("NBoardsPerAPA", fNBoardsPerAPA);
23  const std::string func_name = "HardwareMapperService";
24  {
25  mf::LogInfo loginfo(fServiceName);
26  loginfo << func_name << "\n"
27  << "fLogLevel: " << fLogLevel << "\n"
28  << "fNASICsPerBoard: " << fNASICsPerBoard << "\n"
29  << "fNBoardsPerAPA: " << fNBoardsPerAPA;
30  }
31  //jpd -- This is how to register a callback function to the activity registry
32  // -- This means that upon the preBeginRun (which I assume is immediately before
33  // -- begin run) this function (HardwareMapperService::preBeginRun) will be called
34 
37 }
38 
39 //......................................................
41  const std::string func_name = "checkGeomVsFileDetectorName";
42  if(fLogLevel>1) mf::LogInfo(fServiceName) << "In Function: " << func_name;
43 
44  //jpd -- Check that the Detector Name matches between the Geometry and the File
45  //Inspired by Geometry_service.cc
46  mf::LogInfo loginfo(fServiceName);
47 
48  auto const rdcol = run.getMany<sumdata::RunData>();
49  if (rdcol.empty()) {
50  mf::LogError(fServiceName) << "Can't find sumdata::RunData for geometry vs. file detector name checks";
51  return;
52  }
53 
54  fDetectorNameFromFile = rdcol.front()->DetName();
55 
56  loginfo << "This file has the following detector name: " << fDetectorNameFromFile << "\n";
57  loginfo << "The geometry service has this detector name: " << fDetectorNameFromGeometry << "\n";
58 
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";
65  }
66 }
67 
68 //......................................................
70  const std::string func_name = "fillASICMap";
71 
72  mf::LogInfo loginfo(fServiceName);
73 
74  if(fLogLevel>1||true) loginfo << "In Function: " << func_name << "\n";//FIXME
75 
76  loginfo << "Filling ASIC Map - fNASICsPerBoard: " << fNASICsPerBoard << "\n";
77 
78  if(fLogLevel>0) loginfo << "Looping over Boards" << "\n";
79 
80  Hardware::ID current_asic_id = 0;
81  for(auto id_board_pair: fBoardMap){
82  std::shared_ptr<Hardware::Board> board_ptr = id_board_pair.second;
83 
84  if(fLogLevel>0) loginfo << *board_ptr << "\n";
85 
86  unsigned int channels_in_this_asic = 0;
87  unsigned int max_channels_in_asic = board_ptr->getNChannels() / fNASICsPerBoard;
88 
89  if(fLogLevel>1) loginfo << "current_asic_id: " << current_asic_id << "\n";
90 
91  board_ptr->addHardwareID(Hardware::ASIC(current_asic_id));
92  std::shared_ptr<Hardware::ASIC> this_asic_ptr = std::shared_ptr<Hardware::ASIC>(new Hardware::ASIC(current_asic_id));
93 
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"
98  << "\n\n";
99 
100  if(fLogLevel>1) loginfo << "Looping over channels" << "\n";
101 
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
107  << "\n";
108 
109 
110  fASICMap[this_asic_ptr->getID()] = this_asic_ptr;
111  current_asic_id++;
112  channels_in_this_asic=0;
113 
114  if(fLogLevel>1) loginfo << "Last ASIC: " << *this_asic_ptr << "\n\n";
115 
116  this_asic_ptr=std::shared_ptr<Hardware::ASIC>(new Hardware::ASIC(current_asic_id));
117 
118  board_ptr->addHardwareID(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"
123  << "\n\n";
124  }
125  this_asic_ptr->addChannel(channel);
126  channels_in_this_asic++;
127 
128  }//channel in this board
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
133  << "\n";
134  fASICMap[this_asic_ptr->getID()] = this_asic_ptr;
135  current_asic_id++;//start each Board with a new ASIC
136  if(fLogLevel>0) loginfo << "Finished this Board\n"
137  << *board_ptr << "\n"
138  << "Total ASICs in fASICMap: " << getNASICs() << "\n"
139  << "-----------------------\n\n";
140  }//id_board_pair;
141  loginfo << "Finished filling ASIC Map\n"
142  << "Filled: " << getNASICs() << " ASICs";
143 
144 
145 }
146 
147 //......................................................
149  const std::string func_name = "fillBoardMap";
150  if(fLogLevel>1||true) mf::LogInfo(fServiceName) << "In Function: " << func_name;//FIXME
151 
152  mf::LogInfo loginfo(fServiceName);
153  loginfo << "Filling Board Map - fNBoardsPerAPA: " << fNBoardsPerAPA << "\n";
154 
155  Hardware::ID current_board_id = 0;
156  if(fLogLevel>0) loginfo << "Looping over apas" << "\n";
157 
158  // --- Lets loop over the APA map
159  for(auto id_apa_pair: fAPAMap){
160  // --- Get a handle to this APA object.
161  std::shared_ptr<Hardware::APA> apa_ptr = id_apa_pair.second;
162  // --- How many channels should there be per board?
163  unsigned int max_channels_in_board = apa_ptr->getNChannels() / fNBoardsPerAPA;
164 
165  // Karl::Added to only run on the first APA.
166  //if (apa_ptr->getID() > 1) continue;
167 
168  // --- Record the id of the current board that we are on.
169  Hardware::ID FirstBoard = current_board_id;
170  // --- Make an array of boards for this APA, and then create them.
171  std::vector< std::shared_ptr<Hardware::Board> > BoardsFromAPA;
172  std::vector< TVector3 > ZPosOfColWires;
173  for (unsigned int cb=0; cb<fNBoardsPerAPA; ++cb) {
174  // --- Add a board object to this APA
175  apa_ptr->addHardwareID(Hardware::Board( current_board_id ));
176  // --- Push back objects to my vectors.
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;
180  // --- Incremment the current_board_id number.
181  ++current_board_id;
182  }
183 
184  // --- Now that I have a vector of boards for this APA, lets loop over the channels on this APA and assign them to each board!
185  if(fLogLevel>1) loginfo << "Looping over channels" << "\n";
186  // I need to find out the range of z values which this APA covers, and the number of collection plane wires, in order to correctly assign the channels.
187  // --- !!! I am going to explicitly assuming wrapped wires, and that both sides of the TPC are instrumented !!! ---
188  // --- !!! This is valid in all of the geometries that I am aware of 2nd June 2017 !!! ---
189  double ThisAPA_MinZ = DBL_MAX;
190  double ThisAPA_MaxZ = -DBL_MAX;
191  int TotColWires = 0;
192  for(auto channel : apa_ptr->getChannels()) {
193  if (fGeometryService->View(channel) != 2) continue; // Collection planes wires are view 2.
194  ++TotColWires; // Got a collection plane wire.
195  // Work out the Z position of this wire.
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];
200  }
201  // --- Work out the number of collection plane wires per board.
202  const int NumColWiresPerBoard = TotColWires/fNBoardsPerAPA;
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.";
206  }
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"
210  << std::endl;
211 
212  // --- Set the collection plane wires on our boards.
213  int NumColPush = 0, PushToBoard = 0;
214  for(auto channel : apa_ptr->getChannels()) {
215  if (fGeometryService->View(channel) != 2) continue; // Collection planes wires are view 2.
216  // Get the start and end points of the first wire segment for this channel.
217  double WireSt[3], WireEn[3];
219  BoardsFromAPA[ PushToBoard ]->addChannel(channel);
220  ++NumColPush;
221  if( WireSt[2] < ZPosOfColWires[ PushToBoard ][0] ) ZPosOfColWires[ PushToBoard ][0] = WireSt[2];
222  if( WireEn[2] > ZPosOfColWires[ PushToBoard ][1] ) ZPosOfColWires[ PushToBoard ][1] = WireEn[2];
223  ZPosOfColWires[ PushToBoard ][2] = fGeometryService->FindTPCAtPosition( WireSt ).TPC;
224  /*
225  std::cout << " Looking at channel " << channel << " on plane " << fGeometryService->View(channel) << " TPC [[" << fGeometryService->FindTPCAtPosition( WireSt ) << " ]]."
226  << " Start pos was (" << WireSt[0] << ", " << WireSt[1] << ", " << WireSt[2] << "). "
227  << " Endin pos was (" << WireEn[0] << ", " << WireEn[1] << ", " << WireEn[2] << ").\n"
228  << " Pushing it back to board " << PushToBoard << ", now pushed back " << NumColPush << " wires."
229  << " Extremes are " << ZPosOfColWires[ PushToBoard ].first << " - " << ZPosOfColWires[ PushToBoard ].second
230  << std::endl;
231  */
232  // --- Check that if I want to move to the next board.
233  if ( NumColPush%NumColWiresPerBoard == 0 ) {
234  ++PushToBoard;
235  }
236  }
237 
238  for (unsigned int nn=0; nn<fNBoardsPerAPA; ++nn) {
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;
241  }
242 
243  // --- Now set the induction plane wires on our boards.
244  int NumIndPush = 0;
245 
246  for(auto channel : apa_ptr->getChannels()) {
247  if (fGeometryService->View(channel) == 2) continue; // Collection planes wires are view 2.
248  // --- When looking at induction plane wires whether I look at start or end wire pos depends on APA and TPC number.
249  // --- When looking at even APA number - WireEnd for even TPCs, WireStart for odd TPCs.
250  // --- When looking at odd APA number - WireStart for odd TPCs, WireEnd for even TPCs.
251  // Get the start and end points of the first wire segment for this channel.
252  double WireSt[3], WireEn[3];
254  /*
255  std::cout << "\nLooking at channel " << channel << " on plane " << fGeometryService->View(channel) << " TPC [[" << fGeometryService->FindTPCAtPosition( WireSt ) << " ]]."
256  << " Start pos was (" << WireSt[0] << ", " << WireSt[1] << ", " << WireSt[2] << "). "
257  << " Endin pos was (" << WireEn[0] << ", " << WireEn[1] << ", " << WireEn[2] << ")."
258  << std::endl;
259  */
260  for (unsigned int nb=0; nb<fNBoardsPerAPA; ++nb) {
261  if ( ZPosOfColWires[nb][2] != fGeometryService->FindTPCAtPosition( WireSt ).TPC ) continue;
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);
265  /*
266  std::cout << " Pushing this channel onto board: " << BoardsFromAPA[ nb ]->getID()
267  << ", Extremeities " << ZPosOfColWires[nb][0] << " - " << ZPosOfColWires[nb][1] << " in TPC " << ZPosOfColWires[nb][2]
268  << ". This board now has " << BoardsFromAPA[ nb ]->getNChannels() << std::endl;
269  */
270  break;
271  }
272  }
273  ++NumIndPush;
274  }//channel in this apa
275 
276  // --- Now that I have looped over all of the channels, lets update my map!
277  for (unsigned int cb=0; cb<fNBoardsPerAPA; ++cb) {
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()
282  << std::endl;
283  }
284  if(fLogLevel>0) loginfo << "Finished this APA\n" << *apa_ptr << "\n" << "Total Boards in fBoardMap: " << getNBoards() << "\n-----------------------\n\n";
285  // --- Start each APA with a new board
286  //current_board_id++;
287  }//id_apa_pair;
288 
289  loginfo<< "Finished filling Board Map\n Filled: " << getNBoards() << " Boards";
290 }
291 
292 //......................................................
294  const std::string func_name = "fillTPCMap";
295  mf::LogInfo loginfo(fServiceName);
296  if(fLogLevel>1) loginfo << "In Function: " << func_name << "\n";
297  unsigned int Nchannels = fGeometryService->Nchannels();
298  loginfo << "Filling TPC Map with " << Nchannels << " channels" << "\n";
299 
300  for(raw::ChannelID_t channel=0; channel<Nchannels ;channel++){
301  std::vector<geo::WireID> const Wires = fGeometryService->ChannelToWire(channel);
302  for(auto wire : Wires){
303  auto tpc_id = wire.TPC;
304  //jpd -- See if we have already created a TPC object for this tpc_id in our map
305  auto find_result = fTPCMap.find(tpc_id);
306  std::shared_ptr<Hardware::TPC> this_tpc;
307  if(find_result != fTPCMap.end()){
308  //jpd -- We already have one, add this channel
309  this_tpc = (*find_result).second;
310  }
311  else{
312  //jpd -- We don't have one. Create a new one and add this channel
313  this_tpc = std::shared_ptr<Hardware::TPC>(new Hardware::TPC(tpc_id));
314  }
315  this_tpc->addChannel(channel);
316  fTPCMap[tpc_id] = this_tpc;
317  }//loop over wires
318  }//loop over channels
319  loginfo << "Finished filling TPC Map\n"
320  << "Filled: " << getNTPCs() << " TPCs";
321 
322 }
323 
324 //......................................................
326  const std::string func_name = "fillAPAMap";
327 
328  mf::LogInfo loginfo(fServiceName);
329  if(fLogLevel>1) loginfo << "In Function: " << func_name << "\n";
330 
331  unsigned int Nchannels = fGeometryService->Nchannels();
332  loginfo << "Filling APA Map with " << Nchannels << " channels" << "\n";
333 
334  for(raw::ChannelID_t channel=0; channel<Nchannels ;channel++){
335  std::vector<geo::WireID> const Wires = fGeometryService->ChannelToWire(channel);
336  for(auto wire : Wires){
337  auto apa_id = wire.TPC / 2;
338  //jpd -- See if we have already created a APA object for this apa_id in our map
339  auto find_result = fAPAMap.find(apa_id);
340  std::shared_ptr<Hardware::APA> this_apa;
341  if(find_result != fAPAMap.end()){
342  //jpd -- We already have one, add this channel
343  this_apa = (*find_result).second;
344  }
345  else{
346  //jpd -- We don't have one. Create a new one and add this channel
347  this_apa = std::shared_ptr<Hardware::APA>(new Hardware::APA(apa_id));
348  }
349  this_apa->addChannel(channel);
350  fAPAMap[apa_id] = this_apa;
351  }//loop over wires
352  }//loop over channels
353  loginfo << "Finished filling APA Map\n"
354  << "Filled: " << getNAPAs() << " APAs";
355 }
356 
357 
358 //......................................................
360  const std::string func_name = "fillHardwareMaps";
361  if(fLogLevel>1) mf::LogInfo(fServiceName) << "In Function: " << func_name;
363 
364  {
365  mf::LogInfo loginfo(fServiceName);
366 
367  loginfo << "HardwareMapperService\n";
368  loginfo << "Filling Hardware Maps using geometry service\n";
369  loginfo << "DetectorName: " << fGeometryService->DetectorName() << "\n";
370  loginfo << "Ncryostats: " << fGeometryService->Ncryostats() << "\n";
371  loginfo << "TotalNTPC: " << fGeometryService->TotalNTPC() << "\n";
372  loginfo << "Nchannels: " << fGeometryService->Nchannels() << "\n";
373  loginfo << "NOpChannels: " << fGeometryService->NOpChannels() << "\n";
374  }//using annonymous namespace to force mf::LogInfo destructor call to flush output
375 
376  fillTPCMap();
377  fillAPAMap();
378  fillBoardMap();
379  fillASICMap();
380 
381  mf::LogInfo loginfo(fServiceName);
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";
386 
387 }
388 
389 //......................................................
390 void HardwareMapperService::printASICMap(unsigned int num_asics_to_print){
391  const std::string func_name = "printASICMap";
392  if(fLogLevel>1) mf::LogInfo(fServiceName) << "In Function: " << func_name;
393  mf::LogInfo loginfo(fServiceName);
394  loginfo << "Printing the first: " << num_asics_to_print << " ASICs\n";
395  unsigned int total_channels = 0;
396  unsigned int count = 0;
397  for(auto this_pair : fASICMap ){
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";
402  }
403  loginfo << "\n";
404  loginfo << "Total Channels: " << total_channels << "\n";
405  loginfo << "\n";
406 }
407 
408 //......................................................
409 void HardwareMapperService::printBoardMap(unsigned int num_boards_to_print){
410  const std::string func_name = "printBoardMap";
411  if(fLogLevel>1) mf::LogInfo(fServiceName) << "In Function: " << func_name;
412  mf::LogInfo loginfo(fServiceName);
413  loginfo << "Printing the first: " << num_boards_to_print << " Boards\n";
414  unsigned int total_channels = 0;
415  unsigned int count = 0;
416  for(auto this_pair : fBoardMap ){
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";
421  }
422  loginfo << "\n";
423  loginfo << "Total Channels: " << total_channels << "\n";
424  loginfo << "\n";
425 }
426 
427 //......................................................
428 void HardwareMapperService::printTPCMap(unsigned int num_tpcs_to_print){
429  const std::string func_name = "printTPCMap";
430  if(fLogLevel>1) mf::LogInfo(fServiceName) << "In Function: " << func_name;
431  mf::LogInfo loginfo(fServiceName);
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";
440  }
441  loginfo << "\n";
442  loginfo << "Total Channels: " << total_channels << "\n";
443  loginfo << "\n";
444 }
445 
446 //......................................................
447 void HardwareMapperService::printAPAMap(unsigned int num_apas_to_print){
448  const std::string func_name = "printAPAMap";
449  if(fLogLevel>1) mf::LogInfo(fServiceName) << "In Function: " << func_name;
450  mf::LogInfo loginfo(fServiceName);
451 
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";
460  }
461  loginfo << "\n";
462  loginfo << "Total Channels: " << total_channels << "\n";
463  loginfo << "\n";
464 }
465 
466 //......................................................
468  const std::string func_name = "printHardwareMaps";
469  if(fLogLevel>1) mf::LogInfo(fServiceName) << "In Function: " << func_name;
471  << "fDetectorName: " << fDetectorNameFromGeometry << " taken from Geometry Service at time of fillHardwareMaps()"
472  << "\n"
473  << "N.B. the geometry service can reload a new geometry on beginRun(), which would be bad"
474  << "\n";
475 
480 
481 
483  << "Num ASICs: " << getNASICs() << "\n"
484  << "Num Boards: " << getNBoards() << "\n"
485  << "Num TPCs: " << getNTPCs() << "\n"
486  << "Num APAs: " << getNAPAs();
487 
488 }
489 
490 //......................................................
492  const std::string func_name = "printGeometryInfo";
493  if(fLogLevel>1) mf::LogInfo(fServiceName) << "In Function: " << func_name;
494  {
495  mf::LogInfo loginfo(fServiceName);
496  loginfo << "Geometry Information with current Geometry Service\n";
497  loginfo << "DetectorName: " << fGeometryService->DetectorName() << "\n";
498  loginfo << "TotalMass: " << fGeometryService->TotalMass() << "\n";
499  unsigned int Ncryostats = fGeometryService->Ncryostats();
500  unsigned int TotalNTPC = fGeometryService->TotalNTPC();
501  unsigned int Nchannels = fGeometryService->Nchannels();
502  unsigned int NOpChannels = fGeometryService->NOpChannels();
503  loginfo << "Ncryostats: " << Ncryostats << "\n";
504  loginfo << "TotalNTPC: " << TotalNTPC << "\n";
505  loginfo << "Nchannels: " << Nchannels << "\n";
506  loginfo << "NOpChannels: " << NOpChannels << "\n";
507  loginfo << "\n";
508  }//using annonymous namespace to force mf::LogInfo destructor (which makes flushes the output)
509 
511 
512  return;
513 }
514 
515 //......................................................
516 std::vector<raw::ChannelID_t> const& HardwareMapperService::getTPCChannels(Hardware::ID tpc_id){
517  const std::string func_name = "getTPCChannels";
518  mf::LogInfo loginfo(fServiceName);
519 
520  if(fLogLevel>1) loginfo << "In Function: " << func_name << "\n";
521  if(fLogLevel>1) loginfo << "Finding channels for TPC: " << tpc_id << "\n";
522 
523  auto find_result = fTPCMap.find(tpc_id);
524  std::shared_ptr<Hardware::TPC> this_tpc;
525 
526  if(find_result == fTPCMap.end()){
527  mf::LogError(fServiceName) << "Failed to find this TPC: " << tpc_id << "\n";
528  mf::LogError(fServiceName) << "Returning an empty vector of channels\n";
529  static std::vector<raw::ChannelID_t> emptyVector;
530  return emptyVector;
531  }
532  this_tpc = (*find_result).second;
533  if(fLogLevel>1) loginfo << "Found " << *this_tpc << "\n";
534  if(fLogLevel>1) loginfo << "\n";
535  return this_tpc->getChannels();
536 }
537 
538 //......................................................
539 std::vector<raw::ChannelID_t> const& HardwareMapperService::getAPAChannels(Hardware::ID apa_id){
540  const std::string func_name = "getAPAChannels";
541  if(fLogLevel>1) mf::LogInfo(fServiceName) << "In Function: " << func_name;
542  mf::LogInfo loginfo(fServiceName);
543  if(fLogLevel>1) loginfo << "Finding channels for APA: " << apa_id << "\n";
544 
545  auto find_result = fAPAMap.find(apa_id);
546  std::shared_ptr<Hardware::APA> this_apa;
547 
548  if(find_result == fAPAMap.end()){
549  mf::LogError(fServiceName) << "Failed to find this APA: " << apa_id << "\n";
550  mf::LogError(fServiceName) << "Returning an empty vector of channels\n";
551  static std::vector<raw::ChannelID_t> emptyVector;
552  return emptyVector;
553  }
554  this_apa = (*find_result).second;
555  if(fLogLevel>1) loginfo << "Found " << *this_apa << "\n";
556  if(fLogLevel>1) loginfo << "\n";
557  return this_apa->getChannels();
558 }
559 
560 //......................................................
561 std::set<raw::ChannelID_t> const& HardwareMapperService::getTPCChannelsSet(Hardware::ID tpc_id){
562  const std::string func_name = "getTPCChannelsSet";
563  if(fLogLevel>1) mf::LogInfo(fServiceName) << "In Function: " << func_name;
564  mf::LogInfo loginfo(fServiceName);
565  if(fLogLevel>1) loginfo << "Finding channels for TPC: " << tpc_id << "\n";
566 
567  auto find_result = fTPCMap.find(tpc_id);
568  std::shared_ptr<Hardware::TPC> this_tpc;
569 
570  if(find_result == fTPCMap.end()){
571  mf::LogError(fServiceName) << "Failed to find this TPC: " << tpc_id << "\n";
572  mf::LogError(fServiceName) << "Returning an empty set of channels\n";
573  static std::set<raw::ChannelID_t> emptySet;
574  return emptySet;
575  }
576  this_tpc = (*find_result).second;
577  if(fLogLevel>1) loginfo << "Found " << *this_tpc << "\n";
578  if(fLogLevel>1) loginfo << "\n";
579  return this_tpc->getChannelsSet();
580 }
581 
582 //......................................................
583 std::set<raw::ChannelID_t> const& HardwareMapperService::getAPAChannelsSet(Hardware::ID apa_id){
584  const std::string func_name = "getAPAChannelsSet";
585  if(fLogLevel>1) mf::LogInfo(fServiceName) << "In Function: " << func_name;
586  mf::LogInfo loginfo(fServiceName);
587  if(fLogLevel>1) loginfo << "Finding channels for APA: " << apa_id << "\n";
588 
589  auto find_result = fAPAMap.find(apa_id);
590  std::shared_ptr<Hardware::APA> this_apa;
591 
592  if(find_result == fAPAMap.end()){
593  mf::LogError(fServiceName) << "Failed to find this APA: " << apa_id << "\n";
594  mf::LogError(fServiceName) << "Returning an empty set of channels\n";
595  static std::set<raw::ChannelID_t> emptySet;
596  return emptySet;
597  }
598  this_apa = (*find_result).second;
599  if(fLogLevel>1) loginfo << "Found " << *this_apa << "\n";
600  if(fLogLevel>1) loginfo << "\n";
601  return this_apa->getChannelsSet();
602 }
603 
604 //......................................................
606 
unsigned int getNBoards() const
std::vector< raw::ChannelID_t > const & getAPAChannels(Hardware::ID apa_id)
static constexpr double nb
Definition: Units.h:81
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)
std::string string
Definition: nybbler.cc:12
unsigned int ID
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)
uint8_t channel
Definition: CRTFragment.hh:201
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::set< raw::ChannelID_t > const & getTPCChannelsSet(Hardware::ID tpc_id)
Definition: Run.h:17
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
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
T abs(T value)
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
Definition: DataViewImpl.h:479
void printTPCMap(unsigned int num_tpcs_to_print=20)
HardwareMapperService(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
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
#define DEFINE_ART_SERVICE(svc)
Index NOpChannels(Index)
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
std::optional< T > get_if_present(std::string const &key) const
Definition: ParameterSet.h:224
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.
Definition: RawTypes.h:28
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
Hardware::ASICMap fASICMap
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)