GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
GGSNameDecoder.cpp
Go to the documentation of this file.
1 /*
2  * GGSNameDecoder.cpp
3  *
4  * Created on: 2010-10-06
5  * Author: Emiliano Mocchiutti
6  */
7 
10 #include "utils/GGSNameDecoder.h"
11 
12 #include <cstring>
13 #include <stdio.h>
14 #include <stdlib.h>
15 
17  static GGSNameDecoder instance;
18  return instance;
19 }
20 
21 GGSNameDecoder::GGSNameDecoder() {}
22 
23 GGSNameDecoder::~GGSNameDecoder() {}
24 
25 int GGSNameDecoder::GetHitType(const std::string &volumeName) {
26  if (!IsSensitive(volumeName)) {
27  return -1;
28  }
29  int hitType;
30  if (sscanf(volumeName.c_str(), "%*4cH%dE", &hitType) == 1) {
31  return hitType;
32  }
33  return -1;
34 }
35 
36 bool GGSNameDecoder::IsSensitive(const std::string &volumeName) {
37  if (volumeName.length() != 7)
38  return false;
39 
40  int hitType;
41  if (sscanf(volumeName.c_str(), "%*4cH%dE", &hitType) == 1) {
42  return true;
43  } else {
44  return false;
45  }
46 }
47 
48 const std::string &GGSNameDecoder::GetDetectorName(const std::string &volumeName) {
49  static std::string returnValue;
50  if (!IsSensitive(volumeName)) {
51  returnValue = "";
52  } else {
53  returnValue = volumeName.substr(0, 4);
54  }
55 
56  return returnValue;
57 }
const std::string & GetDetectorName(const std::string &volumeName)
Get detector name.
int GetHitType(const std::string &volumeName)
Get hit type.
static GGSNameDecoder & GetInstance()
Get instance of the singleton.
bool IsSensitive(const std::string &volumeName)
Check if the logical volume is sensitive.
Class needed to decode sensitive volume names.