Go to the documentation of this file.00001 #include <iostream>
00002 #include <stdio.h>
00003
00004 #include "nxyter/Data.h"
00005
00006
00007 #include "LmdFile.h"
00008
00009
00010 #include "TBranch.h"
00011 #include "TClonesArray.h"
00012 #include "TFile.h"
00013 #include "TTree.h"
00014
00015
00016 #include "ScDigi.h"
00017 #include "ScEvent.h"
00018 #include "ScEventBuilder.h"
00019
00020 using namespace std;
00021
00022
00023 ScEventBuilder::ScEventBuilder() {
00024 fTlimit = 100.;
00025 }
00026
00027
00028 ScEventBuilder::~ScEventBuilder() {
00029 }
00030
00031
00032 Int_t ScEventBuilder::Start() {
00033
00034
00035
00036 Int_t nMbsEvents = 0;
00037
00038
00039
00040 mbs::LmdFile inFile;
00041 if ( ! inFile.OpenRead(fInputFile.Data()) ) {
00042 cout << "--E-- EventBuilder: Could not open input file " << fInputFile << endl;
00043 return -1;
00044 }
00045
00046
00047
00048 TFile* outFile = new TFile(fOutputFile, "RECREATE");
00049 if ( outFile->IsZombie() ) {
00050 cout << "--E-- EventBuilder: Could not open output file " << fOutputFile << endl;
00051 return -1;
00052 }
00053
00054
00055
00056
00057
00058 ScEvent* event = new ScEvent();
00059 TTree* outTree = new TTree("cbmdata", "data tree");
00060 outTree->Branch("event", &event);
00061
00062
00063
00064
00065 mbs::EventHeader* mbsEvt = NULL;
00066 mbs::SubeventHeader* mbsSubEvt = NULL;
00067 nxyter::Data* data = NULL;
00068
00069
00070
00071 Long64_t nTotEpochs = 0;
00072 Long64_t nTotHits = 0;
00073 Long64_t nTotAux = 0;
00074 Long64_t nTotEvents = 0;
00075
00076
00077
00078 Int_t nData = 0;
00079 Int_t currentEpoch = 0;
00080 Long64_t currentEpochTime = 0;
00081 Long64_t hitTime = 0;
00082
00083
00084
00085
00086 while ( (mbsEvt = inFile.ReadEvent()) ) {
00087 nMbsEvents++;
00088 mbsSubEvt = NULL;
00089 Int_t nMbsSubEvts = 0;
00090 Int_t nHits = 0;
00091 Int_t nAux = 0;
00092 Int_t nEpochs = 0;
00093 Int_t nEvents = 0;
00094
00095
00096
00097 while ( (mbsSubEvt = mbsEvt->NextSubEvent(mbsSubEvt)) ) {
00098 nMbsSubEvts++;
00099
00100
00101
00102 data = (nxyter::Data*) mbsSubEvt->RawData();
00103 nData = mbsSubEvt->RawDataSize() / 6;
00104 while (nData--) {
00105
00106
00107
00108 if ( data->isEpochMsg() ) {
00109 nEpochs++;
00110 currentEpoch = data->getEpoch();
00111 currentEpochTime = Long64_t(currentEpoch) << 14;
00112 }
00113
00114
00115 else if ( data->isHitMsg() || data->isAuxMsg() ) {
00116
00117
00118 if ( data->isHitMsg() ) {
00119 hitTime = currentEpochTime + Long64_t(data->getNxTs());
00120 nHits++;
00121 }
00122 else {
00123 hitTime = currentEpochTime + Long64_t(data->getAuxTs());
00124 nAux++;
00125 }
00126
00127
00128 if ( event->IsEmpty() || (Double_t(hitTime) - event->GetTime() < fTlimit) ) {
00129 event->AddData(data, hitTime, currentEpoch);
00130 }
00131
00132
00133 else {
00134 outTree->Fill();
00135 event->Clear();
00136 nEvents++;
00137 event->AddData(data, hitTime, currentEpoch);
00138 }
00139
00140 }
00141 data++;
00142
00143 }
00144
00145 }
00146
00147
00148 cout << "MBS Event " << nMbsEvents << " Subevents " << nMbsSubEvts << " Epochs "
00149 << nEpochs << " Hits " << nHits << " Aux " << nAux << " Events "
00150 << nEvents << endl;
00151
00152 nTotEpochs += nEpochs;
00153 nTotHits += nHits;
00154 nTotAux += nAux;
00155 nTotEvents += nEvents;
00156
00157
00158 }
00159
00160
00161
00162
00163 inFile.Close();
00164 outFile->Write();
00165 outFile->Close();
00166
00167 cout << endl << endl;
00168 cout << "===============================================================" << endl;
00169 cout << "Total MBS events " << nMbsEvents << endl;
00170 cout << "Total epochs " << nTotEpochs << endl;
00171 cout << "Total hit messages " << nTotHits << endl;
00172 cout << "Total aux messages " << nTotAux << endl;
00173 cout << "Total events " << nTotEvents << endl;
00174 cout << "===============================================================" << endl;
00175
00176
00177
00178
00179
00180
00181 return 0;
00182
00183 }
00184
00185
00186
00187 ClassImp(ScEventBuilder)