68 std::set<std::string> files1;
70 search_expr.pushDirectory(Poco::format(
"run_%d", run_number));
71 Poco::Glob::glob(search_expr, files1, Poco::Glob::GLOB_CASELESS);
72 BOOST_FOREACH(
const std::string& s, files1)
74 if (s.back() ==
'/' || s.back() ==
'\\')
76 files.insert(s.substr(0,s.length()-1));
87 Poco::RegularExpression re(
"dc_([0-9]+).dat", Poco::RegularExpression::RE_CASELESS);
88 Poco::RegularExpression::MatchVec matches;
90 re.match(file, 0, matches);
91 if (matches.size() == 2)
93 s = file.substr(matches[1].offset, matches[1].length);
94 return Poco::NumberParser::parse(s);
107 for(std::set<std::string>::const_iterator it = files.begin(); it != files.end(); ++it)
121 std::set<std::string> files;
124 if (files.size() == 0)
129 BOOST_FOREACH(
const std::string& f, files)
211 ICPTimer timer(
"EventStore::setOutputFileName", status);
212 LOGSTR_DEBUG(
"Setting output event file names for run number " << run_number);
217 timer.
info(
"After setting of card sources", status);
219 std::set<std::string> files;
221 BOOST_FOREACH(
const std::string& file, files)
223 LOGSTR_DEBUG(
"Removing no longer used source " << file);
230 ICPTimer timer(
"EventStore::clearOutputFile", status);
257 std::set<std::string> files;
259 BOOST_FOREACH(
const std::string& file, files)
265 if (run_dir.exists())
269 run_dir.remove(
true);
271 catch(
const std::exception& ex)
273 status.
addInfoVa(
FAC_DAE,
"Unable to remove all files in event directory of run %d: %s", run_number, ex.what());
290 bool end_seen =
true;
291 unsigned nseen = 0, nchecked = 0;
310 LOGSTR_DEBUG(
"Checking for end header - seen " << nseen <<
"/" << nchecked);
315 template<
typename SLOT>
318 std::list<boost::signals2::connection> conn_list;
321 conn_list.push_back((ec.
card->*func)(slot));
401 #define THROW_RETURN_NE(__comm, __val, __mess) \
402 if ( (__comm) != (__val) ) \
404 throw std::runtime_error(__mess); \
408 m_run_number(-1), m_keep_going(true), m_immediate_stop(false), m_len_buffer(0), m_buffer(NULL)
418 std::string file_name;
419 Poco::format(file_name,
"dc_%d.dat", dc_number);
421 p.pushDirectory(Poco::format(
"run_%d", run_number));
427 std::string info_file_name;
428 Poco::format(info_file_name,
"dc_%d.info", dc_number);
430 p.pushDirectory(Poco::format(
"run_%d", run_number));
436 if (
atomic_read(file_name,
".old", &info, 1) != 0 )
464 LOGSTR_DEBUG(
"Setting output run number to " << run_number);
472 std::string file_name, info_file_name;
475 dir_name.setFileName(
"");
476 Poco::File(dir_name).createDirectories();
486 throw std::runtime_error(
"fopen");
526 throw std::runtime_error(
"atomic_write");
552 m_threads.start(histogram_events,
"histogram_events");
567 Poco::Thread::yield();
594 throw std::runtime_error(
"fwrite");
598 throw std::runtime_error(
"flush");
632 static bool frameworkaround_default = Poco::Util::Application::instance().config().getBool(
"isisicp.frameworkaround",
false);
634 static bool frameworkaround = frameworkaround_default;
635 static bool badheaderworkaround = Poco::Util::Application::instance().config().getBool(
"isisicp.badheaderworkaround",
false);
637 int i, num_words = 0;
638 std::string error_message;
639 unsigned num_frames_fixed = 0;
659 if (badheaderworkaround)
677 LOGSTR_WARNING(
"Skipped " << n <<
" words and found header at offset " << num_words);
682 if ( frame_diff != 1 )
734 if ( num_frames_fixed > 0 )
736 LOGSTR_INFORMATION(
"Frame number in event header was fixed " << num_frames_fixed <<
" times");
797 throw std::runtime_error(
"fopen");
813 uint32_t num_to_read = 0;
821 if (new_words > maxlen)
823 num_unread = new_words - maxlen;
824 num_to_read = maxlen;
829 num_to_read =
static_cast<uint32_t
>(new_words);
833 nread =
m_file.
read(buffer,
sizeof(uint32_t), num_to_read);
834 if (nread != num_to_read)
836 LOGSTR_ERROR(
"Only read " << nread <<
" out of " << num_to_read <<
" requested words");
839 if (nread == static_cast<size_t>(-1))
885 m_source_id(source_id), m_events(0), m_events_sent(0), m_pos(0), m_pos_sent(0), m_last_frame(-1)
898 int persize = (nsp1 + 1) * (ntc1 + 1);
900 for(i=0; i < ndet; i++)
902 maxcrate = std::max(maxcrate,
m_file->
crat[i]);
904 int maxspec = nsp1 + 1;
905 int* last_card_spectrum =
new int[maxcrate+1];
906 memset(last_card_spectrum, 0, (maxcrate+1) *
sizeof(
int));
911 int card, spec, offset;
914 for(i=0; i < ndet; i++)
925 for(i=1; i < maxspec; ++i)
930 delete []last_card_spectrum;
931 for(i=0; i<nper; ++i)
933 for(j=0; j<nsp1+1; ++j)
937 for(k=0; k<ntc1+1; ++k)
939 offset = k + j*(ntc1+1) + i*persize;
971 return readEvents(buffer, maxlen, num_unread);
1019 while(num_sent < max_num_to_read)
1025 spec =
m_pos / (ntc1 + 1);
1046 memcpy(buffer+num_sent, reinterpret_cast<isisU32_t*>(&ev),
sizeof(ev));
1055 #define PPP_TO_UAMPH 1.738E-6
1060 const int isis_frequency = 10;
1061 memset(&header, 0 ,
sizeof(header));
1083 return current_frame;
void flushEvents(DAEstatus &status)
const int * getDAE2SpecMap()
void setLastAddressRead(isisU32_t addr)
static std::string fileNameForDC(int run_number, int dc_number)
NoFrameCallbackType m_no_frame_callbacks
boost::signals2::connection addAllEventCallback(const EventCallbackSlotType &slot)
static void printEventHeader(const DAEEventHeader *head, std::ostream &os)
std::list< boost::signals2::connection > addGoodFrameCallback(const FrameCallbackSlotType &slot)
int seek(int64_t offset, int whence)
size_t write(const void *data, size_t element_size, size_t nelement)
static std::string infoFileNameForDC(int run_number, int dc_number)
boost::signals2::connection addAllFrameCallback(const FrameCallbackSlotType &slot)
uint32_t raw_frames
total number of raw frames in file
static int eventSourceIDFromFileInputSource(const std::string &file)
uint32_t m_pos_sent
number of events sent from pos
int atomic_read(const std::string &filename, const std::string &old_suffix, T *data, size_t n)
virtual const int * getDAE2SpecMap()=0
Poco::MemoryPool m_mempool
virtual int eventSourceID() const =0
uint64_t nNewEventWords(DAEstatus &status)
int eventSourceID() const
isisU32_t * m_buffer
buffer containing new events from detector card
NoFrameCallbackType::slot_type NoFrameCallbackSlotType
uint32_t m_events_sent
events sent to date
Poco::ThreadPool m_threads
std::vector< FileEventSourceBase * > m_sources
std::string getFileName()
static const int DAEEventHeaderFixedMarker
void releaseBuffer(isisU32_t *buffer)
static void OffsetToDAETime(time_t base, double offset, DAEEventHeader::DAETime &daetime)
#define LOGSTR_DEBUG(__arg)
void readInfo(EventStore::FileEventSourceInfo &info)
std::string m_info_file_name
uint32_t getNewEvents(isisU32_t *buffer, uint32_t maxlen, uint64_t &num_unread, bool &run_ended, DAEstatus &status)
void getEnabledEventSourceIDs(std::vector< int > &ids)
void setOutputFileName(int run_number, bool new_run, DAEstatus &status)
virtual uint32_t getNewEvents(isisU32_t *buffer, uint32_t maxlen, uint64_t &num_unread, bool &run_ended, DAEstatus &status)=0
static Poco::Path baseRunDir(int run_number)
void setCardStatus(int id, bool enable)
uint32_t last_frame
offset to start of last frame in words
void addCard(DAEEventSource *det_card, bool enable=false)
uint32_t last_address_read
detector card address read which corresponds to file_words
#define LOGSTR_WARNING(__arg)
virtual ~ISISRAWEventSource()
int eventSourceID() const
ISISRAWEventSource(ISISRAW *iraw, int source_id, time_t run_start)
boost::signals2::connection addNoFrameCallback(const NoFrameCallbackSlotType &slot)
void invokeNoFrameCallbacks(NoFrameCallbackMode mode)
void closeOutputFile(DAEstatus &status)
void stop(bool immediate)
size_t read(void *data, size_t element_size, size_t nelement)
std::vector< EventStoreCardHolder > m_stores
uint64_t raw_events
total number of raw events in file
void add(const FileEventSourceInfo &f)
static const int m_mempool_size
uint64_t nNewEventWords(DAEstatus &status)
uint64_t good_events
total number of good events in file
void checkAndHistogramEvents()
void fixBadFrameHeader(DAEEventHeader &head)
DAEEventHeader header
header of current frame being processed
static int findValidEventHeaderOffset(const isisU32_t *buffer, uint32_t len, DAEstatus &status)
returns index of start of a valid event header, -1 on error
std::list< boost::signals2::connection > addAllFrameCallback(const FrameCallbackSlotType &slot)
int sendHeader(isisU32_t *buffer, int current_frame)
std::list< boost::signals2::connection > addGoodEventCallback(const EventCallbackSlotType &slot)
#define LOGSTR_INFORMATION(__arg)
virtual void updateDAEEventLastRead(DAEstatus &status)=0
void invokeNoFrameCallbacks(NoFrameCallbackMode mode)
FrameCallbackType m_good_frame_callbacks
int readEvents(isisU32_t *buffer, uint32_t max_num_to_read, uint64_t &num_unread)
#define LOGSTR_ERROR(__arg)
void stop(bool immediate)
request stop after processing finished
const int * getDAE2SpecMap()
uint64_t nNewEventWords(DAEstatus &status)
uint32_t m_len_buffer
number of words in m_buffer
double info(const char *title, std::ostream &os, bool add_nl=true)
isisU32_t getLastAddressRead()
virtual ~FileEventSource()
void setLastAddressRead(isisU32_t addr)
bool fixFrameHeader(DAEEventHeader &head)
static void removeFile(const std::string &path)
void closeAndDeleteOutputFile(int run_number, DAEstatus &status)
static void deleteOutputFile(int run_number, DAEstatus &status)
virtual void setLastAddressRead(isisU32_t addr)=0
std::string m_info_file_name
int getFrame(uint32_t event_count)
find out what frame to put event number event_count into - first frame is 0
std::list< boost::signals2::connection > addCallback(boost::signals2::connection(EventStoreCard::*func)(const SLOT &), const SLOT &slot)
uint32_t m_events
total events to send
void setOutputFileName(int run_number, bool new_run, DAEstatus &status)
void updateFilePosition(DAEstatus &status)
int eventSourceID() const
static const unsigned DAE_EVENT_HEADER_WORDS
uint32_t good_frames
total number of good frames in file
boost::signals2::connection addGoodEventCallback(const EventCallbackSlotType &slot)
void findUnusedFileInputSources(int run_number, std::set< std::string > &files)
static void getInfoFileData(const std::string &file_name, InfoFileData &info)
Poco::LogStream * m_logstr
static bool isEndRunHeader(const DAEEventHeader *head, DAEstatus &status)
check whether an event frame header is a special enf of frame header
Poco::ThreadPool m_threads
EventCallbackType m_all_event_callbacks
static const Poco::Path & baseDir()
uint64_t file_words
size of all data in file in words
void clearOutputFile(DAEstatus &status)
std::list< boost::signals2::connection > addNoFrameCallback(const NoFrameCallbackSlotType &slot)
boost::signals2::connection addGoodFrameCallback(const FrameCallbackSlotType &slot)
FrameCallbackType::slot_type FrameCallbackSlotType
static Poco::Path m_base_dir
void setLoggerName(const std::string &logger_name)
FrameCallbackType m_all_frame_callbacks
void addCards(const std::vector< DAEEventSource * > &det_list)
uint32_t m_pos
current location in raw data
int open(const std::string &path, IFile::Mode mode, int shflag)
static void findFileInputSources(int run_number, std::set< std::string > &files)
uint64_t nNewEventWords(DAEstatus &status)
void updateDAEEventLastRead(DAEstatus &status)
uint32_t getNewEvents(isisU32_t *buffer, uint32_t maxlen, uint64_t &num_unread, bool &run_ended, DAEstatus &status)
void addRawFileInputSource(ISISRAW *iraw, int source_id, time_t run_start)
void updateDAEEventLastRead(DAEstatus &status)
std::vector< int > m_frame_events
virtual uint64_t nNewEventWords(DAEstatus &status)=0
uint32_t num_events
total number of events read in frame m_header
EventCallbackType::slot_type EventCallbackSlotType
EventCallbackType m_good_event_callbacks
void addFileInputSource(int run_number, FileEventSourceInfo &info)
int addInfoVa(int facility, const char *format,...)
void getEventSourceIDs(std::vector< int > &ids)
std::list< boost::signals2::connection > addAllEventCallback(const EventCallbackSlotType &slot)
int atomic_write(const std::string &filename, const std::string &old_suffix, const std::string &new_suffix, T *data, int n)
bool endHeaderSeen() const
uint32_t header_words
number of words of header read, if < DAE_EVENT_HEADER_WORDS then we have a partial header ...
void clearOutputFile(DAEstatus &status)
virtual isisU32_t getLastAddressRead()=0
static void checkEventHeader(const DAEEventHeader *head)
isisU32_t getLastAddressRead()
void readInfo(EventStore::FileEventSourceInfo &info)