/* function: config_item_int16_t * locates the config item, parses the integer, and returns the pointer ret_val_ptr, or NULL on failure * root - parsed configuration * item_name - name of config item to locate * defaultvar - value to use if config item isn't present * ret_val_ptr - pointer for return value storage */ int16_t *config_item_int16_t(cnode *root, const char *item_name, const char *defaultvar, int16_t *ret_val_ptr) { const char *tmp; char *endptr; long int conf_int; if(!(tmp = config_str(root, item_name, defaultvar))) { logmsg(ANDROID_LOG_FATAL,"%s config item needed",item_name); return NULL; } errno = 0; conf_int = strtol(tmp,&endptr,10); if(errno > 0) { logmsg(ANDROID_LOG_FATAL,"%s config item is not numeric: %s (error=%s)",item_name,tmp,strerror(errno)); return NULL; } if(endptr == tmp || *tmp == '\0') { logmsg(ANDROID_LOG_FATAL,"%s config item is not numeric: %s",item_name,tmp); return NULL; } if(*endptr != '\0') { logmsg(ANDROID_LOG_FATAL,"%s config item contains non-numeric characters: %s",item_name,endptr); return NULL; } if(conf_int > INT16_MAX || conf_int < INT16_MIN) { logmsg(ANDROID_LOG_FATAL,"%s config item is too big/small: %d",item_name,conf_int); return NULL; } *ret_val_ptr = conf_int; return ret_val_ptr; }
/* function: config_item_str * locates the config item and returns the pointer to a string, or NULL on failure. Caller frees pointer * root - parsed configuration * item_name - name of config item to locate * defaultvar - value to use if config item isn't present */ char *config_item_str(cnode *root, const char *item_name, const char *defaultvar) { const char *tmp; if(!(tmp = config_str(root, item_name, defaultvar))) { logmsg(ANDROID_LOG_FATAL,"%s config item needed",item_name); return NULL; } return strdup(tmp); }
/* function: config_item_ip * locates the config item, parses the ipv4 address, and returns the pointer ret_val_ptr, or NULL on failure * root - parsed configuration * item_name - name of config item to locate * defaultvar - value to use if config item isn't present * ret_val_ptr - pointer for return value storage */ struct in_addr *config_item_ip(cnode *root, const char *item_name, const char *defaultvar, struct in_addr *ret_val_ptr) { const char *tmp; int status; if(!(tmp = config_str(root, item_name, defaultvar))) { logmsg(ANDROID_LOG_FATAL,"%s config item needed",item_name); return NULL; } status = inet_pton(AF_INET, tmp, ret_val_ptr); if(status <= 0) { logmsg(ANDROID_LOG_FATAL,"invalid IPv4 address specified for %s: %s", item_name, tmp); return NULL; } return ret_val_ptr; }
int main( int argc, char* argv[] ) { DrawTools::setStyle(); std::string tag = "V00"; std::string config = "SiPM2015Config"; if( argc>1 ) { std::string tag_str(argv[1]); tag = tag_str; if( argc>2 ) { std::string config_str(argv[2]); config=config_str; } } else { std::cout << "Usage:" << std::endl; std::cout << "./plotterMaps ([tag]) ([config])" << std::endl; exit(12345); } std::cout<<config<<std::endl; theConfiguration_=readConfiguration(config); std::string constDirName = "plots_Simplemaps_"; constDirName+=theConfiguration_.setup; if(theConfiguration_.addTagFileName){ constDirName+="_"; constDirName+=theConfiguration_.tagFileName; } system(Form("mkdir -p %s", constDirName.c_str())); TString dir(constDirName); TString filename= "plots_timingPerformance_"+theConfiguration_.setup+"/mapCreatorOutput_"+tag+".root"; TFile* file = TFile::Open(filename.Data()); std::map<TString,TH1F*> histoNames; std::map<TString,TH2F*> histoNames2D; TList* list = file->GetListOfKeys() ; if (!list) { printf("<E> No keys found in file\n") ; exit(1) ; } TIter next(list) ; TKey* key ; TObject* obj ; while ( key = (TKey*)next() ) { obj = key->ReadObj() ; if ( (strcmp(obj->IsA()->GetName(),"TProfile")!=0) && (!obj->InheritsFrom("TH2")) && (!obj->InheritsFrom("TH1")) ) { printf("<W> Object %s is not 1D or 2D histogram : " "will not be converted\n",obj->GetName()) ; } printf("Histo name:%s title:%s\n",obj->GetName(),obj->GetTitle()); if((strcmp(obj->IsA()->GetName(),"TH1F"))==0){ histoNames[obj->GetName()]=(TH1F*)obj; }else if ((strcmp(obj->IsA()->GetName(),"TH2F"))==0){ histoNames2D[obj->GetName()]=(TH2F*)obj; } } for(std::map<TString,TH2F*>::const_iterator out=histoNames2D.begin();out!=histoNames2D.end();++out){ gStyle->SetPadRightMargin(0.19);//for the palette and ztitle TCanvas c1; TH2F* histo=(TH2F*)out->second->Clone(out->first+"_clone"); histo->GetZaxis()->SetTitleOffset(1.4); if(out->first.Contains("amplitude"))histo->SetZTitle("Amplitude [ADC]"); if(out->first.Contains("timing"))histo->SetZTitle("#DeltaT [ns]"); histo->Draw("colz"); c1.SaveAs(dir+"/"+out->first+".pdf"); c1.SaveAs(dir+"/"+out->first+".png"); } gStyle->SetPadRightMargin(0.10); TH1F* maxAmpl_sel_fibre=(TH1F*)file->Get("maxAmpl_sel_fibre"); TH1F* maxAmpl_sel_channel=(TH1F*)file->Get("maxAmpl_sel_channel"); TCanvas c2; maxAmpl_sel_channel->GetXaxis()->SetRangeUser(0,800.); maxAmpl_sel_channel->SetLineWidth(2); maxAmpl_sel_fibre->SetLineWidth(2); maxAmpl_sel_channel->DrawNormalized(); maxAmpl_sel_fibre->DrawNormalized("same"); TPaveText* pave = DrawTools::getLabelTop_expOnXaxis("Electron Beam"); pave->Draw("same"); c2.SaveAs(dir+"/maxAmpl_comparison.pdf"); c2.SaveAs(dir+"/maxAmpl_comparison.png"); }
static int client_setup_file(CONTEXT *ctx, char *who) { char *p; u_int16_t l, u; /* ** little bit sanity check */ if( !(ctx && who && *who)) { return -1; } /* ** Inform the auditor that we are using the config file */ syslog_write(U_INF, "reading data for '%s' from cfg-file", who); /* ** Evaluate DestinationAddress, except we have magic_addr */ if (INADDR_ANY != ctx->magic_addr) { ctx->srv_addr = ctx->magic_addr; } else { ctx->srv_addr = config_addr(who, "DestinationAddress", INADDR_ANY); #if defined(COMPILE_DEBUG) debug(2, "file DestAddr for %s: '%s'", ctx->cli_ctrl->peer, socket_addr2str(ctx->srv_addr)); #endif } /* ** Evaluate DestinationPort, except we have magic_port */ if (INPORT_ANY != ctx->magic_port) { ctx->srv_port = ctx->magic_port; } else { ctx->srv_port = config_port(who, "DestinationPort", IPPORT_FTP); #if defined(COMPILE_DEBUG) debug(2, "file DestPort for %s: %d", ctx->cli_ctrl->peer, (int) ctx->srv_port); #endif } /* ** Evaluate the destination transfer mode */ p = config_str(who, "DestinationTransferMode", "client"); if(0 == strcasecmp(p, "active")) { ctx->srv_mode = MOD_ACT_FTP; } else if(0 == strcasecmp(p, "passive")) { ctx->srv_mode = MOD_PAS_FTP; } else if(0 == strcasecmp(p, "client")) { ctx->srv_mode = MOD_CLI_FTP; } else { syslog_error("can't eval DestMode for %s", ctx->cli_ctrl->peer); return -1; } #if defined(COMPILE_DEBUG) debug(2, "file DestMode for %s: %s", ctx->cli_ctrl->peer, p); #endif /* ** Evaluate min/max destination port range */ l = config_port(who, "DestinationMinPort", INPORT_ANY); u = config_port(who, "DestinationMaxPort", INPORT_ANY); if (l > 0 && u > 0 && u >= l) { ctx->srv_lrng = l; ctx->srv_urng = u; } else { ctx->srv_lrng = INPORT_ANY; ctx->srv_urng = INPORT_ANY; } #if defined(COMPILE_DEBUG) debug(2, "file DestRange for %s: %u-%u", ctx->cli_ctrl->peer, ctx->srv_lrng, ctx->srv_urng); #endif /* ** Evaluate min/max active port range */ l = config_port(who, "ActiveMinDataPort", INPORT_ANY); u = config_port(who, "ActiveMaxDataPort", INPORT_ANY); if (l > 0 && u > 0 && u >= l) { ctx->act_lrng = l; ctx->act_urng = u; } else { /* do not try to bind a port < 1024 if running as UID != 0 */ if(0 == getuid()) { ctx->act_lrng = (IPPORT_FTP - 1); ctx->act_urng = (IPPORT_FTP - 1); } else { ctx->act_lrng = INPORT_ANY; ctx->act_urng = INPORT_ANY; } } #if defined(COMPILE_DEBUG) debug(2, "file ActiveRange for %s: %u-%u", ctx->cli_ctrl->peer, ctx->act_lrng, ctx->act_urng); #endif /* ** Evaluate min/max passive port range */ l = config_port(who, "PassiveMinDataPort", INPORT_ANY); u = config_port(who, "PassiveMaxDataPort", INPORT_ANY); if (l > 0 && u > 0 && u >= l) { ctx->pas_lrng = l; ctx->pas_urng = u; } else { ctx->pas_lrng = INPORT_ANY; ctx->pas_urng = INPORT_ANY; } #if defined(COMPILE_DEBUG) debug(2, "file PassiveRange for %s: %u-%u", ctx->cli_ctrl->peer, ctx->pas_lrng, ctx->pas_urng); #endif /* ** Setup other configuration options */ ctx->same_adr = config_bool(who, "SameAddress", 1); ctx->timeout = config_int (who, "TimeOut", 900); #if defined(COMPILE_DEBUG) debug(2, "file SameAddress for %s: %s", ctx->cli_ctrl->peer, ctx->same_adr ? "yes" : "no"); debug(2, "file TimeOut for %s: %d", ctx->cli_ctrl->peer, ctx->timeout); #endif /* ** Adjust the allow/deny flags for the commands */ p = config_str(who, "ValidCommands", NULL); cmds_set_allow(p); return 0; }
void client_run(void) { int sock, need, diff; char str[MAX_PATH_SIZE * 2]; char *p, *q; FILE *fp; BUF *buf; /* ** Setup client signal handling (mostly graceful exit) */ signal(SIGINT, client_signal); signal(SIGTERM, client_signal); signal(SIGQUIT, client_signal); signal(SIGHUP, client_signal); signal(SIGCHLD, SIG_IGN); signal(SIGUSR1, SIG_IGN); /* ** Prepare our general client context */ memset(&ctx, 0, sizeof(ctx)); ctx.sess_beg = time(NULL); ctx.cli_mode = MOD_ACT_FTP; ctx.expect = EXP_IDLE; ctx.timeout = config_int(NULL, "TimeOut", 900); sock = fileno(stdin); /* "recover" our socket */ /* ** Check whether a DenyMessage file exists. This ** indicates that we are currently not willing ** to serve any clients. */ p = config_str(NULL, "DenyMessage", NULL); if (p != NULL && (fp = fopen(p, "r")) != NULL) { while (fgets(str, sizeof(str) - 4, fp) != NULL) { p = socket_msgline(str); if ((q = strchr(p, '\n')) != NULL) strcpy(q, "\r\n"); else strcat(p, "\r\n"); send(sock, "421-", 4, 0); send(sock, p, strlen(p), 0); } fclose(fp); if ((p = config_str(NULL, "DenyString", NULL)) != NULL) p = socket_msgline(p); else p = "Service not available"; send(sock, "421 ", 4, 0); send(sock, p, strlen(p), 0); send(sock, ".\r\n", 3, 0); p = socket_addr2str(socket_sck2addr(sock, REM_END, NULL)); close(sock); syslog_write(U_ERR, "reject: '%s' (DenyMessage)", p); exit(EXIT_SUCCESS); } /* ** Create a High Level Socket for the client's User-PI */ if ((ctx.cli_ctrl = socket_init(sock)) == NULL) misc_die(FL, "client_run: ?cli_ctrl?"); ctx.cli_ctrl->ctyp = "Cli-Ctrl"; /* ** Announce the connection request */ syslog_write(U_INF, "connect from %s", ctx.cli_ctrl->peer); /* ** Display the welcome message (invite the user to login) */ if ((p = config_str(NULL, "WelcomeString", NULL)) == NULL) p = "%h FTP server (Version %v - %b) ready"; misc_strncpy(str, socket_msgline(p), sizeof(str)); client_respond(220, config_str(NULL, "WelcomeMessage", NULL), str); /* ** Enter the client mainloop */ while (close_flag == 0) { /* ** We need to go into select() only ** if all input has been processed ** or ** we wait for more data to get a line ** complete (partially sent, no EOL). ** ** (data buffers are never splited) */ need = 1; if (ctx.cli_ctrl && ctx.cli_ctrl->rbuf) need = 0; if (ctx.srv_ctrl && ctx.srv_ctrl->rbuf) need = 0; if((ctx.cli_ctrl && ctx.cli_ctrl->more>0) || (ctx.srv_ctrl && ctx.srv_ctrl->more>0)) need = 1; /* ** use higher priority to writes; ** read only if nothing to write... */ if(ctx.srv_data && ctx.cli_data) { if(ctx.srv_data->wbuf) { ctx.cli_data->more = -1; } else { ctx.cli_data->more = 0; } if(ctx.cli_data->wbuf) { ctx.srv_data->more = -1; } else { ctx.srv_data->more = 0; } } if (need != 0) { if (socket_exec(ctx.timeout, &close_flag) <= 0) break; /* Timed out or worse */ } #if defined(COMPILE_DEBUG) debug(4, "client-loop ..."); #endif /* ** Check if any zombie sockets can be removed */ if (ctx.cli_ctrl != NULL && ctx.cli_ctrl->sock == -1) close_flag = 1; /* Oops, forget it ... */ if (ctx.srv_ctrl != NULL && ctx.srv_ctrl->sock == -1) { #if defined(COMPILE_DEBUG) debug(3, "about to destroy Srv-Ctrl"); #endif /* ** If we have any open data connections, ** make really sure they don't survive. */ if (ctx.cli_data != NULL) ctx.cli_data->kill = 1; if (ctx.srv_data != NULL) ctx.srv_data->kill = 1; /* ** Our client should be informed */ if (ctx.cli_ctrl->kill == 0) { client_respond(421, NULL, "Service not available, " "closing control connection"); } /* ** Don't forget to remove the dead socket */ socket_kill(ctx.srv_ctrl); ctx.srv_ctrl = NULL; } if (ctx.cli_data != NULL && ctx.cli_data->sock == -1) { #if defined(COMPILE_DEBUG) debug(3, "about to destroy Cli-Data"); #endif /* ** If we have an outstanding server reply ** (e.g. 226 Transfer complete), send it. */ if (ctx.xfer_rep[0] != '\0') { socket_printf(ctx.cli_ctrl, "%s\r\n", ctx.xfer_rep); memset(ctx.xfer_rep, 0, sizeof(ctx.xfer_rep)); } else { if(ctx.expect == EXP_XFER) ctx.expect = EXP_PTHR; } /* ** Good time for statistics and data reset */ if (ctx.xfer_beg == 0) ctx.xfer_beg = time(NULL); diff = (int) (time(NULL) - ctx.xfer_beg); if (diff < 1) diff = 1; /* ** print our current statistic */ syslog_write(U_INF, "Transfer for %s %s: %s '%s' %s %u/%d byte/sec", ctx.cli_ctrl->peer, ctx.cli_data->ernr ? "failed" : "completed", ctx.xfer_cmd, ctx.xfer_arg, ctx.cli_data->rcnt ? "sent" : "read", ctx.cli_data->rcnt ? ctx.cli_data->rcnt : ctx.cli_data->wcnt, diff); /* ** update session statistics data */ if(ctx.cli_data->rcnt) ctx.xfer_rsec += diff; ctx.xfer_rcnt += ctx.cli_data->rcnt; if(ctx.cli_data->wcnt) ctx.xfer_wsec += diff; ctx.xfer_wcnt += ctx.cli_data->wcnt; /* ** reset data transfer state */ client_data_reset(MOD_RESET); /* ** Doom the corresponding server socket */ if (ctx.srv_data != NULL) ctx.srv_data->kill = 1; /* ** Don't forget to remove the dead socket */ socket_kill(ctx.cli_data); ctx.cli_data = NULL; } if (ctx.srv_data != NULL && ctx.srv_data->sock == -1) { #if defined(COMPILE_DEBUG) debug(3, "about to destroy Srv-Data"); #endif /* ** Doom the corresponding client socket if an ** error occured, FailResetsPasv=yes or we ** expect other response than PASV (Netscape!) */ if(ctx.cli_data != NULL) { if(0 != ctx.srv_data->ernr) { ctx.cli_data->ernr = -1; ctx.cli_data->kill = 1; } if(config_bool(NULL,"FailResetsPasv", 0)) { ctx.cli_data->kill = 1; } else if(ctx.expect != EXP_PASV) { ctx.cli_data->kill = 1; } } /* ** Don't forget to remove the dead socket */ socket_kill(ctx.srv_data); ctx.srv_data = NULL; } /* ** Serve the control connections */ if (ctx.cli_ctrl != NULL && ctx.cli_ctrl->rbuf != NULL) { if (socket_gets(ctx.cli_ctrl, str, sizeof(str)) != NULL) client_cli_ctrl_read(str); } if (ctx.srv_ctrl != NULL && ctx.srv_ctrl->rbuf != NULL) { if (socket_gets(ctx.srv_ctrl, str, sizeof(str)) != NULL) client_srv_ctrl_read(str); } /* ** Serve the data connections. This is a bit tricky, ** since all we do is move the buffer pointers. */ if (ctx.cli_data != NULL && ctx.srv_data != NULL) { if (ctx.cli_data->rbuf != NULL) { #if defined(COMPILE_DEBUG) debug(2, "Cli-Data -> Srv-Data"); #endif if (ctx.srv_data->wbuf == NULL) { ctx.srv_data->wbuf = ctx.cli_data->rbuf; } else { for (buf = ctx.srv_data->wbuf; buf && buf->next; buf = buf->next) ; buf->next = ctx.cli_data->rbuf; } ctx.cli_data->rbuf = NULL; } if (ctx.srv_data->rbuf != NULL) { #if defined(COMPILE_DEBUG) debug(2, "Srv-Data -> Cli-Data"); #endif if (ctx.cli_data->wbuf == NULL) { ctx.cli_data->wbuf = ctx.srv_data->rbuf; } else { for (buf = ctx.cli_data->wbuf; buf && buf->next; buf = buf->next) ; buf->next = ctx.srv_data->rbuf; } ctx.srv_data->rbuf = NULL; } } /* at this point the main loop resumes ... */ } /* ** Display basic session statistics... ** in secs since session begin ** downloads / read (xfer-reads from server) ** uploads / send (xfer-sends from server) */ syslog_write(U_INF, "closing connect from %s after %d secs - " "read %d/%d, sent %d/%d byte/sec", ctx.cli_ctrl ? ctx.cli_ctrl->peer : "unknown peer", time(NULL)-ctx.sess_beg, ctx.xfer_wcnt, ctx.xfer_wsec, ctx.xfer_rcnt, ctx.xfer_rsec); /* ** Free allocated memory */ ctx.magic_auth = NULL; if (ctx.userauth != NULL) { misc_free(FL, ctx.userauth); ctx.userauth = NULL; } if (ctx.username != NULL) { misc_free(FL, ctx.username); ctx.username = NULL; } if(ctx.userpass != NULL) { misc_free(FL, ctx.userpass); ctx.userpass = NULL; } #if defined(COMPILE_DEBUG) debug(1, "}}}}} %s client-exit", misc_getprog()); #endif exit(EXIT_SUCCESS); }
int client_setup(char *pwd) { char *type; char *who; /* ** Setup defaults for the client's DTP process */ ctx.cli_mode = MOD_ACT_FTP; ctx.cli_addr = ctx.cli_ctrl->addr; ctx.cli_port = ctx.cli_ctrl->port; ctx.srv_addr = INADDR_ANY; ctx.srv_port = INPORT_ANY; /* ** select the proper name for user specific setup... */ if(NULL != ctx.userauth) { who = ctx.userauth; } else { who = ctx.username; } /* ** don't allow empty or invalid names... */ if(NULL != who && '\0' != who[0]) { char *ptr; #if defined(HAVE_REGEX) char *rule; void *preg = NULL; rule = config_str(NULL, "UserNameRule", "^[[:alnum:]]+([%20@/\\._-][[:alnum:]]+)*$"); syslog_write(T_DBG, "compiling UserNameRule: '%.1024s'", rule); if(NULL == (ptr = cmds_reg_comp(&preg, rule))) { return -1; } syslog_write(T_DBG, "DeHTMLized UserNameRule: '%.1024s'", ptr); ptr = cmds_reg_exec(preg, who); if(NULL != ptr) { syslog_write(U_WRN, "invalid user name '%.128s'%s: %s", who, (strlen(who)>128 ? "..." : ""), ptr); cmds_reg_comp(&preg, NULL); /* free regex ptr */ return -1; } else { cmds_reg_comp(&preg, NULL); /* free regex ptr */ } #else /* ** Simplified "emulation" of the above regex: */ if( !(isalnum(who[0]) && isalnum(who[strlen(who)-1]))) { syslog_write(U_ERR, "invalid user name '%.128s'%s", who, (strlen(who)>128 ? "..." : "")); return 1; } for(ptr=who+1; *ptr; ptr++) { if( !(isalnum(*ptr) || ' ' == *ptr || '@' == *ptr || '/' == *ptr || '.' == *ptr || '_' == *ptr || '-' == *ptr)) { syslog_write(U_ERR, "invalid user name '%.128s'%s", who, (strlen(who)>128 ? "..." : "")); return -1; } } #endif } else { /* HUH ?! */ syslog_write(U_ERR, "empty user name"); return -1; } /* ** user specific setup from config file ** with fallback to default values */ if(0 != client_setup_file(&ctx, who)) { return -1; } /* ** check if we have to authenticate the user ** ** authenticate user and setup user specific ** from ldap server if configured */ type = config_str(NULL, "UserAuthType", NULL); if(NULL != type) { if(0 == strcasecmp(type, "ldap")) { /* ** ldap server is mandatory */ if(NULL == config_str(NULL, "LDAPServer", NULL)) { misc_die(FL, "client_setup: ?LDAPServer?"); } /* ** ldap auth + setup */ if(0 != ldap_setup_user(&ctx, who, pwd ? pwd : "")) return -1; } else { misc_die(FL, "client_setup: unknown ?UserAuthType?"); } } else { /* ** try ldap setup only */ ldap_setup_user(&ctx, who, NULL); } /* ** Evaluate mandatory settings or refuse to run. */ errno = 0; if(INADDR_ANY == ctx.srv_addr || INADDR_BROADCAST == ctx.srv_addr) { syslog_error("can't eval DestAddr for %s", ctx.cli_ctrl->peer); return -1; } if(INPORT_ANY == ctx.srv_port) { syslog_error("can't eval DestPort for %s", ctx.cli_ctrl->peer); return -1; } return 0; /* all right */ }
static int client_setup_file(CONTEXT *ctx, char *who) { char *p; u_int16_t l, u; /* ** little bit sanity check */ if( !(ctx && who && *who)) { return -1; } /* ** Inform the auditor that we are using the config file */ syslog_write(U_INF, "[ %s ] reading data for '%s' from cfg-file", ctx->cli_ctrl->peer, who); /* ** Evaluate DestinationAddress, except we have magic_addr */ if (INADDR_ANY != ctx->magic_addr) { ctx->srv_addr = ctx->magic_addr; } else { ctx->srv_addr = config_addr(who, "DestinationAddress", INADDR_ANY); #if defined(COMPILE_DEBUG) debug(2, "[ %s ] file DestAddr for %s: '%s'", ctx->cli_ctrl->peer, ctx->cli_ctrl->peer, socket_addr2str(ctx->srv_addr)); #endif } /* ** Evaluate DestinationPort, except we have magic_port */ if (INPORT_ANY != ctx->magic_port) { ctx->srv_port = ctx->magic_port; } else { ctx->srv_port = config_port(who, "DestinationPort", IPPORT_FTP); #if defined(COMPILE_DEBUG) debug(2, "[ %s ] file DestPort for %s: %d", ctx->cli_ctrl->peer, ctx->cli_ctrl->peer, (int) ctx->srv_port); #endif } /* ** Evaluate the destination transfer mode */ p = config_str(who, "DestinationTransferMode", "client"); if(0 == strcasecmp(p, "active")) { ctx->srv_mode = MOD_ACT_FTP; } else if(0 == strcasecmp(p, "passive")) { ctx->srv_mode = MOD_PAS_FTP; } else if(0 == strcasecmp(p, "client")) { ctx->srv_mode = MOD_CLI_FTP; } else { syslog_error("can't eval DestMode for %s", ctx->cli_ctrl->peer); return -1; } #if defined(COMPILE_DEBUG) debug(2, "file DestMode for %s: %s", ctx->cli_ctrl->peer, p); #endif /* ** Evaluate min/max destination port range */ l = config_port(who, "DestinationMinPort", INPORT_ANY); u = config_port(who, "DestinationMaxPort", INPORT_ANY); if (l > 0 && u > 0 && u >= l) { ctx->srv_lrng = l; ctx->srv_urng = u; } else { ctx->srv_lrng = INPORT_ANY; ctx->srv_urng = INPORT_ANY; } #if defined(COMPILE_DEBUG) debug(2, "file DestRange for %s: %u-%u", ctx->cli_ctrl->peer, ctx->srv_lrng, ctx->srv_urng); #endif /* ** Evaluate min/max active port range */ l = config_port(who, "ActiveMinDataPort", INPORT_ANY); u = config_port(who, "ActiveMaxDataPort", INPORT_ANY); if (l > 0 && u > 0 && u >= l) { ctx->act_lrng = l; ctx->act_urng = u; } else { /* do not try to bind a port < 1024 if running as UID != 0 */ if(0 == getuid()) { ctx->act_lrng = (IPPORT_FTP - 1); ctx->act_urng = (IPPORT_FTP - 1); } else { ctx->act_lrng = INPORT_ANY; ctx->act_urng = INPORT_ANY; } } #if defined(COMPILE_DEBUG) debug(2, "file ActiveRange for %s: %u-%u", ctx->cli_ctrl->peer, ctx->act_lrng, ctx->act_urng); #endif /* ** Evaluate min/max passive port range */ l = config_port(who, "PassiveMinDataPort", INPORT_ANY); u = config_port(who, "PassiveMaxDataPort", INPORT_ANY); if (l > 0 && u > 0 && u >= l) { ctx->pas_lrng = l; ctx->pas_urng = u; } else { ctx->pas_lrng = INPORT_ANY; ctx->pas_urng = INPORT_ANY; } #if defined(COMPILE_DEBUG) debug(2, "file PassiveRange for %s: %u-%u", ctx->cli_ctrl->peer, ctx->pas_lrng, ctx->pas_urng); #endif /* ** Setup other configuration options */ ctx->same_adr = config_bool(who, "SameAddress", 1); ctx->timeout = config_int (who, "TimeOut", 900); #if defined(COMPILE_DEBUG) debug(2, "file SameAddress for %s: %s", ctx->cli_ctrl->peer, ctx->same_adr ? "yes" : "no"); debug(2, "file TimeOut for %s: %d", ctx->cli_ctrl->peer, ctx->timeout); #endif /*** Adjust the allow/deny flags for the commands ** Fred patch */ char dest[17]; char ipdest[17]; char ipsrc[17]; strcpy (ipsrc,ctx->cli_ctrl->peer); strcpy (ipdest, socket_addr2str(ctx->srv_addr)); syslog_write(U_INF, "\n"); syslog_write(U_INF, "[ %s ] Fred Patch rules dest: %s src: %s", ipsrc, ipdest, ipsrc); char groupname[]="group"; char commandename[]="ValidCommands"; char *group; FILE *fp; group = "group1"; int ix; int ix2; u_int32_t dnsaddr; for(ix=1; group != NULL; ix++) { sprintf (&groupname[5],"%d",ix); group = config_str(who, groupname, NULL); } syslog_write(U_INF, "[ %s ] Number of groups: %d", ipsrc, ix-2); for (ix2=1; ix2 <= ix-2; ix2++) { sprintf (&groupname[5],"%d",ix2); group = config_str(who, groupname, NULL); syslog_write(U_INF, "[ %s ] Reading: %s",ipsrc, group ); if ((fp = fopen(group, "r")) == NULL) { syslog_write(U_INF, "File not found"); return 0; } else { fseek(fp, 0, SEEK_SET); while (fgets(dest, 17 , fp) != NULL) { // Pour une IP // Correction Bug Ligne sans \n dest[16] = '\n'; char *c = strchr (dest, '\n'); *c = 0; /* Dns resolution */ if (ipdest != dest) { dnsaddr = socket_str2addr(dest, INADDR_ANY); if (dnsaddr != 0) strcpy (dest, socket_addr2str(dnsaddr)); } if (strcmp(dest,ipdest) == 0 || strcmp(dest,ipsrc) == 0) { sprintf (&commandename[13],"%d",ix); p = config_str(who,commandename, NULL); cmds_set_allow(p); syslog_write(U_INF, "[ %s ] Apply rules for: %s dst: %s",ipsrc, ipsrc, ipdest); syslog_write(U_INF, "[ %s ] Server match %s ",ipsrc, group ); syslog_write(U_INF, "\n"); fclose(fp); return 0; } // Network if (strchr(dest, 'x') != NULL) { char *c = strchr(dest, 'x'); *c = 0; int longueur; longueur = strlen(dest); if (strncmp(dest,ipdest,longueur) == 0 || strncmp(dest,ipsrc,longueur) == 0) { sprintf (&commandename[13],"%d",ix); p = config_str(who,commandename, NULL); cmds_set_allow(p); syslog_write(U_INF, "[ %s ] Apply rules for Network: %s src: %s",ipsrc, ipdest, ipsrc); syslog_write(U_INF, "[ %s ] Server match %s ",ipsrc, group ); syslog_write(U_INF, "\n"); fclose(fp); return 0; } } } fclose(fp); } } syslog_write(U_INF, "[ %s ] Oh, Oh, no rule found -> defaultrules", ipsrc) ; p = config_str(who, "defaultrules", NULL); cmds_set_allow(p); return 0; }
int main( int argc, char* argv[] ) { DrawTools::setStyle(); std::string tag = "V00"; std::string config = "SiPM2015Config"; if( argc>1 ) { std::string tag_str(argv[1]); tag = tag_str; if( argc>2 ) { std::string config_str(argv[2]); config=config_str; } } else { std::cout << "Usage:" << std::endl; std::cout << "./timingStudies ([tag]) ([config])" << std::endl; exit(12345); } std::cout<<config<<std::endl; theConfiguration_=readConfiguration(config); std::vector<float> energies; std::vector<int> wp_channel; std::vector<int> wp_fibre; std::vector<int> runs; for (int i=0;i<theConfiguration_.energies.size();++i){ energies.push_back(theConfiguration_.energies[i]); wp_channel.push_back(theConfiguration_.wp_channel[i]); wp_fibre.push_back(theConfiguration_.wp_fibre[i]); runs.push_back(theConfiguration_.runs[i]); } std::string constDirName = "plots_timing_"; constDirName+=theConfiguration_.setup; system(Form("mkdir -p %s", constDirName.c_str())); TString dir(constDirName); TGraphErrors* resVsEnergy_channel = new TGraphErrors(0); TGraphErrors* resVsEnergy_fibre = new TGraphErrors(0); std::vector<TGraphErrors*> resVsAmplitude; for (int i=0;i<runs.size();++i){ TString run; run.Form("%d",runs[i]); resVsAmplitude.push_back(new TGraphErrors(0)); TFile* file = TFile::Open(dir+"/timingStudiesSiPM_"+tag+"_"+run+".root"); if( file==0 ) { std::cout << "ERROR! Din't find file for run" << runs[i] << std::endl; std::cout << "Exiting." << std::endl; exit(11); } //channel TVectorD* resValueTime_channel=(TVectorD*)file->Get("resValueTime_channel"); TVectorD* resErrValueTime_channel=(TVectorD*)file->Get("resErrValueTime_channel"); TVectorD* resValueAmplitude_channel=(TVectorD*)file->Get("resValueAmplitude_channel"); TVectorD* resErrValueAmplitude_channel=(TVectorD*)file->Get("resErrValueAmplitude_channel"); TVectorD* resErrRelativeValueTime_channel=(TVectorD*)file->Get("resErrRelativeValueTime_channel"); TVectorD* nEntriesTime_channel=(TVectorD*)file->Get("nEntriesTime_channel"); //fibre TVectorD* resValueTime_fibre=(TVectorD*)file->Get("resValueTime_fibre"); TVectorD* resErrValueTime_fibre=(TVectorD*)file->Get("resErrValueTime_fibre"); // resVsEnergy->SetPoint( i, energies[i],(*resValueTime)[wp_100[i]] ); //FIXME resVsEnergy->SetPointError( i, 0, (*resErrValueTime)[wp_100[i]]); resVsEnergy_channel->SetPoint( i, energies[i], (*resValueTime_channel)[wp_channel[i]]); resVsEnergy_channel->SetPointError( i, 0,(*resErrValueTime_channel)[wp_channel[i]] ); resVsEnergy_fibre->SetPoint( i, energies[i], (*resValueTime_fibre)[wp_fibre[i]]); resVsEnergy_fibre->SetPointError( i, 0,(*resErrValueTime_fibre)[wp_fibre[i]] ); for (int j=0;j<resValueTime_channel->GetNoElements();j++){ // std::cout<<j<<" "<<(*resValueAmplitude_channel)[j]<<std::endl; if ((*resValueAmplitude_channel)[j]<10)continue; resVsAmplitude[i]->SetPoint(j,(20+j*10),(*resValueAmplitude_channel)[j]); resVsAmplitude[i]->SetPointError(j,0,(*resErrValueAmplitude_channel)[j]); } } TFile * outFile = new TFile(dir+"/plotsTimingStudiesSiPM_"+tag+".root","recreate"); TCanvas* c1 = new TCanvas( "c1", "", 600, 600 ); float yup=1.1*(resVsAmplitude[2]->GetY())[0]; if((resVsAmplitude[2]->GetY())[0]<10) yup = 1.1*(resVsAmplitude[1]->GetY())[0]; float xlow=(resVsAmplitude[2]->GetX())[0]-10; if(xlow<10)xlow = (resVsAmplitude[1]->GetX())[0]-10; float xup=(resVsAmplitude[2]->GetX())[resVsAmplitude[2]->GetN()-1]+10; if(xup<10)xup = (resVsAmplitude[2]->GetX())[resVsAmplitude[2]->GetN()-1]+10; TH2D* h2_axes_2 = new TH2D( "axes_2", "", 100, xlow,xup , 110, 0., yup); // std::cout<<(resVsEnergy_channel->GetY())[0]+(resVsEnergy_channel->GetErrorY(0))<<std::endl; TH2D* h2_axes_3 = new TH2D( "axes_1", "", 100, -0.0, 250. , 110, 60., 1.1*((resVsEnergy_channel->GetY())[0]+(resVsEnergy_channel->GetErrorY(0)))); h2_axes_3->SetXTitle("Beam Energy [GeV]"); h2_axes_3->SetYTitle("time_{Fibre}-time_{mcp} [ps]"); TH2D* h2_axes_4 = new TH2D( "axes_1", "", 100, -0.0, 250. , 110, 60., 1.1*((resVsEnergy_fibre->GetY())[0]+(resVsEnergy_fibre->GetErrorY(0)))); h2_axes_4->SetXTitle("Beam Energy [GeV]"); h2_axes_4->SetYTitle("time_{Fibre}-time_{mcp} [ps]"); //resolution vs energy //channel TF1* f_ene= new TF1("fun_ene","[1]/x+[0]",(resVsEnergy_channel->GetX())[0]-10,(resVsEnergy_channel->GetX())[resVsEnergy_channel->GetN()-1] +10); h2_axes_3->Draw(""); resVsEnergy_channel->Fit("fun_ene"); TLegend* lego_2 = new TLegend(0.47, 0.7, 0.8, 0.92); lego_2->SetTextSize(0.038); lego_2->AddEntry( (TObject*)0 ,"f(x) = p0 + p1/x", ""); lego_2->AddEntry( (TObject*)0 ,Form("p0 = %.0f #pm %.0f", f_ene->GetParameter(0), f_ene->GetParError(0) ), ""); lego_2->AddEntry( (TObject*)0 ,Form("p1 = %.0f #pm %.0f", f_ene->GetParameter(1), f_ene->GetParError(1) ), ""); lego_2->SetFillColor(0); lego_2->Draw("same"); resVsEnergy_channel->SetMarkerStyle(20); resVsEnergy_channel->SetMarkerSize(1.6); resVsEnergy_channel->SetMarkerColor(kBlue); resVsEnergy_channel->Draw("p same"); resVsEnergy_channel->SetName("resVsEnergy_channel"); resVsEnergy_channel->Write(); c1->SaveAs(dir+"/timingResolutionVsEnergySiPM_channel.png"); c1->SaveAs(dir+"/timingResolutionVsEnergySiPM_channel.pdf"); //fibre h2_axes_4->Draw(""); resVsEnergy_fibre->Fit("fun_ene"); lego_2->Clear(); lego_2->SetTextSize(0.038); lego_2->AddEntry( (TObject*)0 ,"f(x) = p0 + p1/x", ""); lego_2->AddEntry( (TObject*)0 ,Form("p0 = %.0f #pm %.0f", f_ene->GetParameter(0), f_ene->GetParError(0) ), ""); lego_2->AddEntry( (TObject*)0 ,Form("p1 = %.0f #pm %.0f", f_ene->GetParameter(1), f_ene->GetParError(1) ), ""); lego_2->SetFillColor(0); lego_2->Draw("same"); resVsEnergy_fibre->SetMarkerStyle(20); resVsEnergy_fibre->SetMarkerSize(1.6); resVsEnergy_fibre->SetMarkerColor(kBlue); resVsEnergy_fibre->Draw("p same"); resVsEnergy_fibre->SetName("resVsEnergy_fibre"); resVsEnergy_fibre->Write(); c1->SaveAs(dir+"/timingResolutionVsEnergySiPM_fibre.png"); c1->SaveAs(dir+"/timingResolutionVsEnergySiPM_fibre.pdf"); for(int i=0;i<runs.size();++i){ TString ene; ene.Form("%.0f",energies[i]); std::string energy(Form("%.0f", energies[i])); h2_axes_2->SetYTitle("#sigma_{t} [ps]"); h2_axes_2->GetXaxis()->SetTitle("Amplitude [ADC]"); h2_axes_2->Draw(""); TF1* f= new TF1("fun","[1]/x+[0]",(resVsAmplitude[i]->GetX())[0]-10,(resVsAmplitude[i]->GetX())[resVsAmplitude[i]->GetN()-1] +10); resVsAmplitude[i]->Fit("fun"); resVsAmplitude[i]->SetName("resVsAmplitude_"+ene); resVsAmplitude[i]->SetMarkerStyle(20); resVsAmplitude[i]->SetMarkerSize(1.6); resVsAmplitude[i]->SetMarkerColor(kBlue); resVsAmplitude[i]->Draw("p same"); TPaveText* pave = DrawTools::getLabelTop_expOnXaxis(energy+" GeV Electron Beam"); pave->Draw("same"); TLegend* lego = new TLegend(0.47, 0.7, 0.8, 0.92); lego->SetTextSize(0.038); lego->AddEntry( (TObject*)0 ,"f(x) = p0 + p1/x", ""); lego->AddEntry( (TObject*)0 ,Form("p0 = %.0f #pm %.0f", f->GetParameter(0), f->GetParError(0) ), ""); lego->AddEntry( (TObject*)0 ,Form("p1 = %.0f #pm %.0f", f->GetParameter(1), f->GetParError(1) ), ""); lego->SetFillColor(0); lego->Draw("same"); c1->SaveAs(dir+"/timingResolutionVsAmplitudeSiPM_"+ene+"GeV.png"); c1->SaveAs(dir+"/timingResolutionVsAmplitudeSiPM_"+ene+"GeV.pdf"); resVsAmplitude[i]->Write(); } outFile->Write(); outFile->Close(); return 0; }
int main( int argc, char* argv[] ) { DrawTools::setStyle(); std::string tag = "V00"; std::string config = "SiPM2015Config"; if( argc>1 ) { std::string tag_str(argv[1]); tag = tag_str; if( argc>2 ) { std::string config_str(argv[2]); config=config_str; } } else { std::cout << "Usage:" << std::endl; std::cout << "./plotterMaps ([tag]) ([config])" << std::endl; exit(12345); } std::cout<<config<<std::endl; theConfiguration_=readConfiguration(config); std::string constDirName = "plots_maps_"; constDirName+=theConfiguration_.setup; if(theConfiguration_.addTagFileName){ constDirName+="_"; constDirName+=theConfiguration_.tagFileName; } system(Form("mkdir -p %s", constDirName.c_str())); TString dir(constDirName); std::vector<int> runs; std::vector<float> energies; for (int i=0;i<theConfiguration_.runs.size()+1;++i){//+1 for all the run together if(i<theConfiguration_.runs.size()){ runs.push_back(theConfiguration_.runs[i]); energies.push_back(theConfiguration_.energies[i]); } TString filename= "plots_timing_"+theConfiguration_.setup+"/timingStudiesSiPM_"+tag+"_"; if(i<theConfiguration_.runs.size()){ filename+=runs[i]; }else{ filename+="total"; } filename+=".root"; TFile* file = TFile::Open(filename.Data()); TH2F* timing_map_total=(TH2F*)file->Get("timing_map_channel"); TH2F* amplitude_map_total=(TH2F*)file->Get("amplitude_map_channel"); TH2F* amplitude_map_fibre2=(TH2F*)file->Get("amplitude_map_fibre2"); TH2F* timing_map_sel_channel=(TH2F*)file->Get("timing_map_sel_channel"); TH2F* amplitude_map_sel_channel=(TH2F*)file->Get("amplitude_map_sel_channel"); TH2F* timing_map_sel_fibre=(TH2F*)file->Get("timing_map_sel_fibre"); TH2F* amplitude_map_sel_fibre=(TH2F*)file->Get("amplitude_map_sel_fibre"); TH1F* maxAmpl_sel_fibre=(TH1F*)file->Get("maxAmpl_sel_fibre"); TH1F* maxAmpl_sel_channel=(TH1F*)file->Get("maxAmpl_sel_channel"); TString runString; if(i<theConfiguration_.runs.size()){ runString+=runs[i]; }else{ runString+="total"; //for total we do normalized plots float max= amplitude_map_total->GetMaximum(); amplitude_map_total->Scale(1./max); amplitude_map_total->SetAxisRange(0,1,"Z"); max= amplitude_map_fibre2->GetMaximum(); amplitude_map_fibre2->Scale(1./max); amplitude_map_fibre2->SetAxisRange(0,1,"Z"); max= amplitude_map_sel_channel->GetMaximum(); amplitude_map_sel_channel->Scale(1./max); amplitude_map_sel_channel->SetAxisRange(0,1,"Z"); max= amplitude_map_sel_fibre->GetMaximum(); amplitude_map_sel_fibre->Scale(1./max); amplitude_map_sel_fibre->SetAxisRange(0,1,"Z"); //timing should be scaled for number of files after hadd timing_map_total->Scale(1./runs.size()); timing_map_total->SetAxisRange(-0.1,0.9,"Z"); timing_map_sel_channel->Scale(1./runs.size()); timing_map_sel_channel->SetAxisRange(-0.1,0.9,"Z"); timing_map_sel_fibre->Scale(1./runs.size()); timing_map_sel_fibre->SetAxisRange(-0.1,0.6,"Z"); } gStyle->SetPadRightMargin(0.17);//for the palette TCanvas c1; amplitude_map_total->Draw("colz"); c1.SaveAs(dir+"/amplitude_map_"+runString+".pdf"); c1.SaveAs(dir+"/amplitude_map_"+runString+".png"); c1.Clear(); amplitude_map_fibre2->Draw("colz"); c1.SaveAs(dir+"/amplitude_map_fibre2_"+runString+".pdf"); c1.SaveAs(dir+"/amplitude_map_fibre2_"+runString+".png"); c1.Clear(); timing_map_total->Draw("colz"); c1.SaveAs(dir+"/timing_map_"+runString+".pdf"); c1.SaveAs(dir+"/timing_map_"+runString+".png"); c1.Clear(); amplitude_map_sel_channel->Draw("colz"); c1.SaveAs(dir+"/amplitude_map_sel_channel"+runString+".pdf"); c1.SaveAs(dir+"/amplitude_map_sel_channel"+runString+".png"); c1.Clear(); timing_map_sel_channel->Draw("colz"); c1.SaveAs(dir+"/timing_map_sel_channel"+runString+".pdf"); c1.SaveAs(dir+"/timing_map_sel_channel"+runString+".png"); c1.Clear(); amplitude_map_sel_fibre->Draw("colz"); c1.SaveAs(dir+"/amplitude_map_sel_fibre"+runString+".pdf"); c1.SaveAs(dir+"/amplitude_map_sel_fibre"+runString+".png"); c1.Clear(); timing_map_sel_fibre->Draw("colz"); c1.SaveAs(dir+"/timing_map_sel_fibre"+runString+".pdf"); c1.SaveAs(dir+"/timing_map_sel_fibre"+runString+".png"); gStyle->SetPadRightMargin(0.10); TCanvas c2; maxAmpl_sel_channel->GetXaxis()->SetRangeUser(0,800.); maxAmpl_sel_channel->SetLineWidth(2); maxAmpl_sel_fibre->SetLineWidth(2); maxAmpl_sel_channel->DrawNormalized(); maxAmpl_sel_fibre->DrawNormalized("same"); if(i<theConfiguration_.runs.size()){ std::string energy(Form("%.0f",energies[i])); TPaveText* pave = DrawTools::getLabelTop_expOnXaxis(energy+" GeV Electron Beam"); pave->Draw("same"); }else{ std::string energy(Form("%.0f",energies[i])); TPaveText* pave = DrawTools::getLabelTop_expOnXaxis("Electron Beam"); pave->Draw("same"); } c2.SaveAs(dir+"/maxAmpl_comparison_"+runString+".pdf"); c2.SaveAs(dir+"/maxAmpl_comparison_"+runString+".png"); } }