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