Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
flat::FlatMaker Class Reference
Inheritance diagram for flat::FlatMaker:
art::EDProducer art::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = ProducerBase::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 FlatMaker (const fhicl::ParameterSet &pset)
 
virtual ~FlatMaker () noexcept
 
void respondToOpenInputFile (const art::FileBlock &fb)
 
void InitializeOutfile ()
 
void beginJob ()
 
void produce (art::Event &evt) noexcept
 
void endJob ()
 
template<typename PROD , BranchType B = InEvent>
ProductID getProductID (std::string const &instanceName={}) const
 
template<typename PROD , BranchType B>
ProductID getProductID (ModuleDescription const &moduleDescription, std::string const &instanceName) const
 
bool modifiesEvent () const
 
template<typename T , BranchType = InEvent>
ProductToken< Tconsumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< Tconsumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TconsumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< TmayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< TmayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TmayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

Protected Attributes

TFile * fFile
 
TTree * fTree
 
TTree * fSpillTree
 
TTree * fNuTree
 
TDirectory * fRecDir
 
TDirectory * fSpillDir
 
TDirectory * fNuDir
 
flat::FlatRecordfRec
 
flat::FlatSpillfSpillRec
 
flat::FlatNeutrinofNuRec
 
double fTotalPOT
 
double fTotalLivetime
 
long fTotalEvents
 
std::string fStandardRecordLabel
 
std::string fOutputName
 
bool fFillNuTree
 
std::string fDataTier
 
std::string fFileExtension
 

Detailed Description

Definition at line 25 of file FlatMaker_module.cc.

Member Typedef Documentation

using art::EDProducer::ModuleType = EDProducer
inherited

Definition at line 34 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::EDProducer::Table = ProducerBase::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 43 of file EDProducer.h.

using art::EDProducer::WorkerType = WorkerT<EDProducer>
inherited

Definition at line 35 of file EDProducer.h.

Constructor & Destructor Documentation

flat::FlatMaker::FlatMaker ( const fhicl::ParameterSet pset)
explicit

Definition at line 66 of file FlatMaker_module.cc.

67  : art::EDProducer(),
68  fFile(0),
69  fNuTree(0), fNuRec(0),
71  fStandardRecordLabel(pset.get<std::string>("StandardRecordLabel")),
72  fOutputName(pset.get<std::string>("OutputName")),
73  fFillNuTree(pset.get<bool>("FillNuTree")),
74  fDataTier(pset.get<std::string>("DataTier")),
75  fFileExtension(pset.get<std::string>("FileExtension"))
76  {
77  }
std::string fDataTier
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::string fFileExtension
std::string fOutputName
flat::FlatNeutrino * fNuRec
std::string fStandardRecordLabel
enum BeamMode string
flat::FlatMaker::~FlatMaker ( )
virtualnoexcept

Definition at line 80 of file FlatMaker_module.cc.

81  {
82  }

Member Function Documentation

void flat::FlatMaker::beginJob ( )
virtual

Reimplemented from art::EDProducer.

Definition at line 161 of file FlatMaker_module.cc.

162  {
163  }
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 146 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

147 {
148  if (!moduleContext_)
149  return ProductToken<T>::invalid();
150 
151  consumables_[BT].emplace_back(ConsumableType::Product,
152  TypeID{typeid(T)},
153  it.label(),
154  it.instance(),
155  it.process());
156  return ProductToken<T>{it};
157 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 161 of file Consumer.h.

References T.

162 {
163  if (!moduleContext_)
164  return;
165 
166  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
167 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 171 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

172 {
173  if (!moduleContext_)
174  return ViewToken<T>::invalid();
175 
176  consumables_[BT].emplace_back(ConsumableType::ViewElement,
177  TypeID{typeid(T)},
178  it.label(),
179  it.instance(),
180  it.process());
181  return ViewToken<T>{it};
182 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited
CurrentProcessingContext const* art::EDProducer::currentContext ( ) const
protectedinherited
void flat::FlatMaker::endJob ( )
virtual

Reimplemented from art::EDProducer.

Definition at line 202 of file FlatMaker_module.cc.

References DEFINE_ART_MODULE(), fDataTier, fFile, fFillNuTree, fNuDir, fNuRec, fNuTree, fRec, fRecDir, fSpillDir, fSpillRec, fSpillTree, fTotalEvents, fTotalLivetime, fTotalPOT, fTree, meta::MetadataManager::getInstance(), meta::MetadataManager::GetMetadata(), m, runNovaSAM::metadata, and Write().

203  {
204  fFile->cd();
205 
206  fRecDir->cd();
207  fTree->Write();
208  delete fRec; // triggers all the Write() commands for the sub-trees
209 
210  fSpillDir->cd();
211  fSpillTree->Write();
212  delete fSpillRec;
213 
214  if(fFillNuTree){
215  fNuDir->cd();
216  fNuTree->Write();
217  delete fNuRec;
218  }
219 
220  fFile->cd();
221 
222  std::map<std::string, std::string> metadata = meta::MetadataManager::getInstance().GetMetadata();
223  metadata["data_tier"] = fDataTier;
224  fFile->mkdir("metadata")->cd();
225 
226  for(const auto& m: metadata){
227  TObjString(m.second.c_str()).Write(m.first.c_str());
228  }
229 
230  fFile->cd();
231 
232  TH1* hPOT = new TH1D("TotalPOT", "TotalPOT;; POT", 1, 0, 1);
233  hPOT->Fill(.5, fTotalPOT);
234  hPOT->Write();
235 
236  TH1* hEvents = new TH1D("TotalEvents", "TotalEvents;; Events", 1, 0, 1);
237  hEvents->Fill(.5, fTotalEvents);
238  hEvents->Write();
239 
240  TH1* hLivetime = new TH1D("TotalLivetime", "TotalLiveTime;;Seconds", 1, 0, 1);
241  hLivetime->Fill(.5, fTotalLivetime);
242  hLivetime->Write();
243 
244  fFile->Close();
245  }
static MetadataManager & getInstance()
TDirectory * fSpillDir
std::map< std::string, std::string > & GetMetadata()
flat::FlatRecord * fRec
flat::FlatSpill * fSpillRec
TDirectory * fNuDir
std::string fDataTier
TDirectory * fRecDir
flat::FlatNeutrino * fNuRec
gm Write()
seed_t art::EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited
template<typename PROD , BranchType B>
ProductID art::EDProducer::getProductID ( std::string const &  instanceName = {}) const
inlineinherited

Definition at line 123 of file EDProducer.h.

References art::EDProducer::moduleDescription_.

Referenced by skim::NueSkimmer::CopyMichelSlice(), and skim::NueSkimmer::CopyMichelTrack().

124  {
125  return ProducerBase::getProductID<PROD, B>(moduleDescription_,
126  instanceName);
127  }
ModuleDescription moduleDescription_
Definition: EDProducer.h:115
template<typename PROD , BranchType B>
ProductID art::ProducerBase::getProductID ( ModuleDescription const &  moduleDescription,
std::string const &  instanceName 
) const
inherited

Definition at line 56 of file ProducerBase.h.

References art::ModuleDescription::moduleLabel().

Referenced by art::ProducerBase::modifiesEvent().

58  {
59  auto const& pd =
60  get_ProductDescription<PROD>(B, md.moduleLabel(), instanceName);
61  return pd.productID();
62  }
void flat::FlatMaker::InitializeOutfile ( )

Definition at line 118 of file FlatMaker_module.cc.

References ana::assert(), fFile, fFillNuTree, fNuDir, fNuRec, fNuTree, fOutputName, fRec, fRecDir, fSpillDir, fSpillRec, fSpillTree, fStandardRecordLabel, and fTree.

Referenced by respondToOpenInputFile().

119  {
120  assert(!fFile);
121  assert(!fOutputName.empty());
122 
123  mf::LogInfo("FlatMaker") << "Output filename is " << fOutputName;
124 
125  consumes<std::vector<caf::StandardRecord>>(fStandardRecordLabel);
126  consumes<caf::SRSpill>(fStandardRecordLabel);
127  if(fFillNuTree) consumes<caf::SRSpillTruthBranch>(fStandardRecordLabel);
128 
129  fFile = new TFile(fOutputName.c_str(), "RECREATE");
130 
131  fRecDir = fFile->mkdir("recTree");
132  fRecDir->cd();
133  fTree = new TTree("rec", "rec");
134  // Have trouble with memory usage (because several trees are open at
135  // once?). Set the maximum buffer usage (per tree) to 3MB (10x less than
136  // default)
137  fTree->SetAutoFlush(-3*1000*1000);
138 
139 
140  fRec = new flat::FlatRecord("rec.", fTree, 0);
141 
142 
143  fSpillDir = fFile->mkdir("spillTree");
144  fSpillDir->cd();
145 
146  fSpillTree = new TTree("spill", "spill");
147  fSpillTree->SetAutoFlush(-3*1000*1000);
148  fSpillRec = new flat::FlatSpill("spill.", fSpillTree, 0);
149 
150  if(fFillNuTree){
151  fNuDir = fFile->mkdir("nuTree");
152  fNuDir->cd();
153 
154  fNuTree = new TTree("nu", "nu");
155  fNuTree->SetAutoFlush(-3*1000*1000);
156  fNuRec = new flat::FlatNeutrino("nu.", fNuTree, 0);
157  }
158  }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
TDirectory * fSpillDir
flat::FlatRecord * fRec
flat::FlatSpill * fSpillRec
TDirectory * fNuDir
TDirectory * fRecDir
std::string fOutputName
Flat encoding of SRNeutrino.
Definition: FlatNeutrino.h:27
flat::FlatNeutrino * fNuRec
std::string fStandardRecordLabel
Flat encoding of StandardRecord.
Definition: FlatRecord.h:31
assert(nhit_max >=nhit_nbins)
Flat encoding of SRSpill.
Definition: FlatSpill.h:21
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 189 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

190 {
191  if (!moduleContext_)
192  return ProductToken<T>::invalid();
193 
194  consumables_[BT].emplace_back(ConsumableType::Product,
195  TypeID{typeid(T)},
196  it.label(),
197  it.instance(),
198  it.process());
199  return ProductToken<T>{it};
200 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 204 of file Consumer.h.

References T.

205 {
206  if (!moduleContext_)
207  return;
208 
209  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
210 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 214 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

215 {
216  if (!moduleContext_)
217  return ViewToken<T>::invalid();
218 
219  consumables_[BT].emplace_back(ConsumableType::ViewElement,
220  TypeID{typeid(T)},
221  it.label(),
222  it.instance(),
223  it.process());
224  return ViewToken<T>{it};
225 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID(), and string.

41  {
42  return true;
43  }
static cet::exempt_ptr<Consumer> art::Consumer::non_module_context ( )
staticinherited
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited
void flat::FlatMaker::produce ( art::Event evt)
virtualnoexcept

Implements art::EDProducer.

Definition at line 166 of file FlatMaker_module.cc.

References evt, fFillNuTree, flat::FlatSpill::Fill(), flat::FlatNeutrino::Fill(), flat::FlatRecord::Fill(), fNuRec, fNuTree, fRec, fSpillRec, fSpillTree, fStandardRecordLabel, fTotalEvents, fTotalLivetime, fTotalPOT, fTree, caf::SRSpill::livetime, caf_analysis::spill, caf::SRSpill::spillpot, and sr.

167  {
168  ++fTotalEvents;
169 
171  evt.getByLabel(fStandardRecordLabel, srcol);
172 
173  for(const caf::StandardRecord& sr: *srcol){
174  fRec->Fill(sr);
175  fTree->Fill();
176  }
177 
178 
180  evt.getByLabel(fStandardRecordLabel, spill);
181 
182  fSpillRec->Fill(*spill);
183  fSpillTree->Fill();
184 
185  // Should we have checked isgoodspill?
186  fTotalPOT += spill->spillpot;
187  fTotalLivetime += spill->livetime;
188 
189 
190  if(fFillNuTree){
192  evt.getByLabel(fStandardRecordLabel, srtruthcol);
193 
194  for(const caf::SRSpillTruthBranch& sr: *srtruthcol){
195  fNuRec->Fill(sr.nu);
196  fNuTree->Fill();
197  }
198  }
199  }
Truth info for all neutrinos in the spill.
flat::FlatRecord * fRec
flat::FlatSpill * fSpillRec
void Fill(const caf::SRSpill &sr)
void Fill(const caf::StandardRecord &sr)
Definition: FlatRecord.cxx:32
caf::StandardRecord * sr
flat::FlatNeutrino * fNuRec
float livetime
Length of readout [s].
Definition: SRSpill.h:40
std::string fStandardRecordLabel
The StandardRecord is the primary top-level object in the Common Analysis File trees.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
float spillpot
Definition: SRSpill.h:38
void Fill(const caf::SRNeutrino &sr)
void flat::FlatMaker::respondToOpenInputFile ( const art::FileBlock fb)

Definition at line 85 of file FlatMaker_module.cc.

References ana::assert(), fFile, fFileExtension, art::FileBlock::fileName(), fOutputName, InitializeOutfile(), and APDHVSetting::temp.

86  {
87  if(!fFile) {
88  if(fOutputName == "") {
89 
90  // Filename wasn't set in the FCL. Construct it based on the input
91  // filename.
92  char temp[fb.fileName().size() + 1];
93  std::strcpy(temp, fb.fileName().c_str());
94  fOutputName = basename(temp);
95 
96  // if input is PID file (most likely should be), be a little careful
97  // Allows for dots in the file name than just the last bit (eg. prod5.1)
98  if(fOutputName.find(".pid.root") != std::string::npos) {
99  const size_t pidpos = fOutputName.find(".pid.root");
100  fOutputName.resize(pidpos);
101  }
102  else{
103  const size_t dotpos = fOutputName.find('.');
104  assert(dotpos != std::string::npos); // Must have a dot, surely?
105  fOutputName.resize(dotpos);
106  }
107  }
108 
109  fOutputName += fFileExtension;
110 
112 
113  }
114  }
std::string const & fileName() const
Definition: FileBlock.h:38
std::string fFileExtension
std::string fOutputName
assert(nhit_max >=nhit_nbins)
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Referenced by art::RootOutput::endJob().

void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Member Data Documentation

std::string flat::FlatMaker::fDataTier
protected

Definition at line 61 of file FlatMaker_module.cc.

Referenced by endJob().

TFile* flat::FlatMaker::fFile
protected

Definition at line 39 of file FlatMaker_module.cc.

Referenced by endJob(), InitializeOutfile(), and respondToOpenInputFile().

std::string flat::FlatMaker::fFileExtension
protected

Definition at line 62 of file FlatMaker_module.cc.

Referenced by respondToOpenInputFile().

bool flat::FlatMaker::fFillNuTree
protected

Definition at line 59 of file FlatMaker_module.cc.

Referenced by endJob(), InitializeOutfile(), and produce().

TDirectory* flat::FlatMaker::fNuDir
protected

Definition at line 47 of file FlatMaker_module.cc.

Referenced by endJob(), and InitializeOutfile().

flat::FlatNeutrino* flat::FlatMaker::fNuRec
protected

Definition at line 51 of file FlatMaker_module.cc.

Referenced by endJob(), InitializeOutfile(), and produce().

TTree* flat::FlatMaker::fNuTree
protected

Definition at line 43 of file FlatMaker_module.cc.

Referenced by endJob(), InitializeOutfile(), and produce().

std::string flat::FlatMaker::fOutputName
protected

Definition at line 58 of file FlatMaker_module.cc.

Referenced by InitializeOutfile(), and respondToOpenInputFile().

flat::FlatRecord* flat::FlatMaker::fRec
protected

Definition at line 49 of file FlatMaker_module.cc.

Referenced by endJob(), InitializeOutfile(), and produce().

TDirectory* flat::FlatMaker::fRecDir
protected

Definition at line 45 of file FlatMaker_module.cc.

Referenced by endJob(), and InitializeOutfile().

TDirectory* flat::FlatMaker::fSpillDir
protected

Definition at line 46 of file FlatMaker_module.cc.

Referenced by endJob(), and InitializeOutfile().

flat::FlatSpill* flat::FlatMaker::fSpillRec
protected

Definition at line 50 of file FlatMaker_module.cc.

Referenced by endJob(), InitializeOutfile(), and produce().

TTree* flat::FlatMaker::fSpillTree
protected

Definition at line 42 of file FlatMaker_module.cc.

Referenced by endJob(), InitializeOutfile(), and produce().

std::string flat::FlatMaker::fStandardRecordLabel
protected

Definition at line 57 of file FlatMaker_module.cc.

Referenced by InitializeOutfile(), and produce().

long flat::FlatMaker::fTotalEvents
protected

Definition at line 55 of file FlatMaker_module.cc.

Referenced by endJob(), and produce().

double flat::FlatMaker::fTotalLivetime
protected

Definition at line 54 of file FlatMaker_module.cc.

Referenced by endJob(), and produce().

double flat::FlatMaker::fTotalPOT
protected

Definition at line 53 of file FlatMaker_module.cc.

Referenced by endJob(), and produce().

TTree* flat::FlatMaker::fTree
protected

Definition at line 41 of file FlatMaker_module.cc.

Referenced by endJob(), InitializeOutfile(), and produce().


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