Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
cvn::CVNZlibMakerProtoDUNE Class Reference
Inheritance diagram for cvn::CVNZlibMakerProtoDUNE:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Classes

struct  PrimaryTrainingInfo
 

Public Member Functions

 CVNZlibMakerProtoDUNE (fhicl::ParameterSet const &pset)
 
 ~CVNZlibMakerProtoDUNE ()
 
void beginJob () override
 
void analyze (const art::Event &evt) override
 
void reconfigure (const fhicl::ParameterSet &pset)
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
fhicl::ParameterSetID selectorConfig () const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void write_files (const PrimaryTrainingInfo &primary, const art::Ptr< cvn::PixelMap > pm, unsigned int n) const
 

Private Attributes

std::string fOutputDir
 
std::string fPixelMapInput
 
bool fSetLog
 
std::vector< boolfReverseViews
 
std::string fLArG4ModuleLabel
 
std::string out_dir
 

Additional Inherited Members

- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 
- Protected Member Functions inherited from art::Observer
std::string const & processName () const
 
bool wantAllEvents () const noexcept
 
bool wantEvent (ScheduleID id, Event const &e) const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &select_paths, std::vector< std::string > const &reject_paths, fhicl::ParameterSet const &config)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 36 of file CVNZlibMakerProtoDUNE_module.cc.

Constructor & Destructor Documentation

cvn::CVNZlibMakerProtoDUNE::CVNZlibMakerProtoDUNE ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 78 of file CVNZlibMakerProtoDUNE_module.cc.

79  : EDAnalyzer(pset)
80  {
81  this->reconfigure(pset);
82  }
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
void reconfigure(const fhicl::ParameterSet &pset)
cvn::CVNZlibMakerProtoDUNE::~CVNZlibMakerProtoDUNE ( )

Definition at line 85 of file CVNZlibMakerProtoDUNE_module.cc.

86  { }

Member Function Documentation

void cvn::CVNZlibMakerProtoDUNE::analyze ( const art::Event evt)
override

Definition at line 131 of file CVNZlibMakerProtoDUNE_module.cc.

132  {
133 
134  // Get the pixel maps
135  std::vector<art::Ptr<cvn::PixelMap>> pixelmaps;
137  auto h_pixelmaps = evt.getHandle<std::vector<cvn::PixelMap>>(itag1);
138  if (h_pixelmaps)
139  art::fill_ptr_vector(pixelmaps, h_pixelmaps);
140 
141  // If no pixel maps, quit
142  if (pixelmaps.size() == 0) return;
143 
144  // MC information
146 
147  // The truth information we need is the interaction vertex and interaction type
148  AssignLabels labels;
149  unsigned short beamParticleInteraction;
150 
151  // We only have one beam particle called "primary", so find it. It should be the
152  // first particle, but best not to assume
153  float beamParticleEnergy = 0;
154  TVector3 beamParticleVtx; // This is the interaction vertex
155  int beamParticlePDG = 0;
156 
157  bool gotPrimary = false;
158  for(auto const m : piService->ParticleList()){
159  const simb::MCParticle* particle = m.second;
160  if(particle->Process().compare("primary")==0){
161  beamParticleEnergy = particle->E();
162  beamParticleVtx.SetXYZ(particle->EndX(),particle->EndY(),particle->EndZ());
163  beamParticlePDG = particle->PdgCode();
164  beamParticleInteraction = labels.GetProtoDUNEBeamInteractionType(*particle);
165  gotPrimary = true;
166  break;
167  }
168  }
169 
170  if(!gotPrimary) return;
171 
172  const PrimaryTrainingInfo beamPrimary(beamParticleVtx,beamParticleInteraction,beamParticlePDG,beamParticleEnergy);
173 
174  this->write_files(beamPrimary, pixelmaps.at(0), evt.event());
175  }
double E(const int i=0) const
Definition: MCParticle.h:233
int PdgCode() const
Definition: MCParticle.h:212
EventNumber_t event() const
Definition: DataViewImpl.cc:85
double EndZ() const
Definition: MCParticle.h:228
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string Process() const
Definition: MCParticle.h:215
double EndY() const
Definition: MCParticle.h:227
void write_files(const PrimaryTrainingInfo &primary, const art::Ptr< cvn::PixelMap > pm, unsigned int n) const
const sim::ParticleList & ParticleList() const
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
double EndX() const
Definition: MCParticle.h:226
void cvn::CVNZlibMakerProtoDUNE::beginJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 99 of file CVNZlibMakerProtoDUNE_module.cc.

100  {
101  // Set the output directory.
102  // First we look for CONDOR_DIR_INPUT and set it to the grid location.
103  // If it isn't there, we look for a FHICL parameter.
104  // Otherwise it just goes to the current directory.
105 /*
106  char const* grid_dir = getenv("CONDOR_DIR_INPUT");
107  if (grid_dir != NULL) {
108  char const* tmp_grid_dir = getenv("TMP");
109  if (tmp_grid_dir == NULL)
110  throw art::Exception(art::errors::NotFound)
111  << "Could not find environment variable \"TMP\" which "
112  << "is usually set for condor_lar environment." << std::endl;
113  out_dir = std::string(tmp_grid_dir) + "/out";
114  }
115 */
116  if (fOutputDir != "")
118 
119  else
120  out_dir = ".";
121 
122  // Throw an error if the specified output directory doesn't exist
123  if (!fs::exists(out_dir))
125  << "Output directory " << out_dir << " does not exist!" << std::endl;
126 
127  // std::cout << "Writing files to output directory " << out_dir << std::endl;
128  }
bool exists(std::string path)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
QTextStream & endl(QTextStream &s)
void cvn::CVNZlibMakerProtoDUNE::reconfigure ( const fhicl::ParameterSet pset)

Definition at line 89 of file CVNZlibMakerProtoDUNE_module.cc.

90  {
91  fOutputDir = pset.get<std::string>("OutputDir", "");
92  fPixelMapInput = pset.get<std::string>("PixelMapInput");
93  fSetLog = pset.get<bool>("SetLog");
94  fReverseViews = pset.get<std::vector<bool>>("ReverseViews");
95  fLArG4ModuleLabel = pset.get<std::string>("LArG4ModuleLabel");
96  }
std::string string
Definition: nybbler.cc:12
T get(std::string const &key) const
Definition: ParameterSet.h:271
void cvn::CVNZlibMakerProtoDUNE::write_files ( const PrimaryTrainingInfo primary,
const art::Ptr< cvn::PixelMap pm,
unsigned int  n 
) const
private

Definition at line 178 of file CVNZlibMakerProtoDUNE_module.cc.

179  {
180  CVNImageUtils image_utils;
181  std::vector<unsigned char> pixel_array(3 * pm->NWire() * pm->NTdc());
182 
183  image_utils.DisableRegionSelection();
184  image_utils.SetLogScale(fSetLog);
185  image_utils.SetViewReversal(fReverseViews);
186  image_utils.ConvertPixelMapToPixelArray(*(pm.get()),pixel_array);
187 
188  ulong src_len = 3 * pm->NWire() * pm->NTdc(); // pixelArray length
189  ulong dest_len = compressBound(src_len); // calculate size of the compressed data
190  char* ostream = (char *) malloc(dest_len); // allocate memory for the compressed data
191 
192  int res = compress((Bytef *) ostream, &dest_len, (Bytef *) &pixel_array[0], src_len);
193 
194  // Buffer error
195 
196  if (res == Z_BUF_ERROR)
197  std::cout << "Buffer too small!" << std::endl;
198 
199  // Memory error
200  else if (res == Z_MEM_ERROR)
201  std::cout << "Not enough memory for compression!" << std::endl;
202 
203  // Compression ok
204  else {
205 
206  // Create output files
207  std::string image_file_name = out_dir + "/cvn_event_" + std::to_string(n) + ".gz";
208  std::string info_file_name = out_dir + "/cvn_event_" + std::to_string(n) + ".info";
209 
210  std::ofstream image_file (image_file_name, std::ofstream::binary);
211  std::ofstream info_file (info_file_name);
212 
213  if(image_file.is_open() && info_file.is_open()) {
214 
215  // Write compressed data to file
216 
217  image_file.write(ostream, dest_len);
218 
219  image_file.close(); // close file
220 
221  // Write truth information
222 
223  info_file << primary.vertex.X() << std::endl;
224  info_file << primary.vertex.Y() << std::endl;
225  info_file << primary.vertex.Z() << std::endl;
226  info_file << primary.energy << std::endl;
227  info_file << primary.interaction << std::endl;
228  info_file << primary.pdgCode << std::endl;
229  info_file.close(); // close file
230  }
231  else {
232 
233  if (image_file.is_open())
234  image_file.close();
235  else
237  << "Unable to open file " << image_file_name << "!" << std::endl;
238 
239  if (info_file.is_open())
240  info_file.close();
241  else
243  << "Unable to open file " << info_file_name << "!" << std::endl;
244  }
245  }
246 
247  free(ostream); // free allocated memory
248 
249  } // cvn::CVNZlibMakerProtoDUNE::write_files
std::string string
Definition: nybbler.cc:12
std::void_t< T > n
unsigned long ulong
Definition: qglobal.h:352
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
unsigned int NTdc() const
Width in tdcs.
Definition: PixelMap.h:32
T const * get() const
Definition: Ptr.h:149
unsigned int NWire() const
Length in wires.
Definition: PixelMap.h:29
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
QTextStream & endl(QTextStream &s)

Member Data Documentation

std::string cvn::CVNZlibMakerProtoDUNE::fLArG4ModuleLabel
private

Definition at line 69 of file CVNZlibMakerProtoDUNE_module.cc.

std::string cvn::CVNZlibMakerProtoDUNE::fOutputDir
private

Definition at line 64 of file CVNZlibMakerProtoDUNE_module.cc.

std::string cvn::CVNZlibMakerProtoDUNE::fPixelMapInput
private

Definition at line 65 of file CVNZlibMakerProtoDUNE_module.cc.

std::vector<bool> cvn::CVNZlibMakerProtoDUNE::fReverseViews
private

Definition at line 67 of file CVNZlibMakerProtoDUNE_module.cc.

bool cvn::CVNZlibMakerProtoDUNE::fSetLog
private

Definition at line 66 of file CVNZlibMakerProtoDUNE_module.cc.

std::string cvn::CVNZlibMakerProtoDUNE::out_dir
private

Definition at line 71 of file CVNZlibMakerProtoDUNE_module.cc.


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