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

#include <ToolBasedRawDigitPrepService.h>

Inheritance diagram for ToolBasedRawDigitPrepService:
RawDigitPrepService

Classes

struct  NamedTool
 
class  State
 

Public Types

using Index = unsigned int
 
using AdcChannelToolPtr = std::unique_ptr< AdcChannelTool >
 
using AdcChannelToolVector = std::vector< AdcChannelToolPtr >
 
using AdcChannelNamedToolVector = std::vector< NamedTool >
 
- Public Types inherited from RawDigitPrepService
using Index = unsigned int
 
using LongIndex = unsigned long
 

Public Member Functions

 ToolBasedRawDigitPrepService (fhicl::ParameterSet const &pset, art::ActivityRegistry &)
 
 ~ToolBasedRawDigitPrepService ()
 
int beginEvent (const DuneEventInfo &devt) const override
 
int endEvent (const DuneEventInfo &devt) const override
 
int prepare (detinfo::DetectorClocksData const &clockData, AdcChannelDataMap &prepdigs, std::vector< recob::Wire > *pwires, WiredAdcChannelDataMap *pintStates) const override
 
std::ostream & print (std::ostream &out=std::cout, std::string prefix="") const override
 
- Public Member Functions inherited from RawDigitPrepService
virtual ~RawDigitPrepService ()=default
 

Private Types

using Clock = std::chrono::steady_clock
 
using Duration = std::chrono::duration< double >
 

Private Member Functions

Statestate () const
 

Private Attributes

int m_LogLevel
 
bool m_DoWires
 
std::vector< std::stringm_ToolNames
 
std::vector< std::stringm_CallgrindToolNames
 
AdcChannelToolVector m_AdcChannelTools
 
AdcChannelNamedToolVector m_AdcChannelNamedTools
 
const AdcWireBuildingServicem_pWireBuildingService
 
std::set< std::stringm_cgset
 
std::unique_ptr< Statem_pstate
 

Detailed Description

Definition at line 36 of file ToolBasedRawDigitPrepService.h.

Member Typedef Documentation

Definition at line 48 of file ToolBasedRawDigitPrepService.h.

Definition at line 41 of file ToolBasedRawDigitPrepService.h.

Definition at line 47 of file ToolBasedRawDigitPrepService.h.

using ToolBasedRawDigitPrepService::Clock = std::chrono::steady_clock
private

Definition at line 78 of file ToolBasedRawDigitPrepService.h.

using ToolBasedRawDigitPrepService::Duration = std::chrono::duration<double>
private

Definition at line 79 of file ToolBasedRawDigitPrepService.h.

Definition at line 40 of file ToolBasedRawDigitPrepService.h.

Constructor & Destructor Documentation

ToolBasedRawDigitPrepService::ToolBasedRawDigitPrepService ( fhicl::ParameterSet const &  pset,
art::ActivityRegistry  
)

Definition at line 29 of file ToolBasedRawDigitPrepService_service.cc.

30 : m_LogLevel(pset.get<int>("LogLevel")),
31  m_DoWires(pset.get<bool>("DoWires")),
32  m_ToolNames(pset.get<vector<string>>("ToolNames")),
33  m_CallgrindToolNames(pset.get<vector<string>>("CallgrindToolNames")),
34  m_pWireBuildingService(nullptr),
36  m_pstate(new State) {
37  const string myname = "ToolBasedRawDigitPrepService::ctor: ";
38  pset.get_if_present<int>("LogLevel", m_LogLevel);
39  // Fetch the tools.
40  if ( m_ToolNames.size() ) {
42  if ( ptm == nullptr ) {
43  cout << myname << "ERROR: Unable to retrieve tool manaager." << endl;
44  } else {
45  for ( string tname : m_ToolNames ) {
46  if ( m_LogLevel ) cout << myname << " Fetching " << tname << endl;
47  AdcChannelToolPtr ptool = ptm->getPrivate<AdcChannelTool>(tname);
48  NamedTool nt(tname, ptool.get());
49  if ( nt.tool ) {
50  if ( m_LogLevel ) cout << myname << " Found tool " << tname << " @ " << nt.tool << endl;
51  m_AdcChannelTools.push_back(std::move(ptool));
52  m_AdcChannelNamedTools.push_back(nt);
53  } else {
54  cout << myname << "ERROR: Unable to retrieve display tool " << tname << endl;
55  }
56  }
57  }
58  }
59  state().toolTimes.resize(m_ToolNames.size());
60  if ( m_DoWires ) {
61  if ( m_LogLevel ) cout << myname << "Fetching wire building service." << endl;
63  if ( m_LogLevel ) cout << myname << " Wire building service: @" << m_pWireBuildingService << endl;
64  }
65  if ( m_LogLevel >=1 ) print(cout, myname);
66 }
const AdcWireBuildingService * m_pWireBuildingService
std::vector< std::string > m_ToolNames
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const override
AdcChannelNamedToolVector m_AdcChannelNamedTools
std::unique_ptr< AdcChannelTool > AdcChannelToolPtr
def move(depos, offset)
Definition: depos.py:107
std::vector< std::string > m_CallgrindToolNames
std::unique_ptr< T > getPrivate(std::string name)
static DuneToolManager * instance(std::string fclname="", int dbg=1)
QTextStream & endl(QTextStream &s)
ToolBasedRawDigitPrepService::~ToolBasedRawDigitPrepService ( )

Definition at line 70 of file ToolBasedRawDigitPrepService_service.cc.

70  {
71  const string myname = "ToolBasedRawDigitPrepService:dtor: ";
72  if ( state().nevtBegin != state().nevtEnd ) {
73  cout << myname << "WARNING: Event counts are inconsistent: " << state().nevtBegin
74  << " != " << state().nevtEnd << endl;
75  }
76  Index ntoo = m_ToolNames.size();
77  Index nevt = state().nevtEnd;
78  if ( m_LogLevel >= 1 ) {
79  cout << myname << "Event count: " << nevt << endl;
80  cout << myname << " Call count: " << state().ncall << endl;
81  cout << myname << "Time report for " << ntoo << " tools." << endl;
82  string sunit = "sec/event";
83  float xnevt = float(nevt);
84  if ( nevt == 0 ) {
85  xnevt = 1.0;
86  sunit = "sec";
87  }
88  for ( Index itoo=0; itoo<ntoo; ++itoo ) {
89  string name = m_ToolNames[itoo];
90  double time = state().toolTimes[itoo].count();
91  cout << myname << setw(30) << name << ":"
92  << setw(7) << std::fixed << setprecision(2)
93  << time/xnevt << " " << sunit << endl;
94  }
95  }
96 }
static QCString name
Definition: declinfo.cpp:673
std::vector< std::string > m_ToolNames
unsigned int Index
Q_EXPORT QTSManip setprecision(int p)
Definition: qtextstream.h:343
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
QTextStream & endl(QTextStream &s)

Member Function Documentation

int ToolBasedRawDigitPrepService::beginEvent ( const DuneEventInfo devt) const
overridevirtual

Reimplemented from RawDigitPrepService.

Definition at line 100 of file ToolBasedRawDigitPrepService_service.cc.

100  {
101  const string myname = "ToolBasedRawDigitPrepService:beginEvent: ";
102  if ( m_LogLevel >= 2 ) {
103  cout << myname << "Begin processing run " << devt.runString();
104  cout << " event " << devt.event;
105  cout << " with " << m_AdcChannelNamedTools.size() << " tools." << endl;
106  }
107  if ( state().nevtBegin != state().nevtEnd ) {
108  cout << myname << "WARNING: Event counts are inconsistent: " << state().nevtBegin
109  << " != " << state().nevtEnd << endl;
110  }
111  ++state().nevtBegin;
112  Index nfail = 0;
113  if ( m_AdcChannelNamedTools.size() ) {
114  for ( NamedTool nt : m_AdcChannelNamedTools ) {
115  DataMap ret = nt.tool->beginEvent(devt);
116  if ( ret.status() ) {
117  ++nfail;
118  cout << myname << "WARNING: Iniitalization for tool " << nt.name
119  << " failed for event " << devt.event << " with status code " << ret.status() << endl;
120  }
121  }
122  }
123  return nfail;
124 }
unsigned int Index
int status() const
Definition: DataMap.h:202
AdcChannelNamedToolVector m_AdcChannelNamedTools
std::string runString(Index opt=2) const
QTextStream & endl(QTextStream &s)
int ToolBasedRawDigitPrepService::endEvent ( const DuneEventInfo devt) const
overridevirtual

Reimplemented from RawDigitPrepService.

Definition at line 128 of file ToolBasedRawDigitPrepService_service.cc.

128  {
129  const string myname = "ToolBasedRawDigitPrepService:endEvent: ";
130  if ( m_LogLevel >= 2 ) {
131  cout << myname << "End processing run " << devt.runString();
132  cout << " event " << devt.event;
133  cout << " with " << m_AdcChannelNamedTools.size() << " tools." << endl;
134  }
135  Index nfail = 0;
136  ++state().nevtEnd;
137  if ( state().nevtBegin != state().nevtEnd ) {
138  cout << myname << "WARNING: Event counts are inconsistent: " << state().nevtBegin
139  << " != " << state().nevtEnd << endl;
140  }
141  if ( m_AdcChannelNamedTools.size() ) {
142  for ( NamedTool nt : m_AdcChannelNamedTools ) {
143  DataMap ret = nt.tool->endEvent(devt);
144  if ( ret.status() ) {
145  ++nfail;
146  cout << myname << "WARNING: Event finalization for tool " << nt.name
147  << " failed for event " << devt.event << " with status code " << ret.status() << endl;
148  }
149  }
150  }
151  return nfail;
152 }
unsigned int Index
int status() const
Definition: DataMap.h:202
AdcChannelNamedToolVector m_AdcChannelNamedTools
std::string runString(Index opt=2) const
QTextStream & endl(QTextStream &s)
int ToolBasedRawDigitPrepService::prepare ( detinfo::DetectorClocksData const &  clockData,
AdcChannelDataMap prepdigs,
std::vector< recob::Wire > *  pwires,
WiredAdcChannelDataMap pintStates 
) const
overridevirtual

Implements RawDigitPrepService.

Definition at line 157 of file ToolBasedRawDigitPrepService_service.cc.

159  {
160  const string myname = "ToolBasedRawDigitPrepService:prepare: ";
161  // Loop over tools.
162  ++state().ncall;
163  if ( m_LogLevel >= 2 ) cout << myname << "Processing " << datamap.size() << " channels with "
164  << m_AdcChannelNamedTools.size() << " tools." << endl;
165  if ( m_AdcChannelNamedTools.size() ) {
166  Index itoo = 0;
167  for ( NamedTool nt : m_AdcChannelNamedTools ) {
168  if ( m_LogLevel >= 3 ) cout << myname << " Running tool " << nt.name << endl;
169  bool useCallgrind = m_cgset.count(nt.name);
170  if ( useCallgrind ) {
171  CALLGRIND_START_INSTRUMENTATION;
172  CALLGRIND_TOGGLE_COLLECT;
173  }
174  auto start = Clock::now();
175  DataMap ret = nt.tool->updateMap(datamap);
176  auto stop = Clock::now();
177  if ( useCallgrind ) {
178  CALLGRIND_TOGGLE_COLLECT;
179  CALLGRIND_STOP_INSTRUMENTATION;
180  }
181  Duration dtim =stop - start;
182  state().toolTimes[itoo] += dtim;
183  if ( ret ) {
184  cout << myname << "WARNING: Tool " << nt.name << " failed";
185  if ( ret.haveIntVector("failedChannels") ) {
186  Index ncha = ret.getIntVector("failedChannels").size();
187  cout << " for " << ncha << " channel" << (ncha == 1 ? "" : "s");
188  }
189  cout << " with error " << ret.status();
190  if ( ret.haveIntVector("failedCodes") ) {
191  Index ncod = ret.getIntVector("failedCodes").size();
192  if ( ncod > 1 ) cout << " and " << ncod - 1 << " other errors";
193  }
194  cout << "." << endl;
195  }
196  if ( m_LogLevel >= 4 ) {
197  cout << myname << "----------------------------" << endl;
198  ret.print();
199  cout << myname << "----------------------------" << endl;
200  }
201  ++itoo;
202  }
203  }
204  if ( m_DoWires ) {
205  for ( auto& chdata : datamap ) {
206  AdcChannelData& acd = chdata.second;
207  m_pWireBuildingService->build(acd, pwires);
208  }
209  }
210  return 0;
211 }
const AdcWireBuildingService * m_pWireBuildingService
std::chrono::duration< double > Duration
const IntVector & getIntVector(Name name) const
Definition: DataMap.h:219
unsigned int Index
void print(std::ostream *pout) const
Definition: DataMap.h:245
int status() const
Definition: DataMap.h:202
virtual int build(AdcChannelData &data, WireVector *wires) const =0
AdcChannelNamedToolVector m_AdcChannelNamedTools
bool haveIntVector(Name name) const
Definition: DataMap.h:208
QTextStream & endl(QTextStream &s)
std::ostream & ToolBasedRawDigitPrepService::print ( std::ostream &  out = std::cout,
std::string  prefix = "" 
) const
overridevirtual

Implements RawDigitPrepService.

Definition at line 216 of file ToolBasedRawDigitPrepService_service.cc.

216  {
217  out << prefix << "ToolBasedRawDigitPrepService:" << endl;
218  out << prefix << " LogLevel: " << m_LogLevel << endl;
219  out << prefix << " DoWires: " << m_DoWires << endl;
220  if ( m_AdcChannelNamedTools.size() ) {
221  cout << prefix << " ADC channel tools:";
222  for ( const NamedTool& nm : m_AdcChannelNamedTools ) {
223  out << "\n" << prefix << " " << nm.name;
224  if ( m_cgset.count(nm.name) ) cout << " (callgrind enabled)";
225  }
226  cout << endl;
227  } else {
228  out << prefix << " No ADC channel tools." << endl;
229  }
230  return out;
231 }
AdcChannelNamedToolVector m_AdcChannelNamedTools
QTextStream & endl(QTextStream &s)
State& ToolBasedRawDigitPrepService::state ( ) const
inlineprivate

Definition at line 89 of file ToolBasedRawDigitPrepService.h.

89 { return *m_pstate; }

Member Data Documentation

AdcChannelNamedToolVector ToolBasedRawDigitPrepService::m_AdcChannelNamedTools
private

Definition at line 74 of file ToolBasedRawDigitPrepService.h.

AdcChannelToolVector ToolBasedRawDigitPrepService::m_AdcChannelTools
private

Definition at line 73 of file ToolBasedRawDigitPrepService.h.

std::vector<std::string> ToolBasedRawDigitPrepService::m_CallgrindToolNames
private

Definition at line 71 of file ToolBasedRawDigitPrepService.h.

std::set<std::string> ToolBasedRawDigitPrepService::m_cgset
private

Definition at line 76 of file ToolBasedRawDigitPrepService.h.

bool ToolBasedRawDigitPrepService::m_DoWires
private

Definition at line 69 of file ToolBasedRawDigitPrepService.h.

int ToolBasedRawDigitPrepService::m_LogLevel
private

Definition at line 68 of file ToolBasedRawDigitPrepService.h.

std::unique_ptr<State> ToolBasedRawDigitPrepService::m_pstate
private

Definition at line 88 of file ToolBasedRawDigitPrepService.h.

const AdcWireBuildingService* ToolBasedRawDigitPrepService::m_pWireBuildingService
private

Definition at line 75 of file ToolBasedRawDigitPrepService.h.

std::vector<std::string> ToolBasedRawDigitPrepService::m_ToolNames
private

Definition at line 70 of file ToolBasedRawDigitPrepService.h.


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