65 #include "art/Framework/Principal/Event.h"
66 #include "art/Framework/Principal/SubRun.h"
67 #include "art/Framework/Services/Registry/ServiceHandle.h"
68 #include "art/Framework/Services/Registry/ServiceDefinitionMacros.h"
69 #include "art/Framework/Services/System/FileCatalogMetadata.h"
70 #include "art/Framework/Services/System/TriggerNamesService.h"
71 #include "art/Utilities/OutputFileInfo.h"
72 #include "cetlib_except/exception.h"
73 #include "messagefacility/MessageLogger/MessageLogger.h"
77 #include "TTimeStamp.h"
85 art::ActivityRegistry& reg):
86 fFileStats{
"", art::ServiceHandle<art::TriggerNamesService const>{}->getProcessName()}
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);});
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");
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";
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";
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");
120 fPOTModuleLabel = pset.get<std::string>(
"POTModuleLabel",
"generator");
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);
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();
145 if(s.size() < 2 || s[0] !=
'\"' || s[s.size()-1] !=
'\"')
return s;
147 s.erase(s.size()-1, 1);
152 const std::string& key,
155 const auto it = in.find(key);
165 const std::string& key,
166 std::map<std::string, std::string>& out)
177 md.fstart_time = time(0);
180 art::ServiceHandle<art::FileCatalogMetadata> artmds;
182 art::FileCatalogMetadata::collection_type artmd;
183 artmds->getMetadata(artmd);
185 std::map<std::string, std::string> mdmap;
186 for(
const auto& d: artmd)
205 if (fn.length() > 0)
md.fParents.insert(fn);
206 fFileStats.recordInputFile(fn);
213 art::RunNumber_t run = evt.run();
214 art::SubRunNumber_t subrun = evt.subRun();
215 art::EventNumber_t
event = evt.event();
216 art::SubRunID srid = evt.id().subRunID();
219 if (fSubRunNumbers.count(srid) == 0){
220 fSubRunNumbers.insert(srid);
221 md.fruns.push_back(make_tuple(run, subrun, frunType));
225 if (
md.fevent_count == 0)
md.ffirst_event = event;
226 md.flast_event = event;
236 art::RunNumber_t run = sr.run();
237 art::SubRunNumber_t subrun = sr.subRun();
238 art::SubRunID srid = sr.id();
241 if (fSubRunNumbers.count(srid) == 0){
242 fSubRunNumbers.insert(srid);
243 md.fruns.push_back(make_tuple(run, subrun, frunType));
251 art::Handle< sumdata::POTSummary > potListHandle;
253 if(sr.getByLabel(fPOTModuleLabel,potListHandle)){
254 fTotPOT+=potListHandle->totpot;
257 md.fTotPOT += fTotPOT;
265 if(s.size() >= 2 && ((s[0] ==
'{' && s.back() ==
'}') || (s[0] ==
'[' && s.back() ==
']')))
return s;
274 if(
md.fParents.empty())
return "";
278 std::string ret =
"[\n";
279 for(
auto parent:
md.fParents) {
280 std::cout<<
"Parent " << c <<
": " << parent << std::endl;
282 size_t n = parent.find_last_of(
'/');
283 size_t f1 = (n == std::string::npos ? 0 : n+1);
284 ret +=
" {\n \"file_name\": \"" + parent.substr(f1) +
"\"\n }";
285 if(
md.fParents.size() == 1 || c ==
md.fParents.size()) ret +=
"\n";
298 std::string ret =
"[\n";
299 for(
auto&t :
md.fruns){
302 if(
md.fruns.size() == 1 || c ==
md.fruns.size()) ret +=
"\n";
311 std::map<std::string, int>& ints,
312 std::map<std::string, double>& doubles,
313 std::map<std::string, std::string>& objs)
315 strs.clear(); ints.clear(); doubles.clear(); objs.clear();
317 objs[
"application"] =
"{\"family\": \""+std::get<0>(
md.fapplication)+
"\", \"name\": \""+std::get<1>(
md.fapplication)+
"\", \"version\": \""+std::get<2>(
md.fapplication)+
"\"}";
319 if(!
md.fParents.empty()) objs[
"parents"] = GetParentsString();
320 if(!
md.fruns.empty()) objs[
"runs"] = GetRunsString();
323 char endbuf[80], startbuf[80];
325 tstruct = *localtime(&
md.fend_time);
326 strftime(endbuf,
sizeof(endbuf),
"%Y-%m-%dT%H:%M:%S",&tstruct);
327 tstruct = *localtime(&
md.fstart_time);
328 strftime(startbuf,
sizeof(startbuf),
"%Y-%m-%dT%H:%M:%S",&tstruct);
330 strs[
"start_time"] = startbuf;
331 strs[
"end_time"] = endbuf;
333 strs[
"data_tier"] =
md.fdata_tier;
334 ints[
"event_count"] =
md.fevent_count;
335 strs[
"file_format"] =
md.ffile_format;
336 ints[
"first_event"] =
md.ffirst_event;
337 ints[
"last_event"] =
md.flast_event;
339 const std::string proj = fExperiment+
"_project";
352 ints[
"merge.merge"] = (
md.merge==0 ? 0 : 1);
353 ints[
"merge.merged"] = 0;
355 doubles[
"mc.pot"] =
md.fTotPOT;
363 md.fend_time = time(0);
367 for(
unsigned int i=0; i<fJSONFileName.size(); ++i) {
371 md.fdata_tier = fDataTier[i];
372 md.ffile_format = fFileFormat[i];
373 if(fMerge.size() > i)
374 md.merge = fMerge[i];
379 std::map<std::string, std::string> strs;
380 std::map<std::string, int> ints;
381 std::map<std::string, double> doubles;
382 std::map<std::string, std::string> objs;
383 GetMetadataMaps(strs, ints, doubles, objs);
390 if(!fJSONFileName[i].
empty()){
391 std::ofstream jsonfile;
392 jsonfile.open(fJSONFileName[i]);
397 if(!once) jsonfile <<
",\n";
399 jsonfile <<
" \"" << it.first <<
"\": " << it.second;
403 jsonfile <<
",\n \"" << it.first <<
"\": \"" << it.second <<
"\"";
406 jsonfile <<
",\n \"" << it.first <<
"\": " << it.second;
408 for(
auto& it: doubles){
409 jsonfile <<
",\n \"" << it.first <<
"\": " << it.second;
417 fFileStats.recordFileClose();
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
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 to_string(WindowPattern const &pattern)
then echo File list $list not found else cat $list while read file do echo $file sed s
bool empty(FixedBins< T, C > const &) noexcept
BEGIN_PROLOG could also be cout