All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FileCatalogMetadataICARUS_service.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Name: FileCatalogMetadataICARUS_service.cc.
3 //
4 // Purpose: Implementation for FileCatalogMetadataICARUS.
5 //
6 // Created: 30-Dec-2019, M. Wospakrik
7 // based on the MicroBooNE version by H. Greenlee
8 //
9 ////////////////////////////////////////////////////////////////////////
10 
12 #include "art/Framework/Services/Registry/ServiceHandle.h"
13 #include "art/Framework/Services/Registry/ServiceDefinitionMacros.h"
14 #include "art/Framework/Services/System/FileCatalogMetadata.h"
15 
16 //--------------------------------------------------------------------
17 // Constructor.
18 
20 FileCatalogMetadataICARUS(fhicl::ParameterSet const& pset, art::ActivityRegistry& reg)
21 {
22  // Get parameters.
23  std::cout << "FileCatalogMetadataICARUS::parameterset begin" << std::endl;
24  fFCLName = pset.get<std::string>("FCLName");
25  fProjectName = pset.get<std::string>("ProjectName");
26  fProjectStage = pset.get<std::string>("ProjectStage");
27  fProjectVersion = pset.get<std::string>("ProjectVersion");
28  fProjectSoftware = pset.get<std::string>("ProjectSoftware","");
29  fProductionName = pset.get<std::string>("ProductionName",""); //Leave as default value if not running a production
30  fProductionType = pset.get<std::string>("ProductionType",""); //Leave as default value if not running a production
31 
32  fMerge = pset.get<int>("Merge", 0);
33  fParameters = pset.get<std::vector<std::string> >("Parameters", std::vector<std::string>());
34  // It doesn't make sense for parameter vector to have an odd number of elements.
35  if(fParameters.size() % 2 != 0) {
36  throw cet::exception("FileCatalogMetadataICARUS")
37  << "Parameter vector has odd number of elements.\n";
38  }
39 
40 
41  // Register for callbacks.
42 
43  reg.sPostBeginJob.watch(this, &FileCatalogMetadataICARUS::postBeginJob);
44  std::cout << "FileCatalogMetadataICARUS::parameterset ends" << std::endl;
45 
46 }
47 
48 //--------------------------------------------------------------------
49 // PostBeginJob callback.
50 // Insert per-job metadata via FileCatalogMetadata service.
52 {
53  // Get art metadata service.
54 
55  std::cout << "FileCatalogMetadataICARUS::postBeginJob() begin" << std::endl;
56  art::ServiceHandle<art::FileCatalogMetadata> mds;
57 
58  // Add metadata.
59  mds->addMetadata("fcl.name", fFCLName);
60  mds->addMetadata("icarus_project.name", fProjectName);
61  mds->addMetadata("icarus_project.stage", fProjectStage);
62  mds->addMetadata("icarus_project.version", fProjectVersion);
63  mds->addMetadata("icarus_project.software", fProjectSoftware);
64  mds->addMetadata("production.name", fProductionName);
65  mds->addMetadata("production.type", fProductionType);
66  std::ostringstream ostr;
67  ostr << fMerge;
68  mds->addMetadata("merge.merge", ostr.str());
69  mds->addMetadata("merge.merged", "0");
70  for(unsigned int i=0; i<fParameters.size(); i += 2)
71  mds->addMetadata(fParameters[i], fParameters[i+1]);
72  std::cout << "FileCatalogMetadataICARUS::postBeginJob() end" << std::endl;
73 }
74 
75 DEFINE_ART_SERVICE(icarusutil::FileCatalogMetadataICARUS)
FileCatalogMetadataICARUS(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
BEGIN_PROLOG could also be cout