7 #include "TStopwatch.h" 17 Bool_t
CheckEvent(
const std::shared_ptr<TMidasEvent>& evt)
20 static std::map<Int_t, Bool_t> triggermap;
26 int banksize = evt->LocateBank(
nullptr,
"GRF2", &ptr);
30 banksize = evt->LocateBank(
nullptr,
"GRF1", &ptr);
33 uint32_t type = 0xffffffff;
34 uint32_t value = 0xffffffff;
41 for(
int x = 0; x < banksize; x++) {
42 value = *(
reinterpret_cast<int*
>(ptr) + x);
43 type = value & 0xf0000000;
55 if((value & 0xf0000000) != 0x80000000) {
58 chanadd = (value & 0x0003fff0) >> 4;
71 if((value & 0xf0000000) != 0x80000000) {
74 chanadd = (value & 0x000ffff0) >> 4;
80 default: printf(
"This bank not yet defined.\n");
break;
84 case 0x90000000: trigId = value & 0x0fffffff;
87 if(triggermap.find(chanadd) == triggermap.end()) {
88 triggermap[chanadd] =
false;
96 if(triggermap.find(chanadd)->second) {
100 triggermap.find(chanadd)->second =
true;
124 printf(
"Usage: ./bufferclear <input.mid> <output.mid>\n");
129 printf(
"input.mid and output.mid must have different names\n");
136 int runnumber = file->GetRunNumber();
137 int subrunnumber = file->GetSubRunNumber();
139 file->OutOpen(Form(
"cleanrun%05d_%03d.mid", runnumber, subrunnumber));
141 file->OutOpen(
argv[2]);
144 std::ifstream in(file->GetFilename(), std::ifstream::in | std::ifstream::binary);
145 in.seekg(0, std::ifstream::end);
146 long long filesize = in.tellg();
150 long long bytesread = 0;
155 UInt_t num_bad_evt = 0;
157 std::shared_ptr<TMidasEvent>
event = std::make_shared<TMidasEvent>();
160 bytes = file->Read(event);
162 printf(
DMAGENTA "\tfile: %s ended on %s" RESET_COLOR "\n", file->GetFilename(), file->GetLastError());
163 if(file->GetLastErrno() == -1) {
170 switch(event->GetEventId()) {
172 printf(
"start of run\n");
180 printf(
"end of run\n");
202 if(num_evt % 5000 == 0) {
203 gSystem->ProcessEvents();
206 num_bad_evt, num_evt, (bytesread / 1000000.0), (filesize / 1000000.0),
207 (bytesread / 1000000.0) / w.RealTime());
int main(int argc, char **argv)
void Write(std::shared_ptr< TMidasEvent > evt, TMidasFile *outfile)
Reader for MIDAS .mid files.
Bool_t CheckEvent(const std::shared_ptr< TMidasEvent > &evt)
void FillBuffer(const std::shared_ptr< TMidasEvent > &midasEvent, Option_t *opt="")
bool Open(const char *filename) override
Open input file.