Public Member Functions | Private Types | Private Attributes | List of all members
FileChannelMappingService Class Reference

#include <FileChannelMappingService.h>

Inheritance diagram for FileChannelMappingService:
ChannelMappingService

Public Member Functions

 FileChannelMappingService (fhicl::ParameterSet const &pset)
 
 FileChannelMappingService (fhicl::ParameterSet const &pset, art::ActivityRegistry &)
 
Channel offline (Channel onlineChannel) const
 
Channel online (Channel offlineChannel) const
 
std::ostream & print (std::ostream &out=std::cout, std::string prefix="") const
 
- Public Member Functions inherited from ChannelMappingService
virtual ~ChannelMappingService ()=default
 

Private Types

typedef std::vector< ChannelChannelMap
 

Private Attributes

std::string m_FileName
 
std::string m_FilePathEnv
 
int m_LogLevel
 
ChannelMap m_onMap
 
ChannelMap m_offMap
 

Additional Inherited Members

- Public Types inherited from ChannelMappingService
typedef unsigned int Channel
 

Detailed Description

Definition at line 27 of file FileChannelMappingService.h.

Member Typedef Documentation

Definition at line 29 of file FileChannelMappingService.h.

Constructor & Destructor Documentation

FileChannelMappingService::FileChannelMappingService ( fhicl::ParameterSet const &  pset)

Definition at line 31 of file FileChannelMappingService_service.cc.

32 : m_FilePathEnv("FW_SEARCH_PATH"), m_LogLevel(1) {
33  const string myname = "FileChannelMappingService::ctor: ";
34  m_FileName = pset.get<string>("FileName");
35  pset.get_if_present<string>("FilePathEnv", m_FilePathEnv);
36  pset.get_if_present<int>("LogLevel", m_LogLevel);
37  if ( m_LogLevel > 0 ) {
38  print(cout, myname);
39  cout << myname << "Reading map file." << endl;
40  }
41  // Read the map.
43  string fullname;
44  sp.find_file(m_FileName, fullname);
45  if ( fullname.empty() ) {
46  cout << "ERROR: " << "Input file not found: " << m_FileName << endl;
47  cout << "ERROR: " << "Search path: $" << m_FilePathEnv << endl;
48  throw cet::exception("File not found");
49  }
50  std::ifstream infile(fullname);
51  Channel chon;
52  Channel choff;
53  unsigned int count = 0;
54  while ( infile.good() ) {
55  infile >> chon >> choff;
56  if ( m_onMap.size() < choff+1 ) m_onMap.resize(choff+1, bad());
57  if ( m_offMap.size() < chon+1 ) m_offMap.resize(chon+1, bad());
58  m_onMap[choff] = chon;
59  m_offMap[chon] = choff;
60  ++count;
61  }
62  if ( m_LogLevel > 0 ) {
63  cout << myname << "Channel map file: " << fullname << endl;
64  cout << myname << " Number of map entries: " << count << endl;
65  cout << myname << " Maximum online channel: " << m_offMap.size()-1 << endl;
66  cout << myname << " Maximum offline channel: " << m_onMap.size()-1 << endl;
67  }
68 }
string infile
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
unsigned int bad()
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
ChannelMappingService::Channel Channel
FileChannelMappingService::FileChannelMappingService ( fhicl::ParameterSet const &  pset,
art::ActivityRegistry  
)

Definition at line 73 of file FileChannelMappingService_service.cc.

74 : FileChannelMappingService(pset) { }
FileChannelMappingService(fhicl::ParameterSet const &pset)

Member Function Documentation

Channel FileChannelMappingService::offline ( Channel  onlineChannel) const
virtual

Implements ChannelMappingService.

Definition at line 78 of file FileChannelMappingService_service.cc.

78  {
79  const string myname = "FileChannelMappingService::offline: ";
80  Channel chout = bad();
81  if ( chin < m_offMap.size() ) chout = m_offMap[chin];
82  if ( chout == bad() ) {
83  if ( m_LogLevel > 1 ) {
84  cout << myname << "ERROR: " << "No offline channel mapped to online channel " << chin << endl;
85  }
86  throw cet::exception("Online channel not found.");
87  }
88  return chout;
89 }
unsigned int bad()
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
ChannelMappingService::Channel Channel
Channel FileChannelMappingService::online ( Channel  offlineChannel) const
virtual

Implements ChannelMappingService.

Definition at line 93 of file FileChannelMappingService_service.cc.

93  {
94  const string myname = "FileChannelMappingService::online: ";
95  Channel chout = bad();
96  if ( chin < m_onMap.size() ) chout = m_onMap[chin];
97  if ( chout == bad() ) {
98  if ( m_LogLevel > 1 ) {
99  cout << myname << "ERROR: " << "No online channel mapped to offline channel " << chin << endl;
100  }
101  throw cet::exception("Offline channel not found.");
102  }
103  return chout;
104 }
unsigned int bad()
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
ChannelMappingService::Channel Channel
ostream & FileChannelMappingService::print ( std::ostream &  out = std::cout,
std::string  prefix = "" 
) const
virtual

Implements ChannelMappingService.

Definition at line 108 of file FileChannelMappingService_service.cc.

108  {
109  string myname = prefix + " ";
110  cout << myname << " FileName: " << m_FileName << endl;
111  cout << myname << "FilePathEnv: " << m_FilePathEnv << endl;
112  cout << myname << " LogLevel: " << m_LogLevel << endl;
113  return out;
114 }
QTextStream & endl(QTextStream &s)

Member Data Documentation

std::string FileChannelMappingService::m_FileName
private

Definition at line 51 of file FileChannelMappingService.h.

std::string FileChannelMappingService::m_FilePathEnv
private

Definition at line 52 of file FileChannelMappingService.h.

int FileChannelMappingService::m_LogLevel
private

Definition at line 53 of file FileChannelMappingService.h.

ChannelMap FileChannelMappingService::m_offMap
private

Definition at line 57 of file FileChannelMappingService.h.

ChannelMap FileChannelMappingService::m_onMap
private

Definition at line 56 of file FileChannelMappingService.h.


The documentation for this class was generated from the following files: