23 std::cout <<
"handling signal no. " << sig <<
" ";
24 std::cout <<
"(press ctrl-\\ to abort now)\n";
29 std::cout <<
"handling signal no. " << sig <<
"\n";
30 std::cout <<
"Restarts the event loop in online mode." << std::endl;
34#include "THaCodaFile.h"
36#include "THaEtClient.h"
89 (
"online", po::value<bool>()->default_bool_value(
false),
90 "use online data stream");
92 (
"online.RunNumber", po::value<int>()->default_bool_value(0),
93 "Effective run number to be used by online system to find the parameter files");
95 (
"run,r", po::value<string>()->default_value(
"0:0"),
96 "run range in format #[:#]");
99 "data directory, also $QW_DATA");
101 (
"runlist", po::value<string>()->default_value(
""),
102 "run list file name");
104 (
"event,e", po::value<string>()->default_value(
"0:"),
105 "event range in format #[:#]");
107 (
"segment,s", po::value<string>()->default_value(
"0:"),
108 "run segment range in format #[:#]");
110 (
"chainfiles", po::value<bool>()->default_bool_value(
false),
111 "chain file segments together, do not analyze them separately");
114 "stem of the input CODA filename");
117 "extension of the input CODA filename");
119 (
"directfile", po::value<string>(),
120 "Run over single event file");
123 (
"allow-low-subbank-ids", po::value<bool>()->default_bool_value(
false),
124 "allow the sub-bank ids to be 31 or less, when using this flag, all ROCs must be sub-banked");
127 (
"ET.hostname", po::value<string>(),
128 "Name of the ET session's host machine --- Only used in online mode\nDefaults to the environment variable $HOSTNAME");
130 (
"ET.session", po::value<string>(),
131 "ET session name --- Only used in online mode\nDefaults to the environment variable $SESSION");
133 (
"ET.station", po::value<string>(),
134 "ET station name --- Only used in online mode");
136 (
"ET.waitmode", po::value<int>()->default_value(0),
137 "ET system wait mode: 0 is wait-forever, 1 is timeout \"quickly\" --- Only used in online mode");
139 (
"ET.exit-on-end", po::value<bool>()->default_value(
false),
140 "Exit the event loop if the end event is found. JAPAN remains open and waits for the next run. --- Only used in online mode");
142 (
"coda-version", po::value<int>()->default_value(3),
143 "Sets the Coda Version. Allowed values = {2,3}. \nThis is needed for writing and reading mock data. Mock data needs to be written and read with the same Coda Version.");
153 QwError <<
"Online mode will not work without the CODA libraries!"
157 if (options.
HasValue(
"online.RunNumber")) {
160 if (options.
HasValue(
"ET.station")) {
165 if (options.
HasValue(
"ET.hostname")) {
170 if (options.
HasValue(
"ET.session")) {
178 tmp +=
" \"HOSTNAME\"";
180 if (tmp.Length() > 0)
182 tmp +=
" ET \"SESSION\"";
185 <<
" variable(s) is(are) not defined in your environment.\n"
186 <<
" This is needed to run the online analysis."
200 QwError <<
"ERROR: Can't get the data directory in the QwEventBuffer creator."
220 QwError <<
"Invalid Coda Version. Only versions 2 and 3 are supported. "
221 <<
"Please set using --coda-version 2(3)" <<
QwLog::endl;
225 decoder->SetAllowLowSubbankIDs( options.
GetValue<
bool>(
"allow-low-subbank-ids") );
260 if (nevents==0) nevents=1;
264 <<
"CPU time used: " <<
fRunTimer.CpuTime() <<
" s "
266 <<
"Real time used: " <<
fRunTimer.RealTime() <<
" s "
277 std::string eventrange;
297 std::string runrange;
305 QwWarning <<
"No valid event range in run list file: "
307 <<
"Assuming the full event range." <<
QwLog::endl;
344 Int_t status = CODA_ERROR;
365 Int_t status = CODA_ERROR;
375 QwMessage <<
"Try to open the ET station with HOSTNAME=="
390 if (status == CODA_ERROR){
393 QwError <<
"ERROR: Unable to find data files for run "
438 Int_t status = CODA_OK;
461 if (
decoder->GetEvtNumber() > 1000) status = EOF;
478 }
while (status == CODA_OK &&
492 QwMessage << efficiency <<
"% efficiency)";
496 }
else if (
decoder->GetEvtNumber() > 0 &&
decoder->GetEvtNumber() % 100 == 0) {
513 if (status == CODA_OK){
515 UInt_t* evBuffer = (UInt_t*)
fEvStream->getEvBuffer();
519 decoder->DecodeEventIDBank(evBuffer);
531 if(buffer[0] == 0)
return;
532 UInt_t header = buffer[1];
533 int top = (header & 0xff000000) >> 24;
534 int bot = (header & 0xff );
536 if( (top == 0xff) && (bot != 0xcc) ){
538 }
else if( (top != 0xff) && (bot == 0xcc) ){
545 <<
", but it looks like the data is from Coda Version "
555 Int_t status = CODA_OK;
573 Int_t status = CODA_OK;
577 if (status != CODA_OK) {
599 Int_t status = CODA_OK;
602 status = ((THaCodaFile*)
fEvStream)->codaWrite((UInt_t*) buffer);
610 std::vector<UInt_t> buffer;
611 std::vector<ROCID_t> ROCList;
615 std::vector<UInt_t> header =
decoder->EncodePHYSEventHeader(ROCList);
620 int* codabuffer =
new int[header.size() + buffer.size() + 1];
623 codabuffer[k++] = header.size() + buffer.size();
624 for (
size_t i = 0; i < header.size(); i++)
625 codabuffer[k++] = header.at(i);
626 for (
size_t i = 0; i < buffer.size(); i++)
627 codabuffer[k++] = buffer.at(i);
640 decoder->ResetControlParameters();
649 return decoder->GetStartSQLTime();
654 return decoder->GetEndSQLTime();
659 return decoder->GetStartUnixTime();
664 return decoder->GetEndUnixTime();
670 int localtime = (int)time(0);
671 decoder->EncodePrestartEventHeader(buffer, runnumber, runtype, localtime);
677 int localtime = (int)time(0);
679 decoder->EncodeGoEventHeader(buffer, eventcount, localtime);
685 int localtime = (int)time(0);
687 decoder->EncodePauseEventHeader(buffer, eventcount, localtime);
693 int localtime = (int)time(0);
695 decoder->EncodeEndEventHeader(buffer, eventcount, localtime);
712 UInt_t rocnum =
decoder->GetEvtType() - 0x90;
713 QwMessage <<
"QwEventBuffer::FillSubsystemConfigurationData: "
714 <<
"Found configuration event for ROC"
719 UInt_t *localbuff = (UInt_t*)(
fEvStream->getEvBuffer());
720 decoder->DecodeEventIDBank(localbuff);
721 while ((okay =
decoder->DecodeSubbankHeader(&localbuff[
decoder->GetWordsSoFar()]))){
723 if (
decoder->GetSubbankType() == 0x10) {
730 decoder->AddWordsSoFarAndFragLength();
744 &localbuff[
decoder->GetWordsSoFar()],
746 decoder->AddWordsSoFarAndFragLength();
747 QwDebug <<
"QwEventBuffer::FillSubsystemConfigurationData: "
748 <<
"Ending loop: fWordsSoFar=="<<
decoder->GetWordsSoFar()
762 UInt_t *localbuff = (UInt_t*)(
fEvStream->getEvBuffer());
764 decoder->DecodeEventIDBank(localbuff);
783 while ((okay =
decoder->DecodeSubbankHeader(&localbuff[
decoder->GetWordsSoFar()]))){
786 if (
decoder->GetSubbankType() == 0x10)
continue;
791 decoder->AddWordsSoFarAndFragLength();
831 for (
size_t i=0; i<nmarkers; i++){
834 tmpbank = ((tmpbank)<<32) +
decoder->GetSubbankTag();
837 &localbuff[
decoder->GetWordsSoFar()+offset],
838 decoder->GetFragLength()-offset);
841 QwDebug <<
"QwEventBuffer::FillSubsystemData: "
842 <<
"fROC=="<<
decoder->GetROC() <<
", GetSubbankTag()==" <<
decoder->GetSubbankTag()
845 &localbuff[
decoder->GetWordsSoFar()],
848 decoder->AddWordsSoFarAndFragLength();
876 QwVerbose <<
"QwEventBuffer::FillEPICSData: "
879 UInt_t *localbuff = (UInt_t*)(
fEvStream->getEvBuffer());
880 if (
decoder->GetBankDataType()==0x10){
881 while ((okay =
decoder->DecodeSubbankHeader(&localbuff[
decoder->GetWordsSoFar()]))){
883 if (
decoder->GetSubbankType() == 0x10)
continue;
887 decoder->AddWordsSoFarAndFragLength();
891 if (
decoder->GetSubbankType() == 0x3){
894 char* tmpchar = (Char_t*)&localbuff[
decoder->GetWordsSoFar()];
902 decoder->AddWordsSoFarAndFragLength();
913 if (
decoder->GetBankDataType() == 0x3){
916 Char_t* tmpchar = (Char_t*)&localbuff[
decoder->GetWordsSoFar()];
927 QwVerbose <<
"QwEventBuffer::FillEPICSData: End of routine"
954 std::vector<Int_t> tmp_segments;
955 std::vector<Int_t> local_index;
958 tmp_segments.clear();
964 glob(searchpath.Data(), GLOB_ERR, NULL, &globbuf);
970 }
else if (globbuf.gl_pathc == 1){
979 <<
" Trying to find run segments for run "
982 searchpath.Append(
".[0-9]*");
983 glob(searchpath.Data(), GLOB_ERR, NULL, &globbuf);
985 if (globbuf.gl_pathc == 0){
1003 for (
size_t iloop=0;iloop<globbuf.gl_pathc;++iloop){
1005 sscanf(globbuf.gl_pathv[iloop], scanvalue.Data(), &local_segment);
1006 tmp_segments.push_back(local_segment);
1008 local_index.resize(tmp_segments.size(),0);
1011 TMath::Sort(
static_cast<int>(tmp_segments.size()),&(tmp_segments[0]),&(local_index[0]),
1017 for (
size_t iloop=0; iloop<tmp_segments.size(); ++iloop){
1018 local_segment = tmp_segments[local_index[iloop]];
1021 if (local_segment == 0 ||
1037 QwError <<
"First requested run segment "
1054 Int_t last_runsegment;
1059 QwMessage <<
"Closing run segment " << last_runsegment <<
"."
1099 status = CODA_ERROR;
1140 QwDebug <<
"QwEventBuffer::OpenDataFile: File handle doesn't exist.\n"
1141 <<
" Try to open a new file handle!"
1146 QwError <<
"QwEventBuffer::OpenDataFile: The stream is not configured as an input\n"
1147 <<
" file stream! Can't deal with this!\n"
1153 if (rw.Contains(
"w",TString::kIgnoreCase)) {
1160 glob(
fDataFile.Data(), GLOB_ERR, NULL, &globbuf);
1161 if (globbuf.gl_pathc == 0){
1164 glob(
fDataFile.Data(), GLOB_ERR, NULL, &globbuf);
1166 if (globbuf.gl_pathc == 0){
1169 glob(
fDataFile.Data(), GLOB_ERR, NULL, &globbuf);
1171 if (globbuf.gl_pathc == 0){
1174 glob(
fDataFile.Data(), GLOB_ERR, NULL, &globbuf);
1176 if (globbuf.gl_pathc == 1){
1181 << filename.Data() <<
" or "
1202 const TString stationname)
1204 Int_t status = CODA_OK;
1207 if (stationname !=
""){
1208 fEvStream =
new THaEtClient(computer, session, mode, stationname.Data());
1210 fEvStream =
new THaEtClient(computer, session, mode);
1236 std::vector<UInt_t> tmpvec;
1241 QwDebug <<
"QwEventBuffer::GetMarkerWordList: fMarkerList.count(fThisRocBankLabel)=="
1243 <<
" fMarkerList.at(fThisRocBankLabel).size()=="
1257 if (markerpos < num_words && buffer[markerpos] == markerval){
1261 for (
size_t i=0; i<num_words; i++){
1262 if (buffer[i] == markerval){
Definition of the pure virtual base class of all subsystems.
An options class which parses command line, config file and environment.
#define QwVerbose
Predefined log drain for verbose messages.
#define QwError
Predefined log drain for errors.
#define QwWarning
Predefined log drain for warnings.
#define QwMessage
Predefined log drain for regular messages.
#define QwDebug
Predefined log drain for debugging output.
Array container for managing multiple subsystems.
EPICS data event handling and storage.
Event buffer management for reading and processing CODA data.
void sigint_handler(int sig)
void sigusr_handler(int sig)
CODA version 2 event decoder implementation.
CODA version 3 event decoder implementation.
EPICS slow controls data management.
void ExtractEPICSValues(const string &data, int event)
TString GetRunLabel() const
Returns a string like <run#> or <run#>.<file#>
Int_t EncodeSubsystemData(QwSubsystemArray &subsystems)
static const Int_t kRunNotSegmented
time_t GetStartUnixTime()
UInt_t fStartingPhysicsEvent
static std::string fDefaultDataDirectory
std::unordered_map< RocBankLabel_t, std::vector< UInt_t > > fMarkerList
enum QwEventBuffer::CodaStreamMode fEvStreamMode
Int_t CloseStream()
Closes a currently open event stream.
Int_t OpenETStream(TString computer, TString session, int mode, const TString stationname="")
Bool_t GetNextRunRange()
Read the next requested run range, return true if success.
Int_t EncodePrestartEvent(int runnumber, int runtype=0)
QwEventBuffer()
Default constructor.
void VerifyCodaVersion(const UInt_t *buffer)
Int_t WriteFileEvent(int *buffer)
Int_t OpenNextStream()
Opens the event stream (file or ET) based on the internal flags.
static const Int_t kFileHandleNotConfigured
std::vector< Int_t >::iterator fRunSegmentIterator
void ProcessOptions(QwOptions &options)
Sets internal flags based on the QwOptions.
Bool_t FillSubsystemData(QwSubsystemArray &subsystems)
TStopwatch fStopwatch
Timer used for internal timing.
Int_t WriteEvent(int *buffer)
Int_t GetSegmentNumber() const
Return CODA file segment number.
std::unique_ptr< QwParameterFile > fEventListFile
void ResetControlParameters()
const TString & DataFile(const UInt_t run, const Short_t seg)
TString GetStartSQLTime()
static void DefineOptions(QwOptions &options)
std::unordered_map< RocBankLabel_t, std::vector< UInt_t > > fOffsetList
Double_t fCleanParameter[3]
Scan data/clean data from the green monster.
UInt_t FindMarkerWord(UInt_t markerID, UInt_t *buffer, UInt_t num_words)
TString fDataFileExtension
Int_t GetRunNumber() const
Return CODA file run number.
static const UInt_t kNullDataWord
static const Int_t kNoNextDataFile
RocBankLabel_t fThisRocBankLabel
Bool_t GetNextEventRange()
Read the next requested event range, return true if success.
Bool_t DataFileIsSegmented()
std::pair< Int_t, Int_t > fRunRange
std::pair< UInt_t, UInt_t > fEventRange
Int_t OpenDataFile(UInt_t current_run, Short_t seg)
static std::string fDefaultDataFileExtension
std::string fRunListFileName
TStopwatch fRunTimer
Timer used for runlet processing loop.
static std::string fDefaultDataFileStem
Bool_t GetNextRunNumber()
Get the next run in the active run range, proceed to next range if needed.
Bool_t FillEPICSData(QwEPICSEvent &epics)
std::pair< Int_t, Int_t > fSegmentRange
std::unique_ptr< QwParameterFile > fRunListFile
std::size_t CheckForMarkerWords(QwSubsystemArray &subsystems)
std::vector< Int_t > fRunSegments
Bool_t FillSubsystemConfigurationData(QwSubsystemArray &subsystems)
UInt_t GetMarkerWord(UInt_t markerID)
static std::ostream & endl(std::ostream &)
End of the line.
Command-line and configuration file options processor.
std::pair< int, int > GetIntValuePair(const std::string &key)
Get a pair of integer values.
po::options_description_easy_init AddDefaultOptions()
Add a default option.
T GetValue(const std::string &key)
Get a templated value.
bool HasValue(const std::string &key)
Has this key been defined.
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
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.
Container for managing multiple subsystems with common operations.
void SetCodaRunNumber(UInt_t runnum)
Set the internal record of the CODA run number.
void SetCleanParameters(Double_t cleanparameter[3])
Set the internal record of the CODA event number.
UInt_t GetEventTypeMask() const
Get event type mask.
void GetMarkerWordList(const ROCID_t roc_id, const BankID_t bank_id, std::vector< UInt_t > &marker) const
void EncodeEventData(std::vector< UInt_t > &buffer)
Encode the data in this event.
void SetCodaSegmentNumber(UInt_t segnum)
Set the internal record of the CODA segment number.
Int_t ProcessEvBuffer(const UInt_t event_type, const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words)
Process the event buffer for events.
void SetCodaEventNumber(UInt_t evtnum)
Set the internal record of the CODA event number.
void SetCodaEventType(UInt_t evttype)
Set the internal record of the CODA event type.
Int_t ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words)
Process the event buffer for configuration events.
void GetROCIDList(std::vector< ROCID_t > &list)
Get the ROCID list.