BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
GenRdmTrgIdxAlg.cxx
Go to the documentation of this file.
1#include "GenRdmTrgIdxAlg.h"
5#include "GaudiKernel/AlgFactory.h"
6
8
9GenRdmTrgIdxAlg::GenRdmTrgIdxAlg(const std::string& name, ISvcLocator* pSvcLocator)
10 : GaudiAlgorithm(name, pSvcLocator),
11 m_fcount(0)
12{
13 declareProperty("RandomTriggerFiles", m_rdmFiles);
14}
15
17{
18}
19
21{
22 StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
23
24 if ( m_rdmFiles.empty() ) {
25 error() << "RandomTriggerFiles is empty" << endmsg;
26 return StatusCode::FAILURE;
27 }
28
29 m_idxhandler = new EvtIdxHandler;
30 m_freader = new SimpleRawReader(m_rdmFiles[0]);
31
32 return sc;
33}
34
36{
37 SmartDataPtr<TrigData> trigData(eventSvc(), EventModel::Trig::TrigData);
38 if ( trigData->getTrigChannel(9) != 1 ) {
39 // this is not a random trigger event, pass it
40 return StatusCode::SUCCESS;
41 }
42
43 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(), "/Event/EventHeader");
44 uint32_t evtNo = eventHeader->eventNumber();
45 uint32_t runNo = eventHeader->runNumber();
46
47 uint32_t thePos = 0;
48 const uint32_t* data = NULL;
49 uint32_t rdmEvtNo = 0xFFFFFFFF;
50
51 //std::cout << "BEGIN " << evtNo << std::endl;
52 do {
53 thePos = m_freader->raw_stream()->tellg();
54 try {
55 data = m_freader->nextEvent();
56 }
57 catch ( ReachEndOfFile& e ) {
58 m_idxhandler->write( RawFileTools::fname2idxname(m_freader->raw_stream()->currentFile()) );
59 delete m_freader;
60 m_freader = NULL;
61 ++m_fcount;
62 if ( m_fcount < m_rdmFiles.size() ) {
63 m_freader = new SimpleRawReader(m_rdmFiles[m_fcount]);
64 rdmEvtNo = 0xFFFFFFFF;
65 continue;
66 }
67 else {
68 fatal() << "can not find event " << evtNo << " in random trigger data files" << endmsg;
69 return StatusCode::FAILURE;
70 }
71 }
72 catch ( RawFileException& e ) {
73 e.print();
74 throw e;
75 }
76
77 //std::cout << "run " << data[9+data[5]] << ", event " << data[8+data[5]] << std::endl;
78
79 if ( data[9+data[5]] != runNo ) {
80 fatal() << "bad runNo in random trigger data" << endmsg;
81 return StatusCode::FAILURE;
82 }
83 rdmEvtNo = data[8+data[5]];
84 } while ( rdmEvtNo != evtNo );
85
86 m_idxhandler->addPos(data[8+data[5]], thePos);
87
88 return StatusCode::SUCCESS;
89}
90
92{
93 if ( m_freader != NULL ) {
94 m_idxhandler->write( RawFileTools::fname2idxname(m_freader->raw_stream()->currentFile()) );
95 delete m_freader;
96 }
97 delete m_idxhandler;
98
99 return GaudiAlgorithm::finalize(); // must be called after all other actions
100}
int runNo
Definition: DQA_TO_DB.cxx:12
DECLARE_ALGORITHM_FACTORY(ReadRawData)
void write(std::string fname)
void addPos(uint32_t evtId, uint32_t pos)
virtual ~GenRdmTrgIdxAlg()
virtual StatusCode initialize()
Algorithm initialization.
virtual StatusCode execute()
Algorithm execution.
virtual StatusCode finalize()
Algorithm finalization.
virtual void print() const
const uint32_t * nextEvent()
raw_ifstream * raw_stream()
std::string currentFile() const
Definition: raw_ifstream.h:29
_EXTERN_ std::string TrigData
Definition: EventModel.h:68
std::string fname2idxname(const std::string &fname)