Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEventSourceRESTGenerator.cc
Go to the documentation of this file.
1 //
2 // Author: Richard Jones June 29, 2012
3 //
4 //
5 // DEventSourceRESTGenerator methods
6 //
7 
8 #include <string>
9 using std::string;
10 
12 #include "DEventSourceREST.h"
13 
14 //---------------------------------
15 // Description
16 //---------------------------------
18 {
19  return "REST";
20 }
21 
22 //---------------------------------
23 // CheckOpenable
24 //---------------------------------
26 {
27  // Restrict HDDM files to having a ".hddm" suffix
28  string suffix = ".hddm";
29  if(source.length() < suffix.length()) return 0.0;
30  if(source.substr(source.length() - suffix.length()) != suffix) return 0.0;
31 
32  ifstream ifs(source.c_str());
33  if (!ifs.good()) {
34  return 0.0;
35  }
36  //
37  // At this point we know we can open the input stream for reading,
38  // but we cannot be sure that the contents are actually a valid
39  // hddm class "s" data stream. Problem is, if we read the first
40  // few bytes from the stream to check for the hddm header string,
41  // and is coming from a pipe, then we discard forever the header
42  // bytes and the stream will not be valid if later we decide to
43  // actually open a DEventSourceREST object on it. The best we
44  // can do is to look for clues in the filename and guess.
45 
46  if (source.find("_rest") != source.npos ||
47  source.find("rest_") != source.npos)
48  {
49  return 0.90;
50  }
51  else if (source.find("hdgeant") != source.npos)
52  {
53  return 0.10;
54  }
55  else if (source.find("_smeared") != source.npos ||
56  source.find("smeared_") != source.npos)
57  {
58  return 0.15;
59  }
60  else if (source.find("_events") != source.npos ||
61  source.find("events_") != source.npos)
62  {
63  return 0.25;
64  }
65  return 0.5;
66 }
67 
68 //---------------------------------
69 // MakeJEventSource
70 //---------------------------------
72 {
73  return new DEventSourceREST(source.c_str());
74 }
char string[256]
jana::JEventSource * MakeJEventSource(std::string source)
double CheckOpenable(std::string source)
Implements JEventSource for REST files.