14 #ifdef HAVE_LIBNETDIRECTORY
17 #ifdef HAVE_THTTP_SERVER
18 #include "THttpServer.h"
52 struct timeval nowTime;
53 gettimeofday(&nowTime, NULL);
55 double dtime = nowTime.tv_sec -
raLastTime.tv_sec + (nowTime.tv_usec -
raLastTime.tv_usec)/1000000.0;
63 printf(
"Skipped %i events that were too old (>1sec old) out of %i events\n",
81 std::cerr <<
"Singleton Not Instantiated! "
82 <<
" Need to call something like SomeClass::CreateSingleton<SomeClass>(); Exiting!"
89 #ifdef HAVE_THTTP_SERVER
90 THttpServer* gRoot_http_serv = 0;
118 fApp =
new TApplication(
"rootana", 0, argv2);
160 #ifdef HAVE_THTTP_SERVER
161 if(gRoot_http_serv) gRoot_http_serv->SetReadOnly(!readwrite);
165 #ifdef HAVE_THTTP_SERVER
166 THttpServer* TRootanaEventLoop::GetTHttpServer(){
167 return gRoot_http_serv;
175 printf(
"\nUsage:\n");
176 printf(
"\n./analyzer.exe [-h] [-Hhostname] [-Eexptname] [-eMaxEvents] [-P9091] [-p9090] [-m] [file1 file2 ...]\n");
178 printf(
"\t-h: print this help message\n");
179 printf(
"\t-T: test mode - start and serve a test histogram\n");
180 printf(
"\t-D: Become a daemon\n");
181 printf(
"\t-Hhostname: connect to MIDAS experiment on given host\n");
182 printf(
"\t-Eexptname: connect to this MIDAS experiment\n");
183 printf(
"\t-bbuffer: connect to this MIDAS buffer\n");
184 printf(
"\t-P: Start the TNetDirectory server on specified tcp port (for use with roody -Plocalhost:9091)\n");
185 printf(
"\t-p: Start the old midas histogram server on specified tcp port (for use with roody -Hlocalhost:9090)\n");
186 #ifdef HAVE_THTTP_SERVER
187 printf(
"\t-r: Start THttpServer on specified tcp port\n");
189 printf(
"\t-eXXX: Number of events XXX to read from input data files\n");
194 printf(
"Example1: analyze online data: ./analyzer.exe -P9091\n");
195 printf(
"Example2: analyze existing data: ./analyzer.exe /data/alpha/current/run00500.mid\n");
212 if ((pid = fork()) < 0)
221 for (i = 0; i < 3; i++) {
223 fd = open(
"/dev/null", O_RDWR, 0);
225 fd = open(
"/dev/null", O_WRONLY, 0);
227 std::cout <<
"Can't open /dev/null" << std::endl;
231 std::cout <<
"Did not get file descriptor" << std::endl;
249 signal(SIGILL, SIG_DFL);
250 signal(SIGBUS, SIG_DFL);
251 signal(SIGSEGV, SIG_DFL);
253 std::vector<std::string> args;
254 for (
int i=0; i<argc; i++)
256 if (strcmp(argv[i],
"-h")==0)
258 args.push_back(argv[i]);
268 printf(
"Cannot run without X-window support; this program is not setup to run in batch mode\n");
272 bool testMode =
false;
273 bool daemonMode =
false;
275 #ifdef HAVE_THTTP_SERVER
279 const char* hostname = NULL;
280 const char* exptname = NULL;
282 for (
unsigned int i=1; i<args.size(); i++)
284 const char* arg = args[i].c_str();
287 if (strncmp(arg,
"-e",2)==0)
289 else if (strncmp(arg,
"-m",2)==0)
291 else if (strncmp(arg,
"-P",2)==0)
292 tcpPort = atoi(arg+2);
293 #ifdef HAVE_THTTP_SERVER
294 else if (strncmp(arg,
"-r",2)==0)
295 rhttpdPort = atoi(arg+2);
297 else if (strcmp(arg,
"-T")==0)
299 else if (strcmp(arg,
"-D")==0)
302 else if (strncmp(arg,
"-H",2)==0)
303 hostname = strdup(arg+2);
304 else if (strncmp(arg,
"-E",2)==0)
305 exptname = strdup(arg+2);
307 else if (strncmp(arg,
"-b",2)==0){
309 }
else if (strcmp(arg,
"-h")==0)
311 else if(arg[0] ==
'-')
320 for (
unsigned int i=1; i<args.size(); i++){
321 const char* arg = args[i].c_str();
329 printf(
"\nBecoming a daemon...\n");
335 std::cout <<
"Create main window! " << std::endl;
336 mainWindow =
new MainWindow(gClient->GetRoot(), 200, 300);
342 #ifdef HAVE_LIBNETDIRECTORY
347 fprintf(stderr,
"ERROR: No support for the TNetDirectory server!\n");
350 #ifdef HAVE_THTTP_SERVER
353 sprintf(address,
"http:%i",rhttpdPort);
354 gRoot_http_serv =
new THttpServer(address);
365 for (
unsigned int i=1; i<args.size(); i++){
366 const char* arg = args[i].c_str();
374 std::cout <<
"Entering test mode." << std::endl;
376 TH1D* hh =
new TH1D(
"test",
"test", 100, 0, 100);
412 printf(
"Cannot open input file \"%s\"\n",fname);
432 if ((eventId & 0xFFFF) == 0x8000){
446 }
else if ((eventId & 0xFFFF) == 0x8001){
452 }
else if ((eventId & 0xFFFF) == 0x8002){
455 printf(
"Log message: %s\n", event.
GetData());
479 printf(
"Reached event %d, exiting loop.\n",i);
521 if(midasFilename.compare(
"") != 0){
523 if(fullname.compare(
"") != 0){
524 sprintf(filename,
"%s",fullname.c_str());
529 std::cout <<
"Opened output file with name : " << filename << std::endl;
532 #ifdef HAVE_LIBNETDIRECTORY
541 std::cout <<
"Closing ROOT file "
599 printf(
"onlineEventHandler Warning: Output ROOT file is not validly open, so can't fill histograms. Have skipped %i events now.\n",
616 gettimeofday(&now, NULL);
625 printf(
"You are running in 'Only Recent Data' mode, but you haven't gotten any new data in more than 5 seconds.\n");
626 printf(
"Disabling 'Only Recent Data' mode for this run.\n");
641 event.SetData(size, (
char*)pdata);
670 gettimeofday(&now, NULL);
674 printf(
"onlineEventHandler Warning: the time for this bank (%i) is more than 10 sec older \nthan current time (%i). Has happenned %i times now.",
676 printf(
"Either the analyzer is falling behind the data taking \n(try modifying the fraction of events plotted) or times on different computers are not synchronized.\n");
680 printf(
"Buffer level = %i bytes out of %i bytes maximum \n\n",buffer_level,buffer_size);
727 fprintf(stderr,
"Cannot connect to MIDAS, error %d\n", err);
760 std::cout <<
"Using 'Only Recent Data' mode; all events more than 1 second old will be discarded." << std::endl;
struct timeval lastTimeProcessed
int raTotalEventsProcessed
bool disableOnlyRecentMode
void onlineEndRunHandler(int transition, int run, int time)
void MidasPollHandlerLocal()
double nextWarnTimestamps
static bool onlineEventLock
void onlineBeginRunHandler(int transition, int run, int time)
void onlineEventHandler(const void *pheader, const void *pdata, int size)
int raTotalEventsSkippedForAge
struct timeval raLastTime
Little function for printing the number of processed events and processing rate.
virtual void RI(const char *varname, int *value, bool create=false, MVOdbError *error=NULL)=0
void SetMidasEventPointer(TMidasEvent &event)
virtual Bool_t cd(const char *path=0)
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 GetTimeStamp() const
return the time stamp (unix time in seconds)
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 getBufferLevel()
Get buffer level (ie the number of bytes in buffer)
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 getBufferSize()
Get buffer size.
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)
TFile * fOutputFile
Output ROOT file.
bool fDisableRootOutput
Variable for disabling/enabling Root output.
std::string fBufferName
Buffer to connect to.
virtual ~TRootanaEventLoop()
static TRootanaEventLoop & Get(void)
bool fIsOffline
Are we processing offline or online data?
virtual void Initialize(void)
virtual bool CheckOptionRAD(std::string option)
virtual bool ProcessMidasEvent(TDataContainer &dataContainer)=0
void PrintHelp()
Help Message.
void SetCurrentRunNumber(int run)
Current Run Number.
TDataContainer * fDataContainer
std::string fOutputFilename
void UseOnlyRecent(bool setting=true)
void OpenRootFile(int run, std::string midasFilename=std::string(""))
Open output ROOT file.
std::vector< int > fProcessEventIDs
This is the set of eventIDs to process.
virtual void BeginRun(int transition, int run, int time)
virtual std::string SetFullOutputFileName(int run, std::string midasFilename)
virtual bool CheckOption(std::string option)
int fCurrentRunNumber
Current run number.
int ExecuteLoop(int argc, char *argv[])
Method to actually process the Midas information, either as file or online.
bool CheckEventID(int eventId)
Little helper method to check if EventID matchs requested EventID list.
static TRootanaEventLoop * fTRootanaEventLoop
The static pointer to the singleton instance.
void CloseRootFile()
Cloe output ROOT file.
virtual void UsageRAD(void)
Also a special version of usage for TRootanaDisplay. See CheckOptionRAD.
bool fSuppressTimestampWarnings
Bool for suppressing the warnings about old timestamps.
MVOdb * fODB
Pointer to the ODB access instance.
virtual void EndRun(int transition, int run, int time)
virtual void BeginRunRAD(int transition, int run, int time)
virtual void InitializeRAD(void)
Special version of Init method, to be used only by TRootanaDisplay.
virtual void EndRunRAD(int transition, int run, int time)
Also special version of EOR method, to be used only by TRootanaDisplay.
int ProcessMidasOnline(TApplication *app, const char *hostname, const char *exptname)
TDataContainer * GetDataContainer()
Method to get the data container that event loop owns.
std::string fOnlineName
Name of program, as seen by MIDAS.
void SetTHttpServerReadWrite(bool readwrite=true)
TDirectory * fOnlineHistDir
TDirectory for online histograms.
virtual bool PreFilter(TDataContainer &dataContainer)
int ProcessMidasFile(TApplication *app, const char *fname)
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.
void NetDirectoryExport(TDirectory *dir, const char *exportName)
void StartNetDirectoryServer(int port, TDirectory *dir)
uint32_t fTimeStamp
event timestamp in seconds