2323 * 3. Writes HEL::flip, RUN/HEL::scaler, and RUN::unix to new tag-1 events
2424 * 4. Runs post-processing, writing tag-1 information to all events
2525 * 5. Adds .hipo to the output filename, if necessary
26- *
26+ * 6. Outputs a parallel file of select trigger bits with a raw schema
2727 * @author baltzell
2828 */
2929public class Clas12Writer extends HipoToHipoWriter {
@@ -34,6 +34,11 @@ public class Clas12Writer extends HipoToHipoWriter {
3434 SchemaFactory fullSchema ;
3535 boolean postprocess ;
3636
37+ HipoWriterSorted paraWriter ;
38+ long paraCount ;
39+ long paraTriggerMask ;
40+ int paraTriggerPrescale ;
41+
3742 private void init (JSONObject opts ) {
3843 fullSchema = new SchemaFactory ();
3944 fullSchema .initFromDirectory (FileUtils .getEnvironmentPath ("CLAS12DIR" ,"etc/bankdefs/hipo4" ));
@@ -42,6 +47,8 @@ private void init(JSONObject opts) {
4247 conman = new ConstantsManager ();
4348 conman .init ("/runcontrol/hwp" ,"/runcontrol/helicity" );
4449 postprocess = opts .optBoolean ("postprocess" , false );
50+ paraTriggerMask = opts .optLong ("paraTriggerMask" , 0 );
51+ paraTriggerPrescale = opts .optInt ("paraTriggerPrescale" , 0 );
4552 if (opts .has ("variation" )) conman .setVariation (opts .getString ("variation" ));
4653 if (opts .has ("timestamp" )) conman .setTimeStamp (opts .getString ("timestamp" ));
4754 }
@@ -52,7 +59,15 @@ protected HipoWriterSorted createWriter(Path file, JSONObject opts) throws Event
5259 init (opts );
5360 HipoWriterSorted w = new HipoWriterSorted ();
5461 super .configure (w , opts );
55- w .open (file .toString ().endsWith (".hipo" ) ? file .toString () : file .toString ()+".hipo" );
62+ String dirname = file .getParent ().toString ();
63+ String basename = file .getFileName ().toString ();
64+ if (!basename .endsWith (".hipo" )) basename += ".hipo" ;
65+ if (paraTriggerMask > 0 ) {
66+ paraWriter = new HipoWriterSorted ();
67+ paraWriter .getSchemaFactory ().copy (fullSchema );
68+ paraWriter .open (dirname + "/tb" + basename .substring (basename .indexOf ("_" )));
69+ }
70+ w .open (dirname + "/" + basename );
5671 return w ;
5772 } catch (Exception e ) {
5873 throw new EventWriterException (e );
@@ -64,6 +79,17 @@ protected void writeEvent(Object event) throws EventWriterException {
6479 Event t = serial .read ((Event )event );
6580 if (!t .isEmpty ()) writer .addEvent (t , 1 );
6681 super .writeEvent (event );
82+ writeRaw ((Event )event , t );
83+ }
84+
85+ void writeRaw (Event physics , Event tagged ) {
86+ if (paraTriggerMask > 0 ) {
87+ physics .read (runConfig );
88+ if (runConfig .getRows ()>0 && (runConfig .getLong ("trigger" ,0 ) & paraTriggerMask ) != 0 )
89+ if (paraTriggerPrescale <=0 || (++paraCount % paraTriggerPrescale ) == 0 )
90+ paraWriter .addEvent (physics );
91+ if (!tagged .isEmpty ()) paraWriter .addEvent (tagged , tagged .getEventTag ());
92+ }
6793 }
6894
6995 @ Override
@@ -72,6 +98,7 @@ protected void closeWriter() {
7298 super .closeWriter ();
7399 if (postprocess ) postprocess ();
74100 serial .clear ();
101+ if (paraTriggerMask > 0 ) paraWriter .close ();
75102 }
76103
77104 /**
0 commit comments