void setDestroy(Set set) { if (set == NULL) { return; // mimic free() behavior } setClear(set); free(set->dummy); free(set); }
int THaCrateMap::init(TString the_map) { // initialize the crate-map according to the lines in the string 'the_map' // parse each line separately, to ensure that the format is correct // be certain the_map ends with a '\0' so we can make a stringstream from it the_map += '\0'; ISSTREAM s(the_map.Data()); int linecnt = 0; string line; int crate; // current CRATE int slot; typedef string::size_type ssiz_t; for(crate=0; crate<MAXROC; crate++) { crdat[crate].nslot = 0; crdat[crate].crate_used = false; crdat[crate].bank_structure = false; setCrateType(crate,"unknown"); // crate_type[crate] = "unknown"; crdat[crate].minslot=MAXSLOT; crdat[crate].maxslot=0; for(slot=0; slot<MAXSLOT; slot++) { crdat[crate].slot_used[slot] = false; crdat[crate].model[slot] = 0; crdat[crate].header[slot] = 0; crdat[crate].slot_clear[slot] = true; crdat[crate].bank[slot] = -1; } } crate=-1; // current CRATE while ( getline(s,line).good() ) { linecnt++; ssiz_t l = line.find_first_of("!#"); // drop comments if (l != string::npos ) line.erase(l); if ( line.length() <= 0 ) continue; if ( line.find_first_not_of(" \t") == string::npos ) continue; // nothing useful char ctype[21]; // Make the line "==== Crate" not care about how many "=" chars or other // chars before "Crate", but lines beginning in # are still a comment ssiz_t st = line.find("Crate", 0, 5); if (st != string::npos) { string lcopy = line; line.replace(0, lcopy.length(), lcopy, st, st+lcopy.length()); } // set the next CRATE number and type if ( sscanf(line.c_str(),"Crate %d type %20s",&crate,ctype) == 2 ) { if ( setCrateType(crate,ctype) != CM_OK ) { cout << "THaCrateMap:: fatal ERROR 2 setCrateType "<<endl; return CM_ERR; } // for a scaler crate, get the 'name' or location as well if ( crdat[crate].crate_code == kScaler ) { if (sscanf(line.c_str(),"Crate %*d type %*s %20s",ctype) != 1) { cout << "THaCrateMap:: fatal ERROR 3 "<<endl; return CM_ERR; } TString scaler_name(ctype); scaler_name.ReplaceAll("\"",""); // drop extra quotes setScalerLoc(crate,scaler_name); } continue; // onto the next line } // The line is of the format: // slot# model# [clear header mask nchan ndata ] // where clear, header, mask, nchan and ndata are optional interpretted in // that order. // Another option is "bank decoding" : all data in this CODA bank // belongs to this slot and model. The line has the format // slot# model# bank# // Default values: int imodel, cword=1; unsigned int mask=0, iheader=0, ichan=MAXCHAN, idata=MAXDATA; int nread; // must read at least the slot and model numbers if ( crate>=0 && (nread= sscanf(line.c_str(),"%d %d %d %x %x %u %u", &slot,&imodel,&cword,&iheader,&mask,&ichan,&idata)) >=2 ) { if (nread>=6) setModel(crate,slot,imodel,ichan,idata); else setModel(crate,slot,imodel); if (nread==3) setBank(crate, slot, cword); if (nread>3) setClear(crate,slot,cword); if (nread>=4) setHeader(crate,slot,iheader); if (nread>=5) setMask(crate,slot,mask); continue; } // unexpected input cout << "THaCrateMap:: fatal ERROR 4 "<<endl<<"Bad line "<<endl<<line<<endl; cout << " Warning: a bad line could cause wrong decoding !"<<endl; return CM_ERR; } for(crate=0; crate<MAXROC; crate++) { Int_t imin=MAXSLOT; Int_t imax=0; for(slot=0; slot<MAXSLOT; slot++) { if (crdat[crate].bank[slot]>=0) crdat[crate].bank_structure=true; if (crdat[crate].slot_used[slot]) { if (slot < imin) imin=slot; if (slot > imax) imax=slot; } } crdat[crate].minslot=imin; crdat[crate].maxslot=imax; } return CM_OK; }