Skip to content
Snippets Groups Projects

Patches for GenFSRJson to correct JSON output

Merged Alex Grecu requested to merge agrecu/genfsrjson-patch into master
@@ -74,10 +74,8 @@ private:
Gaudi::Property<std::string> m_gaussVersion{this, "gaussVersion", "", "Gauss version used in the simulation"};
Gaudi::Property<std::string> m_simCond{this, "simCond", "", "Tag for the SimCond database"};
Gaudi::Property<std::string> m_dddb{this, "dddb", "", "Tag for the DDDB database"};
Gaudi::Property<std::string> m_jsonOutputLocation{this, "jsonOutputLocation", "",
"Path where to save the .json output"};
Gaudi::Property<std::string> m_jsonOutputName{this, "jsonOutputName", "GenerationFSR_" + m_appConfigFile + ".json",
"Name of the .json output"};
Gaudi::Property<std::string> m_jsonOutputFilename{this, "jsonOutputName", "GenerationFSR.json",
"Full path of the JSON output file"};
SmartIF<IDataProviderSvc> m_fileRecordSvc;
PublicToolHandle<IFSRNavigator> m_navigatorTool{this, "FSRNavigator",
@@ -363,72 +361,88 @@ void GenFSRJson::printFSR() {
// make an inventory of the FileRecord store
std::vector<std::string> addresses = m_navigatorTool->navigate( m_fileRecordName, m_FSRName );
for ( const auto& genRecordAddress : addresses ) {
DataObject* obj = nullptr;
StatusCode sc = m_fileRecordSvc->retrieveObject( genRecordAddress, obj );
if ( !addresses.empty() ) {
// open the new file
if ( msgLevel( MSG::DEBUG ) ) debug() << "write to file: " + m_jsonOutputFilename << endmsg;
std::ofstream jsonOutput( m_jsonOutputFilename.value(), std::fstream::out );
if ( !sc.isSuccess() ) {
error() << "Unable to retrieve object '" << genRecordAddress << "'" << endmsg;
continue;
}
ptree wrap_tree;
ptree arr_tree;
std::string decFiles = "";
LHCb::GenFSR* genFSR = dynamic_cast<LHCb::GenFSR*>( obj );
if ( genFSR == nullptr ) {
warning() << "genFSR record not found!" << endmsg;
if ( msgLevel( MSG::DEBUG ) ) debug() << genRecordAddress << " not found" << endmsg;
} else {
int evtType = genFSR->getSimulationInfo( "evtType", 0 );
int njobs = genFSR->getSimulationInfo( "nJobs", 0 );
std::string genMethod = genFSR->getSimulationInfo( "generationMethod", "" );
std::string genName = genFSR->getSimulationInfo( "hardGenerator", "" );
std::string decFiles = genFSR->getSimulationInfo( "decFiles", "" );
std::string evtType_str = std::to_string( evtType );
std::string njobs_str = std::to_string( njobs );
std::string time = getCurrentTime();
// open the new file
if ( msgLevel( MSG::DEBUG ) ) debug() << "write to file: " + m_jsonOutputName << endmsg;
std::ofstream jsonOutput( m_jsonOutputLocation.value() + m_jsonOutputName.value(), std::fstream::out );
if ( jsonOutput.is_open() ) {
if ( msgLevel( MSG::DEBUG ) )
debug() << "Json output: " + m_jsonOutputLocation.value() + m_jsonOutputName.value() + " created." << endmsg;
ptree main_tree;
std::string evtDesc = getEvtTypeDesc( evtType );
main_tree.put( "APPCONFIG_file", m_appConfigFile );
main_tree.put( "APPCONFIG_version", m_appConfigVersion );
main_tree.put( "evtType", evtType_str );
main_tree.put( "evtTypeDesc", evtDesc );
main_tree.put( "DecFiles_version", decFiles );
main_tree.put( "Hard Generator", genName );
main_tree.put( "Gauss_version", m_gaussVersion );
main_tree.put( "DDDB", m_dddb );
main_tree.put( "SIMCOND", m_simCond );
main_tree.put( "genTimeStamp", time );
ptree gencounters_array = writeGeneratorCounters( *genFSR );
ptree hadroncounters_array = writeHadronCounters( *genFSR );
ptree cross_array = writeGeneratorCrossSections( *genFSR );
ptree efficiencies_array = writeCutEfficiencies( *genFSR );
ptree stats_array = writeGlobalStat( *genFSR );
main_tree.add_child( "InteractionCounters", gencounters_array );
main_tree.add_child( "HadronCounters", hadroncounters_array );
main_tree.add_child( "HardGeneratorCrossSection", cross_array );
main_tree.add_child( "SignalCounters", efficiencies_array );
main_tree.add_child( "globStat", stats_array );
main_tree.put( "prodID", m_prodID );
main_tree.put( "nb_jobs", njobs_str );
main_tree.put( "script_version", script_version );
write_json( jsonOutput, main_tree, false );
jsonOutput.close();
} else if ( msgLevel( MSG::DEBUG ) )
debug() << "The output file was not opened correctly" << endmsg;
}
for ( const auto& genRecordAddress : addresses ) {
DataObject* obj = nullptr;
StatusCode sc = m_fileRecordSvc->retrieveObject( genRecordAddress, obj );
if ( !sc.isSuccess() ) {
error() << "Unable to retrieve object '" << genRecordAddress << "'" << endmsg;
continue;
}
LHCb::GenFSR* genFSR = dynamic_cast<LHCb::GenFSR*>( obj );
if ( genFSR == nullptr ) {
warning() << "genFSR record not found!" << endmsg;
if ( msgLevel( MSG::DEBUG ) ) debug() << genRecordAddress << " not found" << endmsg;
} else {
int evtType = genFSR->getSimulationInfo( "evtType", 0 );
int njobs = genFSR->getSimulationInfo( "nJobs", 0 );
std::string genMethod = genFSR->getSimulationInfo( "generationMethod", "" );
std::string genName = genFSR->getSimulationInfo( "hardGenerator", "" );
std::string evtType_str = std::to_string( evtType );
std::string njobs_str = std::to_string( njobs );
// optimize so that DecFiles version is not derived for each instance in spillover runs
decFiles = genFSR->getSimulationInfo( "decFiles", "" );
if ( jsonOutput.is_open() ) {
if ( msgLevel( MSG::DEBUG ) )
debug() << "Json output: " + m_jsonOutputFilename.value() + " created." << endmsg;
ptree main_tree;
std::string evtDesc = getEvtTypeDesc( evtType );
main_tree.put( "evtType", evtType_str );
main_tree.put( "evtTypeDesc", evtDesc );
main_tree.put( "Hard Generator", genName );
main_tree.put( "Hard Generator Method", genMethod );
ptree gencounters_array = writeGeneratorCounters( *genFSR );
ptree hadroncounters_array = writeHadronCounters( *genFSR );
ptree cross_array = writeGeneratorCrossSections( *genFSR );
ptree efficiencies_array = writeCutEfficiencies( *genFSR );
ptree stats_array = writeGlobalStat( *genFSR );
main_tree.add_child( "InteractionCounters", gencounters_array );
main_tree.add_child( "HadronCounters", hadroncounters_array );
main_tree.add_child( "HardGeneratorCrossSection", cross_array );
main_tree.add_child( "SignalCounters", efficiencies_array );
main_tree.add_child( "globStat", stats_array );
main_tree.put( "nb_jobs", njobs_str );
// add genFSR object to array
arr_tree.push_back( std::make_pair( "", main_tree ) );
} else if ( msgLevel( MSG::DEBUG ) )
debug() << "The output file was not opened correctly" << endmsg;
} // end genFSR processing
} // end cycling on GenFSR sets
if ( jsonOutput.is_open() ) {
std::string time = getCurrentTime();
wrap_tree.put( "nb_methods", addresses.size() );
wrap_tree.put( "genTimeStamp", time );
wrap_tree.put( "script_version", script_version );
wrap_tree.put( "prodID", m_prodID.value() );
wrap_tree.put( "APPCONFIG_file", m_appConfigFile.value() );
wrap_tree.put( "APPCONFIG_version", m_appConfigVersion.value() );
wrap_tree.put( "DecFiles_version", decFiles );
wrap_tree.put( "Gauss_version", m_gaussVersion.value() );
wrap_tree.put( "DDDB", m_dddb.value() );
wrap_tree.put( "SIMCOND", m_simCond.value() );
wrap_tree.add_child( "genFSRs", arr_tree );
write_json( jsonOutput, wrap_tree, false );
jsonOutput.close();
};
}
}
Loading