00001 #include "TrimmingAgent.h" 00002 00003 #include "GaudiKernel/DataObject.h" 00004 #include "GaudiKernel/GaudiException.h" 00005 #include "GaudiKernel/IRegistry.h" 00006 #include "GaudiKernel/MsgStream.h" 00007 #include "DataUtilities/DybArchiveList.h" 00008 00009 TrimmingAgent::TrimmingAgent(MsgStream* msgStream) : 00010 m_window(0), 00011 m_msgStream(msgStream){ 00012 } 00013 00014 TrimmingAgent::~TrimmingAgent() { 00015 if (0 != m_msgStream) { 00016 delete m_msgStream; 00017 } 00018 } 00019 00020 bool TrimmingAgent::analyse(IRegistry* pRegistry, 00021 int /* level */) { 00022 DataObject* object = pRegistry->object(); 00023 if (0 == object) { 00024 return true; 00025 } 00026 00027 DybArchiveList* list = dynamic_cast<DybArchiveList*>(object); 00028 if (0 == list) { 00029 return true; 00030 } 00031 00032 std::string path = pRegistry->identifier(); 00033 TimeStamp earliest = m_latest; 00034 earliest.Add(-1.0 * window(path)); 00035 00036 unsigned int dataCount = 0; 00037 unsigned int temporalCount = 0; 00038 DybArchiveList::iterator entry = list->begin(); 00039 while (list->end() != entry) { 00040 (*m_msgStream)<< MSG::VERBOSE<< "not end" <<endreq; 00041 DataObject* dataObject = (*entry); 00042 00043 // Protect against zero object. 00044 if ( 0 == dataObject) { 00045 entry = list->erase(entry); 00046 } else { 00047 // wangzhe 00048 //ITemporal* temporalObject = dynamic_cast<ITemporal*>(dataObject); 00049 TemporalDataObject * temporalObject = dynamic_cast<TemporalDataObject*>(dataObject); 00050 // wz 00051 00052 if (0 == temporalObject) { 00053 entry = list->erase(entry); 00054 ++dataCount; 00055 } else { 00056 // for debuging 00057 (*m_msgStream)<< MSG::VERBOSE<< path<<endreq; 00058 (*m_msgStream)<< MSG::VERBOSE<< "pObj "<<temporalObject<<endreq; 00059 (*m_msgStream)<< MSG::VERBOSE<< "m_latest "<<m_latest<<endreq; 00060 (*m_msgStream)<< MSG::VERBOSE<< "earliest "<<earliest<<endreq; 00061 (*m_msgStream)<< MSG::VERBOSE<< "window "<<double(window(path))<< " seconds"<<endreq; 00062 (*m_msgStream)<< MSG::VERBOSE<< "obj latest "<<temporalObject->latest()<<endreq; 00063 (*m_msgStream)<< MSG::VERBOSE<< "obj earliest "<<temporalObject->earliest()<<endreq; 00064 (*m_msgStream)<< MSG::VERBOSE<< "obj refCount "<<temporalObject->refCount()<<endreq; 00065 // only earliest time is always in time order. 00066 // Some event with long delay coincidence might inverse the sequence. 00067 if (temporalObject->earliest() <= earliest) { 00068 (*m_msgStream) 00069 << MSG::DEBUG<< "Erased from AES " << path 00070 << " dt = " << double(earliest - temporalObject->earliest()) << " seconds" 00071 << endreq; 00072 entry = list->erase(entry); 00073 ++temporalCount; 00074 } else { 00075 ++entry; 00076 } 00077 // for debuging 00078 // (*m_msgStream) << MSG::VERBOSE<<"obj refCount "<<temporalObject->refCount()<<endreq; 00079 } 00080 } 00081 } 00082 if (0 != m_msgStream) { 00083 if (0 != dataCount) { 00084 std::string plural = ""; 00085 if (1 != dataCount) { 00086 plural == "s"; 00087 } 00088 (*m_msgStream) << MSG::DEBUG 00089 << "Removed " 00090 << dataCount 00091 << " DataObject" 00092 << plural 00093 << " from the \"" 00094 << path 00095 << "\" node in the archive." 00096 << endreq; 00097 } 00098 if (0 != temporalCount) { 00099 std::string plural = ""; 00100 if (1 != dataCount) { 00101 plural == "s"; 00102 } 00103 (*m_msgStream) << MSG::DEBUG 00104 << "Removed " 00105 << temporalCount 00106 << " ITemporal object" 00107 << plural 00108 << " from the \"" 00109 << path 00110 << "\" node in the archive." 00111 << endreq; 00112 } 00113 } 00114 return true; 00115 } 00116 00117 const TimeStamp TrimmingAgent::earliest() { 00118 TimeStamp result = m_latest; 00119 result.Add(m_window); 00120 return result; 00121 } 00122 00123 const TimeStamp& TrimmingAgent::latest() { 00124 return m_latest; 00125 } 00126 00127 const TimeStamp& TrimmingAgent::window() { 00128 return m_window; 00129 } 00130 00131 const TimeStamp& TrimmingAgent::window(const std::string& path) { 00132 WindowMap_t::iterator wit = m_windows.find(path); 00133 if (wit == m_windows.end()) { 00134 return m_window; 00135 } 00136 return wit->second; 00137 } 00138 00139 void TrimmingAgent::setLatest(const TimeStamp& latest) { 00140 m_latest = latest; 00141 } 00142 00143 void TrimmingAgent::setWindow(const TimeStamp& window) { 00144 m_window = window; 00145 } 00146 00147 void TrimmingAgent::setWindow(const std::string& path, 00148 const TimeStamp& window) { 00149 m_windows[path] = window; 00150 }