All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
icarusutil::TFileMetadataICARUS Class Reference

#include <TFileMetadataICARUS.h>

Classes

struct  metadata
 

Public Member Functions

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

Public Attributes

metadata md
 
std::set< art::SubRunID > fSubRunNumbers
 
std::map< std::string,
std::string > 
mdmap
 

Private Member Functions

void postBeginJob ()
 
void postOpenInputFile (std::string const &fn)
 
void postEvent (art::Event const &ev, art::ScheduleContext)
 
void postBeginSubRun (art::SubRun const &subrun)
 
void postCloseInputFile ()
 

Private Attributes

bool fGenerateTFileMetadata
 
std::string fJSONFileName
 
std::string frunType
 
art::FileStatsCollector fFileStats
 

Detailed Description

Definition at line 34 of file TFileMetadataICARUS.h.

Constructor & Destructor Documentation

icarusutil::TFileMetadataICARUS::TFileMetadataICARUS ( fhicl::ParameterSet const &  pset,
art::ActivityRegistry &  reg 
)

Definition at line 78 of file TFileMetadataICARUS_service.cc.

79  :
80  fGenerateTFileMetadata{pset.get<bool>("GenerateTFileMetadata")},
81  fJSONFileName{pset.get<std::string>("JSONFileName")},
82  fFileStats{"", art::ServiceHandle<art::TriggerNamesService const>{}->getProcessName()}
art::FileStatsCollector fFileStats

Member Function Documentation

void icarusutil::TFileMetadataICARUS::postBeginJob ( )
private

Definition at line 99 of file TFileMetadataICARUS_service.cc.

100 {
101  std::cout << "TFileMetadataICARUS postBeginJob() begin" << std::endl;
102  // get the start time
103  md.fstart_time = time(0);
104 
105  // Get art metadata service and extract paramters from there
106  art::ServiceHandle<art::FileCatalogMetadata> artmds;
107 
108  art::FileCatalogMetadata::collection_type artmd;
109  artmds->getMetadata(artmd);
110 
111  for(auto const & d : artmd)
112  mdmap[d.first] = d.second;
113 
114  std::map<std::string,std::string>::iterator it;
115 
116  // if a certain paramter/key is not found, assign an empty string value to it
117 
118  if ((it=mdmap.find("applicationFamily"))!=mdmap.end()) std::get<0>(md.fapplication) = it->second;
119  else std::get<0>(md.fapplication) = "\" \"";
120 
121  if ((it=mdmap.find("process_name"))!=mdmap.end()) std::get<1>(md.fapplication) = it->second;
122  else std::get<1>(md.fapplication) = "\" \"";
123 
124  if ((it=mdmap.find("applicationVersion"))!=mdmap.end()) std::get<2>(md.fapplication) = it->second;
125  else std::get<2>(md.fapplication) = "\" \"";
126 
127  if ((it=mdmap.find("group"))!=mdmap.end()) md.fgroup = it->second;
128  else md.fgroup = "\" \"";
129 
130  if ((it=mdmap.find("file_type"))!=mdmap.end()) md.ffile_type = it->second;
131  else md.ffile_type = "\" \"";
132 
133  if ((it=mdmap.find("runType"))!=mdmap.end()) frunType = it->second;
134  else frunType = "\" \"";
135  std::cout << "TFileMetadataICARUS postBeginJob() end" << std::endl;
136 }
then if[["$THISISATEST"==1]]
Definition: neoSmazza.sh:95
std::tuple< std::string, std::string, std::string > fapplication
std::map< std::string, std::string > mdmap
BEGIN_PROLOG could also be cout
void icarusutil::TFileMetadataICARUS::postBeginSubRun ( art::SubRun const &  subrun)
private

Definition at line 178 of file TFileMetadataICARUS_service.cc.

179 {
180  std::cout << "TFileMetadataICARUS postBeginSubRun() begin" << std::endl;
181  art::RunNumber_t run = sr.run();
182  art::SubRunNumber_t subrun = sr.subRun();
183  art::SubRunID srid = sr.id();
184 
185  // save run, subrun and runType information once every subrun
186  if (fSubRunNumbers.count(srid) == 0){
187  fSubRunNumbers.insert(srid);
188  md.fruns.push_back(make_tuple(run, subrun, frunType));
189  }
190  std::cout << "TFileMetadataICARUS postBeginSubRun() end" << std::endl;
191 }
std::set< art::SubRunID > fSubRunNumbers
std::vector< std::tuple< art::RunNumber_t, art::SubRunNumber_t, std::string > > fruns
BEGIN_PROLOG could also be cout
void icarusutil::TFileMetadataICARUS::postCloseInputFile ( )
private

Definition at line 195 of file TFileMetadataICARUS_service.cc.

196 {
197  std::cout << "TFileMetadataICARUS postCloseInputFile() begin" << std::endl;
198  // get metadata from the FileCatalogMetadataICARUS service, which is filled on its construction
199 
200  art::ServiceHandle<icarusutil::FileCatalogMetadataICARUS> paramhandle;
201  md.fFCLName = paramhandle->GetFCLName();
202  md.fProjectName = paramhandle->GetProjectName();
203  md.fProjectStage = paramhandle->GetProjectStage();
204  md.fProjectVersion = paramhandle->GetProjectVersion();
205  md.fProjectSoftware = paramhandle->GetProjectSoftware();
206  md.fProductionName = paramhandle->GetProductionName();
207  md.fProductionType = paramhandle->GetProductionType();
208 
209  //update end time
210  md.fend_time = time(0);
211 
212  // convert start and end times into time format: Year-Month-DayTHours:Minutes:Seconds
213  char endbuf[80], startbuf[80];
214  struct tm tstruct;
215  tstruct = *localtime(&md.fend_time);
216  strftime(endbuf,sizeof(endbuf),"%Y-%m-%dT%H:%M:%S",&tstruct);
217  tstruct = *localtime(&md.fstart_time);
218  strftime(startbuf,sizeof(startbuf),"%Y-%m-%dT%H:%M:%S",&tstruct);
219 
220  // open a json file and write everything from the struct md complying to the
221  // samweb json format. This json file holds the below information temporarily.
222  // If you submitted a grid job invoking this service, the information from
223  // this file is appended to a final json file and this file will be removed
224 
225  std::ofstream jsonfile;
226  jsonfile.open(fJSONFileName);
227  jsonfile<<"{\n \"application\": {\n \"family\": "<<std::get<0>(md.fapplication)<<",\n \"name\": ";
228  jsonfile<<std::get<1>(md.fapplication)<<",\n \"version\": "<<std::get<2>(md.fapplication)<<"\n },\n ";
229  jsonfile<<"\"data_tier\": \""<<md.fdata_tier<<"\",\n ";
230  jsonfile<<"\"event_count\": "<<md.fevent_count<<",\n ";
231  jsonfile<<"\"file_format\": \""<<md.ffile_format<<"\",\n ";
232  jsonfile<<"\"file_type\": "<<md.ffile_type<<",\n ";
233  jsonfile<<"\"first_event\": "<<md.ffirst_event<<",\n ";
234  jsonfile<<"\"group\": "<<md.fgroup<<",\n ";
235  jsonfile<<"\"last_event\": "<<md.flast_event<<",\n ";
236  unsigned int c=0;
237  //08/06 DBrailsford. Only create the parent json object if there are parent names in the set.
238  if (md.fParents.size() > 0){
239  jsonfile<<"\"parents\": [\n";
240  for(auto parent : md.fParents) {
241  std::cout<<"Parent " << c << ": " << parent << std::endl;
242  c++;
243  size_t n = parent.find_last_of('/');
244  size_t f1 = (n == std::string::npos ? 0 : n+1);
245  jsonfile<<" {\n \"file_name\": \""<<parent.substr(f1)<<"\"\n }";
246  if (md.fParents.size()==1 || c==md.fParents.size()) jsonfile<<"\n";
247  else jsonfile<<",\n";
248  }
249  jsonfile<<" ],\n ";
250  c=0;
251  }
252  jsonfile<<"\"runs\": [\n";
253  for(auto &t : md.fruns){
254  c++;
255  jsonfile<<" [\n "<<std::get<0>(t)<<",\n "<<std::get<1>(t)<<",\n "<<std::get<2>(t)<<"\n ]";
256  if (md.fruns.size()==1 || c==md.fruns.size()) jsonfile<<"\n";
257  else jsonfile<<",\n";
258  }
259  jsonfile<<" ],\n";
260 
261  if (md.fFCLName!="") jsonfile << "\"fcl.name\": \"" << md.fFCLName << "\",\n";
262  if (md.fProjectName!="") jsonfile << "\"icarus_project.name\": \"" << md.fProjectName << "\",\n";
263  if (md.fProjectStage!="") jsonfile << "\"icarus_project.stage\": \"" << md.fProjectStage << "\",\n";
264  if (md.fProjectVersion!="") jsonfile << "\"icarus_project.version\": \"" << md.fProjectVersion << "\",\n";
265  if (md.fProjectSoftware!="") jsonfile << "\"icarus_project.software\": \"" << md.fProjectSoftware << "\",\n";
266  if (md.fProductionName!="") jsonfile << "\"production.name\": \"" << md.fProductionName << "\",\n";
267  if (md.fProductionType!="") jsonfile << "\"production.type\": \"" << md.fProductionType << "\",\n";
268 
269  // put these at the end because we know they'll be there and the last one needs to not have a comma
270  jsonfile<<"\"start_time\": \""<<startbuf<<"\",\n";
271  jsonfile<<"\"end_time\": \""<<endbuf<<"\"\n";
272 
273 
274  jsonfile<<"}\n";
275  jsonfile.close();
276 
277  fFileStats.recordFileClose();
278  //TODO figure out how to make the name identical to the TFile
279  //std::string new_name = fRenamer.maybeRenameFile("myjson.json",fJSONFileName);
280  std::cout << "TFileMetadataICARUS postCloseInputFile() end" << std::endl;
281 }
std::tuple< std::string, std::string, std::string > fapplication
std::vector< std::tuple< art::RunNumber_t, art::SubRunNumber_t, std::string > > fruns
art::FileStatsCollector fFileStats
BEGIN_PROLOG could also be cout
void icarusutil::TFileMetadataICARUS::postEvent ( art::Event const &  ev,
art::ScheduleContext   
)
private

Definition at line 153 of file TFileMetadataICARUS_service.cc.

154 {
155  std::cout << "TFileMetadataICARUS postEvent() begin" << std::endl;
156  art::RunNumber_t run = evt.run();
157  art::SubRunNumber_t subrun = evt.subRun();
158  art::EventNumber_t event = evt.event();
159  art::SubRunID srid = evt.id().subRunID();
160 
161  // save run, subrun and runType information once every subrun
162  if (fSubRunNumbers.count(srid) == 0){
163  fSubRunNumbers.insert(srid);
164  md.fruns.push_back(make_tuple(run, subrun, frunType));
165  }
166 
167  // save the first event
168  if (md.fevent_count == 0) md.ffirst_event = event;
169  md.flast_event = event;
170  // event counter
171  ++md.fevent_count;
172 
173  std::cout << "TFileMetadataICARUS postEvent() end" << std::endl;
174 }
std::set< art::SubRunID > fSubRunNumbers
unsigned int event
Definition: DataStructs.h:634
unsigned int run
Definition: DataStructs.h:635
std::vector< std::tuple< art::RunNumber_t, art::SubRunNumber_t, std::string > > fruns
unsigned int subRun
Definition: DataStructs.h:636
TCEvent evt
Definition: DataStructs.cxx:8
BEGIN_PROLOG could also be cout
void icarusutil::TFileMetadataICARUS::postOpenInputFile ( std::string const &  fn)
private

Definition at line 141 of file TFileMetadataICARUS_service.cc.

142 {
143  std::cout << "TFileMetadataICARUS postOpenInputFile() begin" << std::endl;
144  // save parent input files here
145  // 08/06 DBrailsford: Only save the parent string if the string is filled. The string still exists (with 0 characters) for generation stage files. See redmine issue 20124
146  if (fn.length() > 0) md.fParents.insert(fn);
147  fFileStats.recordInputFile(fn);
148  std::cout << "TFileMetadataICARUS postOpenInputFile() end" << std::endl;
149 }
art::FileStatsCollector fFileStats
BEGIN_PROLOG could also be cout

Member Data Documentation

art::FileStatsCollector icarusutil::TFileMetadataICARUS::fFileStats
private

Definition at line 80 of file TFileMetadataICARUS.h.

bool icarusutil::TFileMetadataICARUS::fGenerateTFileMetadata
private

Definition at line 77 of file TFileMetadataICARUS.h.

std::string icarusutil::TFileMetadataICARUS::fJSONFileName
private

Definition at line 78 of file TFileMetadataICARUS.h.

std::string icarusutil::TFileMetadataICARUS::frunType
private

Definition at line 79 of file TFileMetadataICARUS.h.

std::set<art::SubRunID> icarusutil::TFileMetadataICARUS::fSubRunNumbers

Definition at line 64 of file TFileMetadataICARUS.h.

metadata icarusutil::TFileMetadataICARUS::md

Definition at line 63 of file TFileMetadataICARUS.h.

std::map<std::string,std::string> icarusutil::TFileMetadataICARUS::mdmap

Definition at line 65 of file TFileMetadataICARUS.h.


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