1010import org .jlab .detector .base .DetectorDescriptor ;
1111
1212import org .jlab .detector .base .DetectorType ;
13+ import org .jlab .detector .calib .utils .RCDBProvider .RCDBManager ;
1314import org .jlab .detector .decode .DetectorDataDgtz .HelicityDecoderData ;
1415import org .jlab .detector .helicity .HelicityBit ;
1516import org .jlab .detector .helicity .HelicitySequence ;
@@ -47,8 +48,9 @@ public class CLASDecoder4 {
4748 private HipoDataEvent hipoEvent = null ;
4849 private boolean isRunNumberFixed = false ;
4950 private int decoderDebugMode = 0 ;
50- private SchemaFactory schemaFactory = new SchemaFactory ();
51- private ModeAHDC ahdcExtractor = new ModeAHDC ();
51+ private SchemaFactory schemaFactory = new SchemaFactory ();
52+ private ModeAHDC ahdcExtractor = new ModeAHDC ();
53+ private RCDBManager rcdbManager = new RCDBManager ();
5254
5355 public CLASDecoder4 (boolean development ){
5456 codaDecoder = new CodaEventDecoder ();
@@ -439,11 +441,11 @@ public Bank getDataBankUndecodedSCALER(String name, DetectorType type){
439441 return scalerBANK ;
440442 }
441443
442- public Event getDecodedEvent (EvioDataEvent rawEvent , int run , int counter , double torus , double solenoid ) {
444+ public Event getDecodedEvent (EvioDataEvent rawEvent , int run , int counter , Double torus , Double solenoid ) {
443445
444446 Event decodedEvent = this .getDataEvent (rawEvent );
445447
446- Bank header = this .createHeaderBank (run , counter , ( float ) torus , ( float ) solenoid );
448+ Bank header = this .createHeaderBank (run , counter , torus , solenoid );
447449 if (header !=null ) decodedEvent .write (header );
448450
449451 Bank trigger = this .createTriggerBank ();
@@ -614,7 +616,7 @@ public long getTriggerPhase() {
614616 return ((timestamp %6 )+phase_offset )%6 ; // TI derived phase correction due to TDC and FADC clock differences
615617 }
616618
617- public Bank createHeaderBank ( int nrun , int nevent , float torus , float solenoid ){
619+ public Bank createHeaderBank ( int nrun , int nevent , Double torus , Double solenoid ){
618620
619621 if (schemaFactory .hasSchema ("RUN::config" )==false ) return null ;
620622
@@ -631,24 +633,31 @@ public Bank createHeaderBank( int nrun, int nevent, float torus, float solenoid)
631633 localEvent = nevent ;
632634 }
633635
634- /*
635- // example of getting torus/solenoid from RCDB:
636- if (Math.abs(solenoid)>10) {
637- solenoid = this.detectorDecoder.getRcdbSolenoidScale();
638- }
639- if (Math.abs(torus)>10) {
640- torus = this.detectorDecoder.getRcdbTorusScale();
641- }
642- */
643-
644636 bank .putInt ("run" , 0 , localRun );
645637 bank .putInt ("event" , 0 , localEvent );
646638 bank .putInt ("unixtime" , 0 , localTime );
647639 bank .putLong ("trigger" , 0 , triggerBits );
648- bank .putFloat ("torus" , 0 , torus );
649- bank .putFloat ("solenoid" , 0 , solenoid );
650640 bank .putLong ("timestamp" , 0 , timeStamp );
651641
642+ if (torus != null ) {
643+ bank .putFloat ("torus" , 0 , torus .floatValue ());
644+ }
645+ else if (rcdbManager .getTorusScale (localRun ) == null ) {
646+ if (localRun > 100 ) throw new RuntimeException ("Error retrieving torus scale from RCDB." );
647+ }
648+ else {
649+ bank .putFloat ("torus" , 0 , rcdbManager .getTorusScale (localRun ).floatValue ());
650+ }
651+ if (solenoid != null ) {
652+ bank .putFloat ("solenoid" , 0 , solenoid .floatValue ());
653+ }
654+ else if (rcdbManager .getSolenoidScale (localRun ) == null ) {
655+ if (localRun > 100 ) throw new RuntimeException ("Error retrieving solenoid scale from RCDB." );
656+ }
657+ else {
658+ bank .putFloat ("solenoid" , 0 , rcdbManager .getSolenoidScale (localRun ).floatValue ());
659+ }
660+
652661 return bank ;
653662 }
654663
@@ -774,8 +783,7 @@ public Bank createHelicityDecoderBank(EvioDataEvent event) {
774783 else
775784 return null ;
776785 }
777-
778-
786+
779787 public static void main (String [] args ){
780788
781789 OptionParser parser = new OptionParser ("decoder" );
@@ -786,8 +794,8 @@ public static void main(String[] args){
786794 parser .addOption ("-m" , "run" ,"translation tables source (use -m devel for development tables)" );
787795 parser .addOption ("-b" , "16" ,"record buffer size in MB" );
788796 parser .addOption ("-r" , "-1" ,"run number in the header bank (-1 means use CODA run)" );
789- parser .addOption ("-t" , "-0.5" ,"torus current in the header bank" );
790- parser .addOption ("-s" , "0.5" ,"solenoid current in the header bank" );
797+ parser .addOption ("-t" , null ,"torus current in the header bank (null means use RCDB) " );
798+ parser .addOption ("-s" , null ,"solenoid current in the header bank (null means use RCDB) " );
791799 parser .addOption ("-x" , null ,"CCDB timestamp (MM/DD/YYYY-HH:MM:SS)" );
792800 parser .addOption ("-v" ,"default" ,"CCDB variation" );
793801 parser .addRequired ("-o" ,"output.hipo" );
@@ -833,8 +841,8 @@ public static void main(String[] args){
833841 Event scalerEvent = new Event ();
834842
835843 int nrun = parser .getOption ("-r" ).intValue ();
836- double torus = parser .getOption ("-t" ).doubleValue ();
837- double solenoid = parser .getOption ("-s" ).doubleValue ();
844+ Double torus = parser . getOption ( "-t" ). getValue () == null ? null : parser .getOption ("-t" ).doubleValue ();
845+ Double solenoid = parser . getOption ( "-s" ). getValue () == null ? null : parser .getOption ("-s" ).doubleValue ();
838846
839847 writer .open (outputFile );
840848 ProgressPrintout progress = new ProgressPrintout ();
0 commit comments