BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
evt_filter.cxx File Reference
#include "RawFile/RawFileWriter.h"
#include "RawFile/RawFileReader.h"
#include "IRawFile/RawFileExceptions.h"
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/client_simple.hpp>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <unistd.h>

Go to the source code of this file.

Typedefs

typedef map< int, vector< uint32_t > > EvtRunMap
 

Functions

EvtRunMap getEvtRunMap (const char *fconf)
 
vector< string > getFnamesAtBkk (int run)
 
void listFnames (const vector< string > &fnames)
 
void listNotFound (EvtRunMap &map)
 
int main (int argc, char *argv[])
 

Typedef Documentation

◆ EvtRunMap

typedef map<int, vector<uint32_t> > EvtRunMap

Definition at line 16 of file evt_filter.cxx.

Function Documentation

◆ getEvtRunMap()

EvtRunMap getEvtRunMap ( const char *  fconf)

Definition at line 19 of file evt_filter.cxx.

19 {
20 EvtRunMap map;
21
22 int run;
23 uint32_t evtId;
24 ifstream cfs(fconf);
25
26 while ( !(cfs>>run>>evtId).eof() ) {
27 //std::cout << "run: " << run << " evt: " << evtId << std::endl;
28 map[run].push_back(evtId);
29 }
30
31 return map;
32}
map< int, vector< uint32_t > > EvtRunMap
Definition: evt_filter.cxx:16

Referenced by main().

◆ getFnamesAtBkk()

vector< string > getFnamesAtBkk ( int  run)

Definition at line 34 of file evt_filter.cxx.

35{
36 xmlrpc_c::value result;
37 xmlrpc_c::clientSimple aClient;
38
39 try {
40 aClient.call( "http://bes3db.ihep.ac.cn:8080/bemp/xmlrpc",
41 "FileFinder.getFileByRun",
42 "siss",
43 &result,
44 "REAL",
45 run,
46 "Full",
47 "disk" );
48 }
49 catch (...) {
50 cerr << "Failed to lookup the Bookkeeping Server !!!" << endl;
51 exit(1);
52 }
53
54 vector<string> fnames;
55 vector<xmlrpc_c::value> vItems = ((xmlrpc_c::value_array)result).vectorValueValue();
56
57 for ( vector<xmlrpc_c::value>::iterator it = vItems.begin();
58 it != vItems.end(); ++it ) {
59 //xmlrpc_c::value_struct* item = (xmlrpc_c::value_struct*)(&(*it));
60 map<string, xmlrpc_c::value> item = (xmlrpc_c::value_struct)(*it);
61 string fname = (xmlrpc_c::value_string)(item["Replica"]);
62 fnames.push_back(fname);
63 }
64
65 if ( fnames.empty() ) {
66 cout << "No files found in Bookkeeping !!!" << endl;
67 exit(1);
68 }
69
70 return fnames;
71}

Referenced by main().

◆ listFnames()

void listFnames ( const vector< string > &  fnames)

Definition at line 73 of file evt_filter.cxx.

74{
75 vector<string>::const_iterator it = fnames.begin();
76 for ( ; it != fnames.end(); ++it ) {
77 std::cout << (*it) << std::endl;
78 }
79}

◆ listNotFound()

void listNotFound ( EvtRunMap map)

Definition at line 81 of file evt_filter.cxx.

82{
83 EvtRunMap::iterator it = map.begin();
84
85 while ( it != map.end() ) {
86 vector<uint32_t>::iterator iit = it->second.begin();
87
88 while ( iit != it->second.end() ) {
89 std::cout << "Event " << *iit << " not found in run " << it->first << std::endl;
90 ++iit;
91 }
92 ++it;
93 }
94}

Referenced by main().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 96 of file evt_filter.cxx.

97{
98 if ( argc != 2 && argc != 3 ) {
99 cout << "Usage: " << argv[0] << " EvtList.txt [data.raw]" << endl;
100 exit(0);
101 }
102
103 if ( access( argv[1], F_OK ) < 0 ) {
104 std::cerr << "Invalid file: " << argv[1] << std::endl;
105 exit(1);
106 }
107 EvtRunMap map = getEvtRunMap(argv[1]);
108
109 string ofname = string(argv[1]) + ".raw";
110 RawFileWriter* pfw = new RawFileWriter(ofname.c_str());
111
112 const uint32_t* data;
113
114 if ( argc == 2 ) {
115
116 EvtRunMap::iterator it = map.begin();
117 while( it != map.end() ) {
118 RawFileReader* pfr = new RawFileReader( getFnamesAtBkk(it->first) );
119 /*
120 * can be optimized by pfr->findEventById() when IDX exist!!!
121 */
122 while ( ! it->second.empty() ) {
123 try {
124 data = pfr->nextEvent();
125 }
126 catch ( RawFileException& e ) {
127 e.print();
128 break;
129 }
130
131 uint32_t evtId = data[8 + data[5]];
132 vector<uint32_t>::iterator iit = find(it->second.begin(), it->second.end(), evtId);
133
134 if ( iit != it->second.end() ) {
135 pfw->writeEvent(data);
136 it->second.erase(iit);
137 }
138 }
139
140 delete pfr;
141
142 ++it;
143 }
144 }
145 else {
146
147 RawFileReader* pfr = new RawFileReader( argv[2] );
148 while ( true ) {
149 try {
150 data = pfr->nextEvent();
151 }
152 catch ( RawFileException& e ) {
153 e.print();
154 break;
155 }
156
157 uint32_t evtId = data[8 + data[5]];
158 uint32_t runId = data[9 + data[5]];
159 EvtRunMap::iterator it = map.find( runId );
160 if ( it != map.end() ) {
161 vector<uint32_t>::iterator iit = find(it->second.begin(), it->second.end(), evtId);
162
163 if ( iit != it->second.end() ) {
164 pfw->writeEvent(data);
165 it->second.erase(iit);
166
167 if ( it->second.empty() ) {
168 map.erase( it );
169 if ( map.empty() ) {
170 break;
171 }
172 }
173 }
174 }
175 }
176
177 delete pfr;
178 }
179
180 delete pfw;
181
182 // list events NOT found
183 listNotFound(map);
184
185 return 0;
186}
TTree * data
virtual void print() const
const uint32_t * nextEvent()
int writeEvent(const uint32_t *pevt)
void listNotFound(EvtRunMap &map)
Definition: evt_filter.cxx:81
EvtRunMap getEvtRunMap(const char *fconf)
Definition: evt_filter.cxx:19
vector< string > getFnamesAtBkk(int run)
Definition: evt_filter.cxx:34