26 printf(
"TARunInfo::ctor!\n");
39 printf(
"TARunInfo::dtor!\n");
63 printf(
"TAFlowEvent::ctor: chain %p\n", flow);
70 printf(
"TAFlowEvent::dtor: this %p, next %p\n",
this,
fNext);
85 printf(
"TARunInterface::ctor, run %d\n", runinfo->
fRunNo);
91 printf(
"TARunInterface::BeginRun, run %d\n", runinfo->
fRunNo);
97 printf(
"TARunInterface::EndRun, run %d\n", runinfo->
fRunNo);
103 printf(
"TARunInterface::PauseRun, run %d\n", runinfo->
fRunNo);
109 printf(
"TARunInterface::ResumeRun, run %d\n", runinfo->
fRunNo);
115 printf(
"TARunInterface::Analyze!\n");
122 printf(
"TARunInterface::AnalyzeSpecialEvent!\n");
134 printf(
"TAModuleInterface::Init!\n");
140 printf(
"TAModuleInterface::Finish!\n");
151 #ifdef HAVE_XMLSERVER
156 #ifdef XHAVE_LIBNETDIRECTORY
168 printf(
"TARootHelper::ctor!\n");
170 char xfilename[1024];
171 sprintf(xfilename,
"output%05d.root", runinfo->
fRunNo);
179 #ifdef XHAVE_LIBNETDIRECTORY
182 #ifdef HAVE_XMLSERVER
191 printf(
"TARootHelper::dtor!\n");
208 #include <sys/time.h>
219 #ifdef HAVE_THTTP_SERVER
220 #include "THttpServer.h"
238 gModules =
new std::vector<TAModuleInterface*>;
252 int odbReadAny(
const char*name,
int index,
int tid,
void* buf,
int bufsize = 0) {
return 0; };
253 int odbReadInt(
const char*name,
int index = 0,
int defaultValue = 0) {
return defaultValue; }
254 uint32_t
odbReadUint32(
const char*name,
int index = 0, uint32_t defaultValue = 0) {
return defaultValue; }
255 float odbReadFloat(
const char*name,
int index = 0,
float defaultValue = 0) {
return defaultValue; }
256 double odbReadDouble(
const char*name,
int index = 0,
double defaultValue = 0) {
return defaultValue; }
257 bool odbReadBool(
const char*name,
int index = 0,
bool defaultValue =
false) {
return defaultValue; }
258 const char*
odbReadString(
const char*name,
int index = 0,
const char* defaultValue = NULL) {
return defaultValue; }
265 gettimeofday(&tv,NULL);
266 return tv.tv_sec + 0.000001*tv.tv_usec;
296 for (
unsigned i=0; i<(*gModules).size(); i++)
304 for (
unsigned i=0; i<
fRunRun.size(); i++)
312 for (
unsigned i=0; i<
fRunRun.size(); i++)
320 for (
unsigned i=0; i<
fRunRun.size(); i++) {
334 for (
unsigned i=0; i<
fRunRun.size(); i++)
345 for (
unsigned i=0; i<
fRunRun.size(); i++) {
395 void Transition(
int transition,
int run_number,
int transition_time)
399 if (transition == TR_START) {
408 printf(
"Begin run: %d\n", run_number);
409 }
else if (transition == TR_STOP) {
413 printf(
"End of run %d\n", run_number);
417 void Event(
const void* data,
int data_size)
451 int err = midas->
connect(hostname, exptname,
"rootana");
453 fprintf(stderr,
"Cannot connect to MIDAS, error %d\n", err);
466 int run_number = midas->odbReadInt(
"/runinfo/Run number");
467 int run_state = midas->odbReadInt(
"/runinfo/State");
469 for (
unsigned i=0; i<(*gModules).size(); i++)
472 if ((run_state == STATE_RUNNING)||(run_state == STATE_PAUSED)) {
477 #ifdef HAVE_THTTP_SERVER
484 gSystem->DispatchOneEvent(kTRUE);
497 for (
unsigned i=0; i<(*gModules).size(); i++)
510 for (
unsigned i=0; i<(*gModules).size(); i++)
517 for (
unsigned i=0; i<files.size(); i++) {
518 std::string filename = files[i];
523 printf(
"Could not open \"%s\", error: %s\n", filename.c_str(), reader->
fErrorString.c_str());
539 if (event->event_id == 0x8000)
541 int runno =
event->serial_number;
571 else if (event->event_id == 0x8001)
589 else if (event->event_id == 0x8002)
614 if (num_analyze > 0) {
616 if (num_analyze == 0)
629 gSystem->DispatchOneEvent(kTRUE);
646 for (
unsigned i=0; i<(*gModules).size(); i++)
655 static int ShowMem(
const char* label)
660 FILE* fp = fopen(
"/proc/self/statm",
"r");
665 fscanf(fp,
"%d",&mem);
669 printf(
"memory at %s is %d\n", label, mem);
682 printf(
"EventDumpRun::ctor, run %d\n", runinfo->
fRunNo);
688 printf(
"EventDumpRun::dtor!\n");
693 printf(
"EventDumpRun::BeginRun, run %d\n", runinfo->
fRunNo);
698 printf(
"EventDumpRun::EndRun, run %d\n", runinfo->
fRunNo);
703 printf(
"EventDumpRun::PauseRun, run %d\n", runinfo->
fRunNo);
708 printf(
"EventDumpRun::ResumeRun, run %d\n", runinfo->
fRunNo);
713 printf(
"EventDumpRun::Analyze, run %d, ", runinfo->
fRunNo);
714 event->FindAllBanks();
715 std::string h =
event->HeaderToString();
716 std::string b =
event->BankListToString();
717 printf(
"%s: %s\n", h.c_str(), b.c_str());
731 void Init(
const std::vector<std::string> &args)
734 printf(
"EventDumpModule::Init!\n");
740 printf(
"EventDumpModule::Finish!\n");
746 printf(
"EventDumpModule::NewRun, run %d, file %s\n", runinfo->
fRunNo, runinfo->
fFileName.c_str());
753 #include <TGButton.h>
754 #include <TBrowser.h>
758 #define CTRL_CONTINUE 3
761 #define CTRL_TBROWSER 11
790 printf(
"Pressed!\n");
795 printf(
"Released!\n");
824 printf(
"MainWindow::ctor!\n");
829 SetWindowName(
"ROOT Analyzer Control");
832 fMenu =
new TGPopupMenu(gClient->GetRoot());
834 fMenu->AddEntry(
"-", 0);
838 fMenu->AddEntry(
"-", 0);
843 fMenu->Associate(
this);
845 fMenuBar =
new TGMenuBar(
this, 1, 1, kRaisedFrame);
849 menuBarLayout =
new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX);
856 TGVerticalFrame *hframe1 =
new TGVerticalFrame(
this, 170, 50, kFixedWidth);
860 new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 0, 2, 2));
861 AddFrame(hframe1,
new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
865 TGCompositeFrame *cframe1 =
new TGCompositeFrame(
this, 170, 20, kHorizontalFrame | kFixedWidth);
869 new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 2));
872 new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 2));
874 AddFrame(cframe1,
new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
878 TGCompositeFrame *cframe2 =
new TGCompositeFrame(
this, 170, 20, kHorizontalFrame | kFixedWidth);
881 TGButton* ok =
new XButton(cframe2,
"OK", ctrl, 0);
883 cframe2->AddFrame(ok,
new TGLayoutHints(kLHintsTop | kLHintsExpandX, 3, 2, 2, 2));
885 TGButton* cancel =
new XButton(cframe2,
"Cancel ", ctrl, 0);
886 cframe2->AddFrame(cancel,
new TGLayoutHints(kLHintsTop | kLHintsExpandX, 3, 2, 2, 2));
890 new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 0, 2, 2));
892 AddFrame(cframe2,
new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
902 printf(
"MainWindow::dtor!\n");
913 printf(
"MainWindow::CloseWindow()\n");
923 switch (GET_MSG(msg))
928 switch (GET_SUBMSG(msg))
970 printf(
"InteractiveRun::ctor, run %d\n", runinfo->
fRunNo);
985 printf(
"InteractiveRun::dtor!\n");
990 printf(
"InteractiveRun::BeginRun, run %d\n", runinfo->
fRunNo);
995 printf(
"InteractiveRun::EndRun, run %d\n", runinfo->
fRunNo);
1000 #ifdef HAVE_THTTP_SERVER
1007 gSystem->DispatchOneEvent(kTRUE);
1037 printf(
"InteractiveRun::PauseRun, run %d\n", runinfo->
fRunNo);
1042 printf(
"InteractiveRun::ResumeRun, run %d\n", runinfo->
fRunNo);
1047 printf(
"InteractiveRun::Analyze, run %d, %s\n", runinfo->
fRunNo, event->
HeaderToString().c_str());
1072 #ifdef HAVE_THTTP_SERVER
1079 gSystem->DispatchOneEvent(kTRUE);
1110 fprintf(stdout,
"manalyzer> "); fflush(stdout);
1111 fgets(str,
sizeof(str)-1, stdin);
1113 printf(
"command [%s]\n", str);
1115 if (str[0] ==
'h') {
1116 printf(
"Interactive manalyzer commands:\n");
1117 printf(
" q - quit\n");
1118 printf(
" h - help\n");
1119 printf(
" c - continue until next TAFlag_DISPLAY event\n");
1120 printf(
" n - next event\n");
1121 printf(
" aNNN - analyze N events, i.e. \"a10\"\n");
1122 }
else if (str[0] ==
'q') {
1125 }
else if (str[0] ==
'n') {
1127 }
else if (str[0] ==
'c') {
1130 }
else if (str[0] ==
'a') {
1131 int num = atoi(str+1);
1132 printf(
"Analyzing %d events\n", num);
1146 printf(
"InteractiveRun::AnalyzeSpecialEvent, run %d, event serno %d, id 0x%04x, data size %d\n", runinfo->
fRunNo, event->
serial_number, (
int)event->
event_id, event->
data_size);
1157 void Init(
const std::vector<std::string> &args)
1160 printf(
"InteractiveModule::Init!\n");
1166 printf(
"InteractiveModule::Finish!\n");
1172 printf(
"InteractiveModule::NewRun, run %d, file %s\n", runinfo->
fRunNo, runinfo->
fFileName.c_str());
1179 printf(
"\nUsage:\n");
1180 printf(
"\n./analyzer.exe [-h] [-R8081] [-oOutputfile.mid] [file1 file2 ...] [-- arguments passed to modules ...]\n");
1182 printf(
"\t-h: print this help message\n");
1183 printf(
"\t-Hhostname: connect to MIDAS experiment on given host\n");
1184 printf(
"\t-Eexptname: connect to this MIDAS experiment\n");
1185 printf(
"\t-oOutputfile.mid: write selected events into this file\n");
1186 printf(
"\t-Rnnnn: Start the ROOT THttpServer HTTP server on specified tcp port, access by firefox http://localhost:8081\n");
1187 printf(
"\t-Xnnnn: Start the Xml server on specified tcp port (for use with roody -Xlocalhost:9091)\n");
1188 printf(
"\t-Pnnnn: Start the TNetDirectory server on specified tcp port (for use with roody -Plocalhost:9091)\n");
1189 printf(
"\t-eNNN: Number of events to analyze\n");
1190 printf(
"\t-sNNN: Number of events to skip before starting analysis\n");
1191 printf(
"\t--dump: activate the event dump module\n");
1192 printf(
"\t-t: Enable tracing of constructors, destructors and function calls\n");
1193 printf(
"\t-m: Enable memory leak debugging\n");
1194 printf(
"\t-g: Enable graphics display when processing data files\n");
1195 printf(
"\t-i: Enable intractive mode\n");
1196 printf(
"\t--: All following arguments are passed to the analyzer modules Init() method\n");
1198 printf(
"Example1: analyze online data: ./analyzer.exe -P9091\n");
1199 printf(
"Example2: analyze existing data: ./analyzer.exe /data/alpha/current/run00500.mid\n");
1207 setbuf(stdout, NULL);
1208 setbuf(stderr, NULL);
1210 signal(SIGILL, SIG_DFL);
1211 signal(SIGBUS, SIG_DFL);
1212 signal(SIGSEGV, SIG_DFL);
1213 signal(SIGPIPE, SIG_DFL);
1215 std::vector<std::string> args;
1216 for (
int i=0; i<argc; i++) {
1217 if (strcmp(argv[i],
"-h")==0)
1219 args.push_back(argv[i]);
1225 const char* hostname = NULL;
1226 const char* exptname = NULL;
1229 int num_analyze = 0;
1233 bool event_dump =
false;
1234 bool root_graphics =
false;
1235 bool interactive =
false;
1237 std::vector<std::string> files;
1238 std::vector<std::string> modargs;
1240 for (
unsigned int i=1; i<args.size(); i++) {
1241 const char* arg = args[i].c_str();
1244 if (args[i] ==
"--") {
1245 for (
unsigned j=i+1; j<args.size(); j++)
1246 modargs.push_back(args[j]);
1248 }
else if (args[i] ==
"--dump") {
1250 }
else if (args[i] ==
"-g") {
1251 root_graphics =
true;
1252 }
else if (args[i] ==
"-i") {
1254 }
else if (args[i] ==
"-t") {
1258 }
else if (strncmp(arg,
"-o",2)==0) {
1260 }
else if (strncmp(arg,
"-s",2)==0) {
1261 num_skip = atoi(arg+2);
1262 }
else if (strncmp(arg,
"-e",2)==0) {
1263 num_analyze = atoi(arg+2);
1264 }
else if (strncmp(arg,
"-m",2)==0) {
1266 }
else if (strncmp(arg,
"-P",2)==0) {
1267 tcpPort = atoi(arg+2);
1268 }
else if (strncmp(arg,
"-X",2)==0) {
1269 xmlTcpPort = atoi(arg+2);
1270 }
else if (strncmp(arg,
"-R",2)==0) {
1271 httpPort = atoi(arg+2);
1272 }
else if (strncmp(arg,
"-H",2)==0) {
1273 hostname = strdup(arg+2);
1274 }
else if (strncmp(arg,
"-E",2)==0) {
1275 exptname = strdup(arg+2);
1276 }
else if (strcmp(arg,
"-h")==0) {
1278 }
else if (arg[0] ==
'-') {
1281 files.push_back(args[i]);
1286 gModules =
new std::vector<TAModuleInterface*>;
1288 if ((*gModules).size() == 0)
1297 printf(
"Registered modules: %d\n", (
int)(*gModules).size());
1300 if (root_graphics) {
1308 #ifdef XHAVE_LIBNETDIRECTORY
1315 fprintf(stderr,
"ERROR: No support for the TNetDirectory server!\n");
1318 #ifdef HAVE_XMLSERVER
1322 s->
Start(xmlTcpPort);
1323 s->
Export(gROOT,
"ROOT");
1329 fprintf(stderr,
"ERROR: No support for the XML Server!\n");
1333 #ifdef HAVE_THTTP_SERVER
1335 sprintf(str,
"http:127.0.0.1:%d", httpPort);
1336 THttpServer *s =
new THttpServer(str);
1340 fprintf(stderr,
"ERROR: No support for the THttpServer!\n");
1344 for (
unsigned i=0; i<files.size(); i++) {
1345 printf(
"file[%d]: %s\n", i, files[i].c_str());
1348 if (files.size() > 0) {
int odbReadArraySize(const char *name)
int odbReadInt(const char *name, int index=0, int defaultValue=0)
double odbReadDouble(const char *name, int index=0, double defaultValue=0)
bool odbReadBool(const char *name, int index=0, bool defaultValue=false)
int odbReadAny(const char *name, int index, int tid, void *buf, int bufsize=0)
uint32_t odbReadUint32(const char *name, int index=0, uint32_t defaultValue=0)
float odbReadFloat(const char *name, int index=0, float defaultValue=0)
const char * odbReadString(const char *name, int index=0, const char *defaultValue=NULL)
TARunInterface * NewRun(TARunInfo *runinfo)
void Init(const std::vector< std::string > &args)
void AnalyzeSpecialEvent(TARunInfo *runinfo, TMEvent *event)
void BeginRun(TARunInfo *runinfo)
TAFlowEvent * Analyze(TARunInfo *runinfo, TMEvent *event, TAFlags *flags, TAFlowEvent *flow)
void PauseRun(TARunInfo *runinfo)
void EndRun(TARunInfo *runinfo)
EventDumpRun(TARunInfo *runinfo)
void ResumeRun(TARunInfo *runinfo)
void Init(const std::vector< std::string > &args)
TARunInterface * NewRun(TARunInfo *runinfo)
void ResumeRun(TARunInfo *runinfo)
static MainWindow * fgCtrlWindow
InteractiveRun(TARunInfo *runinfo)
void BeginRun(TARunInfo *runinfo)
void AnalyzeSpecialEvent(TARunInfo *runinfo, TMEvent *event)
void EndRun(TARunInfo *runinfo)
void PauseRun(TARunInfo *runinfo)
TAFlowEvent * Analyze(TARunInfo *runinfo, TMEvent *event, TAFlags *flags, TAFlowEvent *flow)
TGLayoutHints * menuBarItemLayout
TGLayoutHints * menuBarLayout
MainWindow(const TGWindow *w, int s1, int s2, XCtrl *ctrl)
Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
void Event(const void *data, int data_size)
void Transition(int transition, int run_number, int transition_time)
TMWriterInterface * fWriter
OnlineHandler(int num_analyze, TMWriterInterface *writer)
void StartRun(int run_number)
std::vector< TARunInterface * > fRunRun
std::vector< TARunObject * > fRunRun
void AnalyzeEvent(TMEvent *event, TAFlags *flags, TMWriterInterface *writer)
void CreateRun(int run_number, const char *file_name)
void AnalyzeSpecialEvent(TMEvent *event)
void EndRun(TAFlags *flags)
virtual void Init(const std::vector< std::string > &args)
TARegisterModule(TAModuleInterface *m)
static TApplication * fgApp
static THttpServer * fgHttpServer
static XmlServer * fgXmlServer
static TDirectory * fgDir
virtual void EndRun(TARunInfo *runinfo)
virtual void PauseRun(TARunInfo *runinfo)
virtual TAFlowEvent * Analyze(TARunInfo *runinfo, TMEvent *event, TAFlags *flags, TAFlowEvent *flow)
virtual void AnalyzeSpecialEvent(TARunInfo *runinfo, TMEvent *event)
virtual void ResumeRun(TARunInfo *runinfo)
virtual void BeginRun(TARunInfo *runinfo)
virtual Bool_t cd(const char *path=0)
std::string HeaderToString() const
print the MIDAS event header
uint32_t serial_number
MIDAS event serial number.
uint32_t data_size
MIDAS event data size.
uint16_t event_id
MIDAS event ID.
MIDAS online connection, including access to online ODB.
void RegisterHandler(TMHandlerInterface *h)
void registerTransitions()
Ask MIDAS to tell us about run transitions.
int disconnect()
Disconnect from MIDAS.
static TMidasOnline * instance()
int connect(const char *hostname, const char *exptname, const char *progname)
Connect to MIDAS experiment.
int eventRequest(const char *bufferName, int eventId, int triggerMask, int samplingType, bool poll=false)
Request data for delivery via callback (setEventHandler) or by polling (via receiveEvent)
Access to ODB saved in XML format inside midas .mid files.
void Export(TDirectory *dir, const char *exportName)
void SetVerbose(bool verbose)
void TMWriteEvent(TMWriterInterface *writer, const TMEvent *event)
TMReaderInterface * TMNewReader(const char *source)
TMWriterInterface * TMNewWriter(const char *destination)
TMEvent * TMReadEvent(TMReaderInterface *reader)
static int ProcessMidasFiles(const std::vector< std::string > &files, const std::vector< std::string > &args, int num_skip, int num_analyze, TMWriterInterface *writer)
static int ProcessMidasOnline(const std::vector< std::string > &args, const char *hostname, const char *exptname, int num_analyze, TMWriterInterface *writer)
int manalyzer_main(int argc, char *argv[])
static bool gEnableShowMem
std::vector< TAModuleInterface * > * gModules
void NetDirectoryExport(TDirectory *dir, const char *exportName)
void VerboseNetDirectoryServer(bool verbose)
void StartNetDirectoryServer(int port, TDirectory *dir)
int ShowMem(const char *label)