| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

OutputFileRollerTool Class Reference

Change output file name when a condition is met. More...

#include <OutputFileRollerTool.h>

Inheritance diagram for OutputFileRollerTool:

[legend]
Collaboration diagram for OutputFileRollerTool:
[legend]
List of all members.

Public Types

 SUCCESS
 NO_INTERFACE
 VERSMISMATCH
 LAST_ERROR
 SUCCESS
 NO_INTERFACE
 VERSMISMATCH
 LAST_ERROR
enum  Status

Public Member Functions

 OutputFileRollerTool (const std::string &type, const std::string &name, const IInterface *parent)
virtual ~OutputFileRollerTool ()
virtual StatusCode visit (DayaBay::RegistrationSequence &rs)
virtual StatusCode initialize ()
virtual StatusCode finalize ()
INTupleSvcntupleSvc () const
INTupleSvcevtColSvc () const
IDataProviderSvcdetSvc () const
IDataProviderSvcevtSvc () const
IIncidentSvcincSvc () const
IChronoStatSvcchronoSvc () const
IHistogramSvchistoSvc () const
IAlgContextSvccontextSvc () const
DataObjectput (IDataProviderSvc *svc, DataObject *object, const std::string &address, const bool useRootInTES=true) const
DataObjectput (DataObject *object, const std::string &address, const bool useRootInTES=true) const
Gaudi::Utils::GetData< TYPE
>::return_type 
get (IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Gaudi::Utils::GetData< TYPE
>::return_type 
get (const std::string &location, const bool useRootInTES=true) const
TYPE * getDet (IDataProviderSvc *svc, const std::string &location) const
TYPE * getDet (const std::string &location) const
bool exist (IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
bool exist (const std::string &location, const bool useRootInTES=true) const
bool existDet (IDataProviderSvc *svc, const std::string &location) const
bool existDet (const std::string &location) const
TYPE * getOrCreate (IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
TYPE * getOrCreate (const std::string &location, const bool useRootInTES=true) const
TOOL * tool (const std::string &type, const std::string &name, const IInterface *parent=0, bool create=true) const
TOOL * tool (const std::string &type, const IInterface *parent=0, bool create=true) const
SERVICE * svc (const std::string &name, const bool create=true) const
IUpdateManagerSvcupdMgrSvc () const
IDataProviderSvcfastContainersSvc () const
StatusCode Error (const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
StatusCode Warning (const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
StatusCode Print (const std::string &msg, const StatusCode st=StatusCode::SUCCESS, const MSG::Level lev=MSG::INFO) const
StatusCode Assert (const bool ok, const std::string &message="", const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
StatusCode Assert (const bool ok, const char *message, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
StatusCode Exception (const std::string &msg, const GaudiException &exc, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
StatusCode Exception (const std::string &msg, const std::exception &exc, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
StatusCode Exception (const std::string &msg="no message", const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
MsgStreammsgStream (const MSG::Level level) const
MsgStreamalways () const
MsgStreamfatal () const
MsgStreamerr () const
MsgStreamerror () const
MsgStreamwarning () const
MsgStreaminfo () const
MsgStreamdebug () const
MsgStreamverbose () const
MsgStreammsg () const
const Statisticscounters () const
StatEntitycounter (const std::string &tag) const
MSG::Level msgLevel () const
bool msgLevel (const MSG::Level level) const
void resetMsgStream () const
bool typePrint () const
bool propsPrint () const
bool statPrint () const
bool errorsPrint () const
long printStat (const MSG::Level level=MSG::ALWAYS) const
long printErrors (const MSG::Level level=MSG::ALWAYS) const
long printProps (const MSG::Level level=MSG::ALWAYS) const
void registerCondition (const std::string &condition, StatusCode(CallerClass::*mf)()=NULL)
void registerCondition (const std::string &condition, CondType *&condPtrDest, StatusCode(CallerClass::*mf)()=NULL)
void registerCondition (char *condition, StatusCode(CallerClass::*mf)()=NULL)
void registerCondition (TargetClass *condition, StatusCode(CallerClass::*mf)()=NULL)
StatusCode runUpdate ()
TransientFastContainer< T > * getFastContainer (const std::string &location, typename TransientFastContainer< T >::size_type initial=0)
StatusCode release (const IInterface *interface) const
virtual unsigned long release ()
const std::string & context () const
const std::string & rootInTES () const
double globalTimeOffset () const
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvUnknown)
virtual unsigned long addRef ()
virtual const std::string & name () const
virtual const std::string & type () const
virtual const IInterfaceparent () const
virtual StatusCode configure ()
virtual StatusCode start ()
virtual StatusCode stop ()
virtual StatusCode terminate ()
virtual StatusCode reinitialize ()
virtual StatusCode restart ()
virtual Gaudi::StateMachine::State FSMState () const
virtual Gaudi::StateMachine::State targetFSMState () const
virtual StatusCode sysInitialize ()
virtual StatusCode sysStart ()
virtual StatusCode sysStop ()
virtual StatusCode sysFinalize ()
virtual StatusCode sysReinitialize ()
virtual StatusCode sysRestart ()
virtual StatusCode setProperty (const Property &p)
virtual StatusCode setProperty (const std::string &s)
virtual StatusCode setProperty (const std::string &n, const std::string &v)
StatusCode setProperty (const std::string &name, const TYPE &value)
virtual StatusCode getProperty (Property *p) const
virtual const PropertygetProperty (const std::string &name) const
virtual StatusCode getProperty (const std::string &n, std::string &v) const
virtual const std::vector<
Property * > & 
getProperties () const
PropertyMgrgetPropertyMgr ()
ISvcLocatorserviceLocator () const
ISvcLocatorsvcLoc () const
IMessageSvcmsgSvc () const
IToolSvctoolSvc () const
StatusCode setProperties ()
StatusCode service (const std::string &name, T *&svc, bool createIf=true) const
StatusCode service (const std::string &type, const std::string &name, T *&svc) const
void declInterface (const InterfaceID &, void *)
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
IAuditorSvcauditorSvc () const
IMonitorSvcmonitorSvc () const
void declareInfo (const std::string &name, const T &var, const std::string &desc) const
void declareInfo (const std::string &name, const std::string &format, const void *var, int size, const std::string &desc) const
virtual const std::string & type () const =0
virtual const IInterfaceparent () const =0
virtual StatusCode configure ()=0
virtual StatusCode initialize ()=0
virtual StatusCode start ()=0
virtual StatusCode stop ()=0
virtual StatusCode finalize ()=0
virtual StatusCode terminate ()=0
virtual StatusCode reinitialize ()=0
virtual StatusCode restart ()=0
virtual Gaudi::StateMachine::State FSMState () const =0
virtual StatusCode sysInitialize ()=0
virtual StatusCode sysStart ()=0
virtual StatusCode sysStop ()=0
virtual StatusCode sysFinalize ()=0
virtual StatusCode sysReinitialize ()=0
virtual StatusCode sysRestart ()=0
virtual unsigned long refCount () const =0
virtual const std::string & name () const =0
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)=0
virtual unsigned long addRef ()=0
virtual unsigned long release ()=0

Static Public Member Functions

static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()

Public Attributes

 SUCCESS
 NO_INTERFACE
 VERSMISMATCH
 LAST_ERROR

Protected Types

typedef std::map< std::string,
StatEntity
Statistics
typedef std::map< std::string,
unsigned int > 
Counter
typedef std::vector< IAlgTool * > AlgTools
typedef std::pair< IInterface *,
std::string > 
ServiceEntry
typedef std::vector< ServiceEntryServices

Protected Member Functions

StatusCode releaseTool (const IAlgTool *tool) const
StatusCode releaseSvc (const IInterface *svc) const
int outputLevel () const
virtual unsigned long refCount () const
IntegerPropertyoutputLevelProperty ()
void initOutputLevel (Property &prop)

Static Protected Attributes

static const bool IgnoreRootInTES
static const bool UseRootInTES

Private Types

typedef std::map< std::string,
std::string > 
ConditionPropertyMap_t
 Note: this is not a property.
typedef std::map< std::string,
ConditionData
CDMap_t

Private Member Functions

virtual StatusCode _initialize ()
StatusCode roll (std::string stream, ConditionData &cd)
StatusCode check_e (std::string stream, ConditionData &cd)
StatusCode check_m (std::string stream, ConditionData &cd)
StatusCode check_s (std::string stream, ConditionData &cd)

Private Attributes

std::string m_condition
 Property Condition: set the default size of output files for any streams not explicitly listed in the ConditionMap.
int m_startOffset
 Property StartOffset: sets the starting offset for "subrun" numbers to apply to the rolled output files.
ConditionPropertyMap_t m_condpropmap
int m_current_execnum
IRootIOSvc * m_rio
IRootIOSvc::FileMap m_filemap
CDMap_t m_cdmap
bool m_initialized

Classes

struct  ConditionData

Detailed Description

Change output file name when a condition is met.

This works by modifying the RootIOCnvSvc's output file map when a condition is met. If no output files are specified this algorithm quietly does nothing.

The condition is set with the Condition properties, eg 15S will produce files with fifteen seconds worth of data.

The output file map specified on the nuwa.py command line can contain a format code like "%d" (or variants like "%04d"). If so, it will be expanded to hold a count, starting from 1, of the file. If no "%d" code is found then the file names will be modified to change ".root" to "_%04d.root".

This algorithm will roll output file names based on a given condition which consists of integer number followed by a character code:

E: execution cycles M: mebibytes (10^6 bytes) S: seconds period of time as measured by the RegistrationSequences

Note, current RootIO requires all output files to be split on common boundaries in order to be read in correctly.

Brett Viren <bv@bnl.gov> Mon Feb 14 17:33:01 2011

Definition at line 47 of file OutputFileRollerTool.h.


Member Typedef Documentation

typedef std::map<std::string,std::string> OutputFileRollerTool::ConditionPropertyMap_t [private]

Note: this is not a property.

I can be turned on when/if RootIO can handle input streams that do not have common file boundaries. See #671.

ConditionMap: explicitly set condition to split specific output stream. A special stream named "default" can be set which will have the behavior of the Condition property (which overides if set). The map key is a stream name (like "/Event/Gen/GenEvent") and the map value is a condition as described in the Condition property's documentation. Note: for a non-default condition to be applied the stream->file mapping must be explicitly defined in RootIOCnvSvc (via nuwa.py's -O/--output-streams option).

Definition at line 91 of file OutputFileRollerTool.h.

typedef std::map<std::string,ConditionData> OutputFileRollerTool::CDMap_t [private]

Definition at line 114 of file OutputFileRollerTool.h.


Constructor & Destructor Documentation

OutputFileRollerTool::OutputFileRollerTool ( const std::string &  type,
const std::string &  name,
const IInterface parent 
)

Definition at line 15 of file OutputFileRollerTool.cc.

00018     : GaudiTool(type,name,parent)
00019     , m_current_execnum(0)
00020     , m_rio(0), m_initialized(false)
00021 {
00022     declareInterface<IRegSeqVisitor>(this);
00023 
00024     declareProperty("Condition",m_condition="",
00025                     "Set the default condition for rolling to a new output file");
00026 
00027     declareProperty("StartNumber", m_startOffset=0,
00028                     "Set the starting file number offset, def=0 (first file gets 1).");
00029 
00030     // This condition map will be a trivial one just containing
00031     // "default" as set by the global condition above.  It can be made
00032     // non-trivial when/if RootIO can handle reading input streams
00033     // with non-common boundaries.  See #671.
00034 
00035     //declareProperty("ConditionMap",m_condpropmap,
00036     //                "Set the condition map for rolling each stream to a new output file");
00037 }

OutputFileRollerTool::~OutputFileRollerTool (  )  [virtual]

Definition at line 39 of file OutputFileRollerTool.cc.

00040 {
00041 }


Member Function Documentation

StatusCode OutputFileRollerTool::visit ( DayaBay::RegistrationSequence rs  )  [virtual]

Implements IRegSeqVisitor.

Definition at line 212 of file OutputFileRollerTool.cc.

00213 {
00214     if (!m_initialized) {
00215         // have to do explicit initialize as ToolSvc and thus this
00216         // tool gets initialized before RootIOCnvSvc does.
00217         this->_initialize();
00218     }
00219 
00220     if (!m_filemap.size()) {    // no output files, bail blissfully
00221         return StatusCode::SUCCESS;
00222     }
00223 
00224     TimeStamp now = rs.earliest();
00225     ++m_current_execnum;
00226     debug() << "Execution #" << m_current_execnum << " @ " << now << endreq;
00227 
00228     CDMap_t::iterator it, done = m_cdmap.end();
00229     for (it=m_cdmap.begin(); it != done; ++it) {
00230         string stream = it->first;
00231         ConditionData& cd = it->second;
00232 
00233         StatusCode sc;
00234 
00235         switch (cd.unit) {
00236         case 'M':
00237             sc = check_m(stream,cd);
00238             break;
00239         case 'E':
00240             sc = check_e(stream,cd);
00241             break;
00242         case 'S':
00243             sc = check_s(stream,cd);
00244             break;
00245         default:
00246             error() << "Unknown condition unit '" << cd.unit << "'" 
00247                     << " for stream \"" << stream << "\""
00248                     << endreq;
00249             sc = StatusCode::FAILURE;
00250         }
00251         if (sc.isFailure()) return sc;
00252     }
00253     return StatusCode::SUCCESS;
00254 }

StatusCode OutputFileRollerTool::_initialize (  )  [private, virtual]

Definition at line 43 of file OutputFileRollerTool.cc.

00044 {
00045     m_initialized = true;
00046 
00047     // Get IRootIOSvc
00048     StatusCode sc = this->service("RootIOCnvSvc",m_rio);
00049     if (sc.isFailure()) return sc;
00050 
00051     m_filemap = m_rio->fileMap();
00052     if (!m_filemap.size()) {
00053         info () << "Output filemap is empty, nothing for me to do." << endreq;
00054         return StatusCode::SUCCESS; // we just won't play this time
00055     }
00056     
00057     // munge the output filenames where needed
00058     {
00059         IRootIOSvc::FileMap::iterator it, done = m_filemap.end();
00060         for (it = m_filemap.begin(); it != done; ++it) {
00061             string fname = Form(it->second.c_str(),0);
00062             if (fname != it->second) {
00063                 continue;           // already has a %d code that does something
00064             }
00065             
00066             string::size_type ind = it->second.rfind(".");
00067             // shouldn't happen, but whatevs, we'll roll with it
00068             if (string::npos == ind) { 
00069                 ind = it->second.size(); 
00070             }
00071             
00072             // replace filename with one that has a %d code.
00073             fname = it->second.substr(0,ind) + "_%04d" + it->second.substr(ind);
00074             it->second = fname;
00075         }
00076     }
00077     
00078     // specifically set default condition if one is given
00079     if (m_condition.size()) {
00080         m_condpropmap["default"] = m_condition;
00081     }
00082 
00083     { // parse conditions map and strip out any explicit conditions
00084       // with no matching entry in output file map
00085         ConditionPropertyMap_t::iterator it, done = m_condpropmap.end();
00086         for (it=m_condpropmap.begin(); it != done; ++it) {
00087             string stream = it->first;
00088             string condition = it->second;
00089 
00090             if (stream != "default") {
00091                 IRootIOSvc::FileMap::iterator fit = m_filemap.find(stream);
00092                 if (fit == m_filemap.end()) {
00093                     error() << "Condition \"" << condition 
00094                             << "\" for stream \"" << stream 
00095                             << "\" has no output file.  " 
00096                             << "An entry can be specified with nuwa.py's"
00097                             << " -O/--output-stream option"
00098                             << endreq;
00099                     return StatusCode::FAILURE;
00100                 }
00101             }
00102             
00103             string::size_type clen = condition.size();
00104             if (!clen) {
00105                 error() << "Given a null condition for stream \""
00106                         << stream << "\"" << endreq;
00107                 return StatusCode::FAILURE;
00108             }
00109             int size = atoi(condition.substr(0,clen-1).c_str());
00110             char unit = condition[clen-1];
00111             ConditionData cd = ConditionData(size,unit);
00112             cd.cycles = size;   // special init, count down on this if an E condition
00113             m_cdmap[stream] = cd;
00114             info() << "Condition for stream " << stream << ": " << size << unit << endreq;
00115             sc = this->roll(stream,m_cdmap[stream]);
00116             if (sc.isFailure()) return sc;
00117         }
00118     }
00119 
00120     return StatusCode::SUCCESS;
00121 }

StatusCode OutputFileRollerTool::roll ( std::string  stream,
ConditionData cd 
) [private]

Definition at line 122 of file OutputFileRollerTool.cc.

00123 {
00124     ++cd.count;
00125 
00126     IRootIOSvc::FileMap::iterator fit = m_filemap.find(stream);
00127     if (fit == m_filemap.end()) {
00128         error() << "Failed to find output filespec for \"" << stream << "\"" << endreq;
00129         return StatusCode::FAILURE;
00130     }
00131 
00132     string fname = Form(fit->second.c_str(),cd.count+m_startOffset);
00133     m_rio->associateOutput(fname.c_str(),stream.c_str());
00134 
00135     info() << "Rolled " << stream << " to file " << fname << endreq;
00136 
00137     return StatusCode::SUCCESS;
00138 }

StatusCode OutputFileRollerTool::check_e ( std::string  stream,
ConditionData cd 
) [private]

Definition at line 168 of file OutputFileRollerTool.cc.

00169 {
00170     debug() << "check_e " << stream << " " << cd.cycles << " " << (void*)&cd << endreq;
00171 
00172     // check for first time
00173     if (cd.cycles < 0) {
00174         cd.cycles = cd.size;
00175     }
00176 
00177     if (cd.cycles>0) {
00178         --cd.cycles;
00179         return StatusCode::SUCCESS;
00180     }
00181     cd.cycles = cd.size-1;        // reset countdown
00182     info () << "Reached " << cd.size << " execution cycles" << endreq;
00183     return this->roll(stream,cd);
00184 }

StatusCode OutputFileRollerTool::check_m ( std::string  stream,
ConditionData cd 
) [private]

Definition at line 140 of file OutputFileRollerTool.cc.

00141 {
00142     IRootIOSvc::FileMap fm = m_rio->fileMap();
00143     IRootIOSvc::FileMap::iterator fit = fm.find(stream);
00144     if (fit == fm.end()) {
00145         error() << "Failed to find an output file for stream \"" << stream << "\""
00146                 << endreq;
00147         return StatusCode::FAILURE;
00148     }
00149     string fname = fit->second;
00150     struct stat si;
00151     int err = stat(fname.c_str(), &si);
00152     if (err) {
00153         warning() << "Failed to stat " << fname
00154                   << ".  Maybe no output yet?  Letting it go."
00155                   << endreq;
00156         return StatusCode::SUCCESS;
00157     }
00158         
00159     if (si.st_size/1000000 < cd.size) {  // bytes to mibibytes
00160         return StatusCode::SUCCESS;
00161     }
00162     info () << "Reached " << cd.size << " MiB size" << endreq;
00163     return this->roll(stream,cd);
00164 }

StatusCode OutputFileRollerTool::check_s ( std::string  stream,
ConditionData cd 
) [private]

Definition at line 188 of file OutputFileRollerTool.cc.

00189 {
00190     RegistrationSequence* rs = 
00191         get<RegistrationSequence>(RegistrationSequence::defaultLocation());
00192 
00193     TimeStamp now = rs->earliest();
00194 
00195     // check for first time
00196     if (cd.timestamp == TimeStamp::GetBOT()) {
00197         cd.timestamp = now;
00198         return StatusCode::SUCCESS;
00199     }
00200 
00201     TimeStamp dt = now - cd.timestamp;
00202     int deltat = (int)((double)dt);
00203     if (deltat < cd.size) {     // not yet
00204         return StatusCode::SUCCESS;
00205     }
00206     
00207     cd.timestamp = now;
00208     info () << "Reached " << cd.size << " seconds at " << now << endreq;
00209     return this->roll(stream,cd);
00210 }


Member Data Documentation

std::string OutputFileRollerTool::m_condition [private]

Property Condition: set the default size of output files for any streams not explicitly listed in the ConditionMap.

This should be an integer followed by a unit code. The unit code can be one of:

E: execution cycles M: mebibytes (10^6 bytes) S: seconds period of time as measured by the RegistrationSequences

A special condition "None" will leave the stream untouched.

Definition at line 71 of file OutputFileRollerTool.h.

int OutputFileRollerTool::m_startOffset [private]

Property StartOffset: sets the starting offset for "subrun" numbers to apply to the rolled output files.

Default is 0, making the numbering start at 1.

Definition at line 76 of file OutputFileRollerTool.h.

ConditionPropertyMap_t OutputFileRollerTool::m_condpropmap [private]

Definition at line 92 of file OutputFileRollerTool.h.

int OutputFileRollerTool::m_current_execnum [private]

Definition at line 95 of file OutputFileRollerTool.h.

IRootIOSvc* OutputFileRollerTool::m_rio [private]

Definition at line 96 of file OutputFileRollerTool.h.

IRootIOSvc::FileMap OutputFileRollerTool::m_filemap [private]

Definition at line 97 of file OutputFileRollerTool.h.

CDMap_t OutputFileRollerTool::m_cdmap [private]

Definition at line 115 of file OutputFileRollerTool.h.

bool OutputFileRollerTool::m_initialized [private]

Definition at line 117 of file OutputFileRollerTool.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:37:25 2011 for DybTool by doxygen 1.4.7