22 #ifdef HAVE_MIDASSERVER
25 #ifdef HAVE_LIBNETDIRECTORY
35 #include <TApplication.h>
38 #include <TDirectory.h>
65 gettimeofday(&tv,NULL);
66 return tv.tv_sec + 0.000001*tv.tv_usec;
81 assert(handler != NULL);
85 Start(period_msec,kTRUE);
130 sprintf(filename,
"output%05d.root", run);
142 #ifdef HAVE_LIBNETDIRECTORY
147 void endRun(
int transition,
int run,
int time)
152 #ifdef HAVE_MIDASSERVER
166 printf(
"End of run %d\n",run);
176 uint16_t *samples = (uint16_t*) ptr;
177 int numSamples = wsize;
179 if (numSamples != 512)
183 sprintf(name,
"channel%d", ichan);
192 printf(
"Create [%s]\n", name);
193 samplePlot =
new TH1D(name, name, numSamples, 0, numSamples);
195 #ifdef HAVE_MIDASSERVER
201 for(
int ti=0; ti<numSamples; ti++)
202 samplePlot->SetBinContent(ti, samples[ti]);
209 int eventId =
event.GetEventId();
211 if (
false&&(eventId == 1))
214 int size =
event.LocateBank(NULL,
"CHA3", &ptr);
226 else if (
false&&(eventId == 2)&&(
gIsRunning==
true))
254 event.SetData(size, (
char*)pdata);
265 printf(
"Cannot open input file \"%s\"\n",fname);
280 if ((eventId & 0xFFFF) == 0x8000)
299 else if ((eventId & 0xFFFF) == 0x8001)
304 else if ((eventId & 0xFFFF) == 0x8002)
308 printf(
"Log message: %s\n", event.
GetData());
320 printf(
"Processing event %d\n",i);
328 printf(
"Reached event %d, exiting loop.\n",i);
354 #define TApplication void*
361 int err = midas->
connect(hostname, exptname,
"rootana");
364 fprintf(stderr,
"Cannot connect to MIDAS, error %d\n", err);
384 gOdb->
RI(
"runinfo/State", &runstate);
432 #define M_FILE_EXIT 0
437 switch (GET_MSG(msg))
442 switch (GET_SUBMSG(msg))
470 SetWindowName(
"ROOT Analyzer Control");
473 menuFile =
new TGPopupMenu(gClient->GetRoot());
476 menuBarItemLayout =
new TGLayoutHints(kLHintsTop|kLHintsLeft, 0, 4, 0, 0);
478 menuFile->Associate(
this);
481 menuBar =
new TGMenuBar(
this, 1, 1, kRaisedFrame);
482 menuBar->AddPopup(
"&File", menuFile, menuBarItemLayout);
486 menuBarLayout =
new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX);
487 AddFrame(menuBar,menuBarLayout);
518 FILE* fp = fopen(
"/proc/self/statm",
"r");
523 fscanf(fp,
"%d",&mem);
527 printf(
"memory at %s is %d\n", label, mem);
534 printf(
"\nUsage:\n");
535 printf(
"\n./analyzer.exe [-h] [-Hhostname] [-Eexptname] [-eMaxEvents] [-P9091] [-p9090] [-m] [-g] [file1 file2 ...]\n");
537 printf(
"\t-h: print this help message\n");
538 printf(
"\t-T: test mode - start and serve a test histogram\n");
539 printf(
"\t-Hhostname: connect to MIDAS experiment on given host\n");
540 printf(
"\t-Eexptname: connect to this MIDAS experiment\n");
541 printf(
"\t-P: Start the TNetDirectory server on specified tcp port (for use with roody -Plocalhost:9091)\n");
542 printf(
"\t-p: Start the old midas histogram server on specified tcp port (for use with roody -Hlocalhost:9090)\n");
543 printf(
"\t-e: Number of events to read from input data files\n");
544 printf(
"\t-m: Enable memory leak debugging\n");
545 printf(
"\t-g: Enable graphics display when processing data files\n");
547 printf(
"Example1: analyze online data: ./analyzer.exe -P9091\n");
548 printf(
"Example2: analyze existing data: ./analyzer.exe /data/alpha/current/run00500.mid\n");
554 int main(
int argc,
char *argv[])
559 signal(SIGILL, SIG_DFL);
560 signal(SIGBUS, SIG_DFL);
561 signal(SIGSEGV, SIG_DFL);
562 signal(SIGPIPE, SIG_DFL);
564 std::vector<std::string> args;
565 for (
int i=0; i<argc; i++)
567 if (strcmp(argv[i],
"-h")==0)
569 args.push_back(argv[i]);
573 TApplication *app =
new TApplication(
"rootana", &argc, argv);
575 if(gROOT->IsBatch()) {
576 printf(
"Cannot run in batch mode\n");
581 TApplication *app = NULL;
586 bool testMode =
false;
591 const char* hostname = NULL;
592 const char* exptname = NULL;
594 for (
unsigned int i=1; i<args.size(); i++)
596 const char* arg = args[i].c_str();
599 if (strncmp(arg,
"-e",2)==0)
601 else if (strncmp(arg,
"-m",2)==0)
603 else if (strncmp(arg,
"-p",2)==0)
604 oldTcpPort = atoi(arg+2);
605 else if (strncmp(arg,
"-P",2)==0)
606 tcpPort = atoi(arg+2);
607 else if (strncmp(arg,
"-X",2)==0)
608 xmlTcpPort = atoi(arg+2);
609 else if (strcmp(arg,
"-T")==0)
614 else if (strncmp(arg,
"-H",2)==0)
615 hostname = strdup(arg+2);
616 else if (strncmp(arg,
"-E",2)==0)
617 exptname = strdup(arg+2);
619 else if (strcmp(arg,
"-h")==0)
621 else if (arg[0] ==
'-')
626 MainWindow mainWindow(gClient->GetRoot(), 200, 300);
631 #ifdef HAVE_MIDASSERVER
636 fprintf(stderr,
"ERROR: No support for the old midas server!\n");
638 #ifdef HAVE_LIBNETDIRECTORY
643 fprintf(stderr,
"ERROR: No support for the TNetDirectory server!\n");
645 #ifdef HAVE_XMLSERVER
651 xmlServer->
Start(xmlTcpPort);
656 fprintf(stderr,
"ERROR: No support for the XML Server!\n");
662 for (
unsigned int i=1; i<args.size(); i++)
664 const char* arg = args[i].c_str();
679 TH1D* hh =
new TH1D(
"test",
"test", 100, 0, 100);
R__EXTERN TDirectory * gDirectory
void HandleMidasEvent(TMidasEvent &event)
int main(int argc, char *argv[])
void HandleSample(int ichan, void *ptr, int wsize)
void eventHandler(const void *pheader, const void *pdata, int size)
TDirectory * gOnlineHistDir
void startRun(int transition, int run, int time)
int ProcessMidasOnline(TApplication *app, const char *hostname, const char *exptname)
static bool gEnableShowMem
void endRun(int transition, int run, int time)
int ShowMem(const char *label)
int ProcessMidasFile(const char *fname)
virtual void RI(const char *varname, int *value, bool create=false, MVOdbError *error=NULL)=0
virtual void RB(const char *varname, bool *value, bool create=false, MVOdbError *error=NULL)=0
virtual void CloseWindow()
TGLayoutHints * menuBarItemLayout
TGLayoutHints * menuBarLayout
virtual void CloseWindow()
Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
MainWindow(const TGWindow *w, int s1, int s2)
void(* TimerHandler)(void)
MyPeriodic(int period_msec, TimerHandler handler)
virtual Bool_t cd(const char *path=0)
virtual TObject * Get(const char *namecycle)
TMidas_EVENT_HEADER * GetEventHeader()
return pointer to the event header
uint32_t GetDataSize() const
return the event size
uint16_t GetEventId() const
return the event id
uint32_t GetSerialNumber() const
return the serial number
char * GetData()
return pointer to the data buffer
void setEventHandler(EventHandler handler)
Specify user handler for data events.
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.
void setTransitionHandlers(TransitionHandler start, TransitionHandler stop, TransitionHandler pause, TransitionHandler resume)
Specify user handlers for run transitions.
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)
void Export(TDirectory *dir, const char *exportName)
void SetVerbose(bool verbose)
TMReaderInterface * TMNewReader(const char *source)
TMEvent * TMReadEvent(TMReaderInterface *reader)
MVOdb * MakeMidasOdb(int hDB, MVOdbError *error=NULL)
MVOdb * MakeFileDumpOdb(const char *buf, int bufsize, MVOdbError *error=NULL)
Access ODB from a midas file dump. FOrmat could be .xml, .json or .odb.
TFolder * gManaHistosFolder
void StartMidasServer(int port)
void NetDirectoryExport(TDirectory *dir, const char *exportName)
void StartNetDirectoryServer(int port, TDirectory *dir)