Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
dunetpc
dune
Daq
Service
FileChannelMappingService_service.cc
Go to the documentation of this file.
1
// FileChannelMappingService.cxx
2
3
#include "
dune/Daq/Service/FileChannelMappingService.h
"
4
#include "
art/Framework/Services/Registry/ServiceDefinitionMacros.h
"
5
#include <limits>
6
#include <fstream>
7
8
using
std::cout;
9
using
std::ostream;
10
using
std::endl
;
11
using
std::string
;
12
using
std::ifstream;
13
14
#undef UseSeedService
15
16
typedef
ChannelMappingService::Channel
Channel
;
17
18
namespace
{
19
20
// Bad channel value.
21
Channel
bad
() {
22
Channel
val
=
std::numeric_limits<Channel>::max
();
23
return
val
;
24
}
25
26
}
27
28
//**********************************************************************
29
30
FileChannelMappingService::
31
FileChannelMappingService
(
fhicl::ParameterSet
const
& pset)
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.
42
cet::search_path
sp(
m_FilePathEnv
);
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
}
69
70
//**********************************************************************
71
72
FileChannelMappingService::
73
FileChannelMappingService
(
fhicl::ParameterSet
const
& pset,
art::ActivityRegistry
&)
74
:
FileChannelMappingService
(pset) { }
75
76
//**********************************************************************
77
78
Channel
FileChannelMappingService::offline
(
Channel
chin)
const
{
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
}
90
91
//**********************************************************************
92
93
Channel
FileChannelMappingService::online
(
Channel
chin)
const
{
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
}
105
106
//**********************************************************************
107
108
ostream&
FileChannelMappingService::print
(ostream& out,
string
prefix
)
const
{
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
}
115
116
//**********************************************************************
117
118
DEFINE_ART_SERVICE_INTERFACE_IMPL
(
FileChannelMappingService
,
ChannelMappingService
)
119
120
//**********************************************************************
FileChannelMappingService::m_offMap
ChannelMap m_offMap
Definition:
FileChannelMappingService.h:57
FileChannelMappingService::FileChannelMappingService
FileChannelMappingService(fhicl::ParameterSet const &pset)
Definition:
FileChannelMappingService_service.cc:31
FileChannelMappingService::m_onMap
ChannelMap m_onMap
Definition:
FileChannelMappingService.h:56
val
Definition:
registry_via_id_test_2.cc:15
submit_ppfxjobs.prefix
string prefix
Definition:
submit_ppfxjobs.py:128
FileChannelMappingService::m_LogLevel
int m_LogLevel
Definition:
FileChannelMappingService.h:53
string
std::string string
Definition:
nybbler.cc:12
FileChannelMappingService::m_FilePathEnv
std::string m_FilePathEnv
Definition:
FileChannelMappingService.h:52
FileChannelMappingService::m_FileName
std::string m_FileName
Definition:
FileChannelMappingService.h:51
ChannelMappingService::Channel
unsigned int Channel
Definition:
ChannelMappingService.h:19
infile
string infile
Definition:
INukeNucleonCorr.cxx:62
fhicl::ParameterSet::get
T get(std::string const &key) const
Definition:
ParameterSet.h:271
FileChannelMappingService::print
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
Definition:
FileChannelMappingService_service.cc:108
testsqlite3.val
list val
Definition:
testsqlite3.py:13
max
static int max(int a, int b)
Definition:
fortranscanner.cpp:60366
ChannelMappingService
Definition:
ChannelMappingService.h:15
FileChannelMappingService::online
Channel online(Channel offlineChannel) const
Definition:
FileChannelMappingService_service.cc:93
art::ActivityRegistry
Definition:
ActivityRegistry.h:52
fhicl::ParameterSet::get_if_present
std::optional< T > get_if_present(std::string const &key) const
Definition:
ParameterSet.h:224
FileChannelMappingService.h
cet::search_path::find_file
std::string find_file(std::string const &filename) const
Definition:
search_path.cc:96
ServiceDefinitionMacros.h
FileChannelMappingService
Definition:
FileChannelMappingService.h:27
reco_momentum_tuples.count
int count
Definition:
reco_momentum_tuples.py:202
FileChannelMappingService::offline
Channel offline(Channel onlineChannel) const
Definition:
FileChannelMappingService_service.cc:78
bad
unsigned int bad()
Definition:
IcebergChannelMapService_service.cc:14
cet::search_path
Definition:
search_path.h:36
fhicl::exception
cet::coded_exception< error, detail::translate > exception
Definition:
exception.h:33
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
Channel
ChannelMappingService::Channel Channel
Definition:
FileChannelMappingService_service.cc:16
fhicl::ParameterSet
Definition:
ParameterSet.h:36
DEFINE_ART_SERVICE_INTERFACE_IMPL
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)
Definition:
ServiceDefinitionMacros.h:42
Generated by
1.8.11