Skip to content
Snippets Groups Projects
Commit 3d645889 authored by Riccardo Maria Bianchi's avatar Riccardo Maria Bianchi :sunny: Committed by Graeme Stewart
Browse files

added new user settings. Details:...

added new user settings. Details: https://its.cern.ch/jira/browse/ATLASVPONE-220 (VP1AlgsEventProd-00-00-07)

	* Avoid retrieve of EventInfo in VP1EventProd::handle(), use incident
	information instead.

2014-11-06  Vakho Tsulaia  <tsulaia@cern.ch>

	* Cleaning up the way this code manages VP1FileUtilities objects


Former-commit-id: 34f4a5cc
parent c3173738
No related branches found
No related tags found
No related merge requests found
################################################################################
# Package: VP1AlgsEventProd
################################################################################
# Declare the package name:
atlas_subdir( VP1AlgsEventProd )
# Declare the package's dependencies:
atlas_depends_on_subdirs( PUBLIC
Control/AthenaBaseComps
Database/AthenaPOOL/PoolSvc
GaudiKernel
PRIVATE
Database/APR/CollectionBase
Database/APR/CollectionUtilities
Database/APR/POOLCore
Database/APR/PersistencySvc
Database/APR/StorageSvc
Event/EventInfo
Tools/PathResolver
graphics/VP1/VP1UtilsBase )
# External dependencies:
find_package( Qt4 COMPONENTS QtCore QtOpenGL QtGui )
include_directories( /usr/X11R6/include )
# Component(s) in the package:
atlas_add_component( VP1AlgsEventProd
src/*.cxx
src/components/*.cxx
INCLUDE_DIRS ${QT4_INCLUDE_DIRS}
LINK_LIBRARIES ${QT4_LIBRARIES} GL AthenaBaseComps GaudiKernel CollectionBase CollectionUtilities POOLCore PersistencySvc StorageSvc EventInfo PathResolver VP1UtilsBase )
# Install files from the package:
atlas_install_headers( VP1AlgsEventProd )
......@@ -23,8 +23,9 @@
#include "PoolSvc/IPoolSvc.h"
#include <string>
// fwd declarations
class StoreGateSvc;
class VP1FileUtilities;
class VP1EventProd: public AthAlgorithm,
public IIncidentListener
......@@ -40,19 +41,21 @@ class VP1EventProd: public AthAlgorithm,
void handle(const Incident& inc);
private:
VP1FileUtilities* m_fileUtil;
// run/event number to be used in the vp1 event file name
int m_runNumber;
int m_eventNumber;
unsigned long m_runNumber;
unsigned long long m_eventNumber;
unsigned int m_timeStamp;
std::string m_humanTimestamp;
std::string m_outputFileType;
bool m_removeTempInputFiles;
// properties
std::string m_inputPoolFile;
std::string m_destinationDir;
bool m_createDestinationDir;
int m_maxProducedFiles;
int m_nEvent; // Internal counter for the number of processed events
// service handle
ServiceHandle<IPoolSvc> m_poolSvc;
};
......
......@@ -30,7 +30,7 @@ apply_pattern declare_python_modules files="*.py"
private
use VP1Qt VP1Qt-* graphics/VP1 -no_auto_imports # Needed for linker. The flag '-no_auto_imports' avoids CHECKREQ errors.
use VP1UtilsBase VP1UtilsBase-* graphics/VP1
use VP1UtilsBase VP1UtilsBase-* graphics/VP1 # needs to be placed AFTER VP1Qt... I don't know why, but CMT gives errors in linking if it's before!!!
use EventInfo EventInfo-* Event
use PathResolver PathResolver-* Tools
use AtlasPOOL AtlasPOOL-* External
......
......@@ -28,7 +28,6 @@
VP1EventProd::VP1EventProd(const std::string& name, ISvcLocator* svcLocator):
AthAlgorithm(name, svcLocator),
m_fileUtil(0),
m_runNumber(0),
m_eventNumber(0),
m_timeStamp(0),
......@@ -38,7 +37,13 @@ VP1EventProd::VP1EventProd(const std::string& name, ISvcLocator* svcLocator):
{
declareProperty("InputPoolFile", m_inputPoolFile="");
declareProperty("DestinationDirectory", m_destinationDir="."); // produce files in the run directory by default
declareProperty("MaxNumberOfFiles", m_maxProducedFiles=5); // keep 5 event files in the run directory
declareProperty("ForceCreateDestinationDirectory", m_createDestinationDir=true); // force creation of new output folder
declareProperty("MaxNumberOfFiles", m_maxProducedFiles=-1); // keep N event files in the run directory. Default is '-1' that means ALL.
declareProperty("OutputFileTypeLabel", m_outputFileType=""); // put a label at the end of the output file, stating its file type
declareProperty("RemoveTempInputFiles", m_removeTempInputFiles=true); // remove the temp input file, i.e. the single-event files produced by the Athena job (HITS, ESD, ...) and which are then copied to files called "vp1_...pool.root"
// Note: you cannot initialize a VP1FileUtils instance here, because otherwise it would take the default properties only.
}
VP1EventProd::~VP1EventProd()
......@@ -51,21 +56,10 @@ StatusCode VP1EventProd::initialize()
StatusCode result = StatusCode::SUCCESS;
// initialize file utility
try
{
m_fileUtil = new VP1FileUtilities(m_destinationDir, m_maxProducedFiles);
}
catch(std::runtime_error& err)
{
msg(MSG::WARNING) << "Exception caught: " << err.what() << endreq;
return result;
}
// use the incident service to register a handle
IIncidentSvc* incsvc = 0;
StatusCode status = service("IncidentSvc", incsvc, true);
if(status.isFailure() || incsvc==0)
msg(MSG::WARNING) << "Unable to get IncidentSvc!" << endreq;
else
......@@ -90,24 +84,29 @@ StatusCode VP1EventProd::finalize()
{
msg(MSG::INFO) <<"in finalize() " << endreq;
// Let m_fileUtil handle the output of the last event
// handle the output of the last event
if(m_nEvent) {
msg(MSG::INFO) << "--> Input POOL file: " << m_inputPoolFile << endreq;
std::ostringstream ostri;
ostri << m_inputPoolFile << "._" << std::setw(4) << std::setfill('0') << m_nEvent;
try {
if (m_fileUtil) delete m_fileUtil;
m_fileUtil = new VP1FileUtilities(m_destinationDir,m_maxProducedFiles);
m_fileUtil->produceNewFile(ostri.str(), m_runNumber, m_eventNumber, m_timeStamp, m_humanTimestamp);
delete m_fileUtil;
/* clean the output directory if m_maxProducedFiles == 0
* or keep up to 'm_maxProducedFiles' output files
*/
VP1FileUtilities fileUtil(".", m_maxProducedFiles, m_destinationDir, m_createDestinationDir, m_removeTempInputFiles); // inputDir, fileLimit, outputDir, forceMakeOutputDir, removeInputFile
if (m_outputFileType != "")
fileUtil.produceNewFile(ostri.str(), m_runNumber, m_eventNumber, m_timeStamp, m_humanTimestamp+"."+m_outputFileType);
else
fileUtil.produceNewFile(ostri.str(), m_runNumber, m_eventNumber, m_timeStamp, m_humanTimestamp);
}
catch(std::runtime_error& err) {
msg(MSG::WARNING) << "Exception caught: " << err.what() << endreq;
msg(MSG::WARNING) << "Unable to produce new VP1 event file" << endreq;
return StatusCode::FAILURE;
}
}
......@@ -118,80 +117,129 @@ void VP1EventProd::handle(const Incident& inc)
{
msg(MSG::INFO) << "Handling incident '" << inc.type() << "'" << endreq;
// Do something only if m_fileUtil!=0
if(m_fileUtil)
{
const EventIncident* eventInc = dynamic_cast<const EventIncident*>(&inc);
if(eventInc == 0) {
msg(MSG::WARNING) << " Unable to cast incident type" << endreq;
return;
} else {
msg(MSG::DEBUG) << " Event incident casting successful" << endreq;
}
const EventIncident* eventInc = dynamic_cast<const EventIncident*>(&inc);
if(eventInc == 0) {
msg(MSG::WARNING) << " Unable to cast incident type" << endreq;
return;
} else {
msg(MSG::DEBUG) << " Event incident casting successful" << endreq;
}
// Let m_fileUtil handle the output of the previous event
if(m_nEvent) {
msg(MSG::INFO) << "--> Input POOL file: " << m_inputPoolFile << endreq;
std::ostringstream ostri;
ostri << m_inputPoolFile << "._" << std::setw(4) << std::setfill('0') << m_nEvent;
try {
if (m_fileUtil) delete m_fileUtil;
m_fileUtil = new VP1FileUtilities(m_destinationDir,m_maxProducedFiles);
//m_fileUtil->produceNewFile(ostri.str(),m_runNumber,m_eventNumber,m_timeStamp); // with UNIX timestamp
m_fileUtil->produceNewFile(ostri.str(), m_runNumber, m_eventNumber, m_timeStamp, m_humanTimestamp); // with UNIX and human-readable timestamp
}
catch(std::runtime_error& err) {
msg(MSG::WARNING) << "Exception caught: " << err.what() << endreq;
msg(MSG::WARNING) << "Unable to produce new VP1 event file" << endreq;
return;
}
}
m_nEvent++;
// Update run_number/event_number/time_stamp
const EventInfo* _evt = 0; // pointer for the event
StatusCode status = evtStore()->retrieve(_evt); // retrieve the pointer to the event
if(status.isSuccess() && _evt!=0) {
m_eventNumber = _evt->event_ID()->event_number(); // from EventInfo/EventID.h
m_runNumber = _evt->event_ID()->run_number();
m_timeStamp = _evt->event_ID()->time_stamp();
msg(MSG::DEBUG) << " Got run number = " << m_runNumber
<< ", event number = " << m_eventNumber
<< ", UNIX timestamp = " << m_timeStamp << endreq;
time_t t_timestamp = m_timeStamp;
tm *ltm = localtime(&t_timestamp);
// print various components of tm structure.
msg(MSG::DEBUG) << "Year: "<< 1900 + ltm->tm_year
<< " - " << "Month: "<< 1 + ltm->tm_mon<< " - " // tm_mon is in the range [0, 11], so 1 must be added to get real months
<< "Day: "<< ltm->tm_mday
<< " - " "Time: "<< ltm->tm_hour << ":" << ltm->tm_min << ":" << ltm->tm_sec << "CEST"
<< endreq;
std::ostringstream ostri;
ostri << 1900 + ltm->tm_year
<< "-" << 1 + ltm->tm_mon // tm_mon is in the range [0, 11], so 1 must be added to get real months
<< "-" << ltm->tm_mday
<< "T" << ltm->tm_hour << "-" << ltm->tm_min << "-" << ltm->tm_sec << "CEST";
m_humanTimestamp = ostri.str();
msg(MSG::DEBUG) << "'human readable' timestamp: " << m_humanTimestamp << endreq;
// Let VP1FileUtilities handle the output of the previous event.
// Skip this if m_nEvent == 0,
// because the processing of the event is not done yet
// and the input file is not made at this stage.
// Basically we run the code below while in event_2, to get the processed file for event_1
if(m_nEvent) {
msg(MSG::INFO) << "--> Input POOL file: " << m_inputPoolFile << endreq;
std::ostringstream ostri;
ostri << m_inputPoolFile << "._" << std::setw(4) << std::setfill('0') << m_nEvent;
try {
/* clean the output directory if m_maxProducedFiles == 0
* or keep up to 'm_maxProducedFiles' output files
*/
VP1FileUtilities fileUtil(".", m_maxProducedFiles, m_destinationDir, m_createDestinationDir, m_removeTempInputFiles); // inputDir, fileLimit, outputDir, forceMakeOutputDir, removeInputFile
if (m_outputFileType != "")
fileUtil.produceNewFile(ostri.str(), m_runNumber, m_eventNumber, m_timeStamp, m_humanTimestamp+"."+m_outputFileType); // with UNIX and human-readable timestamp
else
fileUtil.produceNewFile(ostri.str(), m_runNumber, m_eventNumber, m_timeStamp, m_humanTimestamp); // with UNIX and human-readable timestamp
}
else {
msg(MSG::ERROR) << " Unable to retrieve EventInfo from StoreGate" << endreq;
m_eventNumber = 0;
m_runNumber = 0;
m_timeStamp = 0;
catch(std::runtime_error& err) {
msg(MSG::WARNING) << "Exception caught: " << err.what() << endreq;
msg(MSG::WARNING) << "Unable to produce new VP1 event file" << endreq;
}
}
/*
* -------------------------------------------------------------------
* === NOTE!!! ===
*
* AFTER having processed the file from previous event,
* we now update the run number and event number for the current event
* --------------------------------------------------------------------
*/
// increment event count
m_nEvent++;
// Update run_number/event_number/time_stamp
m_eventNumber = eventInc->eventInfo().event_ID()->event_number(); // from EventInfo/EventID.h
m_runNumber = eventInc->eventInfo().event_ID()->run_number();
m_timeStamp = eventInc->eventInfo().event_ID()->time_stamp();
msg(MSG::DEBUG) << " Got run number = " << m_runNumber
<< ", event number = " << m_eventNumber
<< ", UNIX timestamp = " << m_timeStamp << endreq;
time_t t_timestamp = m_timeStamp;
tm *ltm = localtime(&t_timestamp);
// print various components of tm structure.
msg(MSG::DEBUG) << "Year: "<< 1900 + ltm->tm_year
<< " - " << "Month: "<< 1 + ltm->tm_mon<< " - " // tm_mon is in the range [0, 11], so 1 must be added to get real months
<< "Day: "<< ltm->tm_mday
<< " - " "Time: "<< ltm->tm_hour << ":" << ltm->tm_min << ":" << ltm->tm_sec << "CEST"
<< endreq;
std::ostringstream ostri;
ostri << 1900 + ltm->tm_year
<< "-" << 1 + ltm->tm_mon // tm_mon is in the range [0, 11], so 1 must be added to get real months
<< "-" << ltm->tm_mday
<< "T" << ltm->tm_hour << "-" << ltm->tm_min << "-" << ltm->tm_sec << "CEST";
m_humanTimestamp = ostri.str();
msg(MSG::DEBUG) << "'human readable' timestamp: " << m_humanTimestamp << endreq;
// OLD CODE
//
// const EventInfo* _evt = 0; // pointer for the event
// StatusCode status = evtStore()->retrieve(_evt); // retrieve the pointer to the event
//
// if(status.isSuccess() && _evt!=0) {
//
// m_eventNumber = _evt->event_ID()->event_number(); // from EventInfo/EventID.h
// m_runNumber = _evt->event_ID()->run_number();
// m_timeStamp = _evt->event_ID()->time_stamp();
//
// msg(MSG::DEBUG) << " Got run number = " << m_runNumber
// << ", event number = " << m_eventNumber
// << ", UNIX timestamp = " << m_timeStamp << endreq;
//
// time_t t_timestamp = m_timeStamp;
// tm *ltm = localtime(&t_timestamp);
//
// // print various components of tm structure.
// msg(MSG::DEBUG) << "Year: "<< 1900 + ltm->tm_year
// << " - " << "Month: "<< 1 + ltm->tm_mon<< " - " // tm_mon is in the range [0, 11], so 1 must be added to get real months
// << "Day: "<< ltm->tm_mday
// << " - " "Time: "<< ltm->tm_hour << ":" << ltm->tm_min << ":" << ltm->tm_sec << "CEST"
// << endreq;
//
// std::ostringstream ostri;
// ostri << 1900 + ltm->tm_year
// << "-" << 1 + ltm->tm_mon // tm_mon is in the range [0, 11], so 1 must be added to get real months
// << "-" << ltm->tm_mday
// << "T" << ltm->tm_hour << "-" << ltm->tm_min << "-" << ltm->tm_sec << "CEST";
//
// m_humanTimestamp = ostri.str();
// msg(MSG::DEBUG) << "'human readable' timestamp: " << m_humanTimestamp << endreq;
//
// }
// else {
// msg(MSG::ERROR) << " Unable to retrieve EventInfo from StoreGate" << endreq;
// m_eventNumber = 0;
// m_runNumber = 0;
// m_timeStamp = 0;
// }
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment