/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/RawFile/RawFile-00-00-10/test/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< stringgetFnamesAtBkk (int run)
void listFnames (const vector< string > &fnames)
void listNotFound (EvtRunMap &map)
int main (int argc, char *argv[])


Typedef Documentation

typedef map<int, vector<uint32_t> > EvtRunMap

Definition at line 16 of file evt_filter.cxx.


Function Documentation

EvtRunMap getEvtRunMap ( const char *  fconf  ) 

Definition at line 19 of file evt_filter.cxx.

Referenced by main().

00019                                           {
00020    EvtRunMap map;
00021 
00022    int      run;
00023    uint32_t evtId;
00024    ifstream cfs(fconf);
00025 
00026    while ( !(cfs>>run>>evtId).eof() ) {
00027       //std::cout << "run: " << run << "  evt: " << evtId << std::endl;
00028       map[run].push_back(evtId);
00029    }
00030 
00031    return map;
00032 }

vector<string> getFnamesAtBkk ( int  run  ) 

Definition at line 34 of file evt_filter.cxx.

References fname, and deljobs::string.

Referenced by main().

00035 {
00036    xmlrpc_c::value result;
00037    xmlrpc_c::clientSimple aClient;
00038 
00039    try {
00040       aClient.call( "http://bes3db.ihep.ac.cn:8080/bemp/xmlrpc",
00041                     "FileFinder.getFileByRun",
00042                     "siss",
00043                     &result,
00044                     "REAL",
00045                     run,
00046                     "Full",
00047                     "disk" );
00048    }
00049    catch (...) {
00050       cerr << "Failed to lookup the Bookkeeping Server !!!" << endl;
00051       exit(1);
00052    }
00053 
00054    vector<string> fnames;
00055    vector<xmlrpc_c::value> vItems = ((xmlrpc_c::value_array)result).vectorValueValue();
00056 
00057    for ( vector<xmlrpc_c::value>::iterator it = vItems.begin();
00058          it != vItems.end(); ++it ) {
00059       //xmlrpc_c::value_struct* item = (xmlrpc_c::value_struct*)(&(*it));
00060       map<string, xmlrpc_c::value> item = (xmlrpc_c::value_struct)(*it);
00061       string fname = (xmlrpc_c::value_string)(item["Replica"]);
00062       fnames.push_back(fname);
00063    }
00064 
00065    if ( fnames.empty() ) {
00066       cout << "No files found in Bookkeeping !!!" << endl;
00067       exit(1);
00068    }
00069 
00070    return fnames;
00071 }

void listFnames ( const vector< string > &  fnames  ) 

Definition at line 73 of file evt_filter.cxx.

00074 {
00075    vector<string>::const_iterator it = fnames.begin();
00076    for ( ; it != fnames.end(); ++it ) {
00077       std::cout << (*it) << std::endl;
00078    }
00079 }

void listNotFound ( EvtRunMap map  ) 

Definition at line 81 of file evt_filter.cxx.

Referenced by main().

00082 {
00083    EvtRunMap::iterator it = map.begin();
00084 
00085    while ( it != map.end() ) {
00086       vector<uint32_t>::iterator iit = it->second.begin();
00087 
00088       while ( iit != it->second.end() ) {
00089          std::cout << "Event " << *iit << " not found in run " << it->first << std::endl;
00090          ++iit;
00091       }
00092       ++it;
00093    }
00094 }

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

Definition at line 96 of file evt_filter.cxx.

References getEvtRunMap(), getFnamesAtBkk(), listNotFound(), RawFileReader::nextEvent(), RawFileException::print(), deljobs::string, and RawFileWriter::writeEvent().

00097 {
00098    if ( argc != 2 && argc != 3 ) {
00099       cout << "Usage: " << argv[0] << "  EvtList.txt  [data.raw]" << endl;
00100       exit(0);
00101    }
00102 
00103    if ( access( argv[1], F_OK ) < 0 ) {
00104       std::cerr << "Invalid file: " << argv[1] << std::endl;
00105       exit(1);
00106    }
00107    EvtRunMap map = getEvtRunMap(argv[1]);
00108 
00109    string ofname = string(argv[1]) + ".raw";
00110    RawFileWriter* pfw = new RawFileWriter(ofname.c_str());
00111 
00112    const uint32_t* data;
00113 
00114    if ( argc == 2 ) {
00115 
00116       EvtRunMap::iterator it = map.begin();
00117       while( it != map.end() ) {
00118          RawFileReader* pfr = new RawFileReader( getFnamesAtBkk(it->first) );
00119          /*
00120           * can be optimized by pfr->findEventById() when IDX exist!!!
00121           */
00122          while ( ! it->second.empty() ) {
00123             try {
00124                data = pfr->nextEvent();
00125             }
00126             catch ( RawFileException& e ) {
00127                e.print();
00128                break;
00129             }
00130 
00131             uint32_t evtId = data[8 + data[5]];
00132             vector<uint32_t>::iterator iit = find(it->second.begin(), it->second.end(), evtId);
00133 
00134             if ( iit != it->second.end() ) {
00135                pfw->writeEvent(data);
00136                it->second.erase(iit);
00137             }
00138          }
00139 
00140          delete pfr;
00141 
00142          ++it;
00143       }
00144    }
00145    else {
00146 
00147       RawFileReader* pfr = new RawFileReader( argv[2] );
00148       while ( true ) {
00149          try {
00150             data = pfr->nextEvent();
00151          }
00152          catch ( RawFileException& e ) {
00153             e.print();
00154             break;
00155          }
00156 
00157          uint32_t evtId = data[8 + data[5]];
00158          uint32_t runId = data[9 + data[5]];
00159          EvtRunMap::iterator it = map.find( runId );
00160          if ( it != map.end() ) {
00161             vector<uint32_t>::iterator iit = find(it->second.begin(), it->second.end(), evtId);
00162 
00163             if ( iit != it->second.end() ) {
00164                pfw->writeEvent(data);
00165                it->second.erase(iit);
00166 
00167                if ( it->second.empty() ) {
00168                   map.erase( it );
00169                   if ( map.empty() ) {
00170                      break;
00171                   }
00172                }
00173             }
00174          }
00175       }
00176 
00177       delete pfr;
00178    }
00179 
00180    delete pfw;
00181 
00182    // list events NOT found
00183    listNotFound(map);
00184 
00185    return 0;
00186 }


Generated on Tue Nov 29 23:15:11 2016 for BOSS_7.0.2 by  doxygen 1.4.7