#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <assert.h>
#include <signal.h>
#include <errno.h>
#include "TMidasEvent.h"
#include "TMidasFile.h"
#include <vector>
Go to the source code of this file.
Functions | |
void | HandleMidasEvent (TMidasEvent &event) |
int | ProcessMidasFile (const char *fname, const char *foutname) |
void | help () |
int | main (int argc, char *argv[]) |
Variables | |
int | gEventCutoff = 0 |
void HandleMidasEvent | ( | TMidasEvent & | event | ) |
Trigger word definition (64 bit unsigned long):
Definition at line 26 of file event_skim.cxx.
00027 { 00028 int eventId = event.GetEventId(); 00029 int eventSN = event.GetSerialNumber(); 00030 //event.Print("a"); 00031 //event.Print(); 00032 // printf("EventSerial#: %i, EventID: %i\n",eventSN,eventId); 00033 00034 // Look for some banks: 00035 const char* fBank = "OMCM" ; 00036 int bankLength = 0; 00037 int bankType = 0; 00038 void *pdata = 0; 00039 00040 int found = event.FindBank(fBank, &bankLength, &bankType, &pdata); 00041 if(found) 00042 { 00043 if (0) { 00044 printf("Dumping bank %s in hex\n",fBank); 00045 for (int j = 0; j < bankLength; j++) 00046 printf("0x%08x%c", ((uint32_t*)pdata)[j], (j%10==9)?'\n':' '); 00047 printf("\n"); 00048 printf("Dumping bank %s in dec\n",fBank); 00049 for (int j = 0; j < bankLength; j++) 00050 printf(" %8d%c", ((uint32_t*)pdata)[j], (j%10==9)?'\n':' '); 00051 printf("\n"); 00052 } 00053 /// Trigger word definition (64 bit unsigned long): 00054 /// - Bits 0-31: Event number 00055 /// - Bits 32-47: Spill number 00056 /// - Bits 48-57: Trigger bits 00057 /// - Bit 48: Beam spill 00058 /// - Bit 49: Pedestal/noise 00059 /// - Bit 50: TPC laser 00060 /// - Bit 51: POD LED 00061 /// - Bit 52: ECAL LED 00062 /// - Bit 53: FGD LED 00063 /// - Bit 54: FEE calibration 00064 /// - Bit 55: TRIP-t cosmic 00065 /// - Bit 56: Reserved for FGD cosmic 00066 /// - Bit 57: unused 00067 /// - Bits 58-63: Instruction 00068 /// - Bit 58: Reserved for start-of-run 00069 /// - Bit 59: Reserved for end-of-run 00070 /// - Bit 60: 1 PPS / counter reset 00071 /// - Bit 61: Go to spill mode 00072 /// - Bit 62: Go to cosmic mode 00073 /// - Bit 63: Decline CTM request/abort 00074 int eventNum = ((uint32_t*)pdata)[1]; 00075 int spillNum = ((uint32_t*)pdata)[2] & 0xFFFF; 00076 int trigBits = (((uint32_t*)pdata)[2] >> 16) & 0xFFFF; 00077 const char* trigType = ""; 00078 int trigBeam = 1; 00079 switch (trigBits) 00080 { 00081 case 1: 00082 trigType = "Beam spill"; 00083 break; 00084 } 00085 if (trigBits == trigBeam) { 00086 // printf("EventSerial#: %i, EventID: %i\n",eventSN,eventId); 00087 printf(" eventNum %d, spillNum %d, trigBits 0x%04x, %s\n",eventNum,spillNum,trigBits,trigType); 00088 } 00089 } else { 00090 printf("Can't find bank %s\n",fBank); 00091 } 00092 //printf("\n"); 00093 00094 }
void help | ( | ) |
Definition at line 189 of file event_skim.cxx.
00190 { 00191 printf("\nUsage:\n"); 00192 printf("\n./event_skim.exe [-h] [-eMaxEvents] [file1 file2 ...]\n"); 00193 printf("\n"); 00194 printf("\t-h: print this help message\n"); 00195 printf("\t-e: Number of events to read from input data files\n"); 00196 printf("\t-o: Generate output file \n"); 00197 printf("\n"); 00198 printf("Example1: print events from file: ./event_skim.exe /data/alpha/current/run00500.mid.gz\n"); 00199 printf("Example2: output selected events: ./event_skim.exe -o skim_00500.mid.gz /data/alpha/current/run00500.mid.gz\n"); 00200 exit(1); 00201 }
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 205 of file event_skim.cxx.
References gEventCutoff, help(), and ProcessMidasFile().
00206 { 00207 setbuf(stdout,NULL); 00208 setbuf(stderr,NULL); 00209 00210 signal(SIGILL, SIG_DFL); 00211 signal(SIGBUS, SIG_DFL); 00212 signal(SIGSEGV, SIG_DFL); 00213 signal(SIGPIPE, SIG_DFL); 00214 00215 std::vector<std::string> args; 00216 for (int i=0; i<argc; i++) 00217 { 00218 if (strcmp(argv[i],"-h")==0) 00219 help(); // does not return 00220 args.push_back(argv[i]); 00221 } 00222 00223 const char* outname = NULL; 00224 00225 for (unsigned int i=1; i<args.size(); i++) // loop over the commandline options 00226 { 00227 const char* arg = args[i].c_str(); 00228 //printf("argv[%d] is %s\n",i,arg); 00229 00230 if (strncmp(arg,"-e",2)==0) // Event cutoff flag (only applicable in offline mode) 00231 gEventCutoff = atoi(arg+2); 00232 else if (strncmp(arg,"-o",2)==0) { // Skim to output file 00233 outname = args[i+1].c_str(); 00234 i++; 00235 } 00236 else if (strcmp(arg,"-h")==0) 00237 help(); // does not return 00238 else if (arg[0] == '-') 00239 help(); // does not return 00240 } 00241 00242 for (unsigned int i=1; i<args.size(); i++) 00243 { 00244 const char* arg = args[i].c_str(); 00245 00246 if (arg[0] != '-') 00247 { 00248 ProcessMidasFile(arg, outname); 00249 } 00250 } 00251 00252 return 0; 00253 }
int ProcessMidasFile | ( | const char * | fname, | |
const char * | foutname | |||
) |
Definition at line 113 of file event_skim.cxx.
References TMidasFile::Close(), TMidasFile::GetLastErrno(), TMidasFile::GetLastError(), gEventCutoff, HandleMidasEvent(), TMidasFile::Open(), TMidasFile::OutClose(), TMidasFile::OutOpen(), TMidasFile::Read(), and TMidasFile::Write().
00114 { 00115 TMidasFile f; 00116 TMidasFile fout; 00117 00118 bool tryOpen = f.Open(fname); 00119 00120 if (!tryOpen) 00121 { 00122 printf("Cannot open input file \"%s\"\n",fname); 00123 return -1; 00124 } 00125 00126 bool tryOutOpen = fout.OutOpen(foutname); 00127 00128 if (!tryOutOpen) 00129 { 00130 printf("Cannot open output file \"%s\"\n",foutname); 00131 printf("Last error is %d, %s\n",f.GetLastErrno(),f.GetLastError()); 00132 printf("Exiting program\n"); 00133 exit (1); 00134 } 00135 00136 int i=0; 00137 while (1) 00138 { 00139 TMidasEvent event; 00140 if (!f.Read(&event)) 00141 break; 00142 00143 int eventId = event.GetEventId(); 00144 printf("Have an event of type %d\n",eventId); 00145 00146 if ((eventId & 0xFFFF) == 0x8000) 00147 { 00148 // begin run 00149 event.Print(); 00150 } 00151 else if ((eventId & 0xFFFF) == 0x8001) 00152 { 00153 // end run 00154 event.Print(); 00155 } 00156 else 00157 { 00158 event.SetBankList(); 00159 //event.Print(); 00160 HandleMidasEvent(event); 00161 } 00162 if((i%500)==0) 00163 { 00164 printf("Processing event %d\n",i); 00165 } 00166 00167 i++; 00168 if ((gEventCutoff!=0)&&(i>=gEventCutoff)) 00169 { 00170 printf("Reached event %d, exiting loop.\n", i); 00171 break; 00172 } 00173 // Output all events 00174 if (!fout.Write(&event)) { 00175 printf("Error writing event to output\n"); 00176 break; 00177 } 00178 printf("Event written to out\n"); 00179 00180 } 00181 00182 f.Close(); 00183 fout.OutClose(); 00184 00185 return 0; 00186 }
int gEventCutoff = 0 |
Definition at line 23 of file event_skim.cxx.