All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
MetadataSBN_service.cc File Reference
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include "sbncode/Metadata/MetadataSBN.h"
#include "sbncode/Metadata/FileCatalogMetadataSBN.h"
#include "larcoreobj/SummaryData/POTSummary.h"
#include "art/Framework/Principal/Event.h"
#include "art/Framework/Principal/SubRun.h"
#include "art/Framework/Services/Registry/ServiceHandle.h"
#include "art/Framework/Services/Registry/ServiceDefinitionMacros.h"
#include "art/Framework/Services/System/FileCatalogMetadata.h"
#include "art/Framework/Services/System/TriggerNamesService.h"
#include "art/Utilities/OutputFileInfo.h"
#include "cetlib_except/exception.h"
#include "messagefacility/MessageLogger/MessageLogger.h"
#include "TROOT.h"
#include "TFile.h"
#include "TTimeStamp.h"

Go to the source code of this file.

Functions

 getProcessName ()}
 
std::string UnQuoteString (std::string s)
 Un-quote quoted strings. More...
 
void MaybeCopyFromMap (const std::map< std::string, std::string > &in, const std::string &key, std::string &out)
 
void MaybeCopyToMap (const std::string &in, const std::string &key, std::map< std::string, std::string > &out)
 
std::string Escape (const std::string &s)
 

Function Documentation

std::string Escape ( const std::string &  s)

Definition at line 262 of file MetadataSBN_service.cc.

263 {
264  // If it's formatted as a dict or list, trust it's already formatted
265  if(s.size() >= 2 && ((s[0] == '{' && s.back() == '}') || (s[0] == '[' && s.back() == ']'))) return s;
266 
267  // otherwise quote it
268  return "\""+s+"\"";
269 }
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
getProcessName ( )

Definition at line 86 of file MetadataSBN_service.cc.

86  {"", art::ServiceHandle<art::TriggerNamesService const>{}->getProcessName()}
87 {
88  // Insist on configuring Experiment from the fcl file (ideally) or the
89  // environment.
90  const char* expt = getenv("EXPERIMENT");
91  if(expt) fExperiment = pset.get<std::string>("Experiment", expt); else fExperiment = pset.get<std::string>("Experiment");
92  std::transform(fExperiment.begin(), fExperiment.end(), fExperiment.begin(), [](unsigned char c){return std::tolower(c);});
93 
94  // Get scalar/vector parameters.
95  if(pset.is_key_to_atom("JSONFileName"))
96  fJSONFileName.push_back(pset.get<std::string>("JSONFileName"));
97  else if(pset.is_key_to_sequence("JSONFileName"))
98  fJSONFileName = pset.get<std::vector<std::string> >("JSONFileName");
99 
100  if(pset.is_key_to_atom("dataTier"))
101  fDataTier.push_back(pset.get<std::string>("dataTier"));
102  else if(pset.is_key_to_sequence("dataTier"))
103  fDataTier = pset.get<std::vector<std::string> >("dataTier");
104  if(fDataTier.size() != fJSONFileName.size())
105  throw cet::exception("MetadataSBN") << "FCL sequence size mismatch.\n";
106 
107  if(pset.is_key_to_atom("fileFormat"))
108  fFileFormat.push_back(pset.get<std::string>("fileFormat"));
109  else if(pset.is_key_to_sequence("fileFormat"))
110  fFileFormat = pset.get<std::vector<std::string> >("fileFormat");
111  if(fFileFormat.size() != fJSONFileName.size())
112  throw cet::exception("MetadataSBN") << "FCL sequence size mismatch.\n";
113 
114  if(pset.has_key("Merge")) {
115  if(pset.is_key_to_atom("Merge"))
116  fMerge.push_back(pset.get<int>("Merge"));
117  else if(pset.is_key_to_sequence("Merge"))
118  fMerge = pset.get<std::vector<int> >("Merge");
119  }
120  fPOTModuleLabel = pset.get<std::string>("POTModuleLabel", "generator");
121 
122  reg.sPostBeginJob.watch(this, &MetadataSBN::postBeginJob);
123  reg.sPostOpenFile.watch(this, &MetadataSBN::postOpenInputFile);
124  reg.sPostCloseFile.watch(this, &MetadataSBN::postCloseInputFile);
125  reg.sPostProcessEvent.watch(this, &MetadataSBN::postEvent);
126  reg.sPostBeginSubRun.watch(this, &MetadataSBN::postBeginSubRun);
127  reg.sPostEndSubRun.watch(this, &MetadataSBN::postEndSubRun);
128 
129  // get metadata from the FileCatalogMetadataSBN service, which is filled on its construction
130  art::ServiceHandle<util::FileCatalogMetadataSBN> paramhandle;
131  md.fFCLName = paramhandle->GetFCLName();
132  md.fProjectName = paramhandle->GetProjectName();
133  md.fProjectStage = paramhandle->GetProjectStage();
134  md.fProjectVersion = paramhandle->GetProjectVersion();
135  md.fProjectSoftware = paramhandle->GetProjectSoftware();
136  md.fProductionName = paramhandle->GetProductionName();
137  md.fProductionType = paramhandle->GetProductionType();
138  md.merge = -1;
139  md.fTotPOT = 0.;
140 }
static constexpr Sample_t transform(Sample_t sample)
void MaybeCopyFromMap ( const std::map< std::string, std::string > &  in,
const std::string &  key,
std::string &  out 
)

Definition at line 151 of file MetadataSBN_service.cc.

154 {
155  const auto it = in.find(key);
156  if(it == in.end()){
157  out = "";
158  }
159  else{
160  out = UnQuoteString(it->second);
161  }
162 }
std::string UnQuoteString(std::string s)
Un-quote quoted strings.
void MaybeCopyToMap ( const std::string &  in,
const std::string &  key,
std::map< std::string, std::string > &  out 
)

Definition at line 164 of file MetadataSBN_service.cc.

167 {
168  if(!in.empty()) out[key] = UnQuoteString(in);
169 }
if &&[-z"$BASH_VERSION"] then echo Attempting to switch to bash bash shellSwitch exit fi &&["$1"= 'shellSwitch'] shift declare a IncludeDirectives for Dir in
std::string UnQuoteString(std::string s)
Un-quote quoted strings.
std::string UnQuoteString ( std::string  s)

Un-quote quoted strings.

Definition at line 143 of file MetadataSBN_service.cc.

144 {
145  if(s.size() < 2 || s[0] != '\"' || s[s.size()-1] != '\"') return s;
146  s.erase(0, 1);
147  s.erase(s.size()-1, 1);
148  return s;
149 }
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60