17 std::cout <<
"handling signal no. " << sig <<
" ";
18 std::cout <<
"(press ctrl-\\ to abort now)\n";
24 #include "THaCodaFile.h"
26 #include "THaEtClient.h"
43 : fDataFileStem(fDefaultDataFileStem),
44 fDataFileExtension(fDefaultDataFileExtension),
45 fEvStreamMode(fEvStreamNull),
48 fRunIsSegmented(kFALSE),
49 fPhysicsEventFlag(kFALSE),
61 QwError <<
"ERROR: Can't get the data directory in the QwEventBuffer creator."
83 "use online data stream");
86 "Effective run number to be used by online system to find the parameter files");
88 (
"run,r", po::value<string>()->default_value(
"0:0"),
89 "run range in format #[:#]");
91 (
"runlist", po::value<string>()->default_value(
""),
92 "run list file example \n[5253]\n 234\n 246\n 256\n 345:456\n 567:789\n [5259]\n [5260]\n 0:10000\n [5261:5270]\n 9000:10000\n- for run 5253 it will analyze three individual events, and two event ranges \n- for run 5259 it will analyze the entire run (all segments) \n- for run 5260 it will analyze the first 10000 events \n- for runs 5261 through 5270 it will analyze the events 9000 through 10000)");
94 (
"event,e", po::value<string>()->default_value(
"0:"),
95 "event range in format #[:#]");
97 (
"segment,s", po::value<string>()->default_value(
"0:"),
98 "run segment range in format #[:#]");
101 "chain file segments together, do not analyze them separately");
104 "stem of the input CODA filename");
107 "extension of the input CODA filename");
110 (
"ET.hostname", po::value<string>(),
111 "Name of the ET session's host machine --- Only used in online mode\nDefaults to the environment variable $HOSTNAME");
113 (
"ET.session", po::value<string>(),
114 "ET session name --- Only used in online mode\nDefaults to the environment variable $SESSION");
116 (
"ET.station", po::value<string>(),
117 "ET station name --- Only used in online mode");
125 QwError <<
"Online mode will not work without the CODA libraries!"
129 if (options.
HasValue(
"online.RunNumber")) {
132 if (options.
HasValue(
"ET.station")) {
137 if (options.
HasValue(
"ET.hostname")) {
142 if (options.
HasValue(
"ET.session")) {
150 tmp +=
" \"HOSTNAME\"";
152 if (tmp.Length() > 0)
154 tmp +=
" ET \"SESSION\"";
157 <<
" variable(s) is(are) not defined in your environment.\n"
158 <<
" This is needed to run the online analysis."
188 if (nevents==0) nevents=1;
192 <<
"CPU time used: " <<
fRunTimer.CpuTime() <<
" s "
194 <<
"Real time used: " <<
fRunTimer.RealTime() <<
" s "
205 std::string eventrange;
227 std::string runrange;
235 QwWarning <<
"No valid event range in run list file: "
237 <<
"Assuming the full event range." <<
QwLog::endl;
274 Int_t status = CODA_ERROR;
295 Int_t status = CODA_ERROR;
305 QwMessage <<
"Try to open the ET station with HOSTNAME=="
320 if (status == CODA_ERROR){
323 QwError <<
"ERROR: Unable to find data files for run "
368 Int_t status = CODA_OK;
393 }
while (status == CODA_OK &&
407 QwMessage << efficiency <<
"% efficiency)";
428 if (status == CODA_OK){
435 Int_t status = CODA_OK;
453 Int_t status = CODA_OK;
457 if (status == CODA_EXIT)
478 Int_t status = CODA_OK;
481 status = ((THaCodaFile*)
fEvStream)->codaWrite(buffer);
489 std::vector<UInt_t> buffer;
493 std::vector<UInt_t> header;
494 header.push_back((0x0001 << 16) | (0x10 << 8) | 0xCC);
497 header.push_back((0xC000 << 16) | (0x01 << 8) | 0x00);
507 int* codabuffer =
new int[header.size() + buffer.size() + 1];
510 codabuffer[k++] = header.size() + buffer.size();
511 for (
size_t i = 0; i < header.size(); i++)
512 codabuffer[k++] = header.at(i);
513 for (
size_t i = 0; i < buffer.size(); i++)
514 codabuffer[k++] = buffer.at(i);
528 int localtime = (int) time(0);
531 buffer[2] = localtime;
532 buffer[3] = runnumber;
540 int localtime = (int) time(0);
543 buffer[1] = ((
kGO_EVENT << 16) | (0x01 << 8) | 0xCC);
544 buffer[2] = localtime;
546 buffer[4] = eventcount;
553 int localtime = (int) time(0);
556 buffer[1] = ((
kPAUSE_EVENT << 16) | (0x01 << 8) | 0xCC);
557 buffer[2] = localtime;
559 buffer[4] = eventcount;
566 int localtime = (int) time(0);
569 buffer[1] = ((
kEND_EVENT << 16) | (0x01 << 8) | 0xCC);
570 buffer[2] = localtime;
572 buffer[4] = eventcount;
584 UInt_t local_datatype;
585 UInt_t local_eventtype;
589 if ( buffer[0] == 0 ){
610 fEvtTag = (buffer[1] & 0xFFFF0000) >> 16;
611 local_datatype = (buffer[1] & 0xFF00) >> 8;
621 if ( local_eventtype <= 15) {
673 QwMessage <<
"QwEventBuffer::FillSubsystemConfigurationData: "
674 <<
"Found configuration event for ROC"
677 QwMessage << Form(
"Evt type: 0x%x; Evt number %d; Evt Class 0x%.8x; ",
681 UInt_t *localbuff = (UInt_t*)(
fEvStream->getEvBuffer());
705 &localbuff[fWordsSoFar],
708 QwDebug <<
"QwEventBuffer::FillSubsystemConfigurationData: "
709 <<
"Ending loop: fWordsSoFar=="<<fWordsSoFar
722 UInt_t *localbuff = (UInt_t*)(
fEvStream->getEvBuffer());
786 &localbuff[fWordsSoFar],
816 QwVerbose <<
"QwEventBuffer::FillEPICSData: "
819 UInt_t *localbuff = (UInt_t*)(
fEvStream->getEvBuffer());
834 char* tmpchar = (Char_t*)&localbuff[fWordsSoFar];
856 Char_t* tmpchar = (Char_t*)&localbuff[
fWordsSoFar];
929 std::vector<Int_t> tmp_segments;
930 std::vector<Int_t> local_index;
933 tmp_segments.clear();
939 glob(searchpath.Data(), GLOB_ERR, NULL, &globbuf);
941 if (globbuf.gl_pathc == 1){
950 <<
" Trying to find run segments for run "
953 searchpath.Append(
".[0-9]*");
954 glob(searchpath.Data(), GLOB_ERR, NULL, &globbuf);
956 if (globbuf.gl_pathc == 0){
974 for (
size_t iloop=0;iloop<globbuf.gl_pathc;++iloop){
976 sscanf(globbuf.gl_pathv[iloop], scanvalue.Data(), &local_segment);
977 tmp_segments.push_back(local_segment);
979 local_index.resize(tmp_segments.size(),0);
982 TMath::Sort(static_cast<int>(tmp_segments.size()),&(tmp_segments[0]),&(local_index[0]),
988 for (
size_t iloop=0; iloop<tmp_segments.size(); ++iloop){
989 local_segment = tmp_segments[local_index[iloop]];
992 if (local_segment == 0 ||
1008 QwError <<
"First requested run segment "
1025 Int_t last_runsegment;
1030 QwMessage <<
"Closing run segment " << last_runsegment <<
"."
1070 status = CODA_ERROR;
1111 QwDebug <<
"QwEventBuffer::OpenDataFile: File handle doesn't exist.\n"
1112 <<
" Try to open a new file handle!"
1117 QwError <<
"QwEventBuffer::OpenDataFile: The stream is not configured as an input\n"
1118 <<
" file stream! Can't deal with this!\n"
1124 if (rw.Contains(
"w",TString::kIgnoreCase)) {
1131 glob(
fDataFile.Data(), GLOB_ERR, NULL, &globbuf);
1132 if (globbuf.gl_pathc == 0){
1135 glob(
fDataFile.Data(), GLOB_ERR, NULL, &globbuf);
1137 if (globbuf.gl_pathc == 0){
1140 glob(
fDataFile.Data(), GLOB_ERR, NULL, &globbuf);
1142 if (globbuf.gl_pathc == 0){
1145 glob(
fDataFile.Data(), GLOB_ERR, NULL, &globbuf);
1147 if (globbuf.gl_pathc == 1){
1152 << filename.Data() <<
" or "
1173 const TString stationname)
1175 Int_t status = CODA_OK;
1178 if (stationname !=
""){
1179 fEvStream =
new THaEtClient(computer, session, mode, stationname);
1181 fEvStream =
new THaEtClient(computer, session, mode);
void SetWordsSoFar(const ULong_t tmpwords)
enum QwEventBuffer::CodaStreamMode fEvStreamMode
QwParameterFile * fEventListFile
#define QwMessage
Predefined log drain for regular messages.
Bool_t DataFileIsSegmented()
Bool_t DecodeSubbankHeader(UInt_t *buffer)
Bool_t GetNextRunRange()
Read the next requested run range, return true if success.
Bool_t FillSubsystemConfigurationData(QwSubsystemArray &subsystems)
Definition of the pure virtual base class of all subsystems.
#define default_bool_value(b)
Int_t GetSegmentNumber() const
Return CODA file segment number.
void SetEventType(const UInt_t tmptype)
Int_t ProcessEvBuffer(const UInt_t event_type, const UInt_t roc_id, const UInt_t bank_id, UInt_t *buffer, UInt_t num_words)
Process the event buffer for events.
std::vector< Int_t > fRunSegments
void ProcessOptions(QwOptions &options)
Sets internal flags based on the QwOptions.
Int_t WriteFileEvent(int *buffer)
UInt_t fStartingPhysicsEvent
bool HasValue(const std::string &key)
Has this key been defined.
Int_t OpenNextStream()
Opens the event stream (file or ET) based on the internal flags.
UInt_t GetEventTypeMask() const
Get event type mask.
po::options_description_easy_init AddDefaultOptions()
Add a default option.
void SetCodaEventNumber(UInt_t evtnum)
Set the internal record of the CODA event number.
Int_t CloseStream()
Closes a currently open event stream.
std::pair< Int_t, Int_t > fRunRange
void TrimComment(const char commentchar)
void sigint_handler(int sig)
#define QwVerbose
Predefined log drain for verbose messages.
Int_t OpenETStream(TString computer, TString session, int mode, const TString stationname="")
void EncodeEventData(std::vector< UInt_t > &buffer)
Encode the data in this event.
Int_t OpenDataFile(UInt_t current_run, Short_t seg)
Bool_t GetNextEventRange()
Read the next requested event range, return true if success.
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
void SetCleanParameters(Double_t cleanparameter[3])
Set the internal record of the CODA event number.
QwParameterFile * ReadNextSection(std::string &secname, const bool keep_header=false)
void ExtractEPICSValues(const string &data, int event)
std::string fRunListFileName
T GetValue(const std::string &key)
Get a templated value.
void ProcessPause(UInt_t local_time, UInt_t evt_count)
Int_t EncodePrestartEvent(int runnumber, int runtype=0)
void SetCodaRunNumber(UInt_t runnum)
Set the internal record of the CODA run number.
Double_t fCleanParameter[3]
Scan data/clean data from the green monster.
std::pair< int, int > GetIntValuePair(const std::string &key)
Get a pair of integer values.
TString fDataFileExtension
#define QwDebug
Predefined log drain for debugging output.
static const UInt_t kNullDataWord
void ProcessControlEvent(UInt_t evtype, UInt_t *buffer)
void DecodeEventIDBank(UInt_t *buffer)
Int_t WriteEvent(int *buffer)
QwParameterFile * fRunListFile
QwEventBuffer()
Default constructor.
Int_t EncodeSubsystemData(QwSubsystemArray &subsystems)
void SetEventLength(const ULong_t tmplength)
Int_t GetRunNumber() const
Return CODA file run number.
static std::string fDefaultDataFileStem
std::vector< Int_t >::iterator fRunSegmentIterator
static void DefineOptions(QwOptions &options)
std::pair< Int_t, Int_t > fSegmentRange
static std::pair< int, int > ParseIntRange(const std::string &separatorchars, const std::string &range)
Parse a range of integers as #:# where either can be missing.
void ProcessPrestart(UInt_t local_time, UInt_t local_runnumber, UInt_t local_runtype)
TStopwatch fRunTimer
Timer used for runlet processing loop.
static const Int_t kNoNextDataFile
static const Int_t kFileHandleNotConfigured
Bool_t FillSubsystemData(QwSubsystemArray &subsystems)
Int_t ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t *buffer, UInt_t num_words)
Process the event buffer for configuration events.
static std::string fDefaultDataFileExtension
void ProcessGo(UInt_t local_time, UInt_t evt_count)
static std::ostream & endl(std::ostream &)
End of the line.
An options class which parses command line, config file and environment.
TString GetRunLabel() const
Returns a string like <run#> or <run#>.<file#>
Bool_t FillEPICSData(QwEPICSEvent &epics)
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
void SetCodaEventType(UInt_t evttype)
Set the internal record of the CODA event type.
#define QwWarning
Predefined log drain for warnings.
std::pair< UInt_t, UInt_t > fEventRange
void SetCodaSegmentNumber(UInt_t segnum)
Set the internal record of the CODA segment number.
UInt_t fEvtNumber
CODA event number; only defined for physics events.
void ProcessEnd(UInt_t local_time, UInt_t evt_count)
const TString & DataFile(const UInt_t run, const Short_t seg)
Bool_t GetNextRunNumber()
Get the next run in the active run range, proceed to next range if needed.
static const Int_t kRunNotSegmented
TStopwatch fStopwatch
Timer used for internal timing.
#define QwError
Predefined log drain for errors.