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

#include <TpcToolBasedRawDigitPrepService.h>

Inheritance diagram for TpcToolBasedRawDigitPrepService:
RawDigitPrepService

Classes

struct  NamedTool
 
class  State
 

Public Types

using Index = unsigned int
 
using TpcDataToolPtr = std::unique_ptr< TpcDataTool >
 
using TpcDataToolVector = std::vector< TpcDataToolPtr >
 
using TpcDataNamedToolVector = std::vector< NamedTool >
 
- Public Types inherited from RawDigitPrepService
using Index = unsigned int
 
using LongIndex = unsigned long
 

Public Member Functions

 TpcToolBasedRawDigitPrepService (fhicl::ParameterSet const &pset, art::ActivityRegistry &)
 
 ~TpcToolBasedRawDigitPrepService ()
 
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
 
TpcDataToolVector m_TpcDataTools
 
TpcDataNamedToolVector m_TpcDataNamedTools
 
const AdcWireBuildingServicem_pWireBuildingService
 
std::set< std::stringm_cgset
 
std::unique_ptr< Statem_pstate
 

Detailed Description

Definition at line 36 of file TpcToolBasedRawDigitPrepService.h.

Member Typedef Documentation

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

Definition at line 78 of file TpcToolBasedRawDigitPrepService.h.

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

Definition at line 79 of file TpcToolBasedRawDigitPrepService.h.

Definition at line 40 of file TpcToolBasedRawDigitPrepService.h.

Definition at line 48 of file TpcToolBasedRawDigitPrepService.h.

Definition at line 41 of file TpcToolBasedRawDigitPrepService.h.

Definition at line 47 of file TpcToolBasedRawDigitPrepService.h.

Constructor & Destructor Documentation

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

Definition at line 29 of file TpcToolBasedRawDigitPrepService_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 = "TpcToolBasedRawDigitPrepService::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  TpcDataToolPtr ptool = ptm->getPrivate<TpcDataTool>(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_TpcDataTools.push_back(std::move(ptool));
52  m_TpcDataNamedTools.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 }
std::unique_ptr< TpcDataTool > TpcDataToolPtr
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const override
def move(depos, offset)
Definition: depos.py:107
std::unique_ptr< T > getPrivate(std::string name)
const AdcWireBuildingService * m_pWireBuildingService
static DuneToolManager * instance(std::string fclname="", int dbg=1)
QTextStream & endl(QTextStream &s)
TpcToolBasedRawDigitPrepService::~TpcToolBasedRawDigitPrepService ( )

Definition at line 70 of file TpcToolBasedRawDigitPrepService_service.cc.

70  {
71  const string myname = "TpcToolBasedRawDigitPrepService: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
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 TpcToolBasedRawDigitPrepService::beginEvent ( const DuneEventInfo devt) const
overridevirtual

Reimplemented from RawDigitPrepService.

Definition at line 100 of file TpcToolBasedRawDigitPrepService_service.cc.

100  {
101  const string myname = "TpcToolBasedRawDigitPrepService:beginEvent: ";
102  if ( m_LogLevel >= 2 ) {
103  cout << myname << "Begin processing run " << devt.runString();
104  cout << " event " << devt.event;
105  cout << " with " << m_TpcDataNamedTools.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_TpcDataNamedTools.size() ) {
114  for ( NamedTool nt : m_TpcDataNamedTools ) {
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
std::string runString(Index opt=2) const
QTextStream & endl(QTextStream &s)
int TpcToolBasedRawDigitPrepService::endEvent ( const DuneEventInfo devt) const
overridevirtual

Reimplemented from RawDigitPrepService.

Definition at line 128 of file TpcToolBasedRawDigitPrepService_service.cc.

128  {
129  const string myname = "TpcToolBasedRawDigitPrepService:endEvent: ";
130  if ( m_LogLevel >= 2 ) {
131  cout << myname << "End processing run " << devt.runString();
132  cout << " event " << devt.event;
133  cout << " with " << m_TpcDataNamedTools.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_TpcDataNamedTools.size() ) {
142  for ( NamedTool nt : m_TpcDataNamedTools ) {
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
std::string runString(Index opt=2) const
QTextStream & endl(QTextStream &s)
int TpcToolBasedRawDigitPrepService::prepare ( detinfo::DetectorClocksData const &  clockData,
AdcChannelDataMap prepdigs,
std::vector< recob::Wire > *  pwires,
WiredAdcChannelDataMap pintStates 
) const
overridevirtual

Implements RawDigitPrepService.

Definition at line 157 of file TpcToolBasedRawDigitPrepService_service.cc.

159  {
160  const string myname = "TpcToolBasedRawDigitPrepService:prepare: ";
161  // Loop over tools.
162  ++state().ncall;
163  if ( m_LogLevel >= 2 ) cout << myname << "Processing " << datamap.size() << " channels with "
164  << m_TpcDataNamedTools.size() << " tools." << endl;
165  if ( m_TpcDataNamedTools.size() ) {
166  Index itoo = 0;
167  for ( NamedTool nt : m_TpcDataNamedTools ) {
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 }
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
const AdcWireBuildingService * m_pWireBuildingService
bool haveIntVector(Name name) const
Definition: DataMap.h:208
QTextStream & endl(QTextStream &s)
std::ostream & TpcToolBasedRawDigitPrepService::print ( std::ostream &  out = std::cout,
std::string  prefix = "" 
) const
overridevirtual

Implements RawDigitPrepService.

Definition at line 216 of file TpcToolBasedRawDigitPrepService_service.cc.

216  {
217  out << prefix << "TpcToolBasedRawDigitPrepService:" << endl;
218  out << prefix << " LogLevel: " << m_LogLevel << endl;
219  out << prefix << " DoWires: " << m_DoWires << endl;
220  if ( m_TpcDataNamedTools.size() ) {
221  cout << prefix << " ADC channel tools:";
222  for ( const NamedTool& nm : m_TpcDataNamedTools ) {
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 }
QTextStream & endl(QTextStream &s)
State& TpcToolBasedRawDigitPrepService::state ( ) const
inlineprivate

Definition at line 89 of file TpcToolBasedRawDigitPrepService.h.

89 { return *m_pstate; }

Member Data Documentation

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

Definition at line 71 of file TpcToolBasedRawDigitPrepService.h.

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

Definition at line 76 of file TpcToolBasedRawDigitPrepService.h.

bool TpcToolBasedRawDigitPrepService::m_DoWires
private

Definition at line 69 of file TpcToolBasedRawDigitPrepService.h.

int TpcToolBasedRawDigitPrepService::m_LogLevel
private

Definition at line 68 of file TpcToolBasedRawDigitPrepService.h.

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

Definition at line 88 of file TpcToolBasedRawDigitPrepService.h.

const AdcWireBuildingService* TpcToolBasedRawDigitPrepService::m_pWireBuildingService
private

Definition at line 75 of file TpcToolBasedRawDigitPrepService.h.

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

Definition at line 70 of file TpcToolBasedRawDigitPrepService.h.

TpcDataNamedToolVector TpcToolBasedRawDigitPrepService::m_TpcDataNamedTools
private

Definition at line 74 of file TpcToolBasedRawDigitPrepService.h.

TpcDataToolVector TpcToolBasedRawDigitPrepService::m_TpcDataTools
private

Definition at line 73 of file TpcToolBasedRawDigitPrepService.h.


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