RdEventAndStationSelector.cc
Go to the documentation of this file.
1 // version $Id: RdEventAndStationSelector.cc 32946 2019-09-19 15:35:43Z gottowik $
2 
4 #include <fwk/CentralConfig.h>
5 #include <det/VManager.h>
6 #include <det/Detector.h>
7 #include <rdet/RDetector.h>
8 
9 #include <utl/Branch.h>
10 #include <utl/ErrorLogger.h>
11 #include <utl/String.h>
12 #include <utl/RadioGeometryUtilities.h>
13 #include <utl/Vector.h>
14 #include <utl/Point.h>
15 
16 #include <evt/ShowerRRecData.h>
17 #include <evt/ShowerSRecData.h>
18 #include <evt/ShowerFRecData.h>
19 #include <evt/ShowerRecData.h>
20 #include <evt/ShowerSimData.h>
21 
22 #include <evt/Event.h>
23 #include <revt/REvent.h>
24 #include <revt/Header.h>
25 #include <revt/StationConstants.h>
26 #include <revt/StationRecData.h>
27 
28 #include <sstream>
29 #include <algorithm>
30 #include <vector>
31 
32 using namespace std;
33 using namespace fwk;
34 
35 
37 
40  {
41  utl::Branch topB = CentralConfig::GetInstance()->GetTopBranch("RdEventAndStationSelector");
42  topB.GetChild("InfoLevel").GetData(fInfoLevel);
43  topB.GetChild("filename").GetData(fFilename);
44 
45  fstream fin;
46  const int MAX_CHARS_PER_LINE = 512;
47  char line[MAX_CHARS_PER_LINE];
48  fin.open(fFilename.c_str(), ios::in); // opening data
49  //fin.getline(line, MAX_CHARS_PER_LINE); // read/skip first line
50  stringstream sstr;
51  sstr.str("");
52  sstr << "loop through file... filename = " << fFilename;
53  INFODebug(sstr.str());
54 
55  if (!fin.good()) {
56  WARNING("File could not be opened");
57  return eFailure;
58  }
59  while (fin.good()) {
60  stringstream output;
61  fin.getline(line, MAX_CHARS_PER_LINE);
62  stringstream tmp_sstr;
63  tmp_sstr << line;
64  std::string segment;
65  if (!std::getline(tmp_sstr, segment, '\t')) {
66  break;
67  }
68  int runNumber = atoi(segment.c_str());
69  std::getline(tmp_sstr, segment, '\t');
70  int eventId = atoi(segment.c_str());
71  std::vector<int> tmp_station_ids;
72  output << "Event " << runNumber << "_" << eventId << ": ";
73  while (std::getline(tmp_sstr, segment, '\t')) {
74  tmp_station_ids.push_back(atoi(segment.c_str()));
75  output << atoi(segment.c_str()) << " ";
76  }
77  std::pair<int, int> event_identifier(runNumber, eventId);
78  fEventSelection[event_identifier] = tmp_station_ids;
79 
80  INFOIntermediate(output.str());
81  }
82  fin.close();
83 
84  return eSuccess;
85  }
86 
87 
89  RdEventAndStationSelector::Run(evt::Event& event)
90  {
91  stringstream sstr;
92  INFODebug(sstr.str());
93  if (!event.HasREvent()) {
94  WARNING("No REvent");
95  return eBreakLoop;
96  }
97  revt::REvent& rEvent = event.GetREvent();
98  int runNumber = rEvent.GetHeader().GetRunNumber();
99  int eventId = rEvent.GetHeader().GetId();
100  std::pair<int, int> event_identifier(runNumber, eventId);
101 
102  if (fEventSelection.find(event_identifier) == fEventSelection.end()) {
103  sstr.str("");
104  sstr << "Event " << event_identifier.first << "_" << event_identifier.second
105  << " not present in selection, event will be skipped";
106  INFOIntermediate(sstr.str());
107  return eContinueLoop;
108  }
109 
110  for (revt::REvent::StationIterator sIt = rEvent.StationsBegin(); sIt != rEvent.StationsEnd(); ++sIt) {
111  const int stationId = sIt->GetId();
112  std::vector<int> stationList = fEventSelection[event_identifier];
113  std::vector<int>::iterator it = std::find(stationList.begin(), stationList.end(), stationId);
114  if (it == stationList.end()) {
115  sIt->SetRejected(revt::eManuallyRejected);
116  sstr.str("");
117  sstr << "station " << sIt->GetId() << " will be rejected";
118  INFOIntermediate(sstr.str());
119  }
120  }
121 
122  return eSuccess;
123  }
124 
125 
127  RdEventAndStationSelector::Finish()
128  {
129  return eSuccess;
130  }
131 
132 }
Branch GetTopBranch() const
Definition: Branch.cc:63
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
StationIterator StationsEnd()
Definition: REvent.h:130
StationIterator StationsBegin()
Definition: REvent.h:128
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
boost::filter_iterator< StationFilter, AllStationIterator > StationIterator
Iterator over all (non-exculded) stations.
Definition: REvent.h:125
bool HasREvent() const
#define INFOIntermediate(y)
Definition: VModule.h:162
Class representing a document branch.
Definition: Branch.h:107
Header & GetHeader()
access to REvent Header
Definition: REvent.h:239
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
#define INFODebug(y)
Definition: VModule.h:163
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
int GetRunNumber() const
Event id in the run (Start at zero at the beginning of each run) /provided by the daq...
Definition: REvent/Header.h:22
int GetId() const
Definition: REvent/Header.h:21

, generated on Tue Sep 26 2023.