1 #include "ERDigibuilder.h" 7 #include "TTreeCache.h" 9 #include "FairRootManager.h" 11 #include "FairLogger.h" 13 #include "DetEventFull.h" 14 #include "DetEventDetector.h" 15 #include "DetEventStation.h" 16 #include "DetMessage.h" 17 #include "DetEventCommon.h" 18 #include "TGo4EventElement.h" 20 #include "ERBeamTimeEventHeader.h" 23 ERDigibuilder::ERDigibuilder()
24 : input_chain_of_events_(
"accdaq")
27 ERDigibuilder::ERDigibuilder(
const TString& tree_name)
28 : input_chain_of_events_(tree_name)
31 void ERDigibuilder::AddFile(
const TString& path) {
32 input_chain_of_events_.Add(path);
33 if (!setup_configuration_) {
35 std::cerr << setup_configuration_ << std::endl;
36 setup_configuration_ =
dynamic_cast<SetupConfiguration*
>(file.Get(
"SetupConfiguration"));
37 std::cerr << setup_configuration_ << std::endl;
38 if (!setup_configuration_)
39 LOG(FATAL) <<
"Cannot load setup configuration from file " << path << FairLogger::endl;
43 Bool_t ERDigibuilder::Init() {
44 if (input_chain_of_events_.GetEntriesFast() == 0)
45 LOG(FATAL) <<
"No events for processing in source ERDigibuilder" << FairLogger::endl;
53 Bool_t ERDigibuilder::InitUnpackers(){
54 const std::map<TString, unsigned short> detectors = setup_configuration_->GetDetectorList();
55 for (
const auto& detector : detectors) {
56 const auto detector_name = detector.first;
57 if (unpacks_.find(detector_name) != unpacks_.end()) {
58 unpacks_[detector_name]->Init(setup_configuration_, input_chain_of_events_);
60 LOG(WARNING) <<
"[Digibuilder] " << detector_name <<
" is defined in setup " 61 <<
"configuration, but unpacker is not added!" << FairLogger::endl;
64 for (
const auto& detector_name_and_unpack : unpacks_) {
65 const auto& detector_name = detector_name_and_unpack.first;
66 const auto& unpack = detector_name_and_unpack.second;
67 if (!unpack->IsInited()) {
68 LOG(WARNING) <<
"[Digibuilder] Detector " << detector_name <<
" not found in setup file. " 69 <<
"Unpacker has not inited!" << FairLogger::endl;
75 Int_t ERDigibuilder::ReadEvent(UInt_t) {
76 if (!common_part_of_event_)
77 LOG(FATAL) <<
"Object fot store common part of event was not inited" << FairLogger::endl;
79 const auto event_number = EventNumber();
80 if (!LoadEvent(event_number))
82 FairRun* run = FairRun::Instance();
84 if (!EventShouldBeProcessed(event_number, header))
86 header->SetTrigger(common_part_of_event_->trigger);
87 for (
auto& detector_name_and_unpack : unpacks_) {
88 const auto& detector_name = detector_name_and_unpack.first;
89 auto& unpack = detector_name_and_unpack.second;
90 if (unpack->IsInited()) {
91 unpack->DoUnpack(
nullptr, 0);
97 uint ERDigibuilder::EventNumber() {
98 FairRootManager* ioman = FairRootManager::Instance();
100 LOG(FATAL) <<
"No FairRootManager" << FairLogger::endl;
101 return static_cast<uint
>(ioman->GetEntryNr());
104 bool ERDigibuilder::LoadEvent(
const uint event_number) {
105 if (event_number % 10000 == 0)
106 LOG(INFO) <<
"[Digibuilder] Event " << event_number << FairLogger::endl;
107 return input_chain_of_events_.GetEntry(event_number);
110 void ERDigibuilder::Close() {
111 LOG(INFO) <<
"[Digibuilder] " << EventNumber() <<
" events were processed" << FairLogger::endl;
114 void ERDigibuilder::Reset(){
115 for (
auto& detector_name_and_unpack : unpacks_) {
116 auto& unpack = detector_name_and_unpack.second;
121 void ERDigibuilder::ApplyUserCut(){
122 if (!UserCutIsDefined())
124 events_for_processing_ =
new TH1I(
"events_for_processing",
"Events for processing",
125 input_chain_of_events_.GetEntries(), 1,
126 input_chain_of_events_.GetEntries());
127 if (input_chain_of_events_.Draw(
"Entry$>>events_for_processing", user_cut_,
"goff") == -1)
128 LOG(FATAL) <<
"[Digibuilder] Error in user cut expression: " << user_cut_ << FairLogger::endl;
131 bool ERDigibuilder::UserCutIsDefined()
const {
132 return user_cut_ !=
"";
135 bool ERDigibuilder::EventShouldBeProcessed(
const uint event_number,
137 if (!UserCutIsDefined())
139 if (!events_for_processing_->GetBinContent(event_number)) {
140 LOG(DEBUG) <<
"[Digibuilder] Event is skipped due user cut. " << FairLogger::endl;
142 header->SetTrigger(-1);
143 if (!hold_events_count_) {
144 FairRun* run = FairRun::Instance();
145 run->MarkFill(kFALSE);
152 void ERDigibuilder::CheckEventHeader() {
153 FairRun* run = FairRun::Instance();
154 if (!dynamic_cast<ERBeamTimeEventHeader*>(run->GetEventHeader())) {
155 LOG(WARNING) <<
"[Digibuilder] ERBeamTimeEventHeader is not used in digibuilding. " 156 <<
"Trigger and another common information will not be written to output file." 161 void ERDigibuilder::ConnectEventCommon() {
162 if (!input_chain_of_events_.FindBranch(
"common")) {
163 LOG(FATAL) <<
"Input file does not contain branch common with trigger" 164 <<
" and another common information" << FairLogger::endl;
166 common_part_of_event_ =
new EventCommon();
167 input_chain_of_events_.SetBranchAddress(
"common", &common_part_of_event_);
170 void ERDigibuilder::SetUserCut(
const TCut& cut,
const bool hold_events_count){
172 hold_events_count_ = hold_events_count;