Classes | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
util::TFileMetadataDUNE Class Reference

#include <TFileMetadataDUNE.h>

Classes

struct  metadata
 

Public Member Functions

 TFileMetadataDUNE (fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
 
 ~TFileMetadataDUNE ()
 
void reconfigure (fhicl::ParameterSet const &p)
 

Public Attributes

metadata md
 
std::set< art::SubRunIDfSubRunNumbers
 
std::map< std::string, std::stringmdmap
 

Private Member Functions

void postBeginJob ()
 
void postOpenFile (std::string const &fn)
 
void postEvent (art::Event const &ev, art::ScheduleContext)
 
void postCloseOutput (art::OutputFileInfo const &)
 
void postBeginSubRun (art::SubRun const &subrun)
 
void postEndJob ()
 

Private Attributes

bool fGenerateTFileMetadata
 
std::string frunType
 
std::string fJSONFileName
 

Detailed Description

Definition at line 30 of file TFileMetadataDUNE.h.

Constructor & Destructor Documentation

util::TFileMetadataDUNE::TFileMetadataDUNE ( fhicl::ParameterSet const &  pset,
art::ActivityRegistry reg 
)

Definition at line 73 of file TFileMetadataDUNE_service.cc.

74  :
76 {
77  reconfigure(pset);
78 
79  // Register for callbacks.
80 
87 }
void reconfigure(fhicl::ParameterSet const &p)
GlobalSignal< detail::SignalResponseType::FIFO, void()> sPostBeginJob
GlobalSignal< detail::SignalResponseType::LIFO, void()> sPostEndJob
GlobalSignal< detail::SignalResponseType::LIFO, void(SubRun const &)> sPostBeginSubRun
void postCloseOutput(art::OutputFileInfo const &)
void postBeginSubRun(art::SubRun const &subrun)
GlobalSignal< detail::SignalResponseType::LIFO, void(Event const &, ScheduleContext)> sPostProcessEvent
GlobalSignal< detail::SignalResponseType::LIFO, void(std::string const &)> sPostOpenFile
void postEvent(art::Event const &ev, art::ScheduleContext)
GlobalSignal< detail::SignalResponseType::LIFO, void(OutputFileInfo const &)> sPostCloseOutputFile
void postOpenFile(std::string const &fn)
util::TFileMetadataDUNE::~TFileMetadataDUNE ( )

Definition at line 91 of file TFileMetadataDUNE_service.cc.

92 {
93 }

Member Function Documentation

void util::TFileMetadataDUNE::postBeginJob ( )
private

Definition at line 112 of file TFileMetadataDUNE_service.cc.

113 {
114  // only generate metadata when this is true
115  if (!fGenerateTFileMetadata) return;
116 
117  // get the start time
118  md.fstart_time = time(0);
119 
120  // Get art metadata service and extract paramters from there
122 
124  artmds->getMetadata(artmd);
125 
126  for(auto const & d : artmd) {
127  mdmap[d.first] = d.second;
128  //std::cout << d.first << " " << d.second << std::endl;
129  }
130 
132 
133  // if a certain paramter/key is not found, assign an empty string value to it
134 
135  if ((it=mdmap.find("application.family"))!=mdmap.end()) {
136  std::cout << "Setting applicationFamily: " << it->second << std::endl;
137  std::get<0>(md.fapplication) = it->second;
138  }
139  else {
140  std::cout << "Setting applicationFamily: empty" << std::endl;
141  std::get<0>(md.fapplication) = "\" \"";
142  }
143 
144  if ((it=mdmap.find("art.process_name"))!=mdmap.end()) {
145  std::cout << "Setting process_name: " << it->second << std::endl;
146  std::get<1>(md.fapplication) = it->second;
147  }
148  else {
149  std::cout << "Setting process_name: empty" << std::endl;
150  std::get<1>(md.fapplication) = "\" \"";
151  }
152 
153  if ((it=mdmap.find("application.version"))!=mdmap.end()) std::get<2>(md.fapplication) = it->second;
154  else std::get<2>(md.fapplication) = "\" \"";
155 
156  if ((it=mdmap.find("application.version"))!=mdmap.end()) std::get<2>(md.fapplication) = it->second;
157  else std::get<2>(md.fapplication) = "\" \"";
158 
159  if ((it=mdmap.find("group"))!=mdmap.end()) md.fgroup = it->second;
160  else md.fgroup = "\" \"";
161 
162  if ((it=mdmap.find("file_type"))!=mdmap.end()) md.ffile_type = it->second;
163  else md.ffile_type = "\" \"";
164 
165  if ((it=mdmap.find("run_type"))!=mdmap.end()) frunType = it->second;
166  else frunType = "\" \"";
167 
168  //std::cout << "Run type: " << frunType << std::endl;
169 
170  //Remove this
171  if ((it=mdmap.find("art.run_type"))!=mdmap.end()) frunType = it->second;
172  else frunType = "\" \"";
173  //std::cout << "Run type: " << frunType << std::endl;
174 
175 }
intermediate_table::iterator iterator
std::vector< std::pair< std::string, std::string >> collection_type
std::map< std::string, std::string > mdmap
std::tuple< std::string, std::string, std::string > fapplication
void getMetadata(collection_type &coll) const
if(!yymsg) yymsg
QTextStream & endl(QTextStream &s)
void util::TFileMetadataDUNE::postBeginSubRun ( art::SubRun const &  subrun)
private

Definition at line 240 of file TFileMetadataDUNE_service.cc.

241 {
242 
243  if(!fGenerateTFileMetadata) return;
244 
245  art::RunNumber_t run = sr.run();
246  art::SubRunNumber_t subrun = sr.subRun();
247  art::SubRunID srid = sr.id();
248 
249  // save run, subrun and runType information once every subrun
250  if (fSubRunNumbers.count(srid) == 0){
251  fSubRunNumbers.insert(srid);
252  md.fruns.push_back(make_tuple(run, subrun, frunType));
253  }
254 }
std::set< art::SubRunID > fSubRunNumbers
std::vector< std::tuple< art::RunNumber_t, art::SubRunNumber_t, std::string > > fruns
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:119
static constexpr double sr
Definition: Units.h:166
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120
void util::TFileMetadataDUNE::postCloseOutput ( art::OutputFileInfo const &  output_file)
private

Definition at line 223 of file TFileMetadataDUNE_service.cc.

224 {
225 
226  if(!fGenerateTFileMetadata) return;
227 
228 
229  // save the first event
230  //if (md.fevent_count == 0) md.ffirst_event = event;
231  //md.flast_event = event;
232  // event counter
233  md.fFileName = output_file.fileName();
234 
235 }
void util::TFileMetadataDUNE::postEndJob ( )
private

Definition at line 258 of file TFileMetadataDUNE_service.cc.

259 {
260 
261  // Do nothing if generating TFile metadata is disabled.
262  if(!fGenerateTFileMetadata) return;
263 
264  // get metadata from the FileCatalogMetadataDUNE service, which is filled on its construction
265 
267  md.fMCGenerators = paramhandle->MCGenerators();
268  md.fMCOscillationP = paramhandle->MCOscillationP();
270  md.fMCBeamEnergy = paramhandle->MCBeamEnergy();
271  md.fMCBeamFluxID = paramhandle->MCBeamFluxID();
272  md.fMCName = paramhandle->MCName();
273  md.fMCDetectorType = paramhandle->MCDetectorType();
274  md.fMCNeutrinoFlavors = paramhandle->MCNeutrinoFlavors();
275  md.fMCMassHierarchy = paramhandle->MCMassHierarchy();
276  md.fMCMiscellaneous = paramhandle->MCMiscellaneous();
277  md.fMCGeometryVersion = paramhandle->MCGeometryVersion();
278  md.fMCOverlay = paramhandle->MCOverlay();
279  md.fDataRunMode = paramhandle->DataRunMode();
280  md.fDataDetectorType = paramhandle->DataDetectorType();
281  md.fDataName = paramhandle->DataName();
282  md.fStageName = paramhandle->StageName();
283 
284  //update end time
285  md.fend_time = time(0);
286 
287  // convert start and end times into time format: Year-Month-DayTHours:Minutes:Seconds
288  char endbuf[80], startbuf[80];
289  struct tm tstruct;
290  tstruct = *localtime(&md.fend_time);
291  strftime(endbuf,sizeof(endbuf),"%Y-%m-%dT%H:%M:%S",&tstruct);
292  tstruct = *localtime(&md.fstart_time);
293  strftime(startbuf,sizeof(startbuf),"%Y-%m-%dT%H:%M:%S",&tstruct);
294 
295  // open a json file and write everything from the struct md complying to the
296  // samweb json format. This json file holds the below information temporarily.
297  // If you submitted a grid job invoking this service, the information from
298  // this file is appended to a final json file and this file will be removed
299 
300  std::ofstream jsonfile;
301  jsonfile.open(fJSONFileName);
302  jsonfile<<"{\n \"application\": {\n \"family\": "<<std::get<0>(md.fapplication)<<",\n \"name\": ";
303  jsonfile<<std::get<1>(md.fapplication)<<",\n \"version\": "<<std::get<2>(md.fapplication)<<"\n },\n ";
304  jsonfile<<"\"data_tier\": \""<<md.fdata_tier<<"\",\n ";
305  jsonfile<<"\"event_count\": "<<md.fnew_event_count<<",\n ";
306  //jsonfile<<"\"fcl.name\": \""<<md.ffcl_name<<"\",\n ";
307  //jsonfile<<"\"fcl.version\": \""<<md.ffcl_version<<"\",\n ";
308  jsonfile<<"\"file_format\": \""<<md.ffile_format<<"\",\n ";
309  jsonfile<<"\"file_type\": "<<md.ffile_type<<",\n ";
310  jsonfile<<"\"first_event\": "<<md.ffirst_event<<",\n ";
311  jsonfile<<"\"group\": "<<md.fgroup<<",\n ";
312  jsonfile<<"\"last_event\": "<<md.flast_event<<",\n ";
313  //if (md.fdataTier != "generated"){
314  unsigned int c=0;
315  jsonfile<<"\"parents\": [\n";
316  for(auto parent : md.fParents) {
317  c++;
318  size_t n = parent.find_last_of('/');
319  size_t f1 = (n == std::string::npos ? 0 : n+1);
320  jsonfile<<" {\n \"file_name\": \""<<parent.substr(f1)<<"\"\n }";
321  if (md.fParents.size()==1 || c==md.fParents.size()) jsonfile<<"\n";
322  else jsonfile<<",\n";
323  }
324  jsonfile<<" ],\n ";
325  //}
326  c=0;
327  jsonfile<<"\"runs\": [\n";
328  for(auto &t : md.fruns){
329  c++;
330  jsonfile<<" [\n "<<std::get<0>(t)<<",\n "<<std::get<1>(t)<<",\n "<<std::get<2>(t)<<"\n ]";
331  if (md.fruns.size()==1 || c==md.fruns.size()) jsonfile<<"\n";
332  else jsonfile<<",\n";
333  }
334  jsonfile<<" ],\n";
335 
336  if (md.fMCGenerators!="") jsonfile << "\"lbne_MC.generators\": \"" << md.fMCGenerators << "\",\n";
337  if (md.fMCOscillationP!="") jsonfile << "\"lbne_MC.oscillationP\": \"" << md.fMCOscillationP << "\",\n";
338  if (md.fMCTriggerListVersion!="") jsonfile << "\"lbne_MC.trigger-list-version\": \"" << md.fMCTriggerListVersion << "\",\n";
339  if (md.fMCBeamEnergy!="") jsonfile << "\"lbne_MC.beam_energy\": \"" << md.fMCBeamEnergy << "\",\n";
340  if (md.fMCBeamFluxID!="") jsonfile << "\"lbne_MC.beam_flux_ID\": \"" << md.fMCBeamFluxID << "\",\n";
341  if (md.fMCName!="") jsonfile << "\"lbne_MC.name\": \"" << md.fMCName << "\",\n";
342  if (md.fMCDetectorType!="") jsonfile << "\"lbne_MC.detector_type\": \"" << md.fMCDetectorType << "\",\n";
343  if (md.fMCNeutrinoFlavors!="") jsonfile << "\"lbne_MC.neutrino_flavors\": \"" << md.fMCNeutrinoFlavors << "\",\n";
344  if (md.fMCMassHierarchy!="") jsonfile << "\"lbne_MC.mass_hierarchy\": \"" << md.fMCMassHierarchy << "\",\n";
345  if (md.fMCMiscellaneous!="") jsonfile << "\"lbne_MC.miscellaneous\": \"" << md.fMCMiscellaneous << "\",\n";
346  if (md.fMCGeometryVersion!="") jsonfile << "\"lbne_MC.geometry_version\": \"" << md.fMCGeometryVersion << "\",\n";
347  if (md.fMCOverlay!="") jsonfile << "\"lbne_MC.overlay\": \"" << md.fMCOverlay << "\",\n";
348  if (md.fDataRunMode!="") jsonfile << "\"lbne_data.run_mode\": \"" << md.fDataRunMode << "\",\n";
349  if (md.fDataDetectorType!="") jsonfile << "\"lbne_data.detector_type\": \"" << md.fDataDetectorType << "\",\n";
350  if (md.fDataName!="") jsonfile << "\"lbne_data.name\": \"" << md.fDataName << "\",\n";
351  // fStageName appears not to be in our metadata spec
352 
353  // put these at the end because we know they'll be there and the last one needs to not have a comma
354 
355  jsonfile<<"\"start_time\": \""<<startbuf<<"\",\n";
356  jsonfile<<"\"end_time\": \""<<endbuf<<"\"\n";
357 
358  //jsonfile<<" \"ub_project.name\": \""<<md.fproject_name<<"\",\n ";
359  //jsonfile<<"\"ub_project.stage\": \""<<md.fproject_stage;
360  //jsonfile<<"\",\n \"ub_project.version\": \""<<md.fproject_version<<"\"\n";
361 
362  jsonfile<<"}\n";
363  jsonfile.close();
364 }
const std::string & MCOverlay() const
const std::string & MCGenerators() const
const std::string & DataName() const
const std::string & MCGeometryVersion() const
tm
Definition: demo.py:21
std::tuple< std::string, std::string, std::string > fapplication
std::vector< std::tuple< art::RunNumber_t, art::SubRunNumber_t, std::string > > fruns
const std::string & MCNeutrinoFlavors() const
const std::string & DataRunMode() const
std::void_t< T > n
const std::string & MCMiscellaneous() const
const std::string & DataDetectorType() const
const std::string & MCTriggerListVersion() const
const std::string & MCBeamFluxID() const
const std::string & MCName() const
const std::string & StageName() const
std::set< std::string > fParents
const std::string & MCOscillationP() const
const std::string & MCDetectorType() const
const std::string & MCBeamEnergy() const
def parent(G, child, parent_type)
Definition: graph.py:67
const std::string & MCMassHierarchy() const
void util::TFileMetadataDUNE::postEvent ( art::Event const &  ev,
art::ScheduleContext   
)
private

Definition at line 191 of file TFileMetadataDUNE_service.cc.

192 {
193 
194  if(!fGenerateTFileMetadata) return;
195 
197  art::SubRunNumber_t subrun = evt.subRun();
198  art::EventNumber_t event = evt.event();
199  art::SubRunID srid = evt.id().subRunID();
200 
201  // save run, subrun and runType information once every subrun
202  if (fSubRunNumbers.count(srid) == 0){
203  fSubRunNumbers.insert(srid);
204  md.fruns.push_back(make_tuple(run, subrun, frunType));
205  }
206 
207  // save the first event
208  if (md.fevent_count == 0) md.ffirst_event = event;
209  md.flast_event = event;
210  // event counter
211  ++md.fevent_count;
212 
214  if (evt.getByLabel("TriggerResults", h) and h->accept()) {
215  // Event passed at least one of the paths
217  }
218 
219 }
unsigned int event
Definition: DataStructs.h:636
unsigned int run
Definition: DataStructs.h:637
std::set< art::SubRunID > fSubRunNumbers
std::vector< std::tuple< art::RunNumber_t, art::SubRunNumber_t, std::string > > fruns
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:119
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
unsigned int subRun
Definition: DataStructs.h:638
TCEvent evt
Definition: DataStructs.cxx:7
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120
void util::TFileMetadataDUNE::postOpenFile ( std::string const &  fn)
private

Definition at line 180 of file TFileMetadataDUNE_service.cc.

181 {
182  if (!fGenerateTFileMetadata) return;
183 
184  // save parent input files here
185  md.fParents.insert(fn);
186 
187 }
QAsciiDict< Entry > fn
std::set< std::string > fParents
void util::TFileMetadataDUNE::reconfigure ( fhicl::ParameterSet const &  p)

Definition at line 97 of file TFileMetadataDUNE_service.cc.

98 {
99  // Get parameters.
100  fGenerateTFileMetadata = pset.get<bool>("GenerateTFileMetadata", false);
101  fJSONFileName = pset.get<std::string>("JSONFileName");
102 
103  if (!fGenerateTFileMetadata) return;
104 
105  md.fdata_tier = pset.get<std::string>("dataTier","root-tuple");
106  md.ffile_format = pset.get<std::string>("fileFormat","root");
107 }
std::string string
Definition: nybbler.cc:12

Member Data Documentation

bool util::TFileMetadataDUNE::fGenerateTFileMetadata
private

Definition at line 92 of file TFileMetadataDUNE.h.

std::string util::TFileMetadataDUNE::fJSONFileName
private

Definition at line 94 of file TFileMetadataDUNE.h.

std::string util::TFileMetadataDUNE::frunType
private

Definition at line 93 of file TFileMetadataDUNE.h.

std::set<art::SubRunID> util::TFileMetadataDUNE::fSubRunNumbers

Definition at line 74 of file TFileMetadataDUNE.h.

metadata util::TFileMetadataDUNE::md

Definition at line 73 of file TFileMetadataDUNE.h.

std::map<std::string,std::string> util::TFileMetadataDUNE::mdmap

Definition at line 75 of file TFileMetadataDUNE.h.


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