30 string str =
"For more information, go to https://github.com/JeffersonLab/HDEventStore/wiki";
59 grade =
"recon-unchecked";
72 if(getenv(
"EVENTSTORE_CONNECTION") != NULL)
75 "Specification of EventStore DB connection.");
77 int test_mode_flag = 0;
78 gPARMS->SetDefaultParameter(
"ESDB:TEST_MODE", test_mode_flag,
79 "Toggle test mode features");
80 if(test_mode_flag != 0) {
83 gRandom =
new TRandom3(0);
90 string es_query(source_name);
91 istringstream iss(es_query);
92 vector<string> tokens;
93 copy(istream_iterator<string>(iss),
94 istream_iterator<string>(),
95 back_inserter(tokens));
101 cout <<
"MySQL connection" << endl;
104 cout <<
"SQLite connection" << endl;
113 if( (tokens[0] !=
"eventstore") || tokens.size() < 3)
116 if( (tokens[1] ==
"in") ) {
119 if(tokens.size() > 3) {
121 size_t token_ind = 3;
124 grade = tokens[token_ind++];
126 while(token_ind < tokens.size()) {
127 if(tokens[token_ind] ==
"runs") {
129 throw JException(
"Cannot set run range and run period in the same command!");
132 if(tokens.size() - token_ind < 3)
135 min_run = atoi(tokens[token_ind+1].c_str());
136 max_run = atoi(tokens[token_ind+2].c_str());
140 throw JException(
"Maximum run must be larger than minimum run!");
143 }
else if(tokens[token_ind] ==
"run_period") {
145 throw JException(
"Cannot set run range and run period in the same command!");
148 if(tokens.size() - token_ind < 2)
151 map< string, pair<int,int> >::iterator run_period_itr = run_period_map.find(tokens[token_ind+1]);
152 if(run_period_itr == run_period_map.end()) {
155 throw JException(
"Invalid ES query = " + es_query +
"\n");
157 min_run = run_period_itr->second.first;
158 max_run = run_period_itr->second.second;
160 }
else if(tokens[token_ind] ==
"skims") {
163 while(token_ind++ < tokens.size()) {
169 throw JException(
"Too many skims specified!!");
178 vector<string> grades_in_db;
181 vector<string>::iterator grade_itr = find(grades_in_db.begin(), grades_in_db.end(),
grade);
182 if(grade_itr == grades_in_db.end()) {
183 jerr <<
"Could not find grade \'" <<
grade <<
"\' in DB!" << endl;
185 throw JException(
"Invalid ES query = " + es_query +
"\n");
199 }
else if( (tokens[1] ==
"info") ) {
205 if(tokens[2] ==
"grades") {
209 }
else if(tokens[2] ==
"run_periods") {
213 }
else if(tokens[2] ==
"skims") {
214 if(tokens.size() < 5)
215 throw JException(
"Invalid query: skims <datestamp> <grade>" );
269 event.SetEventNumber(1);
270 event.SetRunNumber(10000);
271 event.SetJEventSource(
this);
277 event.SetRef(the_es_event);
278 for(
int i=0; i<4; i++)
279 if(gRandom->Uniform() < 0.5)
289 return NO_MORE_EVENTS_IN_SOURCE;
298 if(retval == NOERROR) {
304 event.SetRef(the_es_event);
310 }
else if(retval == NO_MORE_EVENTS_IN_SOURCE) {
341 if(!factory)
throw RESOURCE_UNAVAILABLE;
344 string dataClassName = factory->GetDataClassName();
346 if (dataClassName ==
"DESSkimData") {
347 JFactory<DESSkimData> *essd_factory =
dynamic_cast<JFactory<DESSkimData>*
>(factory);
352 vector<DESSkimData*> skim_data_vec(1, skim_data);
353 essd_factory->CopyTo(skim_data_vec);
365 jerror_t retval =
event_source->GetObjects(event, factory);
367 event.SetRef(the_es_event);
394 jerr <<
"Could not load any files from EventStore!" << endl;
395 return NO_MORE_EVENT_SOURCES;
411 vector<JEventSourceGenerator*> locEventSourceGenerators =
japp->GetEventSourceGenerators();
424 JEventSourceGenerator* locEventSourceGenerator = NULL;
425 double liklihood = 0.0;
427 for(
unsigned int i=0; i<locEventSourceGenerators.size(); i++)
429 double my_liklihood = locEventSourceGenerators[i]->CheckOpenable(locFileName);
430 if(my_liklihood > liklihood)
432 liklihood = my_liklihood;
433 locEventSourceGenerator = locEventSourceGenerators[i];
437 if(locEventSourceGenerator != NULL)
439 jout<<
"Opening source \""<<locFileName<<
"\" of type: "<<locEventSourceGenerator->Description()<<endl;
440 event_source = locEventSourceGenerator->MakeJEventSource(locFileName);
445 jerr<<
" xxxxxxxxxxxx Unable to open event source \""<<locFileName<<
"\"! xxxxxxxxxxxx"<<endl;
453 return NO_MORE_EVENT_SOURCES;
463 vector<string> grades;
467 cout << endl <<
"Available grades:" << endl;
468 for(vector<string>::iterator it = grades.begin();
469 it != grades.end(); it++)
470 cout <<
" " << *it << endl;
479 vector<string> grades;
483 cout << endl <<
"Available Run Periods:" << endl;
484 for(map<
string, pair<int,int> >::iterator it =
run_period_map.begin();
486 pair<int,int> &the_run_range = it->second;
487 cout <<
" " << it->first <<
": "
488 << the_run_range.first <<
" - " << the_run_range.second << endl;
498 vector<string> skims;
502 cout << endl <<
"Available skims for grade " << grade <<
":" << endl;
503 for(vector<string>::iterator it = skims.begin();
504 it != skims.end(); it++)
505 cout <<
" " << *it << endl;
map< string, pair< int, int > > run_period_map
vector< string >::iterator current_file_itr
jerror_t MoveToNextEvent()
jerror_t GetObjects(JEvent &event, JFactory_base *factory)
vector< string > skim_list
void PrintSkims(string timestamp, string grade)
virtual bool GetSkims(vector< string > &grades, string timestamp, string grade)=0
JEventSource * event_source
static string EventstoreQueryHelp()
vector< string > data_files
jerror_t GetEvent(JEvent &event)
virtual bool GetGrades(vector< string > &grades)=0
void Set_EventSource(JEventSource *locEventSource)
void FreeEvent(JEvent &event)
virtual ~DEventSourceEventStore()
void Set_SourceRef(void *locSourceRef)
void Add_Skim(string locSkim)
DEventSourceEventStore(const char *source_name)
void * Get_SourceRef(void) const